From 9755b94a48c2b5b3061447830edf801ea0b8537d Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Thu, 9 May 2013 15:01:25 +0100 Subject: [PATCH] MIFOSX-338: fix issue with failing to create an account with empty/null tagId value. --- ...WritePlatformServiceJpaRepositoryImpl.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java index 6aee906b6..232c21139 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java @@ -70,40 +70,42 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount if (parentId != null) { parentGLAccount = validateParentGLAccount(parentId); } - + CodeValue glAccountTagType = null; - Long tagId = command.longValueOfParameterNamed(GLAccountJsonInputParams.TAGID.getValue()); - Long type = command.longValueOfParameterNamed(GLAccountJsonInputParams.TYPE.getValue()); + final Long tagId = command.longValueOfParameterNamed(GLAccountJsonInputParams.TAGID.getValue()); + final Long type = command.longValueOfParameterNamed(GLAccountJsonInputParams.TYPE.getValue()); GLAccountType accountType = GLAccountType.fromInt(type.intValue()); if (accountType == null) { - // TODO:generate an appropriate exception type. - throw new RuntimeException("Invalid GLAccount Type"); - } + // TODO: Vishwas - should throw appropriate class that extends + // AbstractPlatformResourceNotFoundException + throw new RuntimeException("Invalid GLAccount Type"); + } + + if (tagId != null) { + if (accountType.isAssetType()) { + glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( + AccountingConstants.ASSESTS_TAG_OPTION_CODE_NAME, tagId); + } else if (accountType.isLiabilityType()) { + glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( + AccountingConstants.LIABILITIES_TAG_OPTION_CODE_NAME, tagId); + } else if (accountType.isEquityType()) { + glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( + AccountingConstants.EQUITY_TAG_OPTION_CODE_NAME, tagId); + } else if (accountType.isIncomeType()) { + glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( + AccountingConstants.INCOME_TAG_OPTION_CODE_NAME, tagId); + } else if (accountType.isExpenseType()) { + glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( + AccountingConstants.EXPENSES_TAG_OPTION_CODE_NAME, tagId); + } + } - if (accountType.isAssetType()) { - glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( - AccountingConstants.ASSESTS_TAG_OPTION_CODE_NAME, tagId); - } else if (accountType.isLiabilityType()) { - glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( - AccountingConstants.LIABILITIES_TAG_OPTION_CODE_NAME, tagId); - } else if (accountType.isEquityType()) { - glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( - AccountingConstants.EQUITY_TAG_OPTION_CODE_NAME, tagId); - } else if (accountType.isIncomeType()) { - glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( - AccountingConstants.INCOME_TAG_OPTION_CODE_NAME, tagId); - } else if (accountType.isExpenseType()) { - glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( - AccountingConstants.EXPENSES_TAG_OPTION_CODE_NAME, tagId); - } - - final GLAccount glAccount = GLAccount.fromJson(parentGLAccount, command, glAccountTagType); this.glAccountRepository.saveAndFlush(glAccount); - + glAccount.generateHierarchy(); - + this.glAccountRepository.save(glAccount); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(glAccount.getId()).build();