List of usage examples for org.springframework.dao DataIntegrityViolationException getCause
public synchronized Throwable getCause()
From source file:com.gst.organisation.provisioning.service.ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult createProvisioningCriteria(JsonCommand command) { try {// ww w .ja v a2 s . com this.fromApiJsonDeserializer.validateForCreate(command.json()); ProvisioningCriteria provisioningCriteria = provisioningCriteriaAssembler .fromParsedJson(command.parsedJson()); this.provisioningCriteriaRepository.save(provisioningCriteria); return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withEntityId(provisioningCriteria.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.provisioning.service.ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult updateProvisioningCriteria(final Long criteriaId, JsonCommand command) { try {/*from w w w .java 2 s.c om*/ this.fromApiJsonDeserializer.validateForUpdate(command.json()); ProvisioningCriteria provisioningCriteria = provisioningCriteriaRepository.findOne(criteriaId); if (provisioningCriteria == null) { throw new ProvisioningCategoryNotFoundException(criteriaId); } List<LoanProduct> products = this.provisioningCriteriaAssembler.parseLoanProducts(command.parsedJson()); final Map<String, Object> changes = provisioningCriteria.update(command, products); if (!changes.isEmpty()) { updateProvisioningCriteriaDefinitions(provisioningCriteria, command); provisioningCriteriaRepository.saveAndFlush(provisioningCriteria); } return new CommandProcessingResultBuilder().withCommandId(command.commandId()) .withEntityId(provisioningCriteria.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.entityaccess.service.FineractEntityAccessWriteServiceImpl.java
@Override @Transactional/*from w ww . j a v a2s . com*/ public CommandProcessingResult updateEntityToEntityMapping(Long mapId, JsonCommand command) { try { this.fromApiJsonDeserializer.validateForUpdate(command.json()); final FineractEntityToEntityMapping mapForUpdate = this.fineractEntityToEntityMappingRepositoryWrapper .findOneWithNotFoundDetection(mapId); String relId = mapForUpdate.getRelationId().getId().toString(); final Long fromId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType); final Long toId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.toEntityType); fromApiJsonDeserializer.checkForEntity(relId, fromId, toId); final Map<String, Object> changes = mapForUpdate.updateMap(command); if (!changes.isEmpty()) { this.fineractEntityToEntityMappingRepository.saveAndFlush(mapForUpdate); } return new CommandProcessingResultBuilder(). // withEntityId(mapForUpdate.getId()).withCommandId(command.commandId()).build(); } catch (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.portfolio.shareproducts.service.ShareProductWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult createShareProduct(JsonCommand jsonCommand) { try {// ww w. ja v a2s . co m ShareProduct product = this.serializer.validateAndCreate(jsonCommand); this.repository.save(product); // save accounting mappings this.accountMappingWritePlatformService.createShareProductToGLAccountMapping(product.getId(), jsonCommand); return new CommandProcessingResultBuilder() // .withCommandId(jsonCommand.commandId()) // .withEntityId(product.getId()) // .build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(jsonCommand, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.portfolio.shareproducts.service.ShareProductWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult updateProduct(Long productId, JsonCommand jsonCommand) { try {/*from w w w. j av a 2s . c o m*/ ShareProduct product = this.repository.findOneWithNotFoundDetection(productId); final Map<String, Object> changes = this.serializer.validateAndUpdate(jsonCommand, product); // accounting related changes final boolean accountingTypeChanged = changes .containsKey(ShareProductApiConstants.accountingRuleParamName); final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService .updateShareProductToGLAccountMapping(product.getId(), jsonCommand, accountingTypeChanged, product.getAccountingType()); changes.putAll(accountingMappingChanges); if (!changes.isEmpty()) { this.repository.saveAndFlush(product); } return new CommandProcessingResultBuilder() // .withCommandId(jsonCommand.commandId()) // .withEntityId(productId) // .with(changes) // .build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(jsonCommand, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(jsonCommand, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.entityaccess.service.FineractEntityAccessWriteServiceImpl.java
@Override @Transactional//from w w w . j a v a 2 s.com public CommandProcessingResult createEntityToEntityMapping(Long relId, JsonCommand command) { try { this.fromApiJsonDeserializer.validateForCreate(command.json()); final FineractEntityRelation mapId = this.fineractEntityRelationRepositoryWrapper .findOneWithNotFoundDetection(relId); final Long fromId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType); final Long toId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.toEntityType); final Date startDate = command.DateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate); final Date endDate = command.DateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate); fromApiJsonDeserializer.checkForEntity(relId.toString(), fromId, toId); if (startDate != null && endDate != null) { if (endDate.before(startDate)) { throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString()); } } final FineractEntityToEntityMapping newMap = FineractEntityToEntityMapping.newMap(mapId, fromId, toId, startDate, endDate); this.fineractEntityToEntityMappingRepository.save(newMap); return new CommandProcessingResultBuilder().withEntityId(newMap.getId()) .withCommandId(command.commandId()).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//from w w w.ja va2 s . co 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/*w w w . j av a 2 s . co 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.organisation.office.service.OfficeWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/* w w w .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')") }) 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//from w ww . j a v a2 s .co m @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(); } }