use of io.gravitee.rest.api.model.SubscriptionStatus in project gravitee-management-rest-api by gravitee-io.
the class ApiSubscribersResource method getSubscriberApplicationsByApiId.
@GET
@Produces({ MediaType.APPLICATION_JSON })
public Response getSubscriberApplicationsByApiId(@BeanParam PaginationParam paginationParam, @PathParam("apiId") String apiId, @QueryParam("statuses") List<SubscriptionStatus> statuses) {
String currentUser = getAuthenticatedUserOrNull();
final ApiQuery apiQuery = new ApiQuery();
apiQuery.setIds(Collections.singletonList(apiId));
Collection<ApiEntity> userApis = apiService.findPublishedByUser(currentUser, apiQuery);
Optional<ApiEntity> optionalApi = userApis.stream().filter(a -> a.getId().equals(apiId)).findFirst();
if (optionalApi.isPresent()) {
SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
subscriptionQuery.setApi(apiId);
subscriptionQuery.setStatuses(statuses);
ApiEntity api = optionalApi.get();
if (!api.getPrimaryOwner().getId().equals(currentUser)) {
Set<ApplicationListItem> userApplications = this.applicationService.findByUser(currentUser);
if (userApplications == null || userApplications.isEmpty()) {
return createListResponse(Collections.emptyList(), paginationParam);
}
subscriptionQuery.setApplications(userApplications.stream().map(ApplicationListItem::getId).collect(Collectors.toList()));
}
Map<String, Long> nbHitsByApp = getNbHitsByApplication(apiId);
Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
List<Application> subscribersApplication = subscriptions.stream().map(SubscriptionEntity::getApplication).distinct().map(application -> applicationService.findById(application)).map(application -> applicationMapper.convert(application, uriInfo)).sorted((o1, o2) -> compareApp(nbHitsByApp, o1, o2)).collect(Collectors.toList());
return createListResponse(subscribersApplication, paginationParam);
}
throw new ApiNotFoundException(apiId);
}
use of io.gravitee.rest.api.model.SubscriptionStatus in project gravitee-management-rest-api by gravitee-io.
the class ApplicationSubscribersResource method getSubscriberApisByApplicationId.
@GET
@Produces({ MediaType.APPLICATION_JSON })
public Response getSubscriberApisByApplicationId(@BeanParam PaginationParam paginationParam, @PathParam("applicationId") String applicationId, @QueryParam("statuses") List<SubscriptionStatus> statuses) {
String currentUser = getAuthenticatedUserOrNull();
Collection<ApplicationListItem> userApplications = applicationService.findByUser(currentUser);
Optional<ApplicationListItem> optionalApplication = userApplications.stream().filter(a -> a.getId().equals(applicationId)).findFirst();
if (optionalApplication.isPresent()) {
SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
subscriptionQuery.setApplication(applicationId);
subscriptionQuery.setStatuses(statuses);
ApplicationListItem application = optionalApplication.get();
if (!application.getPrimaryOwner().getId().equals(currentUser)) {
Set<ApiEntity> userApis = this.apiService.findPublishedByUser(currentUser);
if (userApis == null || userApis.isEmpty()) {
return createListResponse(Collections.emptyList(), paginationParam);
}
subscriptionQuery.setApis(userApis.stream().map(ApiEntity::getId).collect(Collectors.toList()));
}
Map<String, Long> nbHitsByApp = getNbHitsByApplication(applicationId);
Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
List<Api> subscribersApis = subscriptions.stream().map(SubscriptionEntity::getApi).distinct().map(api -> apiService.findById(api)).map(apiMapper::convert).sorted((o1, o2) -> compareApp(nbHitsByApp, o1, o2)).collect(Collectors.toList());
return createListResponse(subscribersApis, paginationParam);
}
throw new ApplicationNotFoundException(applicationId);
}
Aggregations