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.DocstoreClientLocator;
21  import org.kuali.ole.docstore.common.document.Bib;
22  import org.kuali.ole.docstore.common.document.BibMarc;
23  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
24  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
25  import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
26  import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
27  import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
28  import org.kuali.ole.DocumentUniqueIDPrefix;
29  import org.kuali.ole.gl.service.SufficientFundsService;
30  import org.kuali.ole.module.purap.PurapConstants;
31  import org.kuali.ole.module.purap.PurapConstants.RequisitionStatuses;
32  import org.kuali.ole.module.purap.PurapParameterConstants;
33  import org.kuali.ole.module.purap.PurapWorkflowConstants;
34  import org.kuali.ole.module.purap.businessobject.DefaultPrincipalAddress;
35  import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
36  import org.kuali.ole.module.purap.businessobject.RequisitionItem;
37  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
38  import org.kuali.ole.module.purap.document.RequisitionDocument;
39  import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
40  import org.kuali.ole.module.purap.document.service.OlePurapService;
41  import org.kuali.ole.module.purap.document.service.PurapService;
42  import org.kuali.ole.module.purap.document.service.RequisitionService;
43  import org.kuali.ole.module.purap.service.PurapAccountingService;
44  import org.kuali.ole.select.OleSelectConstant;
45  import org.kuali.ole.select.businessobject.*;
46  import org.kuali.ole.select.document.service.*;
47  import org.kuali.ole.select.service.BibInfoService;
48  import org.kuali.ole.select.service.BibInfoWrapperService;
49  import org.kuali.ole.select.service.FileProcessingService;
50  import org.kuali.ole.select.service.impl.BibInfoServiceImpl;
51  import org.kuali.ole.select.service.impl.exception.DocStoreConnectionException;
52  import org.kuali.ole.sys.OLEConstants;
53  import org.kuali.ole.sys.OLEPropertyConstants;
54  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
55  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
56  import org.kuali.ole.sys.businessobject.SufficientFundsItem;
57  import org.kuali.ole.sys.context.SpringContext;
58  import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
59  import org.kuali.ole.sys.service.UniversityDateService;
60  import org.kuali.ole.sys.service.impl.OleParameterConstants;
61  import org.kuali.ole.vnd.businessobject.VendorAlias;
62  import org.kuali.rice.core.api.config.property.ConfigContext;
63  import org.kuali.rice.core.api.config.property.ConfigurationService;
64  import org.kuali.rice.core.api.datetime.DateTimeService;
65  import org.kuali.rice.core.api.util.RiceKeyConstants;
66  import org.kuali.rice.core.api.util.type.KualiDecimal;
67  import org.kuali.rice.core.api.util.type.KualiInteger;
68  import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
69  import org.kuali.rice.coreservice.api.parameter.Parameter;
70  import org.kuali.rice.coreservice.api.parameter.ParameterKey;
71  import org.kuali.rice.coreservice.framework.parameter.ParameterConstants.COMPONENT;
72  import org.kuali.rice.coreservice.framework.parameter.ParameterConstants.NAMESPACE;
73  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
74  import org.kuali.rice.kew.api.action.ActionRequestType;
75  import org.kuali.rice.kew.api.action.RoutingReportCriteria;
76  import org.kuali.rice.kew.api.document.WorkflowDocumentService;
77  import org.kuali.rice.kew.api.exception.WorkflowException;
78  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
79  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
80  import org.kuali.rice.kim.api.identity.Person;
81  import org.kuali.rice.kim.api.identity.PersonService;
82  import org.kuali.rice.krad.bo.Note;
83  import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
84  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
85  import org.kuali.rice.krad.rules.rule.event.RouteDocumentEvent;
86  import org.kuali.rice.krad.service.BusinessObjectService;
87  import org.kuali.rice.krad.service.DocumentHeaderService;
88  import org.kuali.rice.krad.service.DocumentService;
89  import org.kuali.rice.krad.service.KRADServiceLocator;
90  import org.kuali.rice.krad.util.GlobalVariables;
91  import org.kuali.rice.krad.util.ObjectUtils;
92  
93  import java.math.BigDecimal;
94  import java.text.SimpleDateFormat;
95  import java.util.*;
96  
97  
98  @NAMESPACE(namespace = OleParameterConstants.PURCHASING_NAMESPACE)
99  @COMPONENT(component = "Requisition")
100 public class OleRequisitionDocument extends RequisitionDocument {
101 
102     /*
103      * Modified as per review comments OLE-24
104      */
105     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleRequisitionDocument.class);
106     // protected DateTimeService dateTimeService;
107     private static final String dateTimeFormat = "MMddHHmm";
108     private static final String dateFormat = "MMddyy";
109     private static final String timeStampFormat = "MMddyyHHmm";
110     private String vendorPoNumber;
111     private PurchasingAccountsPayableDocument purchasingAccountsPayableDocument;
112     private String vendorAliasName;
113     private DocstoreClientLocator docstoreClientLocator;
114     private static transient ConfigurationService kualiConfigurationService;
115     private static transient BibInfoWrapperService bibInfoWrapperService;
116     private static transient DateTimeService dateTimeService;
117     private static transient OleRequestSourceService oleRequestSourceService;
118     private static transient PurchaseOrderTypeService purchaseOrderTypeService;
119     private static transient FileProcessingService fileProcessingService;
120     private static transient BusinessObjectService businessObjectService;
121     private static transient ParameterService parameterService;
122     private static transient RequisitionService RequisitionService;
123     private static transient OlePurchaseOrderService olePurchaseOrderService;
124     private static transient WorkflowDocumentService workflowDocumentService;
125     private static transient OlePurapAccountingService olePurapAccountingService;
126     private static transient PurapService purapServiceImpl;
127     private static transient BibInfoService bibInfoService;
128     private static transient OlePurapService olePurapService;
129     private static transient OlePatronDocumentList olePatronDocumentList;
130     private static transient OleCopyHelperService oleCopyHelperService;
131 
132     public String getVendorAliasName() {
133         return vendorAliasName;
134     }
135 
136     public void setVendorAliasName(String vendorAliasName) {
137         this.vendorAliasName = vendorAliasName;
138     }
139 
140     public DocstoreClientLocator getDocstoreClientLocator() {
141         if (null == docstoreClientLocator) {
142             return SpringContext.getBean(DocstoreClientLocator.class);
143         }
144         return docstoreClientLocator;
145     }
146 
147     @Override
148     public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
149         if (nodeName.equals(PurapWorkflowConstants.HAS_ACCOUNTING_LINES)) {
150             return !isMissingAccountingLines();
151         }
152         /*if (nodeName.equals(PurapWorkflowConstants.HAS_LICENSE_REQUEST)) {
153             return isLicenseRequested();
154         }*/
155         if (nodeName.equals(PurapWorkflowConstants.AMOUNT_REQUIRES_SEPARATION_OF_DUTIES_REVIEW_SPLIT)) {
156             return isSeparationOfDutiesReviewRequired();
157             /*
158          * Modified as per review comments for OLE-24 Methods are commented as Notification is not implemented currently To revisit
159          * the code later based on notification methodology to be adopted
160              */
161         }
162 
163         /*
164          * if (nodeName.equals(PurapWorkflowConstants.FOR_INFORMATION)) return isLineItemGreater(); if
165          * (nodeName.equals(PurapWorkflowConstants.DUPLICATE_RECORD_CHECK)) return isDuplicateRecord(); if
166          * (nodeName.equals(PurapWorkflowConstants.NEW_VENDOR_CHECK)) return isNewVendor();
167         */
168         if (nodeName.equals(PurapWorkflowConstants.YBP_ORDERS)) {
169             return isRequiredOrderType(this.getPurchaseOrderTypeId(), PurapConstants.ORDER_TYPE_FIRM);
170         }
171         if (nodeName.equals(PurapWorkflowConstants.STANDING_ORDERS)) {
172             return isRequiredOrderType(this.getPurchaseOrderTypeId(), PurapConstants.ORDER_TYPE_STANDING);
173         }
174         if (nodeName.equals(PurapWorkflowConstants.SUBSCRIPTION_ORDERS)) {
175             return isRequiredOrderType(this.getPurchaseOrderTypeId(), PurapConstants.ORDER_TYPE_SUBSCRIPTION);
176         }
177         if (nodeName.equals(PurapWorkflowConstants.APPROVAL_ORDERS)) {
178             return isRequiredOrderType(this.getPurchaseOrderTypeId(), PurapConstants.ORDER_TYPE_APPROVAL);
179         }
180         if (nodeName.equals(PurapWorkflowConstants.HAS_VENDOR)) {
181             return isMissingVendor();
182         }
183         if (nodeName.equals(PurapWorkflowConstants.HAS_FIRMFIXED_WITH_LR)) {
184             return isRequiredOrderType(this.getPurchaseOrderTypeId(), PurapConstants.ORDER_TYPE_FIRM);
185         }
186         if (nodeName.equals(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED)) {
187             return isBudgetReviewRequired();
188         }
189         if (nodeName.equals(PurapWorkflowConstants.NOTIFY_BUDGET_REVIEW)) {
190             return isNotificationRequired();
191         }
192         throw new UnsupportedOperationException("Cannot answer split question for this node you call \"" + nodeName + "\"");
193     }
194 
195     /*
196      * Modified as per review comments OLE-24
197      */
198     protected boolean isMissingVendor() {
199         if (this.getVendorHeaderGeneratedIdentifier() == null || this.getVendorDetailAssignedIdentifier() == null) {
200             return false;
201         } else {
202             return true;
203         }
204     }
205 
206     /*protected boolean isLicenseRequested() {
207         if (this.isLicensingRequirementIndicator()) {
208             return true;
209         }
210         else {
211             return false;
212         }
213     }
214 */
215     @Override
216     protected boolean isMissingAccountingLines() {
217         for (Iterator iterator = getItems().iterator(); iterator.hasNext(); ) {
218             RequisitionItem item = (RequisitionItem) iterator.next();
219             if (item.isConsideredEntered() && item.isAccountListEmpty()) {
220                 return true;
221             }
222         }
223 
224         return false;
225     }
226 
227     /*
228      * Modified as per review comments for OLE-24
229      */
230     protected boolean isRequiredOrderType(BigDecimal purchaseOrderTypeId, String orderType) {
231         LOG.debug("----Inside isRequiredOrderType------");
232         /*   Map purchaseOrderTypeIdMap = new HashMap();
233         String purchaseOrderType = "";
234         purchaseOrderTypeIdMap.put("purchaseOrderTypeId", this.getPurchaseOrderTypeId());
235 
236         org.kuali.rice.krad.service.BusinessObjectService
237                 businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
238         List<PurchaseOrderType> purchaseOrderTypeList = (List) businessObjectService.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
239         if (purchaseOrderTypeList.size() > 0) {
240             purchaseOrderType = purchaseOrderTypeList.get(0).getPurchaseOrderType();
241         }
242         if (LOG.isDebugEnabled()) {
243             LOG.debug("Purchase Order Type is >>>>>>" + purchaseOrderType);
244         }
245 
246         if (purchaseOrderType.equals(orderType)) {
247             return true;
248         }*/
249 
250         return true;
251     }
252 
253     public static OlePurapAccountingService getOlePurapAccountingService() {
254         if (olePurapAccountingService == null) {
255             olePurapAccountingService = SpringContext.getBean(OlePurapAccountingService.class);
256         }
257         return olePurapAccountingService;
258     }
259 
260     public static void setOlePurapAccountingService(OlePurapAccountingService olePurapAccountingService) {
261         OleRequisitionDocument.olePurapAccountingService = olePurapAccountingService;
262     }
263 
264     public static PurapService getPurapServiceImpl() {
265         if (purapServiceImpl == null) {
266             purapServiceImpl = SpringContext.getBean(PurapService.class);
267         }
268         return purapServiceImpl;
269     }
270 
271     public static void setPurapServiceImpl(PurapService purapServiceImpl) {
272         OleRequisitionDocument.purapServiceImpl = purapServiceImpl;
273     }
274 
275     public static OlePurchaseOrderService getOlePurchaseOrderService() {
276         if (olePurchaseOrderService == null) {
277             olePurchaseOrderService = SpringContext.getBean(OlePurchaseOrderService.class);
278         }
279         return olePurchaseOrderService;
280     }
281 
282     public static void setOlePurchaseOrderService(OlePurchaseOrderService olePurchaseOrderService) {
283         OleRequisitionDocument.olePurchaseOrderService = olePurchaseOrderService;
284     }
285 
286     public static WorkflowDocumentService getWorkflowDocumentService() {
287         if (workflowDocumentService == null) {
288             workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
289         }
290         return workflowDocumentService;
291     }
292 
293     public static void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) {
294         OleRequisitionDocument.workflowDocumentService = workflowDocumentService;
295     }
296 
297     @Override
298     public ParameterService getParameterService() {
299         if (parameterService == null) {
300             parameterService = SpringContext.getBean(ParameterService.class);
301         }
302         return parameterService;
303     }
304 
305     public static void setParameterService(ParameterService parameterService) {
306         OleRequisitionDocument.parameterService = parameterService;
307     }
308 
309     public static RequisitionService getRequisitionService() {
310         if (RequisitionService == null) {
311             RequisitionService = SpringContext.getBean(RequisitionService.class);
312         }
313         return RequisitionService;
314     }
315 
316     public static void setRequisitionService(RequisitionService RequisitionService) {
317         OleRequisitionDocument.RequisitionService = RequisitionService;
318     }
319 
320     public static ConfigurationService getConfigurationService() {
321         if (kualiConfigurationService == null) {
322             kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
323         }
324         return kualiConfigurationService;
325     }
326 
327     public static void setConfigurationService(ConfigurationService kualiConfigurationService) {
328         OleRequisitionDocument.kualiConfigurationService = kualiConfigurationService;
329     }
330 
331     public static BibInfoWrapperService getBibInfoWrapperService() {
332         if (bibInfoWrapperService == null) {
333             bibInfoWrapperService = SpringContext.getBean(BibInfoWrapperService.class);
334         }
335         return bibInfoWrapperService;
336     }
337 
338     public static void setBibInfoWrapperService(BibInfoWrapperService bibInfoWrapperService) {
339         OleRequisitionDocument.bibInfoWrapperService = bibInfoWrapperService;
340     }
341 
342     public static OleRequestSourceService getOleRequestSourceService() {
343         if (oleRequestSourceService == null) {
344             oleRequestSourceService = SpringContext.getBean(OleRequestSourceService.class);
345         }
346         return oleRequestSourceService;
347     }
348 
349     public static void setOleRequestSourceService(OleRequestSourceService oleRequestSourceService) {
350         OleRequisitionDocument.oleRequestSourceService = oleRequestSourceService;
351     }
352 
353 
354     public static PurchaseOrderTypeService getPurchaseOrderTypeService() {
355         if (purchaseOrderTypeService == null) {
356             purchaseOrderTypeService = SpringContext.getBean(PurchaseOrderTypeService.class);
357         }
358         return purchaseOrderTypeService;
359     }
360 
361     public static void setPurchaseOrderTypeService(PurchaseOrderTypeService purchaseOrderTypeService) {
362         OleRequisitionDocument.purchaseOrderTypeService = purchaseOrderTypeService;
363     }
364 
365 
366     public static FileProcessingService getFileProcessingService() {
367         if (fileProcessingService == null) {
368             fileProcessingService = SpringContext.getBean(FileProcessingService.class);
369         }
370         return fileProcessingService;
371     }
372 
373     public static void setFileProcessingService(FileProcessingService fileProcessingService) {
374         OleRequisitionDocument.fileProcessingService = fileProcessingService;
375     }
376 
377     public static DateTimeService getDateTimeService() {
378         if (dateTimeService == null) {
379             dateTimeService = SpringContext.getBean(DateTimeService.class);
380         }
381         return dateTimeService;
382     }
383 
384     public static void setDateTimeService(DateTimeService dateTimeService) {
385         OleRequisitionDocument.dateTimeService = dateTimeService;
386     }
387 
388     @Override
389     public BusinessObjectService getBusinessObjectService() {
390         if (businessObjectService == null) {
391             businessObjectService = SpringContext.getBean(BusinessObjectService.class);
392         }
393         return businessObjectService;
394     }
395 
396     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
397         this.businessObjectService = businessObjectService;
398     }
399 
400     public static BibInfoService getBibInfoService() {
401         if (bibInfoService == null) {
402             bibInfoService = SpringContext.getBean(BibInfoServiceImpl.class);
403         }
404         return bibInfoService;
405     }
406 
407     public static void setBibInfoService(BibInfoService bibInfoService) {
408         OleRequisitionDocument.bibInfoService = bibInfoService;
409     }
410 
411     public static OlePurapService getOlePurapService() {
412         if (olePurapService == null) {
413             olePurapService = SpringContext.getBean(OlePurapService.class);
414         }
415         return olePurapService;
416     }
417 
418     public static void setOlePurapService(OlePurapService olePurapService) {
419         OleRequisitionDocument.olePurapService = olePurapService;
420     }
421 
422     public static OlePatronDocumentList getOlePatronDocumentList() {
423         if (olePatronDocumentList == null) {
424             olePatronDocumentList = SpringContext.getBean(OlePatronDocumentList.class);
425         }
426         return olePatronDocumentList;
427     }
428 
429     public static void setOlePatronDocumentList(OlePatronDocumentList olePatronDocumentList) {
430         OleRequisitionDocument.olePatronDocumentList = olePatronDocumentList;
431     }
432 
433     public static OleCopyHelperService getOleCopyHelperService() {
434         if(oleCopyHelperService  == null){
435             oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
436         }
437         return oleCopyHelperService;
438     }
439 
440     public static void setOleCopyHelperService(OleCopyHelperService oleCopyHelperService) {
441         OleRequisitionDocument.oleCopyHelperService = oleCopyHelperService;
442     }
443 
444     @Override
445     public void prepareForSave() {
446         try {
447             LOG.debug("###########Inside OleRequisitionDocument prepareForSave###########");
448             if (this.getRequisitionSourceCode() == null) {
449                 this.setRequisitionSourceCode(OleSelectConstant.REQUISITON_SRC_TYPE_DIRECTINPUT);
450             }
451             List<OleRequisitionItem> items = this.getItems();
452             Iterator iterator = items.iterator();
453             while (iterator.hasNext()) {
454                 LOG.debug("###########inside prepareForSave ole requisition item###########");
455                 OleRequisitionItem singleItem = (OleRequisitionItem) iterator.next();
456                 KRADServiceLocator.getBusinessObjectService().delete(singleItem.getDeletedCopiesList());
457                 setItemDetailWhilePrepareForSave(singleItem);
458                 setDocumentHeaderDescription(singleItem);
459                 //Creatbib method is executed when the order is through Preorderservice
460                 if (this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM)) {
461                     createBib(singleItem);
462                 }
463             }
464         } catch (DocStoreConnectionException dsce) {
465             GlobalVariables.getMessageMap().putError("error.requisition.docstore.connectionError", RiceKeyConstants.ERROR_CUSTOM, "Error while connecting to document storage server, contact system administrator.");
466         } catch (Exception e) {
467             LOG.error("Exception during prepareForSave() in OleRequisitionDocument", e);
468             GlobalVariables.getMessageMap().putError("error.requisition.docstore.connectionError", RiceKeyConstants.ERROR_CUSTOM, e.getMessage());
469             throw new RuntimeException(e);
470         }
471     }
472 
473     /**
474      * This method is used to set the item while prepareforsave method is executed
475      * @param singleItem
476      */
477     private void setItemDetailWhilePrepareForSave(OleRequisitionItem singleItem){
478         if (!this.getRequisitionSourceCode().equalsIgnoreCase(
479                 OleSelectConstant.REQUISITON_SRC_TYPE_DIRECTINPUT) && !this.getRequisitionSourceCode().equalsIgnoreCase(
480                 OleSelectConstant.REQUISITON_SRC_TYPE_AUTOINGEST)) {
481             singleItem.setVendorItemPoNumber(this.vendorPoNumber);
482         }
483         if (singleItem.getRequestSourceTypeId() == null) {
484             setRequestSourceTypeId(singleItem);
485             if(this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_AUTOINGEST)){
486                 if (singleItem.getCopyList() == null || singleItem.getCopyList().size() == 0) {
487                     singleItem.setCopyList(getCopyList(singleItem));
488                 }
489             }
490             if (singleItem.getBibInfoBean() != null) {
491                 singleItem.getBibInfoBean().setRequestSource(OleSelectConstant.REQUEST_SRC_TYPE_STAFF);
492             }
493         }
494         if (!StringUtils.isEmpty(singleItem.getInternalRequestorId()) && singleItem.getRequestorTypeId() == null) {
495             singleItem.setRequestorTypeId(getOlePurapService().getRequestorTypeId(OleSelectConstant.REQUESTOR_TYPE_STAFF));
496         }
497     }
498 
499     /**
500      * This method is used to creat bib for the given Bib information
501      * @param singleItem
502      */
503     private void createBib(OleRequisitionItem singleItem){
504         LOG.debug("### Inside createBib() on OleRequisitionDocument ###");
505         try{
506             if (singleItem.getBibInfoBean() != null && singleItem.getBibInfoBean().getTitle() != null && singleItem.getItemTitleId() == null) {
507                 List<BibMarcRecord> bibMarcRecordList = new ArrayList<>();
508                 BibMarcRecords bibMarcRecords = new BibMarcRecords();
509                 BibMarcRecord bibMarcRecord = new BibMarcRecord();
510                 getOlePurapService().setBibMarcRecord(bibMarcRecord,singleItem.getBibInfoBean());
511                 bibMarcRecordList.add(bibMarcRecord);
512                 bibMarcRecords.setRecords(bibMarcRecordList);
513                 BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
514                 Bib newBib = new BibMarc();
515                 newBib.setCategory(DocCategory.WORK.getCode());
516                 newBib.setType(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode());
517                 newBib.setFormat(DocFormat.MARC.getCode());
518                 newBib.setContent(bibMarcRecordProcessor.toXml(bibMarcRecords));
519                 getDocstoreClientLocator().getDocstoreClient().createBib(newBib);
520                 newBib.deserializeContent(newBib);
521                 if (newBib.getId() != null) {
522                     singleItem.setItemTitleId(newBib.getId());
523                     singleItem.getBibInfoBean().setTitleId(newBib.getId());
524                     singleItem.setItemDescription(getOlePurapService().getItemDescription(newBib));
525                     //setItemDescription(singleItem, newBib);
526                 }
527             }
528         }catch(Exception e){
529             LOG.error("Exception while creating bib for Preorderservice in OleRequisitionDocument class",e);
530         }
531     }
532 
533     /**
534      * This method is used to set the item description on item for the given Bib
535      * @param oleRequisitionItem
536      * @param newBib
537      */
538 /*    private void setItemDescription(OleRequisitionItem oleRequisitionItem, Bib newBib){
539         LOG.debug("### Inside setItemDescription() of OleRequisitionDocument ###");
540         String itemDescription = ((newBib.getTitle() != null && !newBib.getTitle().isEmpty()) ? newBib.getTitle() + "," : "") + ((newBib.getAuthor() != null && !newBib.getAuthor().isEmpty()) ? newBib.getAuthor() + "," : "") + ((newBib.getPublisher() != null && !newBib.getPublisher().isEmpty()) ? newBib.getPublisher() + "," : "") + ((newBib.getIsbn() != null && !newBib.getIsbn().isEmpty()) ? newBib.getIsbn() + "," : "");
541         itemDescription = itemDescription.substring(0, itemDescription.lastIndexOf(","));
542         if(LOG.isDebugEnabled()){
543             LOG.debug("Item Description---------->"+itemDescription);
544         }
545         StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
546         itemDescription = stringEscapeUtils.unescapeHtml(itemDescription);
547         oleRequisitionItem.setItemDescription(itemDescription);
548     }*/
549 
550     private void setRequestSourceTypeId(OleRequisitionItem singleItem){
551         try{
552             if(LOG.isInfoEnabled()){
553                 LOG.info("RequisitionSourceCode---->" + this.getRequisitionSourceCode());
554             }
555             if (this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_DIRECTINPUT)) {
556                 singleItem.setRequestSourceTypeId(getOleRequestSourceService().getRequestSourceTypeId(OleSelectConstant.REQUEST_SRC_TYPE_STAFF));
557             } else if (this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM)) {
558                 singleItem.setRequestSourceTypeId(getOleRequestSourceService().getRequestSourceTypeId(OleSelectConstant.REQUEST_SRC_TYPE_WEBFORM));
559             } else {
560                 singleItem.setRequestSourceTypeId(getOleRequestSourceService().getRequestSourceTypeId(OleSelectConstant.REQUEST_SRC_TYPE_BATCHINGEST));
561             }
562         }catch (Exception e){
563             LOG.error("Error while setting RequestSourceTypeId");
564         }
565     }
566     /**
567      * This method is used to get the copies list for the given line item
568      * @param singleItem
569      * @return
570      */
571     private List<OleCopy> getCopyList(OleRequisitionItem singleItem){
572         LOG.debug("### Inside getCopyList() of OleRequisitionDocument ###");
573         List<OleCopies> itemCopies = new ArrayList<>();
574         OleRequisitionCopies oleRequisitionCopies = new OleRequisitionCopies();
575         oleRequisitionCopies.setItemCopies(singleItem.getItemQuantity());
576         oleRequisitionCopies.setParts(singleItem.getItemNoOfParts());
577         oleRequisitionCopies.setLocationCopies(singleItem.getItemLocation());
578         if (singleItem.getOleOrderRecord() != null && singleItem.getOleOrderRecord().getOleTxRecord() != null) {
579             oleRequisitionCopies.setCaption(singleItem.getOleOrderRecord().getOleTxRecord().getCaption());
580             if (singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
581                 StringBuffer stringBuffer = new StringBuffer();
582                 for (int i = 1; i <= singleItem.getItemNoOfParts().intValue(); i++) {
583                     stringBuffer.append(i + ",");
584                 }
585                 oleRequisitionCopies.setVolumeNumber(stringBuffer.toString());
586             } else {
587                 oleRequisitionCopies.setVolumeNumber(singleItem.getOleOrderRecord().getOleTxRecord().getVolumeNumber());
588             }
589         }
590         itemCopies.add(oleRequisitionCopies);
591         List<OleCopy> oleCopyList = getOleCopyHelperService().setCopyValuesForList(itemCopies, singleItem.getItemTitleId(), singleItem.getBibTree());
592         if (oleCopyList != null && oleCopyList.size() > 0) {
593             if (oleCopyList.size() == 1) {
594                 OleCopy oleCopy = oleCopyList.get(0);
595                 singleItem.setItemLocation(oleCopy.getLocation());
596             } else {
597                 singleItem.setItemLocation(OLEConstants.MULTIPLE_ITEM_LOC);
598             }
599         }
600         return oleCopyList;
601     }
602 
603     private void setDocumentHeaderDescription(OleRequisitionItem singleItem) throws Exception {
604         LOG.debug("### Inside setDocumentHeaderDescription of OleRequisitionDocument ###");
605         if (this.getDocumentHeader().getDocumentDescription() == null || StringUtils.isEmpty(this.getDocumentHeader().getDocumentDescription())) {
606             if (this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_DIRECTINPUT)) {
607                 String operatorInitials = getOlePurapService().getOperatorInitials();
608                 this.getDocumentHeader().setDocumentDescription(OleSelectConstant.STAFF_REQUEST + (StringUtils.isEmpty(operatorInitials) ? "" : "_" + operatorInitials) + "_" + getCurrentDateTime());
609             } else if (this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM)) {
610                 String operatorInitials = getOlePurapService().getOperatorInitials();
611                 this.getDocumentHeader().setDocumentDescription(OleSelectConstant.WEBFORM_REQUEST + (StringUtils.isEmpty(operatorInitials) ? "" : "_" + operatorInitials) + "_" + getCurrentDateTime());
612             } else if (this.getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_MANUALINGEST)) {
613                 String operatorInitials = getOlePurapService().getOperatorInitials();
614                 this.getDocumentHeader().setDocumentDescription(OLEConstants.MANUAL_INGEST_DOCUMENT_DESCRIPTION + (StringUtils.isEmpty(operatorInitials) ? "" : "_" + operatorInitials) + "_" + getCurrentDateTime() + (StringUtils.isEmpty(singleItem.getBibInfoBean().getYbp()) ? "" : "_" + singleItem.getBibInfoBean().getYbp()));
615             }
616         }
617     }
618 
619     //TODO: Refactor to call the docsearch api to get the title, author, isbn etc information for the description field
620     @Override
621     public void processAfterRetrieve() {
622         //  super.processAfterRetrieve();
623         try {
624             LOG.debug("###########inside OleRequisitionDocument processAfterRetrieve###########");
625             PurchaseOrderType purchaseOrderTypeDoc = getOlePurapService().getPurchaseOrderType(this.getPurchaseOrderTypeId());
626             if(purchaseOrderTypeDoc != null){
627                 this.setOrderType(purchaseOrderTypeDoc);
628             }
629             if (this.getVendorAliasName() == null) {
630                 populateVendorAliasName();
631             }
632             List<OleRequisitionItem> items = this.getItems();
633             Iterator iterator = items.iterator();
634             while (iterator.hasNext()) {
635                 LOG.debug("###Inside while loop of processAfterRetrive()###");
636                 OleRequisitionItem singleItem = (OleRequisitionItem) iterator.next();
637                 setItemDetailWhileProcessAfterRetrive(singleItem);
638             }
639         } catch (Exception e) {
640             LOG.error("Exception in during processAfterRetrieve for OleRequisitionDocument " + e);
641             throw new RuntimeException(e);
642         }
643     }
644 
645 
646     /**
647      * This method is used to set the item detail while processafterretrive method is executed
648      * @param singleItem
649      */
650     private void setItemDetailWhileProcessAfterRetrive(OleRequisitionItem singleItem){
651         try{
652             if (LOG.isInfoEnabled()) {
653                 LOG.info("Title id while retriving in REQ------>" + singleItem.getItemTitleId());
654             }
655             // Added for jira OLE-2811 starts
656             //Modified for jiar OLE-6032
657             if (singleItem.getRequestorId() != null) {
658                 singleItem.setRequestorFirstName(getOlePurapService().getPatronName(singleItem.getRequestorId()));
659             }
660             if (singleItem.getItemUnitPrice() != null) {
661                 singleItem.setItemUnitPrice(singleItem.getItemUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP));
662             }
663             // Added for jira OLE-2811 ends
664             if (singleItem.getItemTitleId() != null) {
665                 LOG.debug("###########inside processAfterRetrieve ole requisition item###########");
666                 Bib bib = new BibMarc();
667                 if (singleItem.getItemTitleId() != null && singleItem.getItemTitleId() != "") {
668                     bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(singleItem.getItemTitleId());
669                     singleItem.setBibUUID(bib.getId());
670                 }
671                 singleItem.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(singleItem.getItemTitleId()));
672                 singleItem.setBibInfoBean(new BibInfoBean());
673                 singleItem.setItemDescription(getOlePurapService().getItemDescription(bib));
674             }
675             if (singleItem.getItemType() != null && singleItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
676                 populateCopiesSection(singleItem);
677             }
678             if (singleItem.getCopyList().size() > 0) {
679                 getOlePurapService().setInvoiceDocumentsForRequisition(singleItem);
680             }
681             if (singleItem.getClaimDate() == null) {
682                 getOlePurapService().setClaimDateForReq(singleItem,this.vendorDetail);
683             }
684         }catch (Exception e){
685             LOG.error("Error while setting the requisition item detail.",e);
686         }
687     }
688 
689     /**
690      * This method is used to populated the copies section details
691      * @param singleItem
692      */
693     private void populateCopiesSection(OleRequisitionItem singleItem) {
694         if (singleItem.getCopies().size() > 0) {
695             List<OleCopy> copyList = getOleCopyHelperService().setCopyValuesForList(singleItem.getCopies(), singleItem.getItemTitleId(), null);
696             if (copyList.size() >= singleItem.getCopyList().size()) {
697                 int copyCount = 0;
698                 for (OleCopy oleCopy : singleItem.getCopyList()) {
699                     OleCopy copy = copyList.get(copyCount);
700                     oleCopy.setLocation(copy.getLocation());
701                     oleCopy.setEnumeration(copy.getEnumeration());
702                     oleCopy.setCopyNumber(copy.getCopyNumber());
703                     oleCopy.setPartNumber(copy.getPartNumber());
704                     oleCopy.setReqDocNum(this.getPurapDocumentIdentifier());
705                     copyCount++;
706                 }
707                 for (int i = copyCount; i < copyList.size(); i++) {
708                     singleItem.getCopyList().add(copyList.get(copyCount));
709                     copyCount++;
710                 }
711             }
712         } else if (singleItem.getCopyList() != null && singleItem.getCopyList().size() == 1) {
713             singleItem.getCopyList().get(0).setReqDocNum(this.getPurapDocumentIdentifier());
714         } else {
715             if (singleItem.getItemQuantity() != null && singleItem.getItemNoOfParts() != null && (singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
716                     || singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
717                 singleItem.setCopies(getOleCopyHelperService().setCopiesToLineItem(singleItem.getCopyList(), singleItem.getItemNoOfParts(), singleItem.getItemTitleId()));
718             }
719         }
720         if (singleItem.getItemQuantity() != null && singleItem.getItemNoOfParts() != null && !singleItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
721                 && !singleItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)) && singleItem.getCopyList().size() > 0) {
722             singleItem.setSingleCopyNumber(singleItem.getCopyList().get(0).getCopyNumber());
723         }
724     }
725 
726     @Override
727     public Class getItemClass() {
728         // TODO Auto-generated method stub
729         return OleRequisitionItem.class;
730     }
731 
732     /**
733      * Returns current Date in MMddyyHHmm format to be appended in the document description
734      *
735      * @return current getCurrentDateTime in String
736      */
737     public String getCurrentDateTime() {
738         LOG.debug("Inside getCurrentDateTime()");
739         Date date = getDateTimeService().getCurrentDate();
740         String currentDate = SpringContext.getBean(DateTimeService.class).toString(date, timeStampFormat);
741         LOG.debug("End of getCurrentDateTime()");
742         return currentDate;
743     }
744 
745     /**
746      * Prepopulates Requisition Document description to Library Material_operatorinitials_datetime
747      *
748      * @return void
749      */
750     @Override
751     public void initiateDocument() throws WorkflowException {
752         String description = getOlePurapService().getParameter(OLEConstants.REQ_DESC);
753         description = getOlePurapService().setDocumentDescription(description,null);
754         this.getDocumentHeader().setDocumentDescription(description);
755         this.setPurchaseOrderTypeId(getParameterService().getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.DEFAULT_ORDER_TYPE));
756         /*this.setLicensingRequirementCode(getParameterService().getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.DEFAULT_LICENSE_STATUS));*/
757         super.initiateDocument();
758         setDeliveryDetail(this);
759         this.setPurchaseOrderTransmissionMethodCode(OleSelectConstant.METHOD_OF_PO_TRANSMISSION_NOPR);
760         // populating the initialCollapseSections
761         getOlePurapService().getInitialCollapseSections(this);
762     }
763 
764     public boolean getIsFinalReqs() {
765         if (this.getDocumentHeader().getWorkflowDocument().isFinal()) {
766             return true;
767         }
768         return false;
769     }
770 
771     private void setDeliveryDetail(OleRequisitionDocument document) {
772         Person currentUser = GlobalVariables.getUserSession().getPerson();
773         DefaultPrincipalAddress defaultPrincipalAddress = new DefaultPrincipalAddress(currentUser.getPrincipalId());
774         Map addressKeys = getPersistenceService().getPrimaryKeyFieldValues(defaultPrincipalAddress);
775         defaultPrincipalAddress = getBusinessObjectService().findByPrimaryKey(DefaultPrincipalAddress.class, addressKeys);
776         boolean isDefaultAddress = false;
777         if (ObjectUtils.isNotNull(defaultPrincipalAddress) && ObjectUtils.isNotNull(defaultPrincipalAddress.getBuilding())) {
778             isDefaultAddress = defaultPrincipalAddress.getBuilding().isActive();
779         }
780         if (!isDefaultAddress) {
781             Person personImpl = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPrincipalId());
782             //Modified as per review comments OLE-24
783             String defaultRoomNumber = getParameter("DELIVERY_DEFAULT_ROOMNUMBER");
784             if(defaultRoomNumber != null){
785                 defaultRoomNumber = defaultRoomNumber.trim();
786             }
787             document.setDeliveryBuildingLine1Address(personImpl.getAddressLine1());
788             document.setDeliveryBuildingLine2Address(personImpl.getAddressLine2());
789             //Modified as per review comments OLE-24
790             if (document.getDeliveryBuildingLine1Address() != null && !(document.getDeliveryBuildingLine1Address().trim().equals(""))) {
791                 document.setDeliveryBuildingRoomNumber(defaultRoomNumber);
792             }
793             document.setDeliveryCityName(personImpl.getAddressCity());
794             document.setDeliveryStateCode(personImpl.getAddressStateProvinceCode());
795             document.setDeliveryPostalCode(personImpl.getAddressPostalCode());
796             document.setDeliveryToName(personImpl.getName());
797             document.setDeliveryCountryCode(personImpl.getAddressCountryCode());
798 
799         }
800 
801     }
802 
803     /**
804      * Returns current Date in MMddyy(100311) format to be appended in the document description
805      *
806      * @return current DateTime in String
807      */
808     public String getCurrentDate() {
809         LOG.debug("Inside getCurrentDate()");
810         //Modified as per review comments OLE-24
811         Date date = getDateTimeService().getCurrentDate();
812         SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
813         String currentDate = sdf.format(date);
814         LOG.debug("End of getCurrentDate()");
815         return currentDate;
816     }
817 
818     /**
819      * @see org.kuali.rice.krad.document.DocumentBase#doRouteStatusChange()
820      */
821     @Override
822     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
823         LOG.debug("doRouteStatusChange() started");
824         super.doRouteStatusChange(statusChangeEvent);
825         try {
826             if (this.getDocumentHeader().getWorkflowDocument().isProcessed()) {
827                 String newRequisitionStatus = PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS;
828                 if (SpringContext.getBean(RequisitionService.class).isAutomaticPurchaseOrderAllowed(this)) {
829                     newRequisitionStatus = PurapConstants.RequisitionStatuses.APPDOC_CLOSED;
830                     if (this.getDocumentHeader().getDocumentNumber() == null) {
831                         this.setDocumentHeader((SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(this.getDocumentNumber())));
832                         SpringContext.getBean(OlePurchaseOrderService.class).createAutomaticPurchaseOrderDocument(this);
833                     } else {
834                         SpringContext.getBean(OlePurchaseOrderService.class).createAutomaticPurchaseOrderDocument(this);
835                     }
836                 }
837                 this.setApplicationDocumentStatus(newRequisitionStatus);
838             }
839             // DOCUMENT DISAPPROVED
840             else if (this.getDocumentHeader().getWorkflowDocument().isDisapproved()) {
841                 String nodeName = getDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator().next();
842                 //NodeDetails currentNode = NodeDetailEnum.getNodeDetailEnumByName(nodeName);
843                 HashMap<String, String> disApprovedStatusMap = PurapConstants.RequisitionStatuses.getRequistionAppDocStatuses();
844                 if (ObjectUtils.isNotNull(nodeName)) {
845                     if (StringUtils.isNotBlank(disApprovedStatusMap.get(nodeName))) {
846                         this.setApplicationDocumentStatus(disApprovedStatusMap.get(nodeName));
847                         //   updateStatusAndSave(disApprovedStatusMap.get(nodeName));
848                         return;
849                     }
850                 }
851                 logAndThrowRuntimeException("No status found to set for document being disapproved in node '" + nodeName + "'");
852             }
853             // DOCUMENT CANCELED
854             else if (this.getDocumentHeader().getWorkflowDocument().isCanceled()) {
855                 this.setApplicationDocumentStatus(RequisitionStatuses.APPDOC_CANCELLED);
856             }
857         } catch (Exception e) {
858             logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
859         }
860         LOG.debug("doRouteStatusChange() ending");
861     }
862 
863     /**
864      * @see org.kuali.rice.kns.document.DocumentBase#handleRouteLevelChange(org.kuali.rice.kew.clientapp.vo.DocumentRouteLevelChangeDTO)
865      */
866     @Override
867     public void doRouteLevelChange(DocumentRouteLevelChange change) {
868         LOG.debug("handleRouteLevelChange() started");
869         super.doRouteLevelChange(change);
870         try {
871             String newNodeName = change.getNewNodeName();
872             if (StringUtils.isNotBlank(newNodeName)) {
873                 RoutingReportCriteria.Builder reportCriteria = RoutingReportCriteria.Builder
874                         .createByDocumentIdAndTargetNodeName(getDocumentNumber(), newNodeName);
875                 List<String> desiredActions = new ArrayList<String>(2);
876                 desiredActions.add(ActionRequestType.APPROVE.getCode());
877                 desiredActions.add(ActionRequestType.COMPLETE.getCode());
878                 String note = "";
879                 if (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE)
880                         || newNodeName.equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET)) {
881                     if (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE)) {
882                         note = OLEConstants.SufficientFundCheck.REQ_NOTE;
883                     }
884                     if (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET)) {
885                         note = OLEConstants.SufficientFundCheck.FYI_NOTE;
886                     }
887                     DocumentService documentService = SpringContext.getBean(DocumentService.class);
888                     Note apoNote = documentService.createNoteFromDocument(this, note);
889                     this.addNote(apoNote);
890                     documentService.saveDocumentNotes(this);
891 
892                 }
893             }
894         } catch (Exception e) {
895             String errorMsg = "Workflow Error found checking actions requests on document with id "
896                     + getDocumentNumber() + ". *** WILL NOT UPDATE PURAP STATUS ***";
897             LOG.error(errorMsg, e);
898         }
899     }
900 
901     /**
902      * This method is used to get the bibedtior creat url from propertie file
903      *
904      * @return Bibeditor creat url string
905      */
906     public String getBibeditorCreateURL() {
907         String bibeditorCreateURL = getConfigurationService().getPropertyValueAsString(OLEConstants.BIBEDITOR_CREATE_URL_KEY);
908         return bibeditorCreateURL;
909     }
910 
911     public String getBibSearchURL() {
912         String bibSearchURL = getConfigurationService().getPropertyValueAsString(OLEConstants.BIBEDITOR_SEARCH_URL_KEY);
913         return bibSearchURL;
914     }
915 
916     /**
917      * This method is used to get the dublinedtior edit url from propertie file
918      *
919      * @return Dublineditor edit url string
920      */
921     public String getDublinEditorEditURL() {
922         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
923     }
924 
925     /**
926      * This method is used to get the bibedtior edit url from propertie file
927      *
928      * @return Bibeditor edit url string
929      */
930     public String getBibeditorEditURL() {
931         String bibeditorEditURL = getConfigurationService().getPropertyValueAsString(OLEConstants.BIBEDITOR_URL_KEY);
932         return bibeditorEditURL;
933     }
934 
935     /**
936      * This method is used to get the Instanceeditor url from propertie file
937      *
938      * @return Instanceeditor url string
939      */
940     public String getInstanceEditorURL() {
941         String instanceEditorURL = getConfigurationService().getPropertyValueAsString(
942                 OLEConstants.INSTANCEEDITOR_URL_KEY);
943         return instanceEditorURL;
944     }
945 
946     /**
947      * This method is used to get the dublinedtior view url from propertie file
948      *
949      * @return dublineditor view url string
950      */
951     public String getDublinEditorViewURL() {
952         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
953     }
954 
955     /**
956      * This method is used to get the bibedtior view url from propertie file
957      *
958      * @return Bibeditor view url string
959      */
960     public String getBibeditorViewURL() {
961         String bibeditorViewURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.DOCSTORE_APP_URL_KEY);
962         return bibeditorViewURL;
963     }
964 
965     /**
966      * This method is used to get the directory path where the marc xml files need to be created
967      *
968      * @return Directory path string
969      */
970     public String getMarcXMLFileDirLocation() throws Exception {
971         String externaleDirectory = getFileProcessingService().getMarcXMLFileDirLocation();
972         return externaleDirectory;
973     }
974 
975     public boolean getIsSplitPO() {
976         LOG.debug("Inside getIsSplitPO of OleRequisitionDocument");
977         if (this.getDocumentHeader().getWorkflowDocument().getDocumentTypeName().equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_SPLIT) && this.getDocumentHeader().getWorkflowDocument().isSaved()) {
978             return true;
979         }
980         return false;
981     }
982 
983     public boolean getIsReOpenPO() {
984         LOG.debug("Inside getIsReOpenPO of OleRequisitionDocument");
985         if (this.getDocumentHeader().getWorkflowDocument().getDocumentTypeName().equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_REOPEN) && this.getDocumentHeader().getWorkflowDocument().isSaved()) {
986             return true;
987         }
988         return false;
989     }
990 
991     public String getVendorPoNumber() {
992         return vendorPoNumber;
993     }
994 
995     public void setVendorPoNumber(String vendorPoNumber) {
996         this.vendorPoNumber = vendorPoNumber;
997     }
998 
999 
1000     @Override
1001     public void customPrepareForSave(KualiDocumentEvent event) {
1002         // Need this here so that it happens before the GL work is done
1003         getOlePurapAccountingService().updateAccountAmounts(this);
1004 
1005         if (event instanceof RouteDocumentEvent || event instanceof ApproveDocumentEvent) {
1006             if (purchasingAccountsPayableDocument instanceof VendorCreditMemoDocument && ((VendorCreditMemoDocument) purchasingAccountsPayableDocument).isSourceVendor()) {
1007                 return;
1008             }
1009             getPurapServiceImpl().calculateTax(this);
1010         }
1011     }
1012 
1013     /**
1014      * This method is used to check the status of the document for displaying view and edit buttons in line item
1015      *
1016      * @return boolean
1017      */
1018     public boolean getIsSaved() {
1019         if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
1020             return true;
1021         }
1022         return false;
1023     }
1024 
1025     @Override
1026     public String getLicenseURL() {
1027         return ConfigContext.getCurrentContextConfig().getProperty("license.web.service.url");
1028     }
1029 
1030 
1031     public boolean isBudgetReviewRequired() {
1032         OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
1033                 .getBean("oleRequisitionDocumentService");
1034         List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
1035         boolean sufficientFundCheck = false;
1036         for (SourceAccountingLine accLine : sourceAccountingLineList) {
1037             String notificationOption = null;
1038             Map<String, Object> key = new HashMap<String, Object>();
1039             String chartCode = accLine.getChartOfAccountsCode();
1040             String accNo = accLine.getAccountNumber();
1041             key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
1042             key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
1043             OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
1044                     OleSufficientFundCheck.class, key);
1045             if (account != null) {
1046                 notificationOption = account.getNotificationOption();
1047             }
1048             if (notificationOption != null
1049                     && (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW))) {
1050                 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
1051                 if (sufficientFundCheck) {
1052                     return sufficientFundCheck;
1053                 }
1054 
1055             }
1056         }
1057         return sufficientFundCheck;
1058     }
1059 
1060     private boolean isNotificationRequired() {
1061         OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
1062                 .getBean("oleRequisitionDocumentService");
1063         List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
1064         boolean sufficientFundCheck = false;
1065         for (SourceAccountingLine accLine : sourceAccountingLineList) {
1066             String notificationOption = null;
1067             Map<String, Object> key = new HashMap<String, Object>();
1068             String chartCode = accLine.getChartOfAccountsCode();
1069             String accNo = accLine.getAccountNumber();
1070             key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
1071             key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
1072             OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
1073                     OleSufficientFundCheck.class, key);
1074             if (account != null) {
1075                 notificationOption = account.getNotificationOption();
1076             }
1077             if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.NOTIFICATION)) {
1078                 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
1079                 if (sufficientFundCheck) {
1080                     return sufficientFundCheck;
1081                 }
1082             }
1083         }
1084         return sufficientFundCheck;
1085     }
1086 
1087     @Override
1088     protected void populateAccountsForRouting() {
1089 
1090         List<SufficientFundsItem> fundsItems = new ArrayList<SufficientFundsItem>();
1091         try {
1092             String nodeName = getFinancialSystemDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator()
1093                     .next();
1094             if (nodeName != null
1095                     && (nodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || nodeName
1096                     .equalsIgnoreCase(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED))) {
1097                 if (SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear()
1098                         .compareTo(getPostingYear()) >= 0) {
1099                     List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
1100                     for (GeneralLedgerPendingEntry glpe : pendingEntries) {
1101                         glpe.getChartOfAccountsCode();
1102                     }
1103                     SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
1104                     fundsItems = SpringContext.getBean(SufficientFundsService.class).checkSufficientFunds(
1105                             pendingEntries);
1106                     SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(
1107                             this);
1108                     SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());
1109                 }
1110                 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
1111                 accountsForRouting = (SpringContext.getBean(PurapAccountingService.class).generateSummary(getItems()));
1112                 List<String> fundsItemList = new ArrayList<String>();
1113                 for (SufficientFundsItem fundsItem : fundsItems) {
1114                     fundsItemList.add(fundsItem.getAccount().getChartOfAccountsCode());
1115                 }
1116                 setAccountsForRouting(accountsForRouting);
1117                 refreshNonUpdateableReferences();
1118                 for (SourceAccountingLine sourceLine : getAccountsForRouting()) {
1119                     sourceLine.refreshNonUpdateableReferences();
1120                 }
1121             } else {
1122                 super.populateAccountsForRouting();
1123             }
1124         } catch (Exception e) {
1125             logAndThrowRuntimeException("Error in populateAccountsForRouting while submitting document with id "
1126                     + getDocumentNumber(), e);
1127         }
1128 
1129     }
1130 
1131     private void populateVendorAliasName() {
1132         Map vendorDetailMap = new HashMap();
1133         vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
1134         vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
1135         List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
1136         if (vendorDetailList != null && vendorDetailList.size() > 0) {
1137             this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
1138         }
1139     }
1140 
1141     public boolean getIsATypeOfRCVGDoc() {
1142         return false;
1143     }
1144 
1145     public boolean getIsATypeOfCORRDoc() {
1146         return false;
1147     }
1148 
1149     public String getParameter(String name){
1150         ParameterKey parameterKey = ParameterKey.create(org.kuali.ole.OLEConstants.APPL_ID, org.kuali.ole.OLEConstants.SELECT_NMSPC, org.kuali.ole.OLEConstants.SELECT_CMPNT,name);
1151         Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
1152         return parameter!=null?parameter.getValue():null;
1153     }
1154 }