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