1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.kuali.student.r2.core.class1.process; |
6 | |
|
7 | |
import java.text.ParseException; |
8 | |
import java.text.SimpleDateFormat; |
9 | |
import java.util.ArrayList; |
10 | |
import java.util.Date; |
11 | |
import java.util.List; |
12 | |
|
13 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
14 | |
import org.kuali.student.r2.common.util.constants.AtpServiceConstants; |
15 | |
import org.kuali.student.r2.core.atp.dto.AtpInfo; |
16 | |
import org.kuali.student.r2.core.atp.dto.MilestoneInfo; |
17 | |
import org.kuali.student.r2.core.atp.service.AtpService; |
18 | |
import org.kuali.student.r2.core.class1.atp.service.decorators.AtpServiceDecorator; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public class ProcessPocAtpServiceDecorator extends AtpServiceDecorator { |
25 | |
|
26 | |
public ProcessPocAtpServiceDecorator(AtpService nextDecorator) { |
27 | 0 | super(); |
28 | 0 | this.setNextDecorator(nextDecorator); |
29 | 0 | _initializeData(); |
30 | 0 | } |
31 | |
|
32 | |
private void _initializeData() { |
33 | 0 | ContextInfo context = new ContextInfo(); |
34 | 0 | context.setPrincipalId("POC-Initializer"); |
35 | |
|
36 | 0 | AtpInfo spring2011 = this._createAtp(ProcessPocConstants.SPRING_2011_TERM_KEY, AtpServiceConstants.ATP_SPRING_TYPE_KEY, "Spring 2011", "2011-02-01", "2011-05-31", context); |
37 | 0 | AtpInfo summer2011 = this._createAtp(ProcessPocConstants.SUMMER_2011_TERM_KEY, AtpServiceConstants.ATP_SUMMER_TYPE_KEY, "Summer 2011", "2011-06-01", "2011-08-31", context); |
38 | 0 | AtpInfo fall2011 = this._createAtp(ProcessPocConstants.FALL_2011_TERM_KEY, AtpServiceConstants.ATP_FALL_TYPE_KEY, "Fall 2011", "2011-09-01", "2011-12-31", context); |
39 | 0 | AtpInfo spring2012 = this._createAtp(ProcessPocConstants.SPRING_2012_TERM_KEY, AtpServiceConstants.ATP_SPRING_TYPE_KEY, "Spring 2012", "2012-02-01", "2012-05-31", context); |
40 | |
|
41 | 0 | _createRegMilestone(spring2011, "2011-01-20", "2011-02-01", context); |
42 | 0 | _createRegMilestone(summer2011, "2011-06-01", "2011-12-31", context); |
43 | 0 | _createRegMilestone(fall2011, "2011-09-01", "2011-12-31", context); |
44 | 0 | _createRegMilestone(spring2012, "2012-01-20", "2012-02-01", context); |
45 | 0 | } |
46 | |
|
47 | |
private MilestoneInfo _createRegMilestone(AtpInfo atp, String start, String end, ContextInfo context) { |
48 | 0 | MilestoneInfo milestone = new MilestoneInfo(); |
49 | 0 | milestone.setId(atp.getId() + "_reg.period"); |
50 | 0 | milestone.setTypeKey(AtpServiceConstants.MILESTONE_REGISTRATION_PERIOD_TYPE_KEY); |
51 | 0 | milestone.setStateKey(AtpServiceConstants.MILESTONE_OFFICIAL_STATE_KEY); |
52 | 0 | milestone.setStartDate(parseDate(start)); |
53 | 0 | milestone.setEndDate(parseDate(end)); |
54 | 0 | milestone.setIsAllDay(Boolean.TRUE); |
55 | 0 | milestone.setIsDateRange(Boolean.TRUE); |
56 | 0 | milestone.setIsInstructionalDay(Boolean.TRUE); |
57 | 0 | milestone.setIsRelative(Boolean.FALSE); |
58 | 0 | milestone.setName("Registration Period for " + atp.getName()); |
59 | |
try { |
60 | 0 | MilestoneInfo createdMilestone = this.createMilestone(milestone.getTypeKey(), milestone, context); |
61 | 0 | this.addMilestoneToAtp(milestone.getId(), atp.getId(), context); |
62 | 0 | return createdMilestone; |
63 | 0 | } catch (Exception ex) { |
64 | 0 | throw new RuntimeException("unexpected", ex); |
65 | |
} |
66 | |
|
67 | |
|
68 | |
} |
69 | |
|
70 | |
private AtpInfo _createAtp(String key, String type, String name, String start, String end, ContextInfo context) { |
71 | 0 | AtpInfo atp = new AtpInfo(); |
72 | 0 | atp.setId(key); |
73 | 0 | atp.setTypeKey(type); |
74 | 0 | atp.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY); |
75 | 0 | atp.setStartDate(parseDate(start)); |
76 | 0 | atp.setEndDate(parseDate(end)); |
77 | 0 | atp.setName(name); |
78 | |
try { |
79 | 0 | AtpInfo createdAtp = this.createAtp(atp.getTypeKey(), atp, context); |
80 | 0 | return createdAtp; |
81 | 0 | } catch (Exception ex) { |
82 | 0 | throw new RuntimeException("unexpected", ex); |
83 | |
} |
84 | |
} |
85 | |
|
86 | |
private Date parseDate(String str) { |
87 | |
Date date; |
88 | |
try { |
89 | 0 | date = new SimpleDateFormat("yyyy-MM-dd").parse(str); |
90 | 0 | } catch (ParseException ex) { |
91 | 0 | throw new RuntimeException(str, ex); |
92 | 0 | } |
93 | 0 | return date; |
94 | |
} |
95 | |
|
96 | |
private List<String> _getTermTypeKeys() { |
97 | 0 | List<String> list = new ArrayList<String>(); |
98 | 0 | list.add(AtpServiceConstants.ATP_FALL_TYPE_KEY); |
99 | 0 | list.add(AtpServiceConstants.ATP_WINTER_TYPE_KEY); |
100 | 0 | list.add(AtpServiceConstants.ATP_SPRING_TYPE_KEY); |
101 | 0 | list.add(AtpServiceConstants.ATP_SUMMER_TYPE_KEY); |
102 | 0 | return list; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
} |