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