private void renderDigestNotificationContent(NotificationDispatcher dispatcher,
      AlertNotification notification, List<AlertHistoryEntity> histories, AlertTargetEntity target)
      throws IOException {
    String targetType = target.getNotificationType();

    // build the velocity objects for template rendering
    AmbariInfo ambari = new AmbariInfo(m_metaInfo.get(), m_configuration);
    AlertSummaryInfo summary = new AlertSummaryInfo(histories);
    DispatchInfo dispatch = new DispatchInfo(target);

    // get the template for this target type
    final Writer subjectWriter = new StringWriter();
    final Writer bodyWriter = new StringWriter();
    final AlertTemplate template = m_alertTemplates.getTemplate(targetType);

    if (dispatcher.isNotificationContentGenerationRequired()) {
      if (null != template) {
        // create the velocity context for template rendering
        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put(VELOCITY_AMBARI_KEY, ambari);
        velocityContext.put(VELOCITY_SUMMARY_KEY, summary);
        velocityContext.put(VELOCITY_DISPATCH_KEY, dispatch);

        // render the template and assign the content to the notification
        String subjectTemplate = template.getSubject();
        String bodyTemplate = template.getBody();

        // render the subject
        Velocity.evaluate(velocityContext, subjectWriter, VELOCITY_LOG_TAG, subjectTemplate);

        // render the body
        Velocity.evaluate(velocityContext, bodyWriter, VELOCITY_LOG_TAG, bodyTemplate);
      } else {
        // a null template is possible from parsing incorrectly or not
        // having the correct type defined for the target
        for (AlertHistoryEntity alert : histories) {
          subjectWriter.write("Apache Ambari Alert Summary");
          bodyWriter.write(alert.getAlertState().name());
          bodyWriter.write(" ");
          bodyWriter.write(alert.getAlertDefinition().getLabel());
          bodyWriter.write(" ");
          bodyWriter.write(alert.getAlertText());
          bodyWriter.write("\n");
        }
      }
    }

    notification.Subject = subjectWriter.toString();
    notification.Body = bodyWriter.toString();
  }
Generates digest content for the {@link Notification} using the
{@link #m_alertTemplates} and the list of alerts passed in. If there is a
problem with the templates, this will fallback to non-formatted content.

@param dispatcher
         the dispatcher for this notification type (not {@code null}).
@param notification
         the notification (not {@code null}).
@param histories
         the alerts to generate the content from (not {@code null}.
@param target
         the target of the {@link Notification}.
ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java