Search in sources :

Example 1 with IExecutorService

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

the class ExecutorAnnotationPostProcessor method postProcessAfterInitialization.

@SuppressWarnings("unchecked")
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
    try {
        final ExecutorBean beanAnnotation = beanFactory.findAnnotationOnBean(beanName, ExecutorBean.class);
        if (beanAnnotation != null) {
            final IBeanAccess<? extends IBean> beanAccess = beanAccessProvider.getBeanAccess(beanAnnotation.value());
            final List<String> propertyNames = new BeanTypeUtil(beanAccess.getBeanType()).getPropertyNames();
            final Set<Method> methods = getExecutorMethods(bean);
            for (final Method method : methods) {
                final Object proxy = createExecutorProxy(beanFactory, beanName, method);
                final IExecutorServiceBuilder<IBean, Object> builder = CapServiceToolkit.executorServiceBuilder(beanAccess);
                if (proxy instanceof IBeanExecutor) {
                    builder.setExecutor((IBeanExecutor<IBean, Object>) proxy);
                } else {
                    builder.setExecutor((IBeanListExecutor<IBean, Object>) proxy);
                }
                builder.setBeanDtoFactory(propertyNames);
                final Executor executorAnnotation = method.getAnnotation(Executor.class);
                builder.setAllowDeletedBeans(executorAnnotation.allowDeletedBeans());
                builder.setAllowStaleBeans(executorAnnotation.allowStaleBeans());
                if (executorAnnotation.checker() != DefaultExecutableChecker.class) {
                    try {
                        builder.setExecutableChecker(executorAnnotation.checker().newInstance());
                    } catch (final InstantiationException e) {
                        throw new RuntimeException(e);
                    } catch (final IllegalAccessException e) {
                        throw new RuntimeException(e);
                    }
                }
                IExecutorService<Object> executorService = builder.build();
                if (transactionManager != null) {
                    executorService = new TransactionProxyFactory(transactionManager).createProxy(executorService, "execute");
                }
                final IServiceId<IExecutorService<Object>> serviceId = new ServiceId<IExecutorService<Object>>(executorAnnotation.id(), IExecutorService.class);
                if (isLocal()) {
                    final DefaultCapServiceToolkit defaultCapServiceToolkit = new DefaultCapServiceToolkit();
                    final IServicesDecoratorProvider asyncDecoratorProvider = defaultCapServiceToolkit.serviceDecoratorProvider().asyncDecoratorProvider();
                    final IDecorator<IExecutorService<Object>> decorator = asyncDecoratorProvider.getDecorator(serviceId);
                    executorService = decorator.decorate(executorService);
                }
                SpringServiceProvider.getInstance().addService(serviceId, executorService);
            }
        }
    } catch (final NoSuchBeanDefinitionException e) {
    }
    return bean;
}
Also used : Method(java.lang.reflect.Method) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) IServiceId(org.jowidgets.service.api.IServiceId) ServiceId(org.jowidgets.service.tools.ServiceId) DefaultCapServiceToolkit(org.jowidgets.cap.service.impl.DefaultCapServiceToolkit) ExecutorBean(org.jowidgets.cap.service.api.annotation.ExecutorBean) IBeanExecutor(org.jowidgets.cap.service.api.executor.IBeanExecutor) IBeanListExecutor(org.jowidgets.cap.service.api.executor.IBeanListExecutor) IBeanExecutor(org.jowidgets.cap.service.api.executor.IBeanExecutor) Executor(org.jowidgets.cap.service.api.annotation.Executor) IServicesDecoratorProvider(org.jowidgets.service.api.IServicesDecoratorProvider) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IBean(org.jowidgets.cap.common.api.bean.IBean)

Example 2 with IExecutorService

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

the class ExecutorAnnotationPostProcessorTest method testChangeName.

@Test
public void testChangeName() {
    final IExecutorService<String> service = ServiceProvider.getService(new ServiceId<IExecutorService<String>>("changeName", IExecutorService.class));
    Assert.assertNotNull(service);
    final SyncResultCallback<List<IBeanDto>> result = new SyncResultCallback<List<IBeanDto>>();
    service.execute(result, Collections.singletonList(new BeanKey(0, 0)), "Hans", null);
    final List<IBeanDto> dtos = result.getResultSynchronious();
    Assert.assertNotNull(dtos);
    Assert.assertEquals(1, dtos.size());
    final IBeanDto dto = dtos.get(0);
    Assert.assertEquals(0, dto.getId());
    Assert.assertEquals("Hans", dto.getValue("name"));
}
Also used : BeanKey(org.jowidgets.cap.common.tools.bean.BeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) List(java.util.List) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) Test(org.junit.Test)

