Adding a Custom Evaluation Service

Follow these steps to define your own implementation of the IEvaluationService interface with custom evaluation logic:

1. Create the Spring Bean

Create a class that implements the IEvaluationService interface. You will need to implement the following methods:

public interface IEvaluationService {

  /**
   * @return true if limits that pass on evaluation should be stored in the datastore, false if they
   *     should be ignored
   */
  boolean includesPasses();

  /**
   * Evaluates all valid {@link LimitStructureDTO}s based on their current status and the {@link
   * com.activeviam.limits.cache.LimitsAsOfDate}
   *
   * @return The {@link IncidentDTO}s resulting from this evaluation
   */
  Collection<IncidentDTO> evaluateAllValidLimitStructures();

  /**
   * Evaluates all the limits of a KPI. We will group all alert tasks for this KPI into one alert
   * task to improve performance.
   *
   * @param limitStructureDTO - the {@link LimitStructureDTO} to evaluate
   */
  Collection<IncidentDTO> evaluateLimitStructure(LimitStructureDTO limitStructureDTO);

  /**
   * Evaluates the list of {@link LimitStructureEvaluationTask}s.
   *
   * @param structureTasks List of KPI alert tasks to execute
   */
  Collection<IncidentDTO> evaluateLimitStructures(Collection<LimitStructureEvaluationTask> structureTasks);

  /**
   * Evaluates the list of {@code limitEvaluationTasks}.
   *
   * @param limitEvaluationTasks - {@link LimitEvaluationTask}s to evaluate
   */
  Collection<IncidentDTO> evaluateLimits(Collection<LimitEvaluationTask> limitEvaluationTasks);

  /**
   * Writes results to an alerts file for a breach or warning kpi status.
   *
   * @param results the {@link IncidentDTO}s to write to file
   * @param fileName Name of the CSV file to write to
   */
  void writeFile(List<IncidentDTO> results, String fileName, String serverName);

  /**
   * Operations to perform after the evaluation of all limits.
   *
   * @param incidents the incidents resulting from the evaluation
   */
  void postEvaluation(Collection<IncidentDTO> incidents);

  /**
   * @return the {@link IEvaluationErrorHandler} used to handle errors during evaluation
   */
  IEvaluationErrorHandler getErrorHandler();

  /**
   * Gets the Connected Atoti server's AsOfDate dimension.
   *
   * @param serverName Name of server to get AsOfDate dimension for.
   * @return AsOfDate dimension for the given server
   */
  String getServerAsOfDateDimension(String serverName);

  /**
   * @return a {@link MdxRunner} used to execute MDX queries against the business cube
   */
  MdxRunner getMdxRunner();

  /**
   * @return the {@link ILimitsProcessInstanceWorkflowService} used for processing limit workflows
   */
  ILimitsProcessInstanceWorkflowService getLimitsProcessInstanceWorkflowService();
}

note

Make sure to include the @Primary annotation in your class, which tells Spring to use your implementation instead of DefaultEvaluationService.

Evaluation logic should be implemented in the evaluate* methods. The postEvaluation method is invoked after all limits have been evaluated, but before returning the results, so it provides an opportunity to hook into and do any post-processing of the evaluation results before they are presented to users.

2. Import the Spring Bean

Once the bean is created, import it into the project. See Importing Spring Beans into the Project on how to do this. Once done, Spring injects it in all classes that use IEvaluationService.