/** * 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()); }
/** {@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; }