ResultStore.java [src/csip] Revision: 71821307bfe742c00c6dc582c171224a9ac59935 Date: Fri Apr 21 11:46:19 MDT 2017
/*
* $Id$
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API and application suite.
*
* 2012-2017, 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;
/**
*
* @author od
*/
interface ResultStore {
/**
*
* @param request
* @return the result json.
* @throws Exception
*/
String getResult(String request);
/**
* Returns hash
* @param digest
* @param results
* @throws Exception
*/
void putResult(String digest, String results);
/**
* Get the digest.
* @param 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();
/**
* Shut down the resource
* @throws Exception
*/
default void shutdown() throws Exception {
}
/**
*
*/
ResultStore NONE = new ResultStore() {
@Override
public String getResult(String request) {
return null;
}
@Override
public void putResult(String digest, String results) {
}
@Override
public String getDigest(String request) {
return null;
}
@Override
public void purge() {
}
};
}