use throw instead of confusing return null inside catch

in JournalEntryWritePlatformServiceJpaRepositoryImpl
This commit is contained in:
Michael Vorburger
2020-05-03 00:07:49 +02:00
committed by Michael Vorburger ⛑️
parent 8418dd424f
commit 7fe9d2bcbf
@@ -217,8 +217,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId) return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId)
.withTransactionId(transactionId).build(); .withTransactionId(transactionId).build();
} catch (final DataIntegrityViolationException dve) { } catch (final DataIntegrityViolationException dve) {
handleJournalEntryDataIntegrityIssues(dve); throw handleJournalEntryDataIntegrityIssues(dve);
return null;
} }
} }
@@ -539,7 +538,9 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
String transactionId = AccountingProcessorHelper.SHARE_TRANSACTION_IDENTIFIER + shareTransactionId.longValue(); String transactionId = AccountingProcessorHelper.SHARE_TRANSACTION_IDENTIFIER + shareTransactionId.longValue();
List<JournalEntry> journalEntries = this.glJournalEntryRepository.findJournalEntries(transactionId, List<JournalEntry> journalEntries = this.glJournalEntryRepository.findJournalEntries(transactionId,
PortfolioProductType.SHARES.getValue()); PortfolioProductType.SHARES.getValue());
if (journalEntries == null || journalEntries.isEmpty()) continue; if (journalEntries == null || journalEntries.isEmpty()) {
continue;
}
final Long officeId = journalEntries.get(0).getOffice().getId(); final Long officeId = journalEntries.get(0).getOffice().getId();
final String reversalTransactionId = generateTransactionId(officeId); final String reversalTransactionId = generateTransactionId(officeId);
for (final JournalEntry journalEntry : journalEntries) { for (final JournalEntry journalEntry : journalEntries) {
@@ -637,10 +638,10 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
return transactionId; return transactionId;
} }
private void handleJournalEntryDataIntegrityIssues(final DataIntegrityViolationException dve) { private PlatformDataIntegrityException handleJournalEntryDataIntegrityIssues(final DataIntegrityViolationException dve) {
final Throwable realCause = dve.getMostSpecificCause(); final Throwable realCause = dve.getMostSpecificCause();
logger.error("Error occured.", dve); logger.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.glJournalEntry.unknown.data.integrity.issue", return new PlatformDataIntegrityException("error.msg.glJournalEntry.unknown.data.integrity.issue",
"Unknown data integrity issue with resource Journal Entry: " + realCause.getMessage()); "Unknown data integrity issue with resource Journal Entry: " + realCause.getMessage());
} }
@@ -691,8 +692,7 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId) return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(officeId)
.withTransactionId(transactionId).build(); .withTransactionId(transactionId).build();
} catch (final DataIntegrityViolationException dve) { } catch (final DataIntegrityViolationException dve) {
handleJournalEntryDataIntegrityIssues(dve); throw handleJournalEntryDataIntegrityIssues(dve);
return null;
} }
} }
@@ -773,7 +773,9 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!obj.getClass().equals(this.getClass())) return false; if (!obj.getClass().equals(this.getClass())) {
return false;
}
OfficeCurrencyKey copy = (OfficeCurrencyKey) obj; OfficeCurrencyKey copy = (OfficeCurrencyKey) obj;
return Objects.equals(this.office.getId(), copy.office.getId()) && this.currency.equals(copy.currency); return Objects.equals(this.office.getId(), copy.office.getId()) && this.currency.equals(copy.currency);
} }