View Javadoc
1   /**
2    * Copyright 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.shared.InitBean;
22  
23  import javax.annotation.Resource;
24  import javax.xml.bind.JAXBContext;
25  import javax.xml.bind.JAXBException;
26  import javax.xml.bind.Unmarshaller;
27  import java.io.InputStream;
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  /**
32   * @author Kuali Mobility Team (mobility.dev@kuali.org)
33   */
34  public class AcademicsInitBeanDemo implements InitBean {
35      private static Logger LOG = Logger.getLogger(AcademicsInitBeanDemo.class);
36  
37      @Resource(name="academicsDao")
38      private AcademicsDao dao;
39  
40      public void loadData() {
41          List<Term> terms = new ArrayList<Term>();
42          try {
43              Term term = null;
44              JAXBContext jc = JAXBContext.newInstance(Term.class);
45              Unmarshaller um = jc.createUnmarshaller();
46              InputStream in = this.getClass().getResourceAsStream("/ScheduleOfClasses.xml");
47              term = (Term) um.unmarshal(in);
48              terms.add(term);
49          } catch (JAXBException jbe) {
50              LOG.error(jbe.getLocalizedMessage(), jbe);
51          }
52          getDao().setTerms(terms);
53          List<Career> careers = new ArrayList<Career>();
54          List<Subject> subjects = new ArrayList<Subject>();
55          careers.addAll(terms.get(0).getCareers());
56          for( Career c : careers ) {
57              subjects.addAll(c.getSubjects());
58          }
59          getDao().setCareers(careers);
60          getDao().setSubjects(subjects);
61      }
62  
63      public AcademicsDao getDao() {
64          return dao;
65      }
66  
67      public void setDao(AcademicsDao dao) {
68          this.dao = dao;
69      }
70  }