Search in sources :

Example 26 with IBeanDto

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

the class BeanDtoFactoryHelper method createDtos.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <BEAN_TYPE> List<IBeanDto> createDtos(final IBeanDtoFactory<? extends BEAN_TYPE> beanDtoFactory, final Collection<? extends BEAN_TYPE> beans, final IExecutionCallback executionCallback) {
    Assert.paramNotNull(beanDtoFactory, "beanDtoFactory");
    Assert.paramNotNull(beans, "beans");
    final List<IBeanDto> result = new LinkedList<IBeanDto>();
    for (final BEAN_TYPE bean : beans) {
        checkCanceled(executionCallback);
        final IBeanDtoFactory factory = beanDtoFactory;
        result.add(factory.createDto(bean));
    }
    return result;
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanDtoFactory(org.jowidgets.cap.service.api.bean.IBeanDtoFactory) LinkedList(java.util.LinkedList)

Example 27 with IBeanDto

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

the class AbstractSyncCreatorServiceImpl method create.

@SuppressWarnings("unchecked")
@Override
public final List<IBeanDto> create(final List<? extends IBeanKey> parentBeanKeys, final Collection<? extends IBeanData> beansData, final IExecutionCallback executionCallback) {
    final List<IBeanDto> result = new LinkedList<IBeanDto>();
    final List<BEAN_TYPE> beans = new ArrayList<BEAN_TYPE>(beansData.size());
    final Map<IdentityHashKey, IBeanData> beanDataMap = new HashMap<IdentityHashKey, IBeanData>();
    for (final IBeanData beanData : beansData) {
        CapServiceToolkit.checkCanceled(executionCallback);
        final BEAN_TYPE bean = createBean((Collection<IBeanKey>) parentBeanKeys, executionCallback);
        beanDataMap.put(new IdentityHashKey(bean), beanData);
        beans.add(bean);
    }
    final IBeanDataMapper<BEAN_TYPE> beanDataMapper = new BeanDataMapper(beanDataMap);
    beforeInitialize((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
    for (final BEAN_TYPE bean : beans) {
        CapServiceToolkit.checkCanceled(executionCallback);
        beanInitializer.initialize(bean, beanDataMapper.getBeanData(bean));
    }
    afterInitialize((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
    checkExecutableStates(beans, executionCallback);
    validate(beans, executionCallback);
    for (final BEAN_TYPE bean : beans) {
        CapServiceToolkit.checkCanceled(executionCallback);
        persistBean((Collection<IBeanKey>) parentBeanKeys, bean, executionCallback);
    }
    afterCreate((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
    for (final BEAN_TYPE bean : beans) {
        CapServiceToolkit.checkCanceled(executionCallback);
        result.add(dtoFactory.createDto(bean));
    }
    CapServiceToolkit.checkCanceled(executionCallback);
    return result;
}
Also used : IBeanDataMapper(org.jowidgets.cap.service.api.creator.IBeanDataMapper) IdentityHashKey(org.jowidgets.util.collection.IdentityHashKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData)

Example 28 with IBeanDto

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

the class BeanTableModelImplTest method testBeanChangeUpdateWithChangedPositionInSorting.

@Test
public void testBeanChangeUpdateWithChangedPositionInSorting() {
    tableModel.getSortModel().setCurrentSorting(Arrays.asList(new ISort() {

        @Override
        public SortOrder getSortOrder() {
            return SortOrder.DESC;
        }

        @Override
        public String getPropertyName() {
            return "value";
        }
    }));
    tableModel.load();
    triggerPageLoading();
    final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
    updatableCallback.finished(new ArrayList<IBeanDto>());
    updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean2, (IBeanDto) bean1)));
    updatableCallback.update(new BeanDtosChangeUpdate(Arrays.asList((IBeanDto) bean1a)));
    assertTrue("2 beans should be loaded, but was " + tableModel.getSize(), tableModel.getSize() == 2);
    assertTrue("the updated bean should be first now", tableModel.getBean(0).getValue("value").equals(bean1a.getValue("value")));
    assertTrue("the previously first bean should now be second", tableModel.getBean(1).getValue("value").equals(bean2.getValue("value")));
}
Also used : BeanDtosChangeUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ISort(org.jowidgets.cap.common.api.sort.ISort) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 29 with IBeanDto

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

the class BeanTableModelImplTest method testBeanDeletionUpdate.

@Test
public void testBeanDeletionUpdate() {
    tableModel.getSortModel().setCurrentSorting(Arrays.asList(new ISort() {

        @Override
        public SortOrder getSortOrder() {
            return SortOrder.ASC;
        }

        @Override
        public String getPropertyName() {
            return "key";
        }
    }));
    tableModel.load();
    triggerPageLoading();
    final IUpdatableResultCallback<IBeanDtosUpdate, List<IBeanDto>> updatableCallback = assertUpdatableResultCallback(resultCallback);
    updatableCallback.finished(new ArrayList<IBeanDto>());
    updatableCallback.update(new BeanDtosInsertionUpdate(Arrays.asList((IBeanDto) bean1, (IBeanDto) bean2)));
    updatableCallback.update(new BeanDtosDeletionUpdate(Arrays.asList(bean1.getId())));
    final int size = tableModel.getSize();
    assertTrue("Only 1 beans should be loaded, but was " + size, size == 1);
    assertTrue("bean2 should be left", tableModel.getBean(0).getValue("value").equals(bean2.getValue("value")));
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) BeanDtosDeletionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosDeletionUpdate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ISort(org.jowidgets.cap.common.api.sort.ISort) IBeanDtosUpdate(org.jowidgets.cap.common.api.bean.IBeanDtosUpdate) BeanDtosInsertionUpdate(org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate) Test(org.junit.Test)

Example 30 with IBeanDto

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

the class BeanSelectionClipboard method create.

public static IBeanSelectionClipboard create(final IBeanSelection<?> beanSelection) {
    final IBeanSelectionClipboardBuilder builder = builder();
    builder.setEntityId(beanSelection.getEntityId());
    builder.setBeanTypeId(beanSelection.getBeanTypeId());
    builder.setBeanType(beanSelection.getBeanType());
    final List<IBeanDto> beans = new LinkedList<IBeanDto>();
    for (final IBeanProxy<?> beanProxy : beanSelection.getSelection()) {
        final IBeanDto beanDto = beanProxy.createUnmodifiedCopy().getBeanDto();
        if (beanProxy.isTransient()) {
            beans.add(new TransientBeanDto(beanDto));
        } else {
            beans.add(beanDto);
        }
    }
    builder.setBeans(beans);
    return builder.build();
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList)

Aggregations

IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)40 LinkedList (java.util.LinkedList)20 ArrayList (java.util.ArrayList)16 List (java.util.List)12 Test (org.junit.Test)12 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)8 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)7 IBeanDtosUpdate (org.jowidgets.cap.common.api.bean.IBeanDtosUpdate)5 IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)5 BeanDtosInsertionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate)5 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)5 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)4 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 HashMap (java.util.HashMap)3 ISort (org.jowidgets.cap.common.api.sort.ISort)3 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)3 TableCellBluePrint (org.jowidgets.tools.model.table.TableCellBluePrint)3 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)2 BeanDtosChangeUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate)2 IBeanSelectionClipboard (org.jowidgets.cap.ui.api.clipboard.IBeanSelectionClipboard)2