Class RdfSpdxDocumentModelManager

java.lang.Object
org.spdx.spdxRdfStore.RdfSpdxDocumentModelManager
All Implemented Interfaces:
org.spdx.storage.IModelStore.IModelStoreLock

public class RdfSpdxDocumentModelManager
extends Object
implements org.spdx.storage.IModelStore.IModelStoreLock
Manages the reads/write/updates for a specific Jena model associated with a document Since the ID's are not fully qualified with the URI, there is some complexity in this implementation. It is assumed that all ID's are subjects that are either Anonymous or URI types. If a URI type, the ID namespace is either the listed license namespace or the document URI.
Author:
Gary O'Neall
  • Field Details

    • model

      protected org.apache.jena.rdf.model.Model model
  • Constructor Details

    • RdfSpdxDocumentModelManager

      public RdfSpdxDocumentModelManager​(String documentUri, org.apache.jena.rdf.model.Model model)
      Parameters:
      documentUri - Unique URI for this document
      model - Model used to store this document
  • Method Details

    • exists

      public boolean exists​(String id)
      Parameters:
      id - ID of a resource in the model
      Returns:
      true if the resource represented by the ID is present
    • getOrCreate

      protected org.apache.jena.rdf.model.Resource getOrCreate​(String id, String type) throws org.spdx.library.SpdxInvalidIdException
      Gets an existing or creates a new resource with and ID and type
      Parameters:
      id - ID used in the SPDX model
      type - SPDX Type
      Returns:
      the resource
      Throws:
      org.spdx.library.SpdxInvalidIdException
      org.spdx.library.model.DuplicateSpdxIdException
    • getPropertyValueNames

      public List<String> getPropertyValueNames​(String id) throws org.spdx.library.SpdxInvalidIdException
      Parameters:
      id -
      Returns:
      all property names associated with the ID
      Throws:
      org.spdx.library.SpdxInvalidIdException
    • resourceToPropertyName

      protected static String resourceToPropertyName​(org.apache.jena.rdf.model.RDFNode node) throws SpdxRdfException
      Convert an RDFNode to a property name
      Parameters:
      node -
      Returns:
      Throws:
      SpdxRdfException
    • setValue

      public void setValue​(String id, String propertyName, Object value) throws org.spdx.library.InvalidSPDXAnalysisException
      Sets a property for an ID to a value
      Parameters:
      id -
      propertyName -
      value -
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • getPropertyValue

      public Optional<Object> getPropertyValue​(String id, String propertyName) throws org.spdx.library.InvalidSPDXAnalysisException
      Get the value associated with the property associated with the ID
      Parameters:
      id -
      propertyName -
      Returns:
      Optional value
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • getNextId

      public String getNextId​(org.spdx.storage.IModelStore.IdType idType) throws org.spdx.library.InvalidSPDXAnalysisException
      Get the next ID for the give ID type
      Parameters:
      idType -
      Returns:
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • removeProperty

      public void removeProperty​(String id, String propertyName) throws org.spdx.library.InvalidSPDXAnalysisException
      Remove a property associated with a given ID and all values associated with that property
      Parameters:
      id -
      propertyName -
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • getAllItems

      public java.util.stream.Stream<org.spdx.library.model.TypedValue> getAllItems​(@Nullable String typeFilter)
      Get all objects of TypedValue type from the model
      Parameters:
      typeFilter - if null, get all objects otherwise only return items that have a type equal to the filter
      Returns:
      Stream of all items matching the typeFilter
    • removeValueFromCollection

      public boolean removeValueFromCollection​(String id, String propertyName, Object value) throws org.spdx.library.InvalidSPDXAnalysisException
      Remove a specific value from a collection associated with an ID and property
      Parameters:
      id -
      propertyName -
      value -
      Returns:
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • collectionSize

      public int collectionSize​(String id, String propertyName) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id -
      propertyName -
      Returns:
      the total number of objects associated with the ID and property
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • collectionContains

      public boolean collectionContains​(String id, String propertyName, Object value) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id - ID of the resource containing a collection property
      propertyName - Name of the property with the collection
      value - value to check
      Returns:
      true if the value exists in the model as the object of a property associated with the ID
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • clearValueCollection

      public void clearValueCollection​(String id, String propertyName) throws org.spdx.library.InvalidSPDXAnalysisException
      Clear (remove) all values assocociated with the ID and property
      Parameters:
      id -
      propertyName -
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • addValueToCollection

      public boolean addValueToCollection​(String id, String propertyName, Object value) throws org.spdx.library.InvalidSPDXAnalysisException
      Add value to the list of objects where the subject is the id and the predicate is the propertyName
      Parameters:
      id -
      propertyName -
      value -
      Returns:
      true if the collection was modified
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • getValueList

      public Iterator<Object> getValueList​(String id, String propertyName) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id -
      propertyName -
      Returns:
      the list of values associated with id propertyName
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • isCollectionMembersAssignableTo

      public boolean isCollectionMembersAssignableTo​(String id, String propertyName, Class<?> clazz) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id -
      propertyName -
      clazz -
      Returns:
      true if all collection members associated with the property of id is assignable to clazz
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • isPropertyValueAssignableTo

      public boolean isPropertyValueAssignableTo​(String id, String propertyName, Class<?> clazz) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id -
      propertyName -
      clazz -
      Returns:
      true if there is a property value assignable to clazz
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • isCollectionProperty

      public boolean isCollectionProperty​(String id, String propertyName) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id -
      propertyName -
      Returns:
      true if the property of associated with id contains more than one object
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException
    • close

      public void close()
    • enterCriticalSection

      public org.spdx.storage.IModelStore.IModelStoreLock enterCriticalSection​(boolean readLockRequested)
    • unlock

      public void unlock()
      Specified by:
      unlock in interface org.spdx.storage.IModelStore.IModelStoreLock
    • serialize

      public void serialize​(OutputStream stream, OutputFormat outputFormat)
    • getCasesensitiveId

      public Optional<String> getCasesensitiveId​(String caseInsensisitiveId)
      Translate a case insensitive ID into a case sensitive ID
      Parameters:
      caseInsensisitiveId -
      Returns:
      case sensitive ID
    • delete

      public void delete​(String id) throws org.spdx.library.SpdxInvalidIdException
      Delete the entire resource and all statements
      Parameters:
      id -
      Throws:
      org.spdx.library.SpdxInvalidIdException
    • getTypedValue

      public Optional<org.spdx.library.model.TypedValue> getTypedValue​(String id) throws org.spdx.library.InvalidSPDXAnalysisException
      Parameters:
      id - associated with a type
      Returns:
      Type typed value for the ID if it exists and is of an SPDX type, otherwise empty
      Throws:
      org.spdx.library.InvalidSPDXAnalysisException