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.Date; |
10 | |
|
11 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
12 | |
import org.kuali.student.r2.common.util.constants.HoldServiceConstants; |
13 | |
import org.kuali.student.r2.core.hold.dto.HoldInfo; |
14 | |
import org.kuali.student.r2.core.hold.dto.IssueInfo; |
15 | |
import org.kuali.student.r2.core.hold.service.HoldService; |
16 | |
import org.kuali.student.r2.core.hold.service.HoldServiceDecorator; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class ProcessPocHoldServiceDecorator extends HoldServiceDecorator { |
23 | |
|
24 | |
public ProcessPocHoldServiceDecorator(HoldService nextDecorator) { |
25 | 0 | super(); |
26 | 0 | this.setNextDecorator(nextDecorator); |
27 | 0 | _initializeData(); |
28 | 0 | } |
29 | |
|
30 | |
private void _initializeData() { |
31 | 0 | ContextInfo context = new ContextInfo(); |
32 | 0 | context.setPrincipalId("POC-Initializer"); |
33 | |
|
34 | 0 | IssueInfo unpaidTuitionIssue = _createIssue(HoldServiceConstants.ISSUE_KEY_UNPAID_TUITION_PRIOR_TERM, |
35 | |
"Unpaid tuition from last term", HoldServiceConstants.FINANCIAL_ISSUE_TYPE_KEY, context); |
36 | |
|
37 | |
|
38 | 0 | IssueInfo overdueBookIssue = _createIssue(HoldServiceConstants.ISSUE_KEY_BOOK_OVERDUE, |
39 | |
"Overdue Library Book", HoldServiceConstants.OVERDUE_LIBRARY_MATERIALS_ISSUE_TYPE_KEY, context); |
40 | |
|
41 | 0 | this._createHold(ProcessPocConstants.PERSON_ID_KARA_STONE_2272, unpaidTuitionIssue, context); |
42 | 0 | this._createHold(ProcessPocConstants.PERSON_ID_CLIFFORD_RIDDLE_2397, unpaidTuitionIssue, context); |
43 | 0 | this._createHold(ProcessPocConstants.PERSON_ID_NINA_WELCH_2166, unpaidTuitionIssue, context); |
44 | 0 | this._createHold(ProcessPocConstants.PERSON_ID_BETTY_MARTIN_2005, overdueBookIssue, context); |
45 | 0 | this._createHold(ProcessPocConstants.PERSON_ID_NINA_WELCH_2166, overdueBookIssue, context); |
46 | 0 | } |
47 | |
|
48 | |
private IssueInfo _createIssue(String key, String name, String type, ContextInfo context) { |
49 | 0 | IssueInfo issue = new IssueInfo(); |
50 | 0 | issue.setId(key); |
51 | 0 | issue.setName(name); |
52 | 0 | issue.setTypeKey(type); |
53 | 0 | issue.setStateKey(HoldServiceConstants.ISSUE_ACTIVE_STATE_KEY); |
54 | |
try { |
55 | 0 | issue = this.createIssue(issue.getTypeKey(), issue, context); |
56 | 0 | } catch (Exception ex) { |
57 | 0 | throw new RuntimeException("error creating hold", ex); |
58 | 0 | } |
59 | 0 | return issue; |
60 | |
} |
61 | |
|
62 | |
private HoldInfo _createHold(String personId, IssueInfo issue, ContextInfo context) { |
63 | 0 | HoldInfo hold = new HoldInfo(); |
64 | 0 | hold.setTypeKey(HoldServiceConstants.STUDENT_HOLD_TYPE_KEY); |
65 | 0 | hold.setStateKey(HoldServiceConstants.HOLD_ACTIVE_STATE_KEY); |
66 | 0 | hold.setIssueId(issue.getId()); |
67 | 0 | hold.setName(issue.getName()); |
68 | 0 | Date effDate = null; |
69 | |
try { |
70 | 0 | effDate = new SimpleDateFormat ("yyyy-MM-dd").parse ("2011-01-01"); |
71 | 0 | } catch (ParseException ex) { |
72 | 0 | throw new RuntimeException (ex); |
73 | 0 | } |
74 | 0 | hold.setEffectiveDate(effDate); |
75 | 0 | hold.setPersonId(personId); |
76 | |
try { |
77 | 0 | hold = this.createHold(hold.getPersonId(), hold.getIssueId(), hold.getTypeKey(), hold, context); |
78 | 0 | } catch (Exception ex) { |
79 | 0 | throw new RuntimeException("error creating hold", ex); |
80 | 0 | } |
81 | 0 | return hold; |
82 | |
} |
83 | |
} |