Example #1
0
 @GET
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
 @Transactional(readOnly = true)
 public ResourceDTOCollection getResources(
     @DefaultValue("1") @QueryParam("depth") final int depth) {
   List<ResourceDTO> resources = Lists.newLinkedList();
   for (OnmsResource resource : m_resourceDao.findTopLevelResources()) {
     resources.add(ResourceDTO.fromResource(resource, depth));
   }
   return new ResourceDTOCollection(resources);
 }
Example #2
0
  @GET
  @Path("{resourceId}")
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
  @Transactional(readOnly = true)
  public ResourceDTO getResourceById(
      @PathParam("resourceId") final String resourceId,
      @DefaultValue("-1") @QueryParam("depth") final int depth) {
    OnmsResource resource = m_resourceDao.getResourceById(resourceId);
    if (resource == null) {
      throw getException(Status.NOT_FOUND, "No resource with id '{}' found.", resourceId);
    }

    return ResourceDTO.fromResource(resource, depth);
  }
Example #3
0
  @GET
  @Path("fornode/{nodeCriteria}")
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
  @Transactional(readOnly = true)
  public ResourceDTO getResourceForNode(
      @PathParam("nodeCriteria") final String nodeCriteria,
      @DefaultValue("-1") @QueryParam("depth") final int depth) {
    OnmsNode node = m_nodeDao.get(nodeCriteria);
    if (node == null) {
      throw getException(Status.NOT_FOUND, "No node found with criteria '{}'.", nodeCriteria);
    }

    OnmsResource resource = m_resourceDao.getResourceForNode(node);
    if (resource == null) {
      throw getException(
          Status.NOT_FOUND, "No resource found for node with id {}.", "" + node.getId());
    }

    return ResourceDTO.fromResource(resource, depth);
  }