public static void updateSummary(Map<String, AlertDefinitionSummary> summaries, Long definitionId, String definitionName,
                            AlertState state, Long originalTimestampObject, MaintenanceState maintenanceState,
                            String alertText) {
    // NPE sanity
    if (null == state) {
      state = AlertState.UNKNOWN;
    }

    // NPE sanity
    long originalTimestamp = 0;
    if (null != originalTimestampObject) {
      originalTimestamp = originalTimestampObject.longValue();
    }

    // NPE sanity
    boolean isMaintenanceModeEnabled = false;
    if (null != maintenanceState && maintenanceState != MaintenanceState.OFF) {
      isMaintenanceModeEnabled = true;
    }

    // create the group summary info if it doesn't exist yet
    AlertDefinitionSummary groupSummaryInfo = summaries.get(definitionName);
    if (null == groupSummaryInfo) {
      groupSummaryInfo = new AlertDefinitionSummary();
      groupSummaryInfo.Id = definitionId;
      groupSummaryInfo.Name = definitionName;

      summaries.put(definitionName, groupSummaryInfo);
    }

    // set and increment the correct values based on state
    final AlertStateValues alertStateValues;
    switch (state) {
      case CRITICAL: {
        alertStateValues = groupSummaryInfo.State.Critical;
        break;
      }
      case OK: {
        alertStateValues = groupSummaryInfo.State.Ok;
        break;
      }
      case WARNING: {
        alertStateValues = groupSummaryInfo.State.Warning;
        break;
      }
      default:
      case UNKNOWN: {
        alertStateValues = groupSummaryInfo.State.Unknown;
        break;
      }
    }

    // update the maintenance count if in MM is enabled, otherwise the
    // regular count
    if (isMaintenanceModeEnabled) {
      alertStateValues.MaintenanceCount++;
    } else {
      alertStateValues.Count++;
    }

    // check to see if this alerts time is sooner; if so, keep track of it
    // and of its text
    if (originalTimestamp > alertStateValues.Timestamp) {
      alertStateValues.Timestamp = originalTimestamp;
      alertStateValues.AlertText = alertText;
    }
  }
{@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