use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.
the class GroupWebResource method getGroupMembers.
@GET
@Path(ApiConstants.INUM_PARAM_PATH + ApiConstants.GROUP_MEMBERS)
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuPersonApi[].class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Operation(summary = "Get group members", description = "Get a group members")
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response getGroupMembers(@PathParam(ApiConstants.INUM) @NotNull String inum) {
log("Get members of group " + inum);
inum = inum.equalsIgnoreCase("") ? null : inum;
try {
Objects.requireNonNull(inum, "inum should not be null");
GluuGroup group = groupService.getGroupByInum(inum);
List<String> members = new ArrayList<String>();
if (group != null) {
GluuGroupApi gluuGroupApi = convert(Arrays.asList(group)).get(0);
members = gluuGroupApi.getMembers();
return Response.ok(computeMembers(members)).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.
the class GroupWebResource method convert.
private List<GluuGroupApi> convert(List<GluuGroup> gluuGroups) {
List<GluuGroupApi> result = new ArrayList<GluuGroupApi>();
gluuGroups.stream().forEach(e -> {
result.add(new GluuGroupApi(e));
});
return result;
}
use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.
the class GroupWebResourceTest method listGroupsTest.
@Test
public void listGroupsTest() {
HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.GROUPS);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
try {
String content = EntityUtils.toString(entity);
GluuGroupApi[] goups = mapper.readValue(content, GluuGroupApi[].class);
Assert.assertTrue(goups.length >= 1);
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.
the class GroupWebResourceTest method updateGroupTest.
@Test
public void updateGroupTest() {
String name = "AnotherGroup";
GluuGroupApi group = getGroup(name);
HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.GROUPS);
try {
HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(group).toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
request.setEntity(entity);
request.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
GluuGroupApi myGroup = mapper.readValue(EntityUtils.toString(response.getEntity()), GluuGroupApi.class);
Assert.assertEquals(myGroup.getDisplayName(), name);
myGroup.setDescription(myGroup.getDescription() + " Updated");
HttpPut second = new HttpPut(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.GROUPS);
entity = new ByteArrayEntity(mapper.writeValueAsString(myGroup).toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
second.setEntity(entity);
second.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
response = handle(second);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.
the class GroupWebResourceTest method getGroup.
private GluuGroupApi getGroup(String name) {
GluuGroupApi groupApi = new GluuGroupApi();
groupApi.setDescription(name + " description");
groupApi.setDisplayName(name);
groupApi.setStatus(GluuStatus.ACTIVE);
groupApi.setMembers(new ArrayList<>());
return groupApi;
}
Aggregations