Search in sources :

Example 6 with ScriptFailedException

use of com.inova8.intelligentgraph.exceptions.ScriptFailedException in project com.inova8.intelligentgraph by peterjohnlawrence.

the class SEEQSource method getSEEQSignal.

/**
 * Gets the SEEQ signal.
 *
 * @param thing the thing
 * @param signal the signal
 * @param customQueryOptions the custom query options
 * @return the SEEQ signal
 * @throws ScriptFailedException the script failed exception
 */
public static Resource getSEEQSignal(Thing thing, String signal, CustomQueryOptions customQueryOptions) throws ScriptFailedException {
    signal = Utilities.trimIRIString(signal);
    String[] elements = signal.split("/");
    Object result;
    SEEQSource seeqSource = null;
    try {
        if (elements.length < 6) {
            thing.getEvaluationContext().getTracer().decrementLevel();
            String error = String.format("Unsupported signal source: %s", signal);
            logger.error(error);
            thing.getEvaluationContext().getTracer().traceSignalError(error);
            throw new ScriptFailedException(error);
        } else {
            thing.getEvaluationContext().getTracer().traceSEEQ(elements[5], customQueryOptions);
            seeqSource = thing.getSource().seeqSourceFactory(elements[2]);
            result = seeqSource.getSignal(elements[5], customQueryOptions);
            thing.getEvaluationContext().getTracer().decrementLevel();
            return Resource.create(thing.getSource(), literal((Double) result), thing.getEvaluationContext());
        }
    } catch (ScriptException e) {
        throw new ScriptFailedException(e);
    } catch (HandledException e) {
        throw new ScriptFailedException(e);
    }
}
Also used : HandledException(com.inova8.intelligentgraph.exceptions.HandledException) ScriptException(javax.script.ScriptException) ScriptFailedException(com.inova8.intelligentgraph.exceptions.ScriptFailedException)

Aggregations

ScriptFailedException (com.inova8.intelligentgraph.exceptions.ScriptFailedException)6 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)3 IRI (org.eclipse.rdf4j.model.IRI)3 ScriptException (javax.script.ScriptException)2 CircularReferenceException (com.inova8.intelligentgraph.exceptions.CircularReferenceException)1 HandledException (com.inova8.intelligentgraph.exceptions.HandledException)1 NullValueReturnedException (com.inova8.intelligentgraph.exceptions.NullValueReturnedException)1 Resource (com.inova8.intelligentgraph.model.Resource)1 Prefixes (com.inova8.pathql.context.Prefixes)1 AlternativePathElement (com.inova8.pathql.element.AlternativePathElement)1 BoundPathElement (com.inova8.pathql.element.BoundPathElement)1 PathElement (com.inova8.pathql.element.PathElement)1 QueryOptionsPathElement (com.inova8.pathql.element.QueryOptionsPathElement)1 SequencePathElement (com.inova8.pathql.element.SequencePathElement)1 CompiledScript (javax.script.CompiledScript)1 SimpleBindings (javax.script.SimpleBindings)1 Statement (org.eclipse.rdf4j.model.Statement)1 SimpleLiteral (org.eclipse.rdf4j.model.impl.SimpleLiteral)1 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)1