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
20 import org.apache.log4j.Logger;
21 import org.kuali.ole.sys.OLEConstants;
22 import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.sys.document.dataaccess.FinancialSystemDocumentHeaderDao;
25 import org.kuali.rice.kew.api.WorkflowRuntimeException;
26 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
27 import org.kuali.rice.kim.api.identity.Person;
28 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29 import org.kuali.rice.kns.document.MaintenanceDocumentBase;
30 import org.kuali.rice.krad.bo.DocumentHeader;
31
32
33
34
35 public class FinancialSystemMaintenanceDocument extends MaintenanceDocumentBase implements FinancialSystemDocument {
36 private static final Logger LOG = Logger.getLogger(FinancialSystemMaintenanceDocument.class);
37
38 private transient Map<String,Boolean> canEditCache;
39
40
41
42
43 public FinancialSystemMaintenanceDocument() {
44 super();
45 }
46
47
48
49
50
51 public FinancialSystemMaintenanceDocument(String documentTypeName) {
52 super(documentTypeName);
53 }
54
55
56
57
58 @Override
59 public void setDocumentHeader(DocumentHeader documentHeader) {
60 if ((documentHeader != null) && (!FinancialSystemDocumentHeader.class.isAssignableFrom(documentHeader.getClass()))) {
61 throw new IllegalArgumentException("document header of class '" + documentHeader.getClass() + "' is not assignable from financial document header class '" + FinancialSystemDocumentHeader.class + "'");
62 }
63 this.documentHeader = documentHeader;
64 }
65
66
67
68
69
70
71 @Override
72 public void processAfterRetrieve() {
73
74 try {
75 DocumentHeader correctingDocumentHeader = SpringContext.getBean(FinancialSystemDocumentHeaderDao.class).getCorrectingDocumentHeader(getDocumentHeader().getWorkflowDocument().getDocumentId());
76 if (correctingDocumentHeader != null) {
77 getFinancialSystemDocumentHeader().setCorrectedByDocumentId(correctingDocumentHeader.getDocumentNumber());
78 }
79 } catch (RuntimeException e) {
80 LOG.error("Received WorkflowException trying to get route header id from workflow document");
81 throw new WorkflowRuntimeException(e);
82 }
83
84
85
86 super.processAfterRetrieve();
87 }
88
89
90
91
92
93
94 @Override
95 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
96 if (getDocumentHeader().getWorkflowDocument().isCanceled()) {
97 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.CANCELLED);
98 }
99 else if (getDocumentHeader().getWorkflowDocument().isEnroute()) {
100 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.ENROUTE);
101 }
102 if (getDocumentHeader().getWorkflowDocument().isDisapproved()) {
103 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.DISAPPROVED);
104 }
105 if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
106 getFinancialSystemDocumentHeader().setFinancialDocumentStatusCode(OLEConstants.DocumentStatusCodes.APPROVED);
107 }
108 if ( LOG.isInfoEnabled() ) {
109 LOG.info("Status is: " + getFinancialSystemDocumentHeader().getFinancialDocumentStatusCode());
110 }
111
112 super.doRouteStatusChange(statusChangeEvent);
113 }
114
115 @Override
116 public boolean answerSplitNodeQuestion(String nodeName) {
117 if (getNewMaintainableObject() == null) {
118 throw new UnsupportedOperationException("Cannot access Maintainable class to answer split node question");
119 }
120 if (getNewMaintainableObject() instanceof FinancialSystemMaintainable) {
121 return ((FinancialSystemMaintainable)getNewMaintainableObject()).answerSplitNodeQuestion(nodeName);
122 } else if (getNewMaintainableObject() instanceof FinancialSystemGlobalMaintainable) {
123 return ((FinancialSystemGlobalMaintainable)getNewMaintainableObject()).answerSplitNodeQuestion(nodeName);
124 } else {
125 throw new UnsupportedOperationException("Maintainable for "+getNewMaintainableObject().getBoClass().getName()+" does not extend org.kuali.ole.sys.document.FinancialSystemMaintainable nor org.kuali.ole.sys.document.FinancialSystemGlobalMaintainable and therefore cannot answer split node question");
126 }
127 }
128
129
130
131
132
133 public String getInitiatorChartOfAccountsCode() {
134 String[] chartOrg = getInitiatorPrimaryDepartmentCode();
135 return chartOrg[0];
136 }
137
138
139
140
141
142 public String getInitiatorOrganizationCode() {
143 String[] chartOrg = getInitiatorPrimaryDepartmentCode();
144 return chartOrg[1];
145 }
146
147
148
149
150
151
152
153 protected String[] getInitiatorPrimaryDepartmentCode() {
154
155 String netID = documentHeader.getWorkflowDocument().getInitiatorPrincipalId();
156 Person person = KimApiServiceLocator.getPersonService().getPerson(netID);
157
158 String deptCode = person.getPrimaryDepartmentCode();
159 String[] chartOrg = deptCode.split("-");
160 return chartOrg;
161
162 }
163
164 @Override
165 public FinancialSystemDocumentHeader getFinancialSystemDocumentHeader() {
166 return (FinancialSystemDocumentHeader)documentHeader;
167 }
168
169 }
170