FINERACT-1098 - Catch JpaSystemException in jpa transactions

This commit is contained in:
xurror
2020-08-04 15:29:34 +01:00
committed by Yemdjih Kaze Nasser
parent a31d29f1f0
commit e7b2163914
55 changed files with 369 additions and 259 deletions
@@ -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())));
@@ -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());
@@ -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);
@@ -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);
}
}
@@ -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();
}
}
@@ -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();
}
@@ -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);
}
@@ -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) {
@@ -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());
@@ -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",
@@ -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());
@@ -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")) {
@@ -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();
}
@@ -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());
@@ -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<ApiParameterError> 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<ApiParameterError> 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<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("datatable");
@@ -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();
}
}
@@ -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);
@@ -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) {
@@ -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",
@@ -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);
}
@@ -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);
@@ -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",
@@ -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());
@@ -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();
}
}
@@ -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) {
@@ -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) {
@@ -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");
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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",
@@ -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) {
@@ -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",
@@ -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) {
@@ -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();
}
@@ -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);
}
}
@@ -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) {
@@ -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) {
@@ -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();
}
@@ -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",
@@ -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<ApiParameterError> 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<ApiParameterError> 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<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
@@ -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());
@@ -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<ApiParameterError> 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);
@@ -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<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.application");
@@ -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<ApiParameterError> 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<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transaction");
@@ -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<ProductMix> updateRestrictedIds(final Set<String> restrictedIds, final List<ProductMix> existedProductMixes) {
final List<ProductMix> 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();
}
@@ -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) {
@@ -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);
}
}
@@ -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");
@@ -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) {
@@ -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) {
@@ -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();
}
@@ -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();
}
@@ -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);
@@ -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);
}