1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.document; |
17 | |
|
18 | |
import java.util.Collections; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
23 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
24 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
25 | |
import org.kuali.rice.kew.rule.web.WebRuleUtils; |
26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
27 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
28 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
29 | |
import org.kuali.rice.kns.web.ui.Section; |
30 | |
import org.kuali.rice.krad.document.MaintenanceLock; |
31 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class RoutingRuleDelegationMaintainable extends KualiMaintainableImpl { |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
@Override |
47 | |
public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) { |
48 | 0 | List<Section> sections = super.getSections(document, oldMaintainable); |
49 | 0 | return WebRuleUtils.customizeSections(getThisRule(), sections, true); |
50 | |
} |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
@Override |
56 | |
public void processAfterNew(MaintenanceDocument document, |
57 | |
Map<String, String[]> parameters) { |
58 | 0 | initializeBusinessObjects(document); |
59 | 0 | WebRuleUtils.validateRuleAndResponsibility(getOldRuleDelegation(document), getNewRuleDelegation(document), parameters); |
60 | 0 | WebRuleUtils.validateRuleTemplateAndDocumentType(getOldRule(document), getNewRule(document), parameters); |
61 | 0 | WebRuleUtils.establishDefaultRuleValues(getNewRule(document)); |
62 | 0 | getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber()); |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
private void initializeBusinessObjects(MaintenanceDocument document) { |
70 | 0 | RuleDelegation oldRuleDelegation = getOldRuleDelegation(document); |
71 | 0 | RuleDelegation newRuleDelegation = getNewRuleDelegation(document); |
72 | 0 | if (oldRuleDelegation.getDelegationRuleBaseValues() == null) { |
73 | 0 | oldRuleDelegation.setDelegationRuleBaseValues(new RuleBaseValues()); |
74 | |
} |
75 | 0 | if (newRuleDelegation.getDelegationRuleBaseValues() == null) { |
76 | 0 | newRuleDelegation.setDelegationRuleBaseValues(new RuleBaseValues()); |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
@Override |
87 | |
public void setGenerateDefaultValues(String docTypeName) { |
88 | |
|
89 | 0 | } |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Override |
95 | |
public void saveBusinessObject() { |
96 | 0 | WebRuleUtils.clearKeysForSave(getThisRuleDelegation()); |
97 | 0 | WebRuleUtils.translateResponsibilitiesForSave(getThisRule()); |
98 | 0 | WebRuleUtils.translateFieldValuesForSave(getThisRule()); |
99 | 0 | WebRuleUtils.processRuleForDelegationSave(getThisRuleDelegation()); |
100 | 0 | KEWServiceLocator.getRuleService().makeCurrent(getThisRuleDelegation(), true); |
101 | 0 | } |
102 | |
|
103 | |
@Override |
104 | |
public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> parameters) { |
105 | 0 | WebRuleUtils.processRuleForCopy(document.getDocumentNumber(), getOldRule(document), getNewRule(document)); |
106 | 0 | super.processAfterCopy(document, parameters); |
107 | 0 | } |
108 | |
|
109 | |
@Override |
110 | |
public void processAfterEdit(MaintenanceDocument document, |
111 | |
Map<String, String[]> parameters) { |
112 | 0 | if (!getOldRule(document).getCurrentInd()) { |
113 | 0 | throw new RiceRuntimeException("Cannot edit a non-current version of a rule."); |
114 | |
} |
115 | 0 | WebRuleUtils.populateForCopyOrEdit(getOldRule(document), getNewRule(document)); |
116 | 0 | getNewRule(document).setPreviousVersionId(getOldRule(document).getRuleBaseValuesId()); |
117 | 0 | getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber()); |
118 | 0 | super.processAfterEdit(document, parameters); |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
@Override |
123 | |
public List<MaintenanceLock> generateMaintenanceLocks() { |
124 | 0 | if (getThisRule().getRuleBaseValuesId() == null) { |
125 | 0 | return Collections.emptyList(); |
126 | |
} |
127 | 0 | return super.generateMaintenanceLocks(); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public String getDocumentTitle(MaintenanceDocument document) { |
132 | 0 | StringBuffer title = new StringBuffer(); |
133 | 0 | RuleBaseValues rule = getThisRule(); |
134 | 0 | if (rule.getPreviousVersionId() != null) { |
135 | 0 | title.append("Editing Rule Delegation '").append(rule.getDescription()).append("'"); |
136 | |
} else { |
137 | 0 | title.append("Adding Rule Delegation '").append(rule.getDescription()).append("'"); |
138 | |
} |
139 | 0 | return title.toString(); |
140 | |
} |
141 | |
|
142 | |
protected RuleDelegation getNewRuleDelegation(MaintenanceDocument document) { |
143 | 0 | return (RuleDelegation)document.getNewMaintainableObject().getBusinessObject(); |
144 | |
} |
145 | |
|
146 | |
protected RuleDelegation getOldRuleDelegation(MaintenanceDocument document) { |
147 | 0 | return (RuleDelegation)document.getOldMaintainableObject().getBusinessObject(); |
148 | |
} |
149 | |
|
150 | |
protected RuleDelegation getThisRuleDelegation() { |
151 | 0 | return (RuleDelegation)getBusinessObject(); |
152 | |
} |
153 | |
|
154 | |
protected RuleBaseValues getNewRule(MaintenanceDocument document) { |
155 | 0 | return getNewRuleDelegation(document).getDelegationRuleBaseValues(); |
156 | |
} |
157 | |
|
158 | |
protected RuleBaseValues getOldRule(MaintenanceDocument document) { |
159 | 0 | return getOldRuleDelegation(document).getDelegationRuleBaseValues(); |
160 | |
} |
161 | |
|
162 | |
protected RuleBaseValues getThisRule() { |
163 | 0 | return getThisRuleDelegation().getDelegationRuleBaseValues(); |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
@Override |
172 | |
public void prepareForSave() { |
173 | 0 | super.prepareForSave(); |
174 | 0 | WebRuleUtils.translateResponsibilitiesForSave(getThisRule()); |
175 | 0 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
} |