Search in sources :

Example 1 with IdNotFoundToken

use of org.structr.common.error.IdNotFoundToken in project structr by structr.

the class AbstractRelationship method setSourceNodeId.

@Override
public final void setSourceNodeId(final String sourceNodeId) throws FrameworkException {
    // Do nothing if new id equals old
    if (getSourceNodeId().equals(sourceNodeId)) {
        return;
    }
    final App app = StructrApp.getInstance(securityContext);
    final NodeInterface newStartNode = app.getNodeById(sourceNodeId);
    final NodeInterface endNode = getTargetNode();
    final Class relationType = getClass();
    final PropertyMap _props = getProperties();
    final String type = this.getClass().getSimpleName();
    if (newStartNode == null) {
        throw new FrameworkException(404, "Node with ID " + sourceNodeId + " not found", new IdNotFoundToken(type, sourceNodeId));
    }
    // delete this as the new rel will be the container afterwards
    app.delete(this);
    // create new relationship
    app.create(newStartNode, endNode, relationType, _props);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) IdNotFoundToken(org.structr.common.error.IdNotFoundToken) NodeInterface(org.structr.core.graph.NodeInterface)

Example 2 with IdNotFoundToken

use of org.structr.common.error.IdNotFoundToken in project structr by structr.

the class AbstractRelationship method setTargetNodeId.

@Override
public final void setTargetNodeId(final String targetNodeId) throws FrameworkException {
    // Do nothing if new id equals old
    if (getTargetNodeId().equals(targetNodeId)) {
        return;
    }
    final App app = StructrApp.getInstance(securityContext);
    final NodeInterface newTargetNode = app.getNodeById(targetNodeId);
    final NodeInterface startNode = getSourceNode();
    final Class relationType = getClass();
    final PropertyMap _props = getProperties();
    final String type = this.getClass().getSimpleName();
    if (newTargetNode == null) {
        throw new FrameworkException(404, "Node with ID " + targetNodeId + " not found", new IdNotFoundToken(type, targetNodeId));
    }
    // delete this as the new rel will be the container afterwards
    app.delete(this);
    // create new relationship and store here
    app.create(startNode, newTargetNode, relationType, _props);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) IdNotFoundToken(org.structr.common.error.IdNotFoundToken) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)2 IdNotFoundToken (org.structr.common.error.IdNotFoundToken)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 NodeInterface (org.structr.core.graph.NodeInterface)2 PropertyMap (org.structr.core.property.PropertyMap)2