Search in sources :

Example 6 with RoleMembership

use of org.kuali.kfs.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.

the class SecurityRequestDerivedRoleTypeServiceImpl method getRoleMembersFromDerivedRole.

@Override
public List<RoleMembership> getRoleMembersFromDerivedRole(String namespaceCode, String roleName, Map<String, String> qualification) {
    final List<RoleMembership> members = new ArrayList<RoleMembership>();
    LOG.info("getRoleMembersFromDerivedRole() Generating role membership for role: " + roleName + " with qualification " + qualification);
    String documentNumber = qualification.get(AttributeConstants.DOCUMENT_NUMBER);
    SecurityRequestDocument document = null;
    try {
        document = (SecurityRequestDocument) KRADServiceLocatorWeb.getDocumentService().getByDocumentHeaderId(documentNumber);
    } catch (WorkflowException e) {
        LOG.error("getRoleMembersFromDerivedRole() Unable to retrieve security request document: " + documentNumber, e);
        throw new RuntimeException("Unable to retrieve security request document: " + documentNumber, e);
    }
    for (final SecurityRequestRole requestRole : document.getSecurityRequestRoles()) {
        members.addAll(getRoleMembersFromDerivedRole(roleName, document, requestRole));
    }
    LOG.info("getRoleMembersFromDerivedRole() Returning " + members.size() + " members");
    return members;
}
Also used : WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) RoleMembership(org.kuali.kfs.kim.api.role.RoleMembership) SecurityRequestRole(edu.cornell.kfs.ksr.businessobject.SecurityRequestRole) SecurityRequestDocument(edu.cornell.kfs.ksr.document.SecurityRequestDocument)

Example 7 with RoleMembership

use of org.kuali.kfs.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.

the class SecurityRequestDerivedRoleTypeServiceImpl method getRoleMembersFromDistributedAuthorizerRole.

protected List<RoleMembership> getRoleMembersFromDistributedAuthorizerRole(final String authorizerRoleId, final SecurityRequestDocument document, final SecurityRequestRole requestRole) {
    final List<RoleMembership> members = new ArrayList<RoleMembership>();
    Map<String, List<Map<String, String>>> addedMembers = new HashMap<String, List<Map<String, String>>>();
    for (final SecurityRequestRoleQualification roleQualification : requestRole.getRequestRoleQualifications()) {
        Map<String, String> roleQualifier = roleQualification.buildQualificationAttributeSet();
        boolean hasNonBlankQual = false;
        for (Iterator<String> qualValueIter = roleQualifier.values().iterator(); !hasNonBlankQual && qualValueIter.hasNext(); ) {
            if (StringUtils.isNotBlank(qualValueIter.next())) {
                hasNonBlankQual = true;
            }
        }
        if (hasNonBlankQual) {
            boolean addMember = addMemberIfNotPreviouselyAdded(addedMembers, authorizerRoleId, roleQualifier);
            if (addMember) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("getRoleMembersFromDistributedAuthorizerRole() Adding member role id: " + authorizerRoleId + " with qualification: " + roleQualifier.toString());
                }
                List<RoleMembership> authorizerRoleMembers = getAuthorizerRoleMembers(authorizerRoleId, roleQualifier);
                members.addAll(authorizerRoleMembers);
            }
        }
    }
    String primaryDepartmentCode = document.getPrimaryDepartmentCode();
    if (StringUtils.isNotBlank(primaryDepartmentCode) && StringUtils.contains(primaryDepartmentCode, "-")) {
        String[] primaryDepartment = StringUtils.split(primaryDepartmentCode, "-");
        Map<String, String> roleQualifier = new HashMap<String, String>();
        roleQualifier.put("chartOfAccountsCode", primaryDepartment[0]);
        roleQualifier.put("organizationCode", primaryDepartment[1]);
        boolean addMember = addMemberIfNotPreviouselyAdded(addedMembers, authorizerRoleId, roleQualifier);
        if (addMember) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("getRoleMembersFromDistributedAuthorizerRole() Adding member role id: " + authorizerRoleId + " with qualification: " + roleQualifier.toString());
            }
            List<RoleMembership> authorizerRoleMembers = getAuthorizerRoleMembers(authorizerRoleId, roleQualifier);
            members.addAll(authorizerRoleMembers);
        }
    }
    return members;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SecurityRequestRoleQualification(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification) RoleMembership(org.kuali.kfs.kim.api.role.RoleMembership) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with RoleMembership

use of org.kuali.kfs.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.

the class CuRelatedDocumentDerivedRoleTypeServiceImpl method getRoleMembersFromDerivedRole.

