Search in sources :

Example 1 with SecurityRequestRoleQualification

use of edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification in project cu-kfs by CU-CommunityApps.

the class SecurityRequestDocumentRule method isDocumentAttributesValid.

@Override
public boolean isDocumentAttributesValid(Document document, boolean validateRequired) {
    boolean success = true;
    SecurityRequestDocument securityRequestDocument = (SecurityRequestDocument) document;
    for (int i = 0; i < securityRequestDocument.getSecurityRequestRoles().size(); i++) {
        SecurityRequestRole securityRequestRole = securityRequestDocument.getSecurityRequestRoles().get(i);
        KimType tempTypeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(securityRequestRole.getRoleInfo().getKimTypeId());
        if (!securityRequestRole.isActive()) {
            continue;
        } else if (!securityRequestRole.isQualifiedRole()) {
            continue;
        } else {
            String[] requiredQualifications = getRequiredQualificationsMap().get(tempTypeInfo.getServiceName());
            if (requiredQualifications != null && requiredQualifications.length > 0) {
                boolean qualsValid = true;
                boolean[] hasQuals = new boolean[requiredQualifications.length];
                for (SecurityRequestRoleQualification roleQualification : securityRequestRole.getRequestRoleQualifications()) {
                    Arrays.fill(hasQuals, false);
                    for (SecurityRequestRoleQualificationDetail qualDetail : roleQualification.getRoleQualificationDetails()) {
                        for (int j = requiredQualifications.length - 1; j >= 0; j--) {
                            if (requiredQualifications[j].equals(qualDetail.getAttributeName()) && StringUtils.isNotBlank(qualDetail.getAttributeValue())) {
                                hasQuals[j] = true;
                            }
                        }
                    }
                    for (boolean hasQual : hasQuals) {
                        qualsValid &= hasQual;
                    }
                }
                if (!qualsValid || securityRequestRole.getRequestRoleQualifications().size() == 0) {
                    success = false;
                    GlobalVariables.getMessageMap().putError(KSRPropertyConstants.SECURITY_REQUEST_DOC_REQUEST_ROLE + "[" + i + "].active", KSRKeyConstants.ERROR_SECURITY_REQUEST_DOC_QUALIFIER_MULTI_MISSING, new String[] { securityRequestRole.getRoleInfo().getName() });
                }
            } else if (securityRequestRole.getRequestRoleQualifications().size() == 0) {
                securityRequestRole.getRequestRoleQualifications().add(SpringContext.getBean(SecurityRequestDocumentService.class).buildRoleQualificationLine(securityRequestRole, null));
            }
        }
        for (int j = 0; j < securityRequestRole.getRequestRoleQualifications().size(); j++) {
            SecurityRequestRoleQualification requestRoleQualification = securityRequestRole.getRequestRoleQualifications().get(j);
            String typeId = securityRequestRole.getRoleInfo().getKimTypeId();
            KimType typeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(typeId);
            String fieldKeyPrefix = KSRPropertyConstants.SECURITY_REQUEST_DOC_REQUEST_ROLE + "[" + i + "]." + KSRPropertyConstants.SECURITY_REQUEST_DOC_ROLE_QUAL + "[" + j + "].";
            success &= validateQualification(typeInfo, requestRoleQualification, fieldKeyPrefix);
        }
    }
    return super.isDocumentAttributesValid(document, validateRequired) && success;
}
Also used : KimType(org.kuali.kfs.kim.impl.type.KimType) SecurityRequestRoleQualificationDetail(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualificationDetail) SecurityRequestRoleQualification(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification) SecurityRequestRole(edu.cornell.kfs.ksr.businessobject.SecurityRequestRole) SecurityRequestDocument(edu.cornell.kfs.ksr.document.SecurityRequestDocument)

Example 2 with SecurityRequestRoleQualification

use of edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification in project cu-kfs by CU-CommunityApps.

the class SecurityRequestDocumentServiceImpl method buildRoleQualificationLine.

