List of usage examples for org.springframework.dao DataIntegrityViolationException getMostSpecificCause
public Throwable getMostSpecificCause()
From source file:com.gst.organisation.holiday.service.HolidayWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override//ww w .ja va 2s .c o m public CommandProcessingResult createHoliday(final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForCreate(command.json()); validateInputDates(command); final Set<Office> offices = getSelectedOffices(command); final Holiday holiday = Holiday.createNew(offices, command); this.holidayRepository.save(holiday); return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withEntityId(holiday.getId()).build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.organisation.holiday.service.HolidayWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*ww w .java 2 s. c o m*/ public CommandProcessingResult updateHoliday(final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForUpdate(command.json()); final Holiday holiday = this.holidayRepository.findOneWithNotFoundDetection(command.entityId()); Map<String, Object> changes = holiday.update(command); validateInputDates(holiday.getFromDateLocalDate(), holiday.getToDateLocalDate(), holiday.getRepaymentsRescheduledToLocalDate()); if (changes.containsKey(officesParamName)) { final Set<Office> offices = getSelectedOffices(command); final boolean updated = holiday.update(offices); if (!updated) { changes.remove(officesParamName); } } this.holidayRepository.saveAndFlush(holiday); return new CommandProcessingResultBuilder().withEntityId(holiday.getId()).with(changes).build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.accounting.financialactivityaccount.service.FinancialActivityAccountWritePlatformServiceImpl.java
@Override public CommandProcessingResult createFinancialActivityAccountMapping(JsonCommand command) { try {// www . ja v a 2s . c om this.fromApiJsonDeserializer.validateForCreate(command.json()); final Integer financialActivityId = command.integerValueSansLocaleOfParameterNamed( FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); final Long accountId = command .longValueOfParameterNamed(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue()); final GLAccount glAccount = glAccountRepositoryWrapper.findOneWithNotFoundDetection(accountId); FinancialActivityAccount financialActivityAccount = FinancialActivityAccount.createNew(glAccount, financialActivityId); validateFinancialActivityAndAccountMapping(financialActivityAccount); this.financialActivityAccountRepository.save(financialActivityAccount); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(financialActivityAccount.getId()) // .build(); } catch (DataIntegrityViolationException dataIntegrityViolationException) { handleFinancialActivityAccountDataIntegrityIssues(command, dataIntegrityViolationException.getMostSpecificCause(), dataIntegrityViolationException); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); handleFinancialActivityAccountDataIntegrityIssues(command, throwable, ee); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.codes.service.CodeWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*ww w. j a v a 2s. c o m*/ @CacheEvict(value = "codes", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')") public CommandProcessingResult deleteCode(final Long codeId) { this.context.authenticatedUser(); final Code code = retrieveCodeBy(codeId); if (code.isSystemDefined()) { throw new SystemDefinedCodeCannotBeChangedException(); } try { this.codeRepository.delete(code); this.codeRepository.flush(); } catch (final DataIntegrityViolationException e) { throw new PlatformDataIntegrityException("error.msg.cund.unknown.data.integrity.issue", "Unknown data integrity issue with resource: " + e.getMostSpecificCause()); } return new CommandProcessingResultBuilder().withEntityId(codeId).build(); }
From source file:com.gst.accounting.financialactivityaccount.service.FinancialActivityAccountWritePlatformServiceImpl.java
@Override public CommandProcessingResult updateGLAccountActivityMapping(Long financialActivityAccountId, JsonCommand command) {//from ww w. j a va2 s. c o m try { this.fromApiJsonDeserializer.validateForUpdate(command.json()); final FinancialActivityAccount financialActivityAccount = this.financialActivityAccountRepository .findOneWithNotFoundDetection(financialActivityAccountId); Map<String, Object> changes = findChanges(command, financialActivityAccount); if (changes.containsKey(FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue())) { final Long accountId = command.longValueOfParameterNamed( FinancialActivityAccountsJsonInputParams.GL_ACCOUNT_ID.getValue()); final GLAccount glAccount = glAccountRepositoryWrapper.findOneWithNotFoundDetection(accountId); financialActivityAccount.updateGlAccount(glAccount); } if (changes.containsKey(FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue())) { final Integer financialActivityId = command.integerValueSansLocaleOfParameterNamed( FinancialActivityAccountsJsonInputParams.FINANCIAL_ACTIVITY_ID.getValue()); financialActivityAccount.updateFinancialActivityType(financialActivityId); } if (!changes.isEmpty()) { validateFinancialActivityAndAccountMapping(financialActivityAccount); this.financialActivityAccountRepository.save(financialActivityAccount); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(financialActivityAccountId) // .with(changes) // .build(); } catch (DataIntegrityViolationException dataIntegrityViolationException) { handleFinancialActivityAccountDataIntegrityIssues(command, dataIntegrityViolationException.getMostSpecificCause(), dataIntegrityViolationException); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); handleFinancialActivityAccountDataIntegrityIssues(command, throwable, ee); return CommandProcessingResult.empty(); } }
From source file:com.gst.organisation.office.service.OfficeWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/* ww w. j ava 2 s . c om*/ @Caching(evict = { @CacheEvict(value = "offices", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'of')"), @CacheEvict(value = "officesForDropdown", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'ofd')") }) public CommandProcessingResult createOffice(final JsonCommand command) { try { final AppUser currentUser = this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForCreate(command.json()); Long parentId = null; if (command.parameterExists("parentId")) { parentId = command.longValueOfParameterNamed("parentId"); } final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, parentId); final Office office = Office.fromJson(parent, command); // pre save to generate id for use in office hierarchy this.officeRepositoryWrapper.save(office); office.generateHierarchy(); this.officeRepositoryWrapper.save(office); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(office.getId()) // .withOfficeId(office.getId()) // .build(); } catch (final DataIntegrityViolationException dve) { handleOfficeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleOfficeDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.organisation.office.service.OfficeWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*w ww .j a v a 2 s.com*/ @Caching(evict = { @CacheEvict(value = "offices", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'of')"), @CacheEvict(value = "officesForDropdown", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#root.target.context.authenticatedUser().getOffice().getHierarchy()+'ofd')"), @CacheEvict(value = "officesById", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#officeId)") }) public CommandProcessingResult updateOffice(final Long officeId, final JsonCommand command) { try { final AppUser currentUser = this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForUpdate(command.json()); Long parentId = null; if (command.parameterExists("parentId")) { parentId = command.longValueOfParameterNamed("parentId"); } final Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, officeId); final Map<String, Object> changes = office.update(command); if (changes.containsKey("parentId")) { final Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, parentId); office.update(parent); } if (!changes.isEmpty()) { this.officeRepositoryWrapper.saveAndFlush(office); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(office.getId()) // .withOfficeId(office.getId()) // .with(changes) // .build(); } catch (final DataIntegrityViolationException dve) { handleOfficeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleOfficeDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.dataqueries.service.ReportWritePlatformServiceImpl.java
@Transactional @Override/* ww w. j ava 2 s .c o m*/ public CommandProcessingResult createReport(final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validate(command.json()); final Report report = Report.fromJson(command, this.readReportingService.getAllowedReportTypes()); final Set<ReportParameterUsage> reportParameterUsages = assembleSetOfReportParameterUsages(report, command); report.update(reportParameterUsages); this.reportRepository.save(report); final Permission permission = new Permission("report", report.getReportName(), "READ"); this.permissionRepository.save(permission); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(report.getId()) // .build(); } catch (final DataIntegrityViolationException dve) { handleReportDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleReportDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.portfolio.charge.service.ChargeWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*from ww w . j a v a2 s. c o m*/ @CacheEvict(value = "charges", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('ch')") public CommandProcessingResult createCharge(final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForCreate(command.json()); // Retrieve linked GLAccount for Client charges (if present) final Long glAccountId = command.longValueOfParameterNamed(ChargesApiConstants.glAccountIdParamName); GLAccount glAccount = null; if (glAccountId != null) { glAccount = this.gLAccountRepository.findOneWithNotFoundDetection(glAccountId); } final Long taxGroupId = command.longValueOfParameterNamed(ChargesApiConstants.taxGroupIdParamName); TaxGroup taxGroup = null; if (taxGroupId != null) { taxGroup = this.taxGroupRepository.findOneWithNotFoundDetection(taxGroupId); } final Charge charge = Charge.fromJson(command, glAccount, taxGroup); this.chargeRepository.save(charge); // check if the office specific products are enabled. If yes, then // save this savings product against a specific office // i.e. this savings product is specific for this office. fineractEntityAccessUtil.checkConfigurationAndAddProductResrictionsForUserOffice( FineractEntityAccessType.OFFICE_ACCESS_TO_CHARGES, charge.getId()); return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withEntityId(charge.getId()).build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.dataqueries.service.ReportWritePlatformServiceImpl.java
@Transactional @Override/* w ww . j a va 2 s .c o m*/ public CommandProcessingResult updateReport(final Long reportId, final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validate(command.json()); final Report report = this.reportRepository.findOne(reportId); if (report == null) { throw new ReportNotFoundException(reportId); } final Map<String, Object> changes = report.update(command, this.readReportingService.getAllowedReportTypes()); if (changes.containsKey("reportParameters")) { final Set<ReportParameterUsage> reportParameterUsages = assembleSetOfReportParameterUsages(report, command); final boolean updated = report.update(reportParameterUsages); if (!updated) { changes.remove("reportParameters"); } } if (!changes.isEmpty()) { this.reportRepository.saveAndFlush(report); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(report.getId()) // .with(changes) // .build(); } catch (final DataIntegrityViolationException dve) { handleReportDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleReportDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }