Search in sources :

Example 1 with OrganizationService

use of org.kuali.kfs.coa.service.OrganizationService 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;
}
Also used : OrganizationService(org.kuali.kfs.coa.service.OrganizationService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RoleMembership(org.kuali.rice.kim.api.role.RoleMembership) Person(org.kuali.rice.kim.api.identity.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with OrganizationService

use of org.kuali.kfs.coa.service.OrganizationService in project cu-kfs by CU-CommunityApps.

the class AccountGlobalRule method checkOrganizationValidity.

/**
 * Validate that the object code on the form (if entered) is valid for all charts used in the detail sections.
 *
 * @param acctGlobal
 * @return
 */
protected boolean checkOrganizationValidity(AccountGlobal acctGlobal) {
    boolean result = true;
    // check that an org has been entered
    if (StringUtils.isNotBlank(acctGlobal.getOrganizationCode())) {
        // get all distinct charts
        HashSet<String> charts = new HashSet<String>(10);
        for (AccountGlobalDetail acct : acctGlobal.getAccountGlobalDetails()) {
            charts.add(acct.getChartOfAccountsCode());
        }
        OrganizationService orgService = SpringContext.getBean(OrganizationService.class);
        // test for an invalid organization
        for (String chartCode : charts) {
            if (StringUtils.isNotBlank(chartCode)) {
                if (null == orgService.getByPrimaryIdWithCaching(chartCode, acctGlobal.getOrganizationCode())) {
                    result = false;
                    putFieldError("organizationCode", KFSKeyConstants.ERROR_DOCUMENT_GLOBAL_ACCOUNT_INVALID_ORG, new String[] { chartCode, acctGlobal.getOrganizationCode() });
                    break;
                }
            }
        }
    }
    return result;
}
Also used : OrganizationService(org.kuali.kfs.coa.service.OrganizationService) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail) HashSet(java.util.HashSet)

Example 3 with OrganizationService

use of org.kuali.kfs.coa.service.OrganizationService 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);
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) OrganizationService(org.kuali.kfs.coa.service.OrganizationService) RoleMembership(org.kuali.rice.kim.api.role.RoleMembership) Person(org.kuali.rice.kim.api.identity.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

OrganizationService (org.kuali.kfs.coa.service.OrganizationService)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Person (org.kuali.rice.kim.api.identity.Person)2 RoleMembership (org.kuali.rice.kim.api.role.RoleMembership)2 HashSet (java.util.HashSet)1 AccountGlobalDetail (org.kuali.kfs.coa.businessobject.AccountGlobalDetail)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1