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