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