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());
}
}
}
}
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);
}
}
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;
}
Aggregations