001/* 002 * Copyright 2008-2009 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.module.purap.service.impl; 017 018import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItemMapping; 019import org.kuali.ole.module.purap.businessobject.ItemType; 020import org.kuali.ole.module.purap.dataaccess.ElectronicInvoiceItemMappingDao; 021import org.kuali.ole.module.purap.service.ElectronicInvoiceItemMappingService; 022import org.kuali.ole.sys.context.SpringContext; 023import org.kuali.rice.krad.service.BusinessObjectService; 024 025import java.util.List; 026 027public class ElectronicInvoiceItemMappingServiceImpl implements ElectronicInvoiceItemMappingService { 028 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoiceItemMappingServiceImpl.class); 029 030 private ElectronicInvoiceItemMappingDao electronicInvoiceItemMappingDao; 031 032 public void setElectronicInvoiceItemMappingDao(ElectronicInvoiceItemMappingDao d) { 033 this.electronicInvoiceItemMappingDao = d; 034 } 035 036 public List getAll() { 037 return electronicInvoiceItemMappingDao.getAll(); 038 } 039 040 public List getAllItemTypes() { 041 return electronicInvoiceItemMappingDao.getAllItemTypes(); 042 } 043 044 public ElectronicInvoiceItemMapping getById(String id) { 045 return electronicInvoiceItemMappingDao.getById(id); 046 } 047 048 public ItemType getItemTypeByCode(String code) { 049 return electronicInvoiceItemMappingDao.getItemTypeByCode(code); 050 } 051 052 public List save(ElectronicInvoiceItemMapping ei) { 053 // Before saving, if the id is empty, we are supposed to check whether the item mapping has existed in the database. 054 // If so, we should display an error to the user, if not, then continue with the saving. 055 ElectronicInvoiceItemMapping existing = electronicInvoiceItemMappingDao.getByUniqueKeys(ei.getVendorHeaderGeneratedIdentifier(), ei.getVendorDetailAssignedIdentifier(), ei.getInvoiceItemTypeCode()); 056 if ((existing != null && ei.getInvoiceMapIdentifier() == null) || (ei.getInvoiceMapIdentifier() != null && !existing.getInvoiceMapIdentifier().equals(ei.getInvoiceMapIdentifier()))) { 057 /* 058 * FIXME need to record the errors as reject reasons and put those in route log somehow se.setTab("error"); 059 * se.setMessageKey("errors.einvoice.item.mapping.duplicate.rows"); 060 */ 061 } else { 062 SpringContext.getBean(BusinessObjectService.class).save(ei); 063 } 064 return getAll(); 065 } 066 067 public List delete(String id) { 068 ElectronicInvoiceItemMapping ei = getById(id); 069 // If both the vendor ids are null, then we set service error with appropriate tab 070 // and message key, otherwise, do the delete. 071 if (ei.getVendorDetailAssignedIdentifier() == null && ei.getVendorHeaderGeneratedIdentifier() == null) { 072 /* 073 * FIXME need to record the errors as reject reasons and put those in route log somehow se.setTab("error"); 074 * se.setMessageKey("errors.einvoice.item.mapping.null.vendor.id.deletion"); 075 */ 076 } else { 077 electronicInvoiceItemMappingDao.delete(ei); 078 } 079 return getAll(); 080 } 081 082}