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.api.KEWPropertyConstants; |
24 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
25 | |
import org.kuali.rice.kew.rule.RuleResponsibilityBo; |
26 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateBo; |
27 | |
import org.kuali.rice.kew.rule.web.WebRuleUtils; |
28 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
29 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
30 | |
import org.kuali.rice.kns.web.ui.Section; |
31 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
32 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
33 | |
import org.kuali.rice.krad.document.MaintenanceLock; |
34 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class RoutingRuleMaintainable extends KualiMaintainableImpl { |
44 | |
|
45 | |
private static final long serialVersionUID = -5920808902137192662L; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Override |
52 | |
public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) { |
53 | 0 | List<Section> sections = super.getSections(document, oldMaintainable); |
54 | 0 | return WebRuleUtils.customizeSections(getThisRule(), sections, false); |
55 | |
|
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Override |
62 | |
public void processAfterNew(MaintenanceDocument document, |
63 | |
Map<String, String[]> parameters) { |
64 | 0 | WebRuleUtils.validateRuleTemplateAndDocumentType(getOldRule(document), getNewRule(document), parameters); |
65 | 0 | WebRuleUtils.establishDefaultRuleValues(getNewRule(document)); |
66 | 0 | getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber()); |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
@Override |
76 | |
public void setGenerateBlankRequiredValues(String docTypeName) { |
77 | |
|
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@Override |
84 | |
public void saveBusinessObject() { |
85 | 0 | WebRuleUtils.clearKeysForSave(getThisRule()); |
86 | 0 | WebRuleUtils.translateResponsibilitiesForSave(getThisRule()); |
87 | 0 | WebRuleUtils.translateFieldValuesForSave(getThisRule()); |
88 | 0 | KEWServiceLocator.getRuleService().makeCurrent(getThisRule(), true); |
89 | 0 | } |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Override |
95 | |
public void saveDataObject() { |
96 | 0 | WebRuleUtils.clearKeysForSave(getThisRule()); |
97 | 0 | WebRuleUtils.translateResponsibilitiesForSave(getThisRule()); |
98 | 0 | WebRuleUtils.translateFieldValuesForSave(getThisRule()); |
99 | 0 | KEWServiceLocator.getRuleService().makeCurrent(getThisRule(), true); |
100 | 0 | } |
101 | |
|
102 | |
@Override |
103 | |
public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> parameters) { |
104 | 0 | WebRuleUtils.processRuleForCopy(document.getDocumentNumber(), getOldRule(document), getNewRule(document)); |
105 | 0 | super.processAfterCopy(document, parameters); |
106 | 0 | } |
107 | |
|
108 | |
@Override |
109 | |
public void processAfterEdit(MaintenanceDocument document, |
110 | |
Map<String, String[]> parameters) { |
111 | 0 | if (!getOldRule(document).getCurrentInd()) { |
112 | 0 | throw new RiceRuntimeException("Cannot edit a non-current version of a rule."); |
113 | |
} |
114 | 0 | WebRuleUtils.populateForCopyOrEdit(getOldRule(document), getNewRule(document)); |
115 | |
|
116 | 0 | getNewRule(document).setPreviousRuleId(getOldRule(document).getId()); |
117 | |
|
118 | 0 | getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber()); |
119 | 0 | super.processAfterEdit(document, parameters); |
120 | 0 | } |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
protected RuleBaseValues getNewRule(MaintenanceDocument document) { |
126 | 0 | return (RuleBaseValues)document.getNewMaintainableObject().getBusinessObject(); |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
protected RuleBaseValues getOldRule(MaintenanceDocument document) { |
133 | 0 | return (RuleBaseValues)document.getOldMaintainableObject().getBusinessObject(); |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
protected RuleBaseValues getThisRule() { |
140 | 0 | return (RuleBaseValues)getBusinessObject(); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
@Override |
154 | |
public List<MaintenanceLock> generateMaintenanceLocks() { |
155 | 0 | if (getThisRule().getPreviousRuleId() == null) { |
156 | 0 | return Collections.emptyList(); |
157 | |
} |
158 | 0 | return super.generateMaintenanceLocks(); |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
public String getDocumentTitle(MaintenanceDocument document) { |
163 | 0 | StringBuffer title = new StringBuffer(); |
164 | 0 | RuleBaseValues rule = getThisRule(); |
165 | 0 | if (rule.getPreviousRuleId() != null) { |
166 | 0 | title.append("Editing Rule '").append(rule.getDescription()).append("'"); |
167 | |
} else { |
168 | 0 | title.append("Adding Rule '").append(rule.getDescription()).append("'"); |
169 | |
} |
170 | 0 | return title.toString(); |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
@Override |
179 | |
public void prepareForSave() { |
180 | 0 | super.prepareForSave(); |
181 | 0 | WebRuleUtils.translateResponsibilitiesForSave(getThisRule()); |
182 | 0 | } |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
@Override |
188 | |
protected void setNewCollectionLineDefaultValues(String collectionName, |
189 | |
PersistableBusinessObject addLine) { |
190 | 0 | super.setNewCollectionLineDefaultValues(collectionName, addLine); |
191 | 0 | if (KEWPropertyConstants.RESP_SECTION_NAME_SET.contains(collectionName)) { |
192 | 0 | RuleTemplateBo ruleTemplate = getThisRule().getRuleTemplate(); |
193 | |
|
194 | |
|
195 | |
|
196 | 0 | if(ruleTemplate.getDefaultActionRequestValue() != null && ruleTemplate.getDefaultActionRequestValue().getValue() != null){ |
197 | 0 | ((RuleResponsibilityBo) addLine).setActionRequestedCd(ruleTemplate.getDefaultActionRequestValue().getValue()); |
198 | |
} |
199 | |
} |
200 | 0 | } |
201 | |
|
202 | |
} |