001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.kuali.module.purap.document;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.apache.commons.lang.StringUtils;
026: import org.kuali.core.document.TransactionalDocumentBase;
027: import org.kuali.core.service.BusinessObjectService;
028: import org.kuali.core.util.ObjectUtils;
029: import org.kuali.core.workflow.service.KualiWorkflowDocument;
030: import org.kuali.kfs.context.SpringContext;
031: import org.kuali.kfs.service.ParameterService;
032: import org.kuali.module.purap.PurapConstants;
033: import org.kuali.module.purap.PurapParameterConstants;
034: import org.kuali.module.purap.PurapPropertyConstants;
035: import org.kuali.module.purap.PurapWorkflowConstants;
036: import org.kuali.module.purap.bo.AssignContractManagerDetail;
037: import org.kuali.module.purap.service.PurapService;
038: import org.kuali.module.purap.service.PurchaseOrderService;
039: import org.kuali.module.purap.service.RequisitionService;
040:
041: import edu.iu.uis.eden.EdenConstants;
042: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
043: import edu.iu.uis.eden.exception.WorkflowException;
044:
045: public class AssignContractManagerDocument extends
046: TransactionalDocumentBase {
047: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
048: .getLogger(AssignContractManagerDocument.class);
049:
050: private List<AssignContractManagerDetail> assignContractManagerDetails = new ArrayList();
051:
052: // Not persisted (only for labels in tag)
053: private String requisitionNumber;
054: private String deliveryCampusCode;
055: private String vendorName;
056: private String generalDescription;
057: private String requisitionTotalAmount;
058: private String requisitionCreateDate;
059: private String firstItemDescription;
060: private String firstObjectCode;
061:
062: /**
063: * Default constructor.
064: */
065: public AssignContractManagerDocument() {
066: super ();
067: }
068:
069: public AssignContractManagerDetail getAssignContractManagerDetail(
070: int index) {
071: while (assignContractManagerDetails.size() <= index) {
072: assignContractManagerDetails
073: .add(new AssignContractManagerDetail());
074: }
075: return (AssignContractManagerDetail) assignContractManagerDetails
076: .get(index);
077: }
078:
079: /**
080: * Perform logic needed to populate the Assign Contract Manager Document with requisitions in status of Awaiting Contract
081: * Manager Assignment.
082: */
083: public void populateDocumentWithRequisitions() {
084: LOG
085: .debug("populateDocumentWithRequisitions() Entering method.");
086:
087: Map fieldValues = new HashMap();
088: fieldValues
089: .put(
090: PurapPropertyConstants.STATUS_CODE,
091: PurapConstants.RequisitionStatuses.AWAIT_CONTRACT_MANAGER_ASSGN);
092: List<RequisitionDocument> unassignedRequisitions = new ArrayList(
093: SpringContext.getBean(BusinessObjectService.class)
094: .findMatchingOrderBy(RequisitionDocument.class,
095: fieldValues,
096: PurapPropertyConstants.PURAP_DOC_ID,
097: true));
098:
099: for (RequisitionDocument req : unassignedRequisitions) {
100: assignContractManagerDetails
101: .add(new AssignContractManagerDetail(this , req));
102: }
103: LOG.debug("populateDocumentWithRequisitions() Leaving method.");
104: }
105:
106: @Override
107: public void handleRouteStatusChange() {
108: LOG.debug("handleRouteStatusChange() Entering method.");
109:
110: super .handleRouteStatusChange();
111:
112: if (this .getDocumentHeader().getWorkflowDocument()
113: .stateIsProcessed()) {
114: boolean isSuccess = true;
115: StringBuffer failedReqs = new StringBuffer();
116: for (Iterator iter = this .getAssignContractManagerDetails()
117: .iterator(); iter.hasNext();) {
118: AssignContractManagerDetail detail = (AssignContractManagerDetail) iter
119: .next();
120:
121: if (ObjectUtils.isNotNull(detail
122: .getContractManagerCode())) {
123: // Get the requisition for this AssignContractManagerDetail.
124: RequisitionDocument req = SpringContext.getBean(
125: RequisitionService.class)
126: .getRequisitionById(
127: detail.getRequisitionIdentifier());
128:
129: if (req
130: .getStatusCode()
131: .equals(
132: PurapConstants.RequisitionStatuses.AWAIT_CONTRACT_MANAGER_ASSGN)) {
133: // only update REQ if code is empty and status is correct
134: SpringContext
135: .getBean(PurapService.class)
136: .updateStatus(
137: req,
138: PurapConstants.RequisitionStatuses.CLOSED);
139: SpringContext.getBean(RequisitionService.class)
140: .saveDocumentWithoutValidation(req);
141: SpringContext
142: .getBean(PurchaseOrderService.class)
143: .createPurchaseOrderDocument(
144: req,
145: this
146: .getDocumentHeader()
147: .getWorkflowDocument()
148: .getInitiatorNetworkId(),
149: detail.getContractManagerCode());
150:
151: }
152: }
153:
154: }// endfor
155:
156: if (!isSuccess) {
157: failedReqs.deleteCharAt(failedReqs.lastIndexOf(","));
158: KualiWorkflowDocument workflowDoc = this
159: .getDocumentHeader().getWorkflowDocument();
160: String currentNodeName = null;
161: try {
162: currentNodeName = PurapWorkflowConstants.DOC_ADHOC_NODE_NAME;
163: if (!(EdenConstants.ROUTE_HEADER_INITIATED_CD
164: .equals(workflowDoc.getRouteHeader()
165: .getDocRouteStatus()))) {
166: if (this .getCurrentRouteNodeName(workflowDoc) != null) {
167: currentNodeName = this
168: .getCurrentRouteNodeName(workflowDoc);
169: }
170: }
171: workflowDoc
172: .appSpecificRouteDocumentToUser(
173: EdenConstants.ACTION_REQUEST_FYI_REQ,
174: currentNodeName,
175: 0,
176: PurapWorkflowConstants.AssignContractManagerDocument.ASSIGN_CONTRACT_DOC_ERROR_COMPLETING_POST_PROCESSING
177: + failedReqs,
178: new NetworkIdVO(workflowDoc
179: .getInitiatorNetworkId()),
180: "Initiator", true);
181: } catch (WorkflowException e) {
182: // do nothing; document should have processed successfully and problem is with sending FYI
183: }
184: }
185: }
186: LOG.debug("handleRouteStatusChange() Leaving method.");
187: }
188:
189: private String getCurrentRouteNodeName(KualiWorkflowDocument wd)
190: throws WorkflowException {
191: String[] nodeNames = wd.getNodeNames();
192: if ((nodeNames == null) || (nodeNames.length == 0)) {
193: return null;
194: } else {
195: return nodeNames[0];
196: }
197: }
198:
199: /**
200: * @see org.kuali.core.document.Document#getDocumentTitle()
201: */
202: @Override
203: public String getDocumentTitle() {
204: String title = "";
205: String specificTitle = SpringContext
206: .getBean(ParameterService.class)
207: .getParameterValue(
208: AssignContractManagerDocument.class,
209: PurapParameterConstants.PURAP_OVERRIDE_ASSIGN_CONTRACT_MGR_DOC_TITLE);
210: if (StringUtils.equalsIgnoreCase(specificTitle, Boolean.TRUE
211: .toString())) {
212: title = PurapWorkflowConstants.AssignContractManagerDocument.WORKFLOW_DOCUMENT_TITLE;
213: } else {
214: title = super .getDocumentTitle();
215: }
216: return title;
217: }
218:
219: public List getAssignContractManagerDetails() {
220: return assignContractManagerDetails;
221: }
222:
223: public void setAssignContractManagerDetails(
224: List assignContractManagerDetails) {
225: this .assignContractManagerDetails = assignContractManagerDetails;
226: }
227:
228: /**
229: * Gets the firstObjectCode attribute.
230: *
231: * @return Returns the firstObjectCode.
232: */
233: public String getFirstObjectCode() {
234: return firstObjectCode;
235: }
236:
237: /**
238: * Gets the deliveryCampusCode attribute.
239: *
240: * @return Returns the deliveryCampusCode.
241: */
242: public String getDeliveryCampusCode() {
243: return deliveryCampusCode;
244: }
245:
246: /**
247: * Gets the firstItemDescription attribute.
248: *
249: * @return Returns the firstItemDescription.
250: */
251: public String getFirstItemDescription() {
252: return firstItemDescription;
253: }
254:
255: /**
256: * Gets the generalDescription attribute.
257: *
258: * @return Returns the generalDescription.
259: */
260: public String getGeneralDescription() {
261: return generalDescription;
262: }
263:
264: /**
265: * Gets the requisitionCreateDate attribute.
266: *
267: * @return Returns the requisitionCreateDate.
268: */
269: public String getRequisitionCreateDate() {
270: return requisitionCreateDate;
271: }
272:
273: /**
274: * Gets the requisitionNumber attribute.
275: *
276: * @return Returns the requisitionNumber.
277: */
278: public String getRequisitionNumber() {
279: return requisitionNumber;
280: }
281:
282: /**
283: * Gets the requisitionTotalAmount attribute.
284: *
285: * @return Returns the requisitionTotalAmount.
286: */
287: public String getRequisitionTotalAmount() {
288: return requisitionTotalAmount;
289: }
290:
291: /**
292: * Gets the vendorName attribute.
293: *
294: * @return Returns the vendorName.
295: */
296: public String getVendorName() {
297: return vendorName;
298: }
299:
300: }
|