FINERACT-1724: Loan product creation - duplicate short name fix

This commit is contained in:
abraham.menyhart
2023-06-27 13:30:02 +02:00
committed by Arnold Gálovics
parent 0109d24934
commit 573b4bb998
3 changed files with 89 additions and 2 deletions
@@ -328,7 +328,8 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException("error.msg.product.loan.duplicate.name",
"Loan product with name `" + name + "` already exists", "name", name, realCause);
} else if (realCause.getMessage().contains("'unq_short_name'")) {
} else if (realCause.getMessage().contains("'unq_short_name'") || containsDuplicateShortnameErrorForPostgreSQL(realCause)
|| containsDuplicateShortnameErrorForMySQL(realCause)) {
final String shortName = command.stringValueOfParameterNamed("shortName");
throw new PlatformDataIntegrityException("error.msg.product.loan.duplicate.short.name",
@@ -343,6 +344,14 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
"Unknown data integrity issue with resource.", realCause);
}
private static boolean containsDuplicateShortnameErrorForPostgreSQL(Throwable realCause) {
return realCause.getMessage().contains("m_product_loan_short_name_key");
}
private static boolean containsDuplicateShortnameErrorForMySQL(Throwable realCause) {
return (realCause.getMessage().contains("short_name") && realCause.getMessage().toLowerCase().contains("duplicate"));
}
private void validateInputDates(final JsonCommand command) {
final LocalDate startDate = command.localDateValueOfParameterNamed("startDate");
final LocalDate closeDate = command.localDateValueOfParameterNamed("closeDate");