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