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.krad.kim;
017
018import org.kuali.rice.kim.api.KimConstants;
019import org.kuali.rice.kim.api.permission.Permission;
020import org.kuali.rice.kim.impl.permission.PermissionBo;
021import org.kuali.rice.krad.kim.DocumentTypePermissionTypeServiceImpl;
022
023import java.util.ArrayList;
024import java.util.List;
025import java.util.Map;
026
027/**
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030public class DocumentTypeAndAttachmentTypePermissionTypeService extends DocumentTypePermissionTypeServiceImpl {
031
032        @Override
033        protected List<Permission> performPermissionMatches(
034                        Map<String, String> requestedDetails,
035                        List<Permission> permissionsList) {
036
037                List<Permission> matchingPermissions = new ArrayList<Permission>();
038                if (requestedDetails == null) {
039                        return matchingPermissions; // empty list
040                }
041                // loop over the permissions, checking the non-document-related ones
042                for (Permission kimPermissionInfo : permissionsList) {
043            PermissionBo bo = PermissionBo.from(kimPermissionInfo);
044                        if (!bo.getDetails().containsKey(
045                                                KimConstants.AttributeConstants.ATTACHMENT_TYPE_CODE)
046                          || bo.getDetails().get(KimConstants.AttributeConstants.ATTACHMENT_TYPE_CODE)
047                                 .equals(requestedDetails.get(KimConstants.AttributeConstants.ATTACHMENT_TYPE_CODE)))
048                        {
049                                matchingPermissions.add(kimPermissionInfo);
050                        }
051
052                }
053                // now, filter the list to just those for the current document
054                matchingPermissions = super.performPermissionMatches(requestedDetails,
055                                matchingPermissions);
056                return matchingPermissions;
057        }
058}