Search in sources :

Example 1 with Category

use of org.opennms.web.category.Category in project opennms by OpenNMS.

the class AvailabilityRestService method getCategory.

@GET
@Path("/categories/{category}")
public Category getCategory(@PathParam("category") final String categoryName) {
    try {
        final String category = URLDecoder.decode(categoryName, StandardCharsets.UTF_8.name());
        final Category cat = CategoryModel.getInstance().getCategory(category);
        if (cat == null) {
            throw getException(Status.NOT_FOUND, "Category {} was not found.", categoryName);
        }
        return cat;
    } catch (final IOException e) {
        LOG.warn("Failed to get availability data for category {}: {}", categoryName, e.getMessage(), e);
        throw getException(Status.INTERNAL_SERVER_ERROR, "Failed to get availability data for category {} : {}", categoryName, e.getMessage());
    }
}
Also used : Category(org.opennms.web.category.Category) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with Category

use of org.opennms.web.category.Category in project opennms by OpenNMS.

the class AvailabilityRestService method getCategoryNode.

@GET
@Path("/categories/{category}/nodes/{nodeId}")
public AvailabilityNode getCategoryNode(@PathParam("category") final String categoryName, @PathParam("nodeId") final Long nodeId) {
    try {
        final String category = URLDecoder.decode(categoryName, StandardCharsets.UTF_8.name());
        final Category cat = CategoryModel.getInstance().getCategory(category);
        if (cat == null) {
            throw getException(Status.NOT_FOUND, "Category {} was not found.", categoryName);
        }
        final AvailabilityNode node = cat.getNode(nodeId);
        if (node == null) {
            throw getException(Status.NOT_FOUND, "Node {} was not found for category {}.", Long.toString(nodeId), categoryName);
        }
        return getAvailabilityNode(node.getId().intValue());
    } catch (final Exception e) {
        LOG.warn("Failed to get availability data for category {}: {}", categoryName, e.getMessage(), e);
        throw getException(Status.INTERNAL_SERVER_ERROR, "Failed to get availability data for category {} : {}", categoryName, e.getMessage());
    }
}
Also used : Category(org.opennms.web.category.Category) AvailabilityNode(org.opennms.web.category.AvailabilityNode) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with Category

use of org.opennms.web.category.Category in project opennms by OpenNMS.

the class AvailabilityRestService method getCategoryNodes.

@GET
@Path("/categories/{category}/nodes")
public NodeList getCategoryNodes(@PathParam("category") final String categoryName) {
    try {
        final String category = URLDecoder.decode(categoryName, StandardCharsets.UTF_8.name());
        final Category cat = CategoryModel.getInstance().getCategory(category);
        if (cat == null) {
            throw getException(Status.NOT_FOUND, "Category {} was not found.", categoryName);
        }
        return cat.getNodes();
    } catch (final IOException e) {
        LOG.warn("Failed to get availability data for category {}: {}", categoryName, e.getMessage(), e);
        throw getException(Status.INTERNAL_SERVER_ERROR, "Failed to get availability data for category {} : {}", categoryName, e.getMessage());
    }
}
Also used : Category(org.opennms.web.category.Category) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

IOException (java.io.IOException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Category (org.opennms.web.category.Category)3 ServletException (javax.servlet.ServletException)1 AvailabilityNode (org.opennms.web.category.AvailabilityNode)1