@Override
  public Result finalizeResult(Result queryResult) {
    TreeNode<Resource> resultTree = queryResult.getResultTree();
    Map<String, AlertDefinitionSummary> summaries = new HashMap<>();

    // iterate over all returned flattened alerts and build the summary info
    for (TreeNode<Resource> node : resultTree.getChildren()) {
      Resource resource = node.getObject();

      Long definitionId = (Long) resource.getPropertyValue(AlertResourceProvider.ALERT_DEFINITION_ID);
      String definitionName = (String) resource.getPropertyValue(AlertResourceProvider.ALERT_DEFINITION_NAME);
      AlertState state = (AlertState) resource.getPropertyValue(AlertResourceProvider.ALERT_STATE);
      Long originalTimestampObject = (Long) resource.getPropertyValue(AlertResourceProvider.ALERT_ORIGINAL_TIMESTAMP);
      MaintenanceState maintenanceState = (MaintenanceState) resource.getPropertyValue(AlertResourceProvider.ALERT_MAINTENANCE_STATE);
      String alertText = (String) resource.getPropertyValue(AlertResourceProvider.ALERT_TEXT);

      updateSummary(summaries, definitionId, definitionName, state, originalTimestampObject, maintenanceState, alertText);
    }

    Set<Entry<String, AlertDefinitionSummary>> entrySet = summaries.entrySet();
    List<AlertDefinitionSummary> groupedResources = new ArrayList<>(
      entrySet.size());

    // iterate over all summary groups, adding them to the final list
    for (Entry<String, AlertDefinitionSummary> entry : entrySet) {
      groupedResources.add(entry.getValue());
    }

    Result groupedSummary = new ResultImpl(true);
    TreeNode<Resource> summaryTree = groupedSummary.getResultTree();

    Resource resource = new ResourceImpl(Resource.Type.Alert);
    summaryTree.addChild(resource, ALERTS_SUMMARY_GROUP);

    resource.setProperty(ALERTS_SUMMARY_GROUP, groupedResources);
    return groupedSummary;
  }
{@inheritDoc}
<p/>
This will iterate over all of the nodes in the result tree and combine
their {@link AlertResourceProvider#ALERT_STATE} into a single summary
structure.
ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertSummaryGroupedRenderer.java