use of org.jowidgets.cap.common.api.filter.IFilterFactory 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.filter.IFilterFactory 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);
}
Aggregations