View Javadoc

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