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.kns.lookup;
017
018import java.util.Collection;
019import java.util.Set;
020
021import org.kuali.rice.core.api.criteria.PredicateFactory;
022import org.kuali.rice.core.api.criteria.QueryByCriteria;
023import org.kuali.rice.krad.bo.BusinessObject;
024import org.kuali.rice.krad.bo.DataObjectBase;
025import org.kuali.rice.krad.data.KradDataServiceLocator;
026import org.kuali.rice.krad.util.KRADPropertyConstants;
027
028/**
029 * The LookupResultsSupportStrategyService implementation which supports DataObjectBase objects, 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 DataObjectBaseLookupResultsSupportStrategyImpl
037                implements LookupResultsSupportStrategyService {
038
039        /**
040         * Returns the object id
041         *
042         * @see org.kuali.rice.kns.lookup.LookupResultsSupportStrategyService#getLookupIdForBusinessObject(org.kuali.rice.krad.bo.BusinessObject)
043         */
044        @Override
045    public String getLookupIdForBusinessObject(BusinessObject businessObject) {
046                DataObjectBase pbo = (DataObjectBase)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        @Override
056    public <T extends BusinessObject> Collection<T> retrieveSelectedResultBOs(Class<T> boClass, Set<String> lookupIds)
057                        throws Exception {
058
059        return KradDataServiceLocator.getDataObjectService().findMatching(
060                boClass,
061                QueryByCriteria.Builder.fromPredicates( PredicateFactory.in(KRADPropertyConstants.OBJECT_ID, lookupIds) )).getResults();
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        @Override
070    public boolean qualifiesForStrategy(Class<? extends BusinessObject> boClass) {
071                return DataObjectBase.class.isAssignableFrom(boClass);
072        }
073
074}