use of org.structr.api.graph.Node in project structr by structr.
the class AbstractRelationship method onRelationshipInstantiation.
/**
* Called when a relationship of this combinedType is instantiated. Please note that
* a relationship can (and will) be instantiated several times during a
* normal rendering turn.
*/
@Override
public void onRelationshipInstantiation() {
try {
if (dbRelationship != null) {
Node startNode = dbRelationship.getStartNode();
Node endNode = dbRelationship.getEndNode();
if ((startNode != null) && (endNode != null) && startNode.hasProperty(GraphObject.id.dbName()) && endNode.hasProperty(GraphObject.id.dbName())) {
cachedStartNodeId = (String) startNode.getProperty(GraphObject.id.dbName());
cachedEndNodeId = (String) endNode.getProperty(GraphObject.id.dbName());
}
}
} catch (Throwable t) {
}
}
use of org.structr.api.graph.Node in project structr by structr.
the class GenericNode method getPropertyKeys.
@Override
public Set<PropertyKey> getPropertyKeys(final String propertyView) {
final Node node = getNode();
if (node != null) {
final long id = node.getId();
Set<PropertyKey> keys = propertyKeys.get(id);
if (keys == null) {
keys = new TreeSet<>(new PropertyKeyComparator());
// add all properties from a schema entity (if existing)
keys.addAll(Iterables.toList(super.getPropertyKeys(propertyView)));
// add properties that are physically present on the node
keys.addAll(Iterables.toList(Iterables.map(new GenericPropertyKeyMapper(), dbNode.getPropertyKeys())));
propertyKeys.put(id, keys);
}
return keys;
}
// return the whole set
return Collections.EMPTY_SET;
}
use of org.structr.api.graph.Node in project structr by structr.
the class Property method index.
@Override
public void index(final GraphObject entity, final Object value) {
if (entity instanceof AbstractNode) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractNode node = (AbstractNode) entity;
final Node dbNode = node.getNode();
final Index<Node> index = nodeService.getNodeIndex();
if (index != null) {
try {
index.remove(dbNode, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbNode, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
logger.warn("", t);
}
}
} else if (entity instanceof AbstractRelationship) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractRelationship rel = (AbstractRelationship) entity;
final Relationship dbRel = rel.getRelationship();
final Index<Relationship> index = nodeService.getRelationshipIndex();
if (index != null) {
try {
index.remove(dbRel, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbRel, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
}
}
}
}
use of org.structr.api.graph.Node in project structr by structr.
the class TypeProperty method updateLabels.
public static void updateLabels(final DatabaseService graphDb, final NodeInterface node, final Class newType, final boolean removeUnused) {
final Set<Label> intersection = new LinkedHashSet<>();
final Set<Label> toRemove = new LinkedHashSet<>();
final Set<Label> toAdd = new LinkedHashSet<>();
final Node dbNode = node.getNode();
// include optional tenant identifier when modifying labels
final String tenantIdentifier = graphDb.getTenantIdentifier();
if (tenantIdentifier != null) {
toAdd.add(graphDb.forName(Label.class, tenantIdentifier));
}
// collect labels that are already present on a node
for (final Label label : dbNode.getLabels()) {
toRemove.add(label);
}
// collect new labels
for (final Class supertype : SearchCommand.typeAndAllSupertypes(newType)) {
final String supertypeName = supertype.getName();
if (supertypeName.startsWith("org.structr.") || supertypeName.startsWith("com.structr.")) {
toAdd.add(graphDb.forName(Label.class, supertype.getSimpleName()));
}
}
// calculate intersection
intersection.addAll(toAdd);
intersection.retainAll(toRemove);
// calculate differences
toAdd.removeAll(intersection);
toRemove.removeAll(intersection);
if (removeUnused) {
// remove difference
for (final Label remove : toRemove) {
dbNode.removeLabel(remove);
}
}
// add difference
for (final Label add : toAdd) {
dbNode.addLabel(add);
}
}
Aggregations