MIFOSX-338: fix issue with failing to create an account with empty/null tagId value.

This commit is contained in:
Keith Woodlock
2013-05-09 15:01:25 +01:00
parent f206f20eca
commit 9755b94a48
@@ -72,14 +72,16 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
} }
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
// AbstractPlatformResourceNotFoundException
throw new RuntimeException("Invalid GLAccount Type"); throw new RuntimeException("Invalid GLAccount Type");
} }
if (tagId != null) {
if (accountType.isAssetType()) { if (accountType.isAssetType()) {
glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection(
AccountingConstants.ASSESTS_TAG_OPTION_CODE_NAME, tagId); AccountingConstants.ASSESTS_TAG_OPTION_CODE_NAME, tagId);
@@ -96,7 +98,7 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount
glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection( glAccountTagType = this.codeValueRepositoryWrapper.findOneByCodeNameAndIdWithNotFoundDetection(
AccountingConstants.EXPENSES_TAG_OPTION_CODE_NAME, tagId); AccountingConstants.EXPENSES_TAG_OPTION_CODE_NAME, tagId);
} }
}
final GLAccount glAccount = GLAccount.fromJson(parentGLAccount, command, glAccountTagType); final GLAccount glAccount = GLAccount.fromJson(parentGLAccount, command, glAccountTagType);