Search in sources :

Example 6 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class TargetAPI method delete.

@DELETE
@Timed
@Path("{id}")
@Consumes(APPLICATION_JSON)
public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id) {
    LOG.debug("Graph [{}] delete target: {}", graph, id);
    // just check if the graph exists
    @SuppressWarnings("unused") HugeGraph g = graph(manager, graph);
    try {
        manager.authManager().deleteTarget(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid target id: " + id);
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Path(jakarta.ws.rs.Path) DELETE(jakarta.ws.rs.DELETE) Consumes(jakarta.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class BelongAPI method update.

@PUT
@Timed
@Path("{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id, JsonBelong jsonBelong) {
    LOG.debug("Graph [{}] update belong: {}", graph, jsonBelong);
    checkUpdatingBody(jsonBelong);
    HugeGraph g = graph(manager, graph);
    HugeBelong belong;
    try {
        belong = manager.authManager().getBelong(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid belong id: " + id);
    }
    belong = jsonBelong.build(belong);
    manager.authManager().updateBelong(belong);
    return manager.serializer(g).writeAuthElement(belong);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeBelong(com.baidu.hugegraph.auth.HugeBelong) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) PUT(jakarta.ws.rs.PUT)

Example 8 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class GraphTransaction method queryVertex.

public Vertex queryVertex(Object vertexId) {
    Iterator<Vertex> iter = this.queryVerticesByIds(new Object[] { vertexId }, false, true);
    Vertex vertex = QueryResults.one(iter);
    if (vertex == null) {
        throw new NotFoundException("Vertex '%s' does not exist", vertexId);
    }
    return vertex;
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) NotFoundException(com.baidu.hugegraph.exception.NotFoundException)

Example 9 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class GraphTransaction method queryEdge.

public Edge queryEdge(Object edgeId) {
    Iterator<Edge> iter = this.queryEdgesByIds(new Object[] { edgeId }, true);
    Edge edge = QueryResults.one(iter);
    if (edge == null) {
        throw new NotFoundException("Edge '%s' does not exist", edgeId);
    }
    return edge;
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 10 with NotFoundException

use of com.baidu.hugegraph.exception.NotFoundException in project incubator-hugegraph by apache.

the class EdgeAPI method delete.

@DELETE
@Timed
@Path("{id}")
@Consumes(APPLICATION_JSON)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_delete" })
public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id, @QueryParam("label") String label) {
    LOG.debug("Graph [{}] remove vertex by id '{}'", graph, id);
    HugeGraph g = graph(manager, graph);
    commit(g, () -> {
        try {
            g.removeEdge(label, id);
        } catch (NotFoundException e) {
            throw new IllegalArgumentException(String.format("No such edge with id: '%s', %s", id, e));
        } catch (NoSuchElementException e) {
            throw new IllegalArgumentException(String.format("No such edge with id: '%s'", id));
        }
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) NoSuchElementException(java.util.NoSuchElementException) Path(jakarta.ws.rs.Path) DELETE(jakarta.ws.rs.DELETE) RolesAllowed(jakarta.annotation.security.RolesAllowed) Consumes(jakarta.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

NotFoundException (com.baidu.hugegraph.exception.NotFoundException)30 HugeGraph (com.baidu.hugegraph.HugeGraph)15 Timed (com.codahale.metrics.annotation.Timed)15 Path (jakarta.ws.rs.Path)15 Consumes (jakarta.ws.rs.Consumes)14 DELETE (jakarta.ws.rs.DELETE)8 Produces (jakarta.ws.rs.Produces)7 PUT (jakarta.ws.rs.PUT)6 Id (com.baidu.hugegraph.backend.id.Id)5 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)4 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 HugeProject (com.baidu.hugegraph.auth.HugeProject)2 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)2 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)2 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)2 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)2 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)2 ImmutableList (com.google.common.collect.ImmutableList)2 RolesAllowed (jakarta.annotation.security.RolesAllowed)2 ArrayList (java.util.ArrayList)2