1
2
3
4 package de.tivsource.page.admin.actions.others.appointment;
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.appointment.AppointmentDaoLocal;
19 import de.tivsource.page.entity.appointment.Appointment;
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 = 8354239037998933809L;
32
33
34
35
36 private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
37
38 @InjectEJB(name="AppointmentDao")
39 private AppointmentDaoLocal appointmentDaoLocal;
40
41 private List<Appointment> gridModel;
42 private List<Appointment> appointmentList;
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 = { @Result(name = "success", type="json", params={"excludeProperties", "gridModel.*.companions, gridModel.*.gallery, gridModel.*.pictureItems"}) }
55 )
56 })
57 public String execute() {
58 return SUCCESS;
59 }
60
61 public String getJSON() {
62
63 LOGGER.info("Page " + getPage() + " Rows " + getRows()
64 + " Sorting Order " + getSord() + " Index Row :" + getSidx());
65 LOGGER.info("Build new List");
66
67
68
69
70 setRecord(this.appointmentDaoLocal.countAll());
71
72 int to = (getRows() * getPage());
73 int from = to - getRows();
74
75
76
77
78 if (to > getRecord()) {
79 to = getRecord();
80 }
81
82
83
84
85 if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
86 LOGGER.info("Sortieren nach asc");
87 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
88 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.uuid", "asc");
89 } else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
90 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "dm.name", "asc");
91 } else if (getSidx() != null && getSidx().equalsIgnoreCase("pictureOnPage")) {
92 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.pictureOnPage", "asc");
93 } else if (getSidx() != null && getSidx().equalsIgnoreCase("pointInTime")) {
94 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.pointInTime", "asc");
95 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
96 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.created", "asc");
97 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
98 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.visible", "asc");
99 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
100 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.modified", "asc");
101 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
102 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.modifiedBy", "asc");
103 } else {
104 appointmentList = this.appointmentDaoLocal.findAll(from, getRows());
105 }
106 } else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
107 LOGGER.info("Sortieren nach desc");
108 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
109 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.uuid", "desc");
110 } else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
111 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "dm.name", "desc");
112 } else if (getSidx() != null && getSidx().equalsIgnoreCase("pictureOnPage")) {
113 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.pictureOnPage", "desc");
114 } else if (getSidx() != null && getSidx().equalsIgnoreCase("pointInTime")) {
115 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.pointInTime", "desc");
116 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
117 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.created", "desc");
118 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
119 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.visible", "desc");
120 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
121 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.modified", "desc");
122 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
123 appointmentList = this.appointmentDaoLocal.findAll(from, getRows(), "ap.modifiedBy", "desc");
124 } else {
125 appointmentList = this.appointmentDaoLocal.findAll(from, getRows());
126 }
127 }
128
129 setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
130 setGridModel(appointmentList);
131
132 LOGGER.info("Rows:" + rows);
133 LOGGER.info("Page:" + page);
134 LOGGER.info("Total:" + total);
135 LOGGER.info("Record:" + record);
136 LOGGER.info("Sord:" + sord);
137 LOGGER.info("Sidx:" + sidx);
138
139 return execute();
140 }
141
142
143
144
145 public Integer getRows() {
146 return rows;
147 }
148
149
150
151
152
153 public void setRows(Integer rows) {
154 this.rows = rows;
155 }
156
157
158
159
160 public Integer getPage() {
161 return page;
162 }
163
164
165
166
167
168 public void setPage(Integer page) {
169 this.page = page;
170 }
171
172
173
174
175 public Integer getTotal() {
176 return total;
177 }
178
179
180
181
182
183 public void setTotal(Integer total) {
184 this.total = total;
185 }
186
187
188
189
190
191 public Integer getRecord() {
192 return record;
193 }
194
195
196
197
198
199
200 public void setRecord(Integer record) {
201
202 this.record = record;
203
204 if (this.record > 0 && this.rows > 0) {
205 this.total = (int) Math.ceil((double) this.record
206 / (double) this.rows);
207 } else {
208 this.total = 0;
209 }
210 }
211
212
213
214
215 public List<Appointment> getGridModel() {
216 return gridModel;
217 }
218
219
220
221
222
223 public void setGridModel(List<Appointment> gridModel) {
224 this.gridModel = gridModel;
225 }
226
227
228
229
230 public String getSord() {
231 return sord;
232 }
233
234
235
236
237
238 public void setSord(String sord) {
239 this.sord = sord;
240 }
241
242
243
244
245 public String getSidx() {
246 return sidx;
247 }
248
249
250
251
252
253 public void setSidx(String sidx) {
254 this.sidx = sidx;
255 }
256
257 }