use of org.jowidgets.cap.common.api.exception.ServiceCanceledException in project jo-client-platform by jo-source.
the class BeanListExecutionHelper method onExecption.
void onExecption(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final Throwable exception) {
int beanIndex = 0;
for (final IBeanProxy<BEAN_TYPE> bean : executedBeans) {
final IExecutionTask executionTask = bean.getExecutionTask();
final boolean canceled = (exception instanceof ServiceCanceledException) || (executionTask != null && executionTask.isCanceled());
if (!canceled) {
bean.addMessage(exceptionConverter.convert(shortErrorMessage, executedBeans, beanIndex++, bean, exception));
}
bean.setExecutionTask(null);
}
if (fireBeansChanged) {
listModel.fireBeansChanged();
}
}
use of org.jowidgets.cap.common.api.exception.ServiceCanceledException in project jo-client-platform by jo-source.
the class RemotingServiceInitializer method initialize.
/**
* Initializes the remoting services.
* This method blocks until the remoting services are initialized, the invocation was canceled or the timeout elapsed
*
* @param timeout The timeout
* @param cancelCallback Can be used to cancel the initialization
*
* @return True if the remoting services was initialized, false otherwise (e.g. timeout occured)
*/
public synchronized boolean initialize(final long timeout, final ICancelCallback cancelCallback) {
if (!initialized.get()) {
final IServiceProvider serviceProvider;
try {
serviceProvider = RemotingServiceProviderFactory.create(brokerId, timeout, cancelCallback);
ServiceProvider.registerServiceProviderHolder(new DefaultServiceProviderHolder(serviceProvider));
initialized.set(true);
} catch (final RemotingTimeoutException e) {
// do nothing, because this method returns false then
} catch (final ServiceCanceledException e) {
// do nothing, because this method returns false then
}
}
return initialized.get();
}
use of org.jowidgets.cap.common.api.exception.ServiceCanceledException in project jo-client-platform by jo-source.
the class ServiceBeanValidationHelper method validate.
public static <BEAN_TYPE> void validate(final IBeanValidator<BEAN_TYPE> beanValidator, final boolean confirmValidationWarnings, final Collection<BEAN_TYPE> beans, final IBeanIdentityResolver<BEAN_TYPE> beanIdentityResolver, final IExecutionCallback executionCallback) {
final Map<Object, IBeanValidationResult> validationResultMap = new HashMap<Object, IBeanValidationResult>();
boolean hasError = false;
final List<IBeanValidationResult> validationWarnings = new LinkedList<IBeanValidationResult>();
int beanIndex = 0;
BeansValidationException.KeyType keyType = KeyType.ID;
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
final Object id = beanIdentityResolver.getId(bean);
final Collection<IBeanValidationResult> validationResults = beanValidator.validate(bean);
final IBeanValidationResult worstFirst = BeanValidationResultUtil.getWorstFirst(validationResults);
if (worstFirst != null) {
if (!worstFirst.getValidationResult().isValid()) {
hasError = true;
keyType = addResultsToMap(validationResultMap, id, beanIndex, keyType, worstFirst);
} else {
final IValidationMessage validationResult = worstFirst.getValidationResult().getWorstFirst();
if (MessageType.WARNING.equals(validationResult.getType())) {
validationWarnings.add(worstFirst);
keyType = addResultsToMap(validationResultMap, id, beanIndex, keyType, worstFirst);
}
}
}
beanIndex++;
}
if (hasError) {
throw new BeansValidationException(validationResultMap, keyType);
} else if (confirmValidationWarnings && validationWarnings.size() > 0) {
final String userQuestion = createUserQuestionString(validationWarnings);
final UserQuestionResult userQuestionResult;
try {
userQuestionResult = executionCallback.userQuestion(userQuestion);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new ServiceInterruptedException(e);
}
if (UserQuestionResult.NO.equals(userQuestionResult)) {
throw new ServiceCanceledException();
}
}
}
use of org.jowidgets.cap.common.api.exception.ServiceCanceledException in project jo-client-platform by jo-source.
the class AbstractCapServiceInvocationHandler method invoke.
@Override
public final Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Class<?>[] parameterTypes = method.getParameterTypes();
final IExecutionCallback executionCallback = getExecutionCallback(parameterTypes, args);
final int resultCallbackIndex = getFirstMatchingIndex(IResultCallback.class, parameterTypes);
if (resultCallbackIndex == -1) {
if (executionCallback != null && executionCallback.isCanceled()) {
throw new ServiceCanceledException();
}
return invokeSyncSignature(method, args, executionCallback);
} else {
@SuppressWarnings("unchecked") final IResultCallback<Object> resultCallback = (IResultCallback<Object>) args[resultCallbackIndex];
if (executionCallback != null && executionCallback.isCanceled()) {
resultCallback.exception(new ServiceCanceledException());
return null;
}
return invokeAsyncSignature(method, args, resultCallbackIndex, resultCallback, executionCallback);
}
}
use of org.jowidgets.cap.common.api.exception.ServiceCanceledException in project jo-client-platform by jo-source.
the class BeanLinkCreatorCommand method createResultCallback.
private IResultCallback<List<IBeanDto>> createResultCallback(final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IExecutionContext executionContext) {
return new AbstractUiResultCallback<List<IBeanDto>>() {
@Override
protected void finishedUi(final List<IBeanDto> result) {
for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
bean.setExecutionTask(null);
}
if (linkedModel != null) {
if (Cardinality.LESS_OR_EQUAL_ONE.equals(linkedCardinality)) {
linkedModel.removeAllBeans();
}
for (final IBeanDto resultBean : result) {
linkedModel.addBeanDto(resultBean);
}
}
executionObservable.fireAfterExecutionSuccess(executionContext, result);
}
@Override
protected void exceptionUi(final Throwable exception) {
int beanIndex = 0;
for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
bean.setExecutionTask(null);
if (!(exception instanceof ServiceCanceledException)) {
bean.addMessage(exceptionConverter.convert(getShortErrorMessage(), selection, beanIndex++, bean, exception));
}
}
executionObservable.fireAfterExecutionError(executionContext, exception);
}
private String getShortErrorMessage() {
final String actionText = executionContext.getAction().getText().replaceAll("\\.", "").trim();
return MessageReplacer.replace(SHORT_ERROR.get(), actionText);
}
};
}
Aggregations