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