View Javadoc

1   /**
2    * 
3    */
4   package de.tivsource.page.admin.actions.others.linkentry;
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.menuentry.LinkEntry;
19  import de.tivsource.page.dao.linkentry.LinkEntryDaoLocal;
20  
21  /**
22   * @author Marc Michele
23   * 
24   */
25  @ParentPackage(value = "administratorJson")
26  public class JsonAction extends ActionSupport {
27  
28      /**
29       * Serial Version UID.
30       */
31  	private static final long serialVersionUID = 1211255295822079053L;
32  
33  	/**
34       * Statischer Logger der Klasse.
35       */
36      private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
37  	
38  	@InjectEJB(name="LinkEntryDao")
39      private LinkEntryDaoLocal linkEntryDaoLocal;
40  
41  	private List<LinkEntry> gridModel;
42  	private List<LinkEntry> linkEntryList;
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.*.contentItem"}) }
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  		 * Setze die Anzahl aller Objekte in der Datenbank.
69  		 */
70  		setRecord(this.linkEntryDaoLocal.countAll());
71  
72  		int to = (getRows() * getPage());
73  		int from = to - getRows();
74  
75  		/*
76  		 * Setze die Maximalgrenze auf die Maximale Anzahl
77  		 */
78  		if (to > getRecord()) {
79  			to = getRecord();
80  		}
81  		
82  		/*
83  		 * Sortieren aufsteigen
84  		 */
85  		if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
86  		    LOGGER.info("Sortieren nach asc");
87  			if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
88  				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.uuid", "asc");
89  			} else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
90                  linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "dm.name", "asc");
91              } else if (getSidx() != null && getSidx().equalsIgnoreCase("technical")) {
92  				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.technical", "asc");
93  			} else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigation")) {
94                  linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.topNavigation", "asc");
95              } else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigationOrder")) {
96                  linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.topNavigationOrder", "asc");
97              } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigation")) {
98                  linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.navigation", "asc");
99              } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigationOrder")) {
100                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.navigationOrder", "asc");
101             } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigation")) {
102                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.bottomNavigation", "asc");
103             } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigationOrder")) {
104                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.bottomNavigationOrder", "asc");
105             } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigation")) {
106                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.responsiveNavigation", "asc");
107             } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigationOrder")) {
108                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.responsiveNavigationOrder", "asc");
109             }else if (getSidx() != null && getSidx().equalsIgnoreCase("special")) {
110                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.special", "asc");
111             } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
112                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.visible", "asc");
113             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
114 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.modified", "asc");
115 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
116 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.created", "asc");
117 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
118 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.visible", "asc");
119 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
120                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.modified", "asc");
121             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
122                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.modifiedBy", "asc");
123             } else {
124 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows());
125 			}
126 		} else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
127 		    LOGGER.info("Sortieren nach desc");
128 			if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
129 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.uuid", "desc");
130 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
131                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "dm.name", "desc");
132             } else if (getSidx() != null && getSidx().equalsIgnoreCase("technical")) {
133 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.technical", "desc");
134 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigation")) {
135                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.topNavigation", "desc");
136             } else if (getSidx() != null && getSidx().equalsIgnoreCase("topNavigationOrder")) {
137                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.topNavigationOrder", "desc");
138             } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigation")) {
139                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.navigation", "desc");
140             } else if (getSidx() != null && getSidx().equalsIgnoreCase("navigationOrder")) {
141                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.navigationOrder", "desc");
142             } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigation")) {
143                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.bottomNavigation", "desc");
144             } else if (getSidx() != null && getSidx().equalsIgnoreCase("bottomNavigationOrder")) {
145                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.bottomNavigationOrder", "desc");
146             } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigation")) {
147                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.responsiveNavigation", "desc");
148             } else if (getSidx() != null && getSidx().equalsIgnoreCase("responsiveNavigationOrder")) {
149                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.responsiveNavigationOrder", "desc");
150             } else if (getSidx() != null && getSidx().equalsIgnoreCase("special")) {
151                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.special", "desc");
152             } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
153                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.visible", "desc");
154             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
155 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.modified", "desc");
156 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
157 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.created", "desc");
158 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
159 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.visible", "desc");
160 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
161                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.modified", "desc");
162             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
163                 linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows(), "le.modifiedBy", "desc");
164             } else {
165 				linkEntryList = this.linkEntryDaoLocal.findAll(from, getRows());
166 			}
167 		}
168 
169 		setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
170 		setGridModel(linkEntryList);
171 
172 		LOGGER.info("Rows:" + rows);
173 		LOGGER.info("Page:" + page);
174 		LOGGER.info("Total:" + total);
175 		LOGGER.info("Record:" + record);
176 		LOGGER.info("Sord:" + sord);
177 		LOGGER.info("Sidx:" + sidx);
178 		
179 		return execute();
180 	}
181 
182 	/**
183 	 * @return how many rows we want to have into the grid
184 	 */
185 	public Integer getRows() {
186 		return rows;
187 	}
188 
189 	/**
190 	 * @param rows
191 	 *            how many rows we want to have into the grid
192 	 */
193 	public void setRows(Integer rows) {
194 		this.rows = rows;
195 	}
196 
197 	/**
198 	 * @return current page of the query
199 	 */
200 	public Integer getPage() {
201 		return page;
202 	}
203 
204 	/**
205 	 * @param page
206 	 *            current page of the query
207 	 */
208 	public void setPage(Integer page) {
209 		this.page = page;
210 	}
211 
212 	/**
213 	 * @return total pages for the query
214 	 */
215 	public Integer getTotal() {
216 		return total;
217 	}
218 
219 	/**
220 	 * @param total
221 	 *            total pages for the query
222 	 */
223 	public void setTotal(Integer total) {
224 		this.total = total;
225 	}
226 
227 	/**
228 	 * @return total number of records for the query. e.g. select count(*) from
229 	 *         table
230 	 */
231 	public Integer getRecord() {
232 		return record;
233 	}
234 
235 	/**
236 	 * @param record
237 	 *            total number of records for the query. e.g. select count(*)
238 	 *            from table
239 	 */
240 	public void setRecord(Integer record) {
241 
242 		this.record = record;
243 
244 		if (this.record > 0 && this.rows > 0) {
245 			this.total = (int) Math.ceil((double) this.record
246 					/ (double) this.rows);
247 		} else {
248 			this.total = 0;
249 		}
250 	}
251 
252 	/**
253 	 * @return an collection that contains the actual data
254 	 */
255 	public List<LinkEntry> getGridModel() {
256 		return gridModel;
257 	}
258 
259 	/**
260 	 * @param gridModel
261 	 *            an collection that contains the actual data
262 	 */
263 	public void setGridModel(List<LinkEntry> gridModel) {
264 		this.gridModel = gridModel;
265 	}
266 
267 	/**
268 	 * @return sorting order
269 	 */
270 	public String getSord() {
271 		return sord;
272 	}
273 
274 	/**
275 	 * @param sord
276 	 *            sorting order
277 	 */
278 	public void setSord(String sord) {
279 		this.sord = sord;
280 	}
281 
282 	/**
283 	 * @return get index row - i.e. user click to sort.
284 	 */
285 	public String getSidx() {
286 		return sidx;
287 	}
288 
289 	/**
290 	 * @param sidx
291 	 *            get index row - i.e. user click to sort.
292 	 */
293 	public void setSidx(String sidx) {
294 		this.sidx = sidx;
295 	}
296 
297 }// Ende class