diff --git a/pom.xml b/pom.xml
index 1f246e8..37d9805 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
org.spdx
spdx-jackson-store
- 1.1.10-SNAPSHOT
+ 2.0.0-SNAPSHOT
jar
spdx-jackson-store
@@ -141,7 +141,7 @@ This store supports serializing and deserializing files in JSON, YAML and XML fo
org.spdx
java-spdx-library
- 1.1.11
+ 2.0.0-Alpha
com.google.code.gson
diff --git a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
index 975354b..94918bf 100644
--- a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
+++ b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
@@ -31,25 +31,26 @@
import javax.annotation.Nullable;
+import org.spdx.core.IndividualUriValue;
+import org.spdx.core.InvalidSPDXAnalysisException;
+import org.spdx.core.ModelObjectHelper;
+import org.spdx.core.SimpleUriValue;
+import org.spdx.core.TypedValue;
import org.spdx.jacksonstore.MultiFormatStore.Format;
-import org.spdx.library.InvalidSPDXAnalysisException;
-import org.spdx.library.SpdxConstants;
-import org.spdx.library.model.ExternalSpdxElement;
-import org.spdx.library.model.IndividualUriValue;
-import org.spdx.library.model.ModelStorageClassConverter;
-import org.spdx.library.model.ReferenceType;
-import org.spdx.library.model.SimpleUriValue;
-import org.spdx.library.model.SpdxDocument;
-import org.spdx.library.model.SpdxElement;
-import org.spdx.library.model.SpdxModelFactory;
-import org.spdx.library.model.TypedValue;
-import org.spdx.library.model.enumerations.RelationshipType;
-import org.spdx.library.model.license.AnyLicenseInfo;
-import org.spdx.library.model.license.LicenseInfoFactory;
+import org.spdx.library.LicenseInfoFactory;
+import org.spdx.library.model.v2.ExternalSpdxElement;
+import org.spdx.library.model.v2.ReferenceType;
+import org.spdx.library.model.v2.SpdxConstantsCompatV2;
+import org.spdx.library.model.v2.SpdxDocument;
+import org.spdx.library.model.v2.SpdxElement;
+import org.spdx.library.model.v2.SpdxModelFactoryCompatV2;
+import org.spdx.library.model.v2.enumerations.RelationshipType;
+import org.spdx.library.model.v2.license.AnyLicenseInfo;
import org.spdx.library.referencetype.ListedReferenceTypes;
import org.spdx.storage.IModelStore;
import org.spdx.storage.IModelStore.IModelStoreLock;
import org.spdx.storage.IModelStore.IdType;
+import org.spdx.storage.compatv2.CompatibleModelStoreWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -64,15 +65,18 @@
public class JacksonDeSerializer {
/**
- * Properties that should not be restored as part of the deserialization
+ * Property names that should not be restored as part of the deserialization
*/
static final Set SKIPPED_PROPERTIES = Collections.unmodifiableSet(new HashSet(Arrays.asList(new String[] {
- SpdxConstants.PROP_DOCUMENT_PACKAGES, SpdxConstants.PROP_DOCUMENT_FILES,
- SpdxConstants.PROP_DOCUMENT_SNIPPETS, SpdxConstants.SPDX_IDENTIFIER, SpdxConstants.PROP_DOCUMENT_RELATIONSHIPS,
- SpdxConstants.PROP_DOCUMENT_NAMESPACE
+ SpdxConstantsCompatV2.PROP_DOCUMENT_PACKAGES.getName(),
+ SpdxConstantsCompatV2.PROP_DOCUMENT_FILES.getName(),
+ SpdxConstantsCompatV2.PROP_DOCUMENT_SNIPPETS.getName(),
+ SpdxConstantsCompatV2.SPDX_IDENTIFIER,
+ SpdxConstantsCompatV2.PROP_DOCUMENT_RELATIONSHIPS.getName(),
+ SpdxConstantsCompatV2.PROP_DOCUMENT_NAMESPACE.getName()
})));
- private IModelStore store;
+ private CompatibleModelStoreWrapper store;
@SuppressWarnings("unused")
private Format format;
private Map>> addedRelationships = new HashMap<>();
@@ -83,7 +87,7 @@ public class JacksonDeSerializer {
public JacksonDeSerializer(IModelStore store, Format format) {
Objects.requireNonNull(store, "Model store can not be null");
Objects.requireNonNull(format, "Format can not be null");
- this.store = store;
+ this.store = new CompatibleModelStoreWrapper(store);
this.format = format;
}
@@ -100,18 +104,19 @@ public void storeDocument(String documentNamespace, JsonNode doc) throws Invalid
IModelStoreLock lock = store.enterCriticalSection(documentNamespace, false);
try {
Map spdxIdProperties = new HashMap<>(); // properties which contain an SPDX id which needs to be replaced
- store.create(documentNamespace, SpdxConstants.SPDX_DOCUMENT_ID, SpdxConstants.CLASS_SPDX_DOCUMENT);
- restoreObjectPropertyValues(documentNamespace, SpdxConstants.SPDX_DOCUMENT_ID, doc, spdxIdProperties);
+ store.create(documentNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT);
+ restoreObjectPropertyValues(documentNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, doc, spdxIdProperties);
// restore the packages
Map addedElements = new HashMap<>();
- addedElements.put(SpdxConstants.SPDX_DOCUMENT_ID, new TypedValue(SpdxConstants.SPDX_DOCUMENT_ID, SpdxConstants.CLASS_SPDX_DOCUMENT));
- restoreElements(documentNamespace, SpdxConstants.CLASS_SPDX_PACKAGE,
- doc.get(SpdxConstants.PROP_DOCUMENT_PACKAGES), addedElements, spdxIdProperties);
- restoreElements(documentNamespace, SpdxConstants.CLASS_SPDX_FILE,
- doc.get(SpdxConstants.PROP_DOCUMENT_FILES), addedElements, spdxIdProperties);
- restoreElements(documentNamespace, SpdxConstants.CLASS_SPDX_SNIPPET,
- doc.get(SpdxConstants.PROP_DOCUMENT_SNIPPETS), addedElements, spdxIdProperties);
- restoreRelationships(documentNamespace, doc.get(SpdxConstants.PROP_DOCUMENT_RELATIONSHIPS),
+ addedElements.put(SpdxConstantsCompatV2.SPDX_DOCUMENT_ID,
+ CompatibleModelStoreWrapper.typedValueFromDocUri(documentNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT));
+ restoreElements(documentNamespace, SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE,
+ doc.get(SpdxConstantsCompatV2.PROP_DOCUMENT_PACKAGES.getName()), addedElements, spdxIdProperties);
+ restoreElements(documentNamespace, SpdxConstantsCompatV2.CLASS_SPDX_FILE,
+ doc.get(SpdxConstantsCompatV2.PROP_DOCUMENT_FILES.getName()), addedElements, spdxIdProperties);
+ restoreElements(documentNamespace, SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET,
+ doc.get(SpdxConstantsCompatV2.PROP_DOCUMENT_SNIPPETS.getName()), addedElements, spdxIdProperties);
+ restoreRelationships(documentNamespace, doc.get(SpdxConstantsCompatV2.PROP_DOCUMENT_RELATIONSHIPS.getName()),
addedElements);
// fix up the ID's
for (Entry propertyToFix:spdxIdProperties.entrySet()) {
@@ -163,7 +168,7 @@ private void restoreElement(String documentUri, String type, @Nullable JsonNode
if (!jsonNode.isObject()) {
throw new InvalidSPDXAnalysisException("Invalid JSON node type for SPDX element");
}
- JsonNode idNode = jsonNode.get(SpdxConstants.SPDX_IDENTIFIER);
+ JsonNode idNode = jsonNode.get(SpdxConstantsCompatV2.SPDX_IDENTIFIER);
if (Objects.isNull(idNode) || !idNode.isTextual()) {
throw new InvalidSPDXAnalysisException("Missing SPDX ID for type "+type);
}
@@ -181,7 +186,7 @@ private void restoreElement(String documentUri, String type, @Nullable JsonNode
// Add more information to the error message
throw new InvalidSPDXAnalysisException("Error parsing JSON field for ID "+id+": "+ex.getMessage(), ex);
}
- addedElements.put(id, new TypedValue(id, type));
+ addedElements.put(id, CompatibleModelStoreWrapper.typedValueFromDocUri(documentUri, id, store, type));
}
/**
@@ -242,7 +247,7 @@ private void restoreRelationships(String documentNamespace, JsonNode jsonNode,
*/
private void restoreRelationship(String documentNamespace, JsonNode relationship,
Map addedElements) throws InvalidSPDXAnalysisException {
- JsonNode elementIdNode = relationship.get(SpdxConstants.PROP_SPDX_ELEMENTID);
+ JsonNode elementIdNode = relationship.get(SpdxConstantsCompatV2.PROP_SPDX_ELEMENTID.getName());
if (Objects.isNull(elementIdNode) || !elementIdNode.isTextual()) {
throw new InvalidSPDXAnalysisException("Missing SPDX element ID");
}
@@ -250,7 +255,7 @@ private void restoreRelationship(String documentNamespace, JsonNode relationship
if (Objects.isNull(element)) {
throw new InvalidSPDXAnalysisException("Missing SPDX element for ID "+elementIdNode.asText());
}
- JsonNode relationshipTypeNode = relationship.get(SpdxConstants.PROP_RELATIONSHIP_TYPE);
+ JsonNode relationshipTypeNode = relationship.get(SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE.getName());
if (Objects.isNull(relationshipTypeNode) || !relationshipTypeNode.isTextual()) {
throw new InvalidSPDXAnalysisException("Missing required relationship type");
}
@@ -261,19 +266,20 @@ private void restoreRelationship(String documentNamespace, JsonNode relationship
throw new InvalidSPDXAnalysisException("Unknown relationship type: "+relationshipTypeNode.asText());
}
SimpleUriValue relationshipType = new SimpleUriValue(relationshipTypeUri);
- JsonNode relatedElementNode = relationship.get(SpdxConstants.PROP_RELATED_SPDX_ELEMENT);
+ JsonNode relatedElementNode = relationship.get(SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.getName());
if (Objects.isNull(relatedElementNode) || !relatedElementNode.isTextual()) {
throw new InvalidSPDXAnalysisException("Missing required related element");
}
Object relatedElement = idToObjectValue(documentNamespace, relatedElementNode.asText(), addedElements);
- JsonNode commentNode = relationship.get(SpdxConstants.RDFS_PROP_COMMENT);
+ JsonNode commentNode = relationship.get(SpdxConstantsCompatV2.RDFS_PROP_COMMENT.getName());
Optional relationshipComment;
if (Objects.isNull(commentNode) || !commentNode.isTextual()) {
relationshipComment = Optional.empty();
} else {
relationshipComment = Optional.of(commentNode.asText());
}
- addRelationship(documentNamespace, element.getId(), relationshipType, relatedElement, relationshipComment);
+ addRelationship(documentNamespace, CompatibleModelStoreWrapper.objectUriToId(store, element.getObjectUri(), documentNamespace),
+ relationshipType, relatedElement, relationshipComment);
}
/**
@@ -289,7 +295,7 @@ private void restoreRelationship(String documentNamespace, JsonNode relationship
private String addRelationship(String documentNamespace, String elementId, SimpleUriValue relationshipType, Object relatedElement, Optional relationshipComment) throws InvalidSPDXAnalysisException {
String relatedElementId;
if (relatedElement instanceof TypedValue) {
- relatedElementId = ((TypedValue)relatedElement).getId();
+ relatedElementId = CompatibleModelStoreWrapper.objectUriToId(store, ((TypedValue)relatedElement).getObjectUri(), documentNamespace);
} else if (relatedElement instanceof String) {
relatedElementId = (String)relatedElement;
} else if (relatedElement instanceof IndividualUriValue) {
@@ -318,13 +324,13 @@ private String addRelationship(String documentNamespace, String elementId, Simpl
addedRelationships.put(elementId, elementRelationships);
}
String relationshipId = store.getNextId(IdType.Anonymous, documentNamespace);
- store.create(documentNamespace, relationshipId, SpdxConstants.CLASS_RELATIONSHIP);
- store.setValue(documentNamespace, relationshipId, SpdxConstants.PROP_RELATIONSHIP_TYPE, relationshipType);
- store.setValue(documentNamespace, relationshipId, SpdxConstants.PROP_RELATED_SPDX_ELEMENT, relatedElement);
- store.addValueToCollection(documentNamespace, elementId, SpdxConstants.PROP_RELATIONSHIP,
- new TypedValue(relationshipId, SpdxConstants.CLASS_RELATIONSHIP));
+ store.create(documentNamespace, relationshipId, SpdxConstantsCompatV2.CLASS_RELATIONSHIP);
+ store.setValue(documentNamespace, relationshipId, SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE, relationshipType);
+ store.setValue(documentNamespace, relationshipId, SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT, relatedElement);
+ store.addValueToCollection(documentNamespace, elementId, SpdxConstantsCompatV2.PROP_RELATIONSHIP,
+ CompatibleModelStoreWrapper.typedValueFromDocUri(documentNamespace, relationshipId, store, SpdxConstantsCompatV2.CLASS_RELATIONSHIP));
if (relationshipComment.isPresent()) {
- store.setValue(documentNamespace, relationshipId, SpdxConstants.RDFS_PROP_COMMENT, relationshipComment.get());
+ store.setValue(documentNamespace, relationshipId, SpdxConstantsCompatV2.RDFS_PROP_COMMENT, relationshipComment.get());
}
relatedElementRelationships.put(relationshipType, relationshipId);
return relationshipId;
@@ -345,11 +351,11 @@ private void restoreObjectPropertyValues(String documentUri, String id, JsonNode
Entry field = fieldIterator.next();
if (SKIPPED_PROPERTIES.contains(field.getKey())) {
continue;
- } else if (SpdxConstants.PROP_DOCUMENT_DESCRIBES.equals(field.getKey())) {
+ } else if (SpdxConstantsCompatV2.PROP_DOCUMENT_DESCRIBES.getName().equals(field.getKey())) {
// These needs to be converted to a DocumentDescribes relationship
convertFieldToRelationship(documentUri, id, field.getValue(),
RelationshipType.DESCRIBES, spdxIdProperties);
- } else if (SpdxConstants.PROP_PACKAGE_FILE.equals(
+ } else if (SpdxConstantsCompatV2.PROP_PACKAGE_FILE.getName().equals(
MultiFormatStore.collectionPropertyNameToPropertyName(field.getKey()))) {
// These needs to be converted to a CONTAINSS relationship
convertFieldToRelationship(documentUri, id, field.getValue(),
@@ -378,13 +384,13 @@ private void convertFieldToRelationship(String documentUri, String id, JsonNode
String relationshipId = addRelationship(documentUri, id,
new SimpleUriValue(relationshipType.getIndividualURI()),
spdxidNode.asText(), Optional.empty());
- spdxIdProperties.put(relationshipId, SpdxConstants.PROP_RELATED_SPDX_ELEMENT); // Add the SPDX ID to the list to be translated back to elements later
+ spdxIdProperties.put(relationshipId, SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.getName()); // Add the SPDX ID to the list to be translated back to elements later
}
} else {
String relationshipId = addRelationship(documentUri, id,
new SimpleUriValue(relationshipType.getIndividualURI()),
spdxIdField.asText(), Optional.empty());
- spdxIdProperties.put(relationshipId, SpdxConstants.PROP_RELATED_SPDX_ELEMENT); // Add the SPDX ID to the list to be translated back to elements later
+ spdxIdProperties.put(relationshipId, SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.getName()); // Add the SPDX ID to the list to be translated back to elements later
}
}
@@ -477,13 +483,13 @@ private Object toStoredObject(String documentUri, String id, String property, Js
if (!propertyType.isPresent()) {
throw new InvalidSPDXAnalysisException("Unknown type for property " + property);
}
- if (SpdxConstants.CLASS_SINGLE_POINTER.equals(propertyType.get())) {
+ if (SpdxConstantsCompatV2.CLASS_SINGLE_POINTER.equals(propertyType.get())) {
// need to determine whether a byte or line pointer type
// A bit of Duck Typing is in order
- if (Objects.nonNull(value.get(SpdxConstants.PROP_POINTER_OFFSET))) {
- propertyType = Optional.of(SpdxConstants.CLASS_POINTER_BYTE_OFFSET_POINTER);
- } else if (Objects.nonNull(value.get(SpdxConstants.PROP_POINTER_LINE_NUMBER))) {
- propertyType = Optional.of(SpdxConstants.CLASS_POINTER_LINE_CHAR_POINTER);
+ if (Objects.nonNull(value.get(SpdxConstantsCompatV2.PROP_POINTER_OFFSET.getName()))) {
+ propertyType = Optional.of(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER);
+ } else if (Objects.nonNull(value.get(SpdxConstantsCompatV2.PROP_POINTER_LINE_NUMBER.getName()))) {
+ propertyType = Optional.of(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER);
} else {
throw new InvalidSPDXAnalysisException("Can not determine type for snippet pointer");
}
@@ -491,7 +497,7 @@ private Object toStoredObject(String documentUri, String id, String property, Js
String objectId = findObjectIdInJsonObject(documentUri, value);
store.create(documentUri, objectId, propertyType.get());
restoreObjectPropertyValues(documentUri, objectId, value, spdxIdProperties);
- return new TypedValue(objectId, propertyType.get());
+ return CompatibleModelStoreWrapper.typedValueFromDocUri(documentUri, objectId, store, propertyType.get());
}
case STRING:
return getStringPropertyValueForJsonNode(documentUri, id, property, value,
@@ -524,7 +530,7 @@ private Object getStringPropertyValueForJsonNode(String documentUri, String id,
Class> clazz = null;
if (propertyType.isPresent()) {
// check for SPDX model types
- clazz = SpdxModelFactory.SPDX_TYPE_TO_CLASS.get(propertyType.get());
+ clazz = SpdxModelFactoryCompatV2.SPDX_TYPE_TO_CLASS_V2.get(propertyType.get());
if (Objects.isNull(clazz)) {
// check for primitive types
clazz = SpdxJsonLDContext.XMLSCHEMA_TYPE_TO_JAVA_CLASS.get(propertyType.get());
@@ -537,8 +543,8 @@ private Object getStringPropertyValueForJsonNode(String documentUri, String id,
// check for SPDX model classes
if (AnyLicenseInfo.class.isAssignableFrom(clazz)) {
// convert license expressions to their model object form
- AnyLicenseInfo parsedLicense = LicenseInfoFactory.parseSPDXLicenseString(value.asText(), store, documentUri, null);
- return ModelStorageClassConverter.modelObjectToStoredObject(parsedLicense, documentUri, store, null);
+ AnyLicenseInfo parsedLicense = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(value.asText(), store, documentUri, null);
+ return ModelObjectHelper.modelObjectToStoredObject(parsedLicense, store, null, null);
} else if (SpdxDocument.class.isAssignableFrom(clazz)) {
// Convert any IndividualUriValue values
final String uriValue = value.asText();
@@ -616,15 +622,15 @@ public String getIndividualURI() {
* @throws InvalidSPDXAnalysisException
*/
private String findObjectIdInJsonObject(String documentUri, JsonNode jsonObject) throws InvalidSPDXAnalysisException {
- JsonNode retval = jsonObject.get(SpdxConstants.SPDX_IDENTIFIER);
+ JsonNode retval = jsonObject.get(SpdxConstantsCompatV2.SPDX_IDENTIFIER);
if (Objects.isNull(retval) || !retval.isTextual()) {
- retval = jsonObject.get(SpdxConstants.PROP_LICENSE_ID);
+ retval = jsonObject.get(SpdxConstantsCompatV2.PROP_LICENSE_ID.getName());
}
if (Objects.isNull(retval) || !retval.isTextual()) {
- retval = jsonObject.get(SpdxConstants.PROP_LICENSE_EXCEPTION_ID);
+ retval = jsonObject.get(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID.getName());
}
if (Objects.isNull(retval) || !retval.isTextual()) {
- retval = jsonObject.get(SpdxConstants.EXTERNAL_DOCUMENT_REF_IDENTIFIER);
+ retval = jsonObject.get(SpdxConstantsCompatV2.EXTERNAL_DOCUMENT_REF_IDENTIFIER);
}
if (Objects.isNull(retval) || !retval.isTextual()) {
return store.getNextId(IdType.Anonymous, documentUri);
@@ -645,21 +651,21 @@ private String findObjectIdInJsonObject(String documentUri, JsonNode jsonObject)
private Object idToObjectValue(String documentNamespace, String spdxId, Map addedElements) throws InvalidSPDXAnalysisException {
TypedValue fixedValue = addedElements.get(spdxId);
if (Objects.isNull(fixedValue)) {
- if (spdxId.equals(SpdxConstants.NONE_VALUE)) {
+ if (spdxId.equals(SpdxConstantsCompatV2.NONE_VALUE)) {
return new IndividualUriValue() {
@Override
public String getIndividualURI() {
- return SpdxConstants.URI_VALUE_NONE;
+ return SpdxConstantsCompatV2.URI_VALUE_NONE;
}
};
- } else if (spdxId.equals(SpdxConstants.NOASSERTION_VALUE)) {
+ } else if (spdxId.equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) {
return new IndividualUriValue() {
@Override
public String getIndividualURI() {
- return SpdxConstants.URI_VALUE_NOASSERTION;
+ return SpdxConstantsCompatV2.URI_VALUE_NOASSERTION;
}
};
diff --git a/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java
index 6996def..832dadf 100644
--- a/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java
+++ b/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java
@@ -31,25 +31,28 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.spdx.core.CoreModelObject;
+import org.spdx.core.IndividualUriValue;
+import org.spdx.core.InvalidSPDXAnalysisException;
+import org.spdx.core.ModelRegistry;
+import org.spdx.core.SpdxInvalidTypeException;
+import org.spdx.core.TypedValue;
import org.spdx.jacksonstore.MultiFormatStore.Format;
import org.spdx.jacksonstore.MultiFormatStore.Verbose;
-import org.spdx.library.InvalidSPDXAnalysisException;
-import org.spdx.library.SpdxConstants;
-import org.spdx.library.model.ExternalDocumentRef;
-import org.spdx.library.model.ExternalSpdxElement;
-import org.spdx.library.model.IndividualUriValue;
-import org.spdx.library.model.SpdxElement;
-import org.spdx.library.model.SpdxInvalidTypeException;
-import org.spdx.library.model.SpdxModelFactory;
-import org.spdx.library.model.TypedValue;
-import org.spdx.library.model.enumerations.Purpose;
-import org.spdx.library.model.enumerations.RelationshipType;
-import org.spdx.library.model.enumerations.SpdxEnumFactory;
-import org.spdx.library.model.license.AnyLicenseInfo;
-import org.spdx.library.model.license.SimpleLicensingInfo;
+import org.spdx.library.model.v2.ExternalDocumentRef;
+import org.spdx.library.model.v2.ExternalSpdxElement;
+import org.spdx.library.model.v2.SpdxConstantsCompatV2;
+import org.spdx.library.model.v2.SpdxElement;
+import org.spdx.library.model.v2.SpdxModelFactoryCompatV2;
+import org.spdx.library.model.v2.enumerations.Purpose;
+import org.spdx.library.model.v2.enumerations.RelationshipType;
+import org.spdx.library.model.v2.enumerations.SpdxEnumFactoryCompatV2;
+import org.spdx.library.model.v2.license.AnyLicenseInfo;
+import org.spdx.library.model.v2.license.SimpleLicensingInfo;
import org.spdx.storage.IModelStore;
import org.spdx.storage.IModelStore.IModelStoreLock;
import org.spdx.storage.IModelStore.IdType;
+import org.spdx.storage.compatv2.CompatibleModelStoreWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -60,7 +63,7 @@
/**
* Serializer for a model store to convert the document model object into a JsonNode
*
- * the method docToJsonNode(String documentUri)
will generate the JSON node
+ * the method docToJsonNode(String documentUri)
will generate the JSON node for a document
* @author Gary O'Neall
*
*/
@@ -131,25 +134,25 @@ private int compareObject(JsonNode arg0, JsonNode arg1) {
if (!arg1.isObject()) {
return 1;
}
- JsonNode spdxid0 = arg0.get(SpdxConstants.SPDX_IDENTIFIER);
+ JsonNode spdxid0 = arg0.get(SpdxConstantsCompatV2.SPDX_IDENTIFIER);
if (Objects.nonNull(spdxid0) && spdxid0.isTextual()) {
- JsonNode spdxid1 = arg1.get(SpdxConstants.SPDX_IDENTIFIER);
+ JsonNode spdxid1 = arg1.get(SpdxConstantsCompatV2.SPDX_IDENTIFIER);
return Objects.nonNull(spdxid1) && spdxid1.isTextual() ? spdxid0.asText().compareTo(spdxid1.asText()) : 1;
}
// look for special cases where we don't want to sort in the order of properties
- JsonNode licenseId0 = arg0.get(SpdxConstants.PROP_LICENSE_ID);
+ JsonNode licenseId0 = arg0.get(SpdxConstantsCompatV2.PROP_LICENSE_ID.getName());
if (Objects.nonNull(licenseId0) && licenseId0.isTextual()) {
return compareExtractedLicense(licenseId0.asText(), arg1);
}
- JsonNode spdxDocument0 = arg0.get(SpdxConstants.PROP_EXTERNAL_SPDX_DOCUMENT);
- JsonNode externalDocId0 = arg0.get(SpdxConstants.PROP_EXTERNAL_DOCUMENT_ID);
+ JsonNode spdxDocument0 = arg0.get(SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT.getName());
+ JsonNode externalDocId0 = arg0.get(SpdxConstantsCompatV2.PROP_EXTERNAL_DOCUMENT_ID.getName());
if (Objects.nonNull(spdxDocument0) && Objects.nonNull(externalDocId0) &&
spdxDocument0.isTextual() && externalDocId0.isTextual()) {
return compareExternalDocumentRef(spdxDocument0.asText(), externalDocId0.asText(), arg1);
}
- JsonNode refCategory0 = arg0.get(SpdxConstants.PROP_REFERENCE_CATEGORY);
- JsonNode refType0 = arg0.get(SpdxConstants.PROP_REFERENCE_TYPE);
- JsonNode refLocator0 = arg0.get(SpdxConstants.PROP_REFERENCE_LOCATOR);
+ JsonNode refCategory0 = arg0.get(SpdxConstantsCompatV2.PROP_REFERENCE_CATEGORY.getName());
+ JsonNode refType0 = arg0.get(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE.getName());
+ JsonNode refLocator0 = arg0.get(SpdxConstantsCompatV2.PROP_REFERENCE_LOCATOR.getName());
if (Objects.nonNull(refCategory0) && Objects.nonNull(refType0) && Objects.nonNull(refLocator0) &&
refCategory0.isTextual() && refType0.isTextual() && refLocator0.isTextual()) {
return compareExternalRef(refCategory0.asText(), refType0.asText(), refLocator0.asText(), arg1);
@@ -171,9 +174,9 @@ private int compareObject(JsonNode arg0, JsonNode arg1) {
private int compareExternalRef(String refCategory, String refType,
String refLocator, JsonNode compare) {
- JsonNode compRefCategory = compare.get(SpdxConstants.PROP_REFERENCE_CATEGORY);
- JsonNode compRefType = compare.get(SpdxConstants.PROP_REFERENCE_TYPE);
- JsonNode compRefLocator = compare.get(SpdxConstants.PROP_REFERENCE_LOCATOR);
+ JsonNode compRefCategory = compare.get(SpdxConstantsCompatV2.PROP_REFERENCE_CATEGORY.getName());
+ JsonNode compRefType = compare.get(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE.getName());
+ JsonNode compRefLocator = compare.get(SpdxConstantsCompatV2.PROP_REFERENCE_LOCATOR.getName());
if (Objects.isNull(compRefCategory) || Objects.isNull(compRefType) || Objects.isNull(compRefLocator) ||
!compRefCategory.isTextual() || !compRefType.isTextual() || !compRefLocator.isTextual()) {
return 1;
@@ -191,8 +194,8 @@ private int compareExternalRef(String refCategory, String refType,
private int compareExternalDocumentRef(String document, String externalDocId,
JsonNode compare) {
- JsonNode compDocument = compare.get(SpdxConstants.PROP_EXTERNAL_SPDX_DOCUMENT);
- JsonNode compExternalDocId = compare.get(SpdxConstants.PROP_EXTERNAL_DOCUMENT_ID);
+ JsonNode compDocument = compare.get(SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT.getName());
+ JsonNode compExternalDocId = compare.get(SpdxConstantsCompatV2.PROP_EXTERNAL_DOCUMENT_ID.getName());
if (Objects.isNull(compDocument) || Objects.isNull(compExternalDocId) ||
!compDocument.isTextual() || !compExternalDocId.isTextual()) {
return 1;
@@ -205,7 +208,7 @@ private int compareExternalDocumentRef(String document, String externalDocId,
}
private int compareExtractedLicense(String licenseId, JsonNode compare) {
- JsonNode compLicenseId = compare.get(SpdxConstants.PROP_LICENSE_ID);
+ JsonNode compLicenseId = compare.get(SpdxConstantsCompatV2.PROP_LICENSE_ID.getName());
if (Objects.isNull(compLicenseId) || !compLicenseId.isTextual()) {
return 1;
} else {
@@ -216,7 +219,7 @@ private int compareExtractedLicense(String licenseId, JsonNode compare) {
};
private ObjectMapper mapper;
- private IModelStore store;
+ private CompatibleModelStoreWrapper store;
private Format format;
private Verbose verbose;
@@ -226,15 +229,28 @@ private int compareExtractedLicense(String licenseId, JsonNode compare) {
* @param store Model store containing the documents
*/
public JacksonSerializer(ObjectMapper mapper, Format format, Verbose verbose, IModelStore store) {
- Objects.requireNonNull(mapper, "Null required Jackson mapper");
- Objects.requireNonNull(format, "Null required format");
- Objects.requireNonNull(verbose, "Null required verbose");
- Objects.requireNonNull(store, "Null required store");
+ Objects.requireNonNull(mapper, "Non-null required Jackson mapper");
+ Objects.requireNonNull(format, "Non-null required format");
+ Objects.requireNonNull(verbose, "Non-null required verbose");
+ Objects.requireNonNull(store, "Non-null required store");
this.mapper = mapper;
- this.store = store;
+ this.store = new CompatibleModelStoreWrapper(store);
this.format = format;
this.verbose = verbose;
}
+
+ /**
+ * @param documentUris list of document uris
+ * @return JSON array of all documents which have the document Uris
+ * @throws InvalidSPDXAnalysisException
+ */
+ public ArrayNode docsToJsonNode(List documentUris) throws InvalidSPDXAnalysisException {
+ ArrayNode retval = mapper.createArrayNode();
+ for (String documentUri:documentUris) {
+ retval.add(docToJsonNode(documentUri));
+ }
+ return retval;
+ }
/**
* @param documentUri URI for the document to be converted
@@ -245,21 +261,22 @@ public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisEx
Objects.requireNonNull(documentUri,"Null Document URI");
IModelStoreLock lock = store.enterCriticalSection(documentUri, false); //TODO: True value causes deadlock due to false value in ExternalDocumentRef line 58
try {
- TypedValue document = new TypedValue(SpdxConstants.SPDX_DOCUMENT_ID, SpdxConstants.CLASS_SPDX_DOCUMENT);
+ TypedValue document = CompatibleModelStoreWrapper.typedValueFromDocUri(documentUri,
+ SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT);
ArrayNode relationships = mapper.createArrayNode();
ObjectNode doc = typedValueToObjectNode(documentUri, document, relationships);
- doc.put(SpdxConstants.PROP_DOCUMENT_NAMESPACE, documentUri);
- ArrayNode packages = getDocElements(documentUri, SpdxConstants.CLASS_SPDX_PACKAGE, relationships);
+ doc.put(SpdxConstantsCompatV2.PROP_DOCUMENT_NAMESPACE.getName(), documentUri);
+ ArrayNode packages = getDocElements(documentUri, SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, relationships);
if (packages.size() > 0) {
- doc.set(SpdxConstants.PROP_DOCUMENT_PACKAGES, packages);
+ doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_PACKAGES.getName(), packages);
}
- ArrayNode files = getDocElements(documentUri, SpdxConstants.CLASS_SPDX_FILE, relationships);
+ ArrayNode files = getDocElements(documentUri, SpdxConstantsCompatV2.CLASS_SPDX_FILE, relationships);
if (files.size() > 0) {
- doc.set(SpdxConstants.PROP_DOCUMENT_FILES, files);
+ doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_FILES.getName(), files);
}
- ArrayNode snippets = getDocElements(documentUri, SpdxConstants.CLASS_SPDX_SNIPPET, relationships);
+ ArrayNode snippets = getDocElements(documentUri, SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, relationships);
if (snippets.size() > 0) {
- doc.set(SpdxConstants.PROP_DOCUMENT_SNIPPETS, snippets);
+ doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_SNIPPETS.getName(), snippets);
}
//Remove duplicate relationships
Map>> iDRelTypeRelatediDMap = new HashMap<>();
@@ -267,9 +284,9 @@ public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisEx
ArrayNode deDupedRelationships = new ArrayNode(JsonNodeFactory.instance);
while (relIter.hasNext()) {
JsonNode relationship = relIter.next();
- String id = relationship.get(SpdxConstants.PROP_SPDX_ELEMENTID).asText();
- String relType = relationship.get(SpdxConstants.PROP_RELATIONSHIP_TYPE).asText();
- String relatedID = relationship.get(SpdxConstants.PROP_RELATED_SPDX_ELEMENT).asText();
+ String id = relationship.get(SpdxConstantsCompatV2.PROP_SPDX_ELEMENTID.getName()).asText();
+ String relType = relationship.get(SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE.getName()).asText();
+ String relatedID = relationship.get(SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.getName()).asText();
Map> relTypeRelatedIdMap = iDRelTypeRelatediDMap.get(id);
if (Objects.isNull(relTypeRelatedIdMap)) {
relTypeRelatedIdMap = new HashMap<>();
@@ -287,7 +304,7 @@ public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisEx
}
- doc.set(SpdxConstants.PROP_DOCUMENT_RELATIONSHIPS, deDupedRelationships);
+ doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_RELATIONSHIPS.getName(), deDupedRelationships);
ObjectNode output;
switch (format) {
case YAML: {
@@ -328,38 +345,40 @@ private ObjectNode typedValueToObjectNode(String documentUri, TypedValue storedI
ObjectNode retval = mapper.createObjectNode();
Set hasFileIds = new HashSet<>(); // keep track of any hasFile properties added to avoid duplicates
Set documentDescribesIds = new HashSet<>(); // keep track of any documentDescribes properties added to avoid duplicates
- List docPropNames = new ArrayList(store.getPropertyValueNames(documentUri, storedItem.getId()));
+ List docPropNames = new ArrayList(store.getPropertyValueNames(storedItem.getObjectUri()));
docPropNames.sort(new PropertyComparator(storedItem.getType()));
- Class> clazz = SpdxModelFactory.SPDX_TYPE_TO_CLASS.get(storedItem.getType());
- IdType idType = store.getIdType(storedItem.getId());
+ Class> clazz = SpdxModelFactoryCompatV2.SPDX_TYPE_TO_CLASS_V2.get(storedItem.getType());
+ IdType idType = store.getIdType(storedItem.getObjectUri());
+ String id = CompatibleModelStoreWrapper.objectUriToId(store, storedItem.getObjectUri(), documentUri);
if (SpdxElement.class.isAssignableFrom(clazz)) {
if (IdType.SpdxId.equals(idType)) {
- retval.put(SpdxConstants.SPDX_IDENTIFIER, storedItem.getId());
+ retval.put(SpdxConstantsCompatV2.SPDX_IDENTIFIER, CompatibleModelStoreWrapper.objectUriToId(store, storedItem.getObjectUri(), documentUri));
} else if (!IdType.Anonymous.equals(idType)) {
- logger.error("Invalid ID "+storedItem.getId()+". Must be an SPDX Identifier or Anonymous");
- throw new InvalidSPDXAnalysisException("Invalid ID "+storedItem.getId()+". Must be an SPDX Identifier or Anonymous");
+ logger.error("Invalid ID "+storedItem.getObjectUri()+". Must be an SPDX Identifier or Anonymous");
+ throw new InvalidSPDXAnalysisException("Invalid ID "+storedItem.getObjectUri()+". Must be an SPDX Identifier or Anonymous");
}
} else if (ExternalDocumentRef.class.isAssignableFrom(clazz)) {
- retval.put(SpdxConstants.EXTERNAL_DOCUMENT_REF_IDENTIFIER, storedItem.getId());
+ retval.put(SpdxConstantsCompatV2.EXTERNAL_DOCUMENT_REF_IDENTIFIER, CompatibleModelStoreWrapper.objectUriToId(store, storedItem.getObjectUri(), documentUri));
} else if (SimpleLicensingInfo.class.isAssignableFrom(clazz)) {
- retval.put(SpdxConstants.PROP_LICENSE_ID, storedItem.getId());
+ retval.put(SpdxConstantsCompatV2.PROP_LICENSE_ID.getName(), id);
}
for (String propertyName:docPropNames) {
- if (SpdxConstants.PROP_RELATIONSHIP.equals(propertyName)) {
+ if (SpdxConstantsCompatV2.PROP_RELATIONSHIP.getName().equals(propertyName)) {
addJsonRelationships(documentUri, storedItem, retval, relationships, hasFileIds, documentDescribesIds);
- } else if (SpdxConstants.PROP_SPDX_EXTRACTED_LICENSES.equals(propertyName)) {
+ } else if (SpdxConstantsCompatV2.PROP_SPDX_EXTRACTED_LICENSES.getName().equals(propertyName)) {
retval.set(MultiFormatStore.propertyNameToCollectionPropertyName(propertyName),
- toExtractedLicensesArrayNode(documentUri, storedItem.getId(), propertyName, relationships));
- } else if (store.isCollectionProperty(documentUri, storedItem.getId(), propertyName)) {
- Iterator