use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class LinkDeleterServiceImpl method deleteInverseDirectLinks.
private void deleteInverseDirectLinks(final Collection<? extends ILinkDeletion> linksDeletions, final IExecutionCallback executionCallback) {
for (final ILinkDeletion linkDeletion : linksDeletions) {
final IBeanKey sourceKey = linkDeletion.getSourceKey();
resetDirectLink(destinationProperties, sourceKey, sourceBeanAccess, executionCallback);
}
}
use of org.jowidgets.cap.common.api.bean.IBeanKey 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());
}
}
}
}
use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class LinkCreatorServiceImpl method getBeans.
private <BEAN_TYPE extends IBean> List<IBeanDto> getBeans(final IBeanDto linkedBean, final IEntityLinkProperties linkProperties, final Collection<IBeanKey> beanKeys, final IBeanAccess<BEAN_TYPE> beanAccess, final IBeanDtoFactory<BEAN_TYPE> dtoFactory, final IExecutionCallback executionCallback) {
final List<IBeanDto> result = new LinkedList<IBeanDto>();
for (final IBeanKey beanKey : beanKeys) {
CapServiceToolkit.checkCanceled(executionCallback);
final List<IBeanKey> singletonList = Collections.singletonList(beanKey);
final List<BEAN_TYPE> beans = beanAccess.getBeans(singletonList, executionCallback);
if (!EmptyCheck.isEmpty(beans) && beans.size() == 1) {
final BEAN_TYPE bean = beans.iterator().next();
if (linkedBean != null && linkProperties != null) {
final Object sourceKey = linkedBean.getValue(linkProperties.getKeyPropertyName());
BeanUtils.setProperty(bean, linkProperties.getForeignKeyPropertyName(), sourceKey);
}
result.add(dtoFactory.createDto(bean));
} else if (!EmptyCheck.isEmpty(beans) && beans.size() > 1) {
throw new BeanException(beanKey.getId(), "More than one bean found for the key '" + beanKey + "'");
} else {
throw new DeletedBeanException(beanKey.getId());
}
}
return result;
}
use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class LinkDeleterServiceImpl method deleteStandardLinks.
private void deleteStandardLinks(final Collection<? extends ILinkDeletion> linksDeletions, final IExecutionCallback executionCallback) {
final List<IBeanKey> sourceKeys = new LinkedList<IBeanKey>();
final List<IBeanKey> destinationKeys = new LinkedList<IBeanKey>();
final IFilterFactory filterFactory = CapCommonToolkit.filterFactory();
final IBooleanFilterBuilder linkReaderFilterBuilder = filterFactory.booleanFilterBuilder();
linkReaderFilterBuilder.setOperator(BooleanOperator.OR);
for (final ILinkDeletion linkDeletion : linksDeletions) {
final IBeanKey sourceKey = linkDeletion.getSourceKey();
final IBeanKey destinationKey = linkDeletion.getDestinationKey();
if (linkDeletion.deleteSource()) {
sourceKeys.add(sourceKey);
}
if (linkDeletion.deleteDestination()) {
destinationKeys.add(destinationKey);
}
linkReaderFilterBuilder.addFilter(createLinkFilter(sourceKey, destinationKey));
if (symmetric) {
linkReaderFilterBuilder.addFilter(createLinkFilter(destinationKey, sourceKey));
}
}
if (!linkReaderFilterBuilder.isEmpty()) {
deleteLinks(linkReaderFilterBuilder.build(), linksDeletions.size() * 10, executionCallback);
}
deleteKeys(destinationKeys, linkedDeleterService, executionCallback);
deleteKeys(sourceKeys, sourceDeleterService, executionCallback);
}
use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.
the class LinkDeleterServiceImpl method resetDirectLink.
private <BEAN_TYPE extends IBean> void resetDirectLink(final IEntityLinkProperties linkProperties, final IBeanKey beanKey, final IBeanAccess<BEAN_TYPE> beanAccess, final IExecutionCallback executionCallback) {
CapServiceToolkit.checkCanceled(executionCallback);
final List<IBeanKey> singletonList = Collections.singletonList(beanKey);
final List<BEAN_TYPE> beans = beanAccess.getBeans(singletonList, executionCallback);
if (!EmptyCheck.isEmpty(beans) && beans.size() == 1) {
final BEAN_TYPE bean = beans.iterator().next();
BeanUtils.setProperty(bean, linkProperties.getForeignKeyPropertyName(), null);
} else if (!EmptyCheck.isEmpty(beans) && beans.size() > 1) {
throw new BeanException(beanKey.getId(), "More than one bean found for the key '" + beanKey + "'");
} else {
throw new DeletedBeanException(beanKey.getId());
}
}
Aggregations