/** * Count the method statuses for a {@link RestResource} * @param restResource The resource which statuses will be counted * @return The result of the status count */ protected Map<RestMethodStatus, Integer> getRestMethodStatusCount(final RestResource restResource){ Preconditions.checkNotNull(restResource, "The REST resource cannot be null"); final Map<RestMethodStatus, Integer> statuses = ImmutableSet.copyOf(RestMethodStatus.values()).stream() .collect(toMap(status -> status, status -> 0)); final List<RestMethod> methods = this.methodRepository.findWithResourceId(restResource.getId()); methods.stream() .map(RestMethod::getStatus) .forEach(status -> statuses.put(status, statuses.get(status)+1)); return statuses; }
/** * Count the method statuses for {@link RestApplication} * @param restApplication The application which statuses will be counted * @return The result of the status count */ protected Map<RestMethodStatus, Integer> getRestMethodStatusCount(final RestApplication restApplication){ Preconditions.checkNotNull(restApplication, "The REST application cannot be null"); final Map<RestMethodStatus, Integer> statuses = new HashMap<RestMethodStatus, Integer>(); for(RestMethodStatus restMethodStatus : RestMethodStatus.values()){ statuses.put(restMethodStatus, 0); } final List<String> resourceIds = this.resourceRepository.findIdsWithApplicationId(restApplication.getId()); for(String resourceId : resourceIds){ final List<RestMethod> methods = this.methodRepository.findWithResourceId(resourceId); for(RestMethod restMethod : methods){ RestMethodStatus restMethodStatus = restMethod.getStatus(); statuses.put(restMethodStatus, statuses.get(restMethodStatus)+1); } } return statuses; }