/**
   * createGraphResultSet
   *
   * @param resourceId a {@link java.lang.String} object.
   * @param resource a {@link org.opennms.netmgt.model.OnmsResource} object.
   * @param reports an array of {@link java.lang.String} objects.
   * @param graphResults a {@link org.opennms.web.svclayer.model.GraphResults} object.
   * @return a {@link org.opennms.web.svclayer.model.GraphResults.GraphResultSet} object.
   */
  private GraphResultSet createGraphResultSet(
      String resourceId, OnmsResource resource, String[] reports, GraphResults graphResults)
      throws IllegalArgumentException {
    if (resource == null) {
      resource = m_resourceDao.getResourceById(resourceId);
      if (resource == null) {
        throw new IllegalArgumentException("Could not find resource \"" + resourceId + "\"");
      }
    }
    GraphResultSet rs = graphResults.new GraphResultSet();
    rs.setResource(resource);

    if (reports.length == 1 && "all".equals(reports[0])) {
      PrefabGraph[] queries = m_graphDao.getPrefabGraphsForResource(resource);
      List<String> queryNames = new ArrayList<String>(queries.length);
      for (PrefabGraph query : queries) {
        queryNames.add(query.getName());
      }

      reports = queryNames.toArray(new String[queryNames.size()]);
    }

    List<Graph> graphs = new ArrayList<Graph>(reports.length);

    List<String> filesToPromote = new LinkedList<String>();
    for (String report : reports) {
      PrefabGraph prefabGraph = m_graphDao.getPrefabGraph(report);
      Graph graph =
          new Graph(prefabGraph, resource, graphResults.getStart(), graphResults.getEnd());
      getAttributeFiles(graph, filesToPromote);
      graphs.add(graph);
    }

    sendEvent(filesToPromote);

    /*
     * Sort the graphs by their order in the properties file. PrefabGraph
     * implements the Comparable interface.
     */
    Collections.sort(graphs);

    rs.setGraphs(graphs);

    return rs;
  }
  @Override
  public GraphResults findResults(
      String[] resourceIds, String[] reports, long start, long end, String relativeTime) {
    if (resourceIds == null) {
      throw new IllegalArgumentException("resourceIds argument cannot be null");
    }
    if (reports == null) {
      throw new IllegalArgumentException("reports argument cannot be null");
    }
    if (end < start) {
      throw new IllegalArgumentException("end time cannot be before start time");
    }

    GraphResults graphResults = new GraphResults();
    graphResults.setStart(new Date(start));
    graphResults.setEnd(new Date(end));
    graphResults.setRelativeTime(relativeTime);
    graphResults.setRelativeTimePeriods(m_periods);
    graphResults.setReports(reports);

    HashMap<String, List<OnmsResource>> resourcesMap = new HashMap<String, List<OnmsResource>>();

    for (String resourceId : resourceIds) {
      String[] values = parseResourceId(resourceId);
      if (values == null) {
        continue;
      }
      String parent = values[0];
      String childType = values[1];
      String childName = values[2];
      LOG.debug(
          "findResults: parent, childType, childName = {}, {}, {}",
          values[0],
          values[1],
          values[2]);
      OnmsResource resource = null;
      if (!resourcesMap.containsKey(parent)) {
        List<OnmsResource> resourceList =
            m_resourceDao.getResourceById(resourceId).getChildResources();
        if (resourceList == null) {
          LOG.warn("findResults: zero child resources found for {}", parent);
        } else {
          resourcesMap.put(parent, resourceList);
          LOG.debug("findResults: add resourceList to map for {}", parent);
        }
      }
      for (OnmsResource r : resourcesMap.get(parent)) {
        if (childType.equals(r.getResourceType().getName()) && childName.equals(r.getName())) {
          resource = r;
          LOG.debug("findResults: found resource in map{}", r.toString());
          break;
        }
      }
      try {
        graphResults.addGraphResultSet(
            createGraphResultSet(resourceId, resource, reports, graphResults));
      } catch (IllegalArgumentException e) {
        LOG.warn(e.getMessage(), e);
        continue;
      }
    }

    graphResults.setGraphTopOffsetWithText(m_rrdDao.getGraphTopOffsetWithText());
    graphResults.setGraphLeftOffset(m_rrdDao.getGraphLeftOffset());
    graphResults.setGraphRightOffset(m_rrdDao.getGraphRightOffset());

    return graphResults;
  }