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"));
}
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"));
}
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"));
}
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);
}
}
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);
}
};
}
Aggregations