1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document;
17
18 import java.util.Map;
19 import java.util.Set;
20
21 import org.apache.log4j.Logger;
22 import org.kuali.ole.sys.OLEConstants;
23 import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
24 import org.kuali.ole.sys.context.SpringContext;
25
26 import org.kuali.ole.sys.document.service.FinancialSystemDocumentService;
27 import org.kuali.ole.sys.service.impl.OleParameterConstants;
28 import org.kuali.rice.core.api.util.type.KualiDecimal;
29 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
30 import org.kuali.rice.kew.api.WorkflowRuntimeException;
31 import org.kuali.rice.kew.api.exception.WorkflowException;
32 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
33 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
34 import org.kuali.rice.kns.service.DocumentHelperService;
35 import org.kuali.rice.krad.bo.DocumentHeader;
36 import org.kuali.rice.krad.document.TransactionalDocumentBase;
37 import org.kuali.rice.krad.service.BusinessObjectService;
38 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
39 import org.kuali.rice.krad.util.GlobalVariables;
40
41
42
43
44 public class FinancialSystemTransactionalDocumentBase extends TransactionalDocumentBase implements FinancialSystemTransactionalDocument {
45 private static final Logger LOG = Logger.getLogger(FinancialSystemTransactionalDocumentBase.class);
46
47 protected static final String UPDATE_TOTAL_AMOUNT_IN_POST_PROCESSING_PARAMETER_NAME = "UPDATE_TOTAL_AMOUNT_IN_POST_PROCESSING_IND";
48
49 private static transient BusinessObjectService businessObjectService;
50 private static transient FinancialSystemDocumentService financialSystemDocumentService;
51 private static transient ParameterService parameterService;
52 private FinancialSystemDocumentHeader financialSystemDocumentHeader = new FinancialSystemDocumentHeader();
53
54 private transient Map<String,Boolean> canEditCache;
55
56
57
58
59 public FinancialSystemTransactionalDocumentBase() {
60 super();
61 }
62
63 @Override
64 public FinancialSystemDocumentHeader getFinancialSystemDocumentHeader() {
65
66
67
68 return this.financialSystemDocumentHeader;
69 }
70
71 public void setFinancialSystemDocumentHeader(FinancialSystemDocumentHeader financialSystemDocumentHeader) {
72
73 this.financialSystemDocumentHeader = financialSystemDocumentHeader;
74
75 }
76
77
78
79 @Override
80 public void setDocumentHeader(DocumentHeader documentHeader) {
81 super.setDocumentHeader(documentHeader);
82 getFinancialSystemDocumentHeader().setDocumentNumber(documentHeader.getDocumentNumber());
83 }
84
85
86
87
88
89
90
91
92
93
94
95 @Override
96 public void prepareForSave() {
97 if (this instanceof AmountTotaling) {
98 getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(((AmountTotaling) this).getTotalDollarAmount());
99 }
100 super.prepareForSave();
101 }
102
103
104
105
106
107
108 @Override
109 public void processAfterRetrieve() {
110
111 try {
112 DocumentHeader correctingDocumentHeader = KRADServiceLocatorWeb.getDocumentHeaderService().getDocumentHeaderById(getDocumentHeader().getWorkflowDocument().getDocumentId());
113
114 if (correctingDocumentHeader != null) {
115 getFinancialSystemDocumentHeader().setCorrectedByDocumentId(correctingDocumentHeader.getDocumentNumber());
116 }
117 } catch (Exception e) {
118 LOG.error("Received WorkflowException trying to get route header id from workflow document.", e);
119 throw new WorkflowRuntimeException(e);
120 }
121
122
123
124 super.processAfterRetrieve();
125 }
126
127
128
129
130
131
132 @Override
133 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
134 if (getDocumentHeader().getWorkflowDocument().isCanceled()) {
135 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.CANCELLED);
136 }
137 else if (getDocumentHeader().getWorkflowDocument().isEnroute()) {
138 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.ENROUTE);
139 }
140 if (getDocumentHeader().getWorkflowDocument().isDisapproved()) {
141 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.DISAPPROVED);
142 }
143 if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
144 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.APPROVED);
145 }
146 if ( LOG.isInfoEnabled() ) {
147 LOG.info("Document: " + statusChangeEvent.getDocumentId() + " -- Status is: " + getFinancialSystemDocumentHeader().getFinancialDocumentStatusCode());
148 }
149
150 super.doRouteStatusChange(statusChangeEvent);
151 }
152
153
154
155
156
157
158 @Override
159 public void doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) {
160 if (this instanceof AmountTotaling
161 && getDocumentHeader() != null
162 && getParameterService() != null
163 && getBusinessObjectService() != null
164 && getParameterService().parameterExists(OleParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class, UPDATE_TOTAL_AMOUNT_IN_POST_PROCESSING_PARAMETER_NAME)
165 && getParameterService().getParameterValueAsBoolean(OleParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class, UPDATE_TOTAL_AMOUNT_IN_POST_PROCESSING_PARAMETER_NAME)) {
166 final KualiDecimal currentTotal = ((AmountTotaling)this).getTotalDollarAmount();
167 if (!currentTotal.equals(getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount())) {
168 getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(currentTotal);
169 KRADServiceLocatorWeb.getLegacyDataAdapter().save(getFinancialSystemDocumentHeader());
170 }
171 }
172 super.doRouteLevelChange(levelChangeEvent);
173 }
174
175
176
177
178 public void toErrorCorrection() throws WorkflowException, IllegalStateException {
179 DocumentHelperService documentHelperService = SpringContext.getBean(DocumentHelperService.class);
180 final Set<String> documentActionsFromPresentationController = documentHelperService.getDocumentPresentationController(this).getDocumentActions(this);
181 final Set<String> documentActionsFromAuthorizer = documentHelperService.getDocumentAuthorizer(this).getDocumentActions(this, GlobalVariables.getUserSession().getPerson(), documentActionsFromPresentationController);
182 if (!documentActionsFromAuthorizer.contains(OLEConstants.KFS_ACTION_CAN_ERROR_CORRECT)) {
183 throw new IllegalStateException(this.getClass().getName() + " does not support document-level error correction");
184 }
185
186 String sourceDocumentHeaderId = getDocumentNumber();
187 setNewDocumentHeader();
188 getFinancialSystemDocumentHeader().setFinancialDocumentInErrorNumber(sourceDocumentHeaderId);
189 addCopyErrorDocumentNote("error-correction for document " + sourceDocumentHeaderId);
190 }
191
192 @Override
193 public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
194 throw new UnsupportedOperationException("No split node logic defined for split node "+nodeName+" on " + this.getClass().getSimpleName());
195 }
196
197
198
199
200 protected ParameterService getParameterService() {
201 if (parameterService == null) {
202 parameterService = SpringContext.getBean(ParameterService.class);
203 }
204 return parameterService;
205 }
206
207
208
209
210 protected BusinessObjectService getBusinessObjectService() {
211 if (businessObjectService == null) {
212 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
213 }
214 return businessObjectService;
215 }
216
217 protected FinancialSystemDocumentService getFinancialSystemDocumentService() {
218 if (financialSystemDocumentService == null) {
219 financialSystemDocumentService = SpringContext.getBean(FinancialSystemDocumentService.class);
220 }
221 return financialSystemDocumentService;
222 }
223
224 @Override
225 public void toCopy() throws WorkflowException, IllegalStateException {
226 FinancialSystemDocumentHeader oldDocumentHeader = getFinancialSystemDocumentHeader();
227 super.toCopy();
228
229 getFinancialSystemDocumentService().prepareToCopy(oldDocumentHeader, this);
230 }
231
232
233
234
235
236
237
238 public void updateAndSaveAppDocStatus(String applicationDocumentStatus) throws WorkflowException {
239 getFinancialSystemDocumentHeader().updateAndSaveAppDocStatus(applicationDocumentStatus);
240 }
241
242
243
244
245
246
247
248 public String getApplicationDocumentStatus() {
249 return getFinancialSystemDocumentHeader().getApplicationDocumentStatus();
250 }
251
252
253
254
255
256
257
258
259
260
261 public void setApplicationDocumentStatus(String applicationDocumentStatus) {
262 getFinancialSystemDocumentHeader().setApplicationDocumentStatus(applicationDocumentStatus);
263 }
264 }