View Javadoc

1   /***
2   Copyright (C) 2005 The Java Community
3   
4   This program is free software; you can redistribute it and/or modify  it under
5   the terms of the GNU General Public License as published by  the Free Software
6   Foundation; either version 2 of the License, or  (at your option) any later
7   version.
8   
9   This program is distributed in the hope that it will be useful,  but WITHOUT
10  ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License  along with
14  this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
15  Place, Suite 330, Boston, MA 02111-1307 USA.
16  
17  */
18  package org.bejug.javacareers.common.service;
19  
20  import java.util.List;
21  
22  import org.bejug.javacareers.common.constants.JavacareersConstants;
23  import org.bejug.javacareers.common.search.SearchCriteria;
24  import org.bejug.javacareers.common.search.SearchCriteriaFactory;
25  import org.bejug.javacareers.common.search.SearchCriteriaService;
26  import org.bejug.javacareers.jobs.dao.ItemDao;
27  import org.bejug.javacareers.jobs.dao.OfferDao;
28  import org.bejug.javacareers.jobs.model.AcademicEducationOffer;
29  import org.bejug.javacareers.jobs.model.CommercialEducationOffer;
30  import org.bejug.javacareers.jobs.model.ConsultingServiceOffer;
31  import org.bejug.javacareers.jobs.model.EducationServiceOffer;
32  import org.bejug.javacareers.jobs.model.Interview;
33  import org.bejug.javacareers.jobs.model.Item;
34  import org.bejug.javacareers.jobs.model.JobOffer;
35  import org.bejug.javacareers.jobs.model.Resume;
36  
37  /***
38   * Concrete implementation of the ItemService.
39   * @author Bart Meyers (last modified by $Author: shally $)
40   * @version $Revision: 1.19 $ $Date: 2005/12/20 15:36:45 $
41   */
42  public class ItemServiceImpl implements ItemService {
43  
44  	/***
45  	 * The LOG Log.
46  	 */
47  	//private static final Log LOG = LogFactory.getLog(ItemServiceImpl.class);
48  	
49  	/***
50  	 * the searchCriteriaService we need.
51  	 */
52  	private SearchCriteriaService searchCriteriaService = null;
53  	
54  	
55  	/***
56  	 * the searchCriteriaFactory we need.
57  	 */
58  	private SearchCriteriaFactory searchCriteriaFactory = null;
59  	
60  	/***
61  	 * the itemDao we need.
62  	 */
63  	private ItemDao itemDao = null;
64  
65  
66      /***
67       * The commercialEducationOfferDao OfferDao.
68       */
69      private OfferDao commercialEducationOfferDao;
70  
71  	/***
72  	 * 
73  	 * @param service is the service
74  	 * @param factory is the factory
75  	 * @param itemDao is the itemDao
76  	 * @param commercialEducationOfferDao is the commercialEducationOfferDao
77  	 */
78  	public ItemServiceImpl(SearchCriteriaService service,
79  			SearchCriteriaFactory factory,
80  			ItemDao itemDao, OfferDao commercialEducationOfferDao) {
81  		this.searchCriteriaFactory = factory;
82  		this.searchCriteriaService = service;
83  		this.itemDao = itemDao;
84          this.commercialEducationOfferDao = commercialEducationOfferDao;
85  	}
86  
87  	/***
88  	 * {@inheritDoc}
89  	 */
90  	public List getItems() {
91  		SearchCriteria searchCriteria = 
92  			searchCriteriaFactory.createSearchCriteria(Item.class);
93  		searchCriteria.addDescendingOrder("publicationDate");
94  		searchCriteria.addEqualsCriterium("adminApproved", Boolean.TRUE);
95  		return searchCriteriaService.executeQuery(searchCriteria);	
96  	}
97  
98      /***
99       * {@inheritDoc}
100      */
101     public Item getItem(Integer id) {
102         return this.findById(id);  
103     }
104 
105     /***
106 	 * {@inheritDoc}
107 	 */
108 	public List getItems(int itemType) {
109 		SearchCriteria searchCriteria = buildSearchCriteria(itemType);
110 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.TRUE);
111 		return searchCriteriaService.executeQuery(searchCriteria);
112 	}
113 
114    /***
115     * {@inheritDoc}
116 	*/
117     public List getItems(Class clazz) {
118       SearchCriteria searchCriteria =
119 			searchCriteriaFactory.createSearchCriteria(clazz);
120 		searchCriteria.addDescendingOrder("publicationDate");
121 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.TRUE);
122 		return searchCriteriaService.executeQuery(searchCriteria);
123     }
124 
125 	/***
126 	 * Convenient method to build a searchCriteria.
127      * Todo: introduce the enum constants (See JavacareersConstants)
128      *
129 	 * @param itemType an int indicating the type of items we want
130 	 * @return the wanted SearchCriteria.
131 	 */
132 	private SearchCriteria buildSearchCriteria(int itemType) {
133 		SearchCriteria searchCriteria = null;
134 		
135 		switch (itemType) {
136 			case JavacareersConstants.JOBOFFER:
137 				searchCriteria = 
138 					searchCriteriaFactory.createSearchCriteria(JobOffer.class);
139 				break;
140 			case JavacareersConstants.ACADEMIC_EDUCATION_OFFER:
141 				searchCriteria = 
142 					searchCriteriaFactory.createSearchCriteria(AcademicEducationOffer.class);
143 				break;
144 			case JavacareersConstants.COMMERCIAL_EDUCATION_OFFER:
145 				searchCriteria = 
146 					searchCriteriaFactory.createSearchCriteria(CommercialEducationOffer.class);
147 				break;
148 			case JavacareersConstants.CONSULTING_SERVICE_OFFER:
149 				searchCriteria = 
150 					searchCriteriaFactory.createSearchCriteria(ConsultingServiceOffer.class);
151 				break;
152 			case JavacareersConstants.EDUCATION_SERVICE_OFFER:
153 				searchCriteria = 
154 					searchCriteriaFactory.createSearchCriteria(EducationServiceOffer.class);
155 				break;
156 			case JavacareersConstants.RESUME:
157 				searchCriteria = 
158 					searchCriteriaFactory.createSearchCriteria(Resume.class);
159 				break;
160             case JavacareersConstants.INTERVIEW:
161 				searchCriteria =
162 					searchCriteriaFactory.createSearchCriteria(Interview.class);
163 				break;
164 			default:
165 				searchCriteria =
166 					searchCriteriaFactory.createSearchCriteria(Item.class);
167 				break;
168 		}
169 
170 		searchCriteria.addDescendingOrder("publicationDate");
171 
172 		return searchCriteria;
173 	}
174 
175 	/***
176 	 * {@inheritDoc}
177 	 */
178 	public int getItemCount() {
179 		SearchCriteria searchCriteria = 
180 			searchCriteriaFactory.createSearchCriteria(Item.class);
181 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.TRUE);
182 		return searchCriteriaService.executeCountQuery(searchCriteria);
183 	}
184 
185 	/***
186 	 * {@inheritDoc}
187 	 */
188 	public int getItemCount(int itemType) {
189 		SearchCriteria searchCriteria = buildSearchCriteria(itemType);
190 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.TRUE);
191 		return	searchCriteriaService.executeCountQuery(searchCriteria);
192 	}
193 
194 	/***
195 	 * {@inheritDoc}
196 	 */
197 	public int getUnApprovedItemCount(int itemType){
198 		SearchCriteria searchCriteria = buildSearchCriteria(itemType);
199 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.FALSE);
200 		return	searchCriteriaService.executeCountQuery(searchCriteria);
201 	}
202 	
203 	/***
204 	 * {@inheritDoc}
205 	 */
206 	public int getUnApprovedItemCount(){
207 		SearchCriteria searchCriteria = 
208 			searchCriteriaFactory.createSearchCriteria(Item.class);
209 			searchCriteria.addEqualsCriterium("adminApproved", Boolean.FALSE);
210 		return searchCriteriaService.executeCountQuery(searchCriteria);
211 	}
212 	
213 	/***
214 	 * {@inheritDoc}
215 	 */
216 	public Item findById(Integer id) {
217 		return itemDao.getItem(id);
218 	}
219 
220     /***
221 	 * {@inheritDoc}
222 	 */
223 	public void delete(Item item) {
224 		itemDao.deleteItem(item);
225 	}
226 
227 	/***
228 	 * {@inheritDoc}
229 	 */
230 	public void delete(Integer id) {
231 		itemDao.deleteItem(id);
232 	}
233 	
234 	/***
235 	 * {@inheritDoc}
236 	 */
237 	public void store(Item item) {
238         itemDao.storeItem(item);
239 	}
240 
241     /***
242      *
243      * @param item is the item to be stored
244      */
245     public void store(CommercialEducationOffer item) {
246         commercialEducationOfferDao.store(item);
247     }
248 
249     /***
250      *
251      * @return list of UnApprovedItems
252      */
253 	public List getUnApprovedItems() {
254 		SearchCriteria searchCriteria = 
255 			searchCriteriaFactory.createSearchCriteria(Item.class);
256 		searchCriteria.addDescendingOrder("publicationDate");
257 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.FALSE);
258 		return searchCriteriaService.executeQuery(searchCriteria);	
259 	}
260 
261     /***
262 	 * {@inheritDoc}
263 	 */
264 	public List getUnApprovedItems(int itemType) {
265 		SearchCriteria searchCriteria = buildSearchCriteria(itemType);
266 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.FALSE);
267 		return searchCriteriaService.executeQuery(searchCriteria);
268 	}
269 
270    /***
271     * {@inheritDoc}
272 	*/
273     public List getUnApprovedItems(Class clazz) {
274       SearchCriteria searchCriteria =
275 			searchCriteriaFactory.createSearchCriteria(clazz);
276 		searchCriteria.addDescendingOrder("publicationDate");
277 		searchCriteria.addEqualsCriterium("adminApproved", Boolean.FALSE);
278 		return searchCriteriaService.executeQuery(searchCriteria);
279     }
280 }
281 /***
282  * $Log: ItemServiceImpl.java,v $
283  * Revision 1.19  2005/12/20 15:36:45  shally
284  * CheckStyle and PMD changes.
285  *
286  * Revision 1.18  2005/12/09 10:46:55  shally
287  * Opkuis voor checkstyle en PMD
288  *
289  * Revision 1.17  2005/10/11 11:40:07  stephan_janssen
290  * Code cleanup.
291  *
292  * Revision 1.16  2005/10/11 07:52:04  stephan_janssen
293  * Added todo comment.
294  *
295  * Revision 1.15  2005/09/23 07:29:55  schauwvliege
296  * delete content refactory for interview
297  *
298  * Revision 1.14  2005/09/19 16:15:19  schauwvliege
299  * Introduction of Approve items
300  *
301  * Revision 1.13  2005/09/13 08:11:17  schauwvliege
302  * organize imports
303  *
304  * Revision 1.12  2005/09/09 13:09:59  schauwvliege
305  * *** empty log message ***
306  *
307  * Revision 1.11  2005/09/09 10:54:04  bavo_jcs
308  * Added CommercialEducationOffer
309  *
310  * Revision 1.10  2005/09/08 08:50:28  bavo_jcs
311  * Added PostInterview
312  *
313  * Revision 1.9  2005/09/07 12:19:44  schauwvliege
314  * typo
315  *
316  * Revision 1.8  2005/09/06 15:33:32  bavo_jcs
317  * Added PostInterview
318  *
319  * Revision 1.7  2005/09/06 14:52:06  schauwvliege
320  * added add item
321  *
322  * Revision 1.6  2005/09/06 13:21:44  schauwvliege
323  * Intro if interview
324  *
325  * Revision 1.5  2005/08/30 13:07:48  psong09
326  * renamed author: psong09
327  *
328  * Revision 1.4  2005/08/26 15:15:20  bavo_jcs
329  * Implemented method (getItem) from interface which was supposed to be renamed.
330  *
331  * Revision 1.3  2005/08/26 14:00:46  bme_jcs
332  * added sorting
333  *
334  * Revision 1.2  2005/08/26 12:15:12  bme_jcs
335  * Javacareers issue 303
336  *
337  * Revision 1.1  2005/08/26 07:58:28  ge0ffrey
338  * split up the sources in service, serviceimpl and webclient
339  *
340  * Revision 1.3  2005/08/24 16:30:00  schauwvliege
341  * introduction of mixed list of all items
342  *
343  * Revision 1.2  2005/08/23 13:04:51  bme_jcs
344  * added count-queries
345  *
346  * Revision 1.1  2005/08/23 09:32:04  bme_jcs
347  * introduction of ItemService-classes
348  *
349  */