Search in sources :

Example 1 with ICreatorService

use of org.jowidgets.cap.common.api.service.ICreatorService 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 ICreatorService

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

the class BeanTableCreatorActionBuilderFactory method createBuilder.

static <BEAN_TYPE> ICreatorActionBuilder<BEAN_TYPE> createBuilder(final IBeanTable<BEAN_TYPE> table) {
    final IBeanTableModel<BEAN_TYPE> model = table.getModel();
    final IBeanListModel<BEAN_TYPE> wrappedModel = new ScrollToEndAtAddTableModel<BEAN_TYPE>(table);
    final ICapActionFactory actionFactory = CapUiToolkit.actionFactory();
    final ICreatorActionBuilder<BEAN_TYPE> builder = actionFactory.creatorActionBuilder(model.getEntityId(), model.getBeanType(), wrappedModel);
    builder.setBeanPropertyValidators(model.getBeanPropertyValidators());
    builder.setEntityLabelSingular(model.getEntityLabelSingular());
    builder.setParentBeansProvider(new IProvider<List<IBeanKey>>() {

        @Override
        public List<IBeanKey> get() {
            return model.getParentBeanKeys();
        }
    });
    final ICreatorService creatorService = model.getCreatorService();
    if (creatorService != null) {
        builder.setCreatorService(creatorService);
    }
    // Bean form must have all attributes because a later pluged layouter may use them
    final IBeanFormBluePrint<BEAN_TYPE> beanFormBp = CapUiToolkit.bluePrintFactory().beanForm(model.getEntityId(), model.getAttributes());
    builder.setAttributes(model.getAttributes());
    builder.setBeanForm(beanFormBp);
    builder.addExecutionInterceptor(new ExecutionInterceptorAdapter<List<IBeanDto>>() {

        @Override
        public void beforeExecution(final IExecutionContext executionContext, final IVetoable continueExecution) {
            final int pageCount = model.getPageCount();
            if (pageCount > 0 && !model.isPageCreated(pageCount - 1)) {
                model.loadPage(pageCount - 1);
            }
        }
    });
    return builder;
}
Also used : IExecutionContext(org.jowidgets.api.command.IExecutionContext) IVetoable(org.jowidgets.common.types.IVetoable) ICapActionFactory(org.jowidgets.cap.ui.api.command.ICapActionFactory) List(java.util.List) ICreatorService(org.jowidgets.cap.common.api.service.ICreatorService)

Example 3 with ICreatorService

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

the class CreatorActionBuilderImpl method setCreatorService.

@Override
public ICreatorActionBuilder<BEAN_TYPE> setCreatorService(final IServiceId<ICreatorService> creatorServiceId) {
    checkExhausted();
    Assert.paramNotNull(creatorServiceId, "creatorServiceId");
    final ICreatorService service = ServiceProvider.getService(creatorServiceId);
    if (service == null) {
        throw new IllegalArgumentException("No creator service found for the id '" + creatorServiceId + "'.");
    }
    return setCreatorService(service);
}
Also used : ICreatorService(org.jowidgets.cap.common.api.service.ICreatorService)

Aggregations

ICreatorService (org.jowidgets.cap.common.api.service.ICreatorService)3 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IExecutionContext (org.jowidgets.api.command.IExecutionContext)1 IProperty (org.jowidgets.cap.common.api.bean.IProperty)1 IDeleterService (org.jowidgets.cap.common.api.service.IDeleterService)1 IUpdaterService (org.jowidgets.cap.common.api.service.IUpdaterService)1 IBeanServicesProviderBuilder (org.jowidgets.cap.service.api.entity.IBeanServicesProviderBuilder)1 IJpaServiceFactory (org.jowidgets.cap.service.jpa.api.IJpaServiceFactory)1 TransactionProxyFactory (org.jowidgets.cap.service.spring.TransactionProxyFactory)1 ICapActionFactory (org.jowidgets.cap.ui.api.command.ICapActionFactory)1 IVetoable (org.jowidgets.common.types.IVetoable)1