Package org.spdx.spdxRdfStore
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRdfSpdxDocumentModelManager(String documentUri, org.apache.jena.rdf.model.Model model) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddValueToCollection(String id, String propertyName, Object value) Add value to the list of objects where the subject is the id and the predicate is the propertyNamevoidclearValueCollection(String id, String propertyName) Clear (remove) all values assocociated with the ID and propertyvoidclose()booleancollectionContains(String id, String propertyName, Object value) intcollectionSize(String id, String propertyName) voidDelete the entire resource and all statementsorg.spdx.storage.IModelStore.IModelStoreLockenterCriticalSection(boolean readLockRequested) booleanjava.util.stream.Stream<org.spdx.library.model.TypedValue>getAllItems(String typeFilter) Get all objects of TypedValue type from the modelgetCasesensitiveId(String caseInsensisitiveId) Translate a case insensitive ID into a case sensitive IDgetNextId(org.spdx.storage.IModelStore.IdType idType) Get the next ID for the give ID typeprotected org.apache.jena.rdf.model.ResourcegetOrCreate(String id, 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.library.model.TypedValue>getTypedValue(String id) getValueList(String id, String propertyName) booleanisCollectionMembersAssignableTo(String id, String propertyName, Class<?> clazz) booleanisCollectionProperty(String id, String propertyName) booleanisPropertyValueAssignableTo(String id, String propertyName, Class<?> clazz) voidremoveProperty(String id, String propertyName) Remove a property associated with a given ID and all values associated with that propertybooleanremoveValueFromCollection(String id, String propertyName, Object value) Remove a specific value from a collection associated with an ID and propertyprotected static StringresourceToPropertyName(org.apache.jena.rdf.model.RDFNode node) Convert an RDFNode to a property namevoidserialize(OutputStream stream, OutputFormat outputFormat) voidSets a property for an ID to a valuevoidunlock()
-
Field Details
-
model
protected org.apache.jena.rdf.model.Model model
-
-
Constructor Details
-
RdfSpdxDocumentModelManager
- 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 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 modeltype- SPDX Type- Returns:
- the resource
- Throws:
org.spdx.library.SpdxInvalidIdExceptionorg.spdx.library.model.DuplicateSpdxIdException
-
getPropertyValueNames
- 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 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.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:
unlockin interfaceorg.spdx.storage.IModelStore.IModelStoreLock
-
serialize
-
getCasesensitiveId
Translate a case insensitive ID into a case sensitive ID- Parameters:
caseInsensisitiveId-- Returns:
- case sensitive ID
-
delete
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
-