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  
17  package org.kuali.ole.select.document;
18  
19  import org.kuali.ole.module.purap.document.PurchaseOrderReopenDocument;
20  import org.kuali.ole.module.purap.document.RequisitionDocument;
21  import org.kuali.ole.module.purap.document.service.OlePurapService;
22  import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
23  import org.kuali.ole.select.document.service.OlePurchaseOrderDocumentHelperService;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.vnd.businessobject.VendorAlias;
27  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
28  
29  import java.util.HashMap;
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * Purchase Order Reopen Document
36   */
37  public class OlePurchaseOrderReopenDocument extends PurchaseOrderReopenDocument {
38      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderReopenDocument.class);
39  
40      private String vendorPoNumber;
41      private static transient OlePurapService olePurapService;
42      /**
43       * Default constructor.
44       */
45      public OlePurchaseOrderReopenDocument() {
46          super();
47      }
48  
49      /**
50       * This method is overridden to populate newly added ole fields from requisition into Ole Purchase Order Reopen Document.
51       *
52       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#populatePurchaseOrderFromRequisition(org.kuali.ole.module.purap.document.RequisitionDocument)
53       */
54      @Override
55      public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
56  
57          if (LOG.isDebugEnabled()) {
58              LOG.debug("Inside populatePurchaseOrderFromRequisition of OlePurchaseOrderReopenDocument");
59          }
60          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
61  
62  
63      }
64  
65      /**
66       * This method is overriden to populate bib info in Ole Purchase Order Reopen Document
67       *
68       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
69       */
70      @Override
71      public void prepareForSave(KualiDocumentEvent event) {
72  
73          if (LOG.isDebugEnabled()) {
74              LOG.debug("Inside prepareForSave of OlePurchaseOrderReopenDocument");
75          }
76          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
77          super.prepareForSave(event);
78      }
79  
80  
81      /**
82       * This method is overriden to populate bib info in Ole Purchase Order Reopen Document
83       *
84       * @see org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocumentBase#processAfterRetrieve()
85       */
86      @Override
87      public void processAfterRetrieve() {
88          if (LOG.isDebugEnabled()) {
89              LOG.debug("Inside processAfterRetrieve of OlePurchaseOrderReopenDocument");
90          }
91          if (this.getVendorAliasName() == null) {
92              populateVendorAliasName();
93          }
94          try {
95              List<OlePurchaseOrderItem> items = this.getItems();
96              Iterator iterator = items.iterator();
97              while (iterator.hasNext()) {
98                  Object object = iterator.next();
99                  if (object instanceof OlePurchaseOrderItem) {
100                     OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) object;
101                     if(singleItem.getCopyList().size() > 0) {
102                         //getOlePurapService().setInvoiceDocumentsForPO(olePurchaseOrderItem);
103                         getOlePurapService().setInvoiceDocumentsForPO(this,singleItem);
104                     }
105                 }
106             }
107         } catch (Exception e) {
108             LOG.error("Exception in OlePurchaseOrderCloseDocument:processAfterRetrieve" + e.getMessage());
109             throw new RuntimeException(e);
110         }
111         SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).processAfterRetrieve(this);
112 
113     }
114 
115     @Override
116     public List getItemsActiveOnly() {
117         if (LOG.isDebugEnabled()) {
118             LOG.debug("Inside getItemsActiveOnly of OlePurchaseOrderReopenDocument");
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 OlePurchaseOrderReopenDocument");
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 OlePurchaseOrderReopenDocument");
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 OlePurchaseOrderReopenDocument");
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 OlePurchaseOrderReopenDocument");
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 OlePurchaseOrderReopenDocument");
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 OlePurchaseOrderReopenDocument");
179         }
180         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
181     }
182 
183     public String getBibSearchURL() {
184         LOG.debug("Inside getBibSearchURL of OlePurchaseOrderReopenDocument");
185         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
186     }
187 
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 edit url from propertie file
200      *
201      * @return Bibeditor edit url string
202      */
203     public String getBibeditorEditURL() {
204         if (LOG.isDebugEnabled()) {
205             LOG.debug("Inside getBibeditorEditURL of OlePurchaseOrderReopenDocument");
206         }
207         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
208     }
209 
210     /**
211      * This method is used to get the bibedtior view url from propertie file
212      *
213      * @return Bibeditor view url string
214      */
215     public String getBibeditorViewURL() {
216         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
217     }
218 
219     /**
220      * This method is used to get the directory path where the marc xml files need to be created
221      *
222      * @return Directory path string
223      */
224     public String getMarcXMLFileDirLocation() throws Exception {
225         if (LOG.isDebugEnabled()) {
226             LOG.debug("Inside getMarcXMLFileDirLocation of OlePurchaseOrderReopenDocument");
227         }
228         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
229     }
230 
231 
232     public String getVendorPoNumber() {
233         return vendorPoNumber;
234     }
235 
236     public void setVendorPoNumber(String vendorPoNumber) {
237         this.vendorPoNumber = vendorPoNumber;
238     }
239 
240     /**
241      * This method is used to check the status of the document for displaying view and edit buttons in line item
242      *
243      * @return boolean
244      */
245     public boolean getIsSaved() {
246         if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
247             return true;
248         }
249         return false;
250     }
251 
252     public boolean getIsATypeOfRCVGDoc() {
253         return false;
254     }
255 
256     public boolean getIsATypeOfCORRDoc() {
257         return false;
258     }
259 
260     private void populateVendorAliasName() {
261         Map vendorDetailMap = new HashMap();
262         vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
263         vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
264         List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
265         if (vendorDetailList != null && vendorDetailList.size() > 0) {
266             this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
267         }
268     }
269 
270     /**
271      * This method is used to get the dublin editor edit url from property file
272      *
273      * @return Dublineditor edit url string
274      */
275     public String getDublinEditorEditURL() {
276         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
277     }
278 
279     /**
280      * This method is used to get the dublin editor view url from property file
281      *
282      * @return dublineditor view url string
283      */
284     public String getDublinEditorViewURL() {
285         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
286     }
287 
288     public static OlePurapService getOlePurapService() {
289         if (olePurapService == null) {
290             olePurapService = SpringContext.getBean(OlePurapService.class);
291         }
292         return olePurapService;
293     }
294 }