Search in sources :

Example 1 with DeletedBeanException

use of org.jowidgets.cap.common.api.exception.DeletedBeanException in project jo-client-platform by jo-source.

the class SyncDeleterService method delete.

@Override
public void delete(final Collection<? extends IBeanKey> keys, final IExecutionCallback executionCallback) {
    for (final IBeanKey key : keys) {
        final IBean bean = data.getData(key.getId());
        if (!allowDeletedData && bean == null) {
            throw new DeletedBeanException(key.getId());
        }
        if (!allowStaleData && bean != null && bean.getVersion() != key.getVersion()) {
            throw new StaleBeanException(key.getId());
        }
        data.deleteData(key.getId());
    }
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) StaleBeanException(org.jowidgets.cap.common.api.exception.StaleBeanException) IBean(org.jowidgets.cap.common.api.bean.IBean)

Example 2 with DeletedBeanException

use of org.jowidgets.cap.common.api.exception.DeletedBeanException in project jo-client-platform by jo-source.

the class SyncExecutorServiceImpl method checkBeans.

private void checkBeans(final Collection<? extends IBeanKey> keys, final List<BEAN_TYPE> beans, final IExecutionCallback executionCallback) {
    // put beans into map to access them faster at the next step
    final Map<Object, BEAN_TYPE> beanMap = new HashMap<Object, BEAN_TYPE>();
    for (final BEAN_TYPE bean : beans) {
        beanMap.put(getId(bean), bean);
        CapServiceToolkit.checkCanceled(executionCallback);
    }
    // check if beans are deleted or stale
    for (final IBeanKey key : keys) {
        final BEAN_TYPE bean = beanMap.get(key.getId());
        if (!allowDeletedBeans && bean == null) {
            throw new DeletedBeanException(key.getId());
        } else {
            if (!allowStaleBeans && key.getVersion() != getVersion(bean)) {
                throw new StaleBeanException(key.getId());
            }
        }
        CapServiceToolkit.checkCanceled(executionCallback);
    }
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) HashMap(java.util.HashMap) StaleBeanException(org.jowidgets.cap.common.api.exception.StaleBeanException)

Example 3 with DeletedBeanException

use of org.jowidgets.cap.common.api.exception.DeletedBeanException 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 4 with DeletedBeanException

use of org.jowidgets.cap.common.api.exception.DeletedBeanException 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)

Example 5 with DeletedBeanException

use of org.jowidgets.cap.common.api.exception.DeletedBeanException in project jo-client-platform by jo-source.

the class RelationshipBean method setEndNodeId.

protected void setEndNodeId(final Object beanTypeId, final RelationshipType relationshipType, final Object relationBeanTypeId, final Object id) {
    Assert.paramNotNull(beanTypeId, "beanTypeId");
    Assert.paramNotNull(relationshipType, "relationshipType");
    Assert.paramNotNull(id, "id");
    final Node endNode = NodeAccess.findNode(beanTypeId, id);
    if (endNode == null) {
        throw new DeletedBeanException(id);
    }
    final Node startNode = getStartNode();
    if (startNode != null) {
        createRelationship(relationBeanTypeId, relationshipType, startNode, endNode);
        tempStartNode = null;
        tempEndNode = null;
    } else {
        tempEndNode = endNode;
    }
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) Node(org.neo4j.graphdb.Node)

Aggregations

DeletedBeanException (org.jowidgets.cap.common.api.exception.DeletedBeanException)6 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)4 BeanException (org.jowidgets.cap.common.api.exception.BeanException)2 StaleBeanException (org.jowidgets.cap.common.api.exception.StaleBeanException)2 Node (org.neo4j.graphdb.Node)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 IBean (org.jowidgets.cap.common.api.bean.IBean)1 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)1