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