Search in sources :

Example 1 with RoleService

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

the class SecurityRequestDocumentServiceImpl method buildSecurityRequestRoleQualifications.

protected void buildSecurityRequestRoleQualifications(SecurityRequestRole requestRole, String principalId) {
    List<String> roleIds = new ArrayList<String>();
    roleIds.add(requestRole.getRoleId());
    RoleService roleService = KimApiServiceLocator.getRoleService();
    boolean hasRole = roleService.principalHasRole(principalId, roleIds, Collections.emptyMap());
    if (hasRole) {
        requestRole.setActive(true);
        requestRole.setCurrentActive(true);
        requestRole.setCurrentQualifications("");
        if (requestRole.isQualifiedRole()) {
            List<Map<String, String>> principalQualifications = roleService.getNestedRoleQualifiersForPrincipalByRoleIds(principalId, roleIds, Collections.emptyMap());
            List<SecurityRequestRoleQualification> requestQualifications = new ArrayList<SecurityRequestRoleQualification>();
            for (Map<String, String> qualification : principalQualifications) {
                SecurityRequestRoleQualification requestQualification = buildRoleQualificationLine(requestRole, qualification);
                requestQualifications.add(requestQualification);
            }
            requestRole.setRequestRoleQualifications(requestQualifications);
            buildCurrentQualificationsString(requestRole, principalId, principalQualifications);
        }
    } else {
        requestRole.setActive(false);
        requestRole.setCurrentActive(false);
    }
    if (requestRole.isQualifiedRole()) {
        SecurityRequestRoleQualification newRequestRoleQualification = buildRoleQualificationLine(requestRole, null);
        requestRole.setNewRequestRoleQualification(newRequestRoleQualification);
    }
}
Also used : RoleService(org.kuali.kfs.kim.api.role.RoleService) SecurityRequestRoleQualification(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RoleService

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

the class RassMockServiceFactory method buildMockRoleService.

public RoleService buildMockRoleService() {
    RoleLite projectDirectRole = new RoleLite();
    projectDirectRole.setId("123");
    projectDirectRole.setName(KFSConstants.SysKimApiConstants.CONTRACTS_AND_GRANTS_PROJECT_DIRECTOR);
    projectDirectRole.setNamespaceCode(KFSConstants.CoreModuleNamespaces.KFS);
    projectDirectRole.setKimTypeId("R");
    RoleService roleService = Mockito.mock(RoleService.class);
    Mockito.when(roleService.getRoleByNamespaceCodeAndName(KFSConstants.CoreModuleNamespaces.KFS, KFSConstants.SysKimApiConstants.CONTRACTS_AND_GRANTS_PROJECT_DIRECTOR)).thenReturn(projectDirectRole);
    Mockito.when(roleService.principalHasRole(Mockito.anyString(), Mockito.any(), Mockito.any())).thenReturn(true);
    return roleService;
}
Also used : RoleService(org.kuali.kfs.kim.api.role.RoleService) RoleLite(org.kuali.kfs.kim.impl.role.RoleLite)

Example 3 with RoleService

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

the class OrgReviewRoleServiceImpl method populateOrgReviewRoleFromDelegationMember.

@Override
public void populateOrgReviewRoleFromDelegationMember(OrgReviewRole orr, String roleMemberId, String delegationMemberId) {
    RoleMember roleMember = null;
    if (StringUtils.isNotBlank(roleMemberId)) {
        roleMember = getRoleMemberFromKimRoleService(roleMemberId);
    }
    RoleService roleService = KimApiServiceLocator.getRoleService();
    DelegateMember delegationMember = roleService.getDelegationMemberById(delegationMemberId);
    DelegateType delegation = roleService.getDelegateTypeByDelegationId(delegationMember.getDelegationId());
    orr.setDelegationTypeCode(delegation.getDelegationType().getCode());
    orr.setDelegateMember(roleMember, delegationMember);
    orr.setRoleRspActions(roleService.getRoleMemberResponsibilityActions(delegationMember.getRoleMemberId()));
    populateObjectExtras(orr);
}
Also used : OrgReviewRoleService(org.kuali.kfs.coa.service.OrgReviewRoleService) RoleService(org.kuali.kfs.kim.api.role.RoleService) KfsKimDocDelegateMember(org.kuali.kfs.coa.identity.KfsKimDocDelegateMember) DelegateMember(org.kuali.kfs.kim.impl.common.delegate.DelegateMember) DelegateType(org.kuali.kfs.kim.impl.common.delegate.DelegateType) RoleMember(org.kuali.kfs.kim.impl.role.RoleMember)

Example 4 with RoleService

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

the class OrgReviewRoleServiceImpl method saveRoleMemberToKim.

protected void saveRoleMemberToKim(OrgReviewRole orr) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving role member from OrgReviewRole: " + orr);
    }
    RoleService roleService = KimApiServiceLocator.getRoleService();
    // Save role member(s)
    for (RoleMember roleMember : getRoleMembers(orr)) {
        List<RoleResponsibilityAction> roleRspActionsToSave = getRoleResponsibilityActions(orr, roleMember);
        // KFSCNTRB-1391
        GenericQueryResults<RoleMember> roleMembers = null;
        if (orr.isEdit()) {
            roleMembers = roleService.findRoleMembers(QueryByCriteria.Builder.fromPredicates(PredicateUtils.convertMapToPredicate(Collections.singletonMap(KimConstants.PrimaryKeyConstants.ID, roleMember.getId()))));
        }
        if (orr.isEdit() && roleMembers != null && roleMembers.getResults() != null && !roleMembers.getResults().isEmpty()) {
            RoleMember existingRoleMember = roleMembers.getResults().get(0);
            roleMember = roleService.updateRoleMember(existingRoleMember);
        } else {
            roleMember = roleService.createRoleMember(roleMember);
        }
        for (RoleResponsibilityAction rra : roleRspActionsToSave) {
            // ensure linked to the right record
            rra.setRoleMemberId(roleMember.getId());
            if (StringUtils.isBlank(rra.getId())) {
                roleService.createRoleResponsibilityAction(rra);
            } else {
                roleService.updateRoleResponsibilityAction(rra);
            }
        }
        orr.setRoleMemberId(roleMember.getId());
        orr.setORMId(roleMember.getId());
    }
}
Also used : OrgReviewRoleService(org.kuali.kfs.coa.service.OrgReviewRoleService) RoleService(org.kuali.kfs.kim.api.role.RoleService) RoleResponsibilityAction(org.kuali.kfs.kim.impl.role.RoleResponsibilityAction) RoleMember(org.kuali.kfs.kim.impl.role.RoleMember)

