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