Class RdfSpdxModelManager

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

public class RdfSpdxModelManager extends Object implements org.spdx.storage.IModelStore.IModelStoreLock
Manages the reads/write/updates for a specific Jena model associated with a document

Since the IDs are not fully qualified with the URI, there is some complexity in this implementation.

It is assumed that all IDs 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 final org.apache.jena.rdf.model.Model model
  • Constructor Details

    • RdfSpdxModelManager

      public RdfSpdxModelManager(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 objectUri, String type) throws org.spdx.core.SpdxInvalidIdException
      Gets an existing or creates a new resource with and ID and type
      Parameters:
      objectUri - uri or anon type string
      type - SPDX Type
      Returns:
      the resource
      Throws:
      org.spdx.core.SpdxInvalidIdException - on invalid SPDX id
    • getPropertyValueNames

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

      protected static String resourceToPropertyName(org.apache.jena.rdf.model.RDFNode node) throws SpdxRdfException
      Convert an RDFNode to a property name
      Parameters:
      node - RDF node for a resource
      Returns:
      a property name
      Throws:
      SpdxRdfException - On SPDX parsing errors
    • setValue

      public void setValue(String id, String propertyName, Object value) throws org.spdx.core.InvalidSPDXAnalysisException
      Sets a property for an ID to a value
      Parameters:
      id - SPDX ID
      propertyName - property name
      value - value to set
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • getPropertyValue

      public Optional<Object> getPropertyValue(String id, String propertyName) throws org.spdx.core.InvalidSPDXAnalysisException
      Get the value associated with the property associated with the ID
      Parameters:
      id - SPDX ID
      propertyName - property name
      Returns:
      Optional value
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • getNextId

      public String getNextId(org.spdx.storage.IModelStore.IdType idType) throws org.spdx.core.InvalidSPDXAnalysisException
      Get the next ID for the give ID type
      Parameters:
      idType - type of ID
      Returns:
      next ID available
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • removeProperty

      public void removeProperty(String id, String propertyName) throws org.spdx.core.InvalidSPDXAnalysisException
      Remove a property associated with a given ID and all values associated with that property
      Parameters:
      id - SPDX ID
      propertyName - property name
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • getAllItems

      public Stream<org.spdx.core.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.core.InvalidSPDXAnalysisException
      Remove a specific value from a collection associated with an ID and property
      Parameters:
      id - SPDX ID
      propertyName - property name
      value - value to set
      Returns:
      true if the value was present
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • collectionSize

      public int collectionSize(String id, String propertyName) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      id - SPDX ID
      propertyName - property name
      Returns:
      the total number of objects associated with the ID and property
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • collectionContains

      public boolean collectionContains(String id, String propertyName, Object value) throws org.spdx.core.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.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • clearValueCollection

      public void clearValueCollection(String id, String propertyName) throws org.spdx.core.InvalidSPDXAnalysisException
      Clear (remove) all values associated with the ID and property
      Parameters:
      id - SPDX ID
      propertyName - property name
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • addValueToCollection

      public boolean addValueToCollection(String id, String propertyName, Object value) throws org.spdx.core.InvalidSPDXAnalysisException
      Add value to the list of objects where the subject is the id and the predicate are the propertyName
      Parameters:
      id - SPDX ID
      propertyName - property name
      value - value to add
      Returns:
      true if the collection was modified
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • getValueList

      public Iterator<Object> getValueList(String id, String propertyName) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      id - SPDX ID
      propertyName - property name
      Returns:
      the list of values associated with id propertyName
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • isCollectionMembersAssignableTo

      public boolean isCollectionMembersAssignableTo(String id, String propertyName, Class<?> clazz) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      id - SPDX ID
      propertyName - property name
      clazz - class to check for assignability
      Returns:
      true if all collection members associated with the property of id is assignable to clazz
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • isPropertyValueAssignableTo

      public boolean isPropertyValueAssignableTo(String id, String propertyName, Class<?> clazz) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      id - SPDX ID
      propertyName - property name
      clazz - class to check for assignability
      Returns:
      true if there is a property value assignable to clazz
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • isCollectionProperty

      public boolean isCollectionProperty(String id, String propertyName) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      id - SPDX ID
      propertyName - property name
      Returns:
      true if the property of associated with id contains more than one object
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • 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 - ID with case ignored
      Returns:
      case sensitive ID
    • delete

      public void delete(String id) throws org.spdx.core.SpdxInvalidIdException
      Delete the entire resource and all statements
      Parameters:
      id - SPDX ID
      Throws:
      org.spdx.core.SpdxInvalidIdException - On SPDX parsing errors
    • getTypedValue

      public Optional<org.spdx.core.TypedValue> getTypedValue(String id) throws org.spdx.core.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.core.InvalidSPDXAnalysisException - On SPDX parsing errors
    • getModel

      public org.apache.jena.rdf.model.Model getModel()
      Returns:
      the Jena model