Search in sources :

Example 1 with ExecutableCheckException

use of org.jowidgets.cap.common.api.exception.ExecutableCheckException in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method checkExecutableState.

private void checkExecutableState(final ILinkCreation link, final IExecutionCallback executionCallback) {
    final Collection<IBeanKey> linkableBeans = link.getLinkableBeans();
    if (!EmptyCheck.isEmpty(linkableBeans)) {
        for (final IBeanKey sourceBean : link.getSourceBeans()) {
            final IFilterFactory filterFactory = CapCommonToolkit.filterFactory();
            final Object[] linkableKeys = new Object[linkableBeans.size()];
            int index = 0;
            for (final IBeanKey key : linkableBeans) {
                linkableKeys[index] = key.getId();
                index++;
            }
            final IArithmeticFilter filter;
            if (destinationProperties != null) {
                filter = filterFactory.arithmeticFilter(destinationProperties.getKeyPropertyName(), ArithmeticOperator.CONTAINS_ANY, linkableKeys);
            } else if (sourceProperties != null) {
                filter = filterFactory.arithmeticFilter(sourceProperties.getKeyPropertyName(), ArithmeticOperator.CONTAINS_ANY, linkableKeys);
            } else {
                throw new IllegalStateException("Neither the source not the destination properties are defined");
            }
            final SyncResultCallback<Integer> result = new SyncResultCallback<Integer>();
            linkableReaderService.count(result, Collections.singletonList(sourceBean), filter, null, executionCallback);
            final Integer count = result.getResultSynchronious();
            if (count == null || count.intValue() < linkableKeys.length) {
                throw new ExecutableCheckException(sourceBean.getId(), "Beans are not linkable", DATASETS_CAN_NOT_BE_LINKED.get());
            }
        }
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilterFactory(org.jowidgets.cap.common.api.filter.IFilterFactory) IArithmeticFilter(org.jowidgets.cap.common.api.filter.IArithmeticFilter) ExecutableCheckException(org.jowidgets.cap.common.api.exception.ExecutableCheckException) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback)

Example 2 with ExecutableCheckException

use of org.jowidgets.cap.common.api.exception.ExecutableCheckException in project jo-client-platform by jo-source.

the class SyncExecutorServiceImpl method checkExecutableStates.

private void checkExecutableStates(final List<BEAN_TYPE> beans, final IExecutionCallback executionCallback) {
    for (final BEAN_TYPE bean : beans) {
        final IExecutableState executableState = executableChecker.getExecutableState(bean);
        if (!executableState.isExecutable()) {
            throw new ExecutableCheckException(getId(bean), "Executable check could not pass on service execution for bean '" + bean + "'", executableState.getReason());
        }
        CapServiceToolkit.checkCanceled(executionCallback);
    }
}
Also used : IExecutableState(org.jowidgets.cap.common.api.execution.IExecutableState) ExecutableCheckException(org.jowidgets.cap.common.api.exception.ExecutableCheckException)

Example 3 with ExecutableCheckException

use of org.jowidgets.cap.common.api.exception.ExecutableCheckException in project jo-client-platform by jo-source.

the class HibernateExceptionDecoratorImpl method decorate.

private Throwable decorate(final Throwable exception, final Throwable rootException) {
    if (exception instanceof ConstraintViolationException) {
        final ConstraintViolationException constViolationException = (ConstraintViolationException) exception;
        final String message = constViolationException.getMessage();
        final String constraintName = constViolationException.getConstraintName();
        final String userBaseMessage = Messages.getString("HibernateExceptionDecoratorImpl.database_constraint_violated");
        final String userMessage;
        if (!EmptyCheck.isEmpty(constraintName)) {
            userMessage = userBaseMessage.replace("%1", "'" + constraintName + "'");
        } else {
            final SQLException sqlException = constViolationException.getSQLException();
            if (sqlException != null) {
                if (!EmptyCheck.isEmpty(sqlException.getLocalizedMessage())) {
                    userMessage = sqlException.getLocalizedMessage();
                } else if (!EmptyCheck.isEmpty(sqlException.getMessage())) {
                    userMessage = sqlException.getMessage();
                } else {
                    userMessage = userBaseMessage.replace("%1", "");
                }
            } else {
                userMessage = userBaseMessage.replace("%1", "");
            }
        }
        return new ExecutableCheckException(null, message, userMessage);
    } else if (exception instanceof OptimisticLockException && exception.getCause() instanceof StaleObjectStateException) {
        return getStaleBeanException((StaleObjectStateException) exception);
    } else if (exception instanceof UnresolvableObjectException) {
        return getDeletedBeanException((UnresolvableObjectException) exception);
    } else if (exception instanceof JDBCException && !excludeJDBCExceptionDecoration((JDBCException) exception)) {
        return decorateJDBCException((JDBCException) exception);
    } else if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception).getTargetException() != null) {
        return decorate(((InvocationTargetException) exception).getTargetException(), rootException);
    } else if (exception.getCause() != null) {
        return decorate(exception.getCause(), rootException);
    }
    return rootException;
}
Also used : JDBCException(org.hibernate.JDBCException) SQLException(java.sql.SQLException) UnresolvableObjectException(org.hibernate.UnresolvableObjectException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) OptimisticLockException(javax.persistence.OptimisticLockException) ExecutableCheckException(org.jowidgets.cap.common.api.exception.ExecutableCheckException) StaleObjectStateException(org.hibernate.StaleObjectStateException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ExecutableCheckException (org.jowidgets.cap.common.api.exception.ExecutableCheckException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 JDBCException (org.hibernate.JDBCException)1 StaleObjectStateException (org.hibernate.StaleObjectStateException)1 UnresolvableObjectException (org.hibernate.UnresolvableObjectException)1 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)1 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)1 IExecutableState (org.jowidgets.cap.common.api.execution.IExecutableState)1 IArithmeticFilter (org.jowidgets.cap.common.api.filter.IArithmeticFilter)1 IFilterFactory (org.jowidgets.cap.common.api.filter.IFilterFactory)1 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)1