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