Search in sources :

Example 1 with GluuGroupApi

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();
    }
}
Also used : GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 2 with GluuGroupApi

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;
}
Also used : GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) ArrayList(java.util.ArrayList)

Example 3 with GluuGroupApi

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);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with GluuGroupApi

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);
    }
}
Also used : GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 5 with GluuGroupApi

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;
}
Also used : GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi)

Aggregations

GluuGroupApi (org.gluu.oxtrust.api.server.model.GluuGroupApi)8 IOException (java.io.IOException)5 HttpEntity (org.apache.http.HttpEntity)5 HttpResponse (org.apache.http.HttpResponse)5 ParseException (org.apache.http.ParseException)5 Test (org.junit.Test)5 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 ArrayList (java.util.ArrayList)2 HttpPost (org.apache.http.client.methods.HttpPost)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 HttpPut (org.apache.http.client.methods.HttpPut)1 GluuGroup (org.gluu.oxtrust.model.GluuGroup)1 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)1