1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.academics.dao;
16
17 import org.apache.log4j.Logger;
18 import org.kuali.mobility.academics.entity.Career;
19 import org.kuali.mobility.academics.entity.Subject;
20 import org.kuali.mobility.academics.entity.Term;
21 import org.kuali.mobility.academics.util.AcademicsConstants;
22 import org.kuali.mobility.shared.InitBean;
23
24 import javax.annotation.Resource;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30
31
32
33 public class AcademicsInitBean implements InitBean {
34 private static org.apache.log4j.Logger LOG = Logger.getLogger(AcademicsInitBean.class);
35
36 @Resource(name = "academicsDao")
37 private AcademicsDao dao;
38
39 public void loadData() {
40 LOG.info("Initializing Academics...");
41 try {
42 LOG.info("Loading academics bootstrap data.");
43 if (null != getDao()) {
44 List<Term> terms = getDao().getTerms();
45 List<Career> careers = new ArrayList<Career>();
46 List<Subject> subjects = new ArrayList<Subject>();
47
48 for (Term t : terms) {
49 Map<String, String> query = new HashMap<String, String>();
50 query.put(AcademicsConstants.TERM_ID, t.getId());
51 List<Career> lCareers = getDao().getCareers(query);
52 for (Career c : lCareers) {
53 Map<String, String> query2 = new HashMap<String, String>();
54 query2.put(AcademicsConstants.TERM_ID, t.getId());
55 query2.put(AcademicsConstants.CAREER_ID, c.getId());
56 List<Subject> lSubjects = getDao().getSubjects(query2);
57
58 for (Subject s : lSubjects) {
59 if (!subjects.contains(s)) {
60 subjects.add(s);
61 }
62 }
63
64 if (!careers.contains(c)) {
65 careers.add(c);
66 }
67 }
68 }
69 LOG.debug("Setting academics bootstrap data.");
70 getDao().setCareers(careers);
71 getDao().setSubjects(subjects);
72 getDao().setTerms(terms);
73 LOG.debug("Loaded " + careers.size() + " careers.");
74 LOG.debug("Loaded " + subjects.size() + " subjects.");
75 }
76 } catch (Exception e) {
77 LOG.error(e.getLocalizedMessage(), e);
78 }
79 LOG.info("Academics initialization complete.");
80 }
81
82
83
84
85 public AcademicsDao getDao() {
86 return dao;
87 }
88
89
90
91
92 public void setDao(AcademicsDao dao) {
93 this.dao = dao;
94 }
95
96 }