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.kew.service.impl;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.kim.api.KimConstants;
020import org.kuali.rice.kim.api.responsibility.Responsibility;
021import org.kuali.rice.kim.framework.responsibility.ResponsibilityTypeService;
022
023import java.util.ArrayList;
024import java.util.Collections;
025import java.util.Iterator;
026import java.util.List;
027import java.util.Map;
028
029/**
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class ReviewResponsibilityTypeServiceImpl extends DocumentTypeResponsibilityTypeServiceImpl implements ResponsibilityTypeService {
033        {
034                exactMatchStringAttributeName = KimConstants.AttributeConstants.ROUTE_NODE_NAME;
035        }
036
037    @Override
038    protected List<String> getRequiredAttributes() {
039        final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes());
040        attrs.add(KimConstants.AttributeConstants.ROUTE_NODE_NAME);
041        return Collections.unmodifiableList(attrs);
042    }
043
044        @Override
045        protected List<Responsibility> performResponsibilityMatches(
046                        Map<String, String> requestedDetails,
047                        List<Responsibility> responsibilitiesList) {
048                // get the base responsibility matches based on the route level and document type
049                List<Responsibility> baseMatches = super.performResponsibilityMatches(requestedDetails,
050                                responsibilitiesList);
051                // now, if any of the responsibilities have the "qualifierResolverProvidedIdentifier" detail property
052                // perform an exact match on the property with the requested details
053                // if the property does not match or does not exist in the requestedDetails, remove
054                // the responsibility from the list
055                Iterator<Responsibility> respIter = baseMatches.iterator();
056                while ( respIter.hasNext() ) {
057                        Map<String, String> respDetails = respIter.next().getAttributes();
058                        if ( respDetails.containsKey( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER ) && StringUtils.isNotBlank( respDetails.get(KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER) ) ) {
059                                if ( !requestedDetails.containsKey( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER )
060                                                || !StringUtils.equals( respDetails.get(KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER)
061                                                                , requestedDetails.get(KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER))) {
062                                        respIter.remove();
063                                }
064                        }
065                }               
066                return baseMatches;
067        }
068}