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.Actions;
12 import org.apache.struts2.convention.annotation.ParentPackage;
13 import org.apache.struts2.convention.annotation.Result;
14
15 import com.opensymphony.xwork2.ActionSupport;
16
17 import de.tivsource.ejb3plugin.InjectEJB;
18 import de.tivsource.page.dao.event.EventDaoLocal;
19 import de.tivsource.page.dao.reservation.ReservationDaoLocal;
20 import de.tivsource.page.entity.event.Event;
21 import de.tivsource.page.entity.reservation.Reservation;
22
23
24
25
26
27 @ParentPackage(value = "administratorJson")
28 public class JsonAction extends ActionSupport {
29
30
31
32
33 private static final long serialVersionUID = 678640721517515811L;
34
35
36
37
38 private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
39
40 @InjectEJB(name="ReservationDao")
41 private ReservationDaoLocal reservationDaoLocal;
42
43 @InjectEJB(name="EventDao")
44 private EventDaoLocal eventDaoLocal;
45
46 private Event event;
47
48 private String uncheckEvent;
49
50 private List<Reservation> gridModel;
51 private List<Reservation> pageList;
52 private Integer rows = 0;
53 private Integer page = 1;
54 private Integer total = 0;
55 private Integer record = 0;
56 private String sord;
57 private String sidx;
58
59 @Override
60 @Actions({
61 @Action(
62 value = "table",
63 results = {
64 @Result(name = "success", type="json", params={"excludeProperties", "gridModel.*.event"})
65 }
66 )
67 })
68 public String execute() {
69 this.loadPageParameter();
70 return SUCCESS;
71 }
72
73 public String getJSON() {
74
75 LOGGER.info("Page " + getPage() + " Rows " + getRows()
76 + " Sorting Order " + getSord() + " Index Row :" + getSidx());
77 LOGGER.info("Build new List");
78
79
80
81
82 setRecord(this.reservationDaoLocal.countAll(event));
83
84 int to = (getRows() * getPage());
85 int from = to - getRows();
86
87
88
89
90 if (to > getRecord()) {
91 to = getRecord();
92 }
93
94
95
96
97 if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
98 LOGGER.info("Sortieren nach asc");
99 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
100 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.uuid", "asc");
101 } else if (getSidx() != null && getSidx().equalsIgnoreCase("technical")) {
102 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.technical", "asc");
103 } else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigation")) {
104 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.topNavigation", "asc");
105 } else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigationOrder")) {
106 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.topNavigationOrder", "asc");
107 } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigation")) {
108 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.navigation", "asc");
109 } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigationOrder")) {
110 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.navigationOrder", "asc");
111 } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigation")) {
112 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.bottomNavigation", "asc");
113 } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigationOrder")) {
114 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.bottomNavigationOrder", "asc");
115 } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigation")) {
116 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.responsiveNavigation", "asc");
117 } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigationOrder")) {
118 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.responsiveNavigationOrder", "asc");
119 }else if (getSidx() != null && getSidx().equalsIgnoreCase("special")) {
120 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.special", "asc");
121 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
122 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.visible", "asc");
123 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
124 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.modified", "asc");
125 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
126 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.created", "asc");
127 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
128 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.visible", "asc");
129 } else {
130 pageList = this.reservationDaoLocal.findAll(event, from, getRows());
131 }
132 } else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
133 LOGGER.info("Sortieren nach desc");
134 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
135 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.uuid", "desc");
136 } else if (getSidx() != null && getSidx().equalsIgnoreCase("technical")) {
137 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.technical", "desc");
138 } else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigation")) {
139 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.topNavigation", "desc");
140 } else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigationOrder")) {
141 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.topNavigationOrder", "desc");
142 } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigation")) {
143 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.navigation", "desc");
144 } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigationOrder")) {
145 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.navigationOrder", "desc");
146 } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigation")) {
147 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.bottomNavigation", "desc");
148 } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigationOrder")) {
149 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.bottomNavigationOrder", "desc");
150 } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigation")) {
151 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.responsiveNavigation", "desc");
152 } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigationOrder")) {
153 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.responsiveNavigationOrder", "desc");
154 } else if (getSidx() != null && getSidx().equalsIgnoreCase("special")) {
155 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.special", "desc");
156 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
157 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.visible", "desc");
158 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
159 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.modified", "desc");
160 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
161 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.created", "desc");
162 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
163 pageList = this.reservationDaoLocal.findAll(event, from, getRows(), "p.visible", "desc");
164 } else {
165 pageList = this.reservationDaoLocal.findAll(event, from, getRows());
166 }
167 }
168
169 setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
170 setGridModel(pageList);
171
172 LOGGER.info("Rows:" + rows);
173 LOGGER.info("Page:" + page);
174 LOGGER.info("Total:" + total);
175 LOGGER.info("Record:" + record);
176 LOGGER.info("Sord:" + sord);
177 LOGGER.info("Sidx:" + sidx);
178
179 return execute();
180 }
181
182 public void setEvent(String uncheckEvent) {
183 this.uncheckEvent = uncheckEvent;
184 }
185
186
187
188
189 public Integer getRows() {
190 return rows;
191 }
192
193
194
195
196
197 public void setRows(Integer rows) {
198 this.rows = rows;
199 }
200
201
202
203
204 public Integer getPage() {
205 return page;
206 }
207
208
209
210
211
212 public void setPage(Integer page) {
213 this.page = page;
214 }
215
216
217
218
219 public Integer getTotal() {
220 return total;
221 }
222
223
224
225
226
227 public void setTotal(Integer total) {
228 this.total = total;
229 }
230
231
232
233
234
235 public Integer getRecord() {
236 return record;
237 }
238
239
240
241
242
243
244 public void setRecord(Integer record) {
245
246 this.record = record;
247
248 if (this.record > 0 && this.rows > 0) {
249 this.total = (int) Math.ceil((double) this.record
250 / (double) this.rows);
251 } else {
252 this.total = 0;
253 }
254 }
255
256
257
258
259 public List<Reservation> getGridModel() {
260 return gridModel;
261 }
262
263
264
265
266
267 public void setGridModel(List<Reservation> gridModel) {
268 this.gridModel = gridModel;
269 }
270
271
272
273
274 public String getSord() {
275 return sord;
276 }
277
278
279
280
281
282 public void setSord(String sord) {
283 this.sord = sord;
284 }
285
286
287
288
289 public String getSidx() {
290 return sidx;
291 }
292
293
294
295
296
297 public void setSidx(String sidx) {
298 this.sidx = sidx;
299 }
300
301 private void loadPageParameter() {
302 LOGGER.info("loadPageParameter() aufgerufen.");
303 if( uncheckEvent != null && uncheckEvent != "" && uncheckEvent.length() > 0) {
304 LOGGER.info("UncheckEvent: " + uncheckEvent);
305 event = eventDaoLocal.findByUuid(uncheckEvent);
306 }
307 }
308
309 }