ResultStore.java [src/csip] Revision:   Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API and application suite.
 *
 * 2012-2022, Olaf David and others, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package csip;

import csip.utils.Validation;
import org.codehaus.jettison.json.JSONArray;

/**
 *
 * @author od
 */
interface ResultStore extends AutoCloseable {

  /**
   *
   * @param digest digest
   * @return the result json.
   */
  JSONArray getResult(String digest);


  /**
   * Returns hash
   * @param digest digest
   * @param results result jsonarray
   */
  void putResult(String digest, JSONArray results);


  /**
   * Get the digest.
   * @param request request
   * @return the sha1 digest.
   */
  default String getDigest(String request) {
    request = request.replace(" ", "").replace("\n", "").replace("\t", "");
    return Validation.digest(request, "SHA1");
  }


  /**
   * Purge the results.
   */
  void purge();

  /**
   *
   */
  ResultStore NONE = new ResultStore() {
    @Override
    public JSONArray getResult(String digest) {
      return null;
    }


    @Override
    public void putResult(String digest, JSONArray results) {
    }


    @Override
    public void purge() {
    }


    @Override
    public void close() throws Exception {
    }
  };

}