Search in sources :

Example 11 with NotFoundException

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

the class VertexAPI method delete.

@DELETE
@Timed
@Path("{id}")
@Consumes(APPLICATION_JSON)
@RolesAllowed({ "admin", "$owner=$graph $action=vertex_delete" })
public void delete(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String idValue, @QueryParam("label") String label) {
    LOG.debug("Graph [{}] remove vertex by id '{}'", graph, idValue);
    Id id = checkAndParseVertexId(idValue);
    HugeGraph g = graph(manager, graph);
    commit(g, () -> {
        try {
            g.removeVertex(label, id);
        } catch (NotFoundException e) {
            throw new IllegalArgumentException(String.format("No such vertex with id: '%s', %s", id, e));
        } catch (NoSuchElementException e) {
            throw new IllegalArgumentException(String.format("No such vertex with id: '%s'", id));
        }
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Id(com.baidu.hugegraph.backend.id.Id) 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)

Example 12 with NotFoundException

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

the class BelongAPI 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 belong: {}", graph, id);
    // just check if the graph exists
    @SuppressWarnings("unused") HugeGraph g = graph(manager, graph);
    try {
        manager.authManager().deleteBelong(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid belong 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 13 with NotFoundException

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

the class AccessAPI 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, JsonAccess jsonAccess) {
    LOG.debug("Graph [{}] update access: {}", graph, jsonAccess);
    checkUpdatingBody(jsonAccess);
    HugeGraph g = graph(manager, graph);
    HugeAccess access;
    try {
        access = manager.authManager().getAccess(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid access id: " + id);
    }
    access = jsonAccess.build(access);
    manager.authManager().updateAccess(access);
    return manager.serializer(g).writeAuthElement(access);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeAccess(com.baidu.hugegraph.auth.HugeAccess) 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 14 with NotFoundException

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

the class AccessAPI 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 access: {}", graph, id);
    // just check if the graph exists
    @SuppressWarnings("unused") HugeGraph g = graph(manager, graph);
    try {
        manager.authManager().deleteAccess(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid access 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 15 with NotFoundException

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

the class GroupAPI 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, JsonGroup jsonGroup) {
    LOG.debug("Graph [{}] update group: {}", graph, jsonGroup);
    checkUpdatingBody(jsonGroup);
    HugeGraph g = graph(manager, graph);
    HugeGroup group;
    try {
        group = manager.authManager().getGroup(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid group id: " + id);
    }
    group = jsonGroup.build(group);
    manager.authManager().updateGroup(group);
    return manager.serializer(g).writeAuthElement(group);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) 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)

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