org.apache.stanbol.enhancer.servicesapi.helper
Class ExecutionMetadataHelper

java.lang.Object
  extended by org.apache.stanbol.enhancer.servicesapi.helper.ExecutionMetadataHelper

public class ExecutionMetadataHelper
extends java.lang.Object

This class defines utility methods for writing and updating Execution Metadata. This will be usually needed by EnhancementJobManager implementations.

Author:
Rupert Westenthaler

Constructor Summary
ExecutionMetadataHelper()
           
 
Method Summary
static org.apache.clerezza.rdf.core.NonLiteral createChainExecutionNode(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral executionPlan, org.apache.clerezza.rdf.core.UriRef ciUri, boolean defaultChain)
           
static org.apache.clerezza.rdf.core.NonLiteral createEngineExecution(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral chainExecution, org.apache.clerezza.rdf.core.NonLiteral executionNode)
           
static org.apache.clerezza.rdf.core.NonLiteral getChainExecution(org.apache.clerezza.rdf.core.TripleCollection em, org.apache.clerezza.rdf.core.UriRef ciUri)
          Getter for the ChainExecution used to enhance the content item
static org.apache.clerezza.rdf.core.NonLiteral getChainExecutionForChainName(org.apache.clerezza.rdf.core.TripleCollection em, org.apache.clerezza.rdf.core.TripleCollection ep, java.lang.String chainName)
          Getter for the ExecutionMetadata.CHAIN_EXECUTION node of an graph containing ChainExecution metadata for the parsed Chain.getName().
static org.apache.clerezza.rdf.core.NonLiteral getChainExecutionForExecutionPlan(org.apache.clerezza.rdf.core.TripleCollection graph, org.apache.clerezza.rdf.core.NonLiteral executionPlanNode)
          Getter for the ExecutionMetadata.CHAIN_EXECUTION node of an graph containing ChainExecution metadata for the parsed ExecutionPlan.EXECUTION_PLAN node
