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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations