Search in sources :

Example 1 with ServiceCanceledException

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();
    }
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException)

Example 2 with ServiceCanceledException

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();
}
Also used : DefaultServiceProviderHolder(org.jowidgets.service.tools.DefaultServiceProviderHolder) IServiceProvider(org.jowidgets.service.api.IServiceProvider) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException)

Example 3 with ServiceCanceledException

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();
        }
    }
}
Also used : IBeanValidationResult(org.jowidgets.cap.common.api.validation.IBeanValidationResult) IValidationMessage(org.jowidgets.validation.IValidationMessage) HashMap(java.util.HashMap) ServiceInterruptedException(org.jowidgets.cap.common.api.exception.ServiceInterruptedException) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException) ServiceInterruptedException(org.jowidgets.cap.common.api.exception.ServiceInterruptedException) LinkedList(java.util.LinkedList) UserQuestionResult(org.jowidgets.cap.common.api.execution.UserQuestionResult) BeansValidationException(org.jowidgets.cap.common.api.exception.BeansValidationException) KeyType(org.jowidgets.cap.common.api.exception.BeansValidationException.KeyType)

Example 4 with 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);
    }
}
Also used : IExecutionCallback(org.jowidgets.cap.common.api.execution.IExecutionCallback) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException) IResultCallback(org.jowidgets.cap.common.api.execution.IResultCallback)

Example 5 with ServiceCanceledException

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);
        }
    };
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) List(java.util.List) LinkedList(java.util.LinkedList) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException) IBeanLinkPanelBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanLinkPanelBluePrint) IBeanLinkDialogBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanLinkDialogBluePrint) IBeanTableBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanTableBluePrint) IBeanFormBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanFormBluePrint)

Aggregations

ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)6 LinkedList (java.util.LinkedList)3 List (java.util.List)2 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)2 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)2 HashMap (java.util.HashMap)1 BeansValidationException (org.jowidgets.cap.common.api.exception.BeansValidationException)1 KeyType (org.jowidgets.cap.common.api.exception.BeansValidationException.KeyType)1 ServiceInterruptedException (org.jowidgets.cap.common.api.exception.ServiceInterruptedException)1 IExecutionCallback (org.jowidgets.cap.common.api.execution.IExecutionCallback)1 IResultCallback (org.jowidgets.cap.common.api.execution.IResultCallback)1 UserQuestionResult (org.jowidgets.cap.common.api.execution.UserQuestionResult)1 IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)1 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)1 IBeanFormBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanFormBluePrint)1 IBeanLinkDialogBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanLinkDialogBluePrint)1 IBeanLinkPanelBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanLinkPanelBluePrint)1 IBeanTableBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanTableBluePrint)1 IServiceProvider (org.jowidgets.service.api.IServiceProvider)1 DefaultServiceProviderHolder (org.jowidgets.service.tools.DefaultServiceProviderHolder)1