From 7b408b9bc6133e0e5f444bed817ac9ef0649fa24 Mon Sep 17 00:00:00 2001 From: goutham-M Date: Tue, 21 May 2013 12:02:37 +0530 Subject: [PATCH] Updating Accounting Rule json format --- .../glaccount/data/GLAccountData.java | 40 +++++++++++++ .../rule/api/AccountingRuleApiResource.java | 2 +- .../api/AccountingRuleJsonInputParams.java | 2 +- .../rule/command/AccountingRuleCommand.java | 4 +- .../rule/data/AccountingRuleData.java | 60 +++++++++---------- .../AccountingRuleReadPlatformService.java | 2 - ...AccountingRuleReadPlatformServiceImpl.java | 26 ++++---- 7 files changed, 83 insertions(+), 53 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/data/GLAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/data/GLAccountData.java index 09aba58a0..4d3e9d3d3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/data/GLAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/data/GLAccountData.java @@ -126,5 +126,45 @@ public class GLAccountData { final CodeValueData tagId = null; return new GLAccountData(id, name, parentId, glCode, disabled, manualEntriesAllowed, type, usage, description, nameDecorated, tagId); } + + public GLAccountData(final Long id, final String name, final String glCode) { + this.id = id; + this.name = name; + this.parentId = null; + this.glCode = glCode; + this.disabled = false; + this.manualEntriesAllowed = false; + this.type = null; + this.usage = null; + this.description = null; + this.nameDecorated = null; + this.tagId = null; + this.accountTypeOptions = null; + this.usageOptions = null; + this.assetHeaderAccountOptions = null; + this.liabilityHeaderAccountOptions = null; + this.equityHeaderAccountOptions = null; + this.incomeHeaderAccountOptions = null; + this.expenseHeaderAccountOptions = null; + this.allowedAssetsTagOptions = null; + this.allowedLiabilitiesTagOptions = null; + this.allowedEquityTagOptions=null; + this.allowedIncomeTagOptions=null; + this.allowedExpensesTagOptions=null; + } + + public Long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public String getGlCode() { + return this.glCode; + } + + } \ No newline at end of file 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 ed6ef7b06..a5701ab94 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 @@ -83,7 +83,7 @@ public class AccountingRuleApiResource { context.authenticatedUser().validateHasReadPermission(resourceNameForPermission); - AccountingRuleData accountingRuleData = this.accountingRuleReadPlatformService.retrieveNewAccountingRuleDetails(); + AccountingRuleData accountingRuleData = null; accountingRuleData = handleTemplate(accountingRuleData); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleJsonInputParams.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleJsonInputParams.java index d79d53dbb..e50fcde0b 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleJsonInputParams.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/api/AccountingRuleJsonInputParams.java @@ -12,7 +12,7 @@ import java.util.Set; * Enum of all parameters passed in while creating/updating a loan product ***/ public enum AccountingRuleJsonInputParams { - ID("id"), OFFICE_ID("officeId"), ACCOUNT_TO_DEBIT("accountToDebitId"), ACCOUNT_TO_CREDIT("accountToCreditId"), NAME("name"), DESCRIPTION( + ID("id"), OFFICE_ID("officeId"), ACCOUNT_TO_DEBIT("debitAccountHead"), ACCOUNT_TO_CREDIT("creditAccountHead"), NAME("name"), DESCRIPTION( "description"), SYSTEM_DEFINED("systemDefined"); private final String value; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/command/AccountingRuleCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/command/AccountingRuleCommand.java index 205839977..b3f3f45af 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/command/AccountingRuleCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/command/AccountingRuleCommand.java @@ -62,9 +62,9 @@ public class AccountingRuleCommand { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("AccountingRule"); baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.ACCOUNT_TO_DEBIT.getValue()).value(this.accountToDebitId) - .ignoreIfNull().integerGreaterThanZero(); + .ignoreIfNull().notBlank().integerGreaterThanZero(); baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.ACCOUNT_TO_CREDIT.getValue()).value(this.accountToCreditId) - .ignoreIfNull().integerGreaterThanZero(); + .ignoreIfNull().notBlank().integerGreaterThanZero(); baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.OFFICE_ID.getValue()).value(this.officeId).ignoreIfNull() .integerGreaterThanZero(); baseDataValidator.reset().parameter(AccountingRuleJsonInputParams.NAME.getValue()).value(this.name).ignoreIfNull().notBlank() diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/data/AccountingRuleData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/data/AccountingRuleData.java index aab885c34..248c3204d 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/data/AccountingRuleData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/rule/data/AccountingRuleData.java @@ -22,15 +22,11 @@ public class AccountingRuleData { private final Long id; private final Long officeId; private final String officeName; - private final Long accountToDebitId; - private final Long accountToCreditId; private final String name; private final String description; private final boolean systemDefined; - private final String debitAccountName; - private final String creditAccountName; - private final String debitAccountGLCode; - private final String creditAccountGLCode; + private final GLAccountData debitAccountHead; + private final GLAccountData creditAccountHead; // template @SuppressWarnings("unused") @@ -38,36 +34,30 @@ public class AccountingRuleData { @SuppressWarnings("unused") private List allowedAccounts = new ArrayList(); - public AccountingRuleData(final Long id, final Long accountToDebitId, final Long accountToCreditId) { + /*public AccountingRuleData(final Long id, final Long accountToDebitId, final Long accountToCreditId) { this(id, null, null, accountToDebitId, accountToCreditId, null, null, true, null, null, null, null, null, null); - } + }*/ - public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId, + /*public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId, final Long accountToCreditId, final String name, final String description, final boolean systemDefined, final String debitAccountName, final String creditAccountName, final String debitAccountGLCode, final String creditAccountGLCode) { this(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined, debitAccountName, creditAccountName, debitAccountGLCode, creditAccountGLCode, null, null); - } + }*/ - public AccountingRuleData(final Long id, final Long officeId, final String officeName, final Long accountToDebitId, - final Long accountToCreditId, final String name, final String description, final boolean systemDefined, - final String debitAccountName, final String creditAccountName, final String debitAccountGLCode, - final String creditAccountGLCode, final List allowedOffices, final List allowedAccounts) { + public AccountingRuleData(final Long id, final Long officeId, final String officeName, final String name, final String description, + final boolean systemDefined, final List allowedOffices, final List allowedAccounts) { this.id = id; this.officeId = officeId; this.officeName = officeName; - this.accountToDebitId = accountToDebitId; - this.accountToCreditId = accountToCreditId; this.name = name; this.description = description; this.systemDefined = systemDefined; this.allowedOffices = allowedOffices; this.allowedAccounts = allowedAccounts; - this.debitAccountName = debitAccountName; - this.creditAccountName = creditAccountName; - this.debitAccountGLCode = debitAccountGLCode; - this.creditAccountGLCode = creditAccountGLCode; + this.debitAccountHead = null; + this.creditAccountHead = null; } public AccountingRuleData(final AccountingRuleData accountingRuleData, @@ -75,33 +65,39 @@ public class AccountingRuleData { this.id = accountingRuleData.id; this.officeId = accountingRuleData.officeId; this.officeName = accountingRuleData.officeName; - this.accountToDebitId = accountingRuleData.accountToDebitId; - this.accountToCreditId = accountingRuleData.accountToCreditId; this.name = accountingRuleData.name; this.description = accountingRuleData.description; this.systemDefined = accountingRuleData.systemDefined; this.allowedOffices = allowedOffices; this.allowedAccounts = allowedAccounts; - this.debitAccountName = accountingRuleData.debitAccountName; - this.creditAccountName = accountingRuleData.creditAccountName; - this.debitAccountGLCode = accountingRuleData.debitAccountGLCode; - this.creditAccountGLCode = accountingRuleData.creditAccountGLCode; + this.debitAccountHead = accountingRuleData.debitAccountHead; + this.creditAccountHead = accountingRuleData.creditAccountHead; } public AccountingRuleData(final List allowedAccounts, final List allowedOffices) { this.id = null; this.officeId = null; this.officeName = null; - this.accountToDebitId = null; - this.accountToCreditId = null; this.name = null; this.description = null; this.systemDefined = false; this.allowedOffices = allowedOffices; this.allowedAccounts = allowedAccounts; - this.debitAccountName = null; - this.creditAccountName = null; - this.debitAccountGLCode = null; - this.creditAccountGLCode = null; + this.debitAccountHead = null; + this.creditAccountHead = null; + } + + public AccountingRuleData(Long id, Long officeId, String officeName, String name, String description, + boolean systemDefined, GLAccountData debitAccountData, GLAccountData creditAccountData) { + this.id = id; + this.officeId = officeId; + this.officeName = officeName; + this.name = name; + this.description = description; + this.systemDefined = systemDefined; + this.allowedOffices = null; + this.allowedAccounts = null; + this.debitAccountHead = debitAccountData; + this.creditAccountHead = creditAccountData; } } \ No newline at end of file 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 4c87e1cf1..d33b7fef7 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 @@ -15,6 +15,4 @@ public interface AccountingRuleReadPlatformService { AccountingRuleData retrieveAccountingRuleById(long accountingRuleId); - AccountingRuleData retrieveNewAccountingRuleDetails(); - } 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 89b3d6b10..369d7586d 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 @@ -9,6 +9,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; +import org.mifosplatform.accounting.glaccount.data.GLAccountData; import org.mifosplatform.accounting.rule.data.AccountingRuleData; import org.mifosplatform.accounting.rule.exception.AccountingRuleNotFoundException; import org.mifosplatform.infrastructure.core.domain.JdbcSupport; @@ -35,7 +36,7 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead public AccountingRuleMapper() { final StringBuilder sqlBuilder = new StringBuilder(400); - sqlBuilder.append(" rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,") + sqlBuilder.append("distinct rule.id as id,rule.name as name, rule.office_id as officeId,office.name as officeName,") .append(" rule.debit_account_id as debitAccountId,rule.credit_account_id as creditAccountId,") .append(" rule.description as description, rule.system_defined as systemDefined, ") .append("debitAccount.glName as debitAccountName, debitAccount.glCode as debitAccountGLCode,") @@ -68,23 +69,25 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead final String creditAccountName = rs.getString("creditAccountName"); final String debitAccountGLCode = rs.getString("debitAccountGLCode"); final String creditAccountGLCode = rs.getString("creditAccountGLCode"); + + final GLAccountData debitAccountData = new GLAccountData(accountToDebitId, debitAccountName, debitAccountGLCode); + final GLAccountData creditAccountData = new GLAccountData(accountToCreditId, creditAccountName, creditAccountGLCode); - return new AccountingRuleData(id, officeId, officeName, accountToDebitId, accountToCreditId, name, description, systemDefined, - debitAccountName, creditAccountName, debitAccountGLCode, creditAccountGLCode); + return new AccountingRuleData(id, officeId, officeName, name, description, systemDefined, debitAccountData, creditAccountData); } } @Override public List retrieveAllAccountingRules(Long officeId) { final AccountingRuleMapper rm = new AccountingRuleMapper(); + Object[] arguments = new Object[]{}; + String sql = "select " + rm.schema() +" and system_defined=0 "; if(officeId != null) { - String sql = "select " + rm.schema() + " where system_defined=0 and office.id = ?"; - sql = sql + " order by rule.id asc"; - return this.jdbcTemplate.query(sql, rm, new Object[] { officeId }); + sql = sql +" and office.id = ?"; + arguments = new Object[] { officeId }; } - String sql = "select " + rm.schema() + " and system_defined=0 "; sql = sql + " order by rule.id asc"; - return this.jdbcTemplate.query(sql, rm, new Object[] {}); + return this.jdbcTemplate.query(sql, rm, arguments); } @Override @@ -100,11 +103,4 @@ public class AccountingRuleReadPlatformServiceImpl implements AccountingRuleRead throw new AccountingRuleNotFoundException(accountingRuleId); } } - - @Override - public AccountingRuleData retrieveNewAccountingRuleDetails() { - // Modify if any default values required - return null; - } - }