Search in sources :

Example 1 with SyncResultCallback

use of org.jowidgets.cap.common.tools.execution.SyncResultCallback in project jo-client-platform by jo-source.

the class ExecutorAnnotationPostProcessorTest method testChangeFirstAndLastNameWithComplexParameter.

@Test
public void testChangeFirstAndLastNameWithComplexParameter() {
    final IExecutorService<Map<String, String>> service = ServiceProvider.getService(new ServiceId<IExecutorService<Map<String, String>>>("changeFirstAndLastNameWithComplexParameter", IExecutorService.class));
    Assert.assertNotNull(service);
    final SyncResultCallback<List<IBeanDto>> result = new SyncResultCallback<List<IBeanDto>>();
    final Map<String, String> parameter = new HashMap<String, String>() {

        private static final long serialVersionUID = 1L;

        private final String lastName = "Hansen";

        {
            put("firstName", "Hans");
            put("age", "36");
        }

        @SuppressWarnings("unused")
        public String getLastName() {
            return lastName;
        }
    };
    service.execute(result, Collections.singletonList(new BeanKey(0, 0)), parameter, 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 : HashMap(java.util.HashMap) IExecutorService(org.jowidgets.cap.common.api.service.IExecutorService) 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) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with SyncResultCallback

use of org.jowidgets.cap.common.tools.execution.SyncResultCallback in project jo-client-platform by jo-source.

the class ExecutorAnnotationPostProcessorTest method testChangeName.

@Test
public void testChangeName() {
    final IExecutorService<String> service = ServiceProvider.getService(new ServiceId<IExecutorService<String>>("changeName", 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 3 with SyncResultCallback

use of org.jowidgets.cap.common.tools.execution.SyncResultCallback in project jo-client-platform by jo-source.

the class UniqueConstraintCheckerImpl method checkCreation.

@Override
public void checkCreation(final Collection<? extends IBeanData> beansData, final IExecutionCallback executionCallback) {
    final IFilter filter = createFilter(beansData);
    final SyncResultCallback<Integer> resultCallback = new SyncResultCallback<Integer>();
    final List<IBeanKey> parentBeanKeys = Collections.emptyList();
    this.readerService.count(resultCallback, parentBeanKeys, filter, null, executionCallback);
    final Integer result = resultCallback.getResultSynchronious();
    if (result != null && result.intValue() > 0) {
        throw new UniqueConstraintViolationException(propertyNames);
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilter(org.jowidgets.cap.common.api.filter.IFilter) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback) UniqueConstraintViolationException(org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)

Example 4 with SyncResultCallback

use of org.jowidgets.cap.common.tools.execution.SyncResultCallback in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method checkExecutableState.

private void checkExecutableState(final ILinkCreation link, final IExecutionCallback executionCallback) {
    final Collection<IBeanKey> linkableBeans = link.getLinkableBeans();
    if (!EmptyCheck.isEmpty(linkableBeans)) {
        for (final IBeanKey sourceBean : link.getSourceBeans()) {
            final IFilterFactory filterFactory = CapCommonToolkit.filterFactory();
            final Object[] linkableKeys = new Object[linkableBeans.size()];
            int index = 0;
            for (final IBeanKey key : linkableBeans) {
                linkableKeys[index] = key.getId();
                index++;
            }
            final IArithmeticFilter filter;
            if (destinationProperties != null) {
                filter = filterFactory.arithmeticFilter(destinationProperties.getKeyPropertyName(), ArithmeticOperator.CONTAINS_ANY, linkableKeys);
            } else if (sourceProperties != null) {
                filter = filterFactory.arithmeticFilter(sourceProperties.getKeyPropertyName(), ArithmeticOperator.CONTAINS_ANY, linkableKeys);
            } else {
                throw new IllegalStateException("Neither the source not the destination properties are defined");
            }
            final SyncResultCallback<Integer> result = new SyncResultCallback<Integer>();
            linkableReaderService.count(result, Collections.singletonList(sourceBean), filter, null, executionCallback);
            final Integer count = result.getResultSynchronious();
            if (count == null || count.intValue() < linkableKeys.length) {
                throw new ExecutableCheckException(sourceBean.getId(), "Beans are not linkable", DATASETS_CAN_NOT_BE_LINKED.get());
            }
        }
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilterFactory(org.jowidgets.cap.common.api.filter.IFilterFactory) IArithmeticFilter(org.jowidgets.cap.common.api.filter.IArithmeticFilter) ExecutableCheckException(org.jowidgets.cap.common.api.exception.ExecutableCheckException) SyncResultCallback(org.jowidgets.cap.common.tools.execution.SyncResultCallback)

Example 5 with SyncResultCallback

use of org.jowidgets.cap.common.tools.execution.SyncResultCallback 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)

Aggregations

IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)7 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)5 IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)5 Test (org.junit.Test)5 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutableCheckException (org.jowidgets.cap.common.api.exception.ExecutableCheckException)1 UniqueConstraintViolationException (org.jowidgets.cap.common.api.exception.UniqueConstraintViolationException)1 IArithmeticFilter (org.jowidgets.cap.common.api.filter.IArithmeticFilter)1 IFilter (org.jowidgets.cap.common.api.filter.IFilter)1 IFilterFactory (org.jowidgets.cap.common.api.filter.IFilterFactory)1