1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.authorization;
17
18 import java.util.Set;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.fp.businessobject.CashDrawer;
22 import org.kuali.ole.fp.document.CashManagementDocument;
23 import org.kuali.ole.fp.document.service.CashManagementService;
24 import org.kuali.ole.fp.service.CashDrawerService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEConstants.CashDrawerConstants;
27 import org.kuali.ole.sys.OleAuthorizationConstants;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.sys.document.authorization.LedgerPostingDocumentPresentationControllerBase;
30 import org.kuali.rice.kew.api.WorkflowDocument;
31 import org.kuali.rice.kew.api.action.ActionType;
32 import org.kuali.rice.kew.api.action.ValidActions;
33 import org.kuali.rice.kns.service.DataDictionaryService;
34 import org.kuali.rice.krad.document.Document;
35 import org.kuali.rice.krad.service.MaintenanceDocumentService;
36
37 public class CashManagementDocumentPresentationControllerBase extends LedgerPostingDocumentPresentationControllerBase implements CashManagementDocumentPresentationController {
38
39
40
41
42 @Override
43 public Set<String> getEditModes(Document document) {
44 Set<String> editModes = super.getEditModes(document);
45
46 if (!this.canHaveBankEntry(document)) {
47 editModes.add(OLEConstants.BANK_ENTRY_VIEWABLE_EDITING_MODE);
48 }
49
50 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
51 if (workflowDocument.isSaved()) {
52 editModes.add(OleAuthorizationConstants.CashManagementEditMode.ALLOW_CANCEL_DEPOSITS);
53
54 CashManagementDocument cashManagementDocument = (CashManagementDocument) document;
55 if (!cashManagementDocument.hasFinalDeposit()) {
56 editModes.add(OleAuthorizationConstants.CashManagementEditMode.ALLOW_ADDITIONAL_DEPOSITS);
57 }
58 }
59
60 return editModes;
61 }
62
63
64
65
66 @Override
67 public boolean canApprove(Document document) {
68 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
69 if (workflowDocument.isEnroute()) {
70 ValidActions validActions = workflowDocument.getValidActions();
71 return validActions.getValidActions().contains(ActionType.APPROVE);
72 }
73
74 return super.canApprove(document);
75 }
76
77
78
79
80 @Override
81 public boolean canBlanketApprove(Document document) {
82 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
83 if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
84 CashManagementDocument cmDoc = (CashManagementDocument) document;
85 if (!cmDoc.hasFinalDeposit() || !SpringContext.getBean(CashManagementService.class).allVerifiedCashReceiptsAreDeposited(cmDoc)) {
86 return false;
87 }
88
89
90 ValidActions validActions = workflowDocument.getValidActions();
91 return validActions.getValidActions().contains(ActionType.BLANKET_APPROVE);
92 }
93
94 return super.canBlanketApprove(document);
95 }
96
97
98
99
100 @Override
101 public boolean canCancel(Document document) {
102 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
103 if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
104 CashManagementDocument cmDoc = (CashManagementDocument) document;
105 if (!SpringContext.getBean(CashManagementService.class).allowDocumentCancellation(cmDoc)) {
106 return false;
107 }
108
109
110 ValidActions validActions = workflowDocument.getValidActions();
111 return validActions.getValidActions().contains(ActionType.CANCEL);
112 }
113
114 return super.canCancel(document);
115 }
116
117
118
119
120 @Override
121 public boolean canDisapprove(Document document) {
122 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
123 if (workflowDocument.isEnroute()) {
124 ValidActions validActions = workflowDocument.getValidActions();
125 return validActions.getValidActions().contains(ActionType.DISAPPROVE);
126 }
127
128 return super.canDisapprove(document);
129 }
130
131
132
133
134 @Override
135 public boolean canRoute(Document document) {
136 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
137 if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
138 CashManagementDocument cmDoc = (CashManagementDocument) document;
139 if (!cmDoc.hasFinalDeposit() || !SpringContext.getBean(CashManagementService.class).allVerifiedCashReceiptsAreDeposited(cmDoc)) {
140 return false;
141 }
142
143
144 ValidActions validActions = workflowDocument.getValidActions();
145 return validActions.getValidActions().contains(ActionType.ROUTE);
146 }
147
148 return super.canRoute(document);
149 }
150
151
152
153
154 @Override
155 public boolean canSave(Document document) {
156 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
157 if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
158 CashManagementDocument cmDoc = (CashManagementDocument) document;
159 if (cmDoc.getCashDrawerStatus() == null || cmDoc.getCashDrawerStatus().equals(CashDrawerConstants.STATUS_CLOSED)) {
160 return false;
161 }
162
163
164 ValidActions validActions = workflowDocument.getValidActions();
165 return validActions.getValidActions().contains(ActionType.SAVE);
166 }
167
168 return super.canRoute(document);
169 }
170
171
172
173
174 @Override
175 public boolean canAddAdhocRequests(Document document) {
176 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
177 if (workflowDocument.isEnroute()) {
178 ValidActions validActions = workflowDocument.getValidActions();
179 return validActions.getValidActions().contains(ActionType.ADHOC_REQUEST);
180 }
181
182 return super.canAddAdhocRequests(document);
183 }
184
185
186
187
188
189
190
191
192
193
194 @Override
195 public boolean canOpenCashDrawer(Document document) {
196 final CashDrawer cashDrawer = retrieveCashDrawer(document);
197 return cashDrawer.isClosed() && noExistCashDrawerMaintLocks(cashDrawer, document.getDocumentNumber());
198 }
199
200
201
202
203
204
205 protected CashDrawer retrieveCashDrawer(Document document) {
206 final CashManagementDocument cmDoc = (CashManagementDocument)document;
207 final CashDrawer cashDrawer = SpringContext.getBean(CashDrawerService.class).getByCampusCode(cmDoc.getCampusCode());
208 return cashDrawer;
209 }
210
211
212
213
214
215
216 protected boolean noExistCashDrawerMaintLocks(CashDrawer cashDrawer, String documentNumber) {
217 final org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry cashDrawerMaintDocEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getMaintenanceDocumentEntryForBusinessObjectClass(cashDrawer.getClass());
218 org.kuali.rice.krad.maintenance.Maintainable cashDrawerMaintainable = createCashDrawerMaintainable(cashDrawerMaintDocEntry);
219 cashDrawerMaintainable.setDataObjectClass(cashDrawer.getClass());
220 cashDrawerMaintainable.setDataObject(cashDrawer);
221 cashDrawerMaintainable.setDocumentNumber(documentNumber);
222
223 final String lockingDocument = SpringContext.getBean(MaintenanceDocumentService.class).getLockingDocumentId(cashDrawerMaintainable, documentNumber);
224 return StringUtils.isBlank(lockingDocument);
225 }
226
227
228
229
230
231
232 protected org.kuali.rice.krad.maintenance.Maintainable createCashDrawerMaintainable(org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry cashDrawerMaintenanceDocumentEntry) {
233 org.kuali.rice.krad.maintenance.Maintainable cashDrawerMaintainable;
234 try {
235 cashDrawerMaintainable = cashDrawerMaintenanceDocumentEntry.getMaintainableClass().newInstance();
236 }
237 catch (InstantiationException ie) {
238 throw new RuntimeException("Cannot instantiate instance of maintainable implementation "+cashDrawerMaintenanceDocumentEntry.getMaintainableClass().getName(), ie);
239 }
240 catch (IllegalAccessException iae) {
241 throw new RuntimeException("Illegal access occurred while instantiating instance of maintainable implementation "+cashDrawerMaintenanceDocumentEntry.getMaintainableClass().getName(), iae);
242 }
243 return cashDrawerMaintainable;
244 }
245
246 @Override
247 public Set<String> getDocumentActions(Document document) {
248 Set<String> documentActions = super.getDocumentActions(document);
249
250 if (!canHaveBankEntry(document)) {
251 documentActions.add(OLEConstants.KFS_ACTION_CAN_EDIT_BANK);
252 }
253
254 return documentActions;
255 }
256 }