Search in sources :

Example 11 with IBeanKey

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

Example 12 with IBeanKey

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());
            }
        }
    }
}
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 13 with IBeanKey

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;
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) BeanException(org.jowidgets.cap.common.api.exception.BeanException) DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) LinkedList(java.util.LinkedList)

Example 14 with IBeanKey

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

Example 15 with IBeanKey

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());
    }
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) BeanException(org.jowidgets.cap.common.api.exception.BeanException) DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException)

Aggregations

IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)27 LinkedList (java.util.LinkedList)15 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)5 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)4 DeletedBeanException (org.jowidgets.cap.common.api.exception.DeletedBeanException)4 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 List (java.util.List)3 ILinkDeletion (org.jowidgets.cap.common.api.link.ILinkDeletion)3 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 BeanException (org.jowidgets.cap.common.api.exception.BeanException)2 StaleBeanException (org.jowidgets.cap.common.api.exception.StaleBeanException)2 IFilter (org.jowidgets.cap.common.api.filter.IFilter)2 IFilterFactory (org.jowidgets.cap.common.api.filter.IFilterFactory)2 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)2 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)2 Node (org.neo4j.graphdb.Node)2