Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2012 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.kuali.rice.kim.impl.group;
import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
import static org.kuali.rice.core.api.criteria.PredicateFactory.lessThan;

Custom lookupable for the GroupBo lookup to call the group service for searching

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
public class GroupLookupableImpl extends LookupableImpl {
    private static final long serialVersionUID = -3149952849854425077L;

    
Translates any search criteria on principal name to member id and active data, then calls group service to retrieve matching groups

Returns:
List<GroupBo>
    @Override
    protected List<?> getSearchResults(LookupForm formMap<StringStringsearchCriteriaboolean unbounded) {
        Map<StringStringcriteriaMap = new HashMap<StringString>(searchCriteria);
        QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
        if (!criteriaMap.isEmpty()) {
            List<Predicatepredicates = new ArrayList<Predicate>();
            //principalId doesn't exist on 'Group'.  Lets do this predicate conversion separately
            if (StringUtils.isNotBlank(criteriaMap.get(..))) {
                String principalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(
                        criteriaMap.get(..)).getPrincipalId();
                Timestamp currentTime = new Timestamp(Calendar.getInstance().getTimeInMillis());
                predicates.add(and(equal("members.memberId"principalId), equal("members.typeCode",
                        ...getCode()), and(or(isNull(
                        "members.activeFromDateValue"), greaterThanOrEqual("members.activeFromDateValue"currentTime)),
                        or(isNull("members.activeToDateValue"), lessThan("members.activeToDateValue"currentTime)))));
            }
            criteriaMap.remove(..);
            predicates.add(PredicateUtils.convertMapToPredicate(criteriaMap));
            criteria.setPredicates(and(predicates.toArray(new Predicate[predicates.size()])));
        }
        GroupQueryResults groupResults = getGroupService().findGroups(criteria.build());
        List<Groupgroups = groupResults.getResults();
        //have to convert back to Bos :(
        List<GroupBogroupBos = new ArrayList<GroupBo>(groups.size());
        for (Group group : groups) {
            groupBos.add(GroupBo.from(group));
        }
        return groupBos;
    }
    public GroupService getGroupService() {
        return KimApiServiceLocator.getGroupService();
    }
New to GrepCode? Check out our FAQ X