View Javadoc
1   /*
2    * Copyright 2008-2009 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.module.purap.service.impl;
17  
18  import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItemMapping;
19  import org.kuali.ole.module.purap.businessobject.ItemType;
20  import org.kuali.ole.module.purap.dataaccess.ElectronicInvoiceItemMappingDao;
21  import org.kuali.ole.module.purap.service.ElectronicInvoiceItemMappingService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.krad.service.BusinessObjectService;
24  
25  import java.util.List;
26  
27  public class ElectronicInvoiceItemMappingServiceImpl implements ElectronicInvoiceItemMappingService {
28      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoiceItemMappingServiceImpl.class);
29  
30      private ElectronicInvoiceItemMappingDao electronicInvoiceItemMappingDao;
31  
32      public void setElectronicInvoiceItemMappingDao(ElectronicInvoiceItemMappingDao d) {
33          this.electronicInvoiceItemMappingDao = d;
34      }
35  
36      public List getAll() {
37          return electronicInvoiceItemMappingDao.getAll();
38      }
39  
40      public List getAllItemTypes() {
41          return electronicInvoiceItemMappingDao.getAllItemTypes();
42      }
43  
44      public ElectronicInvoiceItemMapping getById(String id) {
45          return electronicInvoiceItemMappingDao.getById(id);
46      }
47  
48      public ItemType getItemTypeByCode(String code) {
49          return electronicInvoiceItemMappingDao.getItemTypeByCode(code);
50      }
51  
52      public List save(ElectronicInvoiceItemMapping ei) {
53          // Before saving, if the id is empty, we are supposed to check whether the item mapping has existed in the database.
54          // If so, we should display an error to the user, if not, then continue with the saving.
55          ElectronicInvoiceItemMapping existing = electronicInvoiceItemMappingDao.getByUniqueKeys(ei.getVendorHeaderGeneratedIdentifier(), ei.getVendorDetailAssignedIdentifier(), ei.getInvoiceItemTypeCode());
56          if ((existing != null && ei.getInvoiceMapIdentifier() == null) || (ei.getInvoiceMapIdentifier() != null && !existing.getInvoiceMapIdentifier().equals(ei.getInvoiceMapIdentifier()))) {
57              /*
58               * FIXME need to record the errors as reject reasons and put those in route log somehow se.setTab("error");
59               * se.setMessageKey("errors.einvoice.item.mapping.duplicate.rows");
60               */
61          } else {
62              SpringContext.getBean(BusinessObjectService.class).save(ei);
63          }
64          return getAll();
65      }
66  
67      public List delete(String id) {
68          ElectronicInvoiceItemMapping ei = getById(id);
69          // If both the vendor ids are null, then we set service error with appropriate tab
70          // and message key, otherwise, do the delete.
71          if (ei.getVendorDetailAssignedIdentifier() == null && ei.getVendorHeaderGeneratedIdentifier() == null) {
72              /*
73               * FIXME need to record the errors as reject reasons and put those in route log somehow se.setTab("error");
74               * se.setMessageKey("errors.einvoice.item.mapping.null.vendor.id.deletion");
75               */
76          } else {
77              electronicInvoiceItemMappingDao.delete(ei);
78          }
79          return getAll();
80      }
81  
82  }