View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.kuali.student.r2.lum.lu.service.impl;
6   
7   import edu.emory.mathcs.backport.java.util.Arrays;
8   import java.util.ArrayList;
9   import java.util.Date;
10  import java.util.List;
11  import org.kuali.student.r2.common.dto.ContextInfo;
12  import org.kuali.student.r2.lum.clu.dto.CluInfo;
13  import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
14  import org.kuali.student.r2.lum.clu.service.CluService;
15  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
16  
17  /**
18   *
19   * @author nwright
20   */
21  public class CluSetDataLoader {
22  
23      private CluService cluService;
24      private ContextInfo contextInfo;
25  
26      public CluService getCluService() {
27          return cluService;
28      }
29  
30      public void setCluService(CluService cluService) {
31          this.cluService = cluService;
32      }
33  
34      public ContextInfo getContextInfo() {
35          return contextInfo;
36      }
37  
38      public void setContextInfo(ContextInfo contextInfo) {
39          this.contextInfo = contextInfo;
40      }
41  
42      public void load() {
43          loadCourseSet("COURSE-SET1", "COURSE-SET1-NAME", "COURSE1");
44          loadCourseSet("COURSE-SET2", "COURSE-SET2-NAME", "COURSE2", "COURSE3");
45          loadCourseSet("COURSE-SET3", "COURSE-SET3-NAME", "COURSE4", "COURSE5", "COURSE6", "COURSE7");
46  
47          loadProgramSet("PROG-SET1", "PROG-SET1-NAME", "PROGRAM1");
48      }
49  
50      public CluSetInfo loadCourseSet(String id, String name, String... cluIds) {
51          return loadCluSet(id, name, CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE, cluIds);
52      }
53  
54      public CluSetInfo loadProgramSet(String id, String name, String... cluIds) {
55          return loadCluSet(id, name, CluServiceConstants.CLUSET_TYPE_PROGRAM, cluIds);
56      }
57  
58      private CluSetInfo loadCluSet(String id, String name, String type, String[] cluIds) {
59          CluSetInfo cluSetInfo = new CluSetInfo();
60          cluSetInfo.setId(id);
61          cluSetInfo.setTypeKey(type);
62          cluSetInfo.setStateKey("Active");
63          cluSetInfo.setName(name);
64          cluSetInfo.setEffectiveDate(new Date());
65          cluSetInfo.setIsReferenceable(Boolean.TRUE);
66          cluSetInfo.setIsReusable(Boolean.FALSE);
67          // convert cluIds into version independent ids
68          List<String> versionIndCluIds = new ArrayList<String>();
69          cluSetInfo.setCluIds(versionIndCluIds);
70          List<CluInfo> clus;
71          try {
72              clus = this.cluService.getClusByIds(Arrays.asList(cluIds), contextInfo);
73          } catch (Exception ex) {
74              throw new IllegalArgumentException(ex);
75          }
76          for (CluInfo cluInfo : clus) {
77              versionIndCluIds.add(cluInfo.getVersion().getVersionIndId());
78          }
79          try {
80              cluSetInfo = this.cluService.createCluSet(cluSetInfo.getTypeKey(), cluSetInfo, contextInfo);
81          } catch (Exception ex) {
82              throw new IllegalArgumentException(ex);
83          }
84          return cluSetInfo;
85      }
86  
87  
88  }