View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.service.impl;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.ole.module.purap.document.CorrectionReceivingDocument;
20  import org.kuali.ole.module.purap.document.LineItemReceivingDocument;
21  import org.kuali.ole.module.purap.document.ReceivingDocument;
22  import org.kuali.ole.select.businessobject.*;
23  import org.kuali.ole.select.document.OleCorrectionReceivingDocument;
24  import org.kuali.ole.select.document.OleLineItemReceivingDocument;
25  import org.kuali.ole.select.document.service.OleLineItemReceivingService;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
28  import org.kuali.rice.krad.service.BusinessObjectService;
29  
30  import java.util.*;
31  
32  public class OleLineItemReceivingServiceImpl implements OleLineItemReceivingService {
33  
34      private static final Logger LOG = Logger.getLogger(OleLineItemReceivingServiceImpl.class);
35  
36      private BusinessObjectService businessObjectService;
37  
38      protected ParameterService parameterService;
39  
40  
41      public void setParameterService(ParameterService parameterService) {
42          this.parameterService = parameterService;
43      }
44  
45      @Override
46      public void saveOleLineItemReceivingItemDoc(OleLineItemReceivingDoc oleLineItemReceivingItemDoc) {
47          //oleLineItemReceivingItemDoc.setActive(true);
48          businessObjectService.save(oleLineItemReceivingItemDoc);
49      }
50  
51  
52      @Override
53      public void saveOleLineItemReceivingCorrection(OleLineItemCorrectionReceivingDoc oleLineItemReceivingCorrection) {
54          //oleLineItemReceivingCorrection.setActive(true);
55          businessObjectService.save(oleLineItemReceivingCorrection);
56      }
57  
58      public OleLineItemReceivingDoc getOleLineItemReceivingDoc(Integer receivingItemIdentifier, Integer lineItemId) {
59          Map keys = new HashMap();
60          keys.put("receivingItemIdentifier", receivingItemIdentifier);
61          keys.put("lineItemId", lineItemId);
62          return (OleLineItemReceivingDoc) businessObjectService.findByPrimaryKey(OleLineItemReceivingDoc.class, keys);
63      }
64  
65      public OlePurchaseOrderItem getOlePurchaseOrderItem(Integer itemIdentifier) {
66          Map keys = new HashMap();
67          keys.put("itemIdentifier", itemIdentifier);
68          return (OlePurchaseOrderItem) businessObjectService.findByPrimaryKey(OlePurchaseOrderItem.class, keys);
69      }
70  
71      public OleLineItemReceivingDoc getOleLineItemReceivingDoc(Integer receivingItemIdentifier) {
72          Map keys = new HashMap();
73          keys.put("receivingLineItemIdentifier", receivingItemIdentifier);
74          return (OleLineItemReceivingDoc) businessObjectService.findByPrimaryKey(OleLineItemReceivingDoc.class, keys);
75      }
76  
77      public BusinessObjectService getBusinessObjectService() {
78          return businessObjectService;
79      }
80  
81      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
82          this.businessObjectService = businessObjectService;
83      }
84  
85      public OleLineItemCorrectionReceivingDoc getOleLineItemCorrectionReceivingDoc(Integer receivingItemIdentifier) {
86          Map keys = new HashMap();
87          keys.put("receivingLineItemIdentifier", receivingItemIdentifier);
88          return (OleLineItemCorrectionReceivingDoc) businessObjectService.findByPrimaryKey(OleLineItemCorrectionReceivingDoc.class, keys);
89  
90      }
91  
92      @Override
93      public String getLineItemDocItemTitleId(OleLineItemReceivingItem oleLineItemReceivingItem) throws Exception {
94          String itemTitleId = null;
95          Map oleLineItemReceivingDocMap = new HashMap();
96          oleLineItemReceivingDocMap.put("receivingLineItemIdentifier", oleLineItemReceivingItem.getReceivingItemIdentifier());
97          List<OleLineItemReceivingDoc> oleLineItemReceivingItemDocList = (List) businessObjectService.findMatching(org.kuali.ole.select.businessobject.OleLineItemReceivingDoc.class, oleLineItemReceivingDocMap);
98          Iterator iterator = oleLineItemReceivingItemDocList.iterator();
99          if (iterator.hasNext()) {
100             OleLineItemReceivingDoc oleLineItemReceivingDoc = (OleLineItemReceivingDoc) iterator.next();
101             itemTitleId = oleLineItemReceivingDoc.getItemTitleId();
102         }
103         return itemTitleId;
104     }
105 
106     @Override
107     public String getCorrectionItemDocItemTitleId(OleCorrectionReceivingItem oleCorrectionReceivingItem) throws Exception {
108         String itemTitleId = null;
109         Map oleCorrectionItemReceivingDocMap = new HashMap();
110         oleCorrectionItemReceivingDocMap.put(OLEConstants.RCV_LN_ITM_IDN, oleCorrectionReceivingItem.getReceivingItemIdentifier());
111         List<OleLineItemCorrectionReceivingDoc> oleLineCorrectionReceivingDoc = (List) businessObjectService.findMatching(org.kuali.ole.select.businessobject.OleLineItemCorrectionReceivingDoc.class, oleCorrectionItemReceivingDocMap);
112         Iterator iterator = oleLineCorrectionReceivingDoc.iterator();
113         if (iterator.hasNext()) {
114             OleLineItemCorrectionReceivingDoc oleLineItemCorrectionReceivingDoc = (OleLineItemCorrectionReceivingDoc) iterator.next();
115             itemTitleId = oleLineItemCorrectionReceivingDoc.getItemTitleId();
116         }
117         return itemTitleId;
118     }
119 
120     /**
121      * This method returns the section Name that are to be collapsed while opening the document
122      * @param document
123      * @return collapseSections
124      */
125     public void getInitialCollapseSections(ReceivingDocument document) {
126         LOG.debug("Inside getInitialCollapseSections()");
127         String[] collapseSections = new String[]{};
128         try {
129             if (document instanceof OleLineItemReceivingDocument) {
130                 OleLineItemReceivingDocument rcvlDocument = (OleLineItemReceivingDocument)document;
131                 collapseSections = parameterService.getParameterValuesAsString(LineItemReceivingDocument.class,
132                         OLEConstants.INITIAL_COLLAPSE_SECTIONS).toArray(new String[]{});
133                 rcvlDocument.setOverviewFlag(canCollapse(OLEConstants.OVERVIEW_SECTION, collapseSections));
134                 rcvlDocument.setDeliveryFlag(canCollapse(OLEConstants.DELIVERY_SECTION, collapseSections));
135                 rcvlDocument.setVendorFlag(canCollapse(OLEConstants.VENDOR_SECTION, collapseSections));
136                 rcvlDocument.setTitlesFlag(canCollapse(OLEConstants.TITLES_SECTION, collapseSections));
137                 rcvlDocument.setRelatedDocumentsFlag(canCollapse(OLEConstants.RELATED_DOCUMENT_SECTION, collapseSections));
138                 rcvlDocument.setNotesAndAttachmentFlag(canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION, collapseSections));
139                 rcvlDocument.setRouteLogFlag(canCollapse(OLEConstants.ROUTE_LOG_SECTION, collapseSections));
140             }
141             else if (document instanceof OleCorrectionReceivingDocument) {
142                 OleCorrectionReceivingDocument rcvcDocument = (OleCorrectionReceivingDocument)document;
143                 collapseSections = parameterService.getParameterValuesAsString(CorrectionReceivingDocument.class,
144                         OLEConstants.INITIAL_COLLAPSE_SECTIONS).toArray(new String[]{});
145                 rcvcDocument.setOverviewFlag(canCollapse(OLEConstants.OVERVIEW_SECTION, collapseSections));
146                 rcvcDocument.setDeliveryFlag(canCollapse(OLEConstants.DELIVERY_SECTION, collapseSections));
147                 rcvcDocument.setVendorFlag(canCollapse(OLEConstants.VENDOR_SECTION, collapseSections));
148                 rcvcDocument.setTitlesFlag(canCollapse(OLEConstants.ITEMS_SECTION, collapseSections));
149                 rcvcDocument.setRelatedDocumentsFlag(canCollapse(OLEConstants.RELATED_DOCUMENT_SECTION, collapseSections));
150                 rcvcDocument.setNotesAndAttachmentFlag(canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION, collapseSections));
151                 rcvcDocument.setRouteLogFlag(canCollapse(OLEConstants.ROUTE_LOG_SECTION,collapseSections));
152             }
153         }
154         catch (Exception e) {
155             LOG.error("Exception while getting the default Collapse section on PurchasingAccountsPayable Document"+e);
156             throw new RuntimeException(e);
157         }
158         LOG.debug("Leaving getInitialCollapseSections()");
159 
160     }
161 
162     private boolean canCollapse(String sectionName, String[] collapseSections) {
163         LOG.debug("Inside method canCollapse()");
164         List<String> sectionLists = Arrays.asList(collapseSections);
165         if (sectionLists.contains(sectionName)) {
166             return false;
167         }
168         return true;
169     }
170 
171 }