From 80439d6e6d9c31d391af926bdf1a623f3bf85950 Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Mon, 16 Jun 2014 01:28:04 -0700 Subject: [PATCH] Rewriting Financial Activity Account Mapping --- ...tes_to_financial_activity_accounts_pt2.sql | 5 + .../integrationtests/AccountTransferTest.java | 36 +--- .../OfficeAccountingMappingsTest.java | 20 +-- ...a => FinancialActivityAccountsHelper.java} | 12 +- .../data/FinancialActivityAccountData.java | 38 ----- .../MappingUpdateNotSupportedException.java | 19 --- ...FinancialActivityAccountDataValidator.java | 90 ---------- ...tivityAccountWritePlatformServiceImpl.java | 141 ---------------- .../common/AccountingConstants.java | 91 +++++----- .../FinancialActivityAccountsApiResource.java | 40 ++--- .../FinancialActivityAccountsConstants.java | 13 ++ ...ancialActivityAccountsJsonInputParams.java | 42 +++++ .../data/FinancialActivityAccountData.java | 68 ++++++++ .../data/FinancialActivityData.java | 30 ++++ .../domain/FinancialActivityAccount.java | 17 +- .../FinancialActivityAccountRepository.java | 2 +- ...ncialActivityAccountRepositoryWrapper.java | 10 +- ...inancialActivityAccountFoundException.java | 4 +- ...ancialActivityAccountInvalidException.java | 25 +++ ...ncialActivityAccountNotFoundException.java | 13 +- ...CreateFinancialActivityAccountHandler.java | 6 +- ...inancialActivityAccountCommandHandler.java | 4 +- ...inancialActivityAccountCommandHandler.java | 4 +- ...FinancialActivityAccountDataValidator.java | 104 ++++++++++++ ...ialActivityAccountReadPlatformService.java | 8 +- ...ctivityAccountReadPlatformServiceImpl.java | 39 +++-- ...alActivityAccountWritePlatformService.java | 4 +- ...tivityAccountWritePlatformServiceImpl.java | 158 ++++++++++++++++++ .../api/GLAccountJsonInputParams.java | 2 +- .../service/AccountingProcessorHelper.java | 53 +++--- ...ccrualBasedAccountingProcessorForLoan.java | 12 +- .../CashBasedAccountingProcessorForLoan.java | 15 +- ...ashBasedAccountingProcessorForSavings.java | 30 ++-- .../commands/domain/CommandWrapper.java | 4 +- .../service/CommandWrapperBuilder.java | 6 +- .../SynchronousCommandProcessingService.java | 2 +- .../portfolio/client/domain/Client.java | 7 +- .../domain/InterestRateChartSlabFields.java | 1 - 38 files changed, 649 insertions(+), 526 deletions(-) create mode 100644 mifosng-db/migrations/core_db/V178__updates_to_financial_activity_accounts_pt2.sql rename mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/{OfficeAccountMappingHelper.java => FinancialActivityAccountsHelper.java} (73%) delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/data/FinancialActivityAccountData.java delete mode 100755 mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/MappingUpdateNotSupportedException.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/serialization/FinancialActivityAccountDataValidator.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformServiceImpl.java rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/api/FinancialActivityAccountsApiResource.java (80%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsConstants.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsJsonInputParams.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityAccountData.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityData.java rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/domain/FinancialActivityAccount.java (78%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/domain/FinancialActivityAccountRepository.java (92%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/domain/FinancialActivityAccountRepositoryWrapper.java (72%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/exception/DuplicateFinancialActivityAccountFoundException.java (76%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/exception/FinancialActivityAccountNotFoundException.java (53%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/handler/CreateFinancialActivityAccountHandler.java (79%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/handler/DeleteFinancialActivityAccountCommandHandler.java (86%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/handler/UpdateFinancialActivityAccountCommandHandler.java (86%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/serialization/FinancialActivityAccountDataValidator.java rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/service/FinancialActivityAccountReadPlatformService.java (54%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/service/FinancialActivityAccountReadPlatformServiceImpl.java (62%) rename mifosng-provider/src/main/java/org/mifosplatform/accounting/{accountmapping => financialactivityaccount}/service/FinancialActivityAccountWritePlatformService.java (79%) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java diff --git a/mifosng-db/migrations/core_db/V178__updates_to_financial_activity_accounts_pt2.sql b/mifosng-db/migrations/core_db/V178__updates_to_financial_activity_accounts_pt2.sql new file mode 100644 index 000000000..37f07b7b3 --- /dev/null +++ b/mifosng-db/migrations/core_db/V178__updates_to_financial_activity_accounts_pt2.sql @@ -0,0 +1,5 @@ +update m_permission set entity_name="FINANCIALACTIVITYACCOUNT" where entity_name="OFFICEGLACCOUNT"; +update m_permission set code="READ_FINANCIALACTIVITYACCOUNT" where code="READ_OFFICEGLACCOUNT"; +update m_permission set code="CREATE_FINANCIALACTIVITYACCOUNT" where code="CREATE_OFFICEGLACCOUNT"; +update m_permission set code="DELETE_FINANCIALACTIVITYACCOUNT" where code="DELETE_OFFICEGLACCOUNT"; +update m_permission set code="UPDATE_FINANCIALACTIVITYACCOUNT" where code="UPDATE_OFFICEGLACCOUNT"; \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java index c7befd2a3..0ed4a31c6 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java @@ -2,25 +2,19 @@ package org.mifosplatform.integrationtests; import static org.junit.Assert.assertEquals; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; import java.util.HashMap; -import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mifosplatform.integrationtests.common.ClientHelper; -import org.mifosplatform.integrationtests.common.CommonConstants; import org.mifosplatform.integrationtests.common.OfficeHelper; import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.accounting.Account; import org.mifosplatform.integrationtests.common.accounting.AccountHelper; +import org.mifosplatform.integrationtests.common.accounting.FinancialActivityAccountsHelper; import org.mifosplatform.integrationtests.common.accounting.JournalEntry; import org.mifosplatform.integrationtests.common.accounting.JournalEntryHelper; -import org.mifosplatform.integrationtests.common.accounting.OfficeAccountMappingHelper; -import org.mifosplatform.integrationtests.common.charges.ChargesHelper; import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker; @@ -98,11 +92,8 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - OfficeAccountMappingHelper accountMappingHelper = new OfficeAccountMappingHelper(this.requestSpec, + FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, new ResponseSpecBuilder().build()); - Integer toTransferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(toOfficeId, - toTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(toTransferAccountMappingId); final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); @@ -134,10 +125,6 @@ public class AccountTransferTest { Account fromTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(fromTransferAccount); - Integer fromTransferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(fromOfficeId, - fromTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(fromTransferAccountMappingId); - final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); Assert.assertNotNull(fromSavingsProductID); @@ -213,11 +200,8 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - OfficeAccountMappingHelper accountMappingHelper = new OfficeAccountMappingHelper(this.requestSpec, + FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, new ResponseSpecBuilder().build()); - Integer toTransferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(toOfficeId, - toTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(toTransferAccountMappingId); final Integer toLoanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); Assert.assertNotNull(toLoanProductID); @@ -245,10 +229,6 @@ public class AccountTransferTest { Account fromTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(fromTransferAccount); - Integer fromTransferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(fromOfficeId, - fromTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(fromTransferAccountMappingId); - final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); Assert.assertNotNull(fromSavingsProductID); @@ -322,11 +302,8 @@ public class AccountTransferTest { Account toTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(toTransferAccount); - OfficeAccountMappingHelper accountMappingHelper = new OfficeAccountMappingHelper(this.requestSpec, + FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, new ResponseSpecBuilder().build()); - Integer toTransferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(toOfficeId, - toTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(toTransferAccountMappingId); final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); @@ -356,10 +333,6 @@ public class AccountTransferTest { Account fromTransferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(fromTransferAccount); - Integer fromTransferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(fromOfficeId, - fromTransferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); - Assert.assertNotNull(fromTransferAccountMappingId); - final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); Assert.assertNotNull(loanProductID); @@ -375,7 +348,6 @@ public class AccountTransferTest { loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, loanID); LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); - final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount, liabilityAccount); Assert.assertNotNull(fromSavingsProductID); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java index cc0d026b0..6d01dac80 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeAccountingMappingsTest.java @@ -10,11 +10,10 @@ import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.mifosplatform.integrationtests.common.CommonConstants; -import org.mifosplatform.integrationtests.common.OfficeHelper; import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.accounting.Account; import org.mifosplatform.integrationtests.common.accounting.AccountHelper; -import org.mifosplatform.integrationtests.common.accounting.OfficeAccountMappingHelper; +import org.mifosplatform.integrationtests.common.accounting.FinancialActivityAccountsHelper; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.builder.ResponseSpecBuilder; @@ -36,22 +35,16 @@ public class OfficeAccountingMappingsTest { this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); } + /** @SuppressWarnings("unchecked") @Test - public void testOfficeAccountingMappings() { - - OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec); - Integer officeId = officeHelper.createOffice("01 January 2014"); - Assert.assertNotNull(officeId); - - Integer officeId2 = officeHelper.createOffice("01 January 2014"); - Assert.assertNotNull(officeId2); + public void testFinancialActivityAccounts() { AccountHelper accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); Account transferAccount = accountHelper.createLiabilityAccount(); Assert.assertNotNull(transferAccount); - OfficeAccountMappingHelper accountMappingHelper = new OfficeAccountMappingHelper(this.requestSpec, + FinancialActivityAccountsHelper accountMappingHelper = new FinancialActivityAccountsHelper(this.requestSpec, new ResponseSpecBuilder().build()); Integer transferAccountMappingId = (Integer) accountMappingHelper.createOfficeAccountMapping(officeId, transferAccount.getAccountID(), CommonConstants.RESPONSE_RESOURCE_ID); @@ -86,8 +79,9 @@ public class OfficeAccountingMappingsTest { List error3 = (List) accountMappingHelper.createOfficeAccountMapping(officeId2, fundAccount.getAccountID(), CommonConstants.RESPONSE_ERROR); - assertEquals("error.msg.liabilityTransferInSuspenseAccountId.invalid.account.type", error3.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + assertEquals("error.msg.liabilityTransferInSuspenseAccountId.invalid.account.type", + error3.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); - } + }**/ } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java similarity index 73% rename from mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingHelper.java rename to mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java index a0e232caa..6a6584e86 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/OfficeAccountMappingHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/accounting/FinancialActivityAccountsHelper.java @@ -8,30 +8,30 @@ import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; @SuppressWarnings("rawtypes") -public class OfficeAccountMappingHelper { +public class FinancialActivityAccountsHelper { - private static final String ACCOUNT_MAPPING_URL = "/mifosng-provider/api/v1/officeglaccounts"; + private static final String ACCOUNT_MAPPING_URL = "/mifosng-provider/api/v1/financialactivityaccounts"; private final RequestSpecification requestSpec; private final ResponseSpecification responseSpec; - public OfficeAccountMappingHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + public FinancialActivityAccountsHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { this.requestSpec = requestSpec; this.responseSpec = responseSpec; } - public Object createOfficeAccountMapping(Integer officeId, Integer glAccountId, String jsonBack) { + public Object createFinancialactivityaccounts(Integer officeId, Integer glAccountId, String jsonBack) { String json = OfficeAccountMappingBuilder.build(officeId, glAccountId); return Utils.performServerPost(this.requestSpec, this.responseSpec, ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack); } - public Object updateOfficeAccountMapping(Integer mappingId, Integer officeId, Integer glAccountId, String jsonBack) { + public Object updateFinancialactivityaccounts(Integer mappingId, Integer officeId, Integer glAccountId, String jsonBack) { String json = OfficeAccountMappingBuilder.build(officeId, glAccountId); return Utils.performServerPut(this.requestSpec, this.responseSpec, ACCOUNT_MAPPING_URL + "/" + mappingId + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack); } - public HashMap getOfficeAccountMapping(final Integer mappingId) { + public HashMap getFinancialactivityaccount(final Integer mappingId) { final String URL = ACCOUNT_MAPPING_URL + "/" + mappingId + "?" + Utils.TENANT_IDENTIFIER; return Utils.performServerGet(requestSpec, responseSpec, URL, ""); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/data/FinancialActivityAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/data/FinancialActivityAccountData.java deleted file mode 100644 index cdf41a11d..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/data/FinancialActivityAccountData.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.mifosplatform.accounting.accountmapping.data; - -import java.util.List; -import java.util.Map; - -import org.mifosplatform.accounting.glaccount.data.GLAccountData; - -public class FinancialActivityAccountData { - - private final Long id; - private final GLAccountData glAccountData; - private final Map> accountingMappingOptions; - - public static FinancialActivityAccountData instance(final Long id, final GLAccountData glAccountData) { - final Map> accountingMappingOptions = null; - return new FinancialActivityAccountData(id, glAccountData, accountingMappingOptions); - } - - public static FinancialActivityAccountData template(final Map> accountingMappingOptions) { - final Long id = null; - final GLAccountData glAccountData = null; - return new FinancialActivityAccountData(id, glAccountData, accountingMappingOptions); - } - - public static FinancialActivityAccountData associateTemplateData(final FinancialActivityAccountData templateData, - final FinancialActivityAccountData accountMappingData) { - return new FinancialActivityAccountData(accountMappingData.id, accountMappingData.glAccountData, - templateData.accountingMappingOptions); - } - - private FinancialActivityAccountData(final Long id, final GLAccountData glAccountData, - final Map> accountingMappingOptions) { - this.id = id; - this.glAccountData = glAccountData; - this.accountingMappingOptions = accountingMappingOptions; - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/MappingUpdateNotSupportedException.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/MappingUpdateNotSupportedException.java deleted file mode 100755 index 4088c59f7..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/MappingUpdateNotSupportedException.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.accounting.accountmapping.exception; - -import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; - -/** - * A {@link RuntimeException} thrown when Calendar resources are not found. - */ -public class MappingUpdateNotSupportedException extends AbstractPlatformDomainRuleException { - - public MappingUpdateNotSupportedException(final String postFix, final String defaultUserMessage, - final Object... defaultUserMessageArgs) { - super("error.msg.officeToAccountMapping.update.of." + postFix + ".is.not.supported", defaultUserMessage, defaultUserMessageArgs); - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/serialization/FinancialActivityAccountDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/serialization/FinancialActivityAccountDataValidator.java deleted file mode 100644 index 4942f0bf7..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/serialization/FinancialActivityAccountDataValidator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.accounting.accountmapping.serialization; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTING_PARAMS; -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; -import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.google.gson.JsonElement; -import com.google.gson.reflect.TypeToken; - -@Component -public final class FinancialActivityAccountDataValidator { - - /** - * The parameters supported for this command. - */ - private final Set supportedParameters = new HashSet(Arrays.asList("locale", - ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue())); - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public FinancialActivityAccountDataValidator(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - - public void validateForCreate(final String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); - - final List dataValidationErrors = new ArrayList(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loanproduct"); - - final JsonElement element = this.fromApiJsonHelper.parse(json); - - final Long liabilityTransferInSuspenseAccountId = this.fromApiJsonHelper.extractLongNamed( - ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), element); - baseDataValidator.reset().parameter(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue()) - .value(liabilityTransferInSuspenseAccountId).notNull().integerGreaterThanZero(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - - public void validateForUpdate(final String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); - - final List dataValidationErrors = new ArrayList(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loanproduct"); - - final JsonElement element = this.fromApiJsonHelper.parse(json); - - if (this.fromApiJsonHelper.parameterExists(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), element)) { - final Long liabilityTransferInSuspenseAccountId = this.fromApiJsonHelper.extractLongNamed( - ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), element); - baseDataValidator.reset().parameter(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue()) - .value(liabilityTransferInSuspenseAccountId).notNull().integerGreaterThanZero(); - } - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformServiceImpl.java deleted file mode 100644 index 405ba8b2a..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformServiceImpl.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.mifosplatform.accounting.accountmapping.service; - -import java.util.HashMap; -import java.util.Map; - -import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccount; -import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccountRepositoryWrapper; -import org.mifosplatform.accounting.accountmapping.exception.DuplicateFinancialActivityAccountFoundException; -import org.mifosplatform.accounting.accountmapping.serialization.FinancialActivityAccountDataValidator; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTING_PARAMS; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTS; -import org.mifosplatform.accounting.glaccount.domain.GLAccount; -import org.mifosplatform.accounting.glaccount.domain.GLAccountRepositoryWrapper; -import org.mifosplatform.accounting.glaccount.domain.GLAccountType; -import org.mifosplatform.accounting.producttoaccountmapping.exception.ProductToGLAccountMappingInvalidException; -import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; -import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; -import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.google.gson.JsonElement; - -@Service -public class FinancialActivityAccountWritePlatformServiceImpl implements FinancialActivityAccountWritePlatformService { - - private final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository; - private final FinancialActivityAccountDataValidator fromApiJsonDeserializer; - private final FromJsonHelper fromApiJsonHelper; - private final GLAccountRepositoryWrapper glAccountRepositoryWrapper; - - @Autowired - public FinancialActivityAccountWritePlatformServiceImpl( - final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository, - final FinancialActivityAccountDataValidator fromApiJsonDeserializer, final FromJsonHelper fromApiJsonHelper, - final GLAccountRepositoryWrapper glAccountRepositoryWrapper) { - this.financialActivityAccountRepository = financialActivityAccountRepository; - this.fromApiJsonDeserializer = fromApiJsonDeserializer; - this.fromApiJsonHelper = fromApiJsonHelper; - this.glAccountRepositoryWrapper = glAccountRepositoryWrapper; - } - - @Override - public CommandProcessingResult createGLAccountActivityMapping(JsonCommand command) { - - this.fromApiJsonDeserializer.validateForCreate(command.json()); - final JsonElement element = this.fromApiJsonHelper.parse(command.json()); - FinancialActivityAccount financialActivityAccount = createLiabilityTrasferSuspenceMapping(element); - checkForExistingMapping(financialActivityAccount); - this.financialActivityAccountRepository.save(financialActivityAccount); - return new CommandProcessingResultBuilder() // - .withCommandId(command.commandId()) // - .withEntityId(financialActivityAccount.getId()) // - .build(); - } - - private void checkForExistingMapping(final FinancialActivityAccount financialActivityAccount) { - FinancialActivityAccount existingMapping = this.financialActivityAccountRepository - .findByFinancialActivityType(financialActivityAccount.getFinancialActivityType()); - if (existingMapping != null) { throw new DuplicateFinancialActivityAccountFoundException( - financialActivityAccount.getFinancialActivityType()); } - } - - @Override - public CommandProcessingResult updateGLAccountActivityMapping(Long mappingId, JsonCommand command) { - this.fromApiJsonDeserializer.validateForUpdate(command.json()); - final FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository - .findOneWithNotFoundDetection(mappingId); - Map changes = findChanges(command, financialActivityAccount); - final JsonElement element = this.fromApiJsonHelper.parse(command.json()); - - if (changes.containsKey(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue())) { - final GLAccount glAccount = fetchGLAccount(element, ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - GLAccountType.LIABILITY); - financialActivityAccount.updateGlAccount(glAccount); - this.financialActivityAccountRepository.save(financialActivityAccount); - } - return new CommandProcessingResultBuilder() // - .withCommandId(command.commandId()) // - .withEntityId(mappingId) // - .with(changes) // - .build(); - } - - @Override - public CommandProcessingResult deleteGLAccountActivityMapping(Long mappingId, JsonCommand command) { - final FinancialActivityAccount officeToGLAccountMapping = this.financialActivityAccountRepository - .findOneWithNotFoundDetection(mappingId); - this.financialActivityAccountRepository.delete(officeToGLAccountMapping); - return new CommandProcessingResultBuilder() // - .withCommandId(command.commandId()) // - .withEntityId(mappingId) // - .build(); - } - - private FinancialActivityAccount createLiabilityTrasferSuspenceMapping(final JsonElement element) { - final GLAccount glAccount = fetchGLAccount(element, ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - GLAccountType.LIABILITY); - final Integer financialAccountType = ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(); - return FinancialActivityAccount.createNew(glAccount, financialAccountType); - } - - private GLAccount fetchGLAccount(final JsonElement element, final String paramName, final GLAccountType expectedAccountType) { - final Long accountId = this.fromApiJsonHelper.extractLongNamed(paramName, element); - final GLAccount glAccount = getAccountByIdAndType(paramName, expectedAccountType, accountId); - return glAccount; - } - - /** - * Fetches account with a particular Id and throws and Exception it is not - * of the expected Account Category ('ASSET','liability' etc) - * - * @param paramName - * @param expectedAccountType - * @param accountId - * @return - */ - public GLAccount getAccountByIdAndType(final String paramName, final GLAccountType expectedAccountType, final Long accountId) { - final GLAccount glAccount = this.glAccountRepositoryWrapper.findOneWithNotFoundDetection(accountId); - // validate account is of the expected Type - if (glAccount.getType().intValue() != expectedAccountType.getValue()) { throw new ProductToGLAccountMappingInvalidException( - paramName, glAccount.getName(), accountId, GLAccountType.fromInt(glAccount.getType()).toString(), - expectedAccountType.toString()); } - return glAccount; - } - - public Map findChanges(JsonCommand command, FinancialActivityAccount financialActivityAccount) { - - Map changes = new HashMap(); - - Long existingGLAccountId = financialActivityAccount.glAccount().getId(); - if (command - .isChangeInLongParameterNamed(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), existingGLAccountId)) { - final Long newValue = command.longValueOfParameterNamed(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue()); - changes.put(ORGANIZATION_ACCOUNTING_PARAMS.LIABILITY_TRANSFER_SUSPENSE.getValue(), newValue); - } - return changes; - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java index 3a9b9c3d9..c9fd912c1 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/common/AccountingConstants.java @@ -5,9 +5,14 @@ */ package org.mifosplatform.accounting.common; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.mifosplatform.accounting.financialactivityaccount.data.FinancialActivityData; +import org.mifosplatform.accounting.glaccount.domain.GLAccountType; + public class AccountingConstants { /*** Accounting placeholders for cash based accounting for loan products ***/ @@ -215,13 +220,18 @@ public class AccountingConstants { } } - public static enum ORGANIZATION_ACCOUNTS { - LIABILITY_TRANSFER_SUSPENSE(100); + public static enum FINANCIAL_ACTIVITY { + ASSET_TRANSFER(100, "assetTransfer", GLAccountType.ASSET), LIABILITY_TRANSFER(200, "liabilityTransfer", GLAccountType.LIABILITY); private final Integer value; + private final String code; + private final GLAccountType mappedGLAccountType; + private static List financialActivities; - private ORGANIZATION_ACCOUNTS(final Integer value) { + private FINANCIAL_ACTIVITY(final Integer value, final String code, final GLAccountType mappedGLAccountType) { this.value = value; + this.code = code; + this.mappedGLAccountType = mappedGLAccountType; } @Override @@ -233,62 +243,49 @@ public class AccountingConstants { return this.value; } - private static final Map intToEnumMap = new HashMap(); + public String getCode() { + return this.code; + } + + public GLAccountType getMappedGLAccountType() { + return mappedGLAccountType; + } + + public String getValueAsString() { + return this.value.toString(); + } + + private static final Map intToEnumMap = new HashMap(); static { - for (final ORGANIZATION_ACCOUNTS type : ORGANIZATION_ACCOUNTS.values()) { + for (final FINANCIAL_ACTIVITY type : FINANCIAL_ACTIVITY.values()) { intToEnumMap.put(type.value, type); } } - public static ORGANIZATION_ACCOUNTS fromInt(final int i) { - final ORGANIZATION_ACCOUNTS type = intToEnumMap.get(Integer.valueOf(i)); + public static FINANCIAL_ACTIVITY fromInt(final int financialActivityId) { + final FINANCIAL_ACTIVITY type = intToEnumMap.get(Integer.valueOf(financialActivityId)); return type; } - } - /*** - * Enum of all accounting related input parameter names used while - * creating/updating a loan product - ***/ - public static enum ORGANIZATION_ACCOUNTING_PARAMS { - LIABILITY_TRANSFER_SUSPENSE("liabilityTransferInSuspenseAccountId"); - - private final String value; - - private ORGANIZATION_ACCOUNTING_PARAMS(final String value) { - this.value = value; + public static FinancialActivityData toFinancialActivityData(final int financialActivityId) { + final FINANCIAL_ACTIVITY type = fromInt(financialActivityId); + return convertToFinancialActivityData(type); } - @Override - public String toString() { - return name().toString().replaceAll("_", " "); + public static List getAllFinancialActivities() { + if (financialActivities == null) { + financialActivities = new ArrayList(); + for (final FINANCIAL_ACTIVITY type : FINANCIAL_ACTIVITY.values()) { + FinancialActivityData financialActivityData = convertToFinancialActivityData(type); + financialActivities.add(financialActivityData); + } + } + return financialActivities; } - public String getValue() { - return this.value; - } - } - - /*** - * Enum of all accounting related input parameter names used while - * creating/updating a loan product - ***/ - public static enum ORGANIZATION_ACCOUNTING_DATA_PARAMS { - LIABILITY_TRANSFER_SUSPENSE("liabilityTransferInSuspenseAccount"); - - private final String value; - - private ORGANIZATION_ACCOUNTING_DATA_PARAMS(final String value) { - this.value = value; - } - - @Override - public String toString() { - return name().toString().replaceAll("_", " "); - } - - public String getValue() { - return this.value; + private static FinancialActivityData convertToFinancialActivityData(final FINANCIAL_ACTIVITY type) { + FinancialActivityData financialActivityData = new FinancialActivityData(type.value, type.code, type.getMappedGLAccountType()); + return financialActivityData; } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/api/FinancialActivityAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsApiResource.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/api/FinancialActivityAccountsApiResource.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsApiResource.java index 4571cd946..89b3158a1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/api/FinancialActivityAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsApiResource.java @@ -3,12 +3,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.api; +package org.mifosplatform.accounting.financialactivityaccount.api; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -22,8 +19,8 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; -import org.mifosplatform.accounting.accountmapping.data.FinancialActivityAccountData; -import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountReadPlatformService; +import org.mifosplatform.accounting.financialactivityaccount.data.FinancialActivityAccountData; +import org.mifosplatform.accounting.financialactivityaccount.service.FinancialActivityAccountReadPlatformService; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; @@ -41,11 +38,6 @@ import org.springframework.stereotype.Component; @Scope("singleton") public class FinancialActivityAccountsApiResource { - private static final Set RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "glAccountData", - "accountingMappingOptions")); - - private final String resourceNameForPermission = "OFFICEGLACCOUNT"; - private final FinancialActivityAccountReadPlatformService financialActivityAccountReadPlatformService; private final DefaultToApiJsonSerializer apiJsonSerializerService; private final ApiRequestParameterHelper apiRequestParameterHelper; @@ -71,12 +63,14 @@ public class FinancialActivityAccountsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String retrieveTemplate(@Context final UriInfo uriInfo) { - this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); + this.context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission); - FinancialActivityAccountData officeToGLAccountMappingData = this.financialActivityAccountReadPlatformService.retrieveTemplate(); + FinancialActivityAccountData financialActivityAccountData = this.financialActivityAccountReadPlatformService + .getFinancialActivityAccountTemplate(); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.apiJsonSerializerService.serialize(settings, officeToGLAccountMappingData, RESPONSE_DATA_PARAMETERS); + return this.apiJsonSerializerService.serialize(settings, financialActivityAccountData, + FinancialActivityAccountsConstants.RESPONSE_DATA_PARAMETERS); } @GET @@ -84,29 +78,31 @@ public class FinancialActivityAccountsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String retrieveAll(@Context final UriInfo uriInfo) { - this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); + this.context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission); final List financialActivityAccounts = this.financialActivityAccountReadPlatformService.retrieveAll(); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.apiJsonSerializerService.serialize(settings, financialActivityAccounts, RESPONSE_DATA_PARAMETERS); + return this.apiJsonSerializerService.serialize(settings, financialActivityAccounts, + FinancialActivityAccountsConstants.RESPONSE_DATA_PARAMETERS); } @GET @Path("{mappingId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String retreiveAccountMapping(@PathParam("mappingId") final Long mappingId, @Context final UriInfo uriInfo) { + public String retreive(@PathParam("mappingId") final Long mappingId, @Context final UriInfo uriInfo) { - this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermission); + this.context.authenticatedUser().validateHasReadPermission(FinancialActivityAccountsConstants.resourceNameForPermission); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - FinancialActivityAccountData officeToGLAccountMappingData = this.financialActivityAccountReadPlatformService.retrieve(mappingId); + FinancialActivityAccountData financialActivityAccountData = this.financialActivityAccountReadPlatformService.retrieve(mappingId); if (settings.isTemplate()) { - FinancialActivityAccountData templateData = this.financialActivityAccountReadPlatformService.retrieveTemplate(); - officeToGLAccountMappingData = FinancialActivityAccountData.associateTemplateData(templateData, officeToGLAccountMappingData); + financialActivityAccountData = this.financialActivityAccountReadPlatformService + .addTemplateDetails(financialActivityAccountData); } - return this.apiJsonSerializerService.serialize(settings, officeToGLAccountMappingData, RESPONSE_DATA_PARAMETERS); + return this.apiJsonSerializerService.serialize(settings, financialActivityAccountData, + FinancialActivityAccountsConstants.RESPONSE_DATA_PARAMETERS); } @POST diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsConstants.java new file mode 100644 index 000000000..1da245b76 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsConstants.java @@ -0,0 +1,13 @@ +package org.mifosplatform.accounting.financialactivityaccount.api; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class FinancialActivityAccountsConstants { + + public static final Set RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "financialActivityData", + "glAccountData", "glAccountOptions", "financialActivityOptions")); + + public static final String resourceNameForPermission = "FINANCIALACTIVITYACCOUNT"; +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsJsonInputParams.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsJsonInputParams.java new file mode 100644 index 000000000..a99f771cd --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/api/FinancialActivityAccountsJsonInputParams.java @@ -0,0 +1,42 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.accounting.financialactivityaccount.api; + +import java.util.HashSet; +import java.util.Set; + +/*** + * Enum of all parameters passed in while creating/updating a GL Account + ***/ +public enum FinancialActivityAccountsJsonInputParams { + FINANCIAL_ACTIVITY_ID("financialActivityId"), GL_ACCOUNT_ID("glAccountId"); + + private final String value; + + private FinancialActivityAccountsJsonInputParams(final String value) { + this.value = value; + } + + private static final Set values = new HashSet(); + static { + for (final FinancialActivityAccountsJsonInputParams type : FinancialActivityAccountsJsonInputParams.values()) { + values.add(type.value); + } + } + + public static Set getAllValues() { + return values; + } + + @Override + public String toString() { + return name().toString().replaceAll("_", " "); + } + + public String getValue() { + return this.value; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityAccountData.java new file mode 100644 index 000000000..015b069ad --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityAccountData.java @@ -0,0 +1,68 @@ +package org.mifosplatform.accounting.financialactivityaccount.data; + +import java.util.List; +import java.util.Map; + +import org.mifosplatform.accounting.glaccount.data.GLAccountData; + +public class FinancialActivityAccountData { + + private final Long id; + private final FinancialActivityData financialActivityData; + private final GLAccountData glAccountData; + private Map> glAccountOptions; + private List financialActivityOptions; + + public FinancialActivityAccountData() { + this.id = null; + this.glAccountData = null; + this.financialActivityData = null; + this.glAccountOptions = null; + this.financialActivityOptions = null; + } + + public FinancialActivityAccountData(final Long id, final FinancialActivityData financialActivityData, final GLAccountData glAccountData) { + this.id = id; + this.glAccountData = glAccountData; + this.financialActivityData = financialActivityData; + } + + public FinancialActivityAccountData(Map> glAccountOptions, + List financialActivityOptions) { + this.id = null; + this.glAccountData = null; + this.financialActivityData = null; + this.glAccountOptions = glAccountOptions; + this.financialActivityOptions = financialActivityOptions; + + } + + public List getFinancialActivityOptions() { + return financialActivityOptions; + } + + public void setFinancialActivityOptions(List financialActivityOptions) { + this.financialActivityOptions = financialActivityOptions; + } + + public Map> getAccountingMappingOptions() { + return this.glAccountOptions; + } + + public void setAccountingMappingOptions(Map> accountingMappingOptions) { + this.glAccountOptions = accountingMappingOptions; + } + + public GLAccountData getGlAccountData() { + return glAccountData; + } + + public FinancialActivityData getFinancialActivityData() { + return financialActivityData; + } + + public Long getId() { + return id; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityData.java new file mode 100644 index 000000000..47a6145b1 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/data/FinancialActivityData.java @@ -0,0 +1,30 @@ +package org.mifosplatform.accounting.financialactivityaccount.data; + +import org.mifosplatform.accounting.glaccount.domain.GLAccountType; + +public class FinancialActivityData { + + private final Integer id; + private final String name; + private final GLAccountType mappedGLAccountType; + + public Integer getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public GLAccountType getMappedGLAccountType() { + return this.mappedGLAccountType; + } + + public FinancialActivityData(Integer id, String name, GLAccountType mappedGLAccountType) { + super(); + this.id = id; + this.name = name; + this.mappedGLAccountType = mappedGLAccountType; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccount.java similarity index 78% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccount.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccount.java index 5f825ac2c..2964f0ee7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccount.java @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.domain; +package org.mifosplatform.accounting.financialactivityaccount.domain; import javax.persistence.Column; import javax.persistence.Entity; @@ -24,9 +24,9 @@ public class FinancialActivityAccount extends AbstractPersistable { private GLAccount glAccount; @Column(name = "financial_activity_type", nullable = false) - private int financialActivityType; + private Integer financialActivityType; - public static FinancialActivityAccount createNew(final GLAccount glAccount, final int financialAccountType) { + public static FinancialActivityAccount createNew(final GLAccount glAccount, final Integer financialAccountType) { return new FinancialActivityAccount(glAccount, financialAccountType); } @@ -39,16 +39,19 @@ public class FinancialActivityAccount extends AbstractPersistable { this.financialActivityType = financialAccountType; } - public GLAccount glAccount() { + public GLAccount getGlAccount() { return this.glAccount; } + public Integer getFinancialActivityType() { + return this.financialActivityType; + } + public void updateGlAccount(final GLAccount glAccount) { this.glAccount = glAccount; } - public int getFinancialActivityType() { - return this.financialActivityType; + public void updateFinancialActivityType(final Integer financialActivityType) { + this.financialActivityType = financialActivityType; } - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccountRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java similarity index 92% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccountRepository.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java index 50e42ea47..1dd901180 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccountRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccountRepository.java @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.domain; +package org.mifosplatform.accounting.financialactivityaccount.domain; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccountRepositoryWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccountRepositoryWrapper.java similarity index 72% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccountRepositoryWrapper.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccountRepositoryWrapper.java index c8cd0a1dc..e6b20ffa6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/domain/FinancialActivityAccountRepositoryWrapper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/domain/FinancialActivityAccountRepositoryWrapper.java @@ -3,11 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.domain; +package org.mifosplatform.accounting.financialactivityaccount.domain; import java.util.List; -import org.mifosplatform.accounting.accountmapping.exception.FinancialActivityAccountNotFoundException; +import org.mifosplatform.accounting.financialactivityaccount.exception.FinancialActivityAccountNotFoundException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,8 +33,10 @@ public class FinancialActivityAccountRepositoryWrapper { return financialActivityAccount; } - public FinancialActivityAccount findByFinancialActivityType(final int financialActivityType) { - return this.repository.findByFinancialActivityType(financialActivityType); + public FinancialActivityAccount findByFinancialActivityTypeWithNotFoundDetection(final int financialActivityType) { + FinancialActivityAccount financialActivityAccount = this.repository.findByFinancialActivityType(financialActivityType); + if (financialActivityAccount == null) { throw new FinancialActivityAccountNotFoundException(financialActivityType); } + return financialActivityAccount; } public List findAll() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/DuplicateFinancialActivityAccountFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java similarity index 76% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/DuplicateFinancialActivityAccountFoundException.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java index e70cd780f..463a1696e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/DuplicateFinancialActivityAccountFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/DuplicateFinancialActivityAccountFoundException.java @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.exception; +package org.mifosplatform.accounting.financialactivityaccount.exception; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; @@ -14,7 +14,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul public class DuplicateFinancialActivityAccountFoundException extends AbstractPlatformDomainRuleException { public DuplicateFinancialActivityAccountFoundException(final Integer financialActivityType) { - super("error.msg.officeToAccountMapping.exists.for.office", "Mapping for activity already exists " + financialActivityType, + super("error.msg.financialActivityAccount.exists.for.office", "Mapping for activity already exists " + financialActivityType, financialActivityType); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java new file mode 100644 index 000000000..47562f5c9 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountInvalidException.java @@ -0,0 +1,25 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.accounting.financialactivityaccount.exception; + +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; +import org.mifosplatform.accounting.glaccount.domain.GLAccount; +import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException; + +/** + * A {@link RuntimeException} thrown when product to GL account mapping are not + * found. + */ +public class FinancialActivityAccountInvalidException extends AbstractPlatformDomainRuleException { + + public FinancialActivityAccountInvalidException(final FINANCIAL_ACTIVITY financialActivity, final GLAccount glAccount) { + super("error.msg.financialActivityAccount.invalid", "Financial Activity '" + financialActivity.getCode() + "' with Id :" + + financialActivity.getValue() + "' can only be associated with a Ledger Account of Type " + + financialActivity.getMappedGLAccountType().getCode() + " the provided Ledger Account '" + glAccount.getName() + "(" + + glAccount.getGlCode() + ")' does not of the required type", financialActivity.getCode(), financialActivity.getValue(), + financialActivity.getMappedGLAccountType().getCode(), glAccount.getName(), glAccount.getGlCode()); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/FinancialActivityAccountNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountNotFoundException.java similarity index 53% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/FinancialActivityAccountNotFoundException.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountNotFoundException.java index bcfedd10b..397d3d7a3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/exception/FinancialActivityAccountNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/exception/FinancialActivityAccountNotFoundException.java @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.exception; +package org.mifosplatform.accounting.financialactivityaccount.exception; import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException; @@ -13,12 +13,13 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN */ public class FinancialActivityAccountNotFoundException extends AbstractPlatformResourceNotFoundException { - public FinancialActivityAccountNotFoundException(final Long officeId, final String accountType) { - super("error.msg.officeToAccountMapping.not.found", "Mapping for office with Id " + officeId - + " does not exist for an account of type " + accountType, officeId, accountType); + public FinancialActivityAccountNotFoundException(final Long id) { + super("error.msg.financialActivityAccount.not.found", "Financial Activity account with Id " + id + " does not exist", id); } - public FinancialActivityAccountNotFoundException(final Long id) { - super("error.msg.officeToAccountMapping.not.found", "Mapping for GL Account with Id " + id + " does not exist", id); + public FinancialActivityAccountNotFoundException(final Integer financialActivityType) { + super("error.msg.financialActivityAccount.not.found", "Financial Activity account with for the financial Activity with Id " + + financialActivityType + " does not exist", financialActivityType); } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/CreateFinancialActivityAccountHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/CreateFinancialActivityAccountHandler.java similarity index 79% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/CreateFinancialActivityAccountHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/CreateFinancialActivityAccountHandler.java index 3db068ab4..57caccb50 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/CreateFinancialActivityAccountHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/CreateFinancialActivityAccountHandler.java @@ -3,9 +3,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.handler; +package org.mifosplatform.accounting.financialactivityaccount.handler; -import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountWritePlatformService; +import org.mifosplatform.accounting.financialactivityaccount.service.FinancialActivityAccountWritePlatformService; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; @@ -27,6 +27,6 @@ public class CreateFinancialActivityAccountHandler implements NewCommandSourceHa @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.createGLAccountActivityMapping(command); + return this.writePlatformService.createFinancialActivityAccountMapping(command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/DeleteFinancialActivityAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/DeleteFinancialActivityAccountCommandHandler.java similarity index 86% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/DeleteFinancialActivityAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/DeleteFinancialActivityAccountCommandHandler.java index f1fbf6d3c..3b5454c93 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/DeleteFinancialActivityAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/DeleteFinancialActivityAccountCommandHandler.java @@ -3,9 +3,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.handler; +package org.mifosplatform.accounting.financialactivityaccount.handler; -import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountWritePlatformService; +import org.mifosplatform.accounting.financialactivityaccount.service.FinancialActivityAccountWritePlatformService; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/UpdateFinancialActivityAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/UpdateFinancialActivityAccountCommandHandler.java similarity index 86% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/UpdateFinancialActivityAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/UpdateFinancialActivityAccountCommandHandler.java index b1ad61963..ba2a94a11 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/handler/UpdateFinancialActivityAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/handler/UpdateFinancialActivityAccountCommandHandler.java @@ -3,9 +3,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.handler; +package org.mifosplatform.accounting.financialactivityaccount.handler; -import org.mifosplatform.accounting.accountmapping.service.FinancialActivityAccountWritePlatformService; +import org.mifosplatform.accounting.financialactivityaccount.service.FinancialActivityAccountWritePlatformService; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/serialization/FinancialActivityAccountDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/serialization/FinancialActivityAccountDataValidator.java new file mode 100644 index 000000000..68f158ca2 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/serialization/FinancialActivityAccountDataValidator.java @@ -0,0 +1,104 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.accounting.financialactivityaccount.serialization; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; +import org.mifosplatform.accounting.financialactivityaccount.api.FinancialActivityAccountsJsonInputParams; +import org.mifosplatform.infrastructure.core.data.ApiParameterError; +import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; +import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; +import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; +import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; + +@Component +public final class FinancialActivityAccountDataValidator { + + /** + * The parameters supported for this command. + */ + private final Set supportedParameters = FinancialActivityAccountsJsonInputParams.getAllValues(); + + private final FromJsonHelper fromApiJsonHelper; + + private final String paramNameForFinancialActivity = FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue(); + private final String paramNameForGLAccount = FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue(); + + @Autowired + public FinancialActivityAccountDataValidator(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validateForCreate(final String json) { + validateJSONAndCheckForUnsupportedParams(json); + + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = getDataValidator(dataValidationErrors); + + final JsonElement element = this.fromApiJsonHelper.parse(json); + + final Integer financialActivityId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(paramNameForFinancialActivity, element); + baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).notNull() + .isOneOfTheseValues(FINANCIAL_ACTIVITY.ASSET_TRANSFER.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue()); + + final Long glAccountId = this.fromApiJsonHelper.extractLongNamed(paramNameForGLAccount, element); + baseDataValidator.reset().parameter(paramNameForGLAccount).value(glAccountId).notNull().integerGreaterThanZero(); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + private DataValidatorBuilder getDataValidator(final List dataValidationErrors) { + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("financialactivityaccount"); + return baseDataValidator; + } + + public void validateForUpdate(final String json) { + validateJSONAndCheckForUnsupportedParams(json); + + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = getDataValidator(dataValidationErrors); + + final JsonElement element = this.fromApiJsonHelper.parse(json); + + if (this.fromApiJsonHelper.parameterExists(paramNameForFinancialActivity, element)) { + final Integer financialActivityId = this.fromApiJsonHelper + .extractIntegerSansLocaleNamed(paramNameForFinancialActivity, element); + baseDataValidator.reset().parameter(paramNameForFinancialActivity).value(financialActivityId).ignoreIfNull() + .isOneOfTheseValues(FINANCIAL_ACTIVITY.ASSET_TRANSFER.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue()); + } + + if (this.fromApiJsonHelper.parameterExists(paramNameForGLAccount, element)) { + final Long glAccountId = this.fromApiJsonHelper.extractLongNamed(paramNameForGLAccount, element); + baseDataValidator.reset().parameter(paramNameForGLAccount).value(glAccountId).ignoreIfNull().integerGreaterThanZero(); + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + private void validateJSONAndCheckForUnsupportedParams(final String json) { + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); + } + + private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountReadPlatformService.java similarity index 54% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountReadPlatformService.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountReadPlatformService.java index ec2c4aa1d..f8ea53cdb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountReadPlatformService.java @@ -3,11 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.service; +package org.mifosplatform.accounting.financialactivityaccount.service; import java.util.List; -import org.mifosplatform.accounting.accountmapping.data.FinancialActivityAccountData; +import org.mifosplatform.accounting.financialactivityaccount.data.FinancialActivityAccountData; public interface FinancialActivityAccountReadPlatformService { @@ -15,6 +15,8 @@ public interface FinancialActivityAccountReadPlatformService { FinancialActivityAccountData retrieve(Long mappingId); - FinancialActivityAccountData retrieveTemplate(); + FinancialActivityAccountData addTemplateDetails(FinancialActivityAccountData financialActivityAccountData); + + FinancialActivityAccountData getFinancialActivityAccountTemplate(); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountReadPlatformServiceImpl.java similarity index 62% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountReadPlatformServiceImpl.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountReadPlatformServiceImpl.java index 78bfe5322..f89394edc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountReadPlatformServiceImpl.java @@ -1,13 +1,15 @@ -package org.mifosplatform.accounting.accountmapping.service; +package org.mifosplatform.accounting.financialactivityaccount.service; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; -import org.mifosplatform.accounting.accountmapping.data.FinancialActivityAccountData; -import org.mifosplatform.accounting.accountmapping.exception.FinancialActivityAccountNotFoundException; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; import org.mifosplatform.accounting.common.AccountingDropdownReadPlatformService; +import org.mifosplatform.accounting.financialactivityaccount.data.FinancialActivityAccountData; +import org.mifosplatform.accounting.financialactivityaccount.data.FinancialActivityData; +import org.mifosplatform.accounting.financialactivityaccount.exception.FinancialActivityAccountNotFoundException; import org.mifosplatform.accounting.glaccount.data.GLAccountData; import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; @@ -39,22 +41,31 @@ public class FinancialActivityAccountReadPlatformServiceImpl implements Financia } @Override - public FinancialActivityAccountData retrieve(Long mappingId) { + public FinancialActivityAccountData retrieve(Long financialActivityAccountId) { try { StringBuilder sqlBuilder = new StringBuilder(200); sqlBuilder.append("select "); sqlBuilder.append(this.financialActivityAccountMapper.schema()); sqlBuilder.append(" where faa.id=?"); - return this.jdbcTemplate.queryForObject(sqlBuilder.toString(), this.financialActivityAccountMapper, new Object[] { mappingId }); + return this.jdbcTemplate.queryForObject(sqlBuilder.toString(), this.financialActivityAccountMapper, + new Object[] { financialActivityAccountId }); } catch (final EmptyResultDataAccessException e) { - throw new FinancialActivityAccountNotFoundException(mappingId); + throw new FinancialActivityAccountNotFoundException(financialActivityAccountId); } } @Override - public FinancialActivityAccountData retrieveTemplate() { + public FinancialActivityAccountData addTemplateDetails(FinancialActivityAccountData financialActivityAccountData) { final Map> accountOptions = this.accountingDropdownReadPlatformService.retrieveAccountMappingOptions(); - return FinancialActivityAccountData.template(accountOptions); + financialActivityAccountData.setAccountingMappingOptions(accountOptions); + financialActivityAccountData.setFinancialActivityOptions(FINANCIAL_ACTIVITY.getAllFinancialActivities()); + return financialActivityAccountData; + } + + @Override + public FinancialActivityAccountData getFinancialActivityAccountTemplate() { + FinancialActivityAccountData financialActivityAccountData = new FinancialActivityAccountData(); + return addTemplateDetails(financialActivityAccountData); } private static final class FinancialActivityAccountMapper implements RowMapper { @@ -63,7 +74,7 @@ public class FinancialActivityAccountReadPlatformServiceImpl implements Financia public FinancialActivityAccountMapper() { StringBuilder sb = new StringBuilder(300); - sb.append(" faa.id , glaccount.id as glAccountId,glaccount.name as glAccountName,glaccount.gl_code as glCode "); + sb.append(" faa.id as id, faa.financial_activity_type as financialActivityId, glaccount.id as glAccountId,glaccount.name as glAccountName,glaccount.gl_code as glCode "); sb.append(" from acc_gl_financial_activity_account faa "); sb.append(" join acc_gl_account glaccount on glaccount.id = faa.gl_account_id"); sql = sb.toString(); @@ -77,15 +88,17 @@ public class FinancialActivityAccountReadPlatformServiceImpl implements Financia public FinancialActivityAccountData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = JdbcSupport.getLong(rs, "id"); final Long glAccountId = JdbcSupport.getLong(rs, "glAccountId"); + final Integer financialActivityId = JdbcSupport.getInteger(rs, "financialActivityId"); final String glAccountName = rs.getString("glAccountName"); final String glCode = rs.getString("glCode"); - final GLAccountData gLAccountData = new GLAccountData(glAccountId, glAccountName, glCode); + final GLAccountData glAccountData = new GLAccountData(glAccountId, glAccountName, glCode); + final FinancialActivityData financialActivityData = FINANCIAL_ACTIVITY.toFinancialActivityData(financialActivityId); - final FinancialActivityAccountData accountMappingData = FinancialActivityAccountData.instance(id, gLAccountData); - return accountMappingData; + final FinancialActivityAccountData financialActivityAccountData = new FinancialActivityAccountData(id, financialActivityData, + glAccountData); + return financialActivityAccountData; } - } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformService.java similarity index 79% rename from mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformService.java rename to mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformService.java index 2dfad021c..35afa8207 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/accountmapping/service/FinancialActivityAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformService.java @@ -3,14 +3,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.mifosplatform.accounting.accountmapping.service; +package org.mifosplatform.accounting.financialactivityaccount.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface FinancialActivityAccountWritePlatformService { - CommandProcessingResult createGLAccountActivityMapping(JsonCommand command); + CommandProcessingResult createFinancialActivityAccountMapping(JsonCommand command); CommandProcessingResult updateGLAccountActivityMapping(Long mappingId, JsonCommand command); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java new file mode 100644 index 000000000..b83f3674d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java @@ -0,0 +1,158 @@ +package org.mifosplatform.accounting.financialactivityaccount.service; + +import java.util.HashMap; +import java.util.Map; + +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; +import org.mifosplatform.accounting.financialactivityaccount.api.FinancialActivityAccountsJsonInputParams; +import org.mifosplatform.accounting.financialactivityaccount.domain.FinancialActivityAccount; +import org.mifosplatform.accounting.financialactivityaccount.domain.FinancialActivityAccountRepositoryWrapper; +import org.mifosplatform.accounting.financialactivityaccount.exception.DuplicateFinancialActivityAccountFoundException; +import org.mifosplatform.accounting.financialactivityaccount.exception.FinancialActivityAccountInvalidException; +import org.mifosplatform.accounting.financialactivityaccount.serialization.FinancialActivityAccountDataValidator; +import org.mifosplatform.accounting.glaccount.domain.GLAccount; +import org.mifosplatform.accounting.glaccount.domain.GLAccountRepositoryWrapper; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; +import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.stereotype.Service; + +@Service +public class FinancialActivityAccountWritePlatformServiceImpl implements FinancialActivityAccountWritePlatformService { + + private final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository; + private final FinancialActivityAccountDataValidator fromApiJsonDeserializer; + private final GLAccountRepositoryWrapper glAccountRepositoryWrapper; + private final static Logger logger = LoggerFactory.getLogger(FinancialActivityAccountWritePlatformServiceImpl.class); + + @Autowired + public FinancialActivityAccountWritePlatformServiceImpl( + final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository, + final FinancialActivityAccountDataValidator fromApiJsonDeserializer, final GLAccountRepositoryWrapper glAccountRepositoryWrapper) { + this.financialActivityAccountRepository = financialActivityAccountRepository; + this.fromApiJsonDeserializer = fromApiJsonDeserializer; + this.glAccountRepositoryWrapper = glAccountRepositoryWrapper; + } + + @Override + public CommandProcessingResult createFinancialActivityAccountMapping(JsonCommand command) { + try { + + this.fromApiJsonDeserializer.validateForCreate(command.json()); + + final Integer financialActivityId = command + .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); + final Long accountId = command.longValueOfParameterNamed(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue()); + final GLAccount glAccount = glAccountRepositoryWrapper.findOneWithNotFoundDetection(accountId); + FinancialActivityAccount financialActivityAccount = FinancialActivityAccount.createNew(glAccount, financialActivityId); + + validateFinancialActivityAndAccountMapping(financialActivityAccount); + this.financialActivityAccountRepository.save(financialActivityAccount); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(financialActivityAccount.getId()) // + .build(); + } catch (DataIntegrityViolationException dataIntegrityViolationException) { + handleFinancialActivityAccountDataIntegrityIssues(command, dataIntegrityViolationException); + return CommandProcessingResult.empty(); + } + } + + /** + * Validate that the GL Account is appropriate for the particular Financial + * Activity Type + **/ + private void validateFinancialActivityAndAccountMapping(FinancialActivityAccount financialActivityAccount) { + FINANCIAL_ACTIVITY financialActivity = FINANCIAL_ACTIVITY.fromInt(financialActivityAccount.getFinancialActivityType()); + GLAccount glAccount = financialActivityAccount.getGlAccount(); + if (!financialActivity.getMappedGLAccountType().getValue().equals(glAccount.getType())) { throw new FinancialActivityAccountInvalidException( + financialActivity, glAccount); } + } + + @Override + public CommandProcessingResult updateGLAccountActivityMapping(Long financialActivityAccountId, JsonCommand command) { + try { + this.fromApiJsonDeserializer.validateForUpdate(command.json()); + final FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository + .findOneWithNotFoundDetection(financialActivityAccountId); + Map changes = findChanges(command, financialActivityAccount); + + if (changes.containsKey(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue())) { + final Long accountId = command.longValueOfParameterNamed(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue()); + final GLAccount glAccount = glAccountRepositoryWrapper.findOneWithNotFoundDetection(accountId); + financialActivityAccount.updateGlAccount(glAccount); + } + + if (changes.containsKey(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue())) { + final Integer financialActivityId = command + .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); + financialActivityAccount.updateFinancialActivityType(financialActivityId); + } + + if (!changes.isEmpty()) { + validateFinancialActivityAndAccountMapping(financialActivityAccount); + this.financialActivityAccountRepository.save(financialActivityAccount); + } + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(financialActivityAccountId) // + .with(changes) // + .build(); + } catch (DataIntegrityViolationException dataIntegrityViolationException) { + handleFinancialActivityAccountDataIntegrityIssues(command, dataIntegrityViolationException); + return CommandProcessingResult.empty(); + } + } + + @Override + public CommandProcessingResult deleteGLAccountActivityMapping(Long financialActivityAccountId, JsonCommand command) { + final FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository + .findOneWithNotFoundDetection(financialActivityAccountId); + this.financialActivityAccountRepository.delete(financialActivityAccount); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(financialActivityAccountId) // + .build(); + } + + private void handleFinancialActivityAccountDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { + final Throwable realCause = dve.getMostSpecificCause(); + if (realCause.getMessage().contains("financial_activity_type")) { + final Integer financialActivityId = command + .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); + throw new DuplicateFinancialActivityAccountFoundException(financialActivityId); + } + + logger.error(dve.getMessage(), dve); + throw new PlatformDataIntegrityException("error.msg.glAccount.unknown.data.integrity.issue", + "Unknown data integrity issue with resource GL Account: " + realCause.getMessage()); + } + + public Map findChanges(JsonCommand command, FinancialActivityAccount financialActivityAccount) { + + Map changes = new HashMap(); + + Long existingGLAccountId = financialActivityAccount.getGlAccount().getId(); + Integer financialActivityType = financialActivityAccount.getFinancialActivityType(); + + // is the account Id changed? + if (command.isChangeInLongParameterNamed(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue(), existingGLAccountId)) { + final Long newValue = command.longValueOfParameterNamed(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue()); + changes.put(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue(), newValue); + } + + // is the financial Activity changed + if (command.isChangeInIntegerSansLocaleParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue(), + financialActivityType)) { + final Integer newValue = command + .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); + changes.put(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue(), newValue); + } + return changes; + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/api/GLAccountJsonInputParams.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/api/GLAccountJsonInputParams.java index 83d0c0b58..ced59a675 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/api/GLAccountJsonInputParams.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/api/GLAccountJsonInputParams.java @@ -9,7 +9,7 @@ import java.util.HashSet; import java.util.Set; /*** - * Enum of all parameters passed in while creating/updating a loan product + * Enum of all parameters passed in while creating/updating a GL Account ***/ public enum GLAccountJsonInputParams { ID("id"), NAME("name"), PARENT_ID("parentId"), GL_CODE("glCode"), DISABLED("disabled"), MANUAL_ENTRIES_ALLOWED("manualEntriesAllowed"), TYPE( diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccountingProcessorHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccountingProcessorHelper.java index 63b231f51..496ae3b6d 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccountingProcessorHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccountingProcessorHelper.java @@ -14,15 +14,14 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; -import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccount; -import org.mifosplatform.accounting.accountmapping.domain.FinancialActivityAccountRepository; -import org.mifosplatform.accounting.accountmapping.exception.FinancialActivityAccountNotFoundException; import org.mifosplatform.accounting.closure.domain.GLClosure; import org.mifosplatform.accounting.closure.domain.GLClosureRepository; import org.mifosplatform.accounting.common.AccountingConstants.ACCRUAL_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_SAVINGS; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTS; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; +import org.mifosplatform.accounting.financialactivityaccount.domain.FinancialActivityAccount; +import org.mifosplatform.accounting.financialactivityaccount.domain.FinancialActivityAccountRepositoryWrapper; import org.mifosplatform.accounting.glaccount.domain.GLAccount; import org.mifosplatform.accounting.journalentry.data.ChargePaymentDTO; import org.mifosplatform.accounting.journalentry.data.LoanDTO; @@ -61,7 +60,7 @@ public class AccountingProcessorHelper { public static final String SAVINGS_TRANSACTION_IDENTIFIER = "S"; private final JournalEntryRepository glJournalEntryRepository; private final ProductToGLAccountMappingRepository accountMappingRepository; - private final FinancialActivityAccountRepository officeToGLAccountMappingRepository; + private final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository; private final GLClosureRepository closureRepository; private final OfficeRepository officeRepository; private final LoanTransactionRepository loanTransactionRepository; @@ -73,7 +72,7 @@ public class AccountingProcessorHelper { final ProductToGLAccountMappingRepository accountMappingRepository, final GLClosureRepository closureRepository, final OfficeRepository officeRepository, final LoanTransactionRepository loanTransactionRepository, final SavingsAccountTransactionRepository savingsAccountTransactionRepository, - final FinancialActivityAccountRepository officeToGLAccountMappingRepository, + final FinancialActivityAccountRepositoryWrapper financialActivityAccountRepository, final AccountTransfersReadPlatformService accountTransfersReadPlatformService) { this.glJournalEntryRepository = glJournalEntryRepository; this.accountMappingRepository = accountMappingRepository; @@ -81,7 +80,7 @@ public class AccountingProcessorHelper { this.officeRepository = officeRepository; this.loanTransactionRepository = loanTransactionRepository; this.savingsAccountTransactionRepository = savingsAccountTransactionRepository; - this.officeToGLAccountMappingRepository = officeToGLAccountMappingRepository; + this.financialActivityAccountRepository = financialActivityAccountRepository; this.accountTransfersReadPlatformService = accountTransfersReadPlatformService; } @@ -350,9 +349,8 @@ public class AccountingProcessorHelper { private void createJournalEntriesForLoan(final Office office, final String currencyCode, final int accountTypeToDebitId, final int accountTypeToCreditId, final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount) { - final GLAccount debitAccount = getLinkedGLAccountForLoanProduct(loanProductId, accountTypeToDebitId, paymentTypeId, office.getId()); - final GLAccount creditAccount = getLinkedGLAccountForLoanProduct(loanProductId, accountTypeToCreditId, paymentTypeId, - office.getId()); + final GLAccount debitAccount = getLinkedGLAccountForLoanProduct(loanProductId, accountTypeToDebitId, paymentTypeId); + final GLAccount creditAccount = getLinkedGLAccountForLoanProduct(loanProductId, accountTypeToCreditId, paymentTypeId); createDebitJournalEntryForLoan(office, currencyCode, debitAccount, loanId, transactionId, transactionDate, amount); createCreditJournalEntryForLoan(office, currencyCode, creditAccount, loanId, transactionId, transactionDate, amount); } @@ -360,10 +358,8 @@ public class AccountingProcessorHelper { private void createJournalEntriesForSavings(final Office office, final String currencyCode, final int accountTypeToDebitId, final int accountTypeToCreditId, final Long savingsProductId, final Long paymentTypeId, final Long savingsId, final String transactionId, final Date transactionDate, final BigDecimal amount) { - final GLAccount debitAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToDebitId, paymentTypeId, - office.getId()); - final GLAccount creditAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToCreditId, paymentTypeId, - office.getId()); + final GLAccount debitAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToDebitId, paymentTypeId); + final GLAccount creditAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToCreditId, paymentTypeId); createDebitJournalEntryForSavings(office, currencyCode, debitAccount, savingsId, transactionId, transactionDate, amount); createCreditJournalEntryForSavings(office, currencyCode, creditAccount, savingsId, transactionId, transactionDate, amount); } @@ -371,7 +367,7 @@ public class AccountingProcessorHelper { public void createDebitJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final int accountMappingTypeId, final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { - final GLAccount account = getLinkedGLAccountForLoanProduct(loanProductId, accountMappingTypeId, paymentTypeId, office.getId()); + final GLAccount account = getLinkedGLAccountForLoanProduct(loanProductId, accountMappingTypeId, paymentTypeId); if (isReversal) { createCreditJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount); } else { @@ -463,7 +459,7 @@ public class AccountingProcessorHelper { final GLAccount chargeSpecificAccount = getLinkedGLAccountForSavingsCharges(savingsProductId, accountTypeToBeCredited.getValue(), chargePaymentDTO.getChargeId()); final GLAccount savingsControlAccount = getLinkedGLAccountForSavingsProduct(savingsProductId, accountTypeToBeDebited.getValue(), - paymentTypeId, office.getId()); + paymentTypeId); if (isReversal) { createDebitJournalEntryForSavings(office, currencyCode, chargeSpecificAccount, loanId, transactionId, transactionDate, totalAmount); @@ -488,7 +484,7 @@ public class AccountingProcessorHelper { private void createCreditJournalEntryOrReversalForLoan(final Office office, final String currencyCode, final int accountMappingTypeId, final Long loanProductId, final Long paymentTypeId, final Long loanId, final String transactionId, final Date transactionDate, final BigDecimal amount, final Boolean isReversal) { - final GLAccount account = getLinkedGLAccountForLoanProduct(loanProductId, accountMappingTypeId, paymentTypeId, office.getId()); + final GLAccount account = getLinkedGLAccountForLoanProduct(loanProductId, accountMappingTypeId, paymentTypeId); if (isReversal) { createDebitJournalEntryForLoan(office, currencyCode, account, loanId, transactionId, transactionDate, amount); } else { @@ -568,15 +564,12 @@ public class AccountingProcessorHelper { this.glJournalEntryRepository.saveAndFlush(journalEntry); } - private GLAccount getLinkedGLAccountForLoanProduct(final Long loanProductId, final int accountMappingTypeId, final Long paymentTypeId, - Long officeId) { + private GLAccount getLinkedGLAccountForLoanProduct(final Long loanProductId, final int accountMappingTypeId, final Long paymentTypeId) { GLAccount glAccount = null; if (isOrganizationAccount(accountMappingTypeId)) { - FinancialActivityAccount financialActivityAccount = this.officeToGLAccountMappingRepository - .findByFinancialActivityType(accountMappingTypeId); - if (financialActivityAccount == null) { throw new FinancialActivityAccountNotFoundException(officeId, - String.valueOf(accountMappingTypeId)); } - glAccount = financialActivityAccount.glAccount(); + FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository + .findByFinancialActivityTypeWithNotFoundDetection(accountMappingTypeId); + glAccount = financialActivityAccount.getGlAccount(); } else { ProductToGLAccountMapping accountMapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(loanProductId, PortfolioProductType.LOAN.getValue(), accountMappingTypeId); @@ -649,14 +642,12 @@ public class AccountingProcessorHelper { } private GLAccount getLinkedGLAccountForSavingsProduct(final Long savingsProductId, final int accountMappingTypeId, - final Long paymentTypeId, Long officeId) { + final Long paymentTypeId) { GLAccount glAccount = null; if (isOrganizationAccount(accountMappingTypeId)) { - FinancialActivityAccount financialActivityAccount = this.officeToGLAccountMappingRepository - .findByFinancialActivityType(accountMappingTypeId); - if (financialActivityAccount == null) { throw new FinancialActivityAccountNotFoundException(officeId, - String.valueOf(accountMappingTypeId)); } - glAccount = financialActivityAccount.glAccount(); + FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository + .findByFinancialActivityTypeWithNotFoundDetection(accountMappingTypeId); + glAccount = financialActivityAccount.getGlAccount(); } else { ProductToGLAccountMapping accountMapping = this.accountMappingRepository.findCoreProductToFinAccountMapping(savingsProductId, PortfolioProductType.SAVING.getValue(), accountMappingTypeId); @@ -680,7 +671,7 @@ public class AccountingProcessorHelper { private boolean isOrganizationAccount(final int accountMappingTypeId) { boolean isOrganizationAccount = false; - if (ORGANIZATION_ACCOUNTS.fromInt(accountMappingTypeId) != null) { + if (FINANCIAL_ACTIVITY.fromInt(accountMappingTypeId) != null) { isOrganizationAccount = true; } return isOrganizationAccount; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java index 6334a7db8..74e53f32d 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java @@ -11,7 +11,7 @@ import java.util.Date; import org.mifosplatform.accounting.closure.domain.GLClosure; import org.mifosplatform.accounting.common.AccountingConstants.ACCRUAL_ACCOUNTS_FOR_LOAN; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_LOAN; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTS; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; import org.mifosplatform.accounting.journalentry.data.LoanDTO; import org.mifosplatform.accounting.journalentry.data.LoanTransactionDTO; import org.mifosplatform.organisation.office.domain.Office; @@ -101,8 +101,8 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess // reversal) if (loanTransactionDTO.isAccountTransfer()) { this.helper.createAccrualBasedJournalEntriesAndReversalsForLoan(office, currencyCode, - ACCRUAL_ACCOUNTS_FOR_LOAN.LOAN_PORTFOLIO.getValue(), ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - loanProductId, paymentTypeId, loanId, transactionId, transactionDate, disbursalAmount, isReversed); + ACCRUAL_ACCOUNTS_FOR_LOAN.LOAN_PORTFOLIO.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), loanProductId, + paymentTypeId, loanId, transactionId, transactionDate, disbursalAmount, isReversed); } else { this.helper.createAccrualBasedJournalEntriesAndReversalsForLoan(office, currencyCode, ACCRUAL_ACCOUNTS_FOR_LOAN.LOAN_PORTFOLIO.getValue(), ACCRUAL_ACCOUNTS_FOR_LOAN.FUND_SOURCE.getValue(), loanProductId, @@ -217,7 +217,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess } else { if (loanTransactionDTO.isAccountTransfer()) { this.helper.createDebitJournalEntryOrReversalForLoan(office, currencyCode, - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), loanProductId, paymentTypeId, loanId, transactionId, + FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), loanProductId, paymentTypeId, loanId, transactionId, transactionDate, totalDebitAmount, isReversal); } else { this.helper.createDebitJournalEntryOrReversalForLoan(office, currencyCode, @@ -321,8 +321,8 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess if (loanTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForLoan(office, currencyCode, - CASH_ACCOUNTS_FOR_LOAN.OVERPAYMENT.getValue(), ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - loanProductId, paymentTypeId, loanId, transactionId, transactionDate, refundAmount, isReversal); + CASH_ACCOUNTS_FOR_LOAN.OVERPAYMENT.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), loanProductId, + paymentTypeId, loanId, transactionId, transactionDate, refundAmount, isReversal); } else { this.helper.createCashBasedJournalEntriesAndReversalsForLoan(office, currencyCode, CASH_ACCOUNTS_FOR_LOAN.OVERPAYMENT.getValue(), CASH_ACCOUNTS_FOR_LOAN.FUND_SOURCE.getValue(), loanProductId, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java index 023bda23a..ea0bbd18f 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java @@ -10,7 +10,7 @@ import java.util.Date; import org.mifosplatform.accounting.closure.domain.GLClosure; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_LOAN; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTS; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; import org.mifosplatform.accounting.journalentry.data.LoanDTO; import org.mifosplatform.accounting.journalentry.data.LoanTransactionDTO; import org.mifosplatform.organisation.office.domain.Office; @@ -111,8 +111,8 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId(); if (loanTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForLoan(office, currencyCode, - CASH_ACCOUNTS_FOR_LOAN.LOAN_PORTFOLIO.getValue(), ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - loanProductId, paymentTypeId, loanId, transactionId, transactionDate, disbursalAmount, isReversal); + CASH_ACCOUNTS_FOR_LOAN.LOAN_PORTFOLIO.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), loanProductId, + paymentTypeId, loanId, transactionId, transactionDate, disbursalAmount, isReversal); } else { this.helper.createCashBasedJournalEntriesAndReversalsForLoan(office, currencyCode, CASH_ACCOUNTS_FOR_LOAN.LOAN_PORTFOLIO.getValue(), CASH_ACCOUNTS_FOR_LOAN.FUND_SOURCE.getValue(), loanProductId, @@ -147,8 +147,8 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF if (loanTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForLoan(office, currencyCode, - CASH_ACCOUNTS_FOR_LOAN.OVERPAYMENT.getValue(), ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - loanProductId, paymentTypeId, loanId, transactionId, transactionDate, refundAmount, isReversal); + CASH_ACCOUNTS_FOR_LOAN.OVERPAYMENT.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), loanProductId, + paymentTypeId, loanId, transactionId, transactionDate, refundAmount, isReversal); } else { this.helper.createCashBasedJournalEntriesAndReversalsForLoan(office, currencyCode, CASH_ACCOUNTS_FOR_LOAN.OVERPAYMENT.getValue(), CASH_ACCOUNTS_FOR_LOAN.FUND_SOURCE.getValue(), loanProductId, @@ -218,9 +218,8 @@ public class CashBasedAccountingProcessorForLoan implements AccountingProcessorF /*** create a single debit entry (or reversal) for the entire amount **/ if (loanTransactionDTO.isAccountTransfer()) { - this.helper.createDebitJournalEntryOrReversalForLoan(office, currencyCode, - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), loanProductId, paymentTypeId, loanId, transactionId, - transactionDate, totalDebitAmount, isReversal); + this.helper.createDebitJournalEntryOrReversalForLoan(office, currencyCode, FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), + loanProductId, paymentTypeId, loanId, transactionId, transactionDate, totalDebitAmount, isReversal); } else { this.helper.createDebitJournalEntryOrReversalForLoan(office, currencyCode, CASH_ACCOUNTS_FOR_LOAN.FUND_SOURCE.getValue(), loanProductId, paymentTypeId, loanId, transactionId, transactionDate, totalDebitAmount, isReversal); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java index 4d7dffa82..1caacbf43 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/service/CashBasedAccountingProcessorForSavings.java @@ -11,7 +11,7 @@ import java.util.List; import org.mifosplatform.accounting.closure.domain.GLClosure; import org.mifosplatform.accounting.common.AccountingConstants.CASH_ACCOUNTS_FOR_SAVINGS; -import org.mifosplatform.accounting.common.AccountingConstants.ORGANIZATION_ACCOUNTS; +import org.mifosplatform.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY; import org.mifosplatform.accounting.journalentry.data.ChargePaymentDTO; import org.mifosplatform.accounting.journalentry.data.SavingsDTO; import org.mifosplatform.accounting.journalentry.data.SavingsTransactionDTO; @@ -52,13 +52,13 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess if (savingsTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, CASH_ACCOUNTS_FOR_SAVINGS.OVERDRAFT_PORTFOLIO_CONTROL.getValue(), - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), savingsProductId, paymentTypeId, savingsId, - transactionId, transactionDate, overdraftAmount, isReversal); + FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), savingsProductId, paymentTypeId, savingsId, transactionId, + transactionDate, overdraftAmount, isReversal); if (amount.subtract(overdraftAmount).compareTo(BigDecimal.ZERO) == 1) { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, - CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), savingsProductId, paymentTypeId, savingsId, - transactionId, transactionDate, amount.subtract(overdraftAmount), isReversal); + CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), + savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, + amount.subtract(overdraftAmount), isReversal); } } else { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, @@ -75,14 +75,14 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess } else if (savingsTransactionDTO.getTransactionType().isDeposit() && savingsTransactionDTO.isOverdraftTransaction()) { if (savingsTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), + FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), CASH_ACCOUNTS_FOR_SAVINGS.OVERDRAFT_PORTFOLIO_CONTROL.getValue(), savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, overdraftAmount, isReversal); if (amount.subtract(overdraftAmount).compareTo(BigDecimal.ZERO) == 1) { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), savingsProductId, paymentTypeId, savingsId, - transactionId, transactionDate, amount.subtract(overdraftAmount), isReversal); + FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), + savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, + amount.subtract(overdraftAmount), isReversal); } } else { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, @@ -102,9 +102,8 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess else if (savingsTransactionDTO.getTransactionType().isDeposit()) { if (savingsTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), - CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), savingsProductId, paymentTypeId, savingsId, - transactionId, transactionDate, amount, isReversal); + FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), + savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal); } else { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_REFERENCE.getValue(), CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), @@ -116,9 +115,8 @@ public class CashBasedAccountingProcessorForSavings implements AccountingProcess else if (savingsTransactionDTO.getTransactionType().isWithdrawal()) { if (savingsTransactionDTO.isAccountTransfer()) { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, - CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), - ORGANIZATION_ACCOUNTS.LIABILITY_TRANSFER_SUSPENSE.getValue(), savingsProductId, paymentTypeId, savingsId, - transactionId, transactionDate, amount, isReversal); + CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue(), + savingsProductId, paymentTypeId, savingsId, transactionId, transactionDate, amount, isReversal); } else { this.helper.createCashBasedJournalEntriesAndReversalsForSavings(office, currencyCode, CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_CONTROL.getValue(), CASH_ACCOUNTS_FOR_SAVINGS.SAVINGS_REFERENCE.getValue(), diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java index 9c03d4082..75bef8a76 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java @@ -834,8 +834,8 @@ public class CommandWrapper { // End - Deposit accounts - public boolean isOfficeToGLAccountMapping() { - return this.entityName.equalsIgnoreCase("OFFICEGLACCOUNT"); + public boolean isFinancialActivityAccountMapping() { + return this.entityName.equalsIgnoreCase("FINANCIALACTIVITYACCOUNT"); } public boolean isRegisterDatatable() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java index 78938f1f1..111337068 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -1960,7 +1960,7 @@ public class CommandWrapperBuilder { public CommandWrapperBuilder createOfficeToGLAccountMapping() { this.actionName = "CREATE"; - this.entityName = "OFFICEGLACCOUNT"; + this.entityName = "FINANCIALACTIVITYACCOUNT"; this.entityId = null; this.href = "/organizationglaccounts/template"; return this; @@ -1968,7 +1968,7 @@ public class CommandWrapperBuilder { public CommandWrapperBuilder updateOfficeToGLAccountMapping(final Long mappingId) { this.actionName = "UPDATE"; - this.entityName = "OFFICEGLACCOUNT"; + this.entityName = "FINANCIALACTIVITYACCOUNT"; this.entityId = mappingId; this.href = "/organizationglaccounts/" + mappingId; return this; @@ -1976,7 +1976,7 @@ public class CommandWrapperBuilder { public CommandWrapperBuilder deleteOfficeToGLAccountMapping(final Long mappingId) { this.actionName = "DELETE"; - this.entityName = "OFFICEGLACCOUNT"; + this.entityName = "FINANCIALACTIVITYACCOUNT"; this.entityId = mappingId; this.href = "/organizationglaccounts/" + mappingId; return this; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java index 8861c7738..547264c41 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java @@ -788,7 +788,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer throw new UnsupportedCommandException(wrapper.commandName()); } - } else if (wrapper.isOfficeToGLAccountMapping()) { + } else if (wrapper.isFinancialActivityAccountMapping()) { if (wrapper.isCreate()) { handler = this.applicationContext.getBean("createFinancialActivityAccountHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java index a7fc78066..75288993e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java @@ -32,7 +32,6 @@ import org.apache.commons.lang.StringUtils; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import org.joda.time.LocalDate; -import org.joda.time.Years; import org.joda.time.format.DateTimeFormatter; import org.mifosplatform.infrastructure.codes.domain.CodeValue; import org.mifosplatform.infrastructure.core.api.JsonCommand; @@ -475,7 +474,7 @@ public final class Client extends AbstractPersistable { this.activationDate = newValue.toDate(); this.officeJoiningDate = this.activationDate; } - + if (command.isChangeInLocalDateParameterNamed(ClientApiConstants.dateOfBirthParamName, dateOfBirthLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName); actualChanges.put(ClientApiConstants.dateOfBirthParamName, valueAsInput); @@ -786,8 +785,8 @@ public final class Client extends AbstractPersistable { public Date dateOfBirth() { return this.dateOfBirth; } - - public LocalDate dateOfBirthLocalDate(){ + + public LocalDate dateOfBirthLocalDate() { LocalDate dateOfBirth = null; if (this.dateOfBirth != null) { dateOfBirth = LocalDate.fromDateFields(this.dateOfBirth); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java index 3323d0678..40ecb4954 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java @@ -53,7 +53,6 @@ public class InterestRateChartSlabFields { @Column(name = "annual_interest_rate", scale = 6, precision = 19, nullable = false) private BigDecimal annualInterestRate; - @SuppressWarnings("unused") @Column(name = "currency_code", nullable = false) private String currencyCode;