Search in sources :

Example 1 with Representation

use of org.neo4j.server.rest.repr.Representation 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 Representation

use of org.neo4j.server.rest.repr.Representation 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 3 with Representation

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

the class ConsoleService method exec.

@POST
public Response exec(@Context InputFormat input, String data) {
    Map<String, Object> args;
    try {
        args = input.readMap(data);
    } catch (BadInputException e) {
        return output.badRequest(e);
    }
    if (!args.containsKey("command")) {
        return Response.status(Status.BAD_REQUEST).entity("Expected command argument not present.").build();
    }
    ScriptSession scriptSession;
    try {
        scriptSession = getSession(args);
    } catch (IllegalArgumentException e) {
        return output.badRequest(e);
    }
    log.debug(scriptSession.toString());
    try {
        Pair<String, String> result = scriptSession.evaluate((String) args.get("command"));
        List<Representation> list = new ArrayList<Representation>(asList(ValueRepresentation.string(result.first()), ValueRepresentation.string(result.other())));
        return output.ok(new ListRepresentation(RepresentationType.STRING, list));
    } catch (Exception e) {
        List<Representation> list = new ArrayList<Representation>(asList(ValueRepresentation.string(e.getClass() + " : " + e.getMessage() + "\n"), ValueRepresentation.string(null)));
        return output.ok(new ListRepresentation(RepresentationType.STRING, list));
    }
}
Also used : ArrayList(java.util.ArrayList) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) ConsoleServiceRepresentation(org.neo4j.server.rest.management.repr.ConsoleServiceRepresentation) Representation(org.neo4j.server.rest.repr.Representation) BadInputException(org.neo4j.server.rest.repr.BadInputException) BadInputException(org.neo4j.server.rest.repr.BadInputException) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) POST(javax.ws.rs.POST)

Example 4 with Representation

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

the class JmxCompositeDataRepresentation method getValue.

@Mapping("value")
public ListRepresentation getValue() {
    ArrayList<Representation> values = new ArrayList<Representation>();
    for (Object key : data.getCompositeType().keySet()) {
        String name = key.toString();
        String description = data.getCompositeType().getDescription(name);
        Representation value = REPRESENTATION_DISPATCHER.dispatch(data.get(name), "");
        values.add(new NameDescriptionValueRepresentation(name, description, value));
    }
    return new ListRepresentation("value", values);
}
Also used : ArrayList(java.util.ArrayList) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) Representation(org.neo4j.server.rest.repr.Representation) ObjectRepresentation(org.neo4j.server.rest.repr.ObjectRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Aggregations

ListRepresentation (org.neo4j.server.rest.repr.ListRepresentation)4 Representation (org.neo4j.server.rest.repr.Representation)4 ValueRepresentation (org.neo4j.server.rest.repr.ValueRepresentation)4 ArrayList (java.util.ArrayList)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)2 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)2 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)2 ConstraintDefinitionRepresentation (org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation)2 DatabaseRepresentation (org.neo4j.server.rest.repr.DatabaseRepresentation)2 IndexDefinitionRepresentation (org.neo4j.server.rest.repr.IndexDefinitionRepresentation)2 IndexRepresentation (org.neo4j.server.rest.repr.IndexRepresentation)2 IndexedEntityRepresentation (org.neo4j.server.rest.repr.IndexedEntityRepresentation)2 NodeIndexRepresentation (org.neo4j.server.rest.repr.NodeIndexRepresentation)2 NodeIndexRootRepresentation (org.neo4j.server.rest.repr.NodeIndexRootRepresentation)2 NodeRepresentation (org.neo4j.server.rest.repr.NodeRepresentation)2 PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)2 PropertiesRepresentation (org.neo4j.server.rest.repr.PropertiesRepresentation)2 RelationshipIndexRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRepresentation)2 RelationshipIndexRootRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation)2