Search in sources :

Example 6 with HugeGroup

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

the class GroupAPI 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 group: {}", graph, id);
    HugeGraph g = graph(manager, graph);
    HugeGroup group = manager.authManager().getGroup(IdGenerator.of(id));
    return manager.serializer(g).writeAuthElement(group);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 7 with HugeGroup

use of com.baidu.hugegraph.auth.HugeGroup 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)

Example 8 with HugeGroup

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

the class GroupAPI 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 groups", graph);
    HugeGraph g = graph(manager, graph);
    List<HugeGroup> groups = manager.authManager().listAllGroups(limit);
    return manager.serializer(g).writeAuthElements("groups", groups);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 9 with HugeGroup

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

the class GroupAPI method create.

@POST
@Timed
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonGroup jsonGroup) {
    LOG.debug("Graph [{}] create group: {}", graph, jsonGroup);
    checkCreatingBody(jsonGroup);
    HugeGraph g = graph(manager, graph);
    HugeGroup group = jsonGroup.build();
    group.id(manager.authManager().createGroup(group));
    return manager.serializer(g).writeAuthElement(group);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 10 with HugeGroup

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

the class AuthTest method testDeleteGroup.

@Test
public void testDeleteGroup() {
    HugeGraph graph = graph();
    AuthManager authManager = graph.authManager();
    Id id1 = authManager.createGroup(makeGroup("group1"));
    Id id2 = authManager.createGroup(makeGroup("group2"));
    Assert.assertEquals(2, authManager.listAllGroups(-1).size());
    HugeGroup group = authManager.deleteGroup(id1);
    Assert.assertEquals("group1", group.name());
    Assert.assertEquals(1, authManager.listAllGroups(-1).size());
    group = authManager.deleteGroup(id2);
    Assert.assertEquals("group2", group.name());
    Assert.assertEquals(0, authManager.listAllGroups(-1).size());
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Id user = authManager.createUser(makeUser("tom", "pass1"));
        authManager.deleteGroup(user);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Aggregations

HugeGroup (com.baidu.hugegraph.auth.HugeGroup)12 HugeGraph (com.baidu.hugegraph.HugeGraph)11 AuthManager (com.baidu.hugegraph.auth.AuthManager)7 Test (org.junit.Test)6 Id (com.baidu.hugegraph.backend.id.Id)5 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 HugeProject (com.baidu.hugegraph.auth.HugeProject)1 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)1 HugeUser (com.baidu.hugegraph.auth.HugeUser)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 After (org.junit.After)1