1
2
3
4 package de.tivsource.page.admin.actions.others.companion;
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.companion.CompanionDaoLocal;
19 import de.tivsource.page.entity.companion.Companion;
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 = -2954188570324511282L;
32
33
34
35
36 private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
37
38 @InjectEJB(name="CompanionDao")
39 private CompanionDaoLocal companionDaoLocal;
40
41 private List<Companion> gridModel;
42 private List<Companion> companionList;
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.companionDaoLocal.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 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.uuid", "asc");
89 } else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
90 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.name", "asc");
91 } else if (getSidx() != null && getSidx().equalsIgnoreCase("appendix")) {
92 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.appendix", "asc");
93 } else if (getSidx() != null && getSidx().equalsIgnoreCase("telephone")) {
94 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.contactDetails.telephone", "asc");
95 } else if (getSidx() != null && getSidx().equalsIgnoreCase("fax")) {
96 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.contactDetails.fax", "asc");
97 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
98 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.created", "asc");
99 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
100 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.visible", "asc");
101 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
102 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.modified", "asc");
103 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
104 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.modifiedBy", "asc");
105 } else {
106 companionList = this.companionDaoLocal.findAll(from, getRows());
107 }
108 } else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
109 LOGGER.info("Sortieren nach desc");
110 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
111 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.uuid", "desc");
112 } else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
113 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.name", "desc");
114 } else if (getSidx() != null && getSidx().equalsIgnoreCase("appendix")) {
115 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.appendix", "desc");
116 } else if (getSidx() != null && getSidx().equalsIgnoreCase("telephone")) {
117 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.contactDetails.telephone", "desc");
118 } else if (getSidx() != null && getSidx().equalsIgnoreCase("fax")) {
119 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.contactDetails.fax", "desc");
120 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
121 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.created", "desc");
122 } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
123 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.visible", "desc");
124 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
125 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.modified", "desc");
126 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
127 companionList = this.companionDaoLocal.findAll(from, getRows(), "c.modifiedBy", "desc");
128 } else {
129 companionList = this.companionDaoLocal.findAll(from, getRows());
130 }
131 }
132
133 setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
134 setGridModel(companionList);
135
136 LOGGER.info("Rows:" + rows);
137 LOGGER.info("Page:" + page);
138 LOGGER.info("Total:" + total);
139 LOGGER.info("Record:" + record);
140 LOGGER.info("Sord:" + sord);
141 LOGGER.info("Sidx:" + sidx);
142
143 return execute();
144 }
145
146
147
148
149 public Integer getRows() {
150 return rows;
151 }
152
153
154
155
156
157 public void setRows(Integer rows) {
158 this.rows = rows;
159 }
160
161
162
163
164 public Integer getPage() {
165 return page;
166 }
167
168
169
170
171
172 public void setPage(Integer page) {
173 this.page = page;
174 }
175
176
177
178
179 public Integer getTotal() {
180 return total;
181 }
182
183
184
185
186
187 public void setTotal(Integer total) {
188 this.total = total;
189 }
190
191
192
193
194
195 public Integer getRecord() {
196 return record;
197 }
198
199
200
201
202
203
204 public void setRecord(Integer record) {
205
206 this.record = record;
207
208 if (this.record > 0 && this.rows > 0) {
209 this.total = (int) Math.ceil((double) this.record
210 / (double) this.rows);
211 } else {
212 this.total = 0;
213 }
214 }
215
216
217
218
219 public List<Companion> getGridModel() {
220 return gridModel;
221 }
222
223
224
225
226
227 public void setGridModel(List<Companion> gridModel) {
228 this.gridModel = gridModel;
229 }
230
231
232
233
234 public String getSord() {
235 return sord;
236 }
237
238
239
240
241
242 public void setSord(String sord) {
243 this.sord = sord;
244 }
245
246
247
248
249 public String getSidx() {
250 return sidx;
251 }
252
253
254
255
256
257 public void setSidx(String sidx) {
258 this.sidx = sidx;
259 }
260
261 }