use of org.structr.core.graph.NodeInterface in project structr by structr.
the class JavaParserModuleTest method createTestRelationships.
protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
final NodeInterface startNode = nodes.get(0);
final NodeInterface endNode = nodes.get(1);
try (final Tx tx = app.tx()) {
List<T> rels = new LinkedList<>();
for (int i = 0; i < number; i++) {
rels.add((T) app.create(startNode, endNode, relType));
}
tx.success();
return rels;
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class ValidationHelper method isValidGloballyUniqueProperty.
public static synchronized boolean isValidGloballyUniqueProperty(final GraphObject object, final PropertyKey key, final ErrorBuffer errorBuffer) {
if (key != null) {
final Object value = object.getProperty(key);
List<? extends GraphObject> result = null;
try {
if (object instanceof NodeInterface) {
result = StructrApp.getInstance().nodeQuery(NodeInterface.class).and(key, value).disableSorting().getAsList();
} else if (object instanceof RelationshipInterface) {
result = StructrApp.getInstance().relationshipQuery(RelationshipInterface.class).and(key, value).disableSorting().getAsList();
} else {
logger.error("GraphObject is neither NodeInterface nor RelationshipInterface");
return false;
}
} catch (FrameworkException fex) {
logger.warn("Unable to fetch list of nodes for uniqueness check", fex);
// handle error
}
if (result != null) {
for (final GraphObject foundNode : result) {
if (foundNode.getId() != object.getId()) {
// validation is aborted when the first validation failure occurs, so
// we can assume that the object currently exmained is the first
// existing object, hence all others get the error message with the
// UUID of the first one.
errorBuffer.add(new UniqueToken(object.getType(), key, object.getUuid()));
// error!
return false;
}
}
}
}
// no error
return true;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class GraphMergeHelper method merge.
/**
* Merge new nodes into original nodes including all relationships and
* properties
*
* @param <T>
* @param newNodes
* @param origNodes
* @param shadowIdPropertyKey
*/
public static <T extends NodeInterface> void merge(final Set<T> origNodes, final Set<T> newNodes, final PropertyKey shadowIdPropertyKey) {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
// and mark all original nodes as deleted which are not contained in new nodes list anymore
for (final NodeInterface origNode : origNodes) {
origNode.setProperty(NodeInterface.deleted, true);
for (final NodeInterface newNode : newNodes) {
final String shadowId = (String) newNode.getProperty(shadowIdPropertyKey);
logger.info("New node shadow id: {}", shadowId);
if (origNode.getUuid().equals(shadowId)) {
origNode.setProperty(NodeInterface.deleted, false);
}
}
}
// Delete all original nodes which are marked as deleted
for (final NodeInterface origNode : origNodes) {
if (origNode.getProperty(NodeInterface.deleted)) {
app.delete(origNode);
}
}
// Delete all new nodes
for (final NodeInterface newNode : newNodes) {
app.delete(newNode);
}
tx.success();
} catch (FrameworkException ex) {
logger.error("", ex);
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class EndNodes method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<T> searchValue, boolean exactMatch, final Query query) {
final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
boolean alreadyAdded = false;
if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {
if (exactMatch) {
for (NodeInterface node : searchValue) {
switch(occur) {
case REQUIRED:
if (!alreadyAdded) {
// the first result is the basis of all subsequent intersections
intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
// the next additions are intersected with this one
alreadyAdded = true;
} else {
intersectionResult.retainAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
break;
case OPTIONAL:
intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
break;
case FORBIDDEN:
break;
}
}
} else {
// loose search behaves differently, all results must be combined
for (NodeInterface node : searchValue) {
intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
}
attr.setResult(intersectionResult);
} else {
// value in the given field
return new EmptySearchAttribute(this, null);
}
return attr;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class EndNodeGroup method getGroupedProperties.
@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
if (source instanceof RelationshipInterface) {
RelationshipInterface rel = (RelationshipInterface) source;
NodeInterface end = rel.getTargetNode();
return super.getGroupedProperties(securityContext, end);
}
return null;
}
Aggregations