1
2
3
4 package de.tivsource.page.admin.actions.system.captcha;
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.common.captcha.Captcha;
19 import de.tivsource.page.dao.captcha.CaptchaDaoLocal;
20
21
22
23
24 @ParentPackage(value = "administratorJson")
25 public class JsonAction extends ActionSupport {
26
27
28
29
30 private static final long serialVersionUID = -3163434204065331938L;
31
32
33
34
35 private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
36
37 @InjectEJB(name="CaptchaDao")
38 private CaptchaDaoLocal captchaDaoLocal;
39
40 private List<Captcha> gridModel;
41 private List<Captcha> captchaList;
42 private Integer rows = 0;
43 private Integer page = 1;
44 private Integer total = 0;
45 private Integer record = 0;
46 private String sord;
47 private String sidx;
48
49 @Override
50 @Actions({
51 @Action(
52 value = "table",
53 results = { @Result(name = "success", type="json", params={"excludeProperties", "gridModel.*.users"}) }
54 )
55 })
56 public String execute() {
57 return SUCCESS;
58 }
59
60 public String getJSON() {
61 LOGGER.info("Page " + getPage() +
62 " Rows " + getRows() +
63 " Sorting Order " + getSord() +
64 " Index Row :" + getSidx());
65 LOGGER.info("Build new List");
66
67
68
69
70 setRecord(this.captchaDaoLocal.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 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.uuid", "asc");
89 } else if (getSidx() != null && getSidx().equalsIgnoreCase("content")) {
90 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.content", "asc");
91 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
92 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.created", "asc");
93 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
94 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.modified", "asc");
95 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
96 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.modifiedBy", "asc");
97 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedAddress")) {
98 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.modifiedAddress", "asc");
99 } else {
100 captchaList = this.captchaDaoLocal.findAll(from, getRows());
101 }
102 } else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
103 LOGGER.info("Sortieren nach desc");
104 if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
105 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.uuid", "desc");
106 } else if (getSidx() != null && getSidx().equalsIgnoreCase("content")) {
107 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.content", "desc");
108 } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
109 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.created", "desc");
110 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
111 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.modified", "desc");
112 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
113 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.modifiedBy", "desc");
114 } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedAddress")) {
115 captchaList = this.captchaDaoLocal.findAll(from, getRows(), "c.modifiedAddress", "desc");
116 } else {
117 captchaList = this.captchaDaoLocal.findAll(from, getRows());
118 }
119 }
120
121 setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
122 setGridModel(captchaList);
123
124 LOGGER.info("Rows:" + rows);
125 LOGGER.info("Page:" + page);
126 LOGGER.info("Total:" + total);
127 LOGGER.info("Record:" + record);
128 LOGGER.info("Sord:" + sord);
129 LOGGER.info("Sidx:" + sidx);
130
131 return execute();
132 }
133
134
135
136
137 public Integer getRows() {
138 return rows;
139 }
140
141
142
143
144 public void setRows(Integer rows) {
145 this.rows = rows;
146 }
147
148
149
150
151 public Integer getPage() {
152 return page;
153 }
154
155
156
157
158 public void setPage(Integer page) {
159 this.page = page;
160 }
161
162
163
164
165 public Integer getTotal() {
166 return total;
167 }
168
169
170
171
172 public void setTotal(Integer total) {
173 this.total = total;
174 }
175
176
177
178
179 public Integer getRecord() {
180 return record;
181 }
182
183
184
185
186 public void setRecord(Integer record) {
187 this.record = record;
188 if (this.record > 0 && this.rows > 0) {
189 this.total = (int) Math.ceil((double) this.record / (double) this.rows);
190 } else {
191 this.total = 0;
192 }
193 }
194
195
196
197
198 public List<Captcha> getGridModel() {
199 return gridModel;
200 }
201
202
203
204
205 public void setGridModel(List<Captcha> gridModel) {
206 this.gridModel = gridModel;
207 }
208
209
210
211
212 public String getSord() {
213 return sord;
214 }
215
216
217
218
219 public void setSord(String sord) {
220 this.sord = sord;
221 }
222
223
224
225
226 public String getSidx() {
227 return sidx;
228 }
229
230
231
232
233 public void setSidx(String sidx) {
234 this.sidx = sidx;
235 }
236
237 }