001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.module.purap.service.impl; 017 018 import java.util.List; 019 020 import org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceItemMapping; 021 import org.kuali.kfs.module.purap.businessobject.ItemType; 022 import org.kuali.kfs.module.purap.dataaccess.ElectronicInvoiceItemMappingDao; 023 import org.kuali.kfs.module.purap.service.ElectronicInvoiceItemMappingService; 024 025 public class ElectronicInvoiceItemMappingServiceImpl implements ElectronicInvoiceItemMappingService { 026 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoiceItemMappingServiceImpl.class); 027 028 private ElectronicInvoiceItemMappingDao electronicInvoiceItemMappingDao; 029 030 public void setElectronicInvoiceItemMappingDao(ElectronicInvoiceItemMappingDao d) { 031 this.electronicInvoiceItemMappingDao = d; 032 } 033 034 public List getAll() { 035 return electronicInvoiceItemMappingDao.getAll(); 036 } 037 038 public List getAllItemTypes() { 039 return electronicInvoiceItemMappingDao.getAllItemTypes(); 040 } 041 042 public ElectronicInvoiceItemMapping getById(String id) { 043 return electronicInvoiceItemMappingDao.getById(id); 044 } 045 046 public ItemType getItemTypeByCode(String code) { 047 return electronicInvoiceItemMappingDao.getItemTypeByCode(code); 048 } 049 050 public List save(ElectronicInvoiceItemMapping ei) { 051 // Before saving, if the id is empty, we are supposed to check whether the item mapping has existed in the database. 052 // If so, we should display an error to the user, if not, then continue with the saving. 053 ElectronicInvoiceItemMapping existing = electronicInvoiceItemMappingDao.getByUniqueKeys(ei.getVendorHeaderGeneratedIdentifier(), ei.getVendorDetailAssignedIdentifier(), ei.getInvoiceItemTypeCode()); 054 if ((existing != null && ei.getInvoiceMapIdentifier() == null) || (ei.getInvoiceMapIdentifier() != null && !existing.getInvoiceMapIdentifier().equals(ei.getInvoiceMapIdentifier()))) { 055 /* 056 * FIXME need to record the errors as reject reasons and put those in route log somehow se.setTab("error"); 057 * se.setMessageKey("errors.einvoice.item.mapping.duplicate.rows"); 058 */ 059 } 060 else { 061 electronicInvoiceItemMappingDao.save(ei); 062 } 063 return getAll(); 064 } 065 066 public List delete(String id) { 067 ElectronicInvoiceItemMapping ei = getById(id); 068 // If both the vendor ids are null, then we set service error with appropriate tab 069 // and message key, otherwise, do the delete. 070 if (ei.getVendorDetailAssignedIdentifier() == null && ei.getVendorHeaderGeneratedIdentifier() == null) { 071 /* 072 * FIXME need to record the errors as reject reasons and put those in route log somehow se.setTab("error"); 073 * se.setMessageKey("errors.einvoice.item.mapping.null.vendor.id.deletion"); 074 */ 075 } 076 else { 077 electronicInvoiceItemMappingDao.delete(ei); 078 } 079 return getAll(); 080 } 081 082 }