Search in sources :

Example 1 with RelationshipIndexRepresentation

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

the class DatabaseActions method getIndexedRelationships.

public ListRepresentation getIndexedRelationships(String indexName, final String key, final String value) {
    if (!graphDb.index().existsForRelationships(indexName)) {
        throw new NotFoundException();
    }
    Index<Relationship> index = graphDb.index().forRelationships(indexName);
    final IndexRepresentation indexRepresentation = new RelationshipIndexRepresentation(indexName);
    IterableWrapper<Representation, Relationship> result = new IterableWrapper<Representation, Relationship>(index.get(key, value)) {

        @Override
        protected Representation underlyingObjectToObject(Relationship relationship) {
            return new IndexedEntityRepresentation(relationship, key, value, indexRepresentation);
        }
    };
    return new ListRepresentation(RepresentationType.RELATIONSHIP, result);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Relationship(org.neo4j.graphdb.Relationship) 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 RelationshipIndexRepresentation

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

the class DatabaseActions method addToRelationshipIndex.

public IndexedEntityRepresentation addToRelationshipIndex(String indexName, String key, String value, long relationshipId) {
    Relationship relationship = graphDb.getRelationshipById(relationshipId);
    Index<Relationship> index = graphDb.index().forRelationships(indexName);
    index.add(relationship, key, value);
    return new IndexedEntityRepresentation(relationship, key, value, new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) Relationship(org.neo4j.graphdb.Relationship) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation)

Example 3 with RelationshipIndexRepresentation

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

the class DatabaseActions method getOrCreateIndexedRelationship.

public Pair<IndexedEntityRepresentation, Boolean> getOrCreateIndexedRelationship(String indexName, String key, String value, Long relationshipOrNull, Long startNode, String type, Long endNode, Map<String, Object> properties) throws BadInputException, RelationshipNotFoundException, NodeNotFoundException {
    assertIsLegalIndexName(indexName);
    Relationship result;
    boolean created;
    if (relationshipOrNull != null) {
        if (startNode != null || type != null || endNode != null || properties != null) {
            throw new InvalidArgumentsException("Either specify a relationship to index uniquely, " + "or the means for creating it.");
        }
        Relationship relationship = relationship(relationshipOrNull);
        result = graphDb.index().forRelationships(indexName).putIfAbsent(relationship, key, value);
        if (created = result == null) {
            UniqueRelationshipFactory factory = new UniqueRelationshipFactory(indexName, relationship.getStartNode(), relationship.getEndNode(), relationship.getType().name(), properties);
            UniqueEntity<Relationship> entity = factory.getOrCreateWithOutcome(key, value);
            // when given a relationship id, return as created if that relationship was newly added to the index
            created = entity.entity().getId() == relationship.getId() || entity.wasCreated();
            result = entity.entity();
        }
    } else if (startNode == null || type == null || endNode == null) {
        throw new InvalidArgumentsException("Either specify a relationship to index uniquely, " + "or the means for creating it.");
    } else {
        UniqueRelationshipFactory factory = new UniqueRelationshipFactory(indexName, node(startNode), node(endNode), type, properties);
        UniqueEntity<Relationship> entity = factory.getOrCreateWithOutcome(key, value);
        result = entity.entity();
        created = entity.wasCreated();
    }
    return Pair.of(new IndexedEntityRepresentation(result, key, value, new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap())), created);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) UniqueEntity(org.neo4j.graphdb.index.UniqueFactory.UniqueEntity) Relationship(org.neo4j.graphdb.Relationship) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) InvalidArgumentsException(org.neo4j.server.rest.repr.InvalidArgumentsException)

Aggregations

Relationship (org.neo4j.graphdb.Relationship)3 IndexedEntityRepresentation (org.neo4j.server.rest.repr.IndexedEntityRepresentation)3 RelationshipIndexRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRepresentation)3 NotFoundException (org.neo4j.graphdb.NotFoundException)1 UniqueEntity (org.neo4j.graphdb.index.UniqueFactory.UniqueEntity)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 NodeIndexRepresentation (org.neo4j.server.rest.repr.NodeIndexRepresentation)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 RelationshipIndexRootRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation)1