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.jobs.view.jsf.model;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.bejug.javacareers.common.service.ItemService;
23 import org.bejug.javacareers.jobs.model.*;
24 import org.hibernate.ObjectNotFoundException;
25 import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException;
26
27 import javax.faces.application.FacesMessage;
28 import javax.faces.context.FacesContext;
29 import java.util.Map;
30
31 /***
32 * The class has been created as a patch for the not working sessionScope
33 * problem with JSF-Spring.
34 *
35 * @author Sven Schauwvliege (last modified by $Author: stephan_janssen $)
36 * @version $Revision: 1.10 $ - $Date: 2005/10/26 15:08:38 $
37 */
38 public class CurrentItem {
39
40 /***
41 * Class logger.
42 */
43 private static final Log LOG = LogFactory.getLog(CurrentItem.class);
44
45 /***
46 * The current item.
47 */
48 private Item item;
49
50 /***
51 * the itemservice.
52 */
53 private ItemService itemService;
54
55 /***
56 * constructor.
57 */
58 public CurrentItem() {
59 LOG.info("Debug: Creating CurrentItem");
60 }
61
62 /***
63 * Set the current item offer.
64 *
65 * @param item Item.
66 */
67 public void setItem(Item item) {
68 this.item = item;
69 }
70
71 /***
72 * Get the stored job offer.
73 *
74 * @return Joboffer.
75 */
76 public Item getItem() {
77 FacesContext ctx = FacesContext.getCurrentInstance();
78 Map params = ctx.getExternalContext().getRequestParameterMap();
79 LOG.info("Debug: Map is: " + params);
80 String id = (String) params.get("id");
81
82 if (id != null) {
83
84 LOG.info("Debug: id: " + id);
85 try {
86 Integer intId = Integer.valueOf(id);
87 if (item == null || !item.getId().equals(intId)) {
88 item = itemService.getItem(intId);
89 }
90
91 } catch (NumberFormatException e) {
92 LOG.error("Bad argument in id: " + id + " " + e);
93 ctx.addMessage(null, new FacesMessage("Job with ID " + id +
94 " has not been found. It might have been deleted."));
95 item = null;
96 }
97 catch (HibernateObjectRetrievalFailureException objnf3) {
98 LOG.info("Debug: Object ID not found: " + id);
99 ctx.addMessage(null, new FacesMessage("Job with ID " + id +
100 " has not been found. It might have been deleted."));
101 item = null;
102 }
103 catch (ObjectNotFoundException objnf2) {
104 LOG.info("Debug: Object ID not found: " + id);
105 ctx.addMessage(null, new FacesMessage("Job with ID " + id +
106 " has not been found. It might have been deleted."));
107 item = null;
108 }
109 }
110 return item;
111 }
112
113 /***
114 * @return resume
115 */
116 public Resume getResume(){
117 if (getItem() instanceof Resume) {
118 return (Resume)getItem();
119 }
120 return null;
121 }
122
123 /***
124 * @return joboffer
125 */
126 public JobOffer getJobOffer(){
127 if (getItem() instanceof JobOffer) {
128 return (JobOffer) getItem();
129 }
130 return null;
131 }
132
133 /***
134 * @return CommercialEducationOffer
135 */
136 public CommercialEducationOffer getCommercialEducationOffer(){
137 if (getItem() instanceof CommercialEducationOffer) {
138 return (CommercialEducationOffer) getItem();
139 }
140 return null;
141 }
142
143
144 /***
145 * @return interview
146 */
147 public Interview getInterview(){
148 if (getItem() instanceof Interview) {
149 return (Interview) getItem();
150 }
151 return null;
152 }
153
154 /***
155 * @return ItemService
156 */
157 public ItemService getItemService() {
158 return itemService;
159
160 }
161
162 /***
163 * @param itemService ItemService
164 */
165 public void setItemService(ItemService itemService) {
166 this.itemService = itemService;
167 }
168 }
169
170 /***
171 * $Log: CurrentItem.java,v $
172 * Revision 1.10 2005/10/26 15:08:38 stephan_janssen
173 * Uncommented getInterview method.
174 *
175 * Revision 1.9 2005/10/11 11:10:24 stephan_janssen
176 * Code cleanup.
177 *
178 * Revision 1.8 2005/09/30 16:20:57 bavo_jcs
179 * Fixed URL
180 *
181 * Revision 1.7 2005/09/30 14:38:07 bavo_jcs
182 * Fixed URL
183 *
184 * Revision 1.6 2005/09/21 08:44:50 bavo_jcs
185 * added changes
186 *
187 * Revision 1.5 2005/09/13 08:11:06 schauwvliege
188 * organize imports
189 *
190 * Revision 1.4 2005/09/09 13:09:13 schauwvliege
191 * added Commercial education offer
192 *
193 * Revision 1.3 2005/09/08 13:52:03 bavo_jcs
194 * Added PostInterview
195 *
196 * Revision 1.2 2005/08/25 15:13:24 schauwvliege
197 * introduction of resume view
198 *
199 * Revision 1.1 2005/08/24 16:30:03 schauwvliege
200 * introduction of mixed list of all items
201 *
202 *
203 */