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