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.batch.service.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
20  import org.kuali.ole.module.purap.document.RequisitionDocument;
21  import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.sys.document.validation.event.DocumentSystemSaveEvent;
24  import org.kuali.rice.kew.framework.postprocessor.IDocumentEvent;
25  import org.kuali.rice.kim.api.identity.Person;
26  import org.kuali.rice.kim.api.identity.PersonService;
27  import org.kuali.rice.krad.service.DocumentService;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import java.util.HashMap;
30  import java.util.List;
31  import java.util.Map;
32  
33  public class RequisitionCreateDocumentServiceImpl implements RequisitionCreateDocumentService {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionCreateDocumentServiceImpl.class);
35  
36      protected DocumentService documentService;
37  
38      /**
39       * Gets the documentService attribute.
40       *
41       * @return Returns the documentService.
42       */
43      public DocumentService getDocumentService() {
44          return documentService;
45      }
46  
47  
48      /**
49       * Sets the documentService attribute value.
50       *
51       * @param documentService The documentService to set.
52       */
53      public void setDocumentService(DocumentService documentService) {
54          this.documentService = documentService;
55      }
56  /*    public boolean saveRequisitionDocuments(RequisitionDocument reqDocument) {
57          try {
58              documentService.saveDocument(reqDocument, DocumentSystemSaveEvent.class);
59              //documentService.prepareWorkflowDocument(reqDocument);
60              if ( LOG.isInfoEnabled() ) {
61                  LOG.info("Saved Requisition document. Document Number: "+reqDocument.getDocumentNumber());
62              }
63          }
64          catch (Exception e) {
65              LOG.error("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
66              throw new RuntimeException("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
67          }
68          return true;
69      }*/
70  
71      public String saveRequisitionDocuments(RequisitionDocument reqDocument) {
72          try {
73              if (LOG.isInfoEnabled()) {
74                  LOG.info("Calling saveRequisitionDocuments in RequisitionCreateDocumentServiceImpl >>>>" + reqDocument.getDocumentNumber());
75              }
76              try {
77                  documentService.saveDocument(reqDocument, DocumentSystemSaveEvent.class);
78              } catch (Exception e) {
79                  LOG.error("Exection while saving requisition document" + e);
80                  e.printStackTrace();
81              }
82              reqDocument.populateDocumentForRouting();
83  
84              Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
85              // reqDocument.getDocumentHeader().setWorkflowDocument(KNSServiceLocator.getWorkflowDocumentService().createWorkflowDocument(new Long(reqDocument.getDocumentNumber()), principalPerson));
86  
87              String purchaseOrderType = "";
88              if (reqDocument.getPurchaseOrderTypeId() != null) {
89  
90                  Map purchaseOrderTypeIdMap = new HashMap();
91                  purchaseOrderTypeIdMap.put("purchaseOrderTypeId", reqDocument.getPurchaseOrderTypeId());
92                  org.kuali.rice.krad.service.BusinessObjectService
93                          businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
94                  List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
95                  if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
96                      PurchaseOrderType purchaseOrderTypeDoc = (PurchaseOrderType) purchaseOrderTypeDocumentList.get(0);
97                      purchaseOrderType = purchaseOrderTypeDoc.getPurchaseOrderType();
98                  }
99                  if (LOG.isDebugEnabled())
100                     LOG.debug("purchaseOrderType >>>>>>>>>>>" + purchaseOrderType);
101                 //Modified for jira OLE-7278
102                 //if (purchaseOrderType.equalsIgnoreCase(PurapConstants.ORDER_TYPE_FIRM)) {
103                     getDocumentService().routeDocument(reqDocument, null, null);
104                 //}
105                 LOG.debug("After Calling createWorkflowDocument >>>>>>>>>>>");
106             }
107             //  System.out.println("After Calling createWorkflowDocument >>>>>>>>>>>" + reqDocument.getDocumentHeader().getWorkflowDocument().getStatus());
108             LOG.debug(IDocumentEvent.BEFORE_PROCESS);
109             if (LOG.isInfoEnabled()) {
110                 LOG.info("Saved Requisition document. Document Number: " + reqDocument.getDocumentNumber());
111             }
112         } catch (Exception e) {
113             LOG.error("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
114             throw new RuntimeException("Error persisting document # " + reqDocument.getDocumentHeader().getDocumentNumber() + " " + e.getMessage(), e);
115         }
116         return reqDocument.getDocumentNumber();
117     }
118 
119 }