Search in sources :

Example 6 with ChainException

use of org.apache.stanbol.enhancer.servicesapi.ChainException in project stanbol by apache.

the class EventJobManagerImpl method enhanceContent.

@Override
public void enhanceContent(ContentItem ci) throws EnhancementException {
    Chain defaultChain = chainManager.getDefault();
    if (defaultChain == null) {
        throw new ChainException("Unable to enhance ContentItem '" + ci.getUri() + "' because currently no enhancement chain is active. Please" + "configure a Chain or enable the default chain");
    }
    enhanceContent(ci, defaultChain);
}
Also used : Chain(org.apache.stanbol.enhancer.servicesapi.Chain) ChainException(org.apache.stanbol.enhancer.servicesapi.ChainException)

Example 7 with ChainException

use of org.apache.stanbol.enhancer.servicesapi.ChainException in project stanbol by apache.

the class EventJobManagerImpl method getActiveEngines.

@Override
public List<EnhancementEngine> getActiveEngines() {
    //This implementation return the list of active engined for the default
    //Chain in the order they would be executed
    Chain defaultChain = chainManager.getDefault();
    if (defaultChain == null) {
        throw new IllegalStateException("Currently no enhancement chain is " + "active. Please configure a Chain or enable the default chain");
    }
    ImmutableGraph ep;
    try {
        ep = defaultChain.getExecutionPlan();
    } catch (ChainException e) {
        throw new IllegalStateException("Unable to get Execution Plan for " + "default enhancement chain (name: '" + defaultChain.getName() + "'| class: '" + defaultChain.getClass() + "')!", e);
    }
    return ExecutionPlanHelper.getActiveEngines(engineManager, ep);
}
Also used : Chain(org.apache.stanbol.enhancer.servicesapi.Chain) ChainException(org.apache.stanbol.enhancer.servicesapi.ChainException) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph)

Example 8 with ChainException

use of org.apache.stanbol.enhancer.servicesapi.ChainException in project stanbol by apache.

the class ExecutionPlanHelper method validateExecutionPlan.

/**
     * Utility that checks if the parsed graph contains a valid execution
     * plan. This method is intended to be used by components that need to
     * ensure that an parsed graph contains a valid execution plan.<p>
     * This especially checks: <ul>
     * <li> if for all {@link ExecutionPlan#EXECUTION_NODE}s
     * <li> if they define a unary and valid value for the
     * {@link ExecutionPlan#ENGINE} property and
     * <li> if all {@link ExecutionPlan#DEPENDS_ON} values do actually point
     * to an other execution node in the parsed graph
     * <ul><p>
     * This method does not modify the parsed graph. Therefore it is save
     * to parse a {@link ImmutableGraph} object.<p>
     * TODO: There is no check for cycles implemented yet.
     * @param the graph to check
     * @return the engine names referenced by the validated execution plan-
     * @throws ChainException
     */
public static Set<String> validateExecutionPlan(Graph executionPlan) throws ChainException {
    Iterator<Triple> executionNodeIt = executionPlan.filter(null, RDF_TYPE, EXECUTION_NODE);
    Set<String> engineNames = new HashSet<String>();
    Map<BlankNodeOrIRI, Collection<BlankNodeOrIRI>> nodeDependencies = new HashMap<BlankNodeOrIRI, Collection<BlankNodeOrIRI>>();
    //1. check the ExecutionNodes
    while (executionNodeIt.hasNext()) {
        BlankNodeOrIRI node = executionNodeIt.next().getSubject();
        Iterator<String> engines = EnhancementEngineHelper.getStrings(executionPlan, node, ENGINE);
        if (!engines.hasNext()) {
            throw new ChainException("Execution Node " + node + " does not define " + "the required property " + ENGINE + "!");
        }
        String engine = engines.next();
        if (engines.hasNext()) {
            throw new ChainException("Execution Node " + node + " does not define " + "multiple values for the property " + ENGINE + "!");
        }
        if (engine.isEmpty()) {
            throw new ChainException("Execution Node " + node + " does not define " + "an empty String as engine name (property " + ENGINE + ")!");
        }
        engineNames.add(engine);
        Collection<BlankNodeOrIRI> dependsOn = new HashSet<BlankNodeOrIRI>();
        for (Iterator<Triple> t = executionPlan.filter(node, DEPENDS_ON, null); t.hasNext(); ) {
            RDFTerm o = t.next().getObject();
            if (o instanceof BlankNodeOrIRI) {
                dependsOn.add((BlankNodeOrIRI) o);
            } else {
                throw new ChainException("Execution Node " + node + " defines the literal '" + o + "' as value for the " + DEPENDS_ON + " property. However this" + "property requires values to be bNodes or URIs.");
            }
        }
        nodeDependencies.put(node, dependsOn);
    }
    //2. now check the dependency graph
    for (Entry<BlankNodeOrIRI, Collection<BlankNodeOrIRI>> entry : nodeDependencies.entrySet()) {
        if (entry.getValue() != null) {
            for (BlankNodeOrIRI dependent : entry.getValue()) {
                if (!nodeDependencies.containsKey(dependent)) {
                    throw new ChainException("Execution Node " + entry.getKey() + " defines a dependency to an non existent ex:ExectutionNode " + dependent + "!");
                }
            //else the dependency is valid
            }
        }
    //no dependencies
    }
    //done ... the parsed graph survived all consistency checks :)
    return engineNames;
}
Also used : HashMap(java.util.HashMap) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) EnhancementEngineHelper.getString(org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString) Triple(org.apache.clerezza.commons.rdf.Triple) Collection(java.util.Collection) ChainException(org.apache.stanbol.enhancer.servicesapi.ChainException) HashSet(java.util.HashSet)

Aggregations

ChainException (org.apache.stanbol.enhancer.servicesapi.ChainException)8 Chain (org.apache.stanbol.enhancer.servicesapi.Chain)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)2 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)2 Triple (org.apache.clerezza.commons.rdf.Triple)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)1 EnhancementJobObserver (org.apache.stanbol.enhancer.jobmanager.event.impl.EnhancementJobHandler.EnhancementJobObserver)1 EnhancementEngine (org.apache.stanbol.enhancer.servicesapi.EnhancementEngine)1 EnhancementException (org.apache.stanbol.enhancer.servicesapi.EnhancementException)1 EnhancementEngineHelper.getString (org.apache.stanbol.enhancer.servicesapi.helper.EnhancementEngineHelper.getString)1