Search in sources :

Example 11 with NoSuchPartException

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

the class ExecutionMetadataHelper method initExecutionMetadataContentPart.

/**
     * Getter/Initialiser for the execution metadata content part of the parsed
     * content item. This part is expected to be registered with the URI
     * {@link 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.<p>
     * Typically users will also want to use 
     * {@link #initExecutionMetadata(Graph, Graph, IRI, String, boolean)}
     * to initialise the state based on the grpah returned by this method.
     * NOTES:<ul>
     * <li> If a content part is registered under the URI 
     * {@link ExecutionMetadata#CHAIN_EXECUTION} that is not of type
     * {@link Graph} this method will replace it with an empty {@link Graph}.
     * <li> This method acquires a write lock on the content item while checking
     * for the content part.
     * </ul>
     * @param contentItem the contentItem
     * @return the {@link Graph} with the execution metadata as registered as
     * content part with the URI {@link ExecutionMetadata#CHAIN_EXECUTION} to 
     * the {@link ContentItem}
     * @throws IllegalArgumentException if the parsed content itme is <code>null</code>.
     */
public static Graph initExecutionMetadataContentPart(ContentItem contentItem) {
    if (contentItem == null) {
        throw new IllegalArgumentException("The parsed ContentItme MUST NOT be NULL!");
    }
    Graph executionMetadata;
    contentItem.getLock().writeLock().lock();
    try {
        try {
            executionMetadata = contentItem.getPart(CHAIN_EXECUTION, Graph.class);
        } catch (NoSuchPartException e) {
            executionMetadata = new IndexedGraph();
            contentItem.addPart(CHAIN_EXECUTION, executionMetadata);
        }
    } finally {
        contentItem.getLock().writeLock().unlock();
    }
    return executionMetadata;
}
Also used : IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) NoSuchPartException(org.apache.stanbol.enhancer.servicesapi.NoSuchPartException) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Aggregations

NoSuchPartException (org.apache.stanbol.enhancer.servicesapi.NoSuchPartException)11 IRI (org.apache.clerezza.commons.rdf.IRI)8 Graph (org.apache.clerezza.commons.rdf.Graph)4 Date (java.util.Date)3 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)3 FeatureStructure (org.apache.stanbol.commons.caslight.FeatureStructure)3 FeatureStructureListHolder (org.apache.stanbol.commons.caslight.FeatureStructureListHolder)3 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)3 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)2 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 Triple (org.apache.clerezza.commons.rdf.Triple)1 LiteralFactory (org.apache.clerezza.rdf.core.LiteralFactory)1 Feature (org.apache.stanbol.commons.caslight.Feature)1 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)1