Search in sources :

Example 31 with IBeanDto

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

the class ExecutorAnnotationPostProcessorTest method testCreateUser.

@Test
public void testCreateUser() {
    final IExecutorService<String> service = ServiceProvider.getService(new ServiceId<IExecutorService<String>>("createUser", IExecutorService.class));
    Assert.assertNotNull(service);
    final SyncResultCallback<List<IBeanDto>> result = new SyncResultCallback<List<IBeanDto>>();
    service.execute(result, new ArrayList<IBeanKey>(), "Hans Meier", null);
    final List<IBeanDto> dtos = result.getResultSynchronious();
    Assert.assertNotNull(dtos);
    Assert.assertEquals(1, dtos.size());
    final IBeanDto dto = dtos.get(0);
    Assert.assertEquals(1, dto.getId());
    Assert.assertEquals("Hans Meier", dto.getValue("name"));
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) ArrayList(java.util.ArrayList) List(java.util.List) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) Test(org.junit.Test)

Example 32 with IBeanDto

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

the class ExecutorAnnotationPostProcessorTest method testChangeFirstAndLastName.

@Test
public void testChangeFirstAndLastName() {
    final IExecutorService<String[]> service = ServiceProvider.getService(new ServiceId<IExecutorService<String[]>>("changeFirstAndLastName", IExecutorService.class));
    Assert.assertNotNull(service);
    final SyncResultCallback<List<IBeanDto>> result = new SyncResultCallback<List<IBeanDto>>();
    service.execute(result, Collections.singletonList(new BeanKey(0, 0)), new String[] { "Hans", "Hansen" }, 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"));
}
Also used : BeanKey(org.jowidgets.cap.common.tools.bean.BeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) List(java.util.List) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) Test(org.junit.Test)

Example 33 with IBeanDto

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

the class ExecutorAnnotationPostProcessorTest method testChangeNameList.

@Test
public void testChangeNameList() {
    final IExecutorService<String> service = ServiceProvider.getService(new ServiceId<IExecutorService<String>>("changeNameList", 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"));
}
Also used : BeanKey(org.jowidgets.cap.common.tools.bean.BeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ArrayList(java.util.ArrayList) List(java.util.List) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) Test(org.junit.Test)

Example 34 with IBeanDto

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

the class BeanTableModelImpl method updateBeansInAddedData.

private void updateBeansInAddedData(final Map<Object, IBeanDto> beansToUpateById, final boolean sorted, final Comparator<IBeanDto> comparator) {
    boolean sortingChanged = false;
    IBeanProxy<BEAN_TYPE> previousBean = null;
    IBeanProxy<BEAN_TYPE> lastUpdatedBean = null;
    for (final IBeanProxy<BEAN_TYPE> beanProxy : addedData) {
        if (beansToUpateById.isEmpty()) {
            break;
        }
        final IBeanDto beanToUpdate = beansToUpateById.get(beanProxy.getId());
        if (beanToUpdate != null) {
            beanProxy.update(beanToUpdate);
            beansToUpateById.remove(beanProxy.getId());
            if (sorted && !sortingChanged && previousBean != null && comparator.compare(previousBean, beanProxy) > 0) {
                sortingChanged = true;
            }
        }
        if (sorted && !sortingChanged && lastUpdatedBean != null && comparator.compare(lastUpdatedBean, beanProxy) > 0) {
            sortingChanged = true;
        }
        if (beanToUpdate != null) {
            lastUpdatedBean = beanProxy;
        } else {
            lastUpdatedBean = null;
        }
        previousBean = beanProxy;
    }
    if (!beansToUpateById.isEmpty()) {
        LOGGER.warn("Cannot find beans for the following updates:" + beansToUpateById.values().toString());
    }
    if (sorted && sortingChanged) {
        final List<IBeanProxy<BEAN_TYPE>> selectedBeans = getSelectedBeans();
        Collections.sort(addedData, comparator);
        int rowIndex = rowCountOfPages;
        for (final IBeanProxy<BEAN_TYPE> bean : addedData) {
            updateRowIndexOfBean(bean, rowIndex);
            rowIndex += 1;
        }
        setSelectedBeans(selectedBeans);
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) TableCellBluePrint(org.jowidgets.tools.model.table.TableCellBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 35 with IBeanDto

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

the class BeanLinkCreatorCommand method createResultCallback.

private IResultCallback<List<IBeanDto>> createResultCallback(final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IExecutionContext executionContext) {
    return new AbstractUiResultCallback<List<IBeanDto>>() {

        @Override
        protected void finishedUi(final List<IBeanDto> result) {
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
            }
            if (linkedModel != null) {
                if (Cardinality.LESS_OR_EQUAL_ONE.equals(linkedCardinality)) {
                    linkedModel.removeAllBeans();
                }
                for (final IBeanDto resultBean : result) {
                    linkedModel.addBeanDto(resultBean);
                }
            }
            executionObservable.fireAfterExecutionSuccess(executionContext, result);
        }

        @Override
        protected void exceptionUi(final Throwable exception) {
            int beanIndex = 0;
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
                if (!(exception instanceof ServiceCanceledException)) {
                    bean.addMessage(exceptionConverter.convert(getShortErrorMessage(), selection, beanIndex++, bean, exception));
                }
            }
            executionObservable.fireAfterExecutionError(executionContext, exception);
        }

        private String getShortErrorMessage() {
            final String actionText = executionContext.getAction().getText().replaceAll("\\.", "").trim();
            return MessageReplacer.replace(SHORT_ERROR.get(), actionText);
        }
    };
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) List(java.util.List) LinkedList(java.util.LinkedList) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException) IBeanLinkPanelBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanLinkPanelBluePrint) IBeanLinkDialogBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanLinkDialogBluePrint) IBeanTableBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanTableBluePrint) IBeanFormBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanFormBluePrint)

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