1
2
3
4 package de.tivsource.page.admin.actions.system.property;
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.property.PropertyDaoLocal;
19 import de.tivsource.page.entity.property.Property;
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="PropertyDao")
38 private PropertyDaoLocal propertyDaoLocal;
39
40 private List<Property> gridModel;
41 private List<Property> propertyList;
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
62 LOGGER.info("Page " + getPage() + " Rows " + getRows()
63 + " Sorting Order " + getSord() + " Index Row :" + getSidx());
64 LOGGER.info("Build new List");
65
66
67
68
69 setRecord(this.propertyDaoLocal.countAll());
70
71 int to = (getRows() * getPage());
72 int from = to - getRows();
73
74
75
76
77 if (to > getRecord()) {
78 to = getRecord();
79 }
80
81
82
83
84 if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
85 LOGGER.info("Sortieren nach asc");
86 if (getSidx() != null && getSidx().equalsIgnoreCase("key")) {
87 propertyList = this.propertyDaoLocal.findAll(from, getRows(), "p.key", "asc");
88 } else if (getSidx() != null && getSidx().equalsIgnoreCase("value")) {
89 propertyList = this.propertyDaoLocal.findAll(from, getRows(), "p.value", "asc");
90 } else {
91 propertyList = this.propertyDaoLocal.findAll(from, getRows());
92 }
93 } else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
94 LOGGER.info("Sortieren nach desc");
95 if (getSidx() != null && getSidx().equalsIgnoreCase("key")) {
96 propertyList = this.propertyDaoLocal.findAll(from, getRows(), "p.key", "desc");
97 } else if (getSidx() != null && getSidx().equalsIgnoreCase("value")) {
98 propertyList = this.propertyDaoLocal.findAll(from, getRows(), "p.value", "desc");
99 } else {
100 propertyList = this.propertyDaoLocal.findAll(from, getRows());
101 }
102 }
103
104 setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
105 setGridModel(propertyList);
106
107 LOGGER.info("Rows:" + rows);
108 LOGGER.info("Page:" + page);
109 LOGGER.info("Total:" + total);
110 LOGGER.info("Record:" + record);
111 LOGGER.info("Sord:" + sord);
112 LOGGER.info("Sidx:" + sidx);
113
114 return execute();
115 }
116
117
118
119
120 public Integer getRows() {
121 return rows;
122 }
123
124
125
126
127
128 public void setRows(Integer rows) {
129 this.rows = rows;
130 }
131
132
133
134
135 public Integer getPage() {
136 return page;
137 }
138
139
140
141
142
143 public void setPage(Integer page) {
144 this.page = page;
145 }
146
147
148
149
150 public Integer getTotal() {
151 return total;
152 }
153
154
155
156
157
158 public void setTotal(Integer total) {
159 this.total = total;
160 }
161
162
163
164
165
166 public Integer getRecord() {
167 return record;
168 }
169
170
171
172
173
174
175 public void setRecord(Integer record) {
176
177 this.record = record;
178
179 if (this.record > 0 && this.rows > 0) {
180 this.total = (int) Math.ceil((double) this.record
181 / (double) this.rows);
182 } else {
183 this.total = 0;
184 }
185 }
186
187
188
189
190 public List<Property> getGridModel() {
191 return gridModel;
192 }
193
194
195
196
197
198 public void setGridModel(List<Property> gridModel) {
199 this.gridModel = gridModel;
200 }
201
202
203
204
205 public String getSord() {
206 return sord;
207 }
208
209
210
211
212
213 public void setSord(String sord) {
214 this.sord = sord;
215 }
216
217
218
219
220 public String getSidx() {
221 return sidx;
222 }
223
224
225
226
227
228 public void setSidx(String sidx) {
229 this.sidx = sidx;
230 }
231
232 }