View Javadoc

1   /**
2    * 
3    */
4   package de.tivsource.page.admin.actions.locations.event;
5   
6   import java.util.List;
7   
8   import org.apache.logging.log4j.LogManager;
9   import org.apache.logging.log4j.Logger;
10  import org.apache.struts2.convention.annotation.Action;
11  import org.apache.struts2.convention.annotation.ParentPackage;
12  import org.apache.struts2.convention.annotation.Result;
13  
14  import com.opensymphony.xwork2.ActionSupport;
15  
16  import de.tivsource.ejb3plugin.InjectEJB;
17  import de.tivsource.page.dao.event.EventDaoLocal;
18  import de.tivsource.page.entity.event.Event;
19  /**
20   * @author Marc Michele
21   * 
22   */
23  @ParentPackage(value = "administratorJson")
24  public class JsonAction extends ActionSupport {
25  
26      /**
27       * Serial Version UID.
28       */
29      private static final long serialVersionUID = -890856479292802431L;
30  
31      /**
32       * Statischer Logger der Klasse.
33       */
34      private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
35      
36      @InjectEJB(name="EventDao")
37      private EventDaoLocal eventDaoLocal;
38  
39  	private List<Event> gridModel;
40  	private List<Event> eventList;
41  	private Integer rows = 0;
42  	private Integer page = 1;
43  	private Integer total = 0;
44  	private Integer record = 0;
45  	private String sord;
46  	private String sidx;
47  
48  	@Override
49      @Action(
50              value = "table",
51              results = {
52                  @Result(name = "success", type="json", params={"excludeProperties", "gridModel.*.reservations, gridModel.*.events, gridModel.*.vacancies, gridModel.*.picture, gridModel.*.pictureItems"})
53              }
54          )
55  	public String execute() {
56  		return SUCCESS;
57  	}
58  
59  	public String getJSON() {
60  
61  	    LOGGER.info("Page " + getPage() + " Rows " + getRows()
62  				+ " Sorting Order " + getSord() + " Index Row :" + getSidx());
63  	    LOGGER.info("Build new List");
64  
65  		/*
66  		 * Setze die Anzahl aller Objekte in der Datenbank.
67  		 */
68  		setRecord(this.eventDaoLocal.countAllActive());
69  
70  		int to = (getRows() * getPage());
71  		int from = to - getRows();
72  
73  		/*
74  		 * Setze die Maximalgrenze auf die Maximale Anzahl
75  		 */
76  		if (to > getRecord()) {
77  			to = getRecord();
78  		}
79  		
80  		/*
81  		 * Sortieren aufsteigen
82  		 */
83  		if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
84  		    LOGGER.info("Sortieren nach asc");
85  			if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
86  				eventList = this.eventDaoLocal.findAllActive(from, getRows(), "dm.name", "asc");
87  			} else if (getSidx() != null && getSidx().equalsIgnoreCase("location")) {
88  				eventList = this.eventDaoLocal.findAllActive(from, getRows(), "edm.name", "asc");
89  			} else if (getSidx() != null && getSidx().equalsIgnoreCase("price")) {
90                  eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.price", "asc");
91              } else if (getSidx() != null && getSidx().equalsIgnoreCase("beginning")) {
92                  eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.beginning", "asc");
93              } else if (getSidx() != null && getSidx().equalsIgnoreCase("ending")) {
94                  eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.ending", "asc");
95              } else if (getSidx() != null && getSidx().equalsIgnoreCase("deadline")) {
96                  eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.deadline", "asc");
97              } else if (getSidx() != null && getSidx().equalsIgnoreCase("reservation")) {
98                  eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.reservation", "asc");
99              } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
100                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.visible", "asc");
101             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
102                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.modified", "asc");
103             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
104                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.modifiedBy", "asc");
105             } else {
106 				eventList = this.eventDaoLocal.findAllActive(from, getRows());
107 			}
108 		} else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
109 		    LOGGER.info("Sortieren nach desc");
110             if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
111                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "dm.name", "desc");
112             } else if (getSidx() != null && getSidx().equalsIgnoreCase("location")) {
113                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "edm.name", "desc");
114             } else if (getSidx() != null && getSidx().equalsIgnoreCase("price")) {
115                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.price", "desc");
116             } else if (getSidx() != null && getSidx().equalsIgnoreCase("beginning")) {
117                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.beginning", "desc");
118             } else if (getSidx() != null && getSidx().equalsIgnoreCase("ending")) {
119                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.ending", "desc");
120             } else if (getSidx() != null && getSidx().equalsIgnoreCase("deadline")) {
121                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.deadline", "desc");
122             } else if (getSidx() != null && getSidx().equalsIgnoreCase("reservation")) {
123                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.reservation", "desc");
124             } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
125                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.visible", "desc");
126             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
127                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.modified", "desc");
128             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
129                 eventList = this.eventDaoLocal.findAllActive(from, getRows(), "e.modifiedBy", "desc");
130             } else {
131                 eventList = this.eventDaoLocal.findAllActive(from, getRows());
132             }
133 		}
134 
135 		setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
136 		setGridModel(eventList);
137 
138 		LOGGER.info("Rows:" + rows);
139 		LOGGER.info("Page:" + page);
140 		LOGGER.info("Total:" + total);
141 		LOGGER.info("Record:" + record);
142 		LOGGER.info("Sord:" + sord);
143 		LOGGER.info("Sidx:" + sidx);
144 		
145 		return execute();
146 	}
147 
148 	/**
149 	 * @return how many rows we want to have into the grid
150 	 */
151 	public Integer getRows() {
152 		return rows;
153 	}
154 
155 	/**
156 	 * @param rows
157 	 *            how many rows we want to have into the grid
158 	 */
159 	public void setRows(Integer rows) {
160 		this.rows = rows;
161 	}
162 
163 	/**
164 	 * @return current page of the query
165 	 */
166 	public Integer getPage() {
167 		return page;
168 	}
169 
170 	/**
171 	 * @param page
172 	 *            current page of the query
173 	 */
174 	public void setPage(Integer page) {
175 		this.page = page;
176 	}
177 
178 	/**
179 	 * @return total pages for the query
180 	 */
181 	public Integer getTotal() {
182 		return total;
183 	}
184 
185 	/**
186 	 * @param total
187 	 *            total pages for the query
188 	 */
189 	public void setTotal(Integer total) {
190 		this.total = total;
191 	}
192 
193 	/**
194 	 * @return total number of records for the query. e.g. select count(*) from
195 	 *         table
196 	 */
197 	public Integer getRecord() {
198 		return record;
199 	}
200 
201 	/**
202 	 * @param record
203 	 *            total number of records for the query. e.g. select count(*)
204 	 *            from table
205 	 */
206 	public void setRecord(Integer record) {
207 
208 		this.record = record;
209 
210 		if (this.record > 0 && this.rows > 0) {
211 			this.total = (int) Math.ceil((double) this.record
212 					/ (double) this.rows);
213 		} else {
214 			this.total = 0;
215 		}
216 	}
217 
218 	/**
219 	 * @return an collection that contains the actual data
220 	 */
221 	public List<Event> getGridModel() {
222 		return gridModel;
223 	}
224 
225 	/**
226 	 * @param gridModel
227 	 *            an collection that contains the actual data
228 	 */
229 	public void setGridModel(List<Event> gridModel) {
230 		this.gridModel = gridModel;
231 	}
232 
233 	/**
234 	 * @return sorting order
235 	 */
236 	public String getSord() {
237 		return sord;
238 	}
239 
240 	/**
241 	 * @param sord
242 	 *            sorting order
243 	 */
244 	public void setSord(String sord) {
245 		this.sord = sord;
246 	}
247 
248 	/**
249 	 * @return get index row - i.e. user click to sort.
250 	 */
251 	public String getSidx() {
252 		return sidx;
253 	}
254 
255 	/**
256 	 * @param sidx
257 	 *            get index row - i.e. user click to sort.
258 	 */
259 	public void setSidx(String sidx) {
260 		this.sidx = sidx;
261 	}
262 
263 }// Ende class