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