use of org.kuali.rice.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.
the class CuAdvanceDepositAccountingLineAuthorizer method isOrgReviewEditable.
/**
* Determines if accounting line is org review editable
*
* @param accountingLine
* @return true if editable, false otherwise
*/
private boolean isOrgReviewEditable(AccountingLine accountingLine) {
boolean orgReviewEditable = false;
OrganizationService organizationService = SpringContext.getBean(OrganizationService.class);
Person currentUser = GlobalVariables.getUserSession().getPerson();
String roleId = getRoleService().getRoleIdByNamespaceCodeAndName(KFSConstants.ParameterNamespaces.FINANCIAL, CUKFSConstants.SysKimApiConstants.ADVANCE_DEPOSIT_ORGANIZATION_REVIEWER_ROLE_NAME);
List<String> roleIds = new ArrayList<String>();
roleIds.add(roleId);
List<Map<String, String>> qualifiers = new ArrayList<Map<String, String>>();
qualifiers.addAll(getRoleService().getRoleQualifersForPrincipalByRoleIds(currentUser.getPrincipalId(), roleIds, new HashMap<String, String>()));
if (qualifiers == null || qualifiers.isEmpty()) {
qualifiers.addAll(getRoleService().getNestedRoleQualifiersForPrincipalByRoleIds(currentUser.getPrincipalId(), roleIds, new HashMap<String, String>()));
}
// RoleMembershipInfo for principals
if (qualifiers == null || qualifiers.isEmpty()) {
List<RoleMembership> roleMemberships = getRoleService().getRoleMembers(roleIds, null);
if (roleMemberships != null && roleMemberships.size() > 0) {
for (RoleMembership roleMembershipInfo : roleMemberships) {
if (currentUser.getPrincipalId().equalsIgnoreCase(roleMembershipInfo.getMemberId())) {
qualifiers.add(roleMembershipInfo.getQualifier());
}
}
}
}
boolean chartMatch = false;
boolean orgMatch = false;
boolean docTypeMatch = false;
String org = StringUtils.EMPTY;
String chart = StringUtils.EMPTY;
if (qualifiers != null && qualifiers.size() > 0) {
for (Map<String, String> qualifier : qualifiers) {
{
for (String key : qualifier.keySet()) {
if (KfsKimAttributes.CHART_OF_ACCOUNTS_CODE.equalsIgnoreCase(key)) {
if (qualifier.get(key) != null && qualifier.get(key).equalsIgnoreCase(accountingLine.getChartOfAccountsCode())) {
chartMatch = true;
chart = qualifier.get(key);
}
}
if (KfsKimAttributes.ORGANIZATION_CODE.equalsIgnoreCase(key)) {
if (qualifier.get(key) != null) {
org = qualifier.get(key);
}
}
if (KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME.equalsIgnoreCase(key)) {
if (qualifier.get(key) != null && qualifier.get(key).equalsIgnoreCase("AD")) {
docTypeMatch = true;
}
}
}
String acctLineOrgCode = KFSConstants.EMPTY_STRING;
accountingLine.refreshReferenceObject(KFSPropertyConstants.ACCOUNT);
if (accountingLine.getAccount() != null) {
acctLineOrgCode = accountingLine.getAccount().getOrganizationCode();
}
if ((chart.equalsIgnoreCase(accountingLine.getChartOfAccountsCode()) && org.equalsIgnoreCase(acctLineOrgCode)) || organizationService.isParentOrganization(accountingLine.getChartOfAccountsCode(), acctLineOrgCode, chart, org)) {
orgMatch = true;
}
if ((chart.equalsIgnoreCase(accountingLine.getChartOfAccountsCode()) && org.equalsIgnoreCase(accountingLine.getAccount().getOrganizationCode())) || organizationService.isParentOrganization(accountingLine.getChartOfAccountsCode(), accountingLine.getAccount().getOrganizationCode(), chart, org)) {
orgMatch = true;
}
if (chartMatch && orgMatch && docTypeMatch) {
orgReviewEditable = true;
}
if (orgReviewEditable) {
break;
}
}
}
}
return orgReviewEditable;
}
use of org.kuali.rice.kim.api.role.RoleMembership in project cu-kfs by CU-CommunityApps.
the class CuAdvanceDepositDocumentAuthorizer method addAttributes.
protected void addAttributes(AdvanceDepositDocument advanceDepositDocument, Map<String, String> attributes) {
organizationService = SpringContext.getBean(OrganizationService.class);
Person currentUser = GlobalVariables.getUserSession().getPerson();
String roleId = getRoleService().getRoleIdByNamespaceCodeAndName(KFSConstants.ParameterNamespaces.FINANCIAL, CUKFSConstants.SysKimApiConstants.ADVANCE_DEPOSIT_ORGANIZATION_REVIEWER_ROLE_NAME);
List<String> roleIds = new ArrayList<String>();
roleIds.add(roleId);
List<Map<String, String>> qualifiers = new ArrayList<Map<String, String>>();
qualifiers.addAll(getRoleService().getRoleQualifersForPrincipalByRoleIds(currentUser.getPrincipalId(), roleIds, new HashMap<String, String>()));
if (qualifiers == null || qualifiers.isEmpty()) {
qualifiers.addAll(getRoleService().getNestedRoleQualifiersForPrincipalByRoleIds(currentUser.getPrincipalId(), roleIds, new HashMap<String, String>()));
}
// getRoleQualifiersForPrincipalIncludingNested does not work for simple principal members so we try RoleMembershipInfo for principals
if (qualifiers == null || qualifiers.isEmpty()) {
List<RoleMembership> roleMemberships = getRoleService().getRoleMembers(roleIds, null);
if (roleMemberships != null && roleMemberships.size() > 0) {
for (RoleMembership roleMembershipInfo : roleMemberships) {
if (currentUser.getPrincipalId().equalsIgnoreCase(roleMembershipInfo.getMemberId())) {
qualifiers.add(roleMembershipInfo.getQualifier());
}
}
}
}
Map<String, String> permissionDetails = new HashMap<String, String>();
if (qualifiers != null && qualifiers.size() > 0) {
for (Map<String, String> qualifier : qualifiers) {
{
for (String key : qualifier.keySet()) {
if (KfsKimAttributes.CHART_OF_ACCOUNTS_CODE.equalsIgnoreCase(key)) {
permissionDetails.put(key, qualifier.get(key));
}
if (KfsKimAttributes.ORGANIZATION_CODE.equalsIgnoreCase(key)) {
permissionDetails.put(key, qualifier.get(key));
}
if (KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME.equalsIgnoreCase(key)) {
permissionDetails.put(key, qualifier.get(key));
}
}
}
}
if (permissionDetails.containsKey(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME) && "AD".equalsIgnoreCase(permissionDetails.get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME))) {
if (permissionDetails.containsKey(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE) && permissionDetails.containsKey(KfsKimAttributes.ORGANIZATION_CODE)) {
if (advanceDepositDocument.getSourceAccountingLines() != null && advanceDepositDocument.getSourceAccountingLines().size() > 0) {
String chart = permissionDetails.get(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE);
String org = permissionDetails.get(KfsKimAttributes.ORGANIZATION_CODE);
for (Object accountingLine : advanceDepositDocument.getSourceAccountingLines()) {
SourceAccountingLine sourceAccountingLine = (SourceAccountingLine) accountingLine;
String accountingLineChart = sourceAccountingLine.getChartOfAccountsCode();
String accountingLineOrg = KFSConstants.EMPTY_STRING;
sourceAccountingLine.refreshReferenceObject("account");
if (sourceAccountingLine.getAccount() != null) {
accountingLineOrg = sourceAccountingLine.getAccount().getOrganizationCode();
}
if (chart != null && chart.equalsIgnoreCase(accountingLineChart) && org != null && (org.equalsIgnoreCase(accountingLineOrg) || organizationService.isParentOrganization(accountingLineChart, accountingLineOrg, chart, org))) {
attributes.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, accountingLineChart);
attributes.put(KfsKimAttributes.ORGANIZATION_CODE, accountingLineOrg);
}
}
}
}
}
}
}
use of org.kuali.rice.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(KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE, 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(KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE, 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;
}
Aggregations