From e7b216391463b0e99b4eb057c9ac9906da2be334 Mon Sep 17 00:00:00 2001 From: xurror Date: Fri, 31 Jul 2020 10:43:37 +0100 Subject: [PATCH] FINERACT-1098 - Catch JpaSystemException in jpa transactions --- ...WritePlatformServiceJpaRepositoryImpl.java | 11 +++++--- ...tivityAccountWritePlatformServiceImpl.java | 28 +++++++++++++------ ...WritePlatformServiceJpaRepositoryImpl.java | 16 +++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 16 +++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 7 +++-- ...WritePlatformServiceJpaRepositoryImpl.java | 16 +++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 28 +++++++++---------- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...mpaignWritePlatformCommandHandlerImpl.java | 12 ++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 22 +++++++++------ ...msCampaignWritePlatformServiceJpaImpl.java | 9 +++--- ...WritePlatformServiceJpaRepositoryImpl.java | 18 +++++++----- ...WritePlatformServiceJpaRepositoryImpl.java | 9 +++--- ...WritePlatformServiceJpaRepositoryImpl.java | 15 ++++++---- .../ReadWriteNonCoreDataServiceImpl.java | 9 +++--- .../ReportWritePlatformServiceImpl.java | 13 +++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- .../FineractEntityAccessWriteServiceImpl.java | 5 ++-- ...eRegistrationWritePlatformServiceImpl.java | 14 +++++----- ...WritePlatformServiceJpaRepositoryImpl.java | 7 +++-- ...ortMailingJobWritePlatformServiceImpl.java | 16 +++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 22 +++++++++------ .../service/WriteLikelihoodServiceImpl.java | 10 ++++--- ...xonomyMappingWritePlatformServiceImpl.java | 3 +- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 21 ++++++++++++-- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- .../TellerWritePlatformServiceJpaImpl.java | 13 +++++---- ...ngInstructionWritePlatformServiceImpl.java | 10 ++++--- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 25 ++++++++++------- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 11 ++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 15 ++++------ .../FloatingRateWritePlatformServiceImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 16 +++++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 9 +++--- .../domain/LoanAccountDomainServiceJpa.java | 7 +++-- ...ritePlatformServiceJpaRepositoryIImpl.java | 15 ++++++---- ...heduleRequestWritePlatformServiceImpl.java | 12 ++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 7 +++-- ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 17 +++++------ ...WritePlatformServiceJpaRepositoryImpl.java | 5 ++-- ...WritePlatformServiceJpaRepositoryImpl.java | 19 +++++++------ .../service/PaymentTypeWriteServiceImpl.java | 9 +++--- .../rate/service/RateWriteServiceImpl.java | 5 ++-- ...eRegistrationWritePlatformServiceImpl.java | 3 +- ...WritePlatformServiceJpaRepositoryImpl.java | 23 +++++++-------- ...WritePlatformServiceJpaRepositoryImpl.java | 11 ++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 3 +- ...WritePlatformServiceJpaRepositoryImpl.java | 11 ++++---- 55 files changed, 369 insertions(+), 259 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java index 9f6c7686a..d2960ac06 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/closure/service/GLClosureWritePlatformServiceJpaRepositoryImpl.java @@ -41,6 +41,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -91,8 +93,9 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId) .withEntityId(glClosure.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleGLClosureIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGLClosureIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -141,9 +144,9 @@ public class GLClosureWritePlatformServiceJpaRepositoryImpl implements GLClosure /** * @param command * @param dve + * @param dve */ - private void handleGLClosureIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleGLClosureIntegrityIssues(final JsonCommand command, final Throwable realCause, NonTransientDataAccessException dve) { if (realCause.getMessage().contains("office_id_closing_date")) { throw new GLClosureDuplicateException(command.longValueOfParameterNamed(GLClosureJsonInputParams.OFFICE_ID.getValue()), new LocalDate(command.dateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue()))); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java index e3ccb20b3..528bf8802 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/financialactivityaccount/service/FinancialActivityAccountWritePlatformServiceImpl.java @@ -39,6 +39,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -77,12 +79,11 @@ public class FinancialActivityAccountWritePlatformServiceImpl implements Financi .withCommandId(command.commandId()) // .withEntityId(financialActivityAccount.getId()) // .build(); - } catch (DataIntegrityViolationException dataIntegrityViolationException) { - handleFinancialActivityAccountDataIntegrityIssues(command, dataIntegrityViolationException.getMostSpecificCause(), - dataIntegrityViolationException); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + handleFinancialActivityAccountDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { - Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); + final Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); handleFinancialActivityAccountDataIntegrityIssues(command, throwable, ee); return CommandProcessingResult.empty(); } @@ -128,9 +129,8 @@ public class FinancialActivityAccountWritePlatformServiceImpl implements Financi .withEntityId(financialActivityAccountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dataIntegrityViolationException) { - handleFinancialActivityAccountDataIntegrityIssues(command, dataIntegrityViolationException.getMostSpecificCause(), - dataIntegrityViolationException); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + handleFinancialActivityAccountDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); @@ -151,7 +151,19 @@ public class FinancialActivityAccountWritePlatformServiceImpl implements Financi } private void handleFinancialActivityAccountDataIntegrityIssues(final JsonCommand command, final Throwable realCause, - final Exception dve) { + final NonTransientDataAccessException dve) { + if (realCause.getMessage().contains("financial_activity_type")) { + final Integer financialActivityId = command + .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); + throw new DuplicateFinancialActivityAccountFoundException(financialActivityId); + } + + LOG.error("Error occured.", dve); + throw new PlatformDataIntegrityException("error.msg.glAccount.unknown.data.integrity.issue", + "Unknown data integrity issue with resource GL Account: " + realCause.getMessage()); + } + + private void handleFinancialActivityAccountDataIntegrityIssues(JsonCommand command, Throwable realCause, PersistenceException dve) { if (realCause.getMessage().contains("financial_activity_type")) { final Integer financialActivityId = command .integerValueSansLocaleOfParameterNamed(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java index fd83c9d2c..37b46b73b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/glaccount/service/GLAccountWritePlatformServiceJpaRepositoryImpl.java @@ -50,7 +50,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.dao.NonTransientDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -108,8 +110,9 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount this.glAccountRepository.save(glAccount); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(glAccount.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleGLAccountDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGLAccountDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -169,8 +172,9 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(glAccount.getId()).with(changesOnly) .build(); - } catch (final DataIntegrityViolationException dve) { - handleGLAccountDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGLAccountDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -229,8 +233,8 @@ public class GLAccountWritePlatformServiceJpaRepositoryImpl implements GLAccount * @param command * @param dve */ - private void handleGLAccountDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleGLAccountDataIntegrityIssues(final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains("acc_gl_code")) { final String glCode = command.stringValueOfParameterNamed(GLAccountJsonInputParams.GL_CODE.getValue()); throw new GLAccountDuplicateException(glCode); diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java index 6700e4c16..3518f51b7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/JournalEntryWritePlatformServiceJpaRepositoryImpl.java @@ -81,6 +81,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -218,8 +220,9 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId) .withTransactionId(transactionId).build(); - } catch (final DataIntegrityViolationException dve) { - throw handleJournalEntryDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + throw handleJournalEntryDataIntegrityIssues(throwable, dve); } } @@ -657,8 +660,8 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa return transactionId; } - private PlatformDataIntegrityException handleJournalEntryDataIntegrityIssues(final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private PlatformDataIntegrityException handleJournalEntryDataIntegrityIssues(final Throwable realCause, + final NonTransientDataAccessException dve) { LOG.error("Error occured.", dve); return new PlatformDataIntegrityException("error.msg.glJournalEntry.unknown.data.integrity.issue", "Unknown data integrity issue with resource Journal Entry: " + realCause.getMessage()); @@ -712,8 +715,9 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId) .withTransactionId(transactionId).build(); - } catch (final DataIntegrityViolationException dve) { - throw handleJournalEntryDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + throw handleJournalEntryDataIntegrityIssues(throwable, dve); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java index d1e7f3fc5..b5c5ce002 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/provisioning/service/ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl.java @@ -63,6 +63,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -168,8 +169,8 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements createProvsioningEntry(currentDate, addJournalEntries); } catch (ProvisioningEntryAlreadyCreatedException peace) { LOG.error("Provisioning Entry already created", peace); - } catch (DataIntegrityViolationException dive) { - LOG.error("Problem occurred in generateLoanLossProvisioningAmount function", dive); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + LOG.error("Problem occurred in generateLoanLossProvisioningAmount function", dve); } } @@ -186,7 +187,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements } ProvisioningEntry requestedEntry = createProvsioningEntry(createdDate, addJournalEntries); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(requestedEntry.getId()).build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { return CommandProcessingResult.empty(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java index bb73a74dc..932af7cf5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/accounting/rule/service/AccountingRuleWritePlatformServiceJpaRepositoryImpl.java @@ -51,6 +51,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -83,8 +85,8 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco * @param command * @param dve */ - private void handleAccountingRuleIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleAccountingRuleIntegrityIssues(final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains("accounting_rule_name_unique")) { throw new AccountingRuleDuplicateException(command.stringValueOfParameterNamed(AccountingRuleJsonInputParams.NAME.getValue())); } else if (realCause.getMessage().contains("UNIQUE_ACCOUNT_RULE_TAGS")) { @@ -114,8 +116,9 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco this.accountingRuleRepository.saveAndFlush(accountingRule); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId) .withEntityId(accountingRule.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleAccountingRuleIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleAccountingRuleIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -280,8 +283,9 @@ public class AccountingRuleWritePlatformServiceJpaRepositoryImpl implements Acco return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(accountingRule.getId()) .with(changesOnly).build(); - } catch (final DataIntegrityViolationException dve) { - handleAccountingRuleIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleAccountingRuleIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/adhocquery/service/AdHocWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/adhocquery/service/AdHocWritePlatformServiceJpaRepositoryImpl.java index 33d39303a..d0a967ef0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/adhocquery/service/AdHocWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/adhocquery/service/AdHocWritePlatformServiceJpaRepositoryImpl.java @@ -31,6 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -64,8 +66,9 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla this.adHocRepository.save(entity); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .build(); @@ -75,9 +78,9 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { + private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { - final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("unq_name")) { final String name = command.stringValueOfParameterNamed("name"); @@ -85,15 +88,11 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla "AdHocQuery with name `" + name + "` already exists", "name", name); } - logAsErrorUnexpectedDataIntegrityException(dve); + LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.adhocquery.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } - private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) { - LOG.error("Error occured.", dve); - } - @Transactional @Override public CommandProcessingResult updateAdHocQuery(final Long adHocId, final JsonCommand command) { @@ -114,8 +113,9 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla .withEntityId(adHocId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .build(); @@ -137,7 +137,7 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla this.adHocRepository.delete(adHoc); return new CommandProcessingResultBuilder().withEntityId(adHocId).build(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); } @@ -158,7 +158,7 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla this.adHocRepository.save(adHoc); return new CommandProcessingResultBuilder().withEntityId(adHocId).build(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); } @@ -179,7 +179,7 @@ public class AdHocWritePlatformServiceJpaRepositoryImpl implements AdHocWritePla this.adHocRepository.save(adHoc); return new CommandProcessingResultBuilder().withEntityId(adHocId).build(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java index 1cea111a2..36ae1e3a5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/accountnumberformat/service/AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java @@ -35,6 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,7 +75,7 @@ public class AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements return new CommandProcessingResultBuilder() // .withEntityId(accountNumberFormat.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { @@ -114,7 +115,7 @@ public class AccountNumberFormatWritePlatformServiceJpaRepositoryImpl implements .withEntityId(accountNumberFormatId) // .with(actualChanges) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java index e5848c214..ef3183e76 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailCampaignWritePlatformCommandHandlerImpl.java @@ -94,6 +94,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -207,8 +209,9 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai .withEntityId(resourceId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } @@ -544,9 +547,8 @@ public class EmailCampaignWritePlatformCommandHandlerImpl implements EmailCampai } - private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, - final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { throw new PlatformDataIntegrityException("error.msg.email.campaign.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailWritePlatformServiceJpaRepositoryImpl.java index 9d8353a59..64c7e38f7 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailWritePlatformServiceJpaRepositoryImpl.java @@ -31,6 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -71,8 +73,9 @@ public class EmailWritePlatformServiceJpaRepositoryImpl implements EmailWritePla .withCommandId(command.commandId()) // .withEntityId(message.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -95,8 +98,9 @@ public class EmailWritePlatformServiceJpaRepositoryImpl implements EmailWritePla .withEntityId(resourceId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -109,8 +113,9 @@ public class EmailWritePlatformServiceJpaRepositoryImpl implements EmailWritePla final EmailMessage message = this.assembler.assembleFromResourceId(resourceId); this.repository.delete(message); this.repository.flush(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(null, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(null, throwable, dve); return CommandProcessingResult.empty(); } return new CommandProcessingResultBuilder().withEntityId(resourceId).build(); @@ -119,9 +124,8 @@ public class EmailWritePlatformServiceJpaRepositoryImpl implements EmailWritePla /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, - final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains("email_address")) { throw new PlatformDataIntegrityException("error.msg.email.no.email.address.exists", diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java index c215ce721..c83760ef0 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java @@ -89,6 +89,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -185,8 +186,9 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP .withEntityId(resourceId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable); return CommandProcessingResult.empty(); } @@ -670,8 +672,7 @@ public class SmsCampaignWritePlatformServiceJpaImpl implements SmsCampaignWriteP } } - private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause) { throw new PlatformDataIntegrityException("error.msg.sms.campaign.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java index 2cd959153..20887d85b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueWritePlatformServiceJpaRepositoryImpl.java @@ -36,6 +36,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -81,8 +83,9 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue .withEntityId(code.getId()) // .withSubEntityId(codeValue.getId())// .build(); - } catch (final DataIntegrityViolationException dve) { - handleCodeValueDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleCodeValueDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .build(); @@ -92,8 +95,8 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleCodeValueDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleCodeValueDataIntegrityIssues(final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains("code_value")) { final String name = command.stringValueOfParameterNamed("name"); throw new PlatformDataIntegrityException("error.msg.code.value.duplicate.label", @@ -127,8 +130,9 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue .withEntityId(codeValueId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleCodeValueDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleCodeValueDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .build(); @@ -157,7 +161,7 @@ public class CodeValueWritePlatformServiceJpaRepositoryImpl implements CodeValue .withEntityId(codeId) // .withSubEntityId(codeValueId)// .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { LOG.error("Error occured.", dve); final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("code_value")) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java index a798a3dd7..79d3f5464 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java @@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -70,7 +71,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf this.codeRepository.save(code); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(code.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleCodeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { @@ -102,7 +103,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf .withEntityId(codeId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleCodeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { @@ -127,9 +128,9 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf try { this.codeRepository.delete(code); this.codeRepository.flush(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", - "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); + "Unknown data integrity issue with resource: " + dve.getMostSpecificCause(), dve); } return new CommandProcessingResultBuilder().withEntityId(codeId).build(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java index b63203c5a..dc825c079 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/configuration/service/GlobalConfigurationWritePlatformServiceJpaRepositoryImpl.java @@ -32,6 +32,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -76,8 +78,9 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(configId).with(changes).build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(throwable, dve); return CommandProcessingResult.empty(); } @@ -89,8 +92,9 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements try { final GlobalConfigurationProperty ppi = GlobalConfigurationProperty.newSurveyConfiguration(name); this.repository.save(ppi); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(throwable, dve); } } @@ -98,9 +102,8 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleDataIntegrityIssues(final DataIntegrityViolationException dve) { + private void handleDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) { - final Throwable realCause = dve.getMostSpecificCause(); LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.globalConfiguration.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java index f708f8209..39fff013f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java @@ -80,6 +80,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -265,7 +266,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ .update("insert into c_configuration (name, value, enabled ) values( :dataTableName , '0','0')", paramMap); } - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { final Throwable cause = dve.getCause(); final Throwable realCause = dve.getMostSpecificCause(); // even if duplicate is only due to permission duplicate, okay to @@ -624,7 +625,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ registerDatatable(datatableName, apptableName); registerColumnCodeMapping(codeMappings); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("datatable"); @@ -1022,7 +1023,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ } } } - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("datatable"); @@ -1078,7 +1079,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ final String sql = "DROP TABLE `" + datatableName + "`"; sqlArray[0] = sql; this.jdbcTemplate.batchUpdate(sqlArray); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("datatable"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java index 61f7e8d9e..8794b585c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/ReportWritePlatformServiceImpl.java @@ -47,6 +47,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -99,7 +100,7 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic .withCommandId(command.commandId()) // .withEntityId(report.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleReportDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -139,12 +140,12 @@ public class ReportWritePlatformServiceImpl implements ReportWritePlatformServic .withEntityId(report.getId()) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleReportDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); + } catch (final JpaSystemException | DataIntegrityViolationException e) { + handleReportDataIntegrityIssues(command, e.getMostSpecificCause(), e); return CommandProcessingResult.empty(); - } catch (final PersistenceException dve) { - Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); - handleReportDataIntegrityIssues(command, throwable, dve); + } catch (final PersistenceException e) { + Throwable throwable = ExceptionUtils.getRootCause(e.getCause()); + handleReportDataIntegrityIssues(command, throwable, e); return CommandProcessingResult.empty(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java index cf4ebc812..b2c7f058d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -79,7 +80,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr this.documentRepository.save(document); return document.getId(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", "Unknown data integrity issue with resource.", dve); @@ -133,7 +134,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr this.documentRepository.saveAndFlush(documentForUpdate); return new CommandProcessingResult(documentForUpdate.getId()); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", "Unknown data integrity issue with resource.", dve); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java index 849c4ce7d..f6dcce03a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/entityaccess/service/FineractEntityAccessWriteServiceImpl.java @@ -41,6 +41,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -109,7 +110,7 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces this.fineractEntityToEntityMappingRepository.save(newMap); return new CommandProcessingResultBuilder().withEntityId(newMap.getId()).withCommandId(command.commandId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -142,7 +143,7 @@ public class FineractEntityAccessWriteServiceImpl implements FineractEntityAcces } return new CommandProcessingResultBuilder(). // withEntityId(mapForUpdate.getId()).withCommandId(command.commandId()).build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java index 569e42f81..57c61be33 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/gcm/service/DeviceRegistrationWritePlatformServiceImpl.java @@ -30,6 +30,7 @@ import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper; import org.apache.openjpa.persistence.EntityExistsException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -58,25 +59,24 @@ public class DeviceRegistrationWritePlatformServiceImpl implements DeviceRegistr this.deviceRegistrationRepository.save(deviceRegistration); return deviceRegistration; } catch (final EntityExistsException dve) { - handleDataIntegrityIssues(registrationId, dve, dve); + handleDataIntegrityIssues(registrationId, dve); return null; - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(registrationId, dve.getMostSpecificCause(), dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + handleDataIntegrityIssues(registrationId, dve.getMostSpecificCause()); return null; } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); - handleDataIntegrityIssues(registrationId, throwable, dve); + handleDataIntegrityIssues(registrationId, throwable); return null; } catch (final Exception dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); - handleDataIntegrityIssues(registrationId, throwable, dve); + handleDataIntegrityIssues(registrationId, throwable); return null; } } - private void handleDataIntegrityIssues(final String registrationId, final Throwable realCause, - @SuppressWarnings("unused") final Exception dve) { + private void handleDataIntegrityIssues(final String registrationId, final Throwable realCause) { if (realCause.getMessage().contains("registration_key")) { throw new PlatformDataIntegrityException("error.msg.duplicate.device.registration.id", diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java index fb03fa80b..94df98760 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/hooks/service/HookWritePlatformServiceJpaRepositoryImpl.java @@ -64,6 +64,7 @@ import org.apache.fineract.template.exception.TemplateNotFoundException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import retrofit.RetrofitError; @@ -118,7 +119,7 @@ public class HookWritePlatformServiceJpaRepositoryImpl implements HookWritePlatf this.hookRepository.save(hook); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(hook.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleHookDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -179,7 +180,7 @@ public class HookWritePlatformServiceJpaRepositoryImpl implements HookWritePlatf .withEntityId(hookId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleHookDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -198,7 +199,7 @@ public class HookWritePlatformServiceJpaRepositoryImpl implements HookWritePlatf final Hook hook = retrieveHookBy(hookId); try { this.hookRepository.delete(hook); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java index 7a343edc4..081fe7802 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/reportmailingjob/service/ReportMailingJobWritePlatformServiceImpl.java @@ -68,6 +68,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -127,8 +129,9 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo return new CommandProcessingResultBuilder().withCommandId(jsonCommand.commandId()).withEntityId(reportMailingJob.getId()) .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(jsonCommand, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(jsonCommand, throwable, dve); return CommandProcessingResult.empty(); } @@ -217,8 +220,9 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo return new CommandProcessingResultBuilder().withCommandId(jsonCommand.commandId()).withEntityId(reportMailingJob.getId()) .with(changes).build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(jsonCommand, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(jsonCommand, throwable, dve); return CommandProcessingResult.empty(); } @@ -407,8 +411,8 @@ public class ReportMailingJobWritePlatformServiceImpl implements ReportMailingJo * -- data integrity exception object * **/ - private void handleDataIntegrityIssues(final JsonCommand jsonCommand, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleDataIntegrityIssues(final JsonCommand jsonCommand, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains(ReportMailingJobConstants.NAME_PARAM_NAME)) { final String name = jsonCommand.stringValueOfParameterNamed(ReportMailingJobConstants.NAME_PARAM_NAME); diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsWritePlatformServiceJpaRepositoryImpl.java index 28feed30c..8039d3f1f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/sms/service/SmsWritePlatformServiceJpaRepositoryImpl.java @@ -31,6 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -71,8 +73,9 @@ public class SmsWritePlatformServiceJpaRepositoryImpl implements SmsWritePlatfor .withCommandId(command.commandId()) // .withEntityId(message.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -95,8 +98,9 @@ public class SmsWritePlatformServiceJpaRepositoryImpl implements SmsWritePlatfor .withEntityId(resourceId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } @@ -109,8 +113,9 @@ public class SmsWritePlatformServiceJpaRepositoryImpl implements SmsWritePlatfor final SmsMessage message = this.assembler.assembleFromResourceId(resourceId); this.repository.delete(message); this.repository.flush(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(null, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(null, throwable, dve); return CommandProcessingResult.empty(); } return new CommandProcessingResultBuilder().withEntityId(resourceId).build(); @@ -119,9 +124,8 @@ public class SmsWritePlatformServiceJpaRepositoryImpl implements SmsWritePlatfor /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, - final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleDataIntegrityIssues(@SuppressWarnings("unused") final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains("mobile_no")) { throw new PlatformDataIntegrityException("error.msg.sms.no.mobile.no.exists", diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/WriteLikelihoodServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/WriteLikelihoodServiceImpl.java index 92bf879fe..a9cb54d40 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/WriteLikelihoodServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/survey/service/WriteLikelihoodServiceImpl.java @@ -31,6 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; /** @@ -81,8 +83,9 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService { return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(likelihood.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(throwable, dve); return CommandProcessingResult.empty(); } @@ -91,9 +94,8 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService { /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleDataIntegrityIssues(final DataIntegrityViolationException dve) { + private void handleDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) { - final Throwable realCause = dve.getMostSpecificCause(); LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.likelihood.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + realCause.getMessage()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/mix/service/MixTaxonomyMappingWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/mix/service/MixTaxonomyMappingWritePlatformServiceImpl.java index 5ff512698..ea2bd143a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/mix/service/MixTaxonomyMappingWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/mix/service/MixTaxonomyMappingWritePlatformServiceImpl.java @@ -25,6 +25,7 @@ import org.apache.fineract.mix.domain.MixTaxonomyMapping; import org.apache.fineract.mix.domain.MixTaxonomyMappingRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,7 +54,7 @@ public class MixTaxonomyMappingWritePlatformServiceImpl implements MixTaxonomyMa return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(mapping.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { return CommandProcessingResult.empty(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java index 82bf9c281..ebe274d78 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java @@ -48,6 +48,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -93,7 +94,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit this.holidayRepository.save(holiday); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(holiday.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -127,7 +128,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit this.holidayRepository.saveAndFlush(holiday); return new CommandProcessingResultBuilder().withEntityId(holiday.getId()).with(changes).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java index c0642a6dc..cb964a924 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java @@ -45,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Caching; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -110,7 +111,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP .withEntityId(office.getId()) // .withOfficeId(office.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleOfficeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -159,7 +160,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP .withOfficeId(office.getId()) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleOfficeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl.java index 3f5b791b7..f9a65ae73 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl.java @@ -35,7 +35,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -64,7 +66,7 @@ public class ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl implement this.provisioningCategoryRepository.save(provisioningCategory); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(provisioningCategory.getId()) .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -99,7 +101,7 @@ public class ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl implement this.provisioningCategoryRepository.save(provisioningCategoryForUpdate); } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(categoryId).with(changes).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -118,7 +120,20 @@ public class ProvisioningCategoryWritePlatformServiceJpaRepositoryImpl implement /* * Guaranteed to throw an exception no matter what the data integrity issue is. */ - private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final Exception dve) { + private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { + + if (realCause.getMessage().contains("category_name")) { + final String name = command.stringValueOfParameterNamed("category_name"); + throw new PlatformDataIntegrityException("error.msg.provisioning.duplicate.categoryname", + "Provisioning Cateory with name `" + name + "` already exists", "category name", name); + } + LOG.error("Error occured.", dve); + throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue", + "Unknown data integrity issue with resource: " + realCause.getMessage()); + } + + private void handleDataIntegrityIssues(final JsonCommand command, final Throwable realCause, final PersistenceException dve) { if (realCause.getMessage().contains("category_name")) { final String name = command.stringValueOfParameterNamed("category_name"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java index 64e7db189..62e43462b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/service/ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java @@ -48,6 +48,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -85,7 +86,7 @@ public class ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl implement this.provisioningCriteriaRepository.save(provisioningCriteria); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(provisioningCriteria.getId()) .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -121,7 +122,7 @@ public class ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl implement } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(provisioningCriteria.getId()) .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java index 9c973b9bd..e349a1cd8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,7 +75,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla .withCommandId(command.commandId()) // .withEntityId(staff.getId()).withOfficeId(officeId) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleStaffDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -106,7 +107,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(staffId) .withOfficeId(staffForUpdate.officeId()).with(changesOnly).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleStaffDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java index 2f0a08236..259ee4bb9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/teller/service/TellerWritePlatformServiceJpaImpl.java @@ -57,6 +57,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -119,7 +120,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer .withEntityId(teller.getId()) // .withOfficeId(teller.getOffice().getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleTellerDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -154,7 +155,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer .withOfficeId(teller.officeId()) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleTellerDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -265,7 +266,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer .withEntityId(teller.getId()) // .withSubEntityId(cashier.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleTellerDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -304,7 +305,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer .withSubEntityId(cashier.getId()) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleTellerDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -329,7 +330,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer final Cashier cashier = validateUserPriviledgeOnCashierAndRetrieve(currentUser, tellerId, cashierId); this.cashierRepository.delete(cashier); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleTellerDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -463,7 +464,7 @@ public class TellerWritePlatformServiceJpaImpl implements TellerWritePlatformSer .withEntityId(cashier.getId()) // .withSubEntityId(cashierTxn.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleTellerDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java index b43f1b10a..e815aec78 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java @@ -64,7 +64,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -129,8 +131,9 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst standingInstructionId = standingInstruction.accountTransferStandingInstruction().getId(); } - } catch (final DataIntegrityViolationException dve) { - handleDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } final CommandProcessingResultBuilder builder = new CommandProcessingResultBuilder().withEntityId(standingInstructionId) @@ -138,9 +141,8 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst return builder.build(); } - private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { + private void handleDataIntegrityIssues(final JsonCommand command, Throwable realCause, final NonTransientDataAccessException dve) { - final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("name")) { final String name = command.stringValueOfParameterNamed(StandingInstructionApiConstants.nameParamName); throw new PlatformDataIntegrityException("error.msg.standinginstruction.duplicate.name", diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java index 1f950c593..e78cb8ff9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java @@ -50,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -116,7 +117,7 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP FineractEntityAccessType.OFFICE_ACCESS_TO_CHARGES, charge.getId()); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(charge.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -189,7 +190,7 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(chargeId).with(changes).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientChargeWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientChargeWritePlatformServiceJpaRepositoryImpl.java index 065d688ab..7cfdc1f5d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientChargeWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientChargeWritePlatformServiceJpaRepositoryImpl.java @@ -60,6 +60,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -140,8 +142,9 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client .withOfficeId(clientCharge.getClient().getOffice().getId()) // .withClientId(clientCharge.getClient().getId()) // .build(); - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(clientId, null, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(clientId, null, throwable, dve); return CommandProcessingResult.empty(); } } @@ -187,8 +190,9 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client .withEntityId(clientCharge.getId()) // .withOfficeId(clientCharge.getClient().getOffice().getId()) // .withClientId(clientCharge.getClient().getId()).build(); - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(clientId, clientChargeId, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(clientId, clientChargeId, throwable, dve); return CommandProcessingResult.empty(); } @@ -226,8 +230,9 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client .withOfficeId(clientCharge.getClient().getOffice().getId()) // .withClientId(clientCharge.getClient().getId()) // .build(); - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(clientId, clientChargeId, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(clientId, clientChargeId, throwable, dve); return CommandProcessingResult.empty(); } } @@ -249,8 +254,9 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client .withOfficeId(clientCharge.getClient().getOffice().getId()) // .withClientId(clientCharge.getClient().getId()) // .build(); - } catch (DataIntegrityViolationException dve) { - handleDataIntegrityIssues(clientId, clientChargeId, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleDataIntegrityIssues(clientId, clientChargeId, throwable, dve); return CommandProcessingResult.empty(); } } @@ -440,9 +446,8 @@ public class ClientChargeWritePlatformServiceJpaRepositoryImpl implements Client } private void handleDataIntegrityIssues(@SuppressWarnings("unused") final Long clientId, final Long clientChargeId, - final DataIntegrityViolationException dve) { + final Throwable realCause, final NonTransientDataAccessException dve) { - final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("FK_m_client_charge_paid_by_m_client_charge")) { throw new PlatformDataIntegrityException("error.msg.client.charge.cannot.be.deleted", diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java index a709ad83a..5ab1f56ad 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientIdentifierWritePlatformServiceJpaRepositoryImpl.java @@ -41,6 +41,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -97,7 +98,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl .withClientId(clientId) // .withEntityId(clientIdentifier.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -161,7 +162,7 @@ public class ClientIdentifierWritePlatformServiceJpaRepositoryImpl implements Cl .withEntityId(identifierId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve.getMostSpecificCause(), dve); return new CommandProcessingResult(Long.valueOf(-1)); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 8b3e14454..76dd93526 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -90,6 +90,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -187,7 +188,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP .withClientId(clientId) // .withEntityId(clientId) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); LOG.error("Error occured.", throwable); throw new PlatformDataIntegrityException("error.msg.client.unknown.data.integrity.issue", @@ -353,7 +354,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP .setRollbackTransaction(rollbackTransaction)// .setRollbackTransaction(result.isRollbackTransaction())// .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -565,7 +566,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP .withEntityId(clientId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -603,7 +604,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP .withSavingsId(result.getSavingsId())// .setRollbackTransaction(result.isRollbackTransaction())// .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -758,7 +759,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP .withClientId(clientId) // .withEntityId(clientId) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralWritePlatformServiceJpaRepositoryImpl.java index 6db49c30b..04817049f 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/collateral/service/CollateralWritePlatformServiceJpaRepositoryImpl.java @@ -45,6 +45,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -100,7 +102,7 @@ public class CollateralWritePlatformServiceJpaRepositoryImpl implements Collater .withLoanId(loan.getId())// .withEntityId(collateral.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleCollateralDataIntegrityViolation(dve); return CommandProcessingResult.empty(); } @@ -149,7 +151,7 @@ public class CollateralWritePlatformServiceJpaRepositoryImpl implements Collater .withEntityId(collateralId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleCollateralDataIntegrityViolation(dve); return new CommandProcessingResult(Long.valueOf(-1)); } @@ -176,14 +178,9 @@ public class CollateralWritePlatformServiceJpaRepositoryImpl implements Collater return new CommandProcessingResultBuilder().withCommandId(commandId).withLoanId(loanId).withEntityId(collateralId).build(); } - private void handleCollateralDataIntegrityViolation(final DataIntegrityViolationException dve) { - logAsErrorUnexpectedDataIntegrityException(dve); + private void handleCollateralDataIntegrityViolation(final NonTransientDataAccessException dve) { + LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.collateral.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } - - private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) { - LOG.error("Error occured.", dve); - } - } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRateWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRateWritePlatformServiceImpl.java index 40aa99fed..7413c411e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRateWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/floatingrates/service/FloatingRateWritePlatformServiceImpl.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -65,7 +66,7 @@ public class FloatingRateWritePlatformServiceImpl implements FloatingRateWritePl .withCommandId(command.commandId()) // .withEntityId(newFloatingRate.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -93,7 +94,7 @@ public class FloatingRateWritePlatformServiceImpl implements FloatingRateWritePl .withEntityId(command.entityId()) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java index f4786c794..323ca5dc9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -70,7 +71,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf this.fundRepository.save(fund); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(fund.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleFundDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -98,7 +99,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(fund.getId()).with(changes).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleFundDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java index 8c2cedc1b..956a5e8cf 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java @@ -39,6 +39,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -88,15 +90,16 @@ public class GroupRolesWritePlatformServiceJpaRepositoryImpl implements GroupRol return new CommandProcessingResultBuilder().withClientId(client.getId()).withGroupId(group.getId()) .withEntityId(groupRole.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleGroupDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGroupDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } } - private void handleGroupDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleGroupDataIntegrityIssues(final JsonCommand command, final Throwable realCause, + final NonTransientDataAccessException dve) { if (realCause.getMessage().contains("UNIQUE_GROUP_ROLES")) { final String clientId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.clientIdParamName); @@ -150,8 +153,9 @@ public class GroupRolesWritePlatformServiceJpaRepositoryImpl implements GroupRol this.groupRoleRepository.saveAndFlush(groupRole); return new CommandProcessingResultBuilder().with(actualChanges).withGroupId(group.getId()).withEntityId(groupRole.getId()) .build(); - } catch (final DataIntegrityViolationException dve) { - handleGroupDataIntegrityIssues(command, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGroupDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java index 8134e5c4a..c6e5ae418 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java @@ -88,6 +88,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -250,7 +251,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group .setRollbackTransaction(rollbackTransaction)// .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleGroupDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, groupingType); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -340,7 +341,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group .withGroupId(groupId) // .withEntityId(groupId) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleGroupDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, GroupTypes.GROUP); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -478,7 +479,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group .with(actualChanges) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleGroupDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, groupingType); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -600,7 +601,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group .withGroupId(groupForDelete.officeId()) // .withEntityId(groupForDelete.getId()) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); LOG.error("Error occured.", throwable); throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue", diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java index 8eaa64c51..9767c7683 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java @@ -76,6 +76,7 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -232,7 +233,7 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { private void saveLoanTransactionWithDataIntegrityViolationChecks(LoanTransaction newRepaymentTransaction) { try { this.loanTransactionRepository.save(newRepaymentTransaction); - } catch (DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction"); @@ -256,7 +257,7 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { } } this.loanRepositoryWrapper.saveAndFlush(loan); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction"); @@ -280,7 +281,7 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService { } } this.loanRepositoryWrapper.save(loan); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java index d1572d355..f0cbdb9ec 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java @@ -58,6 +58,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -174,8 +176,9 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto this.guarantorRepository.save(guarantor); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(guarantor.getOfficeId()) .withEntityId(guarantor.getId()).withLoanId(loan.getId()).build(); - } catch (final DataIntegrityViolationException dve) { - handleGuarantorDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGuarantorDataIntegrityIssues(throwable, dve); return CommandProcessingResult.empty(); } } @@ -244,8 +247,9 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(guarantorForUpdate.getOfficeId()) .withEntityId(guarantorForUpdate.getId()).withOfficeId(guarantorForUpdate.getLoanId()).with(changesOnly).build(); - } catch (final DataIntegrityViolationException dve) { - handleGuarantorDataIntegrityIssues(dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleGuarantorDataIntegrityIssues(throwable, dve); return CommandProcessingResult.empty(); } } @@ -343,8 +347,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto } } - private void handleGuarantorDataIntegrityIssues(final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleGuarantorDataIntegrityIssues(final Throwable realCause, final NonTransientDataAccessException dve) { LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.guarantor.unknown.data.integrity.issue", "Unknown data integrity issue with resource Guarantor: " + realCause.getMessage()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/service/LoanRescheduleRequestWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/service/LoanRescheduleRequestWritePlatformServiceImpl.java index bba3f3589..c7aa49fc9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/service/LoanRescheduleRequestWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/rescheduleloan/service/LoanRescheduleRequestWritePlatformServiceImpl.java @@ -86,6 +86,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -286,7 +288,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche .withGroupId(loan.getGroupId()).build(); } - catch (final DataIntegrityViolationException dve) { + catch (final JpaSystemException | DataIntegrityViolationException dve) { // handle the data integrity violation handleDataIntegrityViolation(dve); @@ -489,7 +491,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche .withOfficeId(loan.getOfficeId()).withGroupId(loan.getGroupId()).build(); } - catch (final DataIntegrityViolationException dve) { + catch (final JpaSystemException | DataIntegrityViolationException dve) { // handle the data integrity violation handleDataIntegrityViolation(dve); @@ -507,7 +509,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche } } this.loanRepositoryWrapper.saveAndFlush(loan); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction"); @@ -571,7 +573,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche .withGroupId(loanRescheduleRequest.getLoan().getGroupId()).build(); } - catch (final DataIntegrityViolationException dve) { + catch (final JpaSystemException | DataIntegrityViolationException dve) { // handle the data integrity violation handleDataIntegrityViolation(dve); @@ -587,7 +589,7 @@ public class LoanRescheduleRequestWritePlatformServiceImpl implements LoanResche * data integrity violation exception * **/ - private void handleDataIntegrityViolation(final DataIntegrityViolationException dve) { + private void handleDataIntegrityViolation(final NonTransientDataAccessException dve) { LOG.error("Error occured.", dve); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java index e3fa01dce..c903459cc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java @@ -142,6 +142,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -583,7 +584,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa .withClientId(newLoanApplication.getClientId()) // .withGroupId(newLoanApplication.getGroupId()) // .withLoanId(newLoanApplication.getId()).withGlimId(newLoanApplication.getGlimId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -1210,7 +1211,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa .withGroupId(existingLoanApplication.getGroupId()) // .withLoanId(existingLoanApplication.getId()) // .with(changes).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -1685,7 +1686,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa } } this.loanRepositoryWrapper.saveAndFlush(loan); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.application"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index f394ee9c4..ada821e75 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -190,6 +190,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -593,7 +594,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf } } this.loanRepositoryWrapper.saveAndFlush(loan); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction"); @@ -616,7 +617,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf } } this.loanRepositoryWrapper.save(loan); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { final Throwable realCause = e.getCause(); final List dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/productmix/service/ProductMixWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/productmix/service/ProductMixWritePlatformServiceJpaRepositoryImpl.java index 718762c53..e4de4d191 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/productmix/service/ProductMixWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/productmix/service/ProductMixWritePlatformServiceJpaRepositoryImpl.java @@ -42,6 +42,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.NonTransientDataAccessException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -91,7 +93,7 @@ public class ProductMixWritePlatformServiceJpaRepositoryImpl implements ProductM changes.put("restrictedProductsForMix", restrictedProductsAsMap.keySet()); changes.put("removedProductsForMix", removedRestrictions); return new CommandProcessingResultBuilder().withProductId(productId).with(changes).withCommandId(command.commandId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(dve); return CommandProcessingResult.empty(); @@ -165,7 +167,7 @@ public class ProductMixWritePlatformServiceJpaRepositoryImpl implements ProductM changes.put("removedProductsForMix", getProductIdsFromCollection(productMixesToRemove)); } return new CommandProcessingResultBuilder().with(changes).withProductId(productId).withCommandId(command.commandId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(dve); return CommandProcessingResult.empty(); @@ -188,16 +190,12 @@ public class ProductMixWritePlatformServiceJpaRepositoryImpl implements ProductM return restricrtedProducts; } - private void handleDataIntegrityIssues(final DataIntegrityViolationException dve) { - logAsErrorUnexpectedDataIntegrityException(dve); + private void handleDataIntegrityIssues(final NonTransientDataAccessException dve) { + LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.product.loan.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } - private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) { - LOG.error("Error occured.", dve); - } - private List updateRestrictedIds(final Set restrictedIds, final List existedProductMixes) { final List productMixesToRemove = new ArrayList<>(); @@ -226,8 +224,7 @@ public class ProductMixWritePlatformServiceJpaRepositoryImpl implements ProductM this.productMixRepository.deleteAll(existedProductMixes); changes.put("removedProductsForMix", getProductIdsFromCollection(existedProductMixes)); return new CommandProcessingResultBuilder().with(changes).withProductId(productId).build(); - } catch (final DataIntegrityViolationException dve) { - + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(dve); return CommandProcessingResult.empty(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java index fcbae8ff4..f90969840 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java @@ -65,6 +65,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -161,7 +162,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro .withEntityId(loanproduct.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -260,7 +261,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final DataIntegrityViolationException | JpaSystemException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResult(Long.valueOf(-1)); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java index 441bc5767..731ade3fb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/meeting/service/MeetingWritePlatformServiceJpaRepositoryImpl.java @@ -59,6 +59,7 @@ import org.apache.fineract.portfolio.meeting.domain.MeetingRepositoryWrapper; import org.joda.time.LocalDate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -134,8 +135,9 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit .withEntityId(newMeeting.getId()) // .withGroupId(groupId).build(); - } catch (final DataIntegrityViolationException dve) { - handleMeetingDataIntegrityIssues(meetingDate, dve); + } catch (final DataIntegrityViolationException | JpaSystemException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleMeetingDataIntegrityIssues(meetingDate, throwable, dve); return new CommandProcessingResultBuilder() // .build(); } @@ -255,8 +257,9 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit if (!changes.isEmpty()) { this.meetingRepositoryWrapper.saveAndFlush(meetingForUpdate); } - } catch (final DataIntegrityViolationException dve) { - handleMeetingDataIntegrityIssues(meetingForUpdate.getMeetingDate(), dve); + } catch (final DataIntegrityViolationException | JpaSystemException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleMeetingDataIntegrityIssues(meetingForUpdate.getMeetingDate(), throwable, dve); return new CommandProcessingResultBuilder() // .build(); } @@ -294,8 +297,7 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit .build(); } - private void handleMeetingDataIntegrityIssues(final Date meetingDate, final DataIntegrityViolationException dve) { - final Throwable realCause = dve.getMostSpecificCause(); + private void handleMeetingDataIntegrityIssues(final Date meetingDate, final Throwable realCause, final Exception dve) { if (realCause.getMessage().contains("unique_calendar_instance_id_meeting_date")) { final LocalDate meetingDateLocal = LocalDate.fromDateFields(meetingDate); throw new PlatformDataIntegrityException("error.msg.meeting.duplicate", @@ -336,8 +338,9 @@ public class MeetingWritePlatformServiceJpaRepositoryImpl implements MeetingWrit } // save meeting details this.meetingRepositoryWrapper.save(newMeeting); - } catch (final DataIntegrityViolationException dve) { - handleMeetingDataIntegrityIssues(meetingDate, dve); + } catch (final JpaSystemException | DataIntegrityViolationException dve) { + final Throwable throwable = dve.getMostSpecificCause(); + handleMeetingDataIntegrityIssues(meetingDate, throwable, dve); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java index a95e95df0..ae48b397a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/paymenttype/service/PaymentTypeWriteServiceImpl.java @@ -30,6 +30,7 @@ import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepository; import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -81,15 +82,15 @@ public class PaymentTypeWriteServiceImpl implements PaymentTypeWriteService { try { this.repository.delete(paymentType); this.repository.flush(); - } catch (final DataIntegrityViolationException e) { - handleDataIntegrityIssues(e); + } catch (final JpaSystemException | DataIntegrityViolationException e) { + final Throwable throwable = e.getMostSpecificCause(); + handleDataIntegrityIssues(throwable, e); } return new CommandProcessingResultBuilder().withEntityId(paymentType.getId()).build(); } - private void handleDataIntegrityIssues(final DataIntegrityViolationException dve) { + private void handleDataIntegrityIssues(final Throwable realCause, final Exception dve) { - final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("acc_product_mapping")) { throw new PlatformDataIntegrityException("error.msg.payment.type.association.exist", "cannot.delete.payment.type.with.association"); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/rate/service/RateWriteServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/rate/service/RateWriteServiceImpl.java index 207283c9c..2e79540a5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/rate/service/RateWriteServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/rate/service/RateWriteServiceImpl.java @@ -39,6 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -81,7 +82,7 @@ public class RateWriteServiceImpl implements RateWriteService { return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(rate.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleRateDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -122,7 +123,7 @@ public class RateWriteServiceImpl implements RateWriteService { .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleRateDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResult((long) -1); } catch (final PersistenceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java index 7092e2b31..6af061680 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java @@ -65,6 +65,7 @@ import org.apache.fineract.useradministration.exception.RoleNotFoundException; import org.apache.fineract.useradministration.service.AppUserReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; @@ -287,7 +288,7 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ this.userDomainService.create(appUser, true); return appUser; - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, username); return null; } catch (final PersistenceException | AuthenticationServiceException dve) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java index 36883ec27..ac43843ea 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountWritePlatformServiceJpaRepositoryImpl.java @@ -59,6 +59,7 @@ import org.apache.fineract.portfolio.shareproducts.domain.ShareProductRepository import org.joda.time.LocalDate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -112,7 +113,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withCommandId(jsonCommand.commandId()) // .withEntityId(account.getId()) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -210,7 +211,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { @@ -244,7 +245,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -289,7 +290,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -323,7 +324,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -360,7 +361,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -382,7 +383,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -419,7 +420,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -448,7 +449,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -484,7 +485,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } @@ -518,7 +519,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA .withEntityId(accountId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java index 82cf914c0..55a33042b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductWritePlatformServiceJpaRepositoryImpl.java @@ -44,6 +44,7 @@ import org.apache.fineract.portfolio.shareproducts.serialization.ShareProductDat import org.joda.time.LocalDate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; @Service @@ -86,7 +87,7 @@ public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareP .withCommandId(jsonCommand.commandId()) // .withEntityId(product.getId()) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (PersistenceException dve) { @@ -117,7 +118,7 @@ public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareP .withEntityId(productId) // .with(changes) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (PersistenceException dve) { @@ -154,7 +155,7 @@ public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareP .withEntityId(productId) // .withSubEntityId(dividendPayOutDetails.getId())// .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(dve); return CommandProcessingResult.empty(); } @@ -173,7 +174,7 @@ public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareP return new CommandProcessingResultBuilder() // .withEntityId(PayOutDetailId) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(dve); return CommandProcessingResult.empty(); } @@ -191,7 +192,7 @@ public class ShareProductWritePlatformServiceJpaRepositoryImpl implements ShareP return new CommandProcessingResultBuilder() // .withEntityId(PayOutDetailId) // .build(); - } catch (DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(dve); return CommandProcessingResult.empty(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java index fdc270022..4d3926763 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -89,7 +90,7 @@ public class PasswordPreferencesWritePlatformServiceJpaRepositoryImpl implements .withCommandId(command.commandId()) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { LOG.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.password.validation.policy.unknown.data.integrity.issue", "Unknown data integrity issue with resource.", dve); diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java index 3a637f691..9cf788393 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java @@ -44,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Caching; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -85,7 +86,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf this.topicDomainService.createTopic(entity); return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // @@ -145,7 +146,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf .withEntityId(roleId) // .with(changes) // .build(); - } catch (final DataIntegrityViolationException dve) { + } catch (final JpaSystemException | DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // @@ -233,7 +234,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf this.roleRepository.delete(role); return new CommandProcessingResultBuilder().withEntityId(roleId).build(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); } @@ -267,7 +268,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf this.roleRepository.save(role); return new CommandProcessingResultBuilder().withEntityId(roleId).build(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); } @@ -290,7 +291,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf this.roleRepository.save(role); return new CommandProcessingResultBuilder().withEntityId(roleId).build(); - } catch (final DataIntegrityViolationException e) { + } catch (final JpaSystemException | DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause(), e); }