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);
}
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()));
}
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);
}
Aggregations