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