1
2
3
4
5 package org.kuali.student.r2.lum.lu.service.impl;
6
7 import java.text.DateFormat;
8 import java.text.ParseException;
9 import java.text.SimpleDateFormat;
10 import java.util.Date;
11
12 import org.kuali.student.r2.common.dto.ContextInfo;
13 import org.kuali.student.r2.common.dto.RichTextInfo;
14 import org.kuali.student.r2.lum.clu.dto.CluIdentifierInfo;
15 import org.kuali.student.r2.lum.clu.dto.CluInfo;
16 import org.kuali.student.r2.lum.clu.service.CluService;
17 import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
18
19
20
21
22 public class CluDataLoader {
23
24 private CluService cluService;
25 private ContextInfo contextInfo;
26
27 public CluService getCluService() {
28 return cluService;
29 }
30
31 public void setCluService(CluService cluService) {
32 this.cluService = cluService;
33 }
34
35 public ContextInfo getContextInfo() {
36 return contextInfo;
37 }
38
39 public void setContextInfo(ContextInfo contextInfo) {
40 this.contextInfo = contextInfo;
41 }
42
43 public void load() {
44 loadCourse("COURSE1", "2012FA", "CHEM", "CHEM123", "Chemistry 123", "description 1");
45 loadCourse("COURSE2", "2012SP", "ENG", "ENG101", "Intro English 1", "description 2");
46 loadCourse("COURSE3", "2012FA", "CHEM", "CHEM124", "Chemistry 124", "description 3");
47 loadCourse("COURSE4", "2012SP", "ENG", "ENG102", "Intro English 2", "description 4");
48 loadCourse("COURSE5", "2012FA", "CHEM", "CHEM125", "Chemistry 125", "description 5");
49 loadCourse("COURSE6", "2012SP", "ENG", "ENG103", "Intro English 3", "description 6");
50 loadCourse("COURSE7", "2012FA", "CHEM", "CHEM126", "Chemistry 126", "description 7");
51 loadCourse("COURSE8", "2012SP", "ENG", "ENG104", "Intro English 4", "description 8");
52
53 loadProgram("PROGRAM1", "2012FA", "PROG1", "Program 1", "Program description 1");
54 loadProgram("PROGRAM2", "2012SP", "PROG2", "Program 2", "Program description 2");
55 }
56
57 public CluInfo loadCourse(String id, String startTermId, String subjectArea, String code, String title,
58 String description) {
59 CluIdentifierInfo official = new CluIdentifierInfo();
60 official.setDivision(subjectArea);
61 official.setCode(code);
62 official.setSuffixCode(code.substring(subjectArea.length()));
63 official.setShortName(title);
64 official.setLongName(title);
65 return loadClu(id, official, startTermId, description, CluServiceConstants.CREDIT_COURSE_LU_TYPE_KEY);
66 }
67
68 public CluInfo loadProgram(String id, String startTermId, String code, String title,
69 String description) {
70 CluIdentifierInfo official = new CluIdentifierInfo();
71 official.setCode(code);
72 official.setShortName(title);
73 official.setLongName(title);
74 return loadClu(id, official, startTermId, description, "kuali.lu.type.MajorDiscipline");
75 }
76
77 private CluInfo loadClu(String id, CluIdentifierInfo official, String startTermId, String description, String type) {
78 CluInfo info = new CluInfo();
79 info.setId(id);
80 info.setExpectedFirstAtp(startTermId);
81 info.setEffectiveDate(calcEffectiveDateForTerm(startTermId, id));
82 info.setOfficialIdentifier(official);
83 RichTextInfo rt = new RichTextInfo();
84 rt.setPlain(description);
85 info.setDescr(rt);
86 info.setTypeKey(type);
87 info.setStateKey("Active");
88 try {
89 return this.cluService.createClu(type, info, contextInfo);
90 } catch (Exception ex) {
91 throw new RuntimeException(ex);
92 }
93 }
94
95 private Date calcEffectiveDateForTerm(String termId, String context) {
96 String year = termId.substring(0, 4);
97 String mmdd = "09-01";
98 if (termId.endsWith("FA")) {
99 mmdd = "09-01";
100 } else if (termId.endsWith("WI")) {
101 mmdd = "01-01";
102 } else if (termId.endsWith("SP")) {
103 mmdd = "03-01";
104 } else if (termId.endsWith("SU")) {
105 mmdd = "06-01";
106 }
107 return str2Date(year + "-" + mmdd + " 00:00:00.0", context);
108 }
109
110 private Date str2Date(String str, String context) {
111 if (str == null) {
112 return null;
113 }
114 DateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.S");
115 try {
116 Date date = df.parse(str);
117 return date;
118 } catch (ParseException ex) {
119 throw new IllegalArgumentException("Bad date " + str + " in " + context);
120 }
121 }
122 }