Example 5 with RoleService

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

the class OrgReviewRoleServiceImpl method saveDelegateMemberToKim.

protected void saveDelegateMemberToKim(OrgReviewRole orr) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving delegate member from OrgReviewRole: " + orr);
    }
    RoleService roleService = KimApiServiceLocator.getRoleService();
    // Save delegation(s)
    List<KfsKimDocDelegateMember> delegationMembers = getDelegationMembersToSave(orr);
    for (KfsKimDocDelegateMember dm : delegationMembers) {
        // retrieve the delegate type so it can be updated
        DelegationType delegationType = dm.getDelegationType();
        DelegateType delegateType = roleService.getDelegateTypeByRoleIdAndDelegateTypeCode(orr.getRoleId(), delegationType);
        if (shouldCreateNewDelegateType(delegateType)) {
            DelegateType newDelegateType = new DelegateType();
            newDelegateType.setRoleId(orr.getRoleId());
            newDelegateType.setDelegationType(delegationType);
            newDelegateType.setDelegationMembers(new ArrayList<>(1));
            // ensure this is set (for new delegation types)
            newDelegateType.setKimTypeId(orr.getKimTypeId());
            delegateType = roleService.createDelegateType(newDelegateType);
            if (LOG.isDebugEnabled()) {
                LOG.debug("No DelegateType in KIM.  Created new one: " + delegateType);
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Pulled DelegateType from KIM: " + delegateType);
            }
        }
        boolean foundExistingMember = false;
        DelegateMember addedMember = null;
        // check for an existing delegation member given its unique ID if found, update that record
        if (StringUtils.isNotBlank(dm.getDelegationMemberId())) {
            DelegateMember member = roleService.getDelegationMemberById(dm.getDelegationMemberId());
            if (member != null) {
                foundExistingMember = true;
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Found existing delegate member - updating existing record. " + member);
                }
                // KFSMI-9628 : fixing issue with the delegate switch from primary to secondary
                // IN this case, we need to delete the member from the "other" delegate type
                // need to determine what the "existing" type was
                DelegateType originalDelegateType = roleService.getDelegateTypeByDelegationId(member.getDelegationId());
                // if they are the same, we can just update the existing record
                if (originalDelegateType.getDelegationType().equals(dm.getDelegationType())) {
                    updateDelegateMemberFromDocDelegateMember(member, dm);
                    addedMember = roleService.updateDelegateMember(member);
                } else {
                    // Otherwise, we need to remove the old one and add a new one
                    // Remove old
                    roleService.removeDelegateMembers(Collections.singletonList(member));
                    // add new
                    DelegateMember newMember = new DelegateMember();
                    newMember.setDelegationId(delegateType.getDelegationId());
                    updateDelegateMemberFromDocDelegateMember(newMember, dm);
                    addedMember = roleService.createDelegateMember(newMember);
                }
            }
        }
        // if we did not find one, then we need to create a new member
        if (!foundExistingMember) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No existing delegate member found, adding as a new delegate: " + dm);
            }
            DelegateMember newMember = new DelegateMember();
            newMember.setDelegationId(delegateType.getDelegationId());
            updateDelegateMemberFromDocDelegateMember(newMember, dm);
            addedMember = roleService.createDelegateMember(newMember);
        }
        if (addedMember != null) {
            orr.setDelegationMemberId(addedMember.getDelegationMemberId());
        }
    }
}
Also used : OrgReviewRoleService(org.kuali.kfs.coa.service.OrgReviewRoleService) RoleService(org.kuali.kfs.kim.api.role.RoleService) KfsKimDocDelegateMember(org.kuali.kfs.coa.identity.KfsKimDocDelegateMember) DelegateMember(org.kuali.kfs.kim.impl.common.delegate.DelegateMember) DelegationType(org.kuali.kfs.core.api.delegation.DelegationType) DelegateType(org.kuali.kfs.kim.impl.common.delegate.DelegateType) KfsKimDocDelegateMember(org.kuali.kfs.coa.identity.KfsKimDocDelegateMember)

Aggregations

RoleService (org.kuali.kfs.kim.api.role.RoleService)5 OrgReviewRoleService (org.kuali.kfs.coa.service.OrgReviewRoleService)3 KfsKimDocDelegateMember (org.kuali.kfs.coa.identity.KfsKimDocDelegateMember)2 DelegateMember (org.kuali.kfs.kim.impl.common.delegate.DelegateMember)2 DelegateType (org.kuali.kfs.kim.impl.common.delegate.DelegateType)2 RoleMember (org.kuali.kfs.kim.impl.role.RoleMember)2 SecurityRequestRoleQualification (edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DelegationType (org.kuali.kfs.core.api.delegation.DelegationType)1 RoleLite (org.kuali.kfs.kim.impl.role.RoleLite)1 RoleResponsibilityAction (org.kuali.kfs.kim.impl.role.RoleResponsibilityAction)1