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);
}
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);
}
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;
}
Aggregations