use of org.neo4j.server.rest.repr.ListRepresentation 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.ListRepresentation in project neo4j by neo4j.
the class TransactionWrappedDatabaseActions method getNodeRelationships.
@Override
public ListRepresentation getNodeRelationships(long nodeId, RelationshipDirection direction, Collection<String> types) throws NodeNotFoundException {
try (Transaction transaction = graph.beginTx()) {
ListRepresentation nodeRelationships = super.getNodeRelationships(nodeId, direction, types);
transaction.success();
return nodeRelationships;
}
}
use of org.neo4j.server.rest.repr.ListRepresentation in project neo4j by neo4j.
the class JmxService method queryBeans.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path(QUERY_PATH)
@SuppressWarnings("unchecked")
public Response queryBeans(String query) {
try {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
String json = dodgeStartingUnicodeMarker(query);
Collection<Object> queries = (Collection<Object>) JsonHelper.readJson(json);
ArrayList<JmxMBeanRepresentation> beans = new ArrayList<JmxMBeanRepresentation>();
for (Object queryObj : queries) {
assert queryObj instanceof String;
for (Object objName : server.queryNames(new ObjectName((String) queryObj), null)) {
beans.add(new JmxMBeanRepresentation((ObjectName) objName));
}
}
return output.ok(new ListRepresentation("jmxBean", beans));
} catch (JsonParseException e) {
return output.badRequest(e);
} catch (MalformedObjectNameException e) {
return output.badRequest(e);
}
}
use of org.neo4j.server.rest.repr.ListRepresentation in project neo4j by neo4j.
the class JmxService method getBean.
@GET
@Path(BEAN_TEMPLATE)
public Response getBean(@PathParam("domain") String domainName, @PathParam("objectName") String objectName) {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ArrayList<JmxMBeanRepresentation> beans = new ArrayList<JmxMBeanRepresentation>();
for (Object objName : server.queryNames(createObjectName(domainName, objectName), null)) {
beans.add(new JmxMBeanRepresentation((ObjectName) objName));
}
return output.ok(new ListRepresentation("bean", beans));
}
use of org.neo4j.server.rest.repr.ListRepresentation in project neo4j by neo4j.
the class DatabaseActions method findPaths.
@SuppressWarnings({ "rawtypes", "unchecked" })
public ListRepresentation findPaths(long startId, long endId, Map<String, Object> map) {
final FindParams findParams = new FindParams(startId, endId, map).invoke();
PathFinder finder = findParams.getFinder();
Node startNode = findParams.getStartNode();
Node endNode = findParams.getEndNode();
Iterable paths = finder.findAllPaths(startNode, endNode);
IterableWrapper<PathRepresentation, Path> pathRepresentations = new IterableWrapper<PathRepresentation, Path>(paths) {
@Override
protected PathRepresentation underlyingObjectToObject(Path path) {
return findParams.pathRepresentationOf(path);
}
};
return new ListRepresentation(RepresentationType.PATH, pathRepresentations);
}
Aggregations