MIFOSX-338: fix issue with failing to create an account with empty/null tagId value.
This commit is contained in:
+28
-26
@@ -70,40 +70,42 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
|
|||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
parentGLAccount = validateParentGLAccount(parentId);
|
parentGLAccount = validateParentGLAccount(parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeValue glAccountTagType = null;
|
CodeValue glAccountTagType = null;
|
||||||
Long tagId = command.longValueOfParameterNamed(GLAccountJsonInputParams.TAGID.getValue());
|
final Long tagId = command.longValueOfParameterNamed(GLAccountJsonInputParams.TAGID.getValue());
|
||||||
Long type = command.longValueOfParameterNamed(GLAccountJsonInputParams.TYPE.getValue());
|
final Long type = command.longValueOfParameterNamed(GLAccountJsonInputParams.TYPE.getValue());
|
||||||
GLAccountType accountType = GLAccountType.fromInt(type.intValue());
|
GLAccountType accountType = GLAccountType.fromInt(type.intValue());
|
||||||
if (accountType == null) {
|
if (accountType == null) {
|
||||||
// TODO:generate an appropriate exception type.
|
// TODO: Vishwas - should throw appropriate class that extends
|
||||||
throw new RuntimeException("Invalid GLAccount Type");
|
// 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);
|
final GLAccount glAccount = GLAccount.fromJson(parentGLAccount, command, glAccountTagType);
|
||||||
|
|
||||||
this.glAccountRepository.saveAndFlush(glAccount);
|
this.glAccountRepository.saveAndFlush(glAccount);
|
||||||
|
|
||||||
glAccount.generateHierarchy();
|
glAccount.generateHierarchy();
|
||||||
|
|
||||||
this.glAccountRepository.save(glAccount);
|
this.glAccountRepository.save(glAccount);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(glAccount.getId()).build();
|
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(glAccount.getId()).build();
|
||||||
|
|||||||
Reference in New Issue
Block a user