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