Search in sources :

Example 1 with QueryParameters

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);
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) QueryParameters(org.opennms.web.utils.QueryParameters) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Produces(javax.ws.rs.Produces) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) GET(javax.ws.rs.GET) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) JaxbListWrapper(org.opennms.core.config.api.JaxbListWrapper) ApplicationStatusService(org.opennms.features.status.api.application.ApplicationStatusService) Strings(com.google.common.base.Strings) MediaType(javax.ws.rs.core.MediaType) StatusSummary(org.opennms.features.status.api.StatusSummary) BusinessServiceStatusService(org.opennms.features.status.api.bsm.BusinessServiceStatusService) Map(java.util.Map) NodeQuery(org.opennms.features.status.api.node.NodeQuery) QueryParametersBuilder(org.opennms.web.utils.QueryParametersBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) SeverityFilter(org.opennms.features.status.api.SeverityFilter) Context(javax.ws.rs.core.Context) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Query(org.opennms.features.status.api.Query) NodeStatusService(org.opennms.features.status.api.node.NodeStatusService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityFilter(org.opennms.features.status.api.SeverityFilter) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) NodeQuery(org.opennms.features.status.api.node.NodeQuery) Query(org.opennms.features.status.api.Query) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with QueryParameters

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);
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) QueryParameters(org.opennms.web.utils.QueryParameters) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Produces(javax.ws.rs.Produces) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) GET(javax.ws.rs.GET) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) JaxbListWrapper(org.opennms.core.config.api.JaxbListWrapper) ApplicationStatusService(org.opennms.features.status.api.application.ApplicationStatusService) Strings(com.google.common.base.Strings) MediaType(javax.ws.rs.core.MediaType) StatusSummary(org.opennms.features.status.api.StatusSummary) BusinessServiceStatusService(org.opennms.features.status.api.bsm.BusinessServiceStatusService) Map(java.util.Map) NodeQuery(org.opennms.features.status.api.node.NodeQuery) QueryParametersBuilder(org.opennms.web.utils.QueryParametersBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) SeverityFilter(org.opennms.features.status.api.SeverityFilter) Context(javax.ws.rs.core.Context) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Query(org.opennms.features.status.api.Query) NodeStatusService(org.opennms.features.status.api.node.NodeStatusService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityFilter(org.opennms.features.status.api.SeverityFilter) NodeQuery(org.opennms.features.status.api.node.NodeQuery) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with QueryParameters

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());
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) QueryParameters(org.opennms.web.utils.QueryParameters)

Example 4 with QueryParameters

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) QueryParameters(org.opennms.web.utils.QueryParameters)

Example 5 with QueryParameters

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);
}
Also used : Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) QueryParameters(org.opennms.web.utils.QueryParameters) NodeStatusCalculationStrategy(org.opennms.features.status.api.node.strategy.NodeStatusCalculationStrategy) Produces(javax.ws.rs.Produces) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) GET(javax.ws.rs.GET) NodeDTO(org.opennms.web.rest.v2.status.model.NodeDTO) Path(javax.ws.rs.Path) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) JaxbListWrapper(org.opennms.core.config.api.JaxbListWrapper) ApplicationStatusService(org.opennms.features.status.api.application.ApplicationStatusService) Strings(com.google.common.base.Strings) MediaType(javax.ws.rs.core.MediaType) StatusSummary(org.opennms.features.status.api.StatusSummary) BusinessServiceStatusService(org.opennms.features.status.api.bsm.BusinessServiceStatusService) Map(java.util.Map) NodeQuery(org.opennms.features.status.api.node.NodeQuery) QueryParametersBuilder(org.opennms.web.utils.QueryParametersBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) ApplicationDTO(org.opennms.web.rest.v2.status.model.ApplicationDTO) SeverityFilter(org.opennms.features.status.api.SeverityFilter) Context(javax.ws.rs.core.Context) NodeDTOList(org.opennms.web.rest.v2.status.model.NodeDTOList) Query(org.opennms.features.status.api.Query) NodeStatusService(org.opennms.features.status.api.node.NodeStatusService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ApplicationDTOList(org.opennms.web.rest.v2.status.model.ApplicationDTOList) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) SeverityFilter(org.opennms.features.status.api.SeverityFilter) NodeQuery(org.opennms.features.status.api.node.NodeQuery) Query(org.opennms.features.status.api.Query) BusinessServiceDTOList(org.opennms.web.rest.v2.status.model.BusinessServiceDTOList) BusinessServiceDTO(org.opennms.web.rest.v2.status.model.BusinessServiceDTO) QueryParameters(org.opennms.web.utils.QueryParameters) StatusEntity(org.opennms.features.status.api.StatusEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

QueryParameters (org.opennms.web.utils.QueryParameters)6 Strings (com.google.common.base.Strings)3 Arrays (java.util.Arrays)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 PathParam (javax.ws.rs.PathParam)3 Produces (javax.ws.rs.Produces)3 Context (javax.ws.rs.core.Context)3 MediaType (javax.ws.rs.core.MediaType)3 Response (javax.ws.rs.core.Response)3 UriInfo (javax.ws.rs.core.UriInfo)3 JaxbListWrapper (org.opennms.core.config.api.JaxbListWrapper)3 Query (org.opennms.features.status.api.Query)3 SeverityFilter (org.opennms.features.status.api.SeverityFilter)3 StatusEntity (org.opennms.features.status.api.StatusEntity)3 StatusSummary (org.opennms.features.status.api.StatusSummary)3