Search in sources :

Example 1 with IBeanServicesProviderBuilder

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

the class JpaEntityService method createServicesProvider.

private <T extends IBean> IBeanServicesProvider createServicesProvider(final Class<? extends IBean> beanInterface, final Class<T> beanType, final IBeanDtoDescriptor descriptor) {
    final IBeanServicesProviderBuilder builder = CapServiceToolkit.beanServicesProviderBuilder(SpringServiceProvider.getInstance(), IEntityService.ID, beanType, beanInterface);
    final List<String> propertyNames = new LinkedList<String>();
    for (final IProperty property : descriptor.getProperties()) {
        propertyNames.add(property.getName());
    }
    final IJpaServiceFactory serviceFactory = JpaServiceToolkit.serviceFactory();
    final TransactionProxyFactory tpf = new TransactionProxyFactory(transactionManager);
    final ICreatorService creatorService = serviceFactory.creatorService(beanType, propertyNames);
    builder.setCreatorService(tpf.createProxy(creatorService, "create"));
    final IDeleterService deleterService = serviceFactory.deleterService(beanType);
    builder.setDeleterService(tpf.createProxy(deleterService, "delete"));
    // TODO: MvR -> Check genericity...
    final ICriteriaQueryCreatorBuilder<Void> queryBuilder = JpaQueryToolkit.criteriaQueryCreatorBuilder(beanType);
    if (ParentLinkHelper.hasParent(beanType)) {
        queryBuilder.setParentPropertyName("parent");
    }
    final IReaderService<Void> readerService = serviceFactory.readerService(beanType, queryBuilder.build(), propertyNames);
    builder.setReaderService(readerService);
    final IBeanAccess<T> beanAccess = serviceFactory.beanAccess(beanType);
    builder.setRefreshService(CapServiceToolkit.refreshServiceBuilder(beanAccess).setBeanDtoFactory(propertyNames).build());
    final IUpdaterService updaterService = CapServiceToolkit.updaterServiceBuilder(beanAccess).setBeanDtoFactoryAndBeanModifier(propertyNames).build();
    builder.setUpdaterService(tpf.createProxy(updaterService, "update"));
    return builder.build();
}
Also used : TransactionProxyFactory(org.jowidgets.cap.service.spring.TransactionProxyFactory) IUpdaterService(org.jowidgets.cap.common.api.service.IUpdaterService) LinkedList(java.util.LinkedList) IBeanServicesProviderBuilder(org.jowidgets.cap.service.api.entity.IBeanServicesProviderBuilder) IProperty(org.jowidgets.cap.common.api.bean.IProperty) IDeleterService(org.jowidgets.cap.common.api.service.IDeleterService) ICreatorService(org.jowidgets.cap.common.api.service.ICreatorService) IJpaServiceFactory(org.jowidgets.cap.service.jpa.api.IJpaServiceFactory)

Example 2 with IBeanServicesProviderBuilder

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

the class AbstractBeanServiceFactory method beanServicesBuilder.

@Override
public <BEAN_TYPE extends IBean> IBeanServicesProviderBuilder beanServicesBuilder(final IServiceRegistry registry, final Object entityId, final Class<? extends BEAN_TYPE> beanType, final Object beanTypeId, final IBeanDtoFactory<BEAN_TYPE> beanDtoFactory, final IBeanInitializer<BEAN_TYPE> beanInitializer, final IBeanModifier<BEAN_TYPE> beanModifier) {
    Assert.paramNotNull(registry, "registry");
    Assert.paramNotNull(entityId, "entityId");
    Assert.paramNotNull(beanType, "beanType");
    Assert.paramNotNull(beanDtoFactory, "beanDtoFactory");
    Assert.paramNotNull(beanInitializer, "beanInitializer");
    Assert.paramNotNull(beanModifier, "beanModifier");
    final IBeanServicesProviderBuilder builder;
    builder = CapServiceToolkit.beanServicesProviderBuilder(registry, IEntityService.ID, beanType, entityId);
    // create bean access
    final IBeanAccess<BEAN_TYPE> beanAccess = beanAccess(beanType, beanTypeId);
    // set creator service
    final ICreatorServiceBuilder<BEAN_TYPE> creatorServiceBuilder = creatorServiceBuilder(beanType, beanTypeId);
    creatorServiceBuilder.setBeanDtoFactory(beanDtoFactory).setBeanInitializer(beanInitializer);
    builder.setCreatorService(creatorServiceBuilder.build());
    // set reader service
    final IReaderService<Void> readerService = readerService(beanType, beanTypeId, beanDtoFactory);
    builder.setReaderService(readerService);
    // set refresh
    builder.setRefreshService(CapServiceToolkit.refreshServiceBuilder(beanAccess).setBeanDtoFactory(beanDtoFactory).build());
    // set updater service
    final IUpdaterServiceBuilder<BEAN_TYPE> updaterServiceBuilder = CapServiceToolkit.updaterServiceBuilder(beanAccess);
    updaterServiceBuilder.setBeanDtoFactory(beanDtoFactory).setBeanModifier(beanModifier);
    builder.setUpdaterService(updaterServiceBuilder.build());
    // set deleter service
    builder.setDeleterService(deleterService(beanType, beanTypeId));
    return builder;
}
Also used : IBeanServicesProviderBuilder(org.jowidgets.cap.service.api.entity.IBeanServicesProviderBuilder)

Aggregations

IBeanServicesProviderBuilder (org.jowidgets.cap.service.api.entity.IBeanServicesProviderBuilder)2 LinkedList (java.util.LinkedList)1 IProperty (org.jowidgets.cap.common.api.bean.IProperty)1 ICreatorService (org.jowidgets.cap.common.api.service.ICreatorService)1 IDeleterService (org.jowidgets.cap.common.api.service.IDeleterService)1 IUpdaterService (org.jowidgets.cap.common.api.service.IUpdaterService)1 IJpaServiceFactory (org.jowidgets.cap.service.jpa.api.IJpaServiceFactory)1 TransactionProxyFactory (org.jowidgets.cap.service.spring.TransactionProxyFactory)1