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);
}
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);
}
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);
}
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);
}
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);
});
}
Aggregations