Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 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.kew.doctype.service.impl;
 
 
 import java.util.*;

Implementation of the DocumentTypePermissionService.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentTypePermissionServiceImpl.class);
 
     @Override
     public boolean canReceiveAdHocRequest(String principalIdDocumentRouteHeaderValue documentString actionRequestType) {
         validatePrincipalId(principalId);
         validateDocument(document);
         DocumentType documentType = document.getDocumentType();
         validateDocumentType(documentType);
         validateActionRequestType(actionRequestType);
         final Boolean result;
 
         Map<StringStringpermissionDetails = buildDocumentTypePermissionDetails(documentTypenullactionRequestTypenull);
         if (useKimPermission(..permissionDetailstrue)) {
             result = getPermissionService().isAuthorizedByTemplate(principalId.,
                     .permissionDetailsnew HashMap<StringString>());
         } else {
             result = .;
         }
         return result;
     }
 
     @Override
     public boolean canGroupReceiveAdHocRequest(String groupIdDocumentRouteHeaderValue documentString actionRequestType) {
         validateGroupId(groupId);
         validateDocument(document);
         DocumentType documentType = document.getDocumentType();
         validateDocumentType(documentType);
         validateActionRequestType(actionRequestType);
 
         Boolean result = .;
         Map<StringStringpermissionDetails = buildDocumentTypePermissionDetails(documentTypenullactionRequestTypenull);
         if (useKimPermission(..permissionDetailstrue)) {
             List<StringprincipalIds = getGroupService().getMemberPrincipalIds(groupId);
             // if any member of the group is not allowed to receive the request, then the group may not receive it
             for (String principalId : principalIds) {
                 if (!getPermissionService().isAuthorizedByTemplate(principalId.,
                         .permissionDetailsnew HashMap<StringString>())) {
                     result = .;
                     break;
                 }
             }
         }
         return result;
     }
 
     @Override
     public boolean canAdministerRouting(String principalIdDocumentType documentType) {
         validatePrincipalId(principalId);
         validateDocumentType(documentType);
 
         final Boolean result;
         if (documentType.isSuperUserGroupDefined()) {
             result = documentType.isSuperUser(principalId);
         } else {
             Map<StringStringpermissionDetails = buildDocumentTypePermissionDetails(documentTypenullnullnull);
             result = getPermissionService().isAuthorizedByTemplate(principalId.,
                     .permissionDetailsnew HashMap<StringString>());
         }
         return result;
     }
 
     @Override
     public boolean canSuperUserApproveSingleActionRequest(String principalIdDocumentType documentType,
                                                          List<RouteNodeInstancerouteNodeInstancesString routeStatusCode) {
        return canSuperUserApproveSingleActionRequest(principalIddocumentTypetoRouteNodeNames(routeNodeInstances), routeStatusCode);
    }
    @Override
    public boolean canSuperUserApproveDocument(String principalIdDocumentType documentType,
                                               List<RouteNodeInstancerouteNodeInstancesString routeStatusCode) {
        return canSuperUserApproveDocument(principalIddocumentTypetoRouteNodeNames(routeNodeInstances), routeStatusCode);
    }
    @Override
    public boolean canSuperUserDisapproveDocument(String principalIdDocumentType documentType,
                                                  List<RouteNodeInstancerouteNodeInstances,String routeStatusCode) {
        return canSuperUserDisapproveDocument(principalIddocumentTypetoRouteNodeNames(routeNodeInstances), routeStatusCode);
    }
    @Override
    public boolean canAddRouteLogMessage(String principalIdDocumentRouteHeaderValue document) {
        validatePrincipalId(principalId);
        validateDocument(document);
        String documentId = document.getDocumentId();
        DocumentType documentType = document.getDocumentType();
        String documentStatus = document.getDocRouteStatus();
        String initiatorPrincipalId = document.getInitiatorWorkflowId();
        validateDocumentType(documentType);
        validateDocumentStatus(documentStatus);
        validatePrincipalId(initiatorPrincipalId);
        Map<StringStringpermissionDetails = buildDocumentTypePermissionDetails(documentTypedocumentStatusnullnull);
        Map<StringStringroleQualifiers = buildDocumentRoleQualifiers(documentpermissionDetails.get(.));
        if (.isDebugEnabled()) {
            .debug("Permission details values: " + permissionDetails);
            .debug("Role qualifiers values: " + roleQualifiers);
        }
        if (useKimPermission(..permissionDetailsfalse)) {
            return getPermissionService().isAuthorizedByTemplate(principalId.,
                    .permissionDetailsroleQualifiers);
        }
        return false;
    }

    
Converts list of RouteNodeInstance objects to a list of the route node names

Parameters:
routeNodeInstances the list RouteNodeInstance objects, may be null
Returns:
non-null, possibly empty, Collection of routenode names
    protected Collection<StringtoRouteNodeNames(Collection<RouteNodeInstancerouteNodeInstances) {
        if (routeNodeInstances != null) {
            return CollectionUtils.collect(routeNodeInstancesnew Transformer() {
                @Override
                public Object transform(Object input) {
                    return ((RouteNodeInstanceinput).getName();
                }
            });
        } else {
            return .;
        }
    }

    
Validates groupId parameter

Parameters:
groupId the group id
Throw:
IllegalArgumentException if groupId is empty or null
    private void validateGroupId(String groupId) {
        if (StringUtils.isBlank(groupId)) {
            throw new IllegalArgumentException("Invalid group ID, value was empty");
        }
    }

    
Validates actionRequestType parameter

Parameters:
actionRequestType the actionRequest type
Throw:
IllegalArgumentException if the actionRequest type is empty or null, or an invalid value
    private void validateActionRequestType(String actionRequestType) {
        if (StringUtils.isBlank(actionRequestType)) {
            throw new IllegalArgumentException("Invalid action request type, value was empty");
        }
        if (!..containsKey(actionRequestType)) {
            throw new IllegalArgumentException("Invalid action request type was given, value was: " + actionRequestType);
        }
    }
    // convenience method to look up KIM GroupService
    protected GroupService getGroupService() {
        return KimApiServiceLocator.getGroupService();
    }
New to GrepCode? Check out our FAQ X