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.core.api.exception.RiceIllegalArgumentException;
020import org.kuali.rice.kim.api.KimConstants;
021import org.kuali.rice.kim.api.permission.Permission;
022import org.kuali.rice.kim.framework.permission.PermissionTypeService;
023import org.kuali.rice.kim.impl.permission.PermissionBo;
024import org.kuali.rice.krad.kim.DocumentTypePermissionTypeServiceImpl;
025
026import java.util.ArrayList;
027import java.util.Collections;
028import java.util.List;
029import java.util.Map;
030
031/**
032 * This is a description of what this class does - jonathan don't forget to fill
033 * this in.
034 * 
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 * 
037 */
038public class AdhocReviewPermissionTypeServiceImpl extends DocumentTypePermissionTypeServiceImpl implements PermissionTypeService {
039
040    @Override
041    protected List<String> getRequiredAttributes() {
042        final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes());
043        attrs.add(KimConstants.AttributeConstants.ACTION_REQUEST_CD);
044        return Collections.unmodifiableList(attrs);
045    }
046
047        @Override
048        public List<Permission> performPermissionMatches(
049                        Map<String, String> requestedDetails,
050                        List<Permission> permissionsList) {
051
052        if (permissionsList == null) {
053            throw new RiceIllegalArgumentException("permissionsList was null or blank");
054        }
055
056        if (requestedDetails == null) {
057            throw new RiceIllegalArgumentException("requestedDetails was null");
058        }
059
060        List<Permission> matchingPermissions = new ArrayList<Permission>();
061                // loop over the permissions, checking the non-document-related ones
062                for (Permission kpi : permissionsList) {
063            PermissionBo bo = PermissionBo.from(kpi);
064                        if (!bo.getDetails().containsKey(KimConstants.AttributeConstants.ACTION_REQUEST_CD)
065                          || StringUtils.equals(bo.getDetails().
066                                 get(KimConstants.AttributeConstants.ACTION_REQUEST_CD), requestedDetails
067                                        .get(KimConstants.AttributeConstants.ACTION_REQUEST_CD))) {
068                                matchingPermissions.add(kpi);
069                        }
070                }
071                // now, filter the list to just those for the current document
072                matchingPermissions = super.performPermissionMatches(requestedDetails,matchingPermissions);
073                return matchingPermissions;
074        }
075}