Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of non-default copyManager in JacksonDeSerializer #76

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
martin-bpw marked this conversation as resolved.
Show resolved Hide resolved
* @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
Loading