All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csip.ResultStore Maven / Gradle / Ivy

Go to download

The Cloud Services Integration Platform is a SoA implementation to offer a Model-as-a-Service framework, Application Programming Interface, deployment infrastructure, and service implementations for environmental modeling.

There is a newer version: 2.6.30
Show newest version
/*
 * $Id: ResultStore.java c4b9d8c126c7 2020-07-28 [email protected] $
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API and application suite.
 *
 * 2012-2019, 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 java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.bind.DatatypeConverter;
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", "");
    try {
      return DatatypeConverter.printHexBinary(MessageDigest.getInstance("SHA1")
          .digest(request.getBytes("UTF-8"))).toLowerCase();
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
      return null;
    }
  }


  /**
   * 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 {
    }
  };

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy