Search in sources :

Example 6 with ListRepresentation

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));
    }
}
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 7 with ListRepresentation

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;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 8 with ListRepresentation

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);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) JmxMBeanRepresentation(org.neo4j.server.rest.management.repr.JmxMBeanRepresentation) JsonParseException(org.neo4j.server.rest.domain.JsonParseException) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 9 with ListRepresentation

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));
}
Also used : ArrayList(java.util.ArrayList) JmxMBeanRepresentation(org.neo4j.server.rest.management.repr.JmxMBeanRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with ListRepresentation

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);
}
Also used : Path(org.neo4j.graphdb.Path) WeightedPath(org.neo4j.graphalgo.WeightedPath) ResourceIterable(org.neo4j.graphdb.ResourceIterable) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) Node(org.neo4j.graphdb.Node) PathFinder(org.neo4j.graphalgo.PathFinder) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Aggregations

ListRepresentation (org.neo4j.server.rest.repr.ListRepresentation)12 ArrayList (java.util.ArrayList)4 IndexDefinitionRepresentation (org.neo4j.server.rest.repr.IndexDefinitionRepresentation)4 Representation (org.neo4j.server.rest.repr.Representation)4 ValueRepresentation (org.neo4j.server.rest.repr.ValueRepresentation)4 MBeanServer (javax.management.MBeanServer)3 Path (javax.ws.rs.Path)3 IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)3 PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)3 WeightedPathRepresentation (org.neo4j.server.rest.repr.WeightedPathRepresentation)3 ObjectName (javax.management.ObjectName)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Node (org.neo4j.graphdb.Node)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)2 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)2 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)2 JmxMBeanRepresentation (org.neo4j.server.rest.management.repr.JmxMBeanRepresentation)2