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