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;
021
022import java.util.ArrayList;
023import java.util.Collections;
024import java.util.List;
025import java.util.Map;
026
027/**
028 * Type service for the 'View Edit Mode' KIM type which matches on the id for a UIF view and edit mode
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class ViewEditModePermissionTypeServiceImpl extends ViewPermissionTypeServiceImpl {
033
034    @Override
035    protected List<String> getRequiredAttributes() {
036        List<String> attributes = new ArrayList<String>(super.getRequiredAttributes());
037        attributes.add(KimConstants.AttributeConstants.VIEW_ID);
038        attributes.add(KimConstants.AttributeConstants.EDIT_MODE);
039
040        return Collections.unmodifiableList(attributes);
041    }
042
043    /**
044     * Filters the given permission list to return those that match on edit mode, then calls super to filter
045     * based on view id
046     *
047     * @param requestedDetails - map of details requested with permission (used for matching)
048     * @param permissionsList - list of permissions to process for matches
049     * @return List<Permission> list of permissions that match the requested details
050     */
051    @Override
052    protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails,
053            List<Permission> permissionsList) {
054
055        List<Permission> matchingPermissions = new ArrayList<Permission>();
056        for (Permission permission : permissionsList) {
057            PermissionBo bo = PermissionBo.from(permission);
058
059            if (requestedDetails.get(KimConstants.AttributeConstants.EDIT_MODE).equals(bo.getDetails().get(
060                    KimConstants.AttributeConstants.EDIT_MODE))) {
061                matchingPermissions.add(permission);
062            }
063        }
064
065        return super.performPermissionMatches(requestedDetails, matchingPermissions);
066    }
067
068}