View Javadoc
1   /**
2    * Copyright 2011-2014 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
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   * @author Joe Swanson <joseswan@umich.edu>
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       * @return the dao
84       */
85      public AcademicsDao getDao() {
86          return dao;
87      }
88  
89      /**
90       * @param dao the dao to set
91       */
92      public void setDao(AcademicsDao dao) {
93          this.dao = dao;
94      }
95  
96  }