static java.util.Date getCompleted(org.apache.clerezza.rdf.core.TripleCollection graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Getter for the completed dateTime of an 'em:Execution'
static org.apache.clerezza.rdf.core.NonLiteral getExecutionNode(org.apache.clerezza.rdf.core.TripleCollection graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Getter for the ep:ExecutionNode for a given em:Execution.
static org.apache.clerezza.rdf.core.NonLiteral getExecutionPlanNode(org.apache.clerezza.rdf.core.TripleCollection em, org.apache.clerezza.rdf.core.NonLiteral chainExecutionNode)
          Getter for the ep:ExecutionPlan node for the parsed em:ChainExecution node
static java.util.Set<org.apache.clerezza.rdf.core.NonLiteral> getExecutions(org.apache.clerezza.rdf.core.TripleCollection em, org.apache.clerezza.rdf.core.NonLiteral chainExecutionNode)
          Get ExecutionMetadata.EXECUTION nodes that are ExecutionMetadata.EXECUTION_PART of the parsed ExecutionMetadata.CHAIN_EXECUTION node
static java.util.Date getStarted(org.apache.clerezza.rdf.core.TripleCollection graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Getter for the started dateTime of an 'em:Execution'
static java.util.Map<org.apache.clerezza.rdf.core.NonLiteral,org.apache.clerezza.rdf.core.NonLiteral> initExecutionMetadata(org.apache.clerezza.rdf.core.MGraph em, org.apache.clerezza.rdf.core.TripleCollection ep, org.apache.clerezza.rdf.core.UriRef ciUri, java.lang.String chainName, java.lang.Boolean isDefaultChain)
          Initialises execution metadata based on the parsed parameter.
static org.apache.clerezza.rdf.core.MGraph initExecutionMetadataContentPart(ContentItem contentItem)
          Getter/Initialiser for the execution metadata content part of the parsed content item.
static boolean isExecutionFailed(org.apache.clerezza.rdf.core.TripleCollection graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Tests if the status if an execution is failed.
static boolean isExecutionFinished(org.apache.clerezza.rdf.core.TripleCollection graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Tests if the status if an execution has already finished.
static void setExecutionCompleted(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral execution, java.lang.String message)
          Sets the state of the ExecutionNode to completed
static void setExecutionFaild(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral execution, java.lang.String message)
          Set the parsed execution node to failed.
static void setExecutionInProgress(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Sets an execution node to in-progress.
static void setExecutionScheduled(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral execution)
          Sets the state of the ExecutionNode to scheduled and deletes any started, completed times
static void setExecutionSkipped(org.apache.clerezza.rdf.core.MGraph graph, org.apache.clerezza.rdf.core.NonLiteral execution, java.lang.String message)
          Sets an execution node to skipped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExecutionMetadataHelper

public ExecutionMetadataHelper()
Method Detail

createChainExecutionNode

public static org.apache.clerezza.rdf.core.NonLiteral createChainExecutionNode(org.apache.clerezza.rdf.core.MGraph graph,
                                                                               org.apache.clerezza.rdf.core.NonLiteral executionPlan,
                                                                               org.apache.clerezza.rdf.core.UriRef ciUri,
                                                                               boolean defaultChain)

createEngineExecution

public static org.apache.clerezza.rdf.core.NonLiteral createEngineExecution(org.apache.clerezza.rdf.core.MGraph graph,
                                                                            org.apache.clerezza.rdf.core.NonLiteral chainExecution,
                                                                            org.apache.clerezza.rdf.core.NonLiteral executionNode)

setExecutionCompleted

public static void setExecutionCompleted(org.apache.clerezza.rdf.core.MGraph graph,
                                         org.apache.clerezza.rdf.core.NonLiteral execution,
                                         java.lang.String message)
Sets the state of the ExecutionNode to completed

Parameters:
graph -
execution -
message - An optional message

setExecutionScheduled

public static void setExecutionScheduled(org.apache.clerezza.rdf.core.MGraph graph,
                                         org.apache.clerezza.rdf.core.NonLiteral execution)
Sets the state of the ExecutionNode to scheduled and deletes any started, completed times

Parameters:
graph - the graph holding the execution metadata
execution - the execution node

setExecutionFaild

public static void setExecutionFaild(org.apache.clerezza.rdf.core.MGraph graph,
                                     org.apache.clerezza.rdf.core.NonLiteral execution,
                                     java.lang.String message)
Set the parsed execution node to failed.

Parameters:
graph -
execution -
message - An message describing why the execution failed

setExecutionSkipped

public static void setExecutionSkipped(org.apache.clerezza.rdf.core.MGraph graph,
                                       org.apache.clerezza.rdf.core.NonLiteral execution,
                                       java.lang.String message)
Sets an execution node to skipped. This sets both the start and the completed time to the current time.

Parameters:
graph -
execution -
message - An optional message why this execution was skipped

setExecutionInProgress

public static void setExecutionInProgress(org.apache.clerezza.rdf.core.MGraph graph,
                                          org.apache.clerezza.rdf.core.NonLiteral execution)
Sets an execution node to in-progress. This also sets the start time to the current time

Parameters:
graph -
execution -

getChainExecutionForChainName

public static final org.apache.clerezza.rdf.core.NonLiteral getChainExecutionForChainName(org.apache.clerezza.rdf.core.TripleCollection em,
                                                                                          org.apache.clerezza.rdf.core.TripleCollection ep,
                                                                                          java.lang.String chainName)
Getter for the ExecutionMetadata.CHAIN_EXECUTION node of an graph containing ChainExecution metadata for the parsed Chain.getName(). If both the execution metadata and the execution plan are in the same graph one need to parse the same triple collection instance for both the execution metadata and the execution plan.

Parameters:
em - the triple collection containing execution metadata
ep - the triple collection containing the execution plan
chainName - the name of the executed chain
Returns:
the node or null if not found.

getChainExecutionForExecutionPlan

public static org.apache.clerezza.rdf.core.NonLiteral getChainExecutionForExecutionPlan(org.apache.clerezza.rdf.core.TripleCollection graph,
                                                                                        org.apache.clerezza.rdf.core.NonLiteral executionPlanNode)
Getter for the ExecutionMetadata.CHAIN_EXECUTION node of an graph containing ChainExecution metadata for the parsed ExecutionPlan.EXECUTION_PLAN node

Parameters:
graph - the graph containing the Execution Metadata
executionPlanNode - the ExecutionPlan.EXECUTION_PLAN node
Returns:
the ExecutionMetadata.CHAIN_EXECUTION node

initExecutionMetadataContentPart

public static org.apache.clerezza.rdf.core.MGraph initExecutionMetadataContentPart(ContentItem contentItem)
Getter/Initialiser for the execution metadata content part of the parsed content item. This part is expected to be registered with the URI ExecutionMetadata.CHAIN_EXECUTION. If it does not already exist this method creates an empty graph and register it with the parsed content item otherwise it returns the existing part registered under that URI.

Typically users will also want to use #initExecutionMetadata(MGraph, TripleCollection, UriRef, String, boolean) to initialise the state based on the grpah returned by this method. NOTES:

Parameters:
contentItem - the contentItem
Returns:
the MGraph with the execution metadata as registered as content part with the URI ExecutionMetadata.CHAIN_EXECUTION to the ContentItem
Throws:
java.lang.IllegalArgumentException - if the parsed content itme is null.

initExecutionMetadata

public static final java.util.Map<org.apache.clerezza.rdf.core.NonLiteral,org.apache.clerezza.rdf.core.NonLiteral> initExecutionMetadata(org.apache.clerezza.rdf.core.MGraph em,
                                                                                                                                         org.apache.clerezza.rdf.core.TripleCollection ep,
                                                                                                                                         org.apache.clerezza.rdf.core.UriRef ciUri,
                                                                                                                                         java.lang.String chainName,
                                                                                                                                         java.lang.Boolean isDefaultChain)
Initialises execution metadata based on the parsed parameter. If the parsed graph with the execution metadata is empty it will initialise the metadata based on the execution plan. If there are already metadata in the graph it will initialise the returned map based on the existing data.

This method can be therefore used to both:

If both the execution metadata and the execution plan are stored within the same graph users need to base this graph as both the first and second parameter

Parameters:
em - The graph containing the execution metadata. MUST NOT be NULL
ep - The graph containing the execution plan. MUST NOT be NULL
ciUri - the URI of the content item. MUST NOT be NULL
chainName - the name of the chain to execute. May be NULL if initialising from existing metadata. MUST NOT be NULL if initialising from empty execution metadata
isDefaultChain - if the chain to execute is the default chain. Will be ignored if initialising from existing execution metadata. MUST NOT be NULL if initialising from empty execution metadata
Returns:
A map containing all em:Execution nodes as key and the according ep:ExecutionNode of the execution plan as values.
Throws:
java.lang.IllegalArgumentException - if any of the requirements stated in the documentation for the parameters is not fulfilled.

getExecutionNode

public static org.apache.clerezza.rdf.core.NonLiteral getExecutionNode(org.apache.clerezza.rdf.core.TripleCollection graph,
                                                                       org.apache.clerezza.rdf.core.NonLiteral execution)
Getter for the ep:ExecutionNode for a given em:Execution.

Parameters:
graph - the graph containing the execution metadata
execution - the em:Execution node
Returns:
the ep:ExecutionNode node

getExecutions

public static java.util.Set<org.apache.clerezza.rdf.core.NonLiteral> getExecutions(org.apache.clerezza.rdf.core.TripleCollection em,
                                                                                   org.apache.clerezza.rdf.core.NonLiteral chainExecutionNode)
Get ExecutionMetadata.EXECUTION nodes that are ExecutionMetadata.EXECUTION_PART of the parsed ExecutionMetadata.CHAIN_EXECUTION node

Parameters:
em - the graph with the execution metadata
chainExecutionNode - the chain execution node
Returns:
the Set with all execution part of the chain execution

getExecutionPlanNode

public static org.apache.clerezza.rdf.core.NonLiteral getExecutionPlanNode(org.apache.clerezza.rdf.core.TripleCollection em,
                                                                           org.apache.clerezza.rdf.core.NonLiteral chainExecutionNode)
Getter for the ep:ExecutionPlan node for the parsed em:ChainExecution node

Parameters:
em - the execution metadata
chainExecutionNode - the chain execution node
Returns:
the execution plan node

getChainExecution

public static org.apache.clerezza.rdf.core.NonLiteral getChainExecution(org.apache.clerezza.rdf.core.TripleCollection em,
                                                                        org.apache.clerezza.rdf.core.UriRef ciUri)
Getter for the ChainExecution used to enhance the content item

Parameters:
em - the graph with the execution metadata
ciUri - the ID of the content item
Returns:
the node that ExecutionMetadata.ENHANCES the ContentItem

isExecutionFailed

public static boolean isExecutionFailed(org.apache.clerezza.rdf.core.TripleCollection graph,
                                        org.apache.clerezza.rdf.core.NonLiteral execution)
Tests if the status if an execution is failed.

Parameters:
graph - the graph with the execution metadata
execution - the execution node
Returns:
true if the status is faild. Otherwise false.

isExecutionFinished

public static boolean isExecutionFinished(org.apache.clerezza.rdf.core.TripleCollection graph,
                                          org.apache.clerezza.rdf.core.NonLiteral execution)
Tests if the status if an execution has already finished. This includes the states completed and failed.

Parameters:
graph - the graph with the execution metadata
execution - the execution node
Returns:
true if the execution has already finished

getStarted

public static java.util.Date getStarted(org.apache.clerezza.rdf.core.TripleCollection graph,
                                        org.apache.clerezza.rdf.core.NonLiteral execution)
Getter for the started dateTime of an 'em:Execution'

Parameters:
graph - the graph
execution - the execution instance
Returns:
the time or null if not present

getCompleted

public static java.util.Date getCompleted(org.apache.clerezza.rdf.core.TripleCollection graph,
                                          org.apache.clerezza.rdf.core.NonLiteral execution)
Getter for the completed dateTime of an 'em:Execution'

Parameters:
graph - the graph
execution - the execution instance
Returns:
the time or null if not present


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.