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.RuleDelegationBo;
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 public class RoutingRuleDelegationMaintainable extends KualiMaintainableImpl {
41
42
43
44
45
46 @Override
47 public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
48 List<Section> sections = super.getSections(document, oldMaintainable);
49 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 initializeBusinessObjects(document);
59 WebRuleUtils.validateRuleAndResponsibility(getOldRuleDelegation(document), getNewRuleDelegation(document), parameters);
60 WebRuleUtils.validateRuleTemplateAndDocumentType(getOldRule(document), getNewRule(document), parameters);
61 WebRuleUtils.establishDefaultRuleValues(getNewRule(document));
62 getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber());
63 }
64
65
66
67
68
69 private void initializeBusinessObjects(MaintenanceDocument document) {
70 RuleDelegationBo oldRuleDelegation = getOldRuleDelegation(document);
71 RuleDelegationBo newRuleDelegation = getNewRuleDelegation(document);
72 if (oldRuleDelegation.getDelegationRule() == null) {
73 oldRuleDelegation.setDelegationRule(new RuleBaseValues());
74 }
75 if (newRuleDelegation.getDelegationRule() == null) {
76 newRuleDelegation.setDelegationRule(new RuleBaseValues());
77 }
78 }
79
80
81
82
83
84
85
86 @Override
87 public void setGenerateDefaultValues(String docTypeName) {
88
89 }
90
91
92
93
94 @Override
95 public void saveBusinessObject() {
96 WebRuleUtils.clearKeysForSave(getThisRuleDelegation());
97 WebRuleUtils.translateResponsibilitiesForSave(getThisRule());
98 WebRuleUtils.translateFieldValuesForSave(getThisRule());
99 WebRuleUtils.processRuleForDelegationSave(getThisRuleDelegation());
100 KEWServiceLocator.getRuleService().makeCurrent(getThisRuleDelegation(), true);
101 }
102
103
104
105
106 @Override
107 public void saveDataObject() {
108 WebRuleUtils.clearKeysForSave(getThisRuleDelegation());
109 WebRuleUtils.translateResponsibilitiesForSave(getThisRule());
110 WebRuleUtils.translateFieldValuesForSave(getThisRule());
111 WebRuleUtils.processRuleForDelegationSave(getThisRuleDelegation());
112 KEWServiceLocator.getRuleService().makeCurrent(getThisRuleDelegation(), true);
113 }
114
115 @Override
116 public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> parameters) {
117 WebRuleUtils.processRuleForCopy(document.getDocumentNumber(), getOldRule(document), getNewRule(document));
118 super.processAfterCopy(document, parameters);
119 }
120
121 @Override
122 public void processAfterEdit(MaintenanceDocument document,
123 Map<String, String[]> parameters) {
124 if (!getOldRule(document).getCurrentInd()) {
125 throw new RiceRuntimeException("Cannot edit a non-current version of a rule.");
126 }
127 WebRuleUtils.populateForCopyOrEdit(getOldRule(document), getNewRule(document));
128 getNewRule(document).setPreviousRuleId(getOldRule(document).getId());
129 getNewRule(document).setDocumentId(document.getDocumentHeader().getDocumentNumber());
130 super.processAfterEdit(document, parameters);
131 }
132
133
134 @Override
135 public List<MaintenanceLock> generateMaintenanceLocks() {
136 if (getThisRule().getId() == null) {
137 return Collections.emptyList();
138 }
139 return super.generateMaintenanceLocks();
140 }
141
142 @Override
143 public String getDocumentTitle(MaintenanceDocument document) {
144 StringBuffer title = new StringBuffer();
145 RuleBaseValues rule = getThisRule();
146 if (rule.getPreviousRuleId() != null) {
147 title.append("Editing Rule Delegation '").append(rule.getDescription()).append("'");
148 } else {
149 title.append("Adding Rule Delegation '").append(rule.getDescription()).append("'");
150 }
151 return title.toString();
152 }
153
154 protected RuleDelegationBo getNewRuleDelegation(MaintenanceDocument document) {
155 return (RuleDelegationBo)document.getNewMaintainableObject().getBusinessObject();
156 }
157
158 protected RuleDelegationBo getOldRuleDelegation(MaintenanceDocument document) {
159 return (RuleDelegationBo)document.getOldMaintainableObject().getBusinessObject();
160 }
161
162 protected RuleDelegationBo getThisRuleDelegation() {
163 return (RuleDelegationBo)getDataObject();
164 }
165
166 protected RuleBaseValues getNewRule(MaintenanceDocument document) {
167 return getNewRuleDelegation(document).getDelegationRule();
168 }
169
170 protected RuleBaseValues getOldRule(MaintenanceDocument document) {
171 return getOldRuleDelegation(document).getDelegationRule();
172 }
173
174 protected RuleBaseValues getThisRule() {
175 return getThisRuleDelegation().getDelegationRule();
176 }
177
178
179
180
181
182
183 @Override
184 public void prepareForSave() {
185 super.prepareForSave();
186 WebRuleUtils.translateResponsibilitiesForSave(getThisRule());
187 }
188
189
190
191
192 }