Search in sources :

Example 1 with ServiceId

use of org.jowidgets.service.tools.ServiceId 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 ServiceId

use of org.jowidgets.service.tools.ServiceId in project jo-client-platform by jo-source.

the class ServicePostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
    try {
        final CapService serviceAnnotation = beanFactory.findAnnotationOnBean(beanName, CapService.class);
        if (serviceAnnotation != null) {
            final Class<?> serviceType;
            if (serviceAnnotation.type() != void.class) {
                serviceType = serviceAnnotation.type();
            } else {
                if (bean.getClass().getInterfaces().length == 0) {
                    throw new RuntimeException(beanName + " must implement at least one interface or type must be set on @CapService annotation");
                }
                serviceType = bean.getClass().getInterfaces()[0];
            }
            String id = serviceAnnotation.id();
            if (id.isEmpty()) {
                id = serviceType.getName();
            }
            final IServiceId<Object> serviceId = new ServiceId<Object>(id, serviceType);
            SpringServiceProvider.getInstance().addService(serviceId, beanProxyFactory.createProxy(beanName, serviceType));
        }
    } catch (final NoSuchBeanDefinitionException e) {
    }
    return bean;
}
Also used : CapService(org.jowidgets.cap.service.api.annotation.CapService) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IServiceId(org.jowidgets.service.api.IServiceId) ServiceId(org.jowidgets.service.tools.ServiceId)

Example 3 with ServiceId

use of org.jowidgets.service.tools.ServiceId in project jo-client-platform by jo-source.

the class JpaReaderAnnotationPostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
    try {
        final ReaderBean beanAnnotation = beanFactory.findAnnotationOnBean(beanName, ReaderBean.class);
        if (beanAnnotation != null) {
            final Class<? extends IBean> beanType = beanAnnotation.type();
            final List<String> propertyNames = new BeanTypeUtil(beanType).getPropertyNames();
            final Set<Method> methods = getReaderMethods(bean);
            for (final Method method : methods) {
                final IPredicateCreator<Object> predicateCreator = createPredicateCreator(beanFactory, beanName, method);
                final ICriteriaQueryCreatorBuilder<Object> queryCreatorBuilder = JpaQueryToolkit.criteriaQueryCreatorBuilder(beanType).setCaseSensitve(!beanAnnotation.caseInsensitive());
                // TODO: MvR -> Check genericity...
                if (ParentLinkHelper.hasParent(beanType)) {
                    queryCreatorBuilder.setParentPropertyName(beanAnnotation.parentPropertyName());
                }
                if (predicateCreator != null) {
                    queryCreatorBuilder.addPredicateCreator(predicateCreator);
                }
                for (final Map.Entry<String, ? extends ICustomFilterPredicateCreator<?>> entry : customFilterPredicateCreators.entrySet()) {
                    final String filterName = entry.getKey();
                    @SuppressWarnings("unchecked") final ICustomFilterPredicateCreator<Object> customFilterPredicateCreator = (ICustomFilterPredicateCreator<Object>) entry.getValue();
                    queryCreatorBuilder.addCustomFilterPredicateCreator(filterName, customFilterPredicateCreator);
                }
                final IQueryCreator<Object> queryCreator = queryCreatorBuilder.build();
                final IReaderService<Object> readerService = JpaServiceToolkit.serviceFactory().readerService(beanType, queryCreator, propertyNames);
                final Reader executorAnnotation = method.getAnnotation(Reader.class);
                final IServiceId<IReaderService<Void>> serviceId = new ServiceId<IReaderService<Void>>(executorAnnotation.value(), IReaderService.class);
                SpringServiceProvider.getInstance().addService(serviceId, readerService);
            }
        }
    } catch (final NoSuchBeanDefinitionException e) {
    }
    return bean;
}
Also used : BeanTypeUtil(org.jowidgets.cap.service.spring.BeanTypeUtil) ICustomFilterPredicateCreator(org.jowidgets.cap.service.jpa.api.query.ICustomFilterPredicateCreator) Reader(org.jowidgets.cap.service.api.annotation.Reader) Method(java.lang.reflect.Method) IReaderService(org.jowidgets.cap.common.api.service.IReaderService) IServiceId(org.jowidgets.service.api.IServiceId) ServiceId(org.jowidgets.service.tools.ServiceId) ReaderBean(org.jowidgets.cap.service.api.annotation.ReaderBean) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Map(java.util.Map)

Example 4 with ServiceId

use of org.jowidgets.service.tools.ServiceId in project jo-client-platform by jo-source.

the class CapServiceProviderBuilder method addLookUpService.

public void addLookUpService(final Object lookUpId, final ISyncLookUpService lookUpService) {
    final IAdapterFactory<ILookUpService, ISyncLookUpService> adapterFactoryProvider;
    adapterFactoryProvider = CapServiceToolkit.adapterFactoryProvider().lookup();
    final ILookUpService asyncService = adapterFactoryProvider.createAdapter(lookUpService);
    final ServiceId<ILookUpService> serviceId = new ServiceId<ILookUpService>(lookUpId, ILookUpService.class);
    addService(serviceId, asyncService);
}
Also used : ISyncLookUpService(org.jowidgets.cap.service.api.adapter.ISyncLookUpService) ILookUpService(org.jowidgets.cap.common.api.service.ILookUpService) IServiceId(org.jowidgets.service.api.IServiceId) ServiceId(org.jowidgets.service.tools.ServiceId)

Aggregations

IServiceId (org.jowidgets.service.api.IServiceId)4 ServiceId (org.jowidgets.service.tools.ServiceId)4 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)3 Method (java.lang.reflect.Method)2 Map (java.util.Map)1 IBean (org.jowidgets.cap.common.api.bean.IBean)1 IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)1 ILookUpService (org.jowidgets.cap.common.api.service.ILookUpService)1 IReaderService (org.jowidgets.cap.common.api.service.IReaderService)1 ISyncLookUpService (org.jowidgets.cap.service.api.adapter.ISyncLookUpService)1 CapService (org.jowidgets.cap.service.api.annotation.CapService)1 Executor (org.jowidgets.cap.service.api.annotation.Executor)1 ExecutorBean (org.jowidgets.cap.service.api.annotation.ExecutorBean)1 Reader (org.jowidgets.cap.service.api.annotation.Reader)1 ReaderBean (org.jowidgets.cap.service.api.annotation.ReaderBean)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 ICustomFilterPredicateCreator (org.jowidgets.cap.service.jpa.api.query.ICustomFilterPredicateCreator)1 BeanTypeUtil (org.jowidgets.cap.service.spring.BeanTypeUtil)1