use of com.redhat.cloud.notifications.db.Query in project notifications-backend by RedHatInsights.
the class EndpointResource method getEndpoints.
@GET
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
@Parameters({ @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page. If the value is 0, it will return all elements", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "pageNumber", in = ParameterIn.QUERY, description = "Page number. Starts at first page (0), if not specified starts at first page.", schema = @Schema(type = SchemaType.INTEGER)) })
public EndpointPage getEndpoints(@Context SecurityContext sec, @BeanParam Query query, @QueryParam("type") List<String> targetType, @QueryParam("active") Boolean activeOnly, @QueryParam("name") String name) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
List<Endpoint> endpoints;
Long count;
if (targetType != null && targetType.size() > 0) {
Set<CompositeEndpointType> compositeType = targetType.stream().map(s -> {
try {
return CompositeEndpointType.fromString(s);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unknown endpoint type: [" + s + "]", e);
}
}).collect(Collectors.toSet());
endpoints = endpointRepository.getEndpointsPerCompositeType(principal.getAccount(), name, compositeType, activeOnly, query);
count = endpointRepository.getEndpointsCountPerCompositeType(principal.getAccount(), name, compositeType, activeOnly);
} else {
endpoints = endpointRepository.getEndpoints(principal.getAccount(), name, query);
count = endpointRepository.getEndpointsCount(principal.getAccount(), name);
}
return new EndpointPage(endpoints, new HashMap<>(), new Meta(count));
}
Aggregations