Search in sources :

Example 21 with Node

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) {
    }
}
Also used : Node(org.structr.api.graph.Node)

Example 22 with Node

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;
}
Also used : Node(org.structr.api.graph.Node) PropertyKey(org.structr.core.property.PropertyKey)

Example 23 with Node

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 });
            }
        }
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) NodeService(org.structr.core.graph.NodeService) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject) AbstractCypherIndex(org.structr.bolt.index.AbstractCypherIndex) Index(org.structr.api.index.Index)

Example 24 with Node

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Node(org.structr.api.graph.Node) Label(org.structr.api.graph.Label)

Aggregations

Node (org.structr.api.graph.Node)24 Relationship (org.structr.api.graph.Relationship)13 AbstractNode (org.structr.core.entity.AbstractNode)11 LinkedList (java.util.LinkedList)8 GraphObject (org.structr.core.GraphObject)8 DatabaseService (org.structr.api.DatabaseService)7 LinkedHashSet (java.util.LinkedHashSet)5 AbstractRelationship (org.structr.core.entity.AbstractRelationship)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 FrameworkException (org.structr.common.error.FrameworkException)4 AbstractSchemaNode (org.structr.core.entity.AbstractSchemaNode)4 PropertyKey (org.structr.core.property.PropertyKey)4 Test (org.junit.Test)3 Transaction (org.structr.api.Transaction)3 App (org.structr.core.app.App)3 StructrApp (org.structr.core.app.StructrApp)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2