001/** 002 * Copyright 2005-2016 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.krms.impl.repository.mock; 017 018import java.util.ArrayList; 019import java.util.LinkedHashMap; 020import java.util.List; 021import java.util.Map; 022import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; 023import org.kuali.rice.krms.api.repository.function.FunctionDefinition; 024import org.kuali.rice.krms.api.repository.function.FunctionRepositoryService; 025 026public class FunctionRepositoryServiceMockImpl implements FunctionRepositoryService { 027 // cache variable 028 // The LinkedHashMap is just so the values come back in a predictable order 029 030 private Map<String, FunctionDefinition> functionDefinitionMap = new LinkedHashMap<String, FunctionDefinition>(); 031 032 public Map<String, FunctionDefinition> getFunctionDefinitionMap() { 033 return functionDefinitionMap; 034 } 035 036 public void setFunctionDefinitionMap(Map<String, FunctionDefinition> functionDefinitionMap) { 037 this.functionDefinitionMap = functionDefinitionMap; 038 } 039 040 public void clear() { 041 this.functionDefinitionMap.clear(); 042 } 043 044 @Override 045 public FunctionDefinition getFunction(String functionId) 046 throws RiceIllegalArgumentException { 047 // GET_BY_ID 048 if (!this.functionDefinitionMap.containsKey(functionId)) { 049 throw new RiceIllegalArgumentException(functionId); 050 } 051 return this.functionDefinitionMap.get(functionId); 052 } 053 054 @Override 055 public List<FunctionDefinition> getFunctions(List<String> functionIds) 056 throws RiceIllegalArgumentException { 057 List<FunctionDefinition> list = new ArrayList<FunctionDefinition> (); 058 for (String id : functionIds) { 059 list.add (this.getFunction(id)); 060 } 061 return list; 062 } 063}