View Javadoc
1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.businessobject;
17  
18  import org.kuali.ole.module.purap.PurapParameterConstants;
19  import org.kuali.ole.module.purap.document.ContractManagerAssignmentDocument;
20  import org.kuali.ole.module.purap.document.RequisitionDocument;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.vnd.businessobject.CommodityContractManager;
24  import org.kuali.ole.vnd.businessobject.ContractManager;
25  import org.kuali.rice.core.web.format.DateViewDateObjectFormatter;
26  import org.kuali.rice.core.web.format.Formatter;
27  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
28  import org.kuali.rice.kew.api.exception.WorkflowException;
29  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
30  
31  import java.util.LinkedHashMap;
32  import java.util.List;
33  
34  /**
35   * Assign Contract Manager Detail Business Object. Defines attributes in Assign Contract Manager tab.
36   */
37  public class ContractManagerAssignmentDetail extends PersistableBusinessObjectBase {
38  
39      private String documentNumber;
40      private Integer requisitionIdentifier;
41      private Integer contractManagerCode;
42      private String deliveryCampusCode;
43      private String vendorName;
44  
45      private RequisitionDocument requisition;
46      private ContractManager contractManager;
47      private ContractManagerAssignmentDocument contractManagerAssignmentDocument;
48  
49      private String createDate;
50  
51      /**
52       * Default constructor.
53       */
54      public ContractManagerAssignmentDetail() {
55  
56      }
57  
58      /**
59       * Constructs a ContractManagerAssignmentDetail object from an existing ContractManagerAssignmentDocument object.
60       *
61       * @param acmDocument         the ContractManagerAssignmentDocument to copy from.
62       * @param requisitionDocument reference to the related requisition document.
63       */
64      public ContractManagerAssignmentDetail(ContractManagerAssignmentDocument acmDocument, RequisitionDocument requisitionDocument) {
65          this.documentNumber = acmDocument.getDocumentNumber();
66          this.contractManagerAssignmentDocument = acmDocument;
67          this.requisition = requisitionDocument;
68          this.requisitionIdentifier = requisitionDocument.getPurapDocumentIdentifier();
69          this.deliveryCampusCode = requisitionDocument.getDeliveryCampusCode();
70          this.vendorName = requisitionDocument.getVendorName();
71      }
72  
73      public String getDocumentNumber() {
74          return documentNumber;
75      }
76  
77      public void setDocumentNumber(String documentNumber) {
78          this.documentNumber = documentNumber;
79      }
80  
81      public Integer getRequisitionIdentifier() {
82          return requisitionIdentifier;
83      }
84  
85      public void setRequisitionIdentifier(Integer requisitionIdentifier) {
86          this.requisitionIdentifier = requisitionIdentifier;
87      }
88  
89      /**
90       * Returns the default contract manager code if the first line item of the
91       * requisition contains commodity codes with one contract manager whose campus
92       * code matches the delivery campus code on the requisition. If there are more
93       * than one contract managers of the same campus code as the delivery code, we'll
94       * return null. If the first line item of the requisition does not contain commodity
95       * code, or contain commodity code that does not have contract manager, we'll
96       * also return null
97       *
98       * @return Integer the default contract manager code if applicable, or null.
99       */
100     public Integer getContractManagerCode() {
101         String paramName = PurapParameterConstants.ENABLE_DEFAULT_CONTRACT_MANAGER_IND;
102         String paramValue = SpringContext.getBean(ParameterService.class).getParameterValueAsString(ContractManagerAssignmentDocument.class, paramName);
103         if (paramValue.equals("Y") && (contractManagerCode == null) && getFirstLineItem().getCommodityCode() != null) {
104             List<CommodityContractManager> commodityContractManagers = getFirstLineItem().getCommodityCode().getCommodityContractManagers();
105             if (commodityContractManagers != null && commodityContractManagers.size() > 0) {
106                 int count = 0;
107                 Integer matchingContractManagerCode = null;
108                 for (CommodityContractManager commodityContractManager : commodityContractManagers) {
109                     if (this.getRequisition().getDeliveryCampusCode().equals(commodityContractManager.getCampusCode())) {
110                         count = count + 1;
111                         matchingContractManagerCode = commodityContractManager.getContractManagerCode();
112                     }
113                 }
114                 if (count == 1) {
115                     setContractManagerCode(matchingContractManagerCode);
116                     return contractManagerCode;
117                 }
118             }
119         }
120         return contractManagerCode;
121     }
122 
123     public void setContractManagerCode(Integer contractManagerCode) {
124         this.contractManagerCode = contractManagerCode;
125     }
126 
127     public ContractManager getContractManager() {
128         return contractManager;
129     }
130 
131     /**
132      * @deprecated
133      */
134     public void setContractManager(ContractManager contractManager) {
135         this.contractManager = contractManager;
136     }
137 
138     public RequisitionDocument getRequisition() {
139         return requisition;
140     }
141 
142     /**
143      * @deprecated
144      */
145     public void setRequisition(RequisitionDocument requisition) {
146         this.requisition = requisition;
147     }
148 
149     public ContractManagerAssignmentDocument getContractManagerAssignmentDocument() {
150         return contractManagerAssignmentDocument;
151     }
152 
153     public void setContractManagerAssignmentDocument(ContractManagerAssignmentDocument contractManagerAssignmentDocument) {
154         this.contractManagerAssignmentDocument = contractManagerAssignmentDocument;
155     }
156 
157     /**
158      * Returns the formatted string of the create date. If the createDate is currently null, we'll
159      * get the createDate from the workflowDocument.
160      *
161      * @return
162      * @throws WorkflowException
163      */
164     public String getCreateDate() throws WorkflowException {
165         if (createDate == null) {
166             Formatter formatter = new DateViewDateObjectFormatter();
167             createDate = (String) formatter.format(getRequisition().getFinancialSystemDocumentHeader().getWorkflowDocument().getDateCreated().toDate());
168         }
169         return createDate;
170     }
171 
172     public void setCreateDate(String createDate) {
173         this.createDate = createDate;
174     }
175 
176     private PurchasingItemBase getFirstLineItem() {
177         return (PurchasingItemBase) this.getRequisition().getItem(0);
178     }
179 
180     public String getDeliveryCampusCode() {
181         return deliveryCampusCode;
182     }
183 
184     public void setDeliveryCampusCode(String deliveryCampusCode) {
185         this.deliveryCampusCode = deliveryCampusCode;
186     }
187 
188     public String getVendorName() {
189         return vendorName;
190     }
191 
192     public void setVendorName(String vendorName) {
193         this.vendorName = vendorName;
194     }
195 
196     /**
197      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
198      */
199     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
200         LinkedHashMap m = new LinkedHashMap();
201         m.put(OLEPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
202         if (this.requisitionIdentifier != null) {
203             m.put("requisitionIdentifier", this.requisitionIdentifier.toString());
204         }
205         return m;
206     }
207 
208 }