use of org.structr.core.graph.NodeInterface 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);
}
use of org.structr.core.graph.NodeInterface 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);
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class OtherNodeTypeRelationFilter method accept.
@Override
public boolean accept(final Relation rel) {
final NodeInterface otherNode = nodeFactory.instantiate(rel.getRelationship().getOtherNode(thisNode));
final Class otherNodeType = otherNode.getClass();
return desiredType.isAssignableFrom(otherNodeType) || otherNodeType.isAssignableFrom(desiredType);
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class ManyEndpoint method set.
@Override
public Object set(final SecurityContext securityContext, final NodeInterface sourceNode, final Iterable<T> collection) throws FrameworkException {
final App app = StructrApp.getInstance(securityContext);
final List<Relation> createdRelationships = new LinkedList<>();
final PropertyMap properties = new PropertyMap();
final T actualSourceNode = (T) unwrap(securityContext, relation.getClass(), sourceNode, properties);
final Set<T> toBeDeleted = new LinkedHashSet<>(Iterables.toList(get(securityContext, actualSourceNode, null)));
final Set<T> toBeCreated = new LinkedHashSet<>();
if (collection != null) {
Iterables.addAll(toBeCreated, collection);
}
// create intersection of both sets
final Set<T> intersection = new HashSet<>(toBeCreated);
intersection.retainAll(toBeDeleted);
// intersection needs no change
toBeCreated.removeAll(intersection);
toBeDeleted.removeAll(intersection);
if (actualSourceNode != null) {
// remove existing relationships
for (T targetNode : toBeDeleted) {
for (Iterator<AbstractRelationship> it = actualSourceNode.getOutgoingRelationships(relation.getClass()).iterator(); it.hasNext(); ) {
final AbstractRelationship rel = it.next();
if (actualSourceNode.equals(targetNode)) {
logger.warn("Preventing deletion of self relationship {}-[{}]->{}. If you experience issue with this, please report to team@structr.com.", new Object[] { actualSourceNode, rel.getRelType(), targetNode });
// skip self relationships
continue;
}
if (rel.getTargetNode().equals(targetNode)) {
app.delete(rel);
}
}
}
// create new relationships
for (T targetNode : toBeCreated) {
if (targetNode != null) {
properties.clear();
final NodeInterface actualTargetNode = (NodeInterface) unwrap(securityContext, relation.getClass(), targetNode, properties);
relation.ensureCardinality(securityContext, actualSourceNode, actualTargetNode);
final PropertyMap notionProperties = getNotionProperties(securityContext, relation.getClass(), actualSourceNode.getName() + relation.name() + actualTargetNode.getName());
if (notionProperties != null) {
properties.putAll(notionProperties);
}
createdRelationships.add(app.create(actualSourceNode, actualTargetNode, relation.getClass(), properties));
}
}
}
return createdRelationships;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class OneEndpoint method set.
@Override
public Object set(final SecurityContext securityContext, final NodeInterface sourceNode, final T targetNode) throws FrameworkException {
final PropertyMap properties = new PropertyMap();
final NodeInterface actualTargetNode = (NodeInterface) unwrap(securityContext, relation.getClass(), targetNode, properties);
final T actualSourceNode = (T) unwrap(securityContext, relation.getClass(), sourceNode, properties);
// let relation check multiplicity
relation.ensureCardinality(securityContext, actualSourceNode, actualTargetNode);
if (actualSourceNode != null && actualTargetNode != null) {
final String storageKey = actualSourceNode.getName() + relation.name() + actualTargetNode.getName();
final PropertyMap notionProperties = getNotionProperties(securityContext, relation.getClass(), storageKey);
if (notionProperties != null) {
properties.putAll(notionProperties);
}
// create new relationship
return StructrApp.getInstance(securityContext).create(actualSourceNode, actualTargetNode, relation.getClass(), properties);
}
return null;
}
Aggregations