private Resource toResource(boolean isCollection, String clusterName,
      AlertCurrentEntity entity, Set<String> requestedIds) {
    AlertHistoryEntity history = entity.getAlertHistory();
    AlertDefinitionEntity definition = history.getAlertDefinition();

    Resource resource = new ResourceImpl(Resource.Type.Alert);
    setResourceProperty(resource, ALERT_CLUSTER_NAME, clusterName, requestedIds);
    setResourceProperty(resource, ALERT_ID, entity.getAlertId(), requestedIds);
    // TODO remove after UI-side fix
    setResourceProperty(resource, ALERT_LATEST_TIMESTAMP, entity.getLatestTimestamp(), requestedIds);
    setResourceProperty(resource, ALERT_MAINTENANCE_STATE, entity.getMaintenanceState(), requestedIds);
    setResourceProperty(resource, ALERT_ORIGINAL_TIMESTAMP, entity.getOriginalTimestamp(), requestedIds);
    setResourceProperty(resource, ALERT_TEXT, entity.getLatestText(), requestedIds);

    setResourceProperty(resource, ALERT_INSTANCE, history.getAlertInstance(), requestedIds);
    setResourceProperty(resource, ALERT_LABEL, definition.getLabel(), requestedIds);
    setResourceProperty(resource, ALERT_STATE, history.getAlertState(), requestedIds);
    setResourceProperty(resource, ALERT_COMPONENT, history.getComponentName(), requestedIds);
    setResourceProperty(resource, ALERT_HOST, history.getHostName(), requestedIds);
    setResourceProperty(resource, ALERT_SERVICE, history.getServiceName(), requestedIds);

    setResourceProperty(resource, ALERT_DEFINITION_ID, definition.getDefinitionId(),requestedIds);
    setResourceProperty(resource, ALERT_DEFINITION_NAME, definition.getDefinitionName(), requestedIds);
    setResourceProperty(resource, ALERT_SCOPE, definition.getScope(), requestedIds);

    // repeat tolerance values
    int repeatTolerance = getRepeatTolerance(definition, clusterName);
    long occurrences = entity.getOccurrences();
    long remaining = (occurrences > repeatTolerance) ? 0 : (repeatTolerance - occurrences);

    // the OK state is special; when received, we ignore tolerance and assume
    // the alert is HARD
    if (history.getAlertState() == AlertState.OK) {
      remaining = 0;
    }

    setResourceProperty(resource, ALERT_REPEAT_TOLERANCE, repeatTolerance, requestedIds);
    setResourceProperty(resource, ALERT_OCCURRENCES, occurrences, requestedIds);
    setResourceProperty(resource, ALERT_REPEAT_TOLERANCE_REMAINING, remaining, requestedIds);
    setResourceProperty(resource, ALERT_FIRMNESS, entity.getFirmness(), requestedIds);

    if (isCollection) {
      // !!! want name/id to be populated as if it were a PK when requesting the
      // collection
      resource.setProperty(ALERT_DEFINITION_ID, definition.getDefinitionId());
      resource.setProperty(ALERT_DEFINITION_NAME, definition.getDefinitionName());
    }

    return resource;
  }
Converts an entity to a resource.

@param isCollection {@code true} if the response is for a collection
@param clusterName the cluster name
@param entity the entity
@param requestedIds the requested ids
@return the resource
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java