Package org.spdx.spdxRdfStore
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
An iterator for traversing RDF list objects associated with a specific property of a resource -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRdfSpdxModelManager
(String documentUri, org.apache.jena.rdf.model.Model model) -
Method Summary
Modifier and TypeMethodDescriptionboolean
addValueToCollection
(String id, String propertyName, Object value) Add value to the list of objects where the subject is the id and the predicate are the propertyNamevoid
clearValueCollection
(String id, String propertyName) Clear (remove) all values associated with the ID and propertyvoid
close()
boolean
collectionContains
(String id, String propertyName, Object value) int
collectionSize
(String id, String propertyName) void
Delete the entire resource and all statementsorg.spdx.storage.IModelStore.IModelStoreLock
enterCriticalSection
(boolean readLockRequested) boolean
Stream
<org.spdx.core.TypedValue> getAllItems
(String typeFilter) Get all objects of TypedValue type from the modelgetCasesensitiveId
(String caseInsensisitiveId) Translate a case-insensitive ID into a case-sensitive IDorg.apache.jena.rdf.model.Model
getModel()
getNextId
(org.spdx.storage.IModelStore.IdType idType) Get the next ID for the give ID typeprotected org.apache.jena.rdf.model.Resource
getOrCreate
(String objectUri, String type) Gets an existing or creates a new resource with and ID and typegetPropertyValue
(String id, String propertyName) Get the value associated with the property associated with the IDOptional
<org.spdx.core.TypedValue> getTypedValue
(String id) getValueList
(String id, String propertyName) boolean
isCollectionMembersAssignableTo
(String id, String propertyName, Class<?> clazz) boolean
isCollectionProperty
(String id, String propertyName) boolean
isPropertyValueAssignableTo
(String id, String propertyName, Class<?> clazz) void
removeProperty
(String id, String propertyName) Remove a property associated with a given ID and all values associated with that propertyboolean
removeValueFromCollection
(String id, String propertyName, Object value) Remove a specific value from a collection associated with an ID and propertyprotected static String
resourceToPropertyName
(org.apache.jena.rdf.model.RDFNode node) Convert an RDFNode to a property namevoid
serialize
(OutputStream stream, OutputFormat outputFormat) void
Sets a property for an ID to a valuevoid
unlock()
-
Field Details
-
model
protected final org.apache.jena.rdf.model.Model model
-
-
Constructor Details
-
RdfSpdxModelManager
- Parameters:
documentUri
- Unique URI for this documentmodel
- Model used to store this document
-
-
Method Details
-
exists
- 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 stringtype
- SPDX Type- Returns:
- the resource
- Throws:
org.spdx.core.SpdxInvalidIdException
- on invalid SPDX id
-
getPropertyValueNames
- 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 IDpropertyName
- property namevalue
- 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 IDpropertyName
- 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 IDpropertyName
- property name- Throws:
org.spdx.core.InvalidSPDXAnalysisException
- On SPDX parsing errors
-
getAllItems
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 IDpropertyName
- property namevalue
- 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 IDpropertyName
- 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 propertypropertyName
- Name of the property with the collectionvalue
- 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 IDpropertyName
- 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 IDpropertyName
- property namevalue
- 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 IDpropertyName
- 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 IDpropertyName
- property nameclazz
- 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 IDpropertyName
- property nameclazz
- 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 IDpropertyName
- 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 interfaceorg.spdx.storage.IModelStore.IModelStoreLock
-
serialize
-
getCasesensitiveId
Translate a case-insensitive ID into a case-sensitive ID- Parameters:
caseInsensisitiveId
- ID with case ignored- Returns:
- case sensitive ID
-
delete
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
-