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.ar.document.service.impl; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 020 import java.util.List; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.kuali.kfs.module.ar.businessobject.Customer; 024 import org.kuali.kfs.module.ar.businessobject.NonAppliedHolding; 025 import org.kuali.kfs.module.ar.document.dataaccess.NonAppliedHoldingDao; 026 import org.kuali.kfs.module.ar.document.service.NonAppliedHoldingService; 027 import org.kuali.rice.kns.service.BusinessObjectService; 028 import org.springframework.transaction.annotation.Transactional; 029 030 @Transactional 031 public class NonAppliedHoldingServiceImpl implements NonAppliedHoldingService { 032 033 private BusinessObjectService businessObjectService; 034 private NonAppliedHoldingDao nonAppliedHoldingDao; 035 036 /** 037 * @see org.kuali.kfs.module.ar.document.service.NonAppliedHoldingService#getNonAppliedHoldingsForCustomer(org.kuali.kfs.module.ar.businessobject.Customer) 038 */ 039 public Collection<NonAppliedHolding> getNonAppliedHoldingsForCustomer(Customer customer) { 040 return null == customer ? null : getNonAppliedHoldingsForCustomer(customer.getCustomerNumber()); 041 } 042 043 /** 044 * @see org.kuali.kfs.module.ar.document.service.NonAppliedHoldingService#getNonAppliedHoldingsForCustomer(java.lang.String) 045 */ 046 public Collection<NonAppliedHolding> getNonAppliedHoldingsForCustomer(String customerNumber) { 047 if (StringUtils.isBlank(customerNumber)) { 048 throw new IllegalArgumentException("The parameter [customerNumber] passed in was blank or null."); 049 } 050 List<NonAppliedHolding> nonAppliedHoldings = new ArrayList<NonAppliedHolding>(); 051 //TODO WARNING this is going to degrade badly performance wise as the db fills up, 052 // this needs to be solved properly with a flag in the NonAppliedHolding 053 Collection<NonAppliedHolding> tempList = nonAppliedHoldingDao.getNonAppliedHoldingsForCustomer(customerNumber); 054 for (NonAppliedHolding nonAppliedHolding : tempList) { 055 if (nonAppliedHolding.getAvailableUnappliedAmount().isPositive()) { 056 nonAppliedHoldings.add(nonAppliedHolding); 057 } 058 } 059 return nonAppliedHoldings; 060 } 061 062 public Collection<NonAppliedHolding> getNonAppliedHoldingsByListOfDocumentNumbers(List<String> docNumbers) { 063 if (docNumbers == null) { 064 throw new IllegalArgumentException("The parameter [docNumbers] passed in was null."); 065 } 066 if (docNumbers.isEmpty()) { 067 return new ArrayList<NonAppliedHolding>(); 068 } 069 070 return nonAppliedHoldingDao.getNonAppliedHoldingsByListOfDocumentNumbers(docNumbers); 071 } 072 073 /** 074 * @param businessObjectService 075 */ 076 public void setBusinessObjectService(BusinessObjectService businessObjectService) { 077 this.businessObjectService = businessObjectService; 078 } 079 080 public void setNonAppliedHoldingDao(NonAppliedHoldingDao nonAppliedHoldingDao) { 081 this.nonAppliedHoldingDao = nonAppliedHoldingDao; 082 } 083 084 }