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