View Javadoc
1   /*
2    * Copyright 2011 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.select.document;
17  
18  import org.kuali.ole.module.purap.document.PurchaseOrderSplitDocument;
19  import org.kuali.ole.module.purap.document.RequisitionDocument;
20  import org.kuali.ole.module.purap.document.service.OlePurapService;
21  import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
22  import org.kuali.ole.select.document.service.OlePurchaseOrderDocumentHelperService;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.ole.vnd.businessobject.VendorAlias;
26  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
27  
28  import java.util.HashMap;
29  import java.util.Iterator;
30  import java.util.List;
31  import java.util.Map;
32  
33  
34  /**
35   * This class is the document class for Ole Purchase Order Split Document
36   */
37  public class OlePurchaseOrderSplitDocument extends PurchaseOrderSplitDocument {
38  
39      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderSplitDocument.class);
40  
41      private String vendorPoNumber;
42      private static transient OlePurapService olePurapService;
43  
44      public String getVendorPoNumber() {
45          return vendorPoNumber;
46      }
47  
48      public void setVendorPoNumber(String vendorPoNumber) {
49          this.vendorPoNumber = vendorPoNumber;
50      }
51  
52      /**
53       * This method is overridden to populate newly added ole fields from requisition into Ole Purchase Order Split Document.
54       *
55       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#populatePurchaseOrderFromRequisition(org.kuali.ole.module.purap.document.RequisitionDocument)
56       */
57      @Override
58      public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
59  
60          if (LOG.isDebugEnabled()) {
61              LOG.debug("Inside populatePurchaseOrderFromRequisition of OlePurchaseOrderSplitDocument");
62          }
63          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
64      }
65  
66      /**
67       * This method is overriden to populate bib info in Ole Purchase Order Split Document
68       *
69       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
70       */
71      @Override
72      public void prepareForSave(KualiDocumentEvent event) {
73  
74          if (LOG.isDebugEnabled()) {
75              LOG.debug("Inside prepareForSave of OlePurchaseOrderSplitDocument");
76          }
77          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
78          super.prepareForSave(event);
79  
80      }
81  
82      /**
83       * This method is overriden to populate bib info in Ole Purchase Order Retransmit Document
84       *
85       * @see org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocumentBase#processAfterRetrieve()
86       */
87      @Override
88      public void processAfterRetrieve() {
89          if (LOG.isDebugEnabled()) {
90              LOG.debug("Inside processAfterRetrieve of OlePurchaseOrderSplitDocument");
91          }
92          if (this.getVendorAliasName() == null) {
93              populateVendorAliasName();
94          }
95          try {
96              List<OlePurchaseOrderItem> items = this.getItems();
97              Iterator iterator = items.iterator();
98              while (iterator.hasNext()) {
99                  Object object = iterator.next();
100                 if (object instanceof OlePurchaseOrderItem) {
101                     OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) object;
102                     if(singleItem.getCopyList().size() > 0) {
103                         //getOlePurapService().setInvoiceDocumentsForPO(olePurchaseOrderItem);
104                         getOlePurapService().setInvoiceDocumentsForPO(this,singleItem);
105                     }
106                 }
107             }
108         } catch (Exception e) {
109             LOG.error("Exception in OlePurchaseOrderCloseDocument:processAfterRetrieve" + e.getMessage());
110             throw new RuntimeException(e);
111         }
112         SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).processAfterRetrieve(this);
113     }
114 
115     @Override
116     public List getItemsActiveOnly() {
117         if (LOG.isDebugEnabled()) {
118             LOG.debug("Inside getItemsActiveOnly of OlePurchaseOrderSplitDocument");
119         }
120         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnly(this);
121     }
122 
123     /**
124      * Gets the active items in this Purchase Order, and sets up the alternate amount for GL entry creation.
125      *
126      * @return the list of all active items in this Purchase Order.
127      */
128     @Override
129     public List getItemsActiveOnlySetupAlternateAmount() {
130         if (LOG.isDebugEnabled()) {
131             LOG.debug("Inside getItemsActiveOnlySetupAlternateAmount of OlePurchaseOrderSplitDocument");
132         }
133         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnlySetupAlternateAmount(this);
134     }
135 
136     @Override
137     public boolean getAdditionalChargesExist() {
138         if (LOG.isDebugEnabled()) {
139             LOG.debug("Inside getAdditionalChargesExist of OlePurchaseOrderSplitDocument");
140         }
141         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getAdditionalChargesExist(this);
142     }
143 
144     /**
145      * This method returns if Purchase Order Document created is in Final Status
146      *
147      * @return
148      */
149     public boolean getIsFinalReqs() {
150         if (LOG.isDebugEnabled()) {
151             LOG.debug("Inside getIsFinalReqs of OlePurchaseOrderSplitDocument");
152         }
153 
154         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsFinalReqs(this);
155     }
156 
157     public boolean getIsSplitPO() {
158         if (LOG.isDebugEnabled()) {
159             LOG.debug("Inside getIsSplitPO of OlePurchaseOrderSplitDocument");
160         }
161         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsSplitPO(this);
162     }
163 
164     public boolean getIsReOpenPO() {
165         if (LOG.isDebugEnabled()) {
166             LOG.debug("Inside getIsReOpenPO of OlePurchaseOrderSplitDocument");
167         }
168         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsReOpenPO(this);
169     }
170 
171     /**
172      * This method is used to get the bibedtior creat url from propertie file
173      *
174      * @return Bibeditor creat url string
175      */
176     public String getBibeditorCreateURL() {
177         if (LOG.isDebugEnabled()) {
178             LOG.debug("Inside getBibeditorCreateURL of OlePurchaseOrderSplitDocument");
179         }
180         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
181     }
182 
183     public String getBibSearchURL() {
184         LOG.debug("Inside getBibSearchURL of OlePurchaseOrderSplitDocument");
185         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
186     }
187 
188     /**
189      * This method is used to get the bibedtior edit url from propertie file
190      *
191      * @return Bibeditor edit url string
192      */
193     public String getBibeditorEditURL() {
194         if (LOG.isDebugEnabled()) {
195             LOG.debug("Inside getBibeditorEditURL of OlePurchaseOrderSplitDocument");
196         }
197         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
198     }
199 
200     /**
201      * This method is used to get the Instanceeditor url from propertie file
202      *
203      * @return Instanceeditor url string
204      */
205     public String getInstanceEditorURL() {
206         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getInstanceEditorURL();
207     }
208 
209     /**
210      * This method is used to get the bibedtior view url from propertie file
211      *
212      * @return Bibeditor view url string
213      */
214     public String getBibeditorViewURL() {
215         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
216     }
217 
218     /**
219      * This method is used to get the dublin editor edit url from property file
220      *
221      * @return Dublineditor edit url string
222      */
223     public String getDublinEditorEditURL() {
224         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
225     }
226 
227     /**
228      * This method is used to get the dublin editor view url from property file
229      *
230      * @return dublineditor view url string
231      */
232     public String getDublinEditorViewURL() {
233         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
234     }
235 
236     /**
237      * This method is used to get the directory path where the marc xml files need to be created
238      *
239      * @return Directory path string
240      */
241     public String getMarcXMLFileDirLocation() throws Exception {
242         if (LOG.isDebugEnabled()) {
243             LOG.debug("Inside getMarcXMLFileDirLocation of OlePurchaseOrderSplitDocument");
244         }
245         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
246     }
247 
248     @Override
249     public Class getItemClass() {
250         return OlePurchaseOrderItem.class;
251     }
252 
253     /**
254      * This method is used to check the status of the document for displaying view and edit buttons in line item
255      *
256      * @return boolean
257      */
258     public boolean getIsSaved() {
259         if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
260             return true;
261         }
262         return false;
263     }
264 
265     public boolean getIsATypeOfRCVGDoc() {
266         return false;
267     }
268 
269     public boolean getIsATypeOfCORRDoc() {
270         return false;
271     }
272 
273     private void populateVendorAliasName() {
274         Map vendorDetailMap = new HashMap();
275         vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
276         vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
277         List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
278         if (vendorDetailList != null && vendorDetailList.size() > 0) {
279             this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
280         }
281     }
282 
283     public static OlePurapService getOlePurapService() {
284         if (olePurapService == null) {
285             olePurapService = SpringContext.getBean(OlePurapService.class);
286         }
287         return olePurapService;
288     }
289 }