001/* 002 * Copyright 2007 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.businessobject.options; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.ole.module.purap.PurapParameterConstants; 020import org.kuali.ole.module.purap.businessobject.PurchaseOrderTransmissionMethod; 021import org.kuali.ole.module.purap.document.PurchaseOrderDocument; 022import org.kuali.ole.sys.context.SpringContext; 023import org.kuali.rice.core.api.util.ConcreteKeyValue; 024import org.kuali.rice.core.api.util.KeyValue; 025import org.kuali.rice.coreservice.framework.parameter.ParameterService; 026import org.kuali.rice.krad.keyvalues.KeyValuesBase; 027import org.kuali.rice.krad.service.KeyValuesService; 028 029import java.util.ArrayList; 030import java.util.Collection; 031import java.util.List; 032 033/** 034 * Value Finder for Purchase Order Retransmission Methods. 035 */ 036public class PurchaseOrderRetransmissionMethodValuesFinder extends KeyValuesBase { 037 038 /** 039 * Returns code/description pairs of all Purchase Order Retransmission Methods. 040 * 041 * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues() 042 */ 043 public List<KeyValue> getKeyValues() { 044 KeyValuesService boService = SpringContext.getBean(KeyValuesService.class); 045 Collection<PurchaseOrderTransmissionMethod> codes = boService.findAll(PurchaseOrderTransmissionMethod.class); 046 String retransmitTypes = SpringContext.getBean(ParameterService.class).getParameterValueAsString(PurchaseOrderDocument.class, PurapParameterConstants.PURAP_PO_RETRANSMIT_TRANSMISSION_METHOD_TYPES); 047 List<KeyValue> labels = new ArrayList<KeyValue>(); 048 if (retransmitTypes != null) { 049 for (PurchaseOrderTransmissionMethod purchaseOrderTransmissionMethod : codes) { 050 if (StringUtils.contains(retransmitTypes, StringUtils.left(purchaseOrderTransmissionMethod.getPurchaseOrderTransmissionMethodCode(), 4)) && 051 purchaseOrderTransmissionMethod.isDisplayToUser()) { 052 labels.add(new ConcreteKeyValue(purchaseOrderTransmissionMethod.getPurchaseOrderTransmissionMethodCode(), purchaseOrderTransmissionMethod.getPurchaseOrderTransmissionMethodDescription())); 053 } 054 } 055 } 056 return labels; 057 } 058}