Search in sources :

Example 1 with GroupDescApiBean

use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.

the class FeatureStoreHttp method readAllGroups.

/**
 * {@inheritDoc}
 */
@Override
public Set<String> readAllGroups() {
    ClientResponse cRes = getGroups().get(ClientResponse.class);
    List<GroupDescApiBean> groupApiBeans = cRes.getEntity(new GenericType<List<GroupDescApiBean>>() {
    });
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot read groups, an HTTP error " + cRes.getStatus() + OCCURED);
    }
    Set<String> groupNames = new HashSet<String>();
    for (GroupDescApiBean groupApiBean : groupApiBeans) {
        groupNames.add(groupApiBean.getGroupName());
    }
    return groupNames;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) List(java.util.List) GroupDescApiBean(org.ff4j.web.api.resources.domain.GroupDescApiBean) HashSet(java.util.HashSet)

Example 2 with GroupDescApiBean

use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.

the class GroupsResourceGetTestIT method getGroups.

/**
 * TDD.
 */
@Test
public void getGroups() {
    // Given
    Assert.assertEquals(2, ff4j.getFeatureStore().readAllGroups().size());
    // When
    WebResource wResff4j = resourceGroups();
    ClientResponse resHttp = wResff4j.get(ClientResponse.class);
    List<GroupDescApiBean> groupApiBeans = resHttp.getEntity(new GenericType<List<GroupDescApiBean>>() {
    });
    // Then, HTTPResponse
    Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
    // Then, Entity Object
    Assert.assertNotNull(groupApiBeans);
    Assert.assertEquals(2, groupApiBeans.size());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) GroupDescApiBean(org.ff4j.web.api.resources.domain.GroupDescApiBean) Test(org.junit.Test)

Example 3 with GroupDescApiBean

use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.

the class FeatureStoreResource method readGroups.

/**
 * Access groups part of the API.
 *
 * @return groups resource
 */
@GET
@Path("/" + RESOURCE_GROUPS)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Display information regarding <b>Groups</b>", response = GroupDescApiBean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Groups resource", response = GroupDescApiBean.class) })
public List<GroupDescApiBean> readGroups() {
    Map<String, Feature> features = getFeatureStore().readAll();
    Map<String, GroupDescApiBean> groups = new HashMap<String, GroupDescApiBean>();
    if (features != null && !features.isEmpty()) {
        // Build groups from features
        for (Map.Entry<String, Feature> featureName : features.entrySet()) {
            String groupName = featureName.getValue().getGroup();
            // Add current group to list
            if (groupName != null && !groupName.isEmpty()) {
                if (!groups.containsKey(groupName)) {
                    groups.put(groupName, new GroupDescApiBean(groupName, new ArrayList<String>()));
                }
                groups.get(groupName).getFeatures().add(featureName.getKey());
            }
        }
    }
    return new ArrayList<GroupDescApiBean>(groups.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Feature(org.ff4j.core.Feature) HashMap(java.util.HashMap) Map(java.util.Map) GroupDescApiBean(org.ff4j.web.api.resources.domain.GroupDescApiBean) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with GroupDescApiBean

use of org.ff4j.web.api.resources.domain.GroupDescApiBean in project ff4j by ff4j.

the class GroupsResourceGetTestIT method getGroups.

/**
 * TDD.
 */
@Test
public void getGroups() {
    // Given
    Assert.assertEquals(2, ff4j.getFeatureStore().readAllGroups().size());
    // When
    WebTarget wResFeatures = resourceGroups();
    Response resHttp = wResFeatures.request().get();
    List<GroupDescApiBean> groupApiBeans = resHttp.readEntity(new GenericType<List<GroupDescApiBean>>() {
    });
    // Then, HTTPResponse
    Assert.assertEquals("Expected status is 200", Status.OK.getStatusCode(), resHttp.getStatus());
    // Then, Entity Object
    Assert.assertNotNull(groupApiBeans);
    Assert.assertEquals(2, groupApiBeans.size());
}
Also used : Response(javax.ws.rs.core.Response) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) GroupDescApiBean(org.ff4j.web.api.resources.domain.GroupDescApiBean) Test(org.junit.Test)

Aggregations

GroupDescApiBean (org.ff4j.web.api.resources.domain.GroupDescApiBean)4 List (java.util.List)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 Test (org.junit.Test)2 WebResource (com.sun.jersey.api.client.WebResource)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 Feature (org.ff4j.core.Feature)1 FeatureAccessException (org.ff4j.exception.FeatureAccessException)1