1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.acal.util;
17
18 import org.kuali.student.r2.common.dto.ContextInfo;
19 import org.kuali.student.r2.common.util.RichTextHelper;
20 import org.kuali.student.r2.core.acal.dto.TermInfo;
21 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
22 import org.kuali.student.r2.core.constants.AtpServiceConstants;
23
24 import java.text.DateFormat;
25 import java.text.ParseException;
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28
29
30
31
32
33
34 public class MockAcalTestDataLoader {
35
36 private AcademicCalendarService acalService;
37 private static String principalId = MockAcalTestDataLoader.class.getSimpleName();
38
39 public AcademicCalendarService getAcalService() {
40 return acalService;
41 }
42
43 public void setAcalService(AcademicCalendarService acalService) {
44 this.acalService = acalService;
45 }
46
47 public MockAcalTestDataLoader(AcademicCalendarService acalService) {
48 this.acalService = acalService;
49 }
50
51 public void loadData() {
52 loadTerm("testAtpId1", "test1", "2000-01-01 00:00:00.0", "2100-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "description 1");
53 }
54
55 public TermInfo loadTerm(String id,
56 String name,
57 String startDate, String endDate, String type, String state, String description) {
58
59 TermInfo info = new TermInfo();
60 info.setId(id);
61 info.setCode(id);
62 info.setName(name);
63 info.setDescr(new RichTextHelper().fromPlain(description));
64 info.setTypeKey(type);
65 info.setStateKey(state);
66 info.setStartDate(str2Date(startDate, id));
67 info.setEndDate(str2Date(endDate, id));
68
69
70 ContextInfo context = new ContextInfo();
71 context.setPrincipalId(principalId);
72 context.setCurrentDate(new Date());
73 try {
74 return this.acalService.createTerm(type, info, context);
75 } catch (Exception ex) {
76 throw new RuntimeException(ex);
77 }
78 }
79
80 private Date str2Date(String str, String context) {
81 if (str == null) {
82 return null;
83 }
84 DateFormat df = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.S");
85 try {
86 return df.parse(str);
87 } catch (ParseException ex) {
88 throw new IllegalArgumentException("Bad date " + str + " in " + context);
89 }
90 }
91
92 }