| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
package org.kuali.student.r2.core.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.setName("Registration Period for " + atp.getName()); |
| 55 | |
try { |
| 56 | 0 | MilestoneInfo createdMilestone = this.createMilestone(milestone, context); |
| 57 | 0 | this.addMilestoneToAtp(milestone.getId(), atp.getId(), context); |
| 58 | 0 | return createdMilestone; |
| 59 | 0 | } catch (Exception ex) { |
| 60 | 0 | throw new RuntimeException("unexpected", ex); |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
} |
| 65 | |
|
| 66 | |
private AtpInfo _createAtp(String key, String type, String name, String start, String end, ContextInfo context) { |
| 67 | 0 | AtpInfo atp = new AtpInfo(); |
| 68 | 0 | atp.setId(key); |
| 69 | 0 | atp.setTypeKey(type); |
| 70 | 0 | atp.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY); |
| 71 | 0 | atp.setStartDate(parseDate(start)); |
| 72 | 0 | atp.setEndDate(parseDate(end)); |
| 73 | 0 | atp.setName(name); |
| 74 | |
try { |
| 75 | 0 | AtpInfo createdAtp = this.createAtp( atp, context); |
| 76 | 0 | return createdAtp; |
| 77 | 0 | } catch (Exception ex) { |
| 78 | 0 | throw new RuntimeException("unexpected", ex); |
| 79 | |
} |
| 80 | |
} |
| 81 | |
|
| 82 | |
private Date parseDate(String str) { |
| 83 | |
Date date; |
| 84 | |
try { |
| 85 | 0 | date = new SimpleDateFormat("yyyy-MM-dd").parse(str); |
| 86 | 0 | } catch (ParseException ex) { |
| 87 | 0 | throw new RuntimeException(str, ex); |
| 88 | 0 | } |
| 89 | 0 | return date; |
| 90 | |
} |
| 91 | |
|
| 92 | |
private List<String> _getTermTypeKeys() { |
| 93 | 0 | List<String> list = new ArrayList<String>(); |
| 94 | 0 | list.add(AtpServiceConstants.ATP_FALL_TYPE_KEY); |
| 95 | 0 | list.add(AtpServiceConstants.ATP_WINTER_TYPE_KEY); |
| 96 | 0 | list.add(AtpServiceConstants.ATP_SPRING_TYPE_KEY); |
| 97 | 0 | list.add(AtpServiceConstants.ATP_SUMMER_TYPE_KEY); |
| 98 | 0 | return list; |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
} |