Search in sources :

Example 16 with NotFoundException

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

the class ProjectAPI method get.

@GET
@Timed
@Path("{id}")
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id) {
    LOG.debug("Graph [{}] get project: {}", graph, id);
    HugeGraph g = graph(manager, graph);
    HugeProject project;
    try {
        project = manager.authManager().getProject(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid project id: " + id);
    }
    return manager.serializer(g).writeAuthElement(project);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeProject(com.baidu.hugegraph.auth.HugeProject) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 17 with NotFoundException

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

the class ProjectAPI 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, @QueryParam("action") String action, JsonProject jsonProject) {
    LOG.debug("Graph [{}] update {} project: {}", graph, action, jsonProject);
    checkUpdatingBody(jsonProject);
    HugeGraph g = graph(manager, graph);
    HugeProject project;
    Id projectId = UserAPI.parseId(id);
    AuthManager authManager = manager.authManager();
    try {
        project = authManager.getProject(projectId);
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid project id: " + id);
    }
    if (ProjectAPI.isAddGraph(action)) {
        project = jsonProject.buildAddGraph(project);
    } else if (ProjectAPI.isRemoveGraph(action)) {
        project = jsonProject.buildRemoveGraph(project);
    } else {
        E.checkArgument(StringUtils.isEmpty(action), "The action parameter can only be either " + "%s or %s or '', but got '%s'", ProjectAPI.ACTION_ADD_GRAPH, ProjectAPI.ACTION_REMOVE_GRAPH, action);
        project = jsonProject.buildUpdateDescription(project);
    }
    authManager.updateProject(project);
    return manager.serializer(g).writeAuthElement(project);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeProject(com.baidu.hugegraph.auth.HugeProject) AuthManager(com.baidu.hugegraph.auth.AuthManager) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) Id(com.baidu.hugegraph.backend.id.Id) 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 18 with NotFoundException

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

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

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

the class TargetAPI 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, JsonTarget jsonTarget) {
    LOG.debug("Graph [{}] update target: {}", graph, jsonTarget);
    checkUpdatingBody(jsonTarget);
    HugeGraph g = graph(manager, graph);
    HugeTarget target;
    try {
        target = manager.authManager().getTarget(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid target id: " + id);
    }
    target = jsonTarget.build(target);
    manager.authManager().updateTarget(target);
    return manager.serializer(g).writeAuthElement(target);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) 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 20 with NotFoundException

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

the class UserAPI 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, JsonUser jsonUser) {
    LOG.debug("Graph [{}] update user: {}", graph, jsonUser);
    checkUpdatingBody(jsonUser);
    HugeGraph g = graph(manager, graph);
    HugeUser user;
    try {
        user = manager.authManager().getUser(UserAPI.parseId(id));
    } catch (NotFoundException e) {
        throw new IllegalArgumentException("Invalid user id: " + id);
    }
    user = jsonUser.build(user);
    manager.authManager().updateUser(user);
    return manager.serializer(g).writeAuthElement(user);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) HugeUser(com.baidu.hugegraph.auth.HugeUser) 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