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.kns.lookup;
017
018import java.util.Collection;
019import java.util.HashMap;
020import java.util.Map;
021import java.util.Set;
022
023import org.kuali.rice.krad.bo.BusinessObject;
024import org.kuali.rice.krad.bo.PersistableBusinessObject;
025import org.kuali.rice.krad.service.BusinessObjectService;
026import org.kuali.rice.krad.util.KRADPropertyConstants;
027
028/**
029 * The LookupResultsSupportStrategyService implementation which supports PersistableBusinessObjects, simply enough 
030 * 
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 *
033 * @deprecated Only used by KNS classes, use KRAD.
034 */
035@Deprecated
036public class PersistableBusinessObjectLookupResultsSupportStrategyImpl
037                implements LookupResultsSupportStrategyService {
038        
039        private BusinessObjectService businessObjectService;
040
041        /**
042         * Returns the object id
043         * 
044         * @see org.kuali.rice.kns.lookup.LookupResultsSupportStrategyService#getLookupIdForBusinessObject(org.kuali.rice.krad.bo.BusinessObject)
045         */
046        public String getLookupIdForBusinessObject(BusinessObject businessObject) {
047                PersistableBusinessObject pbo = (PersistableBusinessObject)businessObject;
048                return pbo.getObjectId(); 
049        }
050
051        /**
052         * Uses the BusinessObjectService to retrieve a collection of PersistableBusinessObjects
053         * 
054         * @see org.kuali.rice.kns.lookup.LookupResultsSupportStrategyService#retrieveSelectedResultBOs(java.lang.String, java.lang.Class, java.lang.String)
055         */
056        public <T extends BusinessObject> Collection<T> retrieveSelectedResultBOs(Class<T> boClass, Set<String> lookupIds)
057                        throws Exception {
058                
059        Map<String, Collection<String>> queryCriteria = new HashMap<String, Collection<String>>();
060        queryCriteria.put(KRADPropertyConstants.OBJECT_ID, lookupIds);
061        return getBusinessObjectService().findMatching(boClass, queryCriteria);
062        }
063        
064
065        /**
066         * Sees if the class implements the PersistableBusinessObject interface; if so, then yes, the BO qualifies!
067         * @see org.kuali.rice.kns.lookup.LookupResultsSupportStrategyService#qualifiesForStrategy(java.lang.Class)
068         */
069        public boolean qualifiesForStrategy(Class<? extends BusinessObject> boClass) {
070                return PersistableBusinessObject.class.isAssignableFrom(boClass);
071        }
072
073        /**
074         * @return the businessObjectService
075         */
076        public BusinessObjectService getBusinessObjectService() {
077                return this.businessObjectService;
078        }
079
080        /**
081         * @param businessObjectService the businessObjectService to set
082         */
083        public void setBusinessObjectService(BusinessObjectService businessObjectService) {
084                this.businessObjectService = businessObjectService;
085        }
086}