Example 3 with IExecutorService

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

the class ExecutorAnnotationPostProcessorTest method testChangeFirstAndLastNameWithComplexParameter.

@Test
public void testChangeFirstAndLastNameWithComplexParameter() {
    final IExecutorService<Map<String, String>> service = ServiceProvider.getService(new ServiceId<IExecutorService<Map<String, String>>>("changeFirstAndLastNameWithComplexParameter", IExecutorService.class));
    Assert.assertNotNull(service);
    final SyncResultCallback<List<IBeanDto>> result = new SyncResultCallback<List<IBeanDto>>();
    final Map<String, String> parameter = new HashMap<String, String>() {

        private static final long serialVersionUID = 1L;

        private final String lastName = "Hansen";

        {
            put("firstName", "Hans");
            put("age", "36");
        }

        @SuppressWarnings("unused")
        public String getLastName() {
            return lastName;
        }
    };
    service.execute(result, Collections.singletonList(new BeanKey(0, 0)), parameter, null);
    final List<IBeanDto> dtos = result.getResultSynchronious();
    Assert.assertNotNull(dtos);
    Assert.assertEquals(1, dtos.size());
    final IBeanDto dto = dtos.get(0);
    Assert.assertEquals(0, dto.getId());
    Assert.assertEquals("Hans HANSEN", dto.getValue("name"));
}
Also used : HashMap(java.util.HashMap) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) BeanKey(org.jowidgets.cap.common.tools.bean.BeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) List(java.util.List) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with IExecutorService

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

the class ExecutorActionBuilderImpl method decorateActionWithPlugins.

private IAction decorateActionWithPlugins(final IAction action) {
    IAction result = action;
    final IPluginProperties properties = PluginProperties.create(IServiceActionDecoratorPlugin.SERVICE_TYPE_PROPERTY_KEY, IExecutorService.class);
    final IExecutorService<?> executorService = (IExecutorService<?>) executor;
    final List<IServiceActionDecoratorPlugin> plugins = PluginProvider.getPlugins(IServiceActionDecoratorPlugin.ID, properties);
    for (final IServiceActionDecoratorPlugin plugin : plugins) {
        result = plugin.decorate(result, executorService);
        if (result == null) {
            return null;
        }
    }
    return result;
}
Also used : IPluginProperties(org.jowidgets.plugin.api.IPluginProperties) IAction(org.jowidgets.api.command.IAction) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) IServiceActionDecoratorPlugin(org.jowidgets.cap.ui.api.plugin.IServiceActionDecoratorPlugin)

Example 5 with IExecutorService

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

the class ExecutorServiceBuilderImpl method build.

@Override
public IExecutorService<PARAM_TYPE> build() {
    final IAdapterFactoryProvider afp = CapServiceToolkit.adapterFactoryProvider();
    final IAdapterFactory<IExecutorService<PARAM_TYPE>, ISyncExecutorService<PARAM_TYPE>> executorAdapterFactory = afp.executor();
    return executorAdapterFactory.createAdapter(buildSyncService());
}
Also used : IAdapterFactoryProvider(org.jowidgets.cap.service.api.adapter.IAdapterFactoryProvider) ISyncExecutorService(org.jowidgets.cap.service.api.adapter.ISyncExecutorService) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService)

Aggregations

IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)8 ArrayList (java.util.ArrayList)5 List (java.util.List)5 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)5 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)5 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)5 Test (org.junit.Test)5 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IAction (org.jowidgets.api.command.IAction)1 IBean (org.jowidgets.cap.common.api.bean.IBean)1 IAdapterFactoryProvider (org.jowidgets.cap.service.api.adapter.IAdapterFactoryProvider)1 ISyncExecutorService (org.jowidgets.cap.service.api.adapter.ISyncExecutorService)1 Executor (org.jowidgets.cap.service.api.annotation.Executor)1 ExecutorBean (org.jowidgets.cap.service.api.annotation.ExecutorBean)1 IBeanExecutor (org.jowidgets.cap.service.api.executor.IBeanExecutor)1 IBeanListExecutor (org.jowidgets.cap.service.api.executor.IBeanListExecutor)1 DefaultCapServiceToolkit (org.jowidgets.cap.service.impl.DefaultCapServiceToolkit)1