Search in sources :

Example 1 with HugeProject

use of com.baidu.hugegraph.auth.HugeProject in project incubator-hugegraph by apache.

the class ProjectAPI method create.

@POST
@Timed
@StatusFilter.Status(StatusFilter.Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonProject jsonProject) {
    LOG.debug("Graph [{}] create project: {}", graph, jsonProject);
    checkCreatingBody(jsonProject);
    HugeGraph g = graph(manager, graph);
    HugeProject project = jsonProject.build();
    Id projectId = manager.authManager().createProject(project);
    /*
         * Some fields of project(like admin_group) can only be known after
         * created
         */
    project = manager.authManager().getProject(projectId);
    return manager.serializer(g).writeAuthElement(project);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeProject(com.baidu.hugegraph.auth.HugeProject) Id(com.baidu.hugegraph.backend.id.Id) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with HugeProject

use of com.baidu.hugegraph.auth.HugeProject in project incubator-hugegraph by apache.

the class AuthTest method testListProject.

@Test
public void testListProject() {
    AuthManager authManager = graph().authManager();
    authManager.createProject(makeProject("test_project1", ""));
    authManager.createProject(makeProject("test_project2", ""));
    authManager.createProject(makeProject("test_project3", ""));
    List<HugeProject> projects = authManager.listAllProject(1);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 1);
    projects = authManager.listAllProject(-1);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 3);
    projects = authManager.listAllProject(3);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 3);
    projects = authManager.listAllProject(4);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 3);
    projects = authManager.listAllProject(2);
    Assert.assertNotNull(projects);
    Assert.assertTrue(projects.size() == 2);
}
Also used : AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeProject(com.baidu.hugegraph.auth.HugeProject) Test(org.junit.Test)

Example 3 with HugeProject

use of com.baidu.hugegraph.auth.HugeProject 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 4 with HugeProject

use of com.baidu.hugegraph.auth.HugeProject 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 5 with HugeProject

use of com.baidu.hugegraph.auth.HugeProject in project incubator-hugegraph by apache.

the class ProjectAPI method list.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("limit") @DefaultValue("100") long limit) {
    LOG.debug("Graph [{}] list project", graph);
    HugeGraph g = graph(manager, graph);
    List<HugeProject> projects = manager.authManager().listAllProject(limit);
    return manager.serializer(g).writeAuthElements("projects", projects);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeProject(com.baidu.hugegraph.auth.HugeProject) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Aggregations

HugeProject (com.baidu.hugegraph.auth.HugeProject)14 AuthManager (com.baidu.hugegraph.auth.AuthManager)8 Id (com.baidu.hugegraph.backend.id.Id)8 Test (org.junit.Test)7 HugeGraph (com.baidu.hugegraph.HugeGraph)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)2 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)1 HugeResource (com.baidu.hugegraph.auth.HugeResource)1 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)1 HugeUser (com.baidu.hugegraph.auth.HugeUser)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 After (org.junit.After)1