Search in sources :

Example 1 with IFilterFactory

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());
            }
        }
    }
}
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 2 with IFilterFactory

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);
}
Also used : IBooleanFilterBuilder(org.jowidgets.cap.common.api.filter.IBooleanFilterBuilder) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IFilterFactory(org.jowidgets.cap.common.api.filter.IFilterFactory) ILinkDeletion(org.jowidgets.cap.common.api.link.ILinkDeletion) LinkedList(java.util.LinkedList)

Aggregations

IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)2 IFilterFactory (org.jowidgets.cap.common.api.filter.IFilterFactory)2 LinkedList (java.util.LinkedList)1 ExecutableCheckException (org.jowidgets.cap.common.api.exception.ExecutableCheckException)1 IArithmeticFilter (org.jowidgets.cap.common.api.filter.IArithmeticFilter)1 IBooleanFilterBuilder (org.jowidgets.cap.common.api.filter.IBooleanFilterBuilder)1 ILinkDeletion (org.jowidgets.cap.common.api.link.ILinkDeletion)1 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)1