001/** 002 * Copyright 2005-2017 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.rice.kew.rule.bo; 017 018import org.kuali.rice.core.api.delegation.DelegationType; 019import org.kuali.rice.core.api.util.ConcreteKeyValue; 020import org.kuali.rice.core.api.util.KeyValue; 021import org.kuali.rice.kew.api.KewApiConstants; 022import org.kuali.rice.kns.util.KNSGlobalVariables; 023import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm; 024import org.kuali.rice.krad.keyvalues.KeyValuesBase; 025 026import java.util.ArrayList; 027import java.util.Collections; 028import java.util.List; 029 030/** 031 * A values finder for returning KEW rule delegation type codes. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035public class DelegationTypeValuesFinder extends KeyValuesBase { 036 037 private static final List<KeyValue> C_DELEGATION_TYPES; 038 private static final List<KeyValue> C_DELEGATION_TYPES_FOR_MAIN_DOCS; 039 static { 040 041 final List<KeyValue> delegationTypes = new ArrayList<KeyValue>(); 042 final List<KeyValue> delegationTypesForMaintDocs = new ArrayList<KeyValue>(); 043 044 for (DelegationType delegationType : DelegationType.values()) { 045 delegationTypes.add(new ConcreteKeyValue(delegationType.getCode(), delegationType.getLabel())); 046 delegationTypesForMaintDocs.add(new ConcreteKeyValue(delegationType.getCode(), delegationType.getLabel())); 047 } 048 // for non maintenance documents, add a "both" option 049 delegationTypes.add(new ConcreteKeyValue(KewApiConstants.DELEGATION_BOTH, KewApiConstants.DELEGATION_BOTH_LABEL)); 050 051 C_DELEGATION_TYPES = Collections.unmodifiableList(delegationTypes); 052 C_DELEGATION_TYPES_FOR_MAIN_DOCS = Collections.unmodifiableList(delegationTypesForMaintDocs); 053 } 054 055 @Override 056 public List<KeyValue> getKeyValues() { 057 // Return the appropriate delegation types list, depending on whether or not it is needed for a maintenance doc. 058 return (KNSGlobalVariables.getKualiForm() instanceof KualiMaintenanceForm) ? C_DELEGATION_TYPES_FOR_MAIN_DOCS : C_DELEGATION_TYPES; 059 } 060 061}