From 52e11ec66814cfde2d2381ac5d946290c497dd3d Mon Sep 17 00:00:00 2001 From: "martin.petruna" Date: Thu, 7 Nov 2024 17:46:46 +0100 Subject: [PATCH 1/3] Allow usage of non-default copyManager in JacksonDeSerializer Signed-off-by: martin.petruna --- .../jacksonstore/JacksonDeSerializer.java | 20 ++++++++++++++++--- .../spdx/jacksonstore/MultiFormatStore.java | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java index 94918bf..20e7ea9 100644 --- a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java +++ b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java @@ -79,6 +79,8 @@ public class JacksonDeSerializer { private CompatibleModelStoreWrapper store; @SuppressWarnings("unused") private Format format; + + private IModelCopyManager modelCopyManager; private Map>> addedRelationships = new HashMap<>(); /** @@ -91,6 +93,18 @@ public JacksonDeSerializer(IModelStore store, Format format) { this.format = format; } + /** + * @param store store to store any documents in + */ + public JacksonDeSerializer(IModelStore store, IModelCopyManager modelCopyManager, Format format) { + Objects.requireNonNull(store, "Model store can not be null"); + Objects.requireNonNull(modelCopyManager, "Model copy manager can not be null"); + Objects.requireNonNull(format, "Format can not be null"); + this.store = new CompatibleModelStoreWrapper(store); + this.modelCopyManager = modelCopyManager; + this.format = format; + } + /** * Stores an SPDX document converted from the JsonNode doc * @param documentNamespace namespace for the document @@ -543,8 +557,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.parseSPDXLicenseStringCompatV2(value.asText(), store, documentUri, null); - return ModelObjectHelper.modelObjectToStoredObject(parsedLicense, store, null, null); + AnyLicenseInfo parsedLicense = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(value.asText(), store, documentUri, modelCopyManager); + return ModelObjectHelper.modelObjectToStoredObject(parsedLicense, store, modelCopyManager, null); } else if (SpdxDocument.class.isAssignableFrom(clazz)) { // Convert any IndividualUriValue values final String uriValue = value.asText(); @@ -676,7 +690,7 @@ public String getIndividualURI() { @Override public String getIndividualURI() { try { - return ExternalSpdxElement.externalSpdxElementIdToURI(spdxId, modelStore, documentNamespace, null); + return ExternalSpdxElement.externalSpdxElementIdToURI(spdxId, modelStore, documentNamespace, modelCopyManager); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/spdx/jacksonstore/MultiFormatStore.java b/src/main/java/org/spdx/jacksonstore/MultiFormatStore.java index 784ba5b..8db73bb 100644 --- a/src/main/java/org/spdx/jacksonstore/MultiFormatStore.java +++ b/src/main/java/org/spdx/jacksonstore/MultiFormatStore.java @@ -296,7 +296,7 @@ public synchronized SpdxDocument deSerialize(InputStream stream, boolean overwri this.leaveCriticalSection(lock); } } - JacksonDeSerializer deSerializer = new JacksonDeSerializer(this, format); + JacksonDeSerializer deSerializer = new JacksonDeSerializer(this, new ModelCopyManager(), format); String docNamespace; if (root instanceof ArrayNode) { for (JsonNode doc:(ArrayNode)root) { From 304afa0a8cb2968a10ce43839169bd344efb9803 Mon Sep 17 00:00:00 2001 From: "martin.petruna" Date: Thu, 7 Nov 2024 22:08:01 +0100 Subject: [PATCH 2/3] Add missing import Signed-off-by: martin.petruna --- src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java index 20e7ea9..abb58f3 100644 --- a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java +++ b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java @@ -31,6 +31,7 @@ import javax.annotation.Nullable; +import org.spdx.core.IModelCopyManager; import org.spdx.core.IndividualUriValue; import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.core.ModelObjectHelper; From 17230e788a4e51be014c48e1f68e5fc863963488 Mon Sep 17 00:00:00 2001 From: martin-bpw Date: Thu, 7 Nov 2024 22:09:27 +0100 Subject: [PATCH 3/3] Update src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java Co-authored-by: Gary O'Neall --- src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java index abb58f3..b407c77 100644 --- a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java +++ b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java @@ -96,6 +96,8 @@ public JacksonDeSerializer(IModelStore store, Format format) { /** * @param store store to store any documents in + * @param modelCopyManager copy manager to use when copying from the SPDX listed license model store + * @parm format Format expected for the serialized data */ public JacksonDeSerializer(IModelStore store, IModelCopyManager modelCopyManager, Format format) { Objects.requireNonNull(store, "Model store can not be null");