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