Skip to content

Commit

Permalink
Merge pull request #76 from martin-bpw/#75
Browse files Browse the repository at this point in the history
Allow usage of non-default copyManager in JacksonDeSerializer
  • Loading branch information
goneall authored Nov 7, 2024
2 parents 55333e8 + 17230e7 commit 9b34e44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,8 @@ public class JacksonDeSerializer {
private CompatibleModelStoreWrapper store;
@SuppressWarnings("unused")
private Format format;

private IModelCopyManager modelCopyManager;
private Map<String, Map<String, Map<SimpleUriValue, String>>> addedRelationships = new HashMap<>();

/**
Expand All @@ -91,6 +94,20 @@ public JacksonDeSerializer(IModelStore store, Format format) {
this.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");
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
Expand Down Expand Up @@ -543,8 +560,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();
Expand Down Expand Up @@ -676,7 +693,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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/jacksonstore/MultiFormatStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9b34e44

Please sign in to comment.