View Javadoc

1   /**
2    * 
3    */
4   package de.tivsource.page.admin.actions.others.vacancy;
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.vacancy.VacancyDaoLocal;
19  import de.tivsource.page.entity.vacancy.Vacancy;
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 = -1054161515297319240L;
32  
33      /**
34       * Statischer Logger der Klasse.
35       */
36      private static final Logger LOGGER = LogManager.getLogger(JsonAction.class);
37  	
38  	@InjectEJB(name="VacancyDao")
39      private VacancyDaoLocal vacancyDaoLocal;
40  
41  	private List<Vacancy> gridModel;
42  	private List<Vacancy> vacancyList;
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 = {
55          		        @Result(name = "success", type="json", params={"excludeProperties", "gridModel.*.events, gridModel.*.vacancies, gridModel.*.applications, gridModel.*.picture, gridModel.*.pictureItems"})
56          		}
57          )
58      })
59  	public String execute() {
60  		return SUCCESS;
61  	}
62  
63  	public String getJSON() {
64  
65  	    LOGGER.info("Page " + getPage() + " Rows " + getRows()
66  				+ " Sorting Order " + getSord() + " Index Row :" + getSidx());
67  	    LOGGER.info("Build new List");
68  
69  		/*
70  		 * Setze die Anzahl aller Objekte in der Datenbank.
71  		 */
72  		setRecord(this.vacancyDaoLocal.countAll());
73  
74  		int to = (getRows() * getPage());
75  		int from = to - getRows();
76  
77  		/*
78  		 * Setze die Maximalgrenze auf die Maximale Anzahl
79  		 */
80  		if (to > getRecord()) {
81  			to = getRecord();
82  		}
83  		
84  		/*
85  		 * Sortieren aufsteigen
86  		 */
87  		if (getSord() != null && getSord().equalsIgnoreCase("asc")) {
88  		    LOGGER.info("Sortieren nach asc");
89  			if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
90  				vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.uuid", "asc");
91  			} else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
92                  vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "dm.name", "asc");
93              } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
94                  vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.visible", "asc");
95              } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
96  				vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.created", "asc");
97  			} else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
98                  vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.modified", "asc");
99              } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
100 				vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.modifiedBy", "asc");
101 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("technical")) {
102                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.technical", "asc");
103             } else if (getSidx() != null && getSidx().equalsIgnoreCase("beginning")) {
104                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.beginning", "asc");
105             } else if (getSidx() != null && getSidx().equalsIgnoreCase("workingTime")) {
106                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.workingTime", "asc");
107             } else {
108 				vacancyList = this.vacancyDaoLocal.findAll(from, getRows());
109 			}
110 		} else if (getSord() != null && getSord().equalsIgnoreCase("desc")) {
111 		    LOGGER.info("Sortieren nach desc");
112 			if (getSidx() != null && getSidx().equalsIgnoreCase("uuid")) {
113 				vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.uuid", "desc");
114 			} else if (getSidx() != null && getSidx().equalsIgnoreCase("name")) {
115                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "dm.name", "desc");
116             } else if (getSidx() != null && getSidx().equalsIgnoreCase("visible")) {
117                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.visible", "desc");
118             } else if (getSidx() != null && getSidx().equalsIgnoreCase("created")) {
119                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.created", "desc");
120             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modified")) {
121                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.modified", "desc");
122             } else if (getSidx() != null && getSidx().equalsIgnoreCase("modifiedBy")) {
123                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.modifiedBy", "desc");
124             } else if (getSidx() != null && getSidx().equalsIgnoreCase("technical")) {
125                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.technical", "desc");
126             } else if (getSidx() != null && getSidx().equalsIgnoreCase("beginning")) {
127                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.beginning", "desc");
128             } else if (getSidx() != null && getSidx().equalsIgnoreCase("workingTime")) {
129                 vacancyList = this.vacancyDaoLocal.findAll(from, getRows(), "v.workingTime", "desc");
130             } else {
131 				vacancyList = this.vacancyDaoLocal.findAll(from, getRows());
132 			}
133 		}
134 
135 		setTotal((int) Math.ceil((double) getRecord() / (double) getRows()));
136 		setGridModel(vacancyList);
137 
138 		LOGGER.info("Rows:" + rows);
139 		LOGGER.info("Page:" + page);
140 		LOGGER.info("Total:" + total);
141 		LOGGER.info("Record:" + record);
142 		LOGGER.info("Sord:" + sord);
143 		LOGGER.info("Sidx:" + sidx);
144 		
145 		return execute();
146 	}
147 
148 	/**
149 	 * @return how many rows we want to have into the grid
150 	 */
151 	public Integer getRows() {
152 		return rows;
153 	}
154 
155 	/**
156 	 * @param rows
157 	 *            how many rows we want to have into the grid
158 	 */
159 	public void setRows(Integer rows) {
160 		this.rows = rows;
161 	}
162 
163 	/**
164 	 * @return current page of the query
165 	 */
166 	public Integer getPage() {
167 		return page;
168 	}
169 
170 	/**
171 	 * @param page
172 	 *            current page of the query
173 	 */
174 	public void setPage(Integer page) {
175 		this.page = page;
176 	}
177 
178 	/**
179 	 * @return total pages for the query
180 	 */
181 	public Integer getTotal() {
182 		return total;
183 	}
184 
185 	/**
186 	 * @param total
187 	 *            total pages for the query
188 	 */
189 	public void setTotal(Integer total) {
190 		this.total = total;
191 	}
192 
193 	/**
194 	 * @return total number of records for the query. e.g. select count(*) from
195 	 *         table
196 	 */
197 	public Integer getRecord() {
198 		return record;
199 	}
200 
201 	/**
202 	 * @param record
203 	 *            total number of records for the query. e.g. select count(*)
204 	 *            from table
205 	 */
206 	public void setRecord(Integer record) {
207 
208 		this.record = record;
209 
210 		if (this.record > 0 && this.rows > 0) {
211 			this.total = (int) Math.ceil((double) this.record
212 					/ (double) this.rows);
213 		} else {
214 			this.total = 0;
215 		}
216 	}
217 
218 	/**
219 	 * @return an collection that contains the actual data
220 	 */
221 	public List<Vacancy> getGridModel() {
222 		return gridModel;
223 	}
224 
225 	/**
226 	 * @param gridModel
227 	 *            an collection that contains the actual data
228 	 */
229 	public void setGridModel(List<Vacancy> gridModel) {
230 		this.gridModel = gridModel;
231 	}
232 
233 	/**
234 	 * @return sorting order
235 	 */
236 	public String getSord() {
237 		return sord;
238 	}
239 
240 	/**
241 	 * @param sord
242 	 *            sorting order
243 	 */
244 	public void setSord(String sord) {
245 		this.sord = sord;
246 	}
247 
248 	/**
249 	 * @return get index row - i.e. user click to sort.
250 	 */
251 	public String getSidx() {
252 		return sidx;
253 	}
254 
255 	/**
256 	 * @param sidx
257 	 *            get index row - i.e. user click to sort.
258 	 */
259 	public void setSidx(String sidx) {
260 		this.sidx = sidx;
261 	}
262 
263 }// Ende class