1
2
3
4 package de.tivsource.page.admin.actions.locations.request;
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.request.RequestDaoLocal;
19 import de.tivsource.page.entity.request.Request;
20
21
22
23
24
25 @ParentPackage(value = "administratorJson")
26 public class JsonAction extends ActionSupport {
27
28
29
30
31 private static final long serialVersionUID = -6847957890182885407L;
32
33
34
35
36 private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
37
38 @InjectEJB(name="RequestDao")
39 private RequestDaoLocal requestDaoLocal;
40
41 private List<Request> gridModel;
42 private List<Request> requestList;
43 private Integer rows = 0;
44 private Integer page = 1;
45 private Integer total = 0;
46 private Integer record = 0;
47 private String sord;
48 private String sidx;
49
50 @Override
51 @Actions({
52 @Action(
53 value = "table",
54 results = {
55 @Result(
56 name = "success",
57 type="json",
58 params={
59 "contentType", "application/json",
60 "excludeProperties",
61 "gridModel.*.uploadFile, "
62 + "gridModel.*.location, "
63 + "gridModel.*.proofOfAuthorityFileInputStream, "
64 + "gridModel.*.reason.requests, "
65 + "gridModel.*.namingItem"
66 }
67 )
68 }
69 )
70 })
71 public String execute() {
72 return SUCCESS;
73 }
74
75 public String getJSON() {
76
77 LOGGER.info("Page: " + getPage() + " Rows: " + getRows()
78 + " Sorting Order: " + getSord() + " Index Row: " + getSidx());
79 LOGGER.info("Build new List");
80
81
82
83
84 setRecord(this.requestDaoLocal.countAll());
85
86 int to = (getRows() * getPage());
87 int from = to - getRows();
88
89
90
91
92 if (to > getRecord()) {
93 to = getRecord();
94 }
95
96
97
98
99 if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
100 LOGGER.info("Sortieren nach asc");
101 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
102 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.uuid", "asc");
103 } else if (getSidx() != null && getSidx().equalsIgnoreCase("gender")) {
104 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.gender", "asc");
105 } else if (getSidx() != null && getSidx().equalsIgnoreCase("firstname")) {
106 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.firstname", "asc");
107 } else if (getSidx() != null && getSidx().equalsIgnoreCase("lastname")) {
108 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.lastname", "asc");
109 } else if (getSidx() != null && getSidx().equalsIgnoreCase("reason")) {
110 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.reason", "asc");
111 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmed")) {
112 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmed", "asc");
113 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmedAddress")) {
114 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmedAddress", "asc");
115 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmedDate")) {
116 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmedDate", "asc");
117 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmedBy")) {
118 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmedBy", "asc");
119 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
120 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.created", "asc");
121 } else if (getSidx() != null && getSidx().equalsIgnoreCase("createdAddress")) {
122 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.createdAddress", "asc");
123 } else {
124 requestList = this.requestDaoLocal.findAll(from, getRows());
125 }
126 } else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
127 LOGGER.info("Sortieren nach desc");
128 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
129 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.uuid", "desc");
130 } else if (getSidx() != null && getSidx().equalsIgnoreCase("gender")) {
131 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.gender", "desc");
132 } else if (getSidx() != null && getSidx().equalsIgnoreCase("firstname")) {
133 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.firstname", "desc");
134 } else if (getSidx() != null && getSidx().equalsIgnoreCase("lastname")) {
135 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.lastname", "desc");
136 } else if (getSidx() != null && getSidx().equalsIgnoreCase("reason")) {
137 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.reason", "desc");
138 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmed")) {
139 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmed", "desc");
140 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmedAddress")) {
141 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmedAddress", "desc");
142 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmedDate")) {
143 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmedDate", "desc");
144 } else if (getSidx() != null && getSidx().equalsIgnoreCase("confirmedBy")) {
145 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.confirmedBy", "desc");
146 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
147 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.created", "desc");
148 } else if (getSidx() != null && getSidx().equalsIgnoreCase("createdAddress")) {
149 requestList = this.requestDaoLocal.findAll(from, getRows(), "r.createdAddress", "desc");
150 } else {
151 requestList = this.requestDaoLocal.findAll(from, getRows());
152 }
153 }
154
155 setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
156 setGridModel(requestList);
157
158 LOGGER.info("Rows:" + rows);
159 LOGGER.info("Page:" + page);
160 LOGGER.info("Total:" + total);
161 LOGGER.info("Record:" + record);
162 LOGGER.info("Sord:" + sord);
163 LOGGER.info("Sidx:" + sidx);
164
165 return execute();
166 }
167
168
169
170
171 public Integer getRows() {
172 return rows;
173 }
174
175
176
177
178
179 public void setRows(Integer rows) {
180 this.rows = rows;
181 }
182
183
184
185
186 public Integer getPage() {
187 return page;
188 }
189
190
191
192
193
194 public void setPage(Integer page) {
195 this.page = page;
196 }
197
198
199
200
201 public Integer getTotal() {
202 return total;
203 }
204
205
206
207
208
209 public void setTotal(Integer total) {
210 this.total = total;
211 }
212
213
214
215
216
217 public Integer getRecord() {
218 return record;
219 }
220
221
222
223
224
225
226 public void setRecord(Integer record) {
227
228 this.record = record;
229
230 if (this.record > 0 && this.rows > 0) {
231 this.total = (int) Math.ceil((double) this.record
232 / (double) this.rows);
233 } else {
234 this.total = 0;
235 }
236 }
237
238
239
240
241 public List<Request> getGridModel() {
242 return gridModel;
243 }
244
245
246
247
248
249 public void setGridModel(List<Request> gridModel) {
250 this.gridModel = gridModel;
251 }
252
253
254
255
256 public String getSord() {
257 return sord;
258 }
259
260
261
262
263
264 public void setSord(String sord) {
265 this.sord = sord;
266 }
267
268
269
270
271 public String getSidx() {
272 return sidx;
273 }
274
275
276
277
278
279 public void setSidx(String sidx) {
280 this.sidx = sidx;
281 }
282
283 }