View Javadoc

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