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.apache.commons.lang.StringEscapeUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.ole.docstore.common.client.*;
21  import org.kuali.ole.docstore.common.client.impl.DocstoreClientLocatorServiceImpl;
22  import org.kuali.ole.docstore.common.document.Bib;
23  import org.kuali.ole.docstore.common.document.BibMarc;
24  import org.kuali.ole.DocumentUniqueIDPrefix;
25  import org.kuali.ole.docstore.model.bo.WorkBibDocument;
26  import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
27  import org.kuali.ole.docstore.model.bo.WorkItemDocument;
28  import org.kuali.ole.docstore.model.enums.DocType;
29  import org.kuali.ole.gl.service.SufficientFundsService;
30  import org.kuali.ole.module.purap.PurapWorkflowConstants;
31  import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
32  import org.kuali.ole.module.purap.document.PurchaseOrderAmendmentDocument;
33  import org.kuali.ole.module.purap.document.RequisitionDocument;
34  import org.kuali.ole.module.purap.document.service.OlePurapService;
35  import org.kuali.ole.module.purap.service.PurapAccountingService;
36  import org.kuali.ole.select.OleSelectConstant;
37  import org.kuali.ole.select.businessobject.*;
38  import org.kuali.ole.select.document.service.*;
39  import org.kuali.ole.sys.OLEConstants;
40  import org.kuali.ole.sys.OLEPropertyConstants;
41  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
42  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
43  import org.kuali.ole.sys.businessobject.SufficientFundsItem;
44  import org.kuali.ole.sys.context.SpringContext;
45  import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
46  import org.kuali.ole.sys.service.UniversityDateService;
47  import org.kuali.ole.vnd.businessobject.VendorAlias;
48  import org.kuali.rice.core.api.util.type.KualiDecimal;
49  import org.kuali.rice.core.api.util.type.KualiInteger;
50  import org.kuali.rice.kew.api.action.RoutingReportCriteria;
51  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
52  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
53  import org.kuali.rice.krad.bo.Note;
54  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
55  import org.kuali.rice.krad.service.BusinessObjectService;
56  import org.kuali.rice.krad.service.DocumentService;
57  
58  import java.math.BigDecimal;
59  import java.util.*;
60  
61  public class OlePurchaseOrderAmendmentDocument extends PurchaseOrderAmendmentDocument {
62      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderAmendmentDocument.class);
63  
64      private String vendorPoNumber;
65      private static transient OlePatronRecordHandler olePatronRecordHandler;
66      private static transient OlePatronDocumentList olePatronDocumentList;
67      private static transient OleSelectDocumentService oleSelectDocumentService;
68      private static transient OlePurapService olePurapService;
69      private static transient OleCopyHelperService oleCopyHelperService;
70      private String vendorAliasName;
71      private DocstoreClientLocator docstoreClientLocator;
72  
73      public DocstoreClientLocator getDocstoreClientLocator() {
74          if (docstoreClientLocator == null) {
75              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
76          }
77          return docstoreClientLocator;
78      }
79  
80      public static OleSelectDocumentService getOleSelectDocumentService() {
81          if (oleSelectDocumentService == null) {
82              oleSelectDocumentService = SpringContext.getBean(OleSelectDocumentService.class);
83          }
84          return oleSelectDocumentService;
85      }
86  
87      public static void setOleSelectDocumentService(OleSelectDocumentService oleSelectDocumentService) {
88          OlePurchaseOrderAmendmentDocument.oleSelectDocumentService = oleSelectDocumentService;
89      }
90  
91      public static OlePatronDocumentList getOlePatronDocumentList() {
92          if (olePatronDocumentList == null) {
93              olePatronDocumentList = SpringContext.getBean(OlePatronDocumentList.class);
94          }
95          return olePatronDocumentList;
96      }
97  
98      public static void setOlePatronDocumentList(OlePatronDocumentList olePatronDocumentList) {
99          OlePurchaseOrderAmendmentDocument.olePatronDocumentList = olePatronDocumentList;
100     }
101 
102 
103     public OlePatronRecordHandler getOlePatronRecordHandler() {
104         if (null == olePatronRecordHandler) {
105             olePatronRecordHandler = new OlePatronRecordHandler();
106         }
107         return olePatronRecordHandler;
108     }
109 
110     public void setOlePatronRecordHandler(OlePatronRecordHandler olePatronRecordHandler) {
111         this.olePatronRecordHandler = olePatronRecordHandler;
112     }
113 
114     public String getVendorAliasName() {
115         return vendorAliasName;
116     }
117 
118     public void setVendorAliasName(String vendorAliasName) {
119         this.vendorAliasName = vendorAliasName;
120     }
121 
122     public static OlePurapService getOlePurapService() {
123         if (olePurapService == null) {
124             olePurapService = SpringContext.getBean(OlePurapService.class);
125         }
126         return olePurapService;
127     }
128 
129     public static void setOlePurapService(OlePurapService olePurapService) {
130         OlePurchaseOrderAmendmentDocument.olePurapService = olePurapService;
131     }
132 
133     public static OleCopyHelperService getOleCopyHelperService() {
134         if(oleCopyHelperService  == null){
135             oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
136         }
137         return oleCopyHelperService;
138     }
139 
140     public static void setOleCopyHelperService(OleCopyHelperService oleCopyHelperService) {
141         OlePurchaseOrderAmendmentDocument.oleCopyHelperService = oleCopyHelperService;
142     }
143 
144     @Override
145     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
146         super.doRouteStatusChange(statusChangeEvent);
147         if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
148             SpringContext.getBean(OlePurchaseOrderService.class).setStatusCompletePurchaseOrderAmendment(this);
149         }
150     }
151 
152     /**
153      * This method is overridden to populate newly added ole fields from requisition into Ole Purchase Order Amendment Document.
154      *
155      * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#populatePurchaseOrderFromRequisition(org.kuali.ole.module.purap.document.RequisitionDocument)
156      */
157     @Override
158     public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
159 
160         LOG.debug("Inside populatePurchaseOrderFromRequisition of OlePurchaseOrderAmendmentDocument");
161         SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
162 
163 
164     }
165 
166     /**
167      * This method is overriden to populate bib info in Ole Purchase Order Amendment Document
168      *
169      * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
170      */
171     @Override
172     public void prepareForSave(KualiDocumentEvent event) {
173 
174         LOG.debug("Inside prepareForSave of OlePurchaseOrderAmendmentDocument");
175         //For single copy, if the itemLocation is changed, based on the user input from Location Change prompt, the itemLocation is updated in docstore's item record.
176         OleDocstoreHelperService oleDocstoreHelperService = SpringContext
177                 .getBean(OleDocstoreHelperService.class);
178         List<OlePurchaseOrderItem> purItem = this.getItems();
179         for (int i = 0; purItem.size() > i; i++) {
180             OlePurchaseOrderItem item = (OlePurchaseOrderItem) this.getItem(i);
181             if (item.isItemLocationChangeFlag()) {
182                 oleDocstoreHelperService.updateItemLocation(this, item);
183             }
184         }
185         SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
186         super.prepareForSave(event);
187     }
188 
189     /**
190      * This method is overriden to populate bib info in Ole Purchase Order Amendment Document
191      *
192      * @see org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocumentBase#processAfterRetrieve()
193      */
194     @Override
195     public void processAfterRetrieve() {
196         LOG.debug("Inside processAfterRetrieve of OlePurchaseOrderAmendmentDocument");
197         if (this.getVendorAliasName() == null) {
198             populateVendorAliasName();
199         }
200         try {
201             PurchaseOrderType purchaseOrderTypeDoc = getOlePurapService().getPurchaseOrderType(this.getPurchaseOrderTypeId());
202             if(purchaseOrderTypeDoc != null){
203                 this.setOrderType(purchaseOrderTypeDoc);
204             }
205         } catch (Exception e) {
206             LOG.error("Error in OlePurchaseOrderDocument:processAfterRetrieve for OleRequisitionItem " + e.getMessage());
207             throw new RuntimeException(e);
208         }
209         try {
210             List<OlePurchaseOrderItem> items = this.getItems();
211             Iterator iterator = items.iterator();
212             while (iterator.hasNext()) {
213                 Object object = iterator.next();
214                 if (object instanceof OlePurchaseOrderItem) {
215                     OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) object;
216                     setItemDetailWhileProcessAfterRetrive(singleItem);
217                 }
218             }
219         } catch (Exception e) {
220             LOG.error("Exception in OlePurchaseOrderDocument:processAfterRetrieve for OlePurchaseOrderItem " + e.getMessage());
221             throw new RuntimeException(e);
222         }
223     }
224 
225     /**
226      * This method is used to set the item detail while processafterretrive method is executed
227      * @param olePurchaseOrderItem
228      */
229     private void setItemDetailWhileProcessAfterRetrive(OlePurchaseOrderItem olePurchaseOrderItem)throws Exception{
230         if (olePurchaseOrderItem.getRequestorId() != null) {
231             olePurchaseOrderItem.setRequestorFirstName(getOlePurapService().getPatronName(olePurchaseOrderItem.getRequestorId()));
232         }
233         olePurchaseOrderItem.setPreviousItemQuantity(olePurchaseOrderItem.getItemQuantity());
234         olePurchaseOrderItem.setPreviousItemNoOfParts(olePurchaseOrderItem.getItemNoOfParts());
235         // Added for jira OLE-2811 ends
236         if (olePurchaseOrderItem.getBibInfoBean() == null) {
237             olePurchaseOrderItem.setBibInfoBean(new BibInfoBean());
238         }
239         if ((!StringUtils.isEmpty(olePurchaseOrderItem.getInternalRequestorId()) || !StringUtils.isEmpty(olePurchaseOrderItem
240                 .getRequestorId())) && olePurchaseOrderItem.getBibInfoBean().getRequestorType() == null) {
241             String requestorType = OleSelectConstant.REQUESTOR_TYPE_STAFF;
242             Map<String, Object> criteria = new HashMap<String, Object>();
243             criteria.put(OleSelectConstant.REQUESTOR_TYPE, requestorType);
244             Collection<OleRequestorType> requestorTypeList = SpringContext.getBean(BusinessObjectService.class).findMatching(OleRequestorType.class, criteria);
245             LOG.debug("###########inside prepareForSave getting requestor type###########");
246             olePurchaseOrderItem.setRequestorTypeId(requestorTypeList.iterator().next().getRequestorTypeId());
247         }
248         if(olePurchaseOrderItem.getItemUnitPrice()!=null){
249             olePurchaseOrderItem.setItemUnitPrice(olePurchaseOrderItem.getItemUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP));
250         }
251         if (olePurchaseOrderItem.getItemTitleId() != null) {
252             LOG.debug("###########inside processAfterRetrieve OlePurchaseOrderAmendmentDocument ###########");
253             Bib bib = new BibMarc();
254             if (olePurchaseOrderItem.getItemTitleId() != null && olePurchaseOrderItem.getItemTitleId() != "") {
255                 bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(olePurchaseOrderItem.getItemTitleId());
256                 olePurchaseOrderItem.setBibUUID(bib.getId());
257             }
258             olePurchaseOrderItem.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(olePurchaseOrderItem.getItemTitleId()));
259             olePurchaseOrderItem.setBibInfoBean(new BibInfoBean());
260             olePurchaseOrderItem.setItemDescription(getOlePurapService().getItemDescription(bib));
261         }
262         if (olePurchaseOrderItem.getItemType() != null && olePurchaseOrderItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
263             populateCopiesSection(olePurchaseOrderItem);
264         }
265         if(olePurchaseOrderItem.getCopyList().size() > 0) {
266             //getOlePurapService().setInvoiceDocumentsForPO(olePurchaseOrderItem);
267             getOlePurapService().setInvoiceDocumentsForPO(this,olePurchaseOrderItem);
268         }
269     }
270 
271     /**
272      * This method is used to populated the copies section details
273      * @param singleItem
274      */
275     private void populateCopiesSection(OlePurchaseOrderItem singleItem) {
276         if (singleItem.getCopies().size() > 0) {
277             List<OleCopy> copyList = getOleCopyHelperService().setCopyValuesForList(singleItem.getCopies(), singleItem.getItemTitleId(), null, null);
278             if (copyList.size() >= singleItem.getCopyList().size()) {
279                 int copyCount = 0;
280                 for (OleCopy oleCopy : singleItem.getCopyList()) {
281                     OleCopy copy = copyList.get(copyCount);
282                     oleCopy.setLocation(copy.getLocation());
283                     oleCopy.setEnumeration(copy.getEnumeration());
284                     oleCopy.setCopyNumber(copy.getCopyNumber());
285                     oleCopy.setPartNumber(copy.getPartNumber());
286                     copyCount++;
287                 }
288                 for(int i = copyCount ; i<copyList.size() ; i++){
289                     singleItem.getCopyList().add(copyList.get(copyCount));
290                     copyCount++;
291                 }
292             }
293         }
294         else {
295             if (singleItem.getItemQuantity() != null && singleItem.getItemNoOfParts() != null && (singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
296                     || singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
297                 singleItem.setCopies(getOleCopyHelperService().setCopiesToLineItem(singleItem.getCopyList(), singleItem.getItemNoOfParts(), singleItem.getItemTitleId()));
298             }
299         }
300         if (singleItem.getItemQuantity() != null && singleItem.getItemNoOfParts() != null && !singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
301                 && !singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))&&singleItem.getCopyList().size()>0) {
302             singleItem.setSingleCopyNumber(singleItem.getCopyList().get(0).getCopyNumber());
303         }
304     }
305 
306     // Added for Jira OLE-1900 Starts
307 
308     /**
309      * This method will set copies into list of copies for LineItem.
310      *
311      * @param singleItem
312      * @param workBibDocument
313      * @return
314      */
315     public List<OleCopies> setCopiesToLineItem(OlePurchaseOrderItem singleItem, WorkBibDocument workBibDocument) {
316         List<WorkInstanceDocument> instanceDocuments = workBibDocument.getWorkInstanceDocumentList();
317         List<OleCopies> copies = new ArrayList<OleCopies>();
318         for (WorkInstanceDocument workInstanceDocument : instanceDocuments) {
319             List<WorkItemDocument> itemDocuments = workInstanceDocument.getItemDocumentList();
320             StringBuffer enumeration = new StringBuffer();
321             for (int itemDocs = 0; itemDocs < itemDocuments.size(); itemDocs++) {
322                 if (itemDocs + 1 == itemDocuments.size()) {
323                     enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration());
324                 } else {
325                     enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration() + ",");
326                 }
327 
328             }
329             int startingCopy = 0;
330             if (singleItem.getItemNoOfParts().intValue() != 0 && null != enumeration) {
331                 String enumerationSplit = enumeration.substring(1, 2);
332                 boolean isint = checkIsEnumerationSplitIsIntegerOrNot(enumerationSplit);
333                 if (isint) {
334                     startingCopy = Integer.parseInt(enumerationSplit);
335                 }
336             }
337             if (singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
338                     || singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
339                 boolean isValid = checkForEnumeration(enumeration);
340                 if (isValid) {
341                     int noOfCopies = workInstanceDocument.getItemDocumentList().size()
342                             / singleItem.getItemNoOfParts().intValue();
343                     OleRequisitionCopies copy = new OleRequisitionCopies();
344                     copy.setParts(singleItem.getItemNoOfParts());
345                     copy.setLocationCopies(workInstanceDocument.getHoldingsDocument().getLocationName());
346                     copy.setItemCopies(new KualiDecimal(noOfCopies));
347                     copy.setPartEnumeration(enumeration.toString());
348                     copy.setStartingCopyNumber(new KualiInteger(startingCopy));
349                     copies.add(copy);
350                 }
351             }
352         }
353         return copies;
354     }
355 
356     public boolean checkForEnumeration(StringBuffer enumeration) {
357         if (null != enumeration && !(enumeration.equals("")) && !(enumeration.toString().equals("null"))) {
358             return true;
359         } else {
360             return false;
361         }
362     }
363 
364     public boolean checkIsEnumerationSplitIsIntegerOrNot(String enumerationSplit) {
365         try {
366             int startingCopy = Integer.parseInt(enumerationSplit);
367         } catch (NumberFormatException e) {
368             return false;
369         }
370         return true;
371     }
372 
373     /**
374      * This method takes List of UUids as parameter and creates a LinkedHashMap with instance as key and id as value. and calls
375      * Docstore's QueryServiceImpl class getWorkBibRecords method and return workBibDocument for passed instance Id.
376      *
377      * @param instanceIdsList
378      * @return List<WorkBibDocument>
379      */
380 //    private List<WorkBibDocument> getWorkBibDocuments(List<String> instanceIdsList) {
381 //        List<LinkedHashMap<String, String>> instanceIdMapList = new ArrayList<LinkedHashMap<String, String>>();
382 //        for (String instanceId : instanceIdsList) {
383 //            LinkedHashMap<String, String> instanceIdMap = new LinkedHashMap<String, String>();
384 //            instanceIdMap.put(DocType.INSTANCE.getDescription(), instanceId);
385 //            instanceIdMapList.add(instanceIdMap);
386 //        }
387 //
388 //        QueryService queryService = QueryServiceImpl.getInstance();
389 //        List<WorkBibDocument> workBibDocuments = new ArrayList<WorkBibDocument>();
390 //        try {
391 //            workBibDocuments = queryService.getWorkBibRecords(instanceIdMapList);
392 //        } catch (Exception ex) {
393 //            // TODO Auto-generated catch block
394 //            ex.printStackTrace();
395 //        }
396 //        return workBibDocuments;
397 //    }
398 
399     // Added for Jira OLE-1900 Ends
400 
401     @Override
402     public List getItemsActiveOnly() {
403         LOG.debug("Inside getItemsActiveOnly of OlePurchaseOrderReopenDocument");
404         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnly(this);
405     }
406 
407     /**
408      * Gets the active items in this Purchase Order, and sets up the alternate amount for GL entry creation.
409      *
410      * @return the list of all active items in this Purchase Order.
411      */
412     @Override
413     public List getItemsActiveOnlySetupAlternateAmount() {
414         LOG.debug("Inside getItemsActiveOnlySetupAlternateAmount of OlePurchaseOrderReopenDocument");
415         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnlySetupAlternateAmount(this);
416     }
417 
418     @Override
419     public boolean getAdditionalChargesExist() {
420         LOG.debug("Inside getAdditionalChargesExist of OlePurchaseOrderReopenDocument");
421         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getAdditionalChargesExist(this);
422     }
423 
424     /**
425      * This method returns if Purchase Order Document created is in Final Status
426      *
427      * @return
428      */
429     public boolean getIsFinalReqs() {
430         LOG.debug("Inside getIsFinalReqs of OlePurchaseOrderAmendmentDocument");
431 
432         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsFinalReqs(this);
433     }
434 
435     public boolean getIsSplitPO() {
436         LOG.debug("Inside getIsSplitPO of OlePurchaseOrderAmendmentDocument");
437         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsSplitPO(this);
438     }
439 
440     public boolean getIsReOpenPO() {
441         LOG.debug("Inside getIsReOpenPO of OlePurchaseOrderAmendmentDocument");
442         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsReOpenPO(this);
443     }
444 
445     /**
446      * This method is used to get the bibedtior creat url from propertie file
447      *
448      * @return Bibeditor creat url string
449      */
450     public String getBibeditorCreateURL() {
451         LOG.debug("Inside getBibeditorCreateURL of OlePurchaseOrderAmendmentDocument");
452         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
453     }
454 
455     public String getBibSearchURL() {
456         LOG.debug("Inside getBibSearchURL of OlePurchaseOrderAmendmentDocument");
457         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
458     }
459 
460     /**
461      * This method is used to get the bibedtior edit url from propertie file
462      *
463      * @return Bibeditor edit url string
464      */
465     public String getBibeditorEditURL() {
466         LOG.debug("Inside getBibeditorEditURL of OlePurchaseOrderAmendmentDocument");
467         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
468     }
469 
470     /**
471      * This method is used to get the dublinedtior edit url from propertie file
472      *
473      * @return Dublineditor edit url string
474      */
475     public String getDublinEditorEditURL() {
476         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
477     }
478     /**
479      * This method is used to get the Instanceeditor url from propertie file
480      *
481      * @return Instanceeditor url string
482      */
483     public String getInstanceEditorURL() {
484         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getInstanceEditorURL();
485     }
486 
487     /**
488      * This method is used to get the bibedtior view url from propertie file
489      *
490      * @return Bibeditor view url string
491      */
492     public String getBibeditorViewURL() {
493         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
494     }
495     /**
496      * This method is used to get the dublinedtior view url from propertie file
497      *
498      * @return dublineditor view url string
499      */
500     public String getDublinEditorViewURL() {
501         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
502     }
503     /**
504      * This method is used to get the directory path where the marc xml files need to be created
505      *
506      * @return Directory path string
507      */
508     public String getMarcXMLFileDirLocation() throws Exception {
509         LOG.debug("Inside getMarcXMLFileDirLocation of OlePurchaseOrderAmendmentDocument");
510         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
511     }
512 
513     @Override
514     public Class getItemClass() {
515         return OlePurchaseOrderItem.class;
516     }
517 
518 
519     @Override
520     public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
521         if (nodeName.equals(PurapWorkflowConstants.HAS_NEW_UNORDERED_ITEMS)) {
522             return isNewUnorderedItem();
523         }
524         if (nodeName.equals(PurapWorkflowConstants.CONTRACT_MANAGEMENT_REVIEW_REQUIRED)) {
525             return isContractManagementReviewRequired();
526         }
527         if (nodeName.equals(PurapWorkflowConstants.AWARD_REVIEW_REQUIRED)) {
528             return isAwardReviewRequired();
529         }
530         if (nodeName.equals(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED)) {
531             return isBudgetReviewRequired();
532         }
533         if (nodeName.equals(PurapWorkflowConstants.VENDOR_IS_EMPLOYEE_OR_NON_RESIDENT_ALIEN)) {
534             return isVendorEmployeeOrNonResidentAlien();
535         }
536 
537         if (nodeName.equals(PurapWorkflowConstants.NOTIFY_BUDGET_REVIEW)) {
538             return isNotificationRequired();
539         }
540         throw new UnsupportedOperationException("Cannot answer split question for this node you call \"" + nodeName + "\"");
541     }
542 
543     public String getVendorPoNumber() {
544         return vendorPoNumber;
545     }
546 
547     public void setVendorPoNumber(String vendorPoNumber) {
548         this.vendorPoNumber = vendorPoNumber;
549     }
550 
551     /**
552      * This method is used to check the status of the document for displaying view and edit buttons in line item
553      *
554      * @return boolean
555      */
556     public boolean getIsSaved() {
557         if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
558             return true;
559         }
560         return false;
561     }
562 
563     public boolean getIsATypeOfRCVGDoc() {
564         return false;
565     }
566 
567     public boolean getIsATypeOfCORRDoc() {
568         return false;
569     }
570 
571 
572     @Override
573     public void doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) {
574         super.doRouteLevelChange(levelChangeEvent);
575         try {
576             String newNodeName = levelChangeEvent.getNewNodeName();
577             String documentId = this.getDocumentNumber();
578             if (!OLEConstants.PO_NOTE_MAP.containsKey(documentId)
579                     && newNodeName != null
580                     && (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || newNodeName
581                     .equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET))) {
582                 addPurchaseOrderNote(levelChangeEvent);
583                 OLEConstants.PO_NOTE_MAP.put(documentId, true);
584 
585             }
586         } catch (Exception e) {
587             String errorMsg = "Workflow Error found checking actions requests on document with id "
588                     + getDocumentNumber() + ". *** WILL NOT UPDATE PURAP STATUS ***";
589             LOG.error(errorMsg, e);
590         }
591     }
592 
593     public void addPurchaseOrderNote(DocumentRouteLevelChange levelChangeEvent) {
594 
595         String newNodeName = levelChangeEvent.getNewNodeName();
596         RoutingReportCriteria.Builder reportCriteria = RoutingReportCriteria.Builder
597                 .createByDocumentIdAndTargetNodeName(getDocumentNumber(), newNodeName);
598         if (newNodeName != null
599                 && (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || newNodeName
600                 .equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET))) {
601             String note = "";
602             if(newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE)){
603                  note = OLEConstants.SufficientFundCheck.POA_NOTE;
604             }
605             if(newNodeName.equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET)){
606                 note = OLEConstants.SufficientFundCheck.FYI_NOTE;
607             }
608             DocumentService documentService = SpringContext.getBean(DocumentService.class);
609             Note apoNote = documentService.createNoteFromDocument(this, note);
610             this.addNote(apoNote);
611             String documentTypeName = this.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
612             if (documentTypeName != null
613                     && documentTypeName.equals(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT)) {
614                 documentService.saveDocumentNotes(this);
615             }
616 
617         }
618 
619     }
620 
621     /**
622      * Method overridden for Fund Check Makes sure that accounts for routing has been generated, so that other information can be
623      * retrieved from that
624      */
625     @Override
626     protected void populateAccountsForRouting() {
627         List<SufficientFundsItem> fundsItems = new ArrayList<SufficientFundsItem>();
628         String documentId = this.getDocumentNumber();
629         try {
630             String nodeName = getFinancialSystemDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator()
631                     .next();
632             if (nodeName != null
633                     && (nodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || nodeName
634                     .equalsIgnoreCase(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED))) {
635                 if (SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear()
636                         .compareTo(getPostingYear()) >= 0) {
637                     List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
638                     for (GeneralLedgerPendingEntry glpe : pendingEntries) {
639                         glpe.getChartOfAccountsCode();
640                     }
641                     SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
642                     fundsItems = SpringContext.getBean(SufficientFundsService.class).checkSufficientFunds(
643                             pendingEntries);
644                     SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(
645                             this);
646                     SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());
647                 }
648                 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
649                 accountsForRouting = (SpringContext.getBean(PurapAccountingService.class).generateSummary(getItems()));
650                 String documentFiscalYearString = this.getPostingYear().toString();
651                 List<String> fundsItemList = new ArrayList<String>();
652                 List<String> accountsList = new ArrayList<String>();
653                 for (SufficientFundsItem fundsItem : fundsItems) {
654                     fundsItemList.add(fundsItem.getAccount().getChartOfAccountsCode());
655                 }
656                 setAccountsForRouting(accountsForRouting);
657                 refreshNonUpdateableReferences();
658                 for (SourceAccountingLine sourceLine : getAccountsForRouting()) {
659                     sourceLine.refreshNonUpdateableReferences();
660                 }
661             } else {
662                 super.populateAccountsForRouting();
663             }
664         } catch (Exception e) {
665             logAndThrowRuntimeException("Error in populateAccountsForRouting while submitting document with id "
666                     + getDocumentNumber(), e);
667         }
668     }
669 
670 
671     @Override
672     protected boolean isBudgetReviewRequired() {
673         OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
674                 .getBean("oleRequisitionDocumentService");
675         boolean sufficientFundCheck = false;
676         List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
677         for (SourceAccountingLine accLine : sourceAccountingLineList) {
678             Map searchMap = new HashMap();
679             String notificationOption = null;
680             Map<String, Object> key = new HashMap<String, Object>();
681             String chartCode = accLine.getChartOfAccountsCode();
682             String accNo = accLine.getAccountNumber();
683             String objectCd = accLine.getFinancialObjectCode();
684             key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
685             key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
686             OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
687                     OleSufficientFundCheck.class, key);
688             if (account != null) {
689                 notificationOption = account.getNotificationOption();
690             }
691             if (notificationOption != null
692                     && (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW))) {
693                 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
694                 if (sufficientFundCheck) {
695                     return true;
696                 }
697             }
698         }
699         return sufficientFundCheck;
700     }
701 
702     private boolean isNotificationRequired() {
703         OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
704                 .getBean("oleRequisitionDocumentService");
705         List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
706         boolean sufficientFundCheck = false;
707         for (SourceAccountingLine accLine : sourceAccountingLineList) {
708             Map searchMap = new HashMap();
709             String notificationOption = null;
710             Map<String, Object> key = new HashMap<String, Object>();
711             String chartCode = accLine.getChartOfAccountsCode();
712             String accNo = accLine.getAccountNumber();
713             String objectCd = accLine.getFinancialObjectCode();
714             key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
715             key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
716             OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
717                     OleSufficientFundCheck.class, key);
718             if (account != null) {
719                 notificationOption = account.getNotificationOption();
720             }
721             if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.NOTIFICATION)) {
722                 sufficientFundCheck =  oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
723                 if (sufficientFundCheck) {
724                     return true;
725                 }
726             }
727         }
728         return sufficientFundCheck;
729     }
730 
731     private void populateVendorAliasName() {
732         Map vendorDetailMap = new HashMap();
733         vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
734         vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
735         List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
736         if (vendorDetailList != null && vendorDetailList.size() > 0) {
737             this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
738         }
739     }
740 
741 }