@Override
public List<RoleMembership> getRoleMembersFromDerivedRole(String namespaceCode, String roleName, Map<String, String> qualification) {
    List<RoleMembership> members = new ArrayList<RoleMembership>();
    if (qualification != null && !qualification.isEmpty()) {
        if (SOURCE_DOCUMENT_ROUTER_ROLE_NAME.equals(roleName)) {
            try {
                PurchasingAccountsPayableDocument document = (PurchasingAccountsPayableDocument) getDocumentService().getByDocumentHeaderId(qualification.get(KFSPropertyConstants.DOCUMENT_NUMBER));
                if (document != null) {
                    PurchasingAccountsPayableDocument sourceDocument = document.getPurApSourceDocumentIfPossible();
                    if (sourceDocument != null && StringUtils.isNotBlank(sourceDocument.getDocumentHeader().getWorkflowDocument().getRoutedByPrincipalId())) {
                        Map<String, String> roleQualifier = new HashMap<String, String>(1);
                        roleQualifier.put(KimConstants.AttributeConstants.DOCUMENT_NUMBER, sourceDocument.getDocumentNumber());
                        Builder roleMember = RoleMembership.Builder.create(null, null, sourceDocument.getDocumentHeader().getWorkflowDocument().getRoutedByPrincipalId(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, roleQualifier);
                        members.add(roleMember.build());
                    }
                }
            } catch (WorkflowException e) {
                throw new RuntimeException("Unable to load document in getPrincipalIdsFromApplicationRole", e);
            }
        } else if (SENSITIVE_RELATED_DOCUMENT_INITATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) {
            // KFSUPGRADE-346
            if (!qualification.containsKey(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER)) {
                Map<String, String> tempQualification = new HashMap<String, String>(1);
                tempQualification.put(KFSPropertyConstants.DOCUMENT_NUMBER, qualification.get("documentNumber"));
                for (String principalId : getRoleService().getRoleMemberPrincipalIds(KFSConstants.CoreModuleNamespaces.WORKFLOW, RouteLogDerivedRoleTypeServiceImpl.INITIATOR_OR_REVIEWER_ROLE_NAME, tempQualification)) {
                    Builder roleMember = RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, tempQualification);
                    members.add(roleMember.build());
                }
            } else {
                for (String documentId : getPurapService().getRelatedDocumentIds(new Integer(qualification.get(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER)))) {
                    Map<String, String> tempQualification = new HashMap<String, String>(1);
                    tempQualification.put(KFSPropertyConstants.DOCUMENT_NUMBER, documentId);
                    for (String principalId : getRoleService().getRoleMemberPrincipalIds(KFSConstants.CoreModuleNamespaces.WORKFLOW, RouteLogDerivedRoleTypeServiceImpl.INITIATOR_OR_REVIEWER_ROLE_NAME, tempQualification)) {
                        Builder roleMember = RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, tempQualification);
                        members.add(roleMember.build());
                    }
                }
            }
        }
    }
    return members;
}
Also used : HashMap(java.util.HashMap) Builder(org.kuali.kfs.kim.api.role.RoleMembership.Builder) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) ArrayList(java.util.ArrayList) RoleMembership(org.kuali.kfs.kim.api.role.RoleMembership) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with RoleMembership

use of org.kuali.kfs.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.

the class RoleServiceImpl method convertToRoleMemberships.

protected List<RoleMembership> convertToRoleMemberships(List<RoleMember>... roleMemberLists) {
    List<RoleMembership> roleMemberships = new ArrayList<>();
    for (List<RoleMember> roleMembers : roleMemberLists) {
        for (RoleMember roleMember : roleMembers) {
            RoleMembership roleMembership = RoleMembership.Builder.create(roleMember.getRoleId(), roleMember.getId(), roleMember.getMemberId(), roleMember.getType(), roleMember.getAttributes()).build();
            roleMemberships.add(roleMembership);
        }
    }
    return roleMemberships;
}
Also used : ArrayList(java.util.ArrayList) RoleMembership(org.kuali.kfs.kim.api.role.RoleMembership)

Example 10 with RoleMembership

use of org.kuali.kfs.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.

the class RoleServiceImpl method getRoleIdToMembershipMap.

/**
 * Helper method used by principalHasRole to build the role ID -> list of members map.
 *
 * @return <b>true</b> if no further checks are needed because no role service is defined
 */
protected boolean getRoleIdToMembershipMap(Map<String, List<RoleMembership>> roleIdToMembershipMap, List<RoleMember> roleMembers) {
    for (RoleMember roleMember : roleMembers) {
        RoleMembership roleMembership = RoleMembership.Builder.create(roleMember.getRoleId(), roleMember.getId(), roleMember.getMemberId(), roleMember.getType(), roleMember.getAttributes()).build();
        // if the role type service is null, assume that all qualifiers match
        if (getRoleTypeService(roleMember.getRoleId()) == null) {
            return true;
        }
        List<RoleMembership> lrmi = roleIdToMembershipMap.computeIfAbsent(roleMembership.getRoleId(), k -> new ArrayList<>());
        lrmi.add(roleMembership);
    }
    return false;
}
Also used : RoleMembership(org.kuali.kfs.kim.api.role.RoleMembership)

Aggregations

RoleMembership (org.kuali.kfs.kim.api.role.RoleMembership)14 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)6 Map (java.util.Map)4 RoleTypeService (org.kuali.kfs.kim.framework.role.RoleTypeService)4 HashSet (java.util.HashSet)3 List (java.util.List)3 DelegateType (org.kuali.kfs.kim.impl.common.delegate.DelegateType)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)2 DelegateMember (org.kuali.kfs.kim.impl.common.delegate.DelegateMember)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 MultiValueMap (org.springframework.util.MultiValueMap)2 SecurityRequestRole (edu.cornell.kfs.ksr.businessobject.SecurityRequestRole)1 SecurityRequestRoleQualification (edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification)1 SecurityRequestDocument (edu.cornell.kfs.ksr.document.SecurityRequestDocument)1 ResponsibilityAction (org.kuali.kfs.kim.api.responsibility.ResponsibilityAction)1 Builder (org.kuali.kfs.kim.api.role.RoleMembership.Builder)1 DelegationTypeService (org.kuali.kfs.kim.framework.common.delegate.DelegationTypeService)1 RoleResponsibilityAction (org.kuali.kfs.kim.impl.role.RoleResponsibilityAction)1