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.util;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.bejug.javacareers.common.exception.DuplicateUserNameException;
23 import org.bejug.javacareers.common.exception.LastAdminException;
24 import org.bejug.javacareers.common.search.SearchCriteria;
25 import org.bejug.javacareers.common.search.SearchCriteriaFactory;
26 import org.bejug.javacareers.common.search.SearchCriteriaService;
27 import org.bejug.javacareers.feeder.FeederDaemonConfig;
28 import org.bejug.javacareers.feeder.model.RssFeed;
29 import org.bejug.javacareers.jobs.model.Address;
30 import org.bejug.javacareers.jobs.model.Country;
31 import org.bejug.javacareers.jobs.model.Organisation;
32 import org.bejug.javacareers.jobs.model.OrganisationType;
33 import org.bejug.javacareers.jobs.model.Profile;
34 import org.bejug.javacareers.jobs.model.Region;
35 import org.bejug.javacareers.jobs.model.User;
36 import org.bejug.javacareers.jobs.service.AdminService;
37 import org.bejug.javacareers.jobs.service.JobService;
38 import org.bejug.javacareers.jobs.service.RssFeedService;
39 import org.bejug.javacareers.project.properties.JavaCareersConfig;
40 import org.springframework.beans.factory.InitializingBean;
41
42 /***
43 * Temporary solution to bootstrap the admin account while working with an
44 * in-memory database.
45 *
46 * @author kva (Last modified by $Author: shally $)
47 * @version $Revision: 1.26 $ - $Date: 2005/12/20 15:36:47 $
48 */
49 public class AdminBootstrap implements InitializingBean {
50
51 /***
52 * The class logger.
53 */
54 private static final Log LOG = LogFactory.getLog(AdminBootstrap.class);
55
56 /***
57 *
58 * adminService.
59 */
60 private AdminService adminService;
61
62 /***
63 * jobservice.
64 */
65 private JobService jobService;
66
67 /***
68 * javaCareersConfig.
69 */
70 private JavaCareersConfig javaCareersConfig;
71
72 /***
73 * feederDaemonConfig.
74 */
75 private FeederDaemonConfig feederDaemonConfig;
76
77 /***
78 * rssFeedService.
79 */
80 private RssFeedService rssFeedService;
81
82 /***
83 * Search factory.
84 */
85 protected SearchCriteriaFactory searchCriteriaFactory;
86
87 /***
88 * Search criteria service.
89 */
90 private SearchCriteriaService searchCriteriaService;
91
92 /***
93 * @return Returns the rssFeedService.
94 */
95 public RssFeedService getRssFeedService() {
96 return rssFeedService;
97 }
98
99 /***
100 *
101 * @return the wanted jobservice
102 */
103 public JobService getJobService() {
104 return jobService;
105 }
106
107 /***
108 *
109 * @param jobService sets the jobservice
110 */
111 public void setJobService(JobService jobService) {
112 this.jobService = jobService;
113 }
114
115 /***
116 * Spring-injection method for RSSFeedDAO
117 *
118 * @param rssFeedService The rssFeedService to set.
119 */
120 public void setRssFeedService(RssFeedService rssFeedService) {
121 LOG.info("Debug: Setting config");
122 this.rssFeedService = rssFeedService;
123 }
124
125 /***
126 * FeederDaemon feederDaemonConfig file is set through Springs IoC.
127 *
128 * @param config Sets the feederDaemonConfig object (Spring)
129 */
130 public void setFeederDaemonConfig(FeederDaemonConfig config) {
131 LOG.info("Debug: >>>>>>>>>>>>>>>>> Setting config");
132 this.feederDaemonConfig = config;
133 }
134
135 /***
136 * @return Config object containg settings
137 */
138 public FeederDaemonConfig getFeederDaemonConfig() {
139 return feederDaemonConfig;
140 }
141
142 /***
143 * @throws LastAdminException on last admin
144 */
145 public void afterPropertiesSet() throws LastAdminException {
146 SearchCriteria searchCriteria =
147 searchCriteriaFactory.createSearchCriteria(Country.class);
148
149
150 searchCriteria.addEqualsCriterium("name","Belgium");
151
152 Country country = null;
153
154
155
156 if (!javaCareersConfig.isProductionMode()) {
157
158 if (adminService.getUserByUserName("user") == null ||
159 adminService.getUserByUserName("admin") == null) {
160
161 LOG.info("Debug: Initialising development mode users");
162
163
164 country = new Country("Belgium");
165 Region region1 = new Region("Oost vlaanderen");
166 Region region2 = new Region("West vlaanderen");
167 country.add(region1);
168 country.add(region2);
169 adminService.storeCountry(country);
170
171 User user;
172
173 OrganisationType community = new OrganisationType("community",
174 "", "en");
175
176 adminService.storeOrganisationType(community);
177
178 user = new User();
179 user.setUserName("admin");
180 user.setPassword("21232f297a57a5a743894a0e4a801fc3");
181 user.setRole("ROLE_ADMIN");
182 user.getContact().setEmail("javacareers-develop@lists.sourceforge.net");
183 user.setFirstName("ad");
184 user.setLastName("min");
185 user.setSalutation("Mr");
186
187 Profile profile1 = new Profile("Senior","Senior developer","en");
188 Profile profile2 = new Profile("Junior","Junior developer","en");
189 adminService.storeProfile(profile1);
190 adminService.storeProfile(profile2);
191
192
193 Organisation adminOrganisation =
194 new Organisation("Bejug", "The Belgian Java Users Group");
195 adminOrganisation.setOrganisationType(community);
196 adminOrganisation.setAddress(
197 new Address("home", "Lijsterbessendreef", "1",
198 "Oostkamp", "8020",region1));
199
200 user.setOrganisation(adminOrganisation);
201 try {
202 adminService.storeUser(user);
203 } catch (DuplicateUserNameException e1) {
204 LOG.info("user exists" + user.getUserName());
205 }
206
207
208 user = new User();
209 user.setUserName("user");
210 user.setPassword("ee11cbb19052e40b07aac0ca060c23ee");
211 user.setRole("ROLE_USER");
212 user.setFirstName("user");
213 user.setLastName("generic");
214 user.getContact().setEmail("javacareers-develop@lists.sourceforge.net");
215 Organisation userOrganisation =
216 new Organisation("Bejug", "The Belgian Java Users Group");
217 userOrganisation.setOrganisationType(community);
218 userOrganisation.setAddress(
219 new Address("home", "Lijsterbessendreef", "1",
220 "Oostkamp", "8020", region1));
221 user.setOrganisation(userOrganisation);
222 try {
223 adminService.storeUser(user);
224 } catch (DuplicateUserNameException e) {
225 LOG.info("user exists" + user.getUserName());
226 }
227
228
229 user = new User();
230 user.setUserName("RssFeeder");
231 int pass = (int)(Math.random()*1000);
232 user.setPassword("rand"+pass);
233 user.setRole("ROLE_USER");
234 user.setFirstName("Rss");
235 user.setLastName("Feeder");
236 user.getContact().setEmail("feeder@bejug.org");
237 Organisation rssOrganisation = new Organisation("RSS Feed",
238 "Rss Feeder");
239 rssOrganisation.setOrganisationType(community);
240 rssOrganisation.setAddress(
241 new Address("", "", "", "", "", region2));
242 user.setOrganisation(rssOrganisation);
243 try {
244 adminService.storeUser(user);
245 } catch (DuplicateUserNameException e) {
246 LOG.info("user exists" + user.getUserName());
247 }
248 createRSSData();
249
250 } else{
251 LOG.info("Debug: Development mode users were already initalised");
252 }
253 }
254 }
255
256 /***
257 * Create some test data
258 */
259 public void createRSSData() {
260 RssFeed feed = new RssFeed();
261 feed.setUri("http://www.jcs.be/rss/jcs-int-jobs-rss.xml");
262 feed.setSourceName("JCS INT");
263 feed.setSourceUrl("http://www.jcs.be");
264 feed.setKeywords(getFeederDaemonConfig().getKeywords());
265
266 RssFeed feed2 = new RssFeed();
267 feed2.setUri(
268 "http://www.vacature.be/scripts/VacZoeker/rss.asp?trefwoord=java%20j2ee");
269 feed2.setSourceName("Vacature.com");
270 feed2.setSourceUrl("http://www.vacature.be");
271 feed2.setKeywords(getFeederDaemonConfig().getKeywords());
272
273
274 RssFeed feed3 = new RssFeed();
275 feed3.setUri("http://www.javajobs.be/jobs.xml");
276 feed3.setSourceName("Javajobs be");
277 feed3.setSourceUrl("http://www.javajobs.be");
278 feed3.setKeywords(getFeederDaemonConfig().getKeywords());
279 LOG.info("Debug: Test feeds created");
280
281
282
283 RssFeed feed4 = new RssFeed();
284 feed4.setUri("http://www.jobat.be/rss/jobs.asp?keyword=java");
285 feed4.setSourceName("Job@t");
286 feed4.setSourceUrl("http://www.jobat.be/");
287 feed4.setKeywords(getFeederDaemonConfig().getKeywords());
288 LOG.info("Debug: Test feeds created");
289
290 getRssFeedService().addRssFeed(feed);
291 getRssFeedService().addRssFeed(feed2);
292 getRssFeedService().addRssFeed(feed3);
293 getRssFeedService().addRssFeed(feed4);
294 LOG.info("Debug: Test feeds added");
295 LOG.info("Debug: Feeder publisher added");
296 }
297
298 /***
299 * @param adminService
300 * The adminService to set.
301 */
302 public void setAdminService(AdminService adminService) {
303 this.adminService = adminService;
304 }
305
306 /***
307 * @param javaCareersConfig The javaCareersConfig to set.
308 */
309 public void setJavaCareersConfig(JavaCareersConfig javaCareersConfig) {
310 this.javaCareersConfig = javaCareersConfig;
311 }
312
313 /***
314 *
315 * @return searchCriteriaFactory
316 */
317 public SearchCriteriaFactory getSearchCriteriaFactory() {
318 return searchCriteriaFactory;
319 }
320
321 /***
322 *
323 * @param searchCriteriaFactory is searchCriteriaFactory
324 */
325 public void setSearchCriteriaFactory(
326 SearchCriteriaFactory searchCriteriaFactory) {
327 this.searchCriteriaFactory = searchCriteriaFactory;
328 }
329
330 /***
331 *
332 * @return searchCriteriaService
333 */
334 public SearchCriteriaService getSearchCriteriaService() {
335 return searchCriteriaService;
336 }
337
338 /***
339 *
340 * @param searchCriteriaService is searchCriteriaService
341 */
342 public void setSearchCriteriaService(
343 SearchCriteriaService searchCriteriaService) {
344 this.searchCriteriaService = searchCriteriaService;
345 }
346 }
347 /***
348 * $Log: AdminBootstrap.java,v $
349 * Revision 1.26 2005/12/20 15:36:47 shally
350 * CheckStyle and PMD changes.
351 *
352 * Revision 1.25 2005/12/08 14:53:46 shally
353 * Opkuis voor checkstyle.
354 *
355 * Revision 1.24 2005/11/01 13:23:18 kristofvb
356 * give admin a salutation
357 *
358 * Revision 1.23 2005/10/11 09:53:27 stephan_janssen
359 * Code cleanup.
360 *
361 * Revision 1.22 2005/09/30 14:38:08 bavo_jcs
362 * Fixed URL
363 *
364 * Revision 1.21 2005/09/13 08:11:06 schauwvliege
365 * organize imports
366 *
367 * Revision 1.20 2005/08/31 12:16:59 bme_jcs
368 * little bug fixed
369 *
370 * Revision 1.19 2005/08/31 11:41:41 bavo_jcs
371 * Update bootsrap
372 *
373 * Revision 1.18 2005/08/23 14:17:18 bavo_jcs
374 * Fixed JDBC insert error caused by empty profile
375 *
376 * Revision 1.17 2005/08/23 12:34:13 ge0ffrey
377 * switched to the javacareers-develop e-mail address for testing
378 *
379 * Revision 1.16 2005/08/16 09:10:14 bme_jcs
380 * checkstyle errors resolved
381 *
382 * Revision 1.15 2005/08/16 06:33:03 bme_jcs
383 * changed the name of the company for the rssfeed from bejug to rss feed
384 *
385 * Revision 1.14 2005/08/10 12:05:49 bme_jcs
386 * refactoring of adminService
387 *
388 * Revision 1.12 2005/08/09 12:59:56 bavo_jcs
389 * Optimized imports
390 *
391 * Revision 1.11 2005/08/08 13:22:12 bme_jcs
392 * added jobService again
393 *
394 * Revision 1.10 2005/08/08 12:08:01 bme_jcs
395 * resolved checkstyle errors
396 *
397 * Revision 1.9 2005/08/08 09:38:23 bme_jcs
398 * resolved checkstyle errors
399 *
400 * Revision 1.8 2005/07/05 15:14:44 schauwvliege
401 * Moved test data to AdminBootstrap
402 *
403 * Revision 1.7 2005/06/27 13:18:21 ge0ffrey
404 * JAVACAREERS-182
405 *
406 * Revision 1.6 2005/06/24 09:32:16 schauwvliege
407 * alwas save a user and admin in the db if they dont exist
408 *
409 * Revision 1.5 2005/06/20 15:42:45 bavo_jcs
410 * added mail to friend
411 *
412 * Revision 1.4 2005/06/14 13:40:05 schauwvliege
413 * Renamed add to store
414 *
415 * Revision 1.3 2005/06/14 12:05:53 schauwvliege
416 * CheckStyle and fixing tests
417 *
418 * Revision 1.2 2005/06/09 08:18:53 bejug_cc
419 * Fix initial import
420 *
421 * Revision 1.9 2005/06/03 19:57:00 kva
422 * one-time setup of default content
423 *
424 * Revision 1.8 2005/05/26 10:41:39 kva
425 * added job digest mail
426 *
427 * Revision 1.7 2005/05/17 14:26:26 kva
428 * add some default profiles
429 *
430 * Revision 1.6 2005/05/17 11:59:56 ssc
431 * Refactored User and Publisher class to User Class added cvAdded Boolean, added Address to user, Fixed test to work with this setup
432 *
433 * Revision 1.5 2005/05/12 11:34:47 kva
434 * added organisation, address, locale, linecount, subscription info to user profile and registration
435 *
436 * Revision 1.4 2005/05/11 20:14:48 kva
437 * fix duplicate JavaCareerException problem
438 * Revision 1.3 2005/05/10 11:02:17 kva added
439 * another user
440 *
441 * Revision 1.2 2005/05/09 14:54:45 ssc checkstyle
442 *
443 * Revision 1.1 2005/05/03 15:24:14 kva setup initial admin account
444 *
445 */