public SecurityRequestRoleQualification buildRoleQualificationLine(SecurityRequestRole requestRole, Map<String, String> qualification) {
    SecurityRequestRoleQualification requestQualification = new SecurityRequestRoleQualification();
    requestQualification.setDocumentNumber(requestRole.getDocumentNumber());
    requestQualification.setRoleRequestId(requestRole.getRoleRequestId());
    KimType typeInfo = KSRUtil.getTypeInfoForRoleRequest(requestRole);
    List<KimTypeAttribute> typeAttributes = KSRUtil.getTypeAttributesForRoleRequest(requestRole);
    for (KimTypeAttribute attributeInfo : typeAttributes) {
        SecurityRequestRoleQualificationDetail requestQualificationDetail = new SecurityRequestRoleQualificationDetail();
        requestQualificationDetail.setDocumentNumber(requestRole.getDocumentNumber());
        requestQualificationDetail.setRoleRequestId(requestRole.getRoleRequestId());
        requestQualificationDetail.setQualificationId(requestRole.getNextQualificationId());
        requestQualificationDetail.setAttributeId(attributeInfo.getKimAttribute().getId());
        requestQualificationDetail.setRoleTypeId(typeInfo.getId());
        if ((qualification != null) && qualification.containsKey(attributeInfo.getKimAttribute().getAttributeName())) {
            requestQualificationDetail.setAttributeValue(qualification.get(attributeInfo.getKimAttribute().getAttributeName()));
        }
        requestQualification.getRoleQualificationDetails().add(requestQualificationDetail);
    }
    requestQualification.setQualificationId(requestRole.getNextQualificationId());
    requestRole.setNextQualificationId(requestRole.getNextQualificationId() + 1);
    return requestQualification;
}
Also used : KimType(org.kuali.kfs.kim.impl.type.KimType) SecurityRequestRoleQualificationDetail(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualificationDetail) KimTypeAttribute(org.kuali.kfs.kim.impl.type.KimTypeAttribute) SecurityRequestRoleQualification(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification)

Example 3 with SecurityRequestRoleQualification

use of edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification 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 4 with SecurityRequestRoleQualification

use of edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification in project cu-kfs by CU-CommunityApps.

the class SecurityRequestDocumentServiceImpl method prepareSecurityRequestDocument.

public void prepareSecurityRequestDocument(SecurityRequestDocument document) {
    if (document.getDocumentHeader().getWorkflowDocument().isSaved()) {
        for (SecurityRequestRole requestRole : document.getSecurityRequestRoles()) {
            SecurityRequestRoleQualification newRequestRoleQualification = buildRoleQualificationLine(requestRole, null);
            requestRole.setNewRequestRoleQualification(newRequestRoleQualification);
        }
    }
}
Also used : SecurityRequestRoleQualification(edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification) SecurityRequestRole(edu.cornell.kfs.ksr.businessobject.SecurityRequestRole)

Example 5 with SecurityRequestRoleQualification

use of edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification 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)

Aggregations

SecurityRequestRoleQualification (edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualification)8 Map (java.util.Map)4 SecurityRequestRole (edu.cornell.kfs.ksr.businessobject.SecurityRequestRole)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SecurityRequestRoleQualificationDetail (edu.cornell.kfs.ksr.businessobject.SecurityRequestRoleQualificationDetail)2 SecurityRequestDocument (edu.cornell.kfs.ksr.document.SecurityRequestDocument)2 KimType (org.kuali.kfs.kim.impl.type.KimType)2 KimTypeAttribute (org.kuali.kfs.kim.impl.type.KimTypeAttribute)2 AddQualificationLineEvent (edu.cornell.kfs.ksr.document.validation.impl.AddQualificationLineEvent)1 SecurityRequestDocumentService (edu.cornell.kfs.ksr.service.SecurityRequestDocumentService)1 List (java.util.List)1 RoleMembership (org.kuali.kfs.kim.api.role.RoleMembership)1 RoleService (org.kuali.kfs.kim.api.role.RoleService)1