List of usage examples for org.springframework.dao DataIntegrityViolationException getMostSpecificCause
public Throwable getMostSpecificCause()
From source file:com.gst.organisation.staff.service.StaffWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*from w w w.j av a 2s. c om*/ public CommandProcessingResult updateStaff(final Long staffId, final JsonCommand command) { try { this.fromApiJsonDeserializer.validateForUpdate(command.json(), staffId); final Staff staffForUpdate = this.staffRepository.findOne(staffId); if (staffForUpdate == null) { throw new StaffNotFoundException(staffId); } final Map<String, Object> changesOnly = staffForUpdate.update(command); if (changesOnly.containsKey("officeId")) { final Long officeId = (Long) changesOnly.get("officeId"); final Office newOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId); staffForUpdate.changeOffice(newOffice); } if (!changesOnly.isEmpty()) { this.staffRepository.saveAndFlush(staffForUpdate); } return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(staffId) .withOfficeId(staffForUpdate.officeId()).with(changesOnly).build(); } catch (final DataIntegrityViolationException dve) { handleStaffDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleStaffDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.codes.service.CodeWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override// ww w .ja v a 2 s .com @CacheEvict(value = "codes", key = "T(com.gst.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat('cv')") public CommandProcessingResult updateCode(final Long codeId, final JsonCommand command) { try { this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForUpdate(command.json()); final Code code = retrieveCodeBy(codeId); final Map<String, Object> changes = code.update(command); if (!changes.isEmpty()) { this.codeRepository.save(code); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(codeId) // .with(changes) // .build(); } catch (final DataIntegrityViolationException dve) { handleCodeDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); handleCodeDataIntegrityIssues(command, throwable, ee); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.accountnumberformat.service.AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
@Override @Transactional//from w w w. j ava 2s .co m public CommandProcessingResult createAccountNumberFormat(JsonCommand command) { try { this.accountNumberFormatDataValidator.validateForCreate(command.json()); final Integer accountTypeId = command .integerValueSansLocaleOfParameterNamed(AccountNumberFormatConstants.accountTypeParamName); final EntityAccountType entityAccountType = EntityAccountType.fromInt(accountTypeId); final Integer prefixTypeId = command .integerValueSansLocaleOfParameterNamed(AccountNumberFormatConstants.prefixTypeParamName); AccountNumberPrefixType accountNumberPrefixType = null; if (prefixTypeId != null) { accountNumberPrefixType = AccountNumberPrefixType.fromInt(prefixTypeId); } AccountNumberFormat accountNumberFormat = new AccountNumberFormat(entityAccountType, accountNumberPrefixType); this.accountNumberFormatRepository.save(accountNumberFormat); return new CommandProcessingResultBuilder() // .withEntityId(accountNumberFormat.getId()) // .build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); handleDataIntegrityIssues(command, throwable, ee); return CommandProcessingResult.empty(); } }
From source file:com.gst.infrastructure.accountnumberformat.service.AccountNumberFormatWritePlatformServiceJpaRepositoryImpl.java
@Override @Transactional//from www . j a v a 2s .co m public CommandProcessingResult updateAccountNumberFormat(Long accountNumberFormatId, JsonCommand command) { try { final AccountNumberFormat accountNumberFormatForUpdate = this.accountNumberFormatRepository .findOneWithNotFoundDetection(accountNumberFormatId); EntityAccountType accountType = accountNumberFormatForUpdate.getAccountType(); this.accountNumberFormatDataValidator.validateForUpdate(command.json(), accountType); final Map<String, Object> actualChanges = new LinkedHashMap<>(9); if (command.isChangeInIntegerSansLocaleParameterNamed(AccountNumberFormatConstants.prefixTypeParamName, accountNumberFormatForUpdate.getPrefixEnum())) { final Integer newValue = command .integerValueSansLocaleOfParameterNamed(AccountNumberFormatConstants.prefixTypeParamName); final AccountNumberPrefixType accountNumberPrefixType = AccountNumberPrefixType.fromInt(newValue); actualChanges.put(AccountNumberFormatConstants.prefixTypeParamName, accountNumberPrefixType); accountNumberFormatForUpdate.setPrefix(accountNumberPrefixType); } if (!actualChanges.isEmpty()) { this.accountNumberFormatRepository.saveAndFlush(accountNumberFormatForUpdate); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(accountNumberFormatId) // .with(actualChanges) // .build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException ee) { Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); handleDataIntegrityIssues(command, throwable, ee); return CommandProcessingResult.empty(); } }
From source file:com.gst.organisation.provisioning.service.ProvisioningCriteriaWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult createProvisioningCriteria(JsonCommand command) { try {//from w w w . j a v a 2 s . c om 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 ww w . ja v a 2 s.c o m*/ 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//ww w.j a v a 2 s . c om 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 {/*from w w w . j a va 2 s. c o 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.infrastructure.entityaccess.service.FineractEntityAccessWriteServiceImpl.java
@Override @Transactional// w w w . j a v a 2s. 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.portfolio.shareproducts.service.ShareProductWritePlatformServiceJpaRepositoryImpl.java
@Override public CommandProcessingResult updateProduct(Long productId, JsonCommand jsonCommand) { try {/*from w w w. ja va 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(); } }