Search in sources :

Example 1 with NodeIndexRepresentation

use of org.neo4j.server.rest.repr.NodeIndexRepresentation in project neo4j by neo4j.

the class DatabaseActions method getIndexedNodes.

public ListRepresentation getIndexedNodes(String indexName, final String key, final String value) {
    if (!graphDb.index().existsForNodes(indexName)) {
        throw new NotFoundException();
    }
    Index<Node> index = graphDb.index().forNodes(indexName);
    final IndexRepresentation indexRepresentation = new NodeIndexRepresentation(indexName);
    final IndexHits<Node> indexHits = index.get(key, value);
    final IterableWrapper<Representation, Node> results = new IterableWrapper<Representation, Node>(indexHits) {

        @Override
        protected Representation underlyingObjectToObject(Node node) {
            return new IndexedEntityRepresentation(node, key, value, indexRepresentation);
        }
    };
    return new ListRepresentation(RepresentationType.NODE, results);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Node(org.neo4j.graphdb.Node) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PropertiesRepresentation(org.neo4j.server.rest.repr.PropertiesRepresentation) ScoredNodeRepresentation(org.neo4j.server.rest.repr.ScoredNodeRepresentation) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) ScoredRelationshipRepresentation(org.neo4j.server.rest.repr.ScoredRelationshipRepresentation) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) Representation(org.neo4j.server.rest.repr.Representation) IndexDefinitionRepresentation(org.neo4j.server.rest.repr.IndexDefinitionRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) RelationshipIndexRootRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRootRepresentation(org.neo4j.server.rest.repr.NodeIndexRootRepresentation) DatabaseRepresentation(org.neo4j.server.rest.repr.DatabaseRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 2 with NodeIndexRepresentation

use of org.neo4j.server.rest.repr.NodeIndexRepresentation in project neo4j by neo4j.

the class DatabaseActions method addToNodeIndex.

public IndexedEntityRepresentation addToNodeIndex(String indexName, String key, String value, long nodeId) {
    Node node = graphDb.getNodeById(nodeId);
    Index<Node> index = graphDb.index().forNodes(indexName);
    index.add(node, key, value);
    return new IndexedEntityRepresentation(node, key, value, new NodeIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
}
Also used : NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Node(org.neo4j.graphdb.Node) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation)

Example 3 with NodeIndexRepresentation

use of org.neo4j.server.rest.repr.NodeIndexRepresentation in project neo4j by neo4j.

the class DatabaseActions method getOrCreateIndexedNode.

public Pair<IndexedEntityRepresentation, Boolean> getOrCreateIndexedNode(String indexName, String key, String value, Long nodeOrNull, Map<String, Object> properties) throws BadInputException, NodeNotFoundException {
    assertIsLegalIndexName(indexName);
    Node result;
    boolean created;
    if (nodeOrNull != null) {
        if (properties != null) {
            throw new InvalidArgumentsException("Cannot specify properties for a new node, " + "when a node to index is specified.");
        }
        Node node = node(nodeOrNull);
        result = graphDb.index().forNodes(indexName).putIfAbsent(node, key, value);
        created = result == null;
        if (created) {
            UniqueNodeFactory factory = new UniqueNodeFactory(indexName, properties);
            UniqueEntity<Node> entity = factory.getOrCreateWithOutcome(key, value);
            // when given a node id, return as created if that node was newly added to the index
            created = entity.entity().getId() == node.getId() || entity.wasCreated();
            result = entity.entity();
        }
    } else {
        if (properties != null) {
            for (Map.Entry<String, Object> entry : properties.entrySet()) {
                entry.setValue(propertySetter.convert(entry.getValue()));
            }
        }
        UniqueNodeFactory factory = new UniqueNodeFactory(indexName, properties);
        UniqueEntity<Node> entity = factory.getOrCreateWithOutcome(key, value);
        result = entity.entity();
        created = entity.wasCreated();
    }
    return Pair.of(new IndexedEntityRepresentation(result, key, value, new NodeIndexRepresentation(indexName, Collections.<String, String>emptyMap())), created);
}
Also used : NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Node(org.neo4j.graphdb.Node) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) InvalidArgumentsException(org.neo4j.server.rest.repr.InvalidArgumentsException) Map(java.util.Map)

Aggregations

Node (org.neo4j.graphdb.Node)3 IndexedEntityRepresentation (org.neo4j.server.rest.repr.IndexedEntityRepresentation)3 NodeIndexRepresentation (org.neo4j.server.rest.repr.NodeIndexRepresentation)3 Map (java.util.Map)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)1 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)1 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)1 ConstraintDefinitionRepresentation (org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation)1 DatabaseRepresentation (org.neo4j.server.rest.repr.DatabaseRepresentation)1 IndexDefinitionRepresentation (org.neo4j.server.rest.repr.IndexDefinitionRepresentation)1 IndexRepresentation (org.neo4j.server.rest.repr.IndexRepresentation)1 InvalidArgumentsException (org.neo4j.server.rest.repr.InvalidArgumentsException)1 ListRepresentation (org.neo4j.server.rest.repr.ListRepresentation)1 NodeIndexRootRepresentation (org.neo4j.server.rest.repr.NodeIndexRootRepresentation)1 NodeRepresentation (org.neo4j.server.rest.repr.NodeRepresentation)1 PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)1 PropertiesRepresentation (org.neo4j.server.rest.repr.PropertiesRepresentation)1 RelationshipIndexRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRepresentation)1 RelationshipIndexRootRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation)1