From 62ff19e0d22166cc112bff703843fec579e2b2ec Mon Sep 17 00:00:00 2001 From: mifoscontributer Date: Sat, 22 Jun 2013 13:49:08 +0530 Subject: [PATCH] Use Login user hierarchy for view accounting rules --- .../rule/api/AccountingRuleApiResource.java | 13 +++++++++---- .../service/AccountingRuleReadPlatformService.java | 2 +- .../AccountingRuleReadPlatformServiceImpl.java | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleApiResource.java index 8173094bf..b3d414980 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleApiResource.java @@ -45,6 +45,7 @@ import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSeria import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.service.OfficeReadPlatformService; +import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -106,17 +107,21 @@ public class AccountingRuleApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveAllAccountingRules(@Context final UriInfo uriInfo) { - - this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); + + final AppUser currentUser = context.authenticatedUser(); + currentUser.validateHasReadPermission(this.resourceNameForPermission); + + final String hierarchy = currentUser.getOffice().getHierarchy(); + final String hierarchySearchString = hierarchy + "%"; + final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); - final Long officeId = this.context.authenticatedUser().getOffice().getId(); boolean isAssociationParametersExists = false; if (!associationParameters.isEmpty()) { if (associationParameters.contains("all")) { isAssociationParametersExists = true; // If true, retrieve additional fields for journal entry form. } } - final List accountingRuleDatas = this.accountingRuleReadPlatformService.retrieveAllAccountingRules(officeId, + final List accountingRuleDatas = this.accountingRuleReadPlatformService.retrieveAllAccountingRules(hierarchySearchString, isAssociationParametersExists); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformService.java index d8d6ab4dd..f896531bb 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformService.java @@ -11,7 +11,7 @@ import org.mifosplatform.accounting.rule.data.AccountingRuleData; public interface AccountingRuleReadPlatformService { - List retrieveAllAccountingRules(Long OfficeId, boolean isAssociationParametersExists); + List retrieveAllAccountingRules(String hierarchySearchString, boolean isAssociationParametersExists); AccountingRuleData retrieveAccountingRuleById(Long accountingRuleId); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java index 6546a4b84..22fe7f30f 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/service/AccountingRuleReadPlatformServiceImpl.java @@ -133,14 +133,14 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead } @Override - public List retrieveAllAccountingRules(final Long officeId, final boolean isAssociationParametersExists) { + public List retrieveAllAccountingRules(final String hierarchySearchString, final boolean isAssociationParametersExists) { final AccountingRuleDataExtractor resultSetExtractor = new AccountingRuleDataExtractor(this.jdbcTemplate, this.glAccountReadPlatformService, isAssociationParametersExists); Object[] arguments = new Object[] {}; String sql = "select " + resultSetExtractor.schema() + " and system_defined=0 "; - if (officeId != null) { - sql = sql + " and office.id = ?"; - arguments = new Object[] { officeId }; + if (hierarchySearchString != null) { + sql = sql + " and office.hierarchy like ?"; + arguments = new Object[] { hierarchySearchString }; } sql = sql + " order by rule.id asc"; final Map extractedData = this.jdbcTemplate.query(sql, resultSetExtractor, arguments);