diff --git a/pom.xml b/pom.xml
index ce6a06a..c827e00 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,7 +141,7 @@ This store supports serializing and deserializing files in JSON, YAML and XML fo
org.spdxjava-spdx-library
- 2.0.0-Alpha
+ 2.0.0-RC1com.google.code.gson
diff --git a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
index b407c77..95adf8b 100644
--- a/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
+++ b/src/main/java/org/spdx/jacksonstore/JacksonDeSerializer.java
@@ -1,14 +1,15 @@
/**
* Copyright (c) 2020 Source Auditor Inc.
*
+ *
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -68,21 +69,19 @@ public class JacksonDeSerializer {
/**
* 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[] {
- 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()
- })));
+ static final Set SKIPPED_PROPERTIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(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 CompatibleModelStoreWrapper store;
+ private final CompatibleModelStoreWrapper store;
@SuppressWarnings("unused")
- private Format format;
+ private final Format format;
private IModelCopyManager modelCopyManager;
- private Map>> addedRelationships = new HashMap<>();
+ private final Map>> addedRelationships = new HashMap<>();
/**
* @param store store to store any documents in
@@ -97,7 +96,7 @@ 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
+ * @param format Format expected for the serialized data
*/
public JacksonDeSerializer(IModelStore store, IModelCopyManager modelCopyManager, Format format) {
Objects.requireNonNull(store, "Model store can not be null");
@@ -112,7 +111,7 @@ public JacksonDeSerializer(IModelStore store, IModelCopyManager modelCopyManager
* Stores an SPDX document converted from the JsonNode doc
* @param documentNamespace namespace for the document
* @param doc JsonNode containing the SPDX document
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
@SuppressWarnings("unchecked")
public void storeDocument(String documentNamespace, JsonNode doc) throws InvalidSPDXAnalysisException {
@@ -170,12 +169,12 @@ public void storeDocument(String documentNamespace, JsonNode doc) throws Invalid
/**
* Restores a single SPDX element of a specific type
- * @param documentUri
- * @param type
- * @param jsonNode
- * @param addedElements
+ * @param documentUri namespace for the document
+ * @param type SPDX Model object type
+ * @param jsonNode node containing an element
+ * @param addedElements map of any elements added to the mode
* @param spdxIdProperties Properties which contain an SPDX ID which needs to be replaced
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void restoreElement(String documentUri, String type, @Nullable JsonNode jsonNode,
Map addedElements, Map spdxIdProperties) throws InvalidSPDXAnalysisException {
@@ -208,12 +207,12 @@ private void restoreElement(String documentUri, String type, @Nullable JsonNode
/**
* Restores SPDX elements of a specific type
- * @param documentUri
- * @param type
- * @param jsonNode
- * @param addedElements
+ * @param documentUri namespace for the document
+ * @param type SPDX Model object type
+ * @param jsonNode node containing an element
+ * @param addedElements map of any elements added to the mode
* @param spdxIdProperties Properties which contain an SPDX ID which needs to be replaced
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void restoreElements(String documentUri, String type, @Nullable JsonNode jsonNode,
Map addedElements, Map spdxIdProperties) throws InvalidSPDXAnalysisException {
@@ -234,10 +233,10 @@ private void restoreElements(String documentUri, String type, @Nullable JsonNode
/**
* Restore the relationships adding them as properties to the correct elements
- * @param documentNamespace
- * @param jsonNode
- * @param addedElements
- * @throws InvalidSPDXAnalysisException
+ * @param documentNamespace namespace for the document
+ * @param jsonNode node containing an element
+ * @param addedElements map of any elements added to the mode
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void restoreRelationships(String documentNamespace, JsonNode jsonNode,
Map addedElements) throws InvalidSPDXAnalysisException {
@@ -257,10 +256,10 @@ private void restoreRelationships(String documentNamespace, JsonNode jsonNode,
/**
* Restore a relationship adding it as properties to the correct elements
- * @param documentNamespace
- * @param relationship
- * @param addedElements
- * @throws InvalidSPDXAnalysisException
+ * @param documentNamespace namespace for the document
+ * @param relationship JSON Node containing the relationship
+ * @param addedElements map of any elements added to the mode
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void restoreRelationship(String documentNamespace, JsonNode relationship,
Map addedElements) throws InvalidSPDXAnalysisException {
@@ -276,7 +275,7 @@ private void restoreRelationship(String documentNamespace, JsonNode relationship
if (Objects.isNull(relationshipTypeNode) || !relationshipTypeNode.isTextual()) {
throw new InvalidSPDXAnalysisException("Missing required relationship type");
}
- String relationshipTypeUri = null;
+ String relationshipTypeUri;
try {
relationshipTypeUri = RelationshipType.valueOf(relationshipTypeNode.asText()).getIndividualURI();
} catch(Exception ex) {
@@ -307,9 +306,9 @@ private void restoreRelationship(String documentNamespace, JsonNode relationship
* @param relatedElement related element
* @param relationshipComment optional comment for the relationship
* @return the ID of the relationship
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
- private String addRelationship(String documentNamespace, String elementId, SimpleUriValue relationshipType, Object relatedElement, Optional relationshipComment) throws InvalidSPDXAnalysisException {
+ private String addRelationship(String documentNamespace, String elementId, SimpleUriValue relationshipType, Object relatedElement, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional relationshipComment) throws InvalidSPDXAnalysisException {
String relatedElementId;
if (relatedElement instanceof TypedValue) {
relatedElementId = CompatibleModelStoreWrapper.objectUriToId(store, ((TypedValue)relatedElement).getObjectUri(), documentNamespace);
@@ -321,7 +320,7 @@ private String addRelationship(String documentNamespace, String elementId, Simpl
throw new InvalidSPDXAnalysisException("Related element is not of an Element type for relationship to element "+elementId);
}
// check for duplicates
- Map relatedElementRelationships = null;
+ Map relatedElementRelationships;
Map> elementRelationships = addedRelationships.get(elementId);
if (Objects.nonNull(elementRelationships)) {
relatedElementRelationships = elementRelationships.get(relatedElementId);
@@ -359,7 +358,7 @@ private String addRelationship(String documentNamespace, String elementId, Simpl
* @param id ID for the element containing the properties
* @param node Node containing the property values
* @param spdxIdProperties Properties which contain an SPDX ID which needs to be replaced
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void restoreObjectPropertyValues(String documentUri, String id, JsonNode node,
Map spdxIdProperties) throws InvalidSPDXAnalysisException {
@@ -367,14 +366,15 @@ private void restoreObjectPropertyValues(String documentUri, String id, JsonNode
while (fieldIterator.hasNext()) {
Entry field = fieldIterator.next();
if (SKIPPED_PROPERTIES.contains(field.getKey())) {
- continue;
+ //noinspection UnnecessaryContinue
+ continue;
} 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 (SpdxConstantsCompatV2.PROP_PACKAGE_FILE.getName().equals(
MultiFormatStore.collectionPropertyNameToPropertyName(field.getKey()))) {
- // These needs to be converted to a CONTAINSS relationship
+ // These needs to be converted to a CONTAINS relationship
convertFieldToRelationship(documentUri, id, field.getValue(),
RelationshipType.CONTAINS, spdxIdProperties);
} else {
@@ -392,15 +392,15 @@ private void restoreObjectPropertyValues(String documentUri, String id, JsonNode
* @param spdxIdField Either a single SPDX ID or an array of SPDX IDs
* @param relationshipType Relationship type to use
* @param spdxIdProperties properties to add the relationship to
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void convertFieldToRelationship(String documentUri, String id, JsonNode spdxIdField,
RelationshipType relationshipType, Map spdxIdProperties) throws InvalidSPDXAnalysisException {
if ((spdxIdField instanceof ArrayNode)) {
- for (JsonNode spdxidNode:((ArrayNode)spdxIdField)) {
+ for (JsonNode spdxIdNode: spdxIdField) {
String relationshipId = addRelationship(documentUri, id,
new SimpleUriValue(relationshipType.getIndividualURI()),
- spdxidNode.asText(), Optional.empty());
+ spdxIdNode.asText(), Optional.empty());
spdxIdProperties.put(relationshipId, SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.getName()); // Add the SPDX ID to the list to be translated back to elements later
}
} else {
@@ -419,7 +419,7 @@ private void convertFieldToRelationship(String documentUri, String id, JsonNode
* @param value JSON node containing the value
* @param spdxIdProperties Properties which contain an SPDX ID which needs to be replaced
* @param list true if this property is a list type
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private void setPropertyValueForJsonNode(String documentUri, String id, String property, JsonNode value,
Map spdxIdProperties, boolean list) throws InvalidSPDXAnalysisException {
@@ -435,13 +435,13 @@ private void setPropertyValueForJsonNode(String documentUri, String id, String p
// ignore te null;
Optional propertyType = SpdxJsonLDContext.getInstance().getType(property);
if (list) {
- store.addValueToCollection(documentUri, id,
+ store.addValueToCollection(documentUri, id,
MultiFormatStore.collectionPropertyNameToPropertyName(property),
toStoredObject(documentUri, id,
- property, value, propertyType, spdxIdProperties, list));
+ property, value, propertyType, spdxIdProperties, true));
} else {
store.setValue(documentUri, id, property, toStoredObject(documentUri, id,
- property, value, propertyType, spdxIdProperties, list));
+ property, value, propertyType, spdxIdProperties, false));
}
}
}
@@ -455,16 +455,17 @@ private void setPropertyValueForJsonNode(String documentUri, String id, String p
* @param spdxIdProperties Properties which contain an SPDX ID which needs to be replaced
* @param list true if this property is a list type
* @return the object to be stored
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
- private Object toStoredObject(String documentUri, String id, String property, JsonNode value,
- Optional propertyType, Map spdxIdProperties, boolean list) throws InvalidSPDXAnalysisException {
+ @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
+ private Object toStoredObject(String documentUri, String id, String property, JsonNode value,
+ Optional propertyType, Map spdxIdProperties, boolean list) throws InvalidSPDXAnalysisException {
switch (value.getNodeType()) {
case ARRAY:
throw new InvalidSPDXAnalysisException("Can not convert a JSON array to a stored object");
case BOOLEAN:
if (propertyType.isPresent()) {
- Class extends Object> toStoreClass = SpdxJsonLDContext.XMLSCHEMA_TYPE_TO_JAVA_CLASS.get(propertyType.get());
+ Class> toStoreClass = SpdxJsonLDContext.XMLSCHEMA_TYPE_TO_JAVA_CLASS.get(propertyType.get());
if (Objects.isNull(toStoreClass)) {
// assume it is a boolean type
return value.asBoolean();
@@ -473,7 +474,7 @@ private Object toStoredObject(String documentUri, String id, String property, Js
} else if (Boolean.class.equals(toStoreClass)) {
return value.asBoolean();
} else {
- throw new InvalidSPDXAnalysisException("Can not convert a JSON BOOLEAN to a "+toStoreClass.toString());
+ throw new InvalidSPDXAnalysisException("Can not convert a JSON BOOLEAN to a "+ toStoreClass);
}
} else {
return value.asBoolean();
@@ -481,16 +482,16 @@ private Object toStoredObject(String documentUri, String id, String property, Js
case NULL: throw new InvalidSPDXAnalysisException("Can not convert a JSON NULL to a stored object");
case NUMBER: {
if (propertyType.isPresent()) {
- Class extends Object> toStoreClass = SpdxJsonLDContext.XMLSCHEMA_TYPE_TO_JAVA_CLASS.get(propertyType.get());
+ Class> toStoreClass = SpdxJsonLDContext.XMLSCHEMA_TYPE_TO_JAVA_CLASS.get(propertyType.get());
if (Objects.isNull(toStoreClass)) {
- // assume it is a integer type
+ // assume it is an integer type
return value.asInt();
} else if (String.class.equals(toStoreClass)) {
return Double.toString(value.asDouble());
} else if (Integer.class.equals(toStoreClass)) {
return value.asInt();
} else {
- throw new InvalidSPDXAnalysisException("Can not convert a JSON NUMBER to a "+toStoreClass.toString());
+ throw new InvalidSPDXAnalysisException("Can not convert a JSON NUMBER to a "+ toStoreClass);
}
} else {
return value.asInt();
@@ -522,28 +523,24 @@ private Object toStoredObject(String documentUri, String id, String property, Js
case BINARY:
case MISSING:
case POJO:
- default: throw new InvalidSPDXAnalysisException("Unsupported JSON node type: "+value.toString());
+ default: throw new InvalidSPDXAnalysisException("Unsupported JSON node type: "+ value);
}
}
-
- /**
- * @param spdxIdProperties Properties which contain an SPDX ID which needs to be replaced
- *
- * @throws InvalidSPDXAnalysisException
- */
+
/**
* Gets the property value for a string JsonNode
* @param documentUri document URI
* @param id ID of the object to store the value
* @param property property name
* @param value JSON node containing the value
- * @param propertyType
+ * @param propertyType SPDX model type for the property
* @param list true if this property is a list type
* @return the appropriate object to store
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
- private Object getStringPropertyValueForJsonNode(String documentUri, String id, String property, JsonNode value,
- Optional propertyType, Map spdxIdProperties, boolean list) throws InvalidSPDXAnalysisException {
+ @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
+ private Object getStringPropertyValueForJsonNode(String documentUri, String id, String property, JsonNode value,
+ Optional propertyType, Map spdxIdProperties, boolean list) throws InvalidSPDXAnalysisException {
Class> clazz = null;
if (propertyType.isPresent()) {
// check for SPDX model types
@@ -565,14 +562,7 @@ private Object getStringPropertyValueForJsonNode(String documentUri, String id,
} else if (SpdxDocument.class.isAssignableFrom(clazz)) {
// Convert any IndividualUriValue values
final String uriValue = value.asText();
- return new IndividualUriValue() {
-
- @Override
- public String getIndividualURI() {
- return uriValue;
- }
-
- };
+ return (IndividualUriValue) () -> uriValue;
} else if (ReferenceType.class.isAssignableFrom(clazz)) {
String referenceTypeValue = value.asText();
try {
@@ -587,14 +577,7 @@ public String getIndividualURI() {
}
final String uriValue = referenceTypeValue;
// Check for listed reference types
- return new IndividualUriValue() {
-
- @Override
- public String getIndividualURI() {
- return uriValue;
- }
-
- };
+ return (IndividualUriValue) () -> uriValue;
} else if (SpdxElement.class.isAssignableFrom(clazz)) {
// store the ID and save it in the spdxIdProperties to replace with the actual class later
// once everything is restored
@@ -633,10 +616,10 @@ public String getIndividualURI() {
/**
- * @param documentUri
- * @param jsonObject
+ * @param documentUri namespace for the document
+ * @param jsonObject JSON Object to search for an ID
* @return the ID for the JSON object based on what property values are available
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private String findObjectIdInJsonObject(String documentUri, JsonNode jsonObject) throws InvalidSPDXAnalysisException {
JsonNode retval = jsonObject.get(SpdxConstantsCompatV2.SPDX_IDENTIFIER);
@@ -659,48 +642,28 @@ private String findObjectIdInJsonObject(String documentUri, JsonNode jsonObject)
/**
* Convert an ID into the value object to be stored
- * @param documentNamespace
+ * @param documentNamespace namespace for the document
* @param spdxId ID to be replaced by the actual object
* @param addedElements SPDX elements added
- * @return
- * @throws InvalidSPDXAnalysisException
+ * @return value object to be stored
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private Object idToObjectValue(String documentNamespace, String spdxId, Map addedElements) throws InvalidSPDXAnalysisException {
TypedValue fixedValue = addedElements.get(spdxId);
if (Objects.isNull(fixedValue)) {
if (spdxId.equals(SpdxConstantsCompatV2.NONE_VALUE)) {
- return new IndividualUriValue() {
-
- @Override
- public String getIndividualURI() {
- return SpdxConstantsCompatV2.URI_VALUE_NONE;
- }
-
- };
+ return (IndividualUriValue) () -> SpdxConstantsCompatV2.URI_VALUE_NONE;
} else if (spdxId.equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) {
- return new IndividualUriValue() {
-
- @Override
- public String getIndividualURI() {
- return SpdxConstantsCompatV2.URI_VALUE_NOASSERTION;
- }
-
- };
+ return (IndividualUriValue) () -> SpdxConstantsCompatV2.URI_VALUE_NOASSERTION;
} else if (spdxId.startsWith("DocumentRef-")) {
final IModelStore modelStore = store;
- IndividualUriValue spdxExternalElementRef = new IndividualUriValue() {
-
- @Override
- public String getIndividualURI() {
- try {
- return ExternalSpdxElement.externalSpdxElementIdToURI(spdxId, modelStore, documentNamespace, modelCopyManager);
- } catch (InvalidSPDXAnalysisException e) {
- throw new RuntimeException(e);
- }
- }
-
- };
- return spdxExternalElementRef;
+ return (IndividualUriValue) () -> {
+ try {
+ return ExternalSpdxElement.externalSpdxElementIdToURI(spdxId, modelStore, documentNamespace, modelCopyManager);
+ } catch (InvalidSPDXAnalysisException e) {
+ throw new RuntimeException(e);
+ }
+ };
} else {
throw new InvalidSPDXAnalysisException("No SPDX element found for SPDX ID "+spdxId);
}
diff --git a/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java b/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java
index 832dadf..6938e37 100644
--- a/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java
+++ b/src/main/java/org/spdx/jacksonstore/JacksonSerializer.java
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2020 Source Auditor Inc.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -62,7 +62,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 for a document
* @author Gary O'Neall
*
@@ -75,7 +75,7 @@ public class JacksonSerializer {
* Class to for the name of the XML element to Document
*
*/
- class Document extends ObjectNode {
+ static class Document extends ObjectNode {
/**
*
@@ -112,10 +112,10 @@ public int compare(JsonNode arg0, JsonNode arg1) {
return -1;
} else {
List list0 = new ArrayList<>();
- arg0.spliterator().forEachRemaining((node) -> list0.add(node));
+ arg0.spliterator().forEachRemaining(list0::add);
list0.sort(NODE_COMPARATOR);
List list1 = new ArrayList<>();
- arg1.spliterator().forEachRemaining((node) -> list1.add(node));
+ arg1.spliterator().forEachRemaining(list1::add);
list1.sort(NODE_COMPARATOR);
for (int i = 0; i < list0.size(); i++) {
int retval = compare(list0.get(i), list1.get(i));
@@ -158,7 +158,7 @@ private int compareObject(JsonNode arg0, JsonNode arg1) {
return compareExternalRef(refCategory0.asText(), refType0.asText(), refLocator0.asText(), arg1);
}
List fieldNames = new ArrayList<>();
- arg0.fieldNames().forEachRemaining((String field) -> fieldNames.add(field));
+ arg0.fieldNames().forEachRemaining(fieldNames::add);
Collections.sort(fieldNames);
int retval = 0;
for (String fieldName:fieldNames) {
@@ -218,10 +218,10 @@ private int compareExtractedLicense(String licenseId, JsonNode compare) {
};
- private ObjectMapper mapper;
- private CompatibleModelStoreWrapper store;
- private Format format;
- private Verbose verbose;
+ private final ObjectMapper mapper;
+ private final CompatibleModelStoreWrapper store;
+ private final Format format;
+ private final Verbose verbose;
/**
* @param mapper Jackson Object Mapper to use for creating JSON objects
@@ -242,7 +242,7 @@ public JacksonSerializer(ObjectMapper mapper, Format format, Verbose verbose, IM
/**
* @param documentUris list of document uris
* @return JSON array of all documents which have the document Uris
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
public ArrayNode docsToJsonNode(List documentUris) throws InvalidSPDXAnalysisException {
ArrayNode retval = mapper.createArrayNode();
@@ -255,7 +255,7 @@ public ArrayNode docsToJsonNode(List documentUris) throws InvalidSPDXAna
/**
* @param documentUri URI for the document to be converted
* @return ObjectNode for an SPDX document in Jackson JSON tree format
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisException {
Objects.requireNonNull(documentUri,"Null Document URI");
@@ -267,15 +267,15 @@ public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisEx
ObjectNode doc = typedValueToObjectNode(documentUri, document, relationships);
doc.put(SpdxConstantsCompatV2.PROP_DOCUMENT_NAMESPACE.getName(), documentUri);
ArrayNode packages = getDocElements(documentUri, SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, relationships);
- if (packages.size() > 0) {
+ if (!packages.isEmpty()) {
doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_PACKAGES.getName(), packages);
}
ArrayNode files = getDocElements(documentUri, SpdxConstantsCompatV2.CLASS_SPDX_FILE, relationships);
- if (files.size() > 0) {
+ if (!files.isEmpty()) {
doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_FILES.getName(), files);
}
ArrayNode snippets = getDocElements(documentUri, SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, relationships);
- if (snippets.size() > 0) {
+ if (!snippets.isEmpty()) {
doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_SNIPPETS.getName(), snippets);
}
//Remove duplicate relationships
@@ -307,19 +307,13 @@ public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisEx
doc.set(SpdxConstantsCompatV2.PROP_DOCUMENT_RELATIONSHIPS.getName(), deDupedRelationships);
ObjectNode output;
switch (format) {
- case YAML: {
- output = doc;
- break;
- }
case XML: {
output = new Document(JsonNodeFactory.instance);
output.setAll(doc);
break;
}
- case JSON: {
- output = doc;
- break;
- }
+ case JSON:
+ case YAML:
case JSON_PRETTY:
default: {
output = doc;
@@ -338,14 +332,14 @@ public ObjectNode docToJsonNode(String documentUri) throws InvalidSPDXAnalysisEx
* @param storedItem stored value to convert to a JSON serializable form
* @param relationships ArrayNode of relationships to add any found relationships
* @return ObjectNode with all fields added from the stored typedValue
- * @throws InvalidSPDXAnalysisException
+ * @throws InvalidSPDXAnalysisException on SPDX parsing errors
*/
private ObjectNode typedValueToObjectNode(String documentUri, TypedValue storedItem,
ArrayNode relationships) throws InvalidSPDXAnalysisException {
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(storedItem.getObjectUri()));
+ List docPropNames = new ArrayList<>(store.getPropertyValueNames(storedItem.getObjectUri()));
docPropNames.sort(new PropertyComparator(storedItem.getType()));
Class> clazz = SpdxModelFactoryCompatV2.SPDX_TYPE_TO_CLASS_V2.get(storedItem.getType());
IdType idType = store.getIdType(storedItem.getObjectUri());
@@ -354,7 +348,7 @@ private ObjectNode typedValueToObjectNode(String documentUri, TypedValue storedI
if (IdType.SpdxId.equals(idType)) {
retval.put(SpdxConstantsCompatV2.SPDX_IDENTIFIER, CompatibleModelStoreWrapper.objectUriToId(store, storedItem.getObjectUri(), documentUri));
} else if (!IdType.Anonymous.equals(idType)) {
- logger.error("Invalid ID "+storedItem.getObjectUri()+". Must be an SPDX Identifier or Anonymous");
+ logger.error("Invalid ID {}. Must be an SPDX Identifier or Anonymous", storedItem.getObjectUri());
throw new InvalidSPDXAnalysisException("Invalid ID "+storedItem.getObjectUri()+". Must be an SPDX Identifier or Anonymous");
}
} else if (ExternalDocumentRef.class.isAssignableFrom(clazz)) {
@@ -371,7 +365,7 @@ private ObjectNode typedValueToObjectNode(String documentUri, TypedValue storedI
} else if (store.isCollectionProperty(documentUri, id, propertyName)) {
Iterator