1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.module.purap.document;
18
19 import org.kuali.ole.module.purap.PurapParameterConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.PurapWorkflowConstants;
22 import org.kuali.ole.module.purap.businessobject.ContractManagerAssignmentDetail;
23 import org.kuali.ole.module.purap.document.service.RequisitionService;
24 import org.kuali.ole.select.document.service.OlePurchaseOrderService;
25 import org.kuali.ole.sys.DynamicCollectionComparator;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.FinancialSystemTransactionalDocumentBase;
28 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
29 import org.kuali.rice.kew.api.WorkflowDocument;
30 import org.kuali.rice.kew.api.action.ActionRequestType;
31 import org.kuali.rice.kew.api.document.DocumentStatus;
32 import org.kuali.rice.kew.api.exception.WorkflowException;
33 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
34 import org.kuali.rice.krad.document.Document;
35 import org.kuali.rice.krad.service.DocumentService;
36
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.Set;
40
41 public class ContractManagerAssignmentDocument extends FinancialSystemTransactionalDocumentBase {
42 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ContractManagerAssignmentDocument.class);
43
44 protected List<ContractManagerAssignmentDetail> contractManagerAssignmentDetails = new ArrayList<ContractManagerAssignmentDetail>();
45
46
47 protected String requisitionNumber;
48 protected String deliveryCampusCode;
49 protected String vendorName;
50 protected String generalDescription;
51 protected String requisitionTotalAmount;
52 protected String requisitionCreateDate;
53 protected String firstItemDescription;
54 protected String firstItemCommodityCode;
55 protected String firstObjectCode;
56 protected String universityFiscalYear;
57
58
59
60
61
62 public ContractManagerAssignmentDocument() {
63 super();
64 }
65
66 public ContractManagerAssignmentDetail getContractManagerAssignmentDetail(int index) {
67 while (contractManagerAssignmentDetails.size() <= index) {
68 contractManagerAssignmentDetails.add(new ContractManagerAssignmentDetail());
69 }
70 return (ContractManagerAssignmentDetail) contractManagerAssignmentDetails.get(index);
71 }
72
73
74
75
76
77 public void populateDocumentWithRequisitions() {
78 LOG.debug("populateDocumentWithRequisitions() Entering method.");
79
80 List<RequisitionDocument> unassignedRequisitions = new ArrayList(SpringContext.getBean(RequisitionService.class).getRequisitionsAwaitingContractManagerAssignment());
81 List<String> documentHeaderIds = new ArrayList();
82 for (RequisitionDocument req : unassignedRequisitions) {
83 documentHeaderIds.add(req.getDocumentNumber());
84 }
85
86 List<Document> requisitionDocumentsFromDocService = new ArrayList();
87 try {
88 if (documentHeaderIds.size() > 0)
89 requisitionDocumentsFromDocService = SpringContext.getBean(DocumentService.class).getDocumentsByListOfDocumentHeaderIds(RequisitionDocument.class, documentHeaderIds);
90 } catch (WorkflowException we) {
91 String errorMsg = "Workflow Exception caught: " + we.getLocalizedMessage();
92 LOG.error(errorMsg, we);
93 throw new RuntimeException(errorMsg, we);
94 }
95
96 for (Document req : requisitionDocumentsFromDocService) {
97 contractManagerAssignmentDetails.add(new ContractManagerAssignmentDetail(this, (RequisitionDocument) req));
98 }
99
100 String[] fieldNames = {PurapPropertyConstants.DELIVERY_CAMPUS_CODE, PurapPropertyConstants.VENDOR_NAME, PurapPropertyConstants.REQUISITION_IDENTIFIER};
101 DynamicCollectionComparator.sort(contractManagerAssignmentDetails, fieldNames);
102 LOG.debug("populateDocumentWithRequisitions() Leaving method.");
103 }
104
105 @Override
106 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
107 LOG.debug("doRouteStatusChange() Entering method.");
108
109 super.doRouteStatusChange(statusChangeEvent);
110
111 if (this.getDocumentHeader().getWorkflowDocument().isProcessed()) {
112 boolean isSuccess = true;
113 StringBuffer failedReqs = new StringBuffer();
114 SpringContext.getBean(OlePurchaseOrderService.class).processACMReq(this);
115
116 if (!isSuccess) {
117 failedReqs.deleteCharAt(failedReqs.lastIndexOf(","));
118 WorkflowDocument workflowDoc = this.getDocumentHeader().getWorkflowDocument();
119 String currentNodeName = null;
120 try {
121 currentNodeName = PurapWorkflowConstants.DOC_ADHOC_NODE_NAME;
122 if (!(DocumentStatus.INITIATED.equals(workflowDoc.getStatus()))) {
123 if (this.getCurrentRouteNodeName(workflowDoc) != null) {
124 currentNodeName = this.getCurrentRouteNodeName(workflowDoc);
125 }
126 }
127 workflowDoc.adHocToPrincipal(ActionRequestType.FYI, currentNodeName, PurapWorkflowConstants.ContractManagerAssignmentDocument.ASSIGN_CONTRACT_DOC_ERROR_COMPLETING_POST_PROCESSING + failedReqs, workflowDoc.getInitiatorPrincipalId(), "Initiator", true);
128 } catch (WorkflowException e) {
129
130 }
131 }
132 }
133 LOG.debug("doRouteStatusChange() Leaving method.");
134 }
135
136
137
138
139
140
141 protected String getCurrentRouteNodeName(WorkflowDocument wd) throws WorkflowException {
142 Set<String> nodeNames = wd.getCurrentNodeNames();
143 if (nodeNames == null || nodeNames.isEmpty()) {
144 return null;
145 } else {
146 return nodeNames.iterator().next();
147 }
148 }
149
150
151
152
153 @Override
154 public String getDocumentTitle() {
155 String title = "";
156 if (SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(ContractManagerAssignmentDocument.class, PurapParameterConstants.PURAP_OVERRIDE_ASSIGN_CONTRACT_MGR_DOC_TITLE)) {
157 title = PurapWorkflowConstants.ContractManagerAssignmentDocument.WORKFLOW_DOCUMENT_TITLE;
158 } else {
159 title = super.getDocumentTitle();
160 }
161 return title;
162 }
163
164 public List getContractManagerAssignmentDetails() {
165 return contractManagerAssignmentDetails;
166 }
167
168 public void setContractManagerAssignmentDetailss(List contractManagerAssignmentDetails) {
169 this.contractManagerAssignmentDetails = contractManagerAssignmentDetails;
170 }
171
172
173
174
175
176
177 public String getFirstObjectCode() {
178 return firstObjectCode;
179 }
180
181
182
183
184
185
186 public String getDeliveryCampusCode() {
187 return deliveryCampusCode;
188 }
189
190
191
192
193
194
195 public String getFirstItemDescription() {
196 return firstItemDescription;
197 }
198
199
200
201
202
203
204 public String getFirstItemCommodityCode() {
205 return firstItemCommodityCode;
206 }
207
208
209
210
211
212
213 public String getGeneralDescription() {
214 return generalDescription;
215 }
216
217
218
219
220
221
222 public String getRequisitionCreateDate() {
223 return requisitionCreateDate;
224 }
225
226
227
228
229
230
231 public String getRequisitionNumber() {
232 return requisitionNumber;
233 }
234
235
236
237
238
239
240 public String getRequisitionTotalAmount() {
241 return requisitionTotalAmount;
242 }
243
244
245
246
247
248
249 public String getVendorName() {
250 return vendorName;
251 }
252
253 public String getUniversityFiscalYear() {
254 return universityFiscalYear;
255 }
256
257 }