Example usage for org.springframework.dao DataAccessException getMostSpecificCause

List of usage examples for org.springframework.dao DataAccessException getMostSpecificCause

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMostSpecificCause.

Prototype

public Throwable getMostSpecificCause() 

Source Link

Document

Retrieve the most specific cause of this exception, that is, either the innermost cause (root cause) or this exception itself.

Usage

From source file:com.gst.portfolio.savings.service.FixedDepositProductWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//from   w ww  .j  a v  a 2 s .  c  o m
public CommandProcessingResult create(final JsonCommand command) {

    try {
        this.fromApiJsonDataValidator.validateForFixedDepositCreate(command.json());

        final FixedDepositProduct product = this.depositProductAssembler.assembleFixedDepositProduct(command);

        this.fixedDepositProductRepository.save(product);

        // save accounting mappings
        this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command,
                DepositAccountType.FIXED_DEPOSIT);

        return new CommandProcessingResultBuilder() //
                .withEntityId(product.getId()) //
                .build();
    } catch (final DataAccessException e) {
        handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        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.savings.service.RecurringDepositProductWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*w w w .jav  a2  s  .co  m*/
public CommandProcessingResult create(final JsonCommand command) {

    try {
        this.fromApiJsonDataValidator.validateForRecurringDepositCreate(command.json());

        final RecurringDepositProduct product = this.depositProductAssembler
                .assembleRecurringDepositProduct(command);

        this.recurringDepositProductRepository.save(product);

        // save accounting mappings
        this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command,
                DepositAccountType.RECURRING_DEPOSIT);

        return new CommandProcessingResultBuilder() //
                .withEntityId(product.getId()) //
                .build();
    } catch (final DataAccessException e) {
        handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        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.savings.service.SavingsProductWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//  www . j a v a 2s .c  o m
public CommandProcessingResult create(final JsonCommand command) {

    try {
        this.fromApiJsonDataValidator.validateForCreate(command.json());

        final SavingsProduct product = this.savingsProductAssembler.assemble(command);

        this.savingProductRepository.save(product);

        // save accounting mappings
        this.accountMappingWritePlatformService.createSavingProductToGLAccountMapping(product.getId(), command,
                DepositAccountType.SAVINGS_DEPOSIT);

        // 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_SAVINGS_PRODUCTS, product.getId());

        return new CommandProcessingResultBuilder() //
                .withEntityId(product.getId()) //
                .build();
    } catch (final DataAccessException e) {
        handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        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.savings.service.FixedDepositProductWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//from w ww .  j av  a2  s. c o m
public CommandProcessingResult update(final Long productId, final JsonCommand command) {

    try {
        this.context.authenticatedUser();
        this.fromApiJsonDataValidator.validateForFixedDepositUpdate(command.json());

        final FixedDepositProduct product = this.fixedDepositProductRepository.findOne(productId);
        if (product == null) {
            throw new FixedDepositProductNotFoundException(productId);
        }
        product.setHelpers(this.chartAssembler);

        final Map<String, Object> changes = product.update(command);

        if (changes.containsKey(chargesParamName)) {
            final Set<Charge> savingsProductCharges = this.depositProductAssembler
                    .assembleListOfSavingsProductCharges(command, product.currency().getCode());
            final boolean updated = product.update(savingsProductCharges);
            if (!updated) {
                changes.remove(chargesParamName);
            }
        }

        if (changes.containsKey(taxGroupIdParamName)) {
            final TaxGroup taxGroup = this.depositProductAssembler.assembleTaxGroup(command);
            product.setTaxGroup(taxGroup);
            if (product.withHoldTax() && product.getTaxGroup() == null) {
                final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
                        .resource(FIXED_DEPOSIT_PRODUCT_RESOURCE_NAME);
                final Long taxGroupId = null;
                baseDataValidator.reset().parameter(taxGroupIdParamName).value(taxGroupId).notBlank();
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }

        // accounting related changes
        final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
        final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
                .updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged,
                        product.getAccountingType(), DepositAccountType.FIXED_DEPOSIT);
        changes.putAll(accountingMappingChanges);

        if (!changes.isEmpty()) {
            this.fixedDepositProductRepository.save(product);
        }

        return new CommandProcessingResultBuilder() //
                .withEntityId(product.getId()) //
                .with(changes).build();
    } catch (final DataAccessException e) {
        handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        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.savings.service.RecurringDepositProductWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*from ww w. j a v  a  2s  .c om*/
public CommandProcessingResult update(final Long productId, final JsonCommand command) {

    try {
        this.context.authenticatedUser();
        this.fromApiJsonDataValidator.validateForRecurringDepositUpdate(command.json());

        final RecurringDepositProduct product = this.recurringDepositProductRepository.findOne(productId);
        if (product == null) {
            throw new RecurringDepositProductNotFoundException(productId);
        }
        product.setHelpers(this.chartAssembler);

        final Map<String, Object> changes = product.update(command);

        if (changes.containsKey(chargesParamName)) {
            final Set<Charge> savingsProductCharges = this.depositProductAssembler
                    .assembleListOfSavingsProductCharges(command, product.currency().getCode());
            final boolean updated = product.update(savingsProductCharges);
            if (!updated) {
                changes.remove(chargesParamName);
            }
        }

        if (changes.containsKey(taxGroupIdParamName)) {
            final TaxGroup taxGroup = this.depositProductAssembler.assembleTaxGroup(command);
            product.setTaxGroup(taxGroup);
            if (product.withHoldTax() && product.getTaxGroup() == null) {
                final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
                        .resource(RECURRING_DEPOSIT_PRODUCT_RESOURCE_NAME);
                final Long taxGroupId = null;
                baseDataValidator.reset().parameter(taxGroupIdParamName).value(taxGroupId).notBlank();
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }

        // accounting related changes
        final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
        final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
                .updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged,
                        product.getAccountingType(), DepositAccountType.RECURRING_DEPOSIT);
        changes.putAll(accountingMappingChanges);

        if (!changes.isEmpty()) {
            this.recurringDepositProductRepository.save(product);
        }

        return new CommandProcessingResultBuilder() //
                .withEntityId(product.getId()) //
                .with(changes).build();
    } catch (final DataAccessException e) {
        handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        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.savings.service.SavingsProductWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*from w  ww . j  a v a  2s.c o  m*/
public CommandProcessingResult update(final Long productId, final JsonCommand command) {

    try {
        this.context.authenticatedUser();
        final SavingsProduct product = this.savingProductRepository.findOne(productId);
        if (product == null) {
            throw new SavingsProductNotFoundException(productId);
        }

        this.fromApiJsonDataValidator.validateForUpdate(command.json(), product);

        final Map<String, Object> changes = product.update(command);

        if (changes.containsKey(chargesParamName)) {
            final Set<Charge> savingsProductCharges = this.savingsProductAssembler
                    .assembleListOfSavingsProductCharges(command, product.currency().getCode());
            final boolean updated = product.update(savingsProductCharges);
            if (!updated) {
                changes.remove(chargesParamName);
            }
        }

        if (changes.containsKey(taxGroupIdParamName)) {
            final TaxGroup taxGroup = this.savingsProductAssembler.assembleTaxGroup(command);
            product.setTaxGroup(taxGroup);
            if (product.withHoldTax() && product.getTaxGroup() == null) {
                final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
                final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
                        .resource(SAVINGS_PRODUCT_RESOURCE_NAME);
                final Long taxGroupId = null;
                baseDataValidator.reset().parameter(taxGroupIdParamName).value(taxGroupId).notBlank();
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }

        // accounting related changes
        final boolean accountingTypeChanged = changes.containsKey(accountingRuleParamName);
        final Map<String, Object> accountingMappingChanges = this.accountMappingWritePlatformService
                .updateSavingsProductToGLAccountMapping(product.getId(), command, accountingTypeChanged,
                        product.getAccountingType(), DepositAccountType.SAVINGS_DEPOSIT);
        changes.putAll(accountingMappingChanges);

        if (!changes.isEmpty()) {
            this.savingProductRepository.saveAndFlush(product);
        }

        return new CommandProcessingResultBuilder() //
                .withEntityId(product.getId()) //
                .with(changes).build();
    } catch (final DataAccessException e) {
        handleDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        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.EntityDatatableChecksWritePlatformServiceImpl.java

@Transactional
@Override//from  ww  w  .jav  a 2s  .  co m
public CommandProcessingResult createCheck(final JsonCommand command) {

    try {
        this.context.authenticatedUser();

        this.fromApiJsonDeserializer.validateForCreate(command.json());

        // check if the datatable is linked to the entity

        String datatableName = command.stringValueOfParameterNamed("datatableName");
        DatatableData datatableData = this.readWriteNonCoreDataService.retrieveDatatable(datatableName);

        if (datatableData == null) {
            throw new DatatableNotFoundException(datatableName);
        }

        final String entity = command.stringValueOfParameterNamed("entity");
        final String foreignKeyColumnName = EntityTables.getForeignKeyColumnNameOnDatatable(entity);
        final boolean columnExist = datatableData.hasColumn(foreignKeyColumnName);

        logger.info(datatableData.getRegisteredTableName() + "has column " + foreignKeyColumnName + " ? "
                + columnExist);

        if (!columnExist) {
            throw new EntityDatatableCheckNotSupportedException(datatableData.getRegisteredTableName(), entity);
        }

        final Long productId = command.longValueOfParameterNamed("productId");
        final Long status = command.longValueOfParameterNamed("status");

        List<EntityDatatableChecks> entityDatatableCheck = null;
        if (productId == null) {
            entityDatatableCheck = this.entityDatatableChecksRepository
                    .findByEntityStatusAndDatatableIdAndNoProduct(entity, status, datatableName);
            if (!entityDatatableCheck.isEmpty()) {
                throw new EntityDatatableCheckAlreadyExistsException(entity, status, datatableName);
            }
        } else {
            if (entity.equals("m_loan")) {
                // if invalid loan product id, throws exception
                this.loanProductReadPlatformService.retrieveLoanProduct(productId);
            } else if (entity.equals("m_savings_account")) {
                // if invalid savings product id, throws exception
                this.savingsProductReadPlatformService.retrieveOne(productId);
            } else {
                throw new EntityDatatableCheckNotSupportedException(entity, productId);
            }
            entityDatatableCheck = this.entityDatatableChecksRepository
                    .findByEntityStatusAndDatatableIdAndProductId(entity, status, datatableName, productId);
            if (!entityDatatableCheck.isEmpty()) {
                throw new EntityDatatableCheckAlreadyExistsException(entity, status, datatableName, productId);
            }
        }

        final EntityDatatableChecks check = EntityDatatableChecks.fromJson(command);

        this.entityDatatableChecksRepository.saveAndFlush(check);

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(check.getId()) //
                .build();
    } catch (final DataAccessException e) {
        handleReportDataIntegrityIssues(command, e.getMostSpecificCause(), e);
        return CommandProcessingResult.empty();
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleReportDataIntegrityIssues(command, throwable, dve);
        return CommandProcessingResult.empty();
    }
}

From source file:ch.systemsx.cisd.openbis.generic.server.CommonServer.java

private static UserFailureException createUserFailureException(final DataAccessException ex) {
    return new UserFailureException(ex.getMostSpecificCause().getMessage(), ex);
}

From source file:de.forsthaus.webui.security.rolegroup.SecRolegroupCtrl.java

/**
 * This method saves the status of the checkboxed right-item.<br>
 * <br>/*from   w  w w .j  a v  a 2  s  .  c om*/
 * 1. we iterate over all items in the listbox <br>
 * 2. for each 'checked item' we must check if it is 'newly' checked <br>
 * 3. if newly than get a new object first and <b>save</b> it to DB. <br>
 * 4. for each 'unchecked item' we must check if it newly unchecked <br>
 * 5. if newly unchecked we must <b>delete</b> this item from DB. <br>
 * 
 * @throws InterruptedException
 */
public void doSave() throws InterruptedException {

    List<Listitem> li = this.listBoxSecRolegroup.getItems();

    for (Listitem listitem : li) {

        Listcell lc = (Listcell) listitem.getFirstChild();
        Checkbox cb = (Checkbox) lc.getFirstChild();

        if (cb != null) {

            if (cb.isChecked() == true) {

                // Get the group object by casting
                SecGroup aGroup = (SecGroup) listitem.getAttribute("data");
                // get the role
                SecRole aRole = getSelectedRole();

                // check if the item is newly checked. If so we cannot found
                // it in the SecGroupRight-table
                SecRolegroup aRoleGroup = getSecurityService().getRolegroupByRoleAndGroup(aRole, aGroup);

                // if new, we make a newly Object
                if (aRoleGroup == null) {
                    aRoleGroup = getSecurityService().getNewSecRolegroup();
                    aRoleGroup.setSecGroup(aGroup);
                    aRoleGroup.setSecRole(aRole);
                }

                try {
                    // save to DB
                    getSecurityService().saveOrUpdate(aRoleGroup);
                } catch (DataAccessException e) {
                    ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());
                }

            } else if (cb.isChecked() == false) {

                // Get the group object by casting
                SecGroup aGroup = (SecGroup) listitem.getAttribute("data");
                // get the role
                SecRole aRole = getSelectedRole();

                // check if the item is newly unChecked. If so we must
                // found it in the SecRolegroup-table
                SecRolegroup aRoleGroup = getSecurityService().getRolegroupByRoleAndGroup(aRole, aGroup);

                if (aRoleGroup != null) {
                    // delete from DB
                    getSecurityService().delete(aRoleGroup);
                }
            }
        }
    }

}

From source file:de.forsthaus.webui.security.userrole.SecUserroleCtrl.java

/**
 * doSave(). This method saves the status of the checkboxed right-item.<br>
 * <br>//from   w w  w.  j  a va 2 s  .  com
 * 1. we iterate over all items in the listbox <br>
 * 2. for each 'checked item' we must check if it is 'newly' checked <br>
 * 3. if newly than get a new object first and <b>save</b> it to DB. <br>
 * 4. for each 'unchecked item' we must check if it newly unchecked <br>
 * 5. if newly unchecked we must <b>delete</b> this item from DB. <br>
 * 
 * @throws InterruptedException
 */
@SuppressWarnings("unchecked")
public void doSave() throws InterruptedException {

    List<Listitem> li = this.listBoxSecRoles.getItems();

    for (Listitem listitem : li) {

        Listcell lc = (Listcell) listitem.getFirstChild();
        Checkbox cb = (Checkbox) lc.getFirstChild();

        if (cb != null) {

            if (cb.isChecked() == true) {

                // Get the role object by casting
                SecRole aRole = (SecRole) listitem.getAttribute("data");
                // get the user
                SecUser anUser = getSelectedUser();

                // check if the item is newly checked. If so we cannot
                // found it in the SecUserrole-table
                SecUserrole anUserRole = getSecurityService().getUserroleByUserAndRole(anUser, aRole);

                // if new, we make a newly Object
                if (anUserRole == null) {
                    anUserRole = getSecurityService().getNewSecUserrole();
                    anUserRole.setSecUser(anUser);
                    anUserRole.setSecRole(aRole);
                }

                try {
                    // save to DB
                    getSecurityService().saveOrUpdate(anUserRole);
                } catch (DataAccessException e) {
                    ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());
                }

            } else if (cb.isChecked() == false) {

                // Get the role object by casting
                SecRole aRole = (SecRole) listitem.getAttribute("data");
                // get the user
                SecUser anUser = getSelectedUser();

                // check if the item is newly checked. If so we cannot
                // found it in the SecUserrole-table
                SecUserrole anUserRole = getSecurityService().getUserroleByUserAndRole(anUser, aRole);

                if (anUserRole != null) {
                    // delete from DB
                    getSecurityService().delete(anUserRole);
                }
            }
        }
    }

}