use of org.opennms.web.utils.QueryParameters in project opennms by OpenNMS.
the class StatusRestService method getApplications.
@GET
@Path("/applications")
public Response getApplications(@Context final UriInfo uriInfo) {
final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
final Query query = new Query(queryParameters, severityFilter);
final List<StatusEntity<OnmsApplication>> applications = applicationStatusService.getStatus(query);
final int totalCount = applicationStatusService.count(query);
final int offset = queryParameters.getOffset();
final List<ApplicationDTO> statusEntities = applications.stream().map(a -> {
ApplicationDTO dto = new ApplicationDTO();
dto.setId(a.getEntity().getId());
dto.setName(a.getEntity().getName());
dto.setSeverity(a.getStatus());
return dto;
}).collect(Collectors.toList());
final ApplicationDTOList list = new ApplicationDTOList(statusEntities);
list.setOffset(queryParameters.getOffset());
list.setTotalCount(totalCount);
return createResponse(list, offset, totalCount);
}
use of org.opennms.web.utils.QueryParameters in project opennms by OpenNMS.
the class StatusRestService method getNodes.
@GET
@Path("/nodes/{type}")
public Response getNodes(@Context final UriInfo uriInfo, @PathParam("type") String type) {
final NodeStatusCalculationStrategy strategy = NodeStatusCalculationStrategy.createFrom(type);
if (strategy == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Strategy '" + type + "' not supported. Supported values are:" + Arrays.toString(NodeStatusCalculationStrategy.values())).build();
}
final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
final NodeQuery query = new NodeQuery(queryParameters, severityFilter);
query.setStatusCalculationStrategy(strategy);
// Adjust order parameters
if (query.getParameters().getOrder() != null && query.getParameters().getOrder().getColumn().equals("label")) {
query.getParameters().setOrder(new QueryParameters.Order("node.nodelabel", query.getParameters().getOrder().isDesc()));
}
final List<StatusEntity<OnmsNode>> nodes = nodeStatusService.getStatus(query);
final int totalCount = nodeStatusService.count(query);
final int offset = queryParameters.getOffset();
final List<NodeDTO> statusEntities = nodes.stream().map(node -> {
NodeDTO nodeDTO = new NodeDTO();
nodeDTO.setId(node.getEntity().getId());
nodeDTO.setName(node.getEntity().getLabel());
nodeDTO.setSeverity(node.getStatus());
return nodeDTO;
}).collect(Collectors.toList());
final NodeDTOList list = new NodeDTOList(statusEntities);
list.setOffset(queryParameters.getOffset());
list.setTotalCount(totalCount);
return createResponse(list, offset, totalCount);
}
use of org.opennms.web.utils.QueryParameters in project opennms by OpenNMS.
the class AbstractStatusService method count.
public int count(Q query) {
final QueryParameters queryParameters = query.getParameters();
final SeverityFilter filter = query.getSeverityFilter();
final CriteriaBuilder builder = getCriteriaBuilder(queryParameters);
// Remove limit, offset and ordering to fetch count
builder.limit(null);
builder.offset(null);
builder.clearOrder();
// If a severity is given, we must count manually!
if (filter != null && filter.getSeverities() != null && !filter.getSeverities().isEmpty()) {
List<StatusEntity<T>> collect = findMatching(query, builder);
collect = apply(collect, filter);
return collect.size();
} else {
return countMatching(builder.toCriteria());
}
}
use of org.opennms.web.utils.QueryParameters in project opennms by OpenNMS.
the class AbstractStatusService method getStatus.
public List<StatusEntity<T>> getStatus(Q query) {
final QueryParameters queryParameters = query.getParameters();
final SeverityFilter filter = query.getSeverityFilter();
final CriteriaBuilder criteriaBuilder = getCriteriaBuilder(queryParameters);
// therefore it is not supported to order by severityon dao level.
if (isSeverityRelatedQuery(query)) {
criteriaBuilder.offset(null);
criteriaBuilder.limit(null);
// no column "severity" exists, clear it to avoid hibernate complaining about it
if (queryParameters.getOrder().getColumn().equals("severity")) {
criteriaBuilder.clearOrder();
}
}
// Query and apply filters
List<StatusEntity<T>> collect = findMatching(query, criteriaBuilder);
collect = apply(collect, filter);
// sort manually if required
if (queryParameters.getOrder() != null && queryParameters.getOrder().getColumn().equals("severity")) {
Comparator<StatusEntity<T>> comparator = Comparator.comparing(StatusEntity::getStatus);
if (queryParameters.getOrder().isDesc()) {
comparator = comparator.reversed();
}
collect.sort(comparator);
collect = subList(collect, queryParameters);
}
return collect;
}
use of org.opennms.web.utils.QueryParameters in project opennms by OpenNMS.
the class StatusRestService method getBusinessServices.
@GET
@Path("/business-services")
public Response getBusinessServices(@Context final UriInfo uriInfo) {
final QueryParameters queryParameters = QueryParametersBuilder.buildFrom(uriInfo);
final SeverityFilter severityFilter = getSeverityFilter(uriInfo);
final Query query = new Query(queryParameters, severityFilter);
final List<StatusEntity<BusinessService>> services = businessServiceStatusService.getStatus(query);
final int totalCount = businessServiceStatusService.count(query);
final int offset = queryParameters.getOffset();
final List<BusinessServiceDTO> statusEntities = services.stream().map(bs -> {
BusinessServiceDTO statusDTO = new BusinessServiceDTO();
statusDTO.setId(bs.getEntity().getId().intValue());
statusDTO.setName(bs.getEntity().getName());
statusDTO.setSeverity(bs.getStatus());
return statusDTO;
}).collect(Collectors.toList());
final BusinessServiceDTOList list = new BusinessServiceDTOList(statusEntities);
list.setOffset(queryParameters.getOffset());
list.setTotalCount(totalCount);
return createResponse(list, offset, totalCount);
}
Aggregations