From e4faf911af570319b6c9377764aa80a5d4f12768 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Tue, 30 May 2023 07:37:52 -0700 Subject: [PATCH 01/62] Change propertyName to propertyDescriptor This is a breaking change. Change the storage interface to use a PropertyDescriptor type which includes both a property name and a namespace. This prevents property name collisions which will occur in the SPDX v3 model update. To update any code which uses the storage interface, change the property name to PropertyDescriptor for all calls to the interface which used propertyName. The constants have been updated to use the PropertyDescriptor type which should minimize the amount of change. Signed-off-by: Gary O'Neall --- .../org/spdx/library/ModelCopyManager.java | 41 +-- .../java/org/spdx/library/SpdxConstants.java | 288 +++++++++--------- .../spdx/library/model/ModelCollection.java | 34 ++- .../org/spdx/library/model/ModelObject.java | 275 +++++++++-------- .../java/org/spdx/library/model/ModelSet.java | 7 +- .../org/spdx/library/model/SpdxDocument.java | 3 +- .../org/spdx/library/model/SpdxElement.java | 7 +- .../java/org/spdx/library/model/SpdxFile.java | 5 +- .../java/org/spdx/library/model/SpdxItem.java | 3 +- .../org/spdx/library/model/SpdxPackage.java | 3 +- .../org/spdx/library/model/SpdxSnippet.java | 3 +- .../java/org/spdx/storage/IModelStore.java | 70 ++--- .../org/spdx/storage/PropertyDescriptor.java | 90 ++++++ .../storage/listedlicense/ExceptionJson.java | 4 +- .../storage/listedlicense/LicenseJson.java | 11 +- .../SpdxListedLicenseModelStore.java | 122 ++++---- .../storage/simple/ExtendedSpdxStore.java | 57 ++-- .../spdx/storage/simple/InMemSpdxStore.java | 245 ++++++++------- .../spdx/storage/simple/StoredTypedItem.java | 179 ++++++----- .../library/model/ModelCollectionTest.java | 4 +- .../spdx/library/model/ModelObjectTest.java | 98 ++++-- .../listedlicense/CrossRefJsonTest.java | 14 +- .../listedlicense/ExceptionJsonTest.java | 28 +- .../listedlicense/LicenseJsonTest.java | 33 +- .../storage/simple/InMemSpdxStoreTest.java | 93 +++--- .../storage/simple/StoredTypedItemTest.java | 48 +-- 26 files changed, 982 insertions(+), 783 deletions(-) create mode 100644 src/main/java/org/spdx/storage/PropertyDescriptor.java diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index dd4d36983..d26c2a836 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -31,6 +31,7 @@ import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.PropertyDescriptor; /** * This class helps facilitate copying objects from one model to another. @@ -172,12 +173,12 @@ public void copy(IModelStore toStore, String toDocumentUri, String toId, if (!(excludeLicenseDetails && (SpdxConstants.CLASS_SPDX_LISTED_LICENSE.equals(type) || SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)))) { - List propertyNames = fromStore.getPropertyValueNames(fromDocumentUri, fromId); - for (String propName:propertyNames) { - if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { - copyCollectionProperty(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, propName, excludeLicenseDetails); + List propertyDescriptors = fromStore.getPropertyValueDescriptors(fromDocumentUri, fromId); + for (PropertyDescriptor propDesc:propertyDescriptors) { + if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propDesc)) { + copyCollectionProperty(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, propDesc, excludeLicenseDetails); } else { - copyIndividualProperty(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, propName, excludeLicenseDetails); + copyIndividualProperty(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, propDesc, excludeLicenseDetails); } } } @@ -191,37 +192,37 @@ public void copy(IModelStore toStore, String toDocumentUri, String toId, * @param fromStore Model Store containing the source item * @param fromDocumentUri Document URI for the source item * @param fromId ID source ID - * @param propName Name of the property + * @param propDescriptor Descriptor for the property * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses * @throws InvalidSPDXAnalysisException */ private void copyIndividualProperty(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, - String fromDocumentUri, String fromId, String propName, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { + String fromDocumentUri, String fromId, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(fromDocumentUri, false); //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection Optional result = Optional.empty(); try { - if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { - throw new InvalidSPDXAnalysisException("Property "+propName+" is a collection type"); + if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propDescriptor)) { + throw new InvalidSPDXAnalysisException("Property "+propDescriptor+" is a collection type"); } - result = fromStore.getValue(fromDocumentUri, fromId, propName); + result = fromStore.getValue(fromDocumentUri, fromId, propDescriptor); } finally { fromStoreLock.unlock(); } if (result.isPresent()) { if (result.get() instanceof IndividualUriValue) { - toStore.setValue(toDocumentUri, toId, propName, new SimpleUriValue((IndividualUriValue)result.get())); + toStore.setValue(toDocumentUri, toId, propDescriptor, new SimpleUriValue((IndividualUriValue)result.get())); } else if (result.get() instanceof TypedValue) { TypedValue tv = (TypedValue)result.get(); if (fromStore.equals(toStore) && fromDocumentUri.equals(toDocumentUri)) { - toStore.setValue(toDocumentUri, toId, propName, tv); + toStore.setValue(toDocumentUri, toId, propDescriptor, tv); } else { - toStore.setValue(toDocumentUri, toId, propName, + toStore.setValue(toDocumentUri, toId, propDescriptor, copy(toStore, toDocumentUri, fromStore, fromDocumentUri, tv.getId(), tv.getType(), excludeLicenseDetails)); } } else { - toStore.setValue(toDocumentUri, toId, propName, result.get()); + toStore.setValue(toDocumentUri, toId, propDescriptor, result.get()); } } } @@ -234,20 +235,20 @@ private void copyIndividualProperty(IModelStore toStore, String toDocumentUri, S * @param fromStore Model Store containing the source item * @param fromDocumentUri Document URI for the source item * @param fromId ID source ID - * @param propName Name of the property + * @param propDescriptor Descriptor for the property * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses * @throws InvalidSPDXAnalysisException */ private void copyCollectionProperty(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, - String fromDocumentUri, String fromId, String propName, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { + String fromDocumentUri, String fromId, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(fromDocumentUri, false); //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection Iterator fromListIter = null; try { - if (!fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { - throw new InvalidSPDXAnalysisException("Property "+propName+" is not a collection type"); + if (!fromStore.isCollectionProperty(fromDocumentUri, fromId, propDescriptor)) { + throw new InvalidSPDXAnalysisException("Property "+propDescriptor+" is not a collection type"); } - fromListIter = fromStore.listValues(fromDocumentUri, fromId, propName); + fromListIter = fromStore.listValues(fromDocumentUri, fromId, propDescriptor); } finally { fromStoreLock.unlock(); } @@ -267,7 +268,7 @@ private void copyCollectionProperty(IModelStore toStore, String toDocumentUri, S } else { toStoreItem = listItem; } - toStore.addValueToCollection(toDocumentUri, toId, propName, toStoreItem); + toStore.addValueToCollection(toDocumentUri, toId, propDescriptor, toStoreItem); } } diff --git a/src/main/java/org/spdx/library/SpdxConstants.java b/src/main/java/org/spdx/library/SpdxConstants.java index 41967413c..1120f9a09 100644 --- a/src/main/java/org/spdx/library/SpdxConstants.java +++ b/src/main/java/org/spdx/library/SpdxConstants.java @@ -18,6 +18,8 @@ import java.util.regex.Pattern; +import org.spdx.storage.PropertyDescriptor; + /** * Constants which map to the SPDX specifications found at http://spdx.org/rdf/terms @@ -36,28 +38,29 @@ public class SpdxConstants { public static final String XML_SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema#"; // RDF Properties - within the RDF_NAMESPACE - public static final String RDF_PROP_TYPE = "type"; - public static final String RDF_PROP_RESOURCE = "resource"; - public static final String[] RDF_PROPERTIES = new String[] {RDF_PROP_TYPE, RDF_PROP_RESOURCE}; + public static final PropertyDescriptor RDF_PROP_TYPE = new PropertyDescriptor("type", RDF_NAMESPACE); + public static final PropertyDescriptor RDF_PROP_RESOURCE = new PropertyDescriptor("resource", RDF_NAMESPACE); + public static final String[] RDF_PROPERTIES = new String[] {RDF_PROP_TYPE.getName(), RDF_PROP_RESOURCE.getName()}; // OWL Properties - within the OWL_NAMESPACE - public static final String PROP_OWL_SAME_AS = "sameAs"; - public static final String[] OWL_PROPERTIES = new String[] {PROP_OWL_SAME_AS}; + public static final PropertyDescriptor PROP_OWL_SAME_AS = new PropertyDescriptor("sameAs", OWL_NAMESPACE); + public static final String[] OWL_PROPERTIES = new String[] {PROP_OWL_SAME_AS.getName()}; // RDFS Properties - within the RDFS_NAMESPACE - public static final String RDFS_PROP_COMMENT = "comment"; - public static final String RDFS_PROP_LABEL = "label"; - public static final String RDFS_PROP_SEE_ALSO = "seeAlso"; - public static final String[] RDFS_PROPERTIES = new String[] {RDFS_PROP_COMMENT, RDFS_PROP_LABEL, RDFS_PROP_SEE_ALSO}; + public static final PropertyDescriptor RDFS_PROP_COMMENT = new PropertyDescriptor("comment", RDFS_NAMESPACE); + public static final PropertyDescriptor RDFS_PROP_LABEL = new PropertyDescriptor("label", RDFS_NAMESPACE); + public static final PropertyDescriptor RDFS_PROP_SEE_ALSO = new PropertyDescriptor("seeAlso", RDFS_NAMESPACE); + public static final String[] RDFS_PROPERTIES = new String[] {RDFS_PROP_COMMENT.getName(), + RDFS_PROP_LABEL.getName(), RDFS_PROP_SEE_ALSO.getName()}; // DOAP Class Names - within the DOAP_NAMESPACE public static final String CLASS_DOAP_PROJECT = "Project"; public static final String[] DOAP_CLASSES = {CLASS_DOAP_PROJECT}; // DOAP Project Property Names - within the DOAP_NAMESPACE - public static final String PROP_PROJECT_HOMEPAGE = "homepage"; - public static final String[] DOAP_PROPERTIES = new String[] {PROP_PROJECT_HOMEPAGE}; + public static final PropertyDescriptor PROP_PROJECT_HOMEPAGE = new PropertyDescriptor("homepage", DOAP_NAMESPACE); + public static final String[] DOAP_PROPERTIES = new String[] {PROP_PROJECT_HOMEPAGE.getName()}; // Pointer Class Names - with in the RDF_POINTER_NAMESPACE public static final String CLASS_POINTER_START_END_POINTER = "StartEndPointer"; @@ -71,14 +74,15 @@ public class SpdxConstants { }; // Pointer Properties - with in the RDF_POINTER_NAMESPACE - public static final String PROP_POINTER_START_POINTER = "startPointer"; - public static final String PROP_POINTER_END_POINTER = "endPointer"; - public static final String PROP_POINTER_REFERENCE = "reference"; - public static final String PROP_POINTER_OFFSET = "offset"; - public static final String PROP_POINTER_LINE_NUMBER = "lineNumber"; + public static final PropertyDescriptor PROP_POINTER_START_POINTER = new PropertyDescriptor("startPointer", RDF_POINTER_NAMESPACE); + public static final PropertyDescriptor PROP_POINTER_END_POINTER = new PropertyDescriptor("endPointer", RDF_POINTER_NAMESPACE); + public static final PropertyDescriptor PROP_POINTER_REFERENCE = new PropertyDescriptor("reference", RDF_POINTER_NAMESPACE); + public static final PropertyDescriptor PROP_POINTER_OFFSET = new PropertyDescriptor("offset", RDF_POINTER_NAMESPACE); + public static final PropertyDescriptor PROP_POINTER_LINE_NUMBER = new PropertyDescriptor("lineNumber", RDF_POINTER_NAMESPACE); public static final String[] POINTER_PROPERTIES = new String[] { - PROP_POINTER_START_POINTER, PROP_POINTER_END_POINTER, PROP_POINTER_REFERENCE, PROP_POINTER_OFFSET, - PROP_POINTER_LINE_NUMBER + PROP_POINTER_START_POINTER.getName(), PROP_POINTER_END_POINTER.getName(), + PROP_POINTER_REFERENCE.getName(), PROP_POINTER_OFFSET.getName(), + PROP_POINTER_LINE_NUMBER.getName() }; // SPDX Class Names @@ -145,124 +149,122 @@ public class SpdxConstants { public static final String ENUM_REFERENCE_RELATIONSHIP_TYPE = "RelationshipType"; public static final String ENUM_PURPOSE = "Purpose"; // General SPDX Properties - public static final String PROP_VALUE_NONE = "none"; - public static final String URI_VALUE_NONE = SPDX_NAMESPACE + PROP_VALUE_NONE; - public static final String PROP_VALUE_NOASSERTION = "noassertion"; - public static final String URI_VALUE_NOASSERTION = SPDX_NAMESPACE + PROP_VALUE_NOASSERTION; + public static final PropertyDescriptor PROP_VALUE_NONE = new PropertyDescriptor("none", SPDX_NAMESPACE); + public static final String URI_VALUE_NONE = PROP_VALUE_NONE.toString(); + public static final PropertyDescriptor PROP_VALUE_NOASSERTION = new PropertyDescriptor("noassertion", SPDX_NAMESPACE); + public static final String URI_VALUE_NOASSERTION = PROP_VALUE_NOASSERTION.toString(); public static final String SPDX_IDENTIFIER = "SPDXID"; public static final String EXTERNAL_DOCUMENT_REF_IDENTIFIER = "externalDocumentId"; // SPDX Document Properties // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - public static final String PROP_SPDX_REVIEWED_BY = "reviewed"; - public static final String PROP_SPDX_EXTRACTED_LICENSES = "hasExtractedLicensingInfo"; - public static final String PROP_SPDX_VERSION = "specVersion"; // TODO: Migrate this to PROP_SPDX_SPEC_VERSION in 3.0. See issue - public static final String PROP_SPDX_SPEC_VERSION = "spdxVersion"; - public static final String PROP_SPDX_CREATION_INFO = "creationInfo"; - public static final String PROP_SPDX_PACKAGE = "describesPackage"; - @Deprecated // since 2.0 Planned to be removed in next major spec revision - public static final String PROP_SPDX_FILE_REFERENCE = "referencesFile"; - public static final String PROP_SPDX_DATA_LICENSE = "dataLicense"; - public static final String PROP_SPDX_EXTERNAL_DOC_REF = "externalDocumentRef"; + public static final PropertyDescriptor PROP_SPDX_REVIEWED_BY = new PropertyDescriptor("reviewed", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_EXTRACTED_LICENSES = new PropertyDescriptor("hasExtractedLicensingInfo", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_VERSION = new PropertyDescriptor("specVersion", SPDX_NAMESPACE); // TODO: Migrate this to PROP_SPDX_SPEC_VERSION in 3.0. See issue + public static final PropertyDescriptor PROP_SPDX_SPEC_VERSION = new PropertyDescriptor("spdxVersion", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_CREATION_INFO = new PropertyDescriptor("creationInfo", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_PACKAGE = new PropertyDescriptor("describesPackage", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_DATA_LICENSE = new PropertyDescriptor("dataLicense", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_EXTERNAL_DOC_REF = new PropertyDescriptor("externalDocumentRef", SPDX_NAMESPACE); public static final String SPDX_DOCUMENT_ID = "SPDXRef-DOCUMENT"; - public static final String PROP_DOCUMENT_NAMESPACE = "documentNamespace"; + public static final PropertyDescriptor PROP_DOCUMENT_NAMESPACE = new PropertyDescriptor("documentNamespace", SPDX_NAMESPACE); // SPDX Document properties for JSON and YAML files - public static final String PROP_DOCUMENT_DESCRIBES = "documentDescribes"; //TODO: This is not yet approved in the spec - see issue # - public static final String PROP_DOCUMENT_FILES = "files"; //TODO: This is not yet approved in the spec - see issue # - public static final String PROP_DOCUMENT_PACKAGES = "packages"; //TODO: This is not yet approved in the spec - see issue # - public static final String PROP_DOCUMENT_SNIPPETS = "snippets"; //TODO: This is not yet approved in the spec - see issue # - public static final String PROP_DOCUMENT_RELATIONSHIPS = "relationships"; //TODO: This is not yet approved in the spec - see issue # + public static final PropertyDescriptor PROP_DOCUMENT_DESCRIBES = new PropertyDescriptor("documentDescribes", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # + public static final PropertyDescriptor PROP_DOCUMENT_FILES = new PropertyDescriptor("files", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # + public static final PropertyDescriptor PROP_DOCUMENT_PACKAGES = new PropertyDescriptor("packages", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # + public static final PropertyDescriptor PROP_DOCUMENT_SNIPPETS = new PropertyDescriptor("snippets", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # + public static final PropertyDescriptor PROP_DOCUMENT_RELATIONSHIPS = new PropertyDescriptor("relationships", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # // SPDX CreationInfo Properties // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - public static final String PROP_CREATION_CREATOR = "creator"; - public static final String PROP_CREATION_CREATED = "created"; // creation timestamp - public static final String PROP_LICENSE_LIST_VERSION = "licenseListVersion"; + public static final PropertyDescriptor PROP_CREATION_CREATOR = new PropertyDescriptor("creator", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CREATION_CREATED = new PropertyDescriptor("created", SPDX_NAMESPACE); // creation timestamp + public static final PropertyDescriptor PROP_LICENSE_LIST_VERSION = new PropertyDescriptor("licenseListVersion", SPDX_NAMESPACE); public static final String CREATOR_PREFIX_PERSON = "Person:"; public static final String CREATOR_PREFIX_ORGANIZATION = "Organization:"; public static final String CREATOR_PREFIX_TOOL = "Tool:"; // SPDX Checksum Properties - public static final String PROP_CHECKSUM_ALGORITHM = "algorithm"; - public static final String PROP_CHECKSUM_VALUE = "checksumValue"; + public static final PropertyDescriptor PROP_CHECKSUM_ALGORITHM = new PropertyDescriptor("algorithm", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CHECKSUM_VALUE = new PropertyDescriptor("checksumValue", SPDX_NAMESPACE); public static final String ALGORITHM_SHA1 = "SHA1"; public static final String PROP_CHECKSUM_ALGORITHM_SHA1 = "checksumAlgorithm_sha1"; // SPDX PackageVerificationCode Properties - public static final String PROP_VERIFICATIONCODE_IGNORED_FILES = "packageVerificationCodeExcludedFile"; - public static final String PROP_VERIFICATIONCODE_VALUE = "packageVerificationCodeValue"; + public static final PropertyDescriptor PROP_VERIFICATIONCODE_IGNORED_FILES = new PropertyDescriptor("packageVerificationCodeExcludedFile", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_VERIFICATIONCODE_VALUE = new PropertyDescriptor("packageVerificationCodeValue", SPDX_NAMESPACE); // SPDX Element Properties - public static final String PROP_ANNOTATION = "annotation"; - public static final String PROP_RELATIONSHIP = "relationship"; + public static final PropertyDescriptor PROP_ANNOTATION = new PropertyDescriptor("annotation", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_RELATIONSHIP = new PropertyDescriptor("relationship", SPDX_NAMESPACE); // SPDX Item Properties - public static final String PROP_LICENSE_CONCLUDED = "licenseConcluded"; - public static final String PROP_COPYRIGHT_TEXT = "copyrightText"; - public static final String PROP_LIC_COMMENTS = "licenseComments"; - public static final String PROP_LICENSE_DECLARED = "licenseDeclared"; - public static final String PROP_ATTRIBUTION_TEXT = "attributionText"; + public static final PropertyDescriptor PROP_LICENSE_CONCLUDED = new PropertyDescriptor("licenseConcluded", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_COPYRIGHT_TEXT = new PropertyDescriptor("copyrightText", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LIC_COMMENTS = new PropertyDescriptor("licenseComments", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_DECLARED = new PropertyDescriptor("licenseDeclared", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_ATTRIBUTION_TEXT = new PropertyDescriptor("attributionText", SPDX_NAMESPACE); // SPDX Package Properties - public static final String PROP_PACKAGE_DECLARED_NAME = "name"; - public static final String PROP_PACKAGE_FILE_NAME = "packageFileName"; - public static final String PROP_PACKAGE_CHECKSUM = "checksum"; - public static final String PROP_PACKAGE_DOWNLOAD_URL = "downloadLocation"; - public static final String PROP_PACKAGE_SOURCE_INFO = "sourceInfo"; - public static final String PROP_PACKAGE_DECLARED_LICENSE = "licenseDeclared"; - public static final String PROP_PACKAGE_CONCLUDED_LICENSE = PROP_LICENSE_CONCLUDED; - public static final String PROP_PACKAGE_DECLARED_COPYRIGHT = PROP_COPYRIGHT_TEXT; - public static final String PROP_PACKAGE_SHORT_DESC = "summary"; - public static final String PROP_PACKAGE_DESCRIPTION = "description"; - public static final String PROP_PACKAGE_FILE = "hasFile"; - public static final String PROP_PACKAGE_VERIFICATION_CODE = "packageVerificationCode"; - public static final String PROP_PACKAGE_LICENSE_INFO_FROM_FILES = "licenseInfoFromFiles"; - public static final String PROP_PACKAGE_LICENSE_COMMENT = "licenseComments"; - public static final String PROP_PACKAGE_VERSION_INFO = "versionInfo"; - public static final String PROP_PACKAGE_ORIGINATOR = "originator"; - public static final String PROP_PACKAGE_SUPPLIER = "supplier"; - public static final String PROP_PACKAGE_FILES_ANALYZED = "filesAnalyzed"; - public static final String PROP_EXTERNAL_REF = "externalRef"; - public static final String PROP_PRIMARY_PACKAGE_PURPOSE = "primaryPackagePurpose"; - public static final String PROP_BUILT_DATE = "builtDate"; - public static final String PROP_RELEASE_DATE = "releaseDate"; - public static final String PROP_VALID_UNTIL_DATE = "validUntilDate"; + public static final PropertyDescriptor PROP_PACKAGE_DECLARED_NAME = new PropertyDescriptor("name", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_FILE_NAME = new PropertyDescriptor("packageFileName", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_CHECKSUM = new PropertyDescriptor("checksum", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_DOWNLOAD_URL = new PropertyDescriptor("downloadLocation", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_SOURCE_INFO = new PropertyDescriptor("sourceInfo", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_DECLARED_LICENSE = new PropertyDescriptor("licenseDeclared", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_CONCLUDED_LICENSE = PROP_LICENSE_CONCLUDED; + public static final PropertyDescriptor PROP_PACKAGE_DECLARED_COPYRIGHT = PROP_COPYRIGHT_TEXT; + public static final PropertyDescriptor PROP_PACKAGE_SHORT_DESC = new PropertyDescriptor("summary", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_DESCRIPTION = new PropertyDescriptor("description", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_FILE = new PropertyDescriptor("hasFile", SPDX_NAMESPACE);; + public static final PropertyDescriptor PROP_PACKAGE_VERIFICATION_CODE = new PropertyDescriptor("packageVerificationCode", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_LICENSE_INFO_FROM_FILES = new PropertyDescriptor("licenseInfoFromFiles", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_LICENSE_COMMENT = new PropertyDescriptor("licenseComments", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_VERSION_INFO = new PropertyDescriptor("versionInfo", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_ORIGINATOR = new PropertyDescriptor("originator", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_SUPPLIER = new PropertyDescriptor("supplier", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PACKAGE_FILES_ANALYZED = new PropertyDescriptor("filesAnalyzed", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXTERNAL_REF = new PropertyDescriptor("externalRef", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_PRIMARY_PACKAGE_PURPOSE = new PropertyDescriptor("primaryPackagePurpose", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_BUILT_DATE = new PropertyDescriptor("builtDate", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_RELEASE_DATE = new PropertyDescriptor("releaseDate", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_VALID_UNTIL_DATE = new PropertyDescriptor("validUntilDate", SPDX_NAMESPACE); public static final Pattern REFERENCE_TYPE_URI_PATTERN = Pattern.compile("https?://spdx.org/rdf/references/.+"); // SPDX License Properties // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace // the seeAlso property is in the RDFS_PROP_SEE_ALSO property in the rdfs namespace - public static final String PROP_LICENSE_ID = "licenseId"; - public static final String PROP_LICENSE_TEXT = "licenseText"; - public static final String PROP_LICENSE_TEXT_HTML = "licenseTextHtml"; - public static final String PROP_EXTRACTED_TEXT = "extractedText"; - public static final String PROP_LICENSE_NAME = "licenseName"; - public static final String PROP_STD_LICENSE_NAME_VERSION_1 = "licenseName"; // old property name (pre 1.1 spec) - public static final String PROP_STD_LICENSE_NAME = "name"; - public static final String PROP_STD_LICENSE_URL_VERSION_1 = "licenseSourceUrl"; // This has been replaced with the rdfs:seeAlso property - public static final String PROP_STD_LICENSE_NOTES_VERSION_1 = "licenseNotes"; // old property name (pre 1.1 spec) - public static final String PROP_STD_LICENSE_HEADER_VERSION_1 = "licenseHeader"; // old property name (pre 1.1 spec) - public static final String PROP_STD_LICENSE_NOTICE = "standardLicenseHeader"; - public static final String PROP_STD_LICENSE_HEADER_TEMPLATE = "standardLicenseHeaderTemplate"; - public static final String PROP_LICENSE_HEADER_HTML = "standardLicenseHeaderHtml"; - public static final String PROP_STD_LICENSE_TEMPLATE_VERSION_1 = "licenseTemplate"; // old property name (pre 1.2 spec) - public static final String PROP_STD_LICENSE_TEMPLATE = "standardLicenseTemplate"; - public static final String PROP_STD_LICENSE_OSI_APPROVED = "isOsiApproved"; - public static final String PROP_STD_LICENSE_FSF_LIBRE = "isFsfLibre"; - public static final String PROP_STD_LICENSE_OSI_APPROVED_VERSION_1 = "licenseOsiApproved"; // old property name (pre 1.1 spec) - public static final String PROP_LICENSE_SET_MEMEBER = "member"; - public static final String TERM_LICENSE_NOASSERTION = PROP_VALUE_NOASSERTION; - public static final String TERM_LICENSE_NONE = PROP_VALUE_NONE; - public static final String PROP_LICENSE_EXCEPTION_ID = "licenseExceptionId"; - public static final String PROP_EXAMPLE = "example"; - public static final String PROP_EXCEPTION_TEXT = "licenseExceptionText"; - public static final String PROP_EXCEPTION_TEXT_HTML = "exceptionTextHtml"; - public static final String PROP_EXCEPTION_TEMPLATE = "licenseExceptionTemplate"; - public static final String PROP_LICENSE_EXCEPTION = "licenseException"; - public static final String PROP_LIC_ID_DEPRECATED = "isDeprecatedLicenseId"; - public static final String PROP_LIC_DEPRECATED_VERSION = "deprecatedVersion"; - public static final String PROP_CROSS_REF = "crossRef"; + public static final PropertyDescriptor PROP_LICENSE_ID = new PropertyDescriptor("licenseId", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_TEXT = new PropertyDescriptor("licenseText", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_TEXT_HTML = new PropertyDescriptor("licenseTextHtml", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXTRACTED_TEXT = new PropertyDescriptor("extractedText", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_NAME = new PropertyDescriptor("licenseName", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_NAME_VERSION_1 = new PropertyDescriptor("licenseName", SPDX_NAMESPACE); // old property name (pre 1.1 spec) + public static final PropertyDescriptor PROP_STD_LICENSE_NAME = new PropertyDescriptor("name", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_URL_VERSION_1 = new PropertyDescriptor("licenseSourceUrl", SPDX_NAMESPACE); // This has been replaced with the rdfs:seeAlso property + public static final PropertyDescriptor PROP_STD_LICENSE_NOTES_VERSION_1 = new PropertyDescriptor("licenseNotes", SPDX_NAMESPACE); // old property name (pre 1.1 spec) + public static final PropertyDescriptor PROP_STD_LICENSE_HEADER_VERSION_1 = new PropertyDescriptor("licenseHeader", SPDX_NAMESPACE); // old property name (pre 1.1 spec) + public static final PropertyDescriptor PROP_STD_LICENSE_NOTICE = new PropertyDescriptor("standardLicenseHeader", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_HEADER_TEMPLATE = new PropertyDescriptor("standardLicenseHeaderTemplate", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_HEADER_HTML = new PropertyDescriptor("standardLicenseHeaderHtml", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_TEMPLATE_VERSION_1 = new PropertyDescriptor("licenseTemplate", SPDX_NAMESPACE); // old property name (pre 1.2 spec) + public static final PropertyDescriptor PROP_STD_LICENSE_TEMPLATE = new PropertyDescriptor("standardLicenseTemplate", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_OSI_APPROVED = new PropertyDescriptor("isOsiApproved", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_FSF_LIBRE = new PropertyDescriptor("isFsfLibre", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_STD_LICENSE_OSI_APPROVED_VERSION_1 = new PropertyDescriptor("licenseOsiApproved", SPDX_NAMESPACE); // old property name (pre 1.1 spec) + public static final PropertyDescriptor PROP_LICENSE_SET_MEMEBER = new PropertyDescriptor("member", SPDX_NAMESPACE); + public static final String TERM_LICENSE_NOASSERTION = PROP_VALUE_NOASSERTION.getName(); + public static final String TERM_LICENSE_NONE = PROP_VALUE_NONE.getName(); + public static final PropertyDescriptor PROP_LICENSE_EXCEPTION_ID = new PropertyDescriptor("licenseExceptionId", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXAMPLE = new PropertyDescriptor("example", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXCEPTION_TEXT = new PropertyDescriptor("licenseExceptionText", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXCEPTION_TEXT_HTML = new PropertyDescriptor("exceptionTextHtml", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXCEPTION_TEMPLATE = new PropertyDescriptor("licenseExceptionTemplate", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_EXCEPTION = new PropertyDescriptor("licenseException", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LIC_ID_DEPRECATED = new PropertyDescriptor("isDeprecatedLicenseId", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LIC_DEPRECATED_VERSION = new PropertyDescriptor("deprecatedVersion", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF = new PropertyDescriptor("crossRef", SPDX_NAMESPACE); // SPDX Listed License constants public static final String LISTED_LICENSE_URL = "https://spdx.org/licenses/"; @@ -271,35 +273,35 @@ public class SpdxConstants { public static final String LISTED_LICENSE_NAMESPACE_PREFIX = "http://spdx.org/licenses/"; // crossrefs details (crossRef) properties - public static final String PROP_CROSS_REF_IS_VALID = "isValid"; - public static final String PROP_CROSS_REF_WAYBACK_LINK = "isWayBackLink"; - public static final String PROP_CROSS_REF_MATCH = "match"; - public static final String PROP_CROSS_REF_URL = "url"; - public static final String PROP_CROSS_REF_IS_LIVE = "isLive"; - public static final String PROP_CROSS_REF_TIMESTAMP = "timestamp"; - public static final String PROP_CROSS_REF_ORDER = "order"; + public static final PropertyDescriptor PROP_CROSS_REF_IS_VALID = new PropertyDescriptor("isValid", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF_WAYBACK_LINK = new PropertyDescriptor("isWayBackLink", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF_MATCH = new PropertyDescriptor("match", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF_URL = new PropertyDescriptor("url", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF_IS_LIVE = new PropertyDescriptor("isLive", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF_TIMESTAMP = new PropertyDescriptor("timestamp", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_CROSS_REF_ORDER = new PropertyDescriptor("order", SPDX_NAMESPACE); // SpdxElement Properties - public static final String PROP_NAME = "name"; + public static final PropertyDescriptor PROP_NAME = new PropertyDescriptor("name", SPDX_NAMESPACE); // SPDX File Properties // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - public static final String PROP_FILE_NAME = "fileName"; - public static final String PROP_FILE_TYPE = "fileType"; - public static final String PROP_FILE_LICENSE = PROP_LICENSE_CONCLUDED; - public static final String PROP_FILE_COPYRIGHT = PROP_COPYRIGHT_TEXT; - public static final String PROP_FILE_CHECKSUM = "checksum"; - public static final String PROP_FILE_SEEN_LICENSE = "licenseInfoInFile"; - public static final String PROP_FILE_LIC_COMMENTS = PROP_LIC_COMMENTS; - public static final String PROP_FILE_ARTIFACTOF = "artifactOf"; - public static final String PROP_FILE_FILE_DEPENDENCY = "fileDependency"; - public static final String PROP_FILE_CONTRIBUTOR = "fileContributor"; - public static final String PROP_FILE_NOTICE = "noticeText"; + public static final PropertyDescriptor PROP_FILE_NAME = new PropertyDescriptor("fileName", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_TYPE = new PropertyDescriptor("fileType", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_LICENSE = PROP_LICENSE_CONCLUDED; + public static final PropertyDescriptor PROP_FILE_COPYRIGHT = PROP_COPYRIGHT_TEXT; + public static final PropertyDescriptor PROP_FILE_CHECKSUM = new PropertyDescriptor("checksum", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_SEEN_LICENSE = new PropertyDescriptor("licenseInfoInFile", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_LIC_COMMENTS = PROP_LIC_COMMENTS; + public static final PropertyDescriptor PROP_FILE_ARTIFACTOF = new PropertyDescriptor("artifactOf", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_FILE_DEPENDENCY = new PropertyDescriptor("fileDependency", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_CONTRIBUTOR = new PropertyDescriptor("fileContributor", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_FILE_NOTICE = new PropertyDescriptor("noticeText", SPDX_NAMESPACE); // SPDX Snippet Properties - public static final String PROP_SNIPPET_FROM_FILE = "snippetFromFile"; - public static final String PROP_SNIPPET_RANGE = "range"; - public static final String PROP_LICENSE_INFO_FROM_SNIPPETS = "licenseInfoInSnippet"; + public static final PropertyDescriptor PROP_SNIPPET_FROM_FILE = new PropertyDescriptor("snippetFromFile", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SNIPPET_RANGE = new PropertyDescriptor("range", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_LICENSE_INFO_FROM_SNIPPETS = new PropertyDescriptor("licenseInfoInSnippet", SPDX_NAMESPACE); // SPDX File Type Properties public static final String PROP_FILE_TYPE_SOURCE = "fileType_source"; @@ -313,32 +315,24 @@ public class SpdxConstants { public static final String FILE_TYPE_OTHER = "OTHER"; // SPDX Annotation Properties - public static final String PROP_ANNOTATOR = "annotator"; - public static final String PROP_ANNOTATION_DATE = "annotationDate"; - public static final String PROP_ANNOTATION_TYPE = "annotationType"; + public static final PropertyDescriptor PROP_ANNOTATOR = new PropertyDescriptor("annotator", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_ANNOTATION_DATE = new PropertyDescriptor("annotationDate", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_ANNOTATION_TYPE = new PropertyDescriptor("annotationType", SPDX_NAMESPACE); // SPDX Relationship Properties - public static final String PROP_RELATED_SPDX_ELEMENT = "relatedSpdxElement"; - public static final String PROP_RELATIONSHIP_TYPE = "relationshipType"; - public static final String PROP_SPDX_ELEMENTID = "spdxElementId"; + public static final PropertyDescriptor PROP_RELATED_SPDX_ELEMENT = new PropertyDescriptor("relatedSpdxElement", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_RELATIONSHIP_TYPE = new PropertyDescriptor("relationshipType", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_SPDX_ELEMENTID = new PropertyDescriptor("spdxElementId", SPDX_NAMESPACE); // ExternalDocumentRef properties - public static final String PROP_EXTERNAL_DOC_CHECKSUM = "checksum"; - public static final String PROP_EXTERNAL_SPDX_DOCUMENT = "spdxDocument"; - public static final String PROP_EXTERNAL_DOCUMENT_ID = "externalDocumentId"; + public static final PropertyDescriptor PROP_EXTERNAL_DOC_CHECKSUM = new PropertyDescriptor("checksum", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXTERNAL_SPDX_DOCUMENT = new PropertyDescriptor("spdxDocument", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_EXTERNAL_DOCUMENT_ID = new PropertyDescriptor("externalDocumentId", SPDX_NAMESPACE); // External Reference properties - public static final String PROP_REFERENCE_CATEGORY = "referenceCategory"; - public static final String PROP_REFERENCE_TYPE = "referenceType"; - public static final String PROP_REFERENCE_LOCATOR = "referenceLocator"; - - // SPDX Review Properties - // NOTE: These have all been deprecated as of SPDX 2.0 - // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - @Deprecated - public static final String PROP_REVIEW_REVIEWER = "reviewer"; - @Deprecated - public static final String PROP_REVIEW_DATE = "reviewDate"; + public static final PropertyDescriptor PROP_REFERENCE_CATEGORY = new PropertyDescriptor("referenceCategory", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_REFERENCE_TYPE = new PropertyDescriptor("referenceType", SPDX_NAMESPACE); + public static final PropertyDescriptor PROP_REFERENCE_LOCATOR = new PropertyDescriptor("referenceLocator", SPDX_NAMESPACE); // Date format - NOTE: This format does not handle milliseconds. Use Instant.parse for full ISO 8601 parsing public static final String SPDX_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; diff --git a/src/main/java/org/spdx/library/model/ModelCollection.java b/src/main/java/org/spdx/library/model/ModelCollection.java index 774bc9aba..ca3115700 100644 --- a/src/main/java/org/spdx/library/model/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/ModelCollection.java @@ -37,6 +37,7 @@ import org.spdx.library.model.license.SpdxNoAssertionLicense; import org.spdx.library.model.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; /** * Collection of elements stored in a ModelStore @@ -49,7 +50,7 @@ public class ModelCollection implements Collection { private IModelStore modelStore; private String documentUri; private String id; - private String propertyName; + private PropertyDescriptor propertyDescriptor; private ModelCopyManager copyManager; private Class type; private boolean licensePrimitiveAssignable; // If true, NONE and NOASSERTION should be converted to NoneLicense and NoAssertionLicense @@ -78,11 +79,12 @@ public Object next() { * @param modelStore Storage for the model collection * @param documentUri SPDX Document URI for a document associated with this model collection * @param id ID for this collection - must be unique within the SPDX document + * @param propertyDescriptor descriptor for the property use for the model collections * @param copyManager if non-null, use this to copy properties when referenced outside this model store * @param type The class of the elements to be stored in the collection if none, null if not known * @throws InvalidSPDXAnalysisException */ - public ModelCollection(IModelStore modelStore, String documentUri, String id, String propertyName, + public ModelCollection(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { Objects.requireNonNull(modelStore, "Model store can not be null"); @@ -91,8 +93,8 @@ public ModelCollection(IModelStore modelStore, String documentUri, String id, St this.documentUri = documentUri; Objects.requireNonNull(id, "ID can not be null"); this.id = id; - Objects.requireNonNull(propertyName, "Property name can not be null"); - this.propertyName = propertyName; + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); + this.propertyDescriptor = propertyDescriptor; this.copyManager = copyManager; if (!modelStore.exists(documentUri, id)) { throw new SpdxIdNotFoundException(id+" does not exist in document "+documentUri); @@ -100,8 +102,8 @@ public ModelCollection(IModelStore modelStore, String documentUri, String id, St if (Objects.nonNull(type)) { this.type = type; licensePrimitiveAssignable = type.isAssignableFrom(SpdxNoneLicense.class); - if (!modelStore.isCollectionMembersAssignableTo(documentUri, id, propertyName, type)) { - throw new SpdxInvalidTypeException("Incompatible type for property "+propertyName+": "+type.toString()); + if (!modelStore.isCollectionMembersAssignableTo(documentUri, id, propertyDescriptor, type)) { + throw new SpdxInvalidTypeException("Incompatible type for property "+propertyDescriptor+": "+type.toString()); } } else { licensePrimitiveAssignable = false; @@ -111,7 +113,7 @@ public ModelCollection(IModelStore modelStore, String documentUri, String id, St @Override public int size() { try { - return this.modelStore.collectionSize(this.documentUri, this.id, this.propertyName); + return this.modelStore.collectionSize(this.documentUri, this.id, this.propertyDescriptor); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -120,7 +122,7 @@ public int size() { @Override public boolean isEmpty() { try { - return this.modelStore.collectionSize(this.documentUri, this.id, this.propertyName) == 0; + return this.modelStore.collectionSize(this.documentUri, this.id, this.propertyDescriptor) == 0; } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -135,7 +137,7 @@ public boolean contains(Object o) { } catch (SpdxObjectNotInStoreException e1) { return false; // The exception is due to the model object not being in the store } - return this.modelStore.collectionContains(this.documentUri, this.id, this.propertyName, storedObject); + return this.modelStore.collectionContains(this.documentUri, this.id, this.propertyDescriptor, storedObject); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -182,7 +184,7 @@ public List toImmutableList() { @Override public Iterator iterator() { try { - return new ModelCollectionIterator(modelStore.listValues(documentUri, id, propertyName)); + return new ModelCollectionIterator(modelStore.listValues(documentUri, id, propertyDescriptor)); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -201,7 +203,7 @@ public AT[] toArray(AT[] a) { @Override public boolean add(Object element) { try { - return modelStore.addValueToCollection(documentUri, id, propertyName, + return modelStore.addValueToCollection(documentUri, id, propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, copyManager)); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); @@ -211,7 +213,7 @@ public boolean add(Object element) { @Override public boolean remove(Object element) { try { - return modelStore.removeValueFromCollection(documentUri, id, propertyName, + return modelStore.removeValueFromCollection(documentUri, id, propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, null)); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); @@ -264,7 +266,7 @@ public boolean retainAll(Collection c) { @Override public void clear() { try { - modelStore.clearValueCollection(documentUri, id, propertyName); + modelStore.clearValueCollection(documentUri, id, propertyDescriptor); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -292,9 +294,9 @@ public String getId() { } /** - * @return the propertyName + * @return the propertyDescriptor */ - public String getPropertyName() { - return propertyName; + public PropertyDescriptor getPropertyDescriptor() { + return propertyDescriptor; } } diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 527b6540c..61872574a 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -55,6 +55,7 @@ import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.ModelUpdate; +import org.spdx.storage.PropertyDescriptor; /** * @author Gary O'Neall @@ -70,7 +71,7 @@ * The Document URI uniquely identifies the document containing the model object. * * The concrete classes are expected to implements getters for the model class properties which translate - * into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property name + * into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property descriptor * is passed as a parameter. * * There are 2 methods of setting values: @@ -115,13 +116,13 @@ enum NotEquivalent { DIFFERENT_CLASS, MISSING_PROPERTY, PROPERTY_NOT_EQUIVALENT, COMPARE_PROPERTY_MISSING}; static class NotEquivalentReason { NotEquivalent reason; - String property = null; + PropertyDescriptor property = null; public NotEquivalentReason(NotEquivalent reason) { this.reason = reason; } - public NotEquivalentReason(NotEquivalent reason, String property) { + public NotEquivalentReason(NotEquivalent reason, PropertyDescriptor property) { this(reason); this.property = property; } @@ -143,14 +144,14 @@ public void setReason(NotEquivalent reason) { /** * @return the property */ - public String getProperty() { + public PropertyDescriptor getProperty() { return property; } /** * @param property the property to set */ - public void setProperty(String property) { + public void setProperty(PropertyDescriptor property) { this.property = property; } } @@ -313,20 +314,20 @@ public void leaveCriticalSection(IModelStoreLock lock) { //The following methods are to manage the properties associated with the model object /** - * @return all names of property values currently associated with this object + * @return all names of property descriptors currently associated with this object * @throws InvalidSPDXAnalysisException */ - public List getPropertyValueNames() throws InvalidSPDXAnalysisException { - return modelStore.getPropertyValueNames(documentUri, id); + public List getPropertyValueDescriptors() throws InvalidSPDXAnalysisException { + return modelStore.getPropertyValueDescriptors(documentUri, id); } /** * Get an object value for a property - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @return value associated with a property */ - protected Optional getObjectPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(modelStore, documentUri, id, propertyName, copyManager); + protected Optional getObjectPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(modelStore, documentUri, id, propertyDescriptor, copyManager); if (retval.isPresent() && retval.get() instanceof ModelObject && !strict) { ((ModelObject)retval.get()).setStrict(strict); } @@ -338,22 +339,22 @@ protected Optional getObjectPropertyValue(String propertyName) throws In * @param stModelStore * @param stDocumentUri * @param stId - * @param propertyName + * @param propertyDescriptor * @param copyManager if non null, any ModelObject property value not stored in the stModelStore under the stDocumentUri will be copied to make it available * @return value associated with a property * @throws InvalidSPDXAnalysisException */ protected static Optional getObjectPropertyValue(IModelStore stModelStore, String stDocumentUri, - String stId, String propertyName, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + String stId, PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { IModelStoreLock lock = stModelStore.enterCriticalSection(stDocumentUri, false); // NOTE: we use a write lock since the ModelStorageClassConverter may end up creating objects in the store try { if (!stModelStore.exists(stDocumentUri, stId)) { return Optional.empty(); - } else if (stModelStore.isCollectionProperty(stDocumentUri, stId, propertyName)) { - return Optional.of(new ModelCollection<>(stModelStore, stDocumentUri, stId, propertyName, copyManager, null)); + } else if (stModelStore.isCollectionProperty(stDocumentUri, stId, propertyDescriptor)) { + return Optional.of(new ModelCollection<>(stModelStore, stDocumentUri, stId, propertyDescriptor, copyManager, null)); } else { - return ModelStorageClassConverter.optionalStoredObjectToModelObject(stModelStore.getValue(stDocumentUri, stId, propertyName), + return ModelStorageClassConverter.optionalStoredObjectToModelObject(stModelStore.getValue(stDocumentUri, stId, propertyDescriptor), stDocumentUri, stModelStore, copyManager); } } finally { @@ -362,64 +363,64 @@ protected static Optional getObjectPropertyValue(IModelStore stModelStor } /** - * Set a property value for a property name, creating the property if necessary + * Set a property value for a property descriptor, creating the property if necessary * @param stModelStore Model store for the properties * @param stDocumentUri Unique document URI * @param stId ID of the item to associate the property with - * @param propertyName Name of the property associated with this object + * @param propertyDescriptor Descriptor for the property associated with this object * @param value Value to associate with the property * @param copyManager if non null, any ModelObject property value not stored in the stModelStore under the stDocumentUri will be copied to make it available * @throws InvalidSPDXAnalysisException */ protected static void setPropertyValue(IModelStore stModelStore, String stDocumentUri, - String stId, String propertyName, @Nullable Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + String stId, PropertyDescriptor propertyDescriptor, @Nullable Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(stModelStore, "Model Store can not be null"); Objects.requireNonNull(stDocumentUri, "Document Uri can not be null"); Objects.requireNonNull(stId, "ID can not be null"); - Objects.requireNonNull(propertyName, "Property name can not be null"); + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); if (value == null) { // we just remove the value - removeProperty(stModelStore, stDocumentUri, stId, propertyName); + removeProperty(stModelStore, stDocumentUri, stId, propertyDescriptor); } else if (value instanceof Collection) { - replacePropertyValueCollection(stModelStore, stDocumentUri, stId, propertyName, (Collection)value, copyManager); + replacePropertyValueCollection(stModelStore, stDocumentUri, stId, propertyDescriptor, (Collection)value, copyManager); } else { - stModelStore.setValue(stDocumentUri, stId, propertyName, ModelStorageClassConverter.modelObjectToStoredObject( + stModelStore.setValue(stDocumentUri, stId, propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject( value, stDocumentUri, stModelStore, copyManager)); } } /** - * Set a property value for a property name, creating the property if necessary - * @param propertyName Name of the property associated with this object + * Set a property value for a property descriptor, creating the property if necessary + * @param propertyDescriptor Descriptor for the property associated with this object * @param value Value to associate with the property * @throws InvalidSPDXAnalysisException */ - protected void setPropertyValue(String propertyName, @Nullable Object value) throws InvalidSPDXAnalysisException { + protected void setPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Object value) throws InvalidSPDXAnalysisException { if (this instanceof IndividualUriValue) { throw new InvalidSPDXAnalysisException("Can not set a property for the literal value "+((IndividualUriValue)this).getIndividualURI()); } - setPropertyValue(this.modelStore, this.documentUri, this.id, propertyName, value, copyManager); + setPropertyValue(this.modelStore, this.documentUri, this.id, propertyDescriptor, value, copyManager); } /** - * Create an update when, when applied by the ModelStore, sets a property value for a property name, creating the property if necessary - * @param propertyName Name of the property associated with this object + * Create an update when, when applied by the ModelStore, sets a property value for a property descriptor, creating the property if necessary + * @param propertyDescriptor Descriptor for the property associated with this object * @param value Value to associate with the property * @return an update which can be applied by invoking the apply method */ - protected ModelUpdate updatePropertyValue(String propertyName, Object value) { + protected ModelUpdate updatePropertyValue(PropertyDescriptor propertyDescriptor, Object value) { return () ->{ - setPropertyValue(this.modelStore, this.documentUri, this.id, propertyName, value, copyManager); + setPropertyValue(this.modelStore, this.documentUri, this.id, propertyDescriptor, value, copyManager); }; } /** - * @param propertyName Name of a property + * @param propertyDescriptor Descriptor for a property * @return the Optional String value associated with a property, null if no value is present * @throws SpdxInvalidTypeException */ - protected Optional getStringPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyName); + protected Optional getStringPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); if (result.isPresent()) { if (result.get() instanceof String) { return Optional.of((String)result.get()); @@ -434,8 +435,8 @@ protected Optional getStringPropertyValue(String propertyName) throws In throw new SpdxInvalidTypeException("Can not convert a URI value to String: "+uri); } } else { - logger.error("Property "+propertyName+" is not of type String"); - throw new SpdxInvalidTypeException("Property "+propertyName+" is not of type String"); + logger.error("Property "+propertyDescriptor+" is not of type String"); + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type String"); } } else { return Optional.empty(); @@ -443,16 +444,16 @@ protected Optional getStringPropertyValue(String propertyName) throws In } /** - * @param propertyName Name of a property + * @param propertyDescriptor Descriptor for a property * @return the Optional Integer value associated with a property, null if no value is present * @throws InvalidSPDXAnalysisException */ - protected Optional getIntegerPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyName); + protected Optional getIntegerPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); Optional retval; if (result.isPresent()) { if (!(result.get() instanceof Integer)) { - throw new SpdxInvalidTypeException("Property "+propertyName+" is not of type Integer"); + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Integer"); } retval = Optional.of((Integer)result.get()); } else { @@ -461,9 +462,14 @@ protected Optional getIntegerPropertyValue(String propertyName) throws return retval; } + /** + * @param propertyDescriptor descriptor for the property + * @return an enumeration value for the property + * @throws InvalidSPDXAnalysisException + */ @SuppressWarnings("unchecked") - protected Optional> getEnumPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyName); + protected Optional> getEnumPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); if (!result.isPresent()) { return Optional.empty(); } @@ -471,7 +477,7 @@ protected Optional> getEnumPropertyValue(String propertyName) throws Inv return (Optional>)(Optional)result; } if (!(result.get() instanceof IndividualUriValue)) { - throw new SpdxInvalidTypeException("Property "+propertyName+" is not of type Individual Value or enum"); + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Individual Value or enum"); } Enum retval = SpdxEnumFactory.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); if (Objects.isNull(retval)) { @@ -483,12 +489,12 @@ protected Optional> getEnumPropertyValue(String propertyName) throws Inv } /** - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @return the Optional Boolean value for a property * @throws SpdxInvalidTypeException */ - protected Optional getBooleanPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyName); + protected Optional getBooleanPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); if (result.isPresent()) { if (result.get() instanceof Boolean) { return Optional.of((Boolean)result.get()); @@ -500,10 +506,10 @@ protected Optional getBooleanPropertyValue(String propertyName) throws } else if ("false".equals(sResult)) { return Optional.of(Boolean.valueOf(false)); } else { - throw new SpdxInvalidTypeException("Property "+propertyName+" is not of type Boolean"); + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); } } else { - throw new SpdxInvalidTypeException("Property "+propertyName+" is not of type Boolean"); + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); } } else { return Optional.empty(); @@ -512,13 +518,13 @@ protected Optional getBooleanPropertyValue(String propertyName) throws /** * Converts property values to an AnyLicenseInfo if possible - if NONE or NOASSERTION URI value, convert to the appropriate license - * @param propertyName - * @return AnyLicenseInfo + * @param propertyDescriptor descriptor for the property + * @return AnyLicenseInfo license info for the property * @throws InvalidSPDXAnalysisException */ @SuppressWarnings("unchecked") - protected Optional getAnyLicenseInfoPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyName); + protected Optional getAnyLicenseInfoPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); if (!result.isPresent()) { return Optional.empty(); } else if (result.get() instanceof AnyLicenseInfo) { @@ -541,13 +547,13 @@ protected Optional getAnyLicenseInfoPropertyValue(String propert /** * Converts property values to an SpdxElement if possible - if NONE or NOASSERTION URI value, convert to the appropriate SpdxElement - * @param propertyName name of the property + * @param propertyDescriptor Descriptor for the property * @return SpdxElement stored * @throws InvalidSPDXAnalysisException */ @SuppressWarnings("unchecked") - protected Optional getElementPropertyValue(String propertyName) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyName); + protected Optional getElementPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); if (!result.isPresent()) { return Optional.empty(); } else if (result.get() instanceof SpdxElement) { @@ -573,30 +579,31 @@ protected Optional getElementPropertyValue(String propertyName) thr * @param stModelStore Model store for the properties * @param stDocumentUri Unique document URI * @param stId ID of the item to associate the property with - * @param propertyName Name of the property associated with this object to be removed + * @param propertyDescriptor Descriptor for the property associated with this object to be removed * @throws InvalidSPDXAnalysisException */ - protected static void removeProperty(IModelStore stModelStore, String stDocumentUri, String stId, String propertyName) throws InvalidSPDXAnalysisException { - stModelStore.removeProperty(stDocumentUri, stId, propertyName); + protected static void removeProperty(IModelStore stModelStore, String stDocumentUri, + String stId, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + stModelStore.removeProperty(stDocumentUri, stId, propertyDescriptor); } /** * Removes a property and its value from the model store if it exists - * @param propertyName Name of the property associated with this object to be removed + * @param propertyDescriptor Descriptor for the property associated with this object to be removed * @throws InvalidSPDXAnalysisException */ - protected void removeProperty(String propertyName) throws InvalidSPDXAnalysisException { - removeProperty(modelStore, documentUri, id, propertyName); + protected void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + removeProperty(modelStore, documentUri, id, propertyDescriptor); } /** * Create an update when, when applied by the ModelStore, removes a property and its value from the model store if it exists - * @param propertyName Name of the property associated with this object to be removed + * @param propertyDescriptor Descriptor for the property associated with this object to be removed * @return an update which can be applied by invoking the apply method */ - protected ModelUpdate updateRemoveProperty(String propertyName) { + protected ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor) { return () -> { - removeProperty(modelStore, documentUri, id, propertyName); + removeProperty(modelStore, documentUri, id, propertyDescriptor); }; } @@ -606,29 +613,30 @@ protected ModelUpdate updateRemoveProperty(String propertyName) { * @param stModelStore Model store for the properties * @param stDocumentUri Unique document URI * @param stId ID of the item to associate the property with - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @throws InvalidSPDXAnalysisException */ - protected static void clearValueCollection(IModelStore stModelStore, String stDocumentUri, String stId, String propertyName) throws InvalidSPDXAnalysisException { - stModelStore.clearValueCollection(stDocumentUri, stId, propertyName); + protected static void clearValueCollection(IModelStore stModelStore, String stDocumentUri, + String stId, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + stModelStore.clearValueCollection(stDocumentUri, stId, propertyDescriptor); } /** * Clears a collection of values associated with a property - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property */ - protected void clearValueCollection(String propertyName) throws InvalidSPDXAnalysisException { - clearValueCollection(modelStore, documentUri, id, propertyName); + protected void clearValueCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + clearValueCollection(modelStore, documentUri, id, propertyDescriptor); } /** * Create an update when, when applied by the ModelStore, clears a collection of values associated with a property - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @return an update which can be applied by invoking the apply method */ - protected ModelUpdate updateClearValueCollection(String propertyName) { + protected ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDescriptor) { return () ->{ - clearValueCollection(modelStore, documentUri, id, propertyName); + clearValueCollection(modelStore, documentUri, id, propertyDescriptor); }; } @@ -640,39 +648,39 @@ protected ModelUpdate updateClearValueCollection(String propertyName) { * @param stModelStore Model store for the properties * @param stDocumentUri Unique document URI * @param stId ID of the item to associate the property with - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @param value to add * @param copyManager * @throws InvalidSPDXAnalysisException */ protected static void addValueToCollection(IModelStore stModelStore, String stDocumentUri, String stId, - String propertyName, Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + PropertyDescriptor propertyDescriptor, Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(value, "Value can not be null"); - stModelStore.addValueToCollection(stDocumentUri, stId, propertyName, + stModelStore.addValueToCollection(stDocumentUri, stId, propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(value, stDocumentUri, stModelStore, copyManager)); } /** * Add a value to a collection of values associated with a property. If a value is a ModelObject and does not * belong to the document, it will be copied into the object store - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @param value to add * @throws InvalidSPDXAnalysisException */ - protected void addPropertyValueToCollection(String propertyName, Object value) throws InvalidSPDXAnalysisException { - addValueToCollection(modelStore, documentUri, id, propertyName, value, copyManager); + protected void addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + addValueToCollection(modelStore, documentUri, id, propertyDescriptor, value, copyManager); } /** * Create an update when, when applied, adds a value to a collection of values associated with a property. If a value is a ModelObject and does not * belong to the document, it will be copied into the object store - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @param value to add * @return an update which can be applied by invoking the apply method */ - protected ModelUpdate updateAddPropertyValueToCollection(String propertyName, Object value) { + protected ModelUpdate updateAddPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) { return () ->{ - addValueToCollection(modelStore, documentUri, id, propertyName, value, copyManager); + addValueToCollection(modelStore, documentUri, id, propertyDescriptor, value, copyManager); }; } @@ -682,16 +690,16 @@ protected ModelUpdate updateAddPropertyValueToCollection(String propertyName, Ob * @param stModelStore Model store for the properties * @param stDocumentUri Unique document URI * @param stId ID of the item to associate the property with - * @param propertyName name of the property + * @param propertyDescriptor Descriptor for the property * @param values collection of new properties * @param copyManager if non-null, any ModelObject property value not stored in the stModelStore under the stDocumentUri will be copied to make it available * @throws InvalidSPDXAnalysisException */ protected static void replacePropertyValueCollection(IModelStore stModelStore, String stDocumentUri, String stId, - String propertyName, Collection values, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - clearValueCollection(stModelStore, stDocumentUri, stId, propertyName); + PropertyDescriptor propertyDescriptor, Collection values, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + clearValueCollection(stModelStore, stDocumentUri, stId, propertyDescriptor); for (Object value:values) { - addValueToCollection(stModelStore, stDocumentUri, stId, propertyName, value, copyManager); + addValueToCollection(stModelStore, stDocumentUri, stId, propertyDescriptor, value, copyManager); } } @@ -700,69 +708,69 @@ protected static void replacePropertyValueCollection(IModelStore stModelStore, S * @param stModelStore Model store for the properties * @param stDocumentUri Unique document URI * @param stId ID of the item to associate the property with - * @param propertyName name of the property + * @param propertyDescriptor descriptor for the property * @param value Value to be removed * @throws InvalidSPDXAnalysisException */ protected static void removePropertyValueFromCollection(IModelStore stModelStore, String stDocumentUri, String stId, - String propertyName, Object value) throws InvalidSPDXAnalysisException { - stModelStore.removeValueFromCollection(stDocumentUri, stId, propertyName, + PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + stModelStore.removeValueFromCollection(stDocumentUri, stId, propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(value, stDocumentUri, stModelStore, null)); } /** * Remove a property value from a collection - * @param propertyName name of the property + * @param propertyDescriptor Descriptor for the property * @param value Value to be removed * @throws InvalidSPDXAnalysisException */ - protected void removePropertyValueFromCollection(String propertyName, Object value) throws InvalidSPDXAnalysisException { - removePropertyValueFromCollection(modelStore, documentUri, id, propertyName, value); + protected void removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + removePropertyValueFromCollection(modelStore, documentUri, id, propertyDescriptor, value); } /** * Create an update when, when applied, removes a property value from a collection - * @param propertyName name of the property + * @param propertyDescriptor descriptor for the property * @param value Value to be removed * @return an update which can be applied by invoking the apply method */ - protected ModelUpdate updateRemovePropertyValueFromCollection(String propertyName, Object value) { + protected ModelUpdate updateRemovePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) { return () -> { - removePropertyValueFromCollection(modelStore, documentUri, id, propertyName, value); + removePropertyValueFromCollection(modelStore, documentUri, id, propertyDescriptor, value); }; } /** - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @return Set of values associated with a property */ - protected ModelSet getObjectPropertyValueSet(String propertyName, Class type) throws InvalidSPDXAnalysisException { - return new ModelSet(this.modelStore, this.documentUri, this.id, propertyName, this.copyManager, type); + protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { + return new ModelSet(this.modelStore, this.documentUri, this.id, propertyDescriptor, this.copyManager, type); } /** - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @return Collection of values associated with a property */ - protected ModelCollection getObjectPropertyValueCollection(String propertyName, Class type) throws InvalidSPDXAnalysisException { - return new ModelCollection(this.modelStore, this.documentUri, this.id, propertyName, this.copyManager, type); + protected ModelCollection getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { + return new ModelCollection(this.modelStore, this.documentUri, this.id, propertyDescriptor, this.copyManager, type); } /** - * @param propertyName Name of property + * @param propertyDescriptor Descriptor for property * @return Collection of Strings associated with the property * @throws SpdxInvalidTypeException */ @SuppressWarnings("unchecked") - protected Collection getStringCollection(String propertyName) throws InvalidSPDXAnalysisException { - if (!isCollectionMembersAssignableTo(propertyName, String.class)) { - throw new SpdxInvalidTypeException("Property "+propertyName+" does not contain a collection of Strings"); + protected Collection getStringCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + if (!isCollectionMembersAssignableTo(propertyDescriptor, String.class)) { + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" does not contain a collection of Strings"); } - return (Collection)(Collection)getObjectPropertyValueSet(propertyName, String.class); + return (Collection)(Collection)getObjectPropertyValueSet(propertyDescriptor, String.class); } - protected boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) throws InvalidSPDXAnalysisException { - return modelStore.isCollectionMembersAssignableTo(this.documentUri, this.id, propertyName, + protected boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { + return modelStore.isCollectionMembersAssignableTo(this.documentUri, this.id, propertyDescriptor, ModelStorageClassConverter.modelClassToStoredClass(clazz)); } @@ -784,48 +792,48 @@ public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) th lastNotEquivalentReason = new NotEquivalentReason(NotEquivalent.DIFFERENT_CLASS); return false; } - List propertyValueNames = getPropertyValueNames(); - List comparePropertyValueNames = new ArrayList(compare.getPropertyValueNames()); // create a copy since we're going to modify it - for (String propertyName:propertyValueNames) { - if (ignoreRelatedElements && isRelatedElement(propertyName)) { + List propertyValueDescriptors = getPropertyValueDescriptors(); + List comparePropertyValueDescriptors = new ArrayList(compare.getPropertyValueDescriptors()); // create a copy since we're going to modify it + for (PropertyDescriptor propertyDescriptor:propertyValueDescriptors) { + if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { continue; } - if (comparePropertyValueNames.contains(propertyName)) { - if (!propertyValuesEquivalent(propertyName, this.getObjectPropertyValue(propertyName), - compare.getObjectPropertyValue(propertyName), ignoreRelatedElements)) { + if (comparePropertyValueDescriptors.contains(propertyDescriptor)) { + if (!propertyValuesEquivalent(propertyDescriptor, this.getObjectPropertyValue(propertyDescriptor), + compare.getObjectPropertyValue(propertyDescriptor), ignoreRelatedElements)) { lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.PROPERTY_NOT_EQUIVALENT, propertyName); + NotEquivalent.PROPERTY_NOT_EQUIVALENT, propertyDescriptor); return false; } - comparePropertyValueNames.remove(propertyName); + comparePropertyValueDescriptors.remove(propertyDescriptor); } else { // No property value - Optional propertyValueOptional = this.getObjectPropertyValue(propertyName); + Optional propertyValueOptional = this.getObjectPropertyValue(propertyDescriptor); if (propertyValueOptional.isPresent()) { Object propertyValue = propertyValueOptional.get(); - if (isEquivalentToNull(propertyValue, propertyName)) { + if (isEquivalentToNull(propertyValue, propertyDescriptor)) { continue; } lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.COMPARE_PROPERTY_MISSING, propertyName); + NotEquivalent.COMPARE_PROPERTY_MISSING, propertyDescriptor); return false; } } } - for (String propertyName:comparePropertyValueNames) { // check any remaining property values - if (ignoreRelatedElements && isRelatedElement(propertyName)) { + for (PropertyDescriptor propertyDescriptor:comparePropertyValueDescriptors) { // check any remaining property values + if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { continue; } - Optional comparePropertyValueOptional = compare.getObjectPropertyValue(propertyName); + Optional comparePropertyValueOptional = compare.getObjectPropertyValue(propertyDescriptor); if (!comparePropertyValueOptional.isPresent()) { continue; } Object comparePropertyValue = comparePropertyValueOptional.get(); - if (isEquivalentToNull(comparePropertyValue, propertyName)) { + if (isEquivalentToNull(comparePropertyValue, propertyDescriptor)) { continue; } lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.MISSING_PROPERTY, propertyName); + NotEquivalent.MISSING_PROPERTY, propertyDescriptor); return false; } return true; @@ -833,20 +841,20 @@ public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) th // Some values are treated like null in comparisons - in particular empty model collections and // "no assertion" values and a filesAnalyzed filed with a value of true - private boolean isEquivalentToNull(Object propertyValue, String propertyName) { + private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor propertyDescriptor) { if (propertyValue instanceof ModelCollection) { return ((ModelCollection) propertyValue).size() == 0; } else if (isNoAssertion(propertyValue)) { return true; - } else if (SpdxConstants.PROP_PACKAGE_FILES_ANALYZED.equals(propertyName)) { + } else if (SpdxConstants.PROP_PACKAGE_FILES_ANALYZED.equals(propertyDescriptor.getName())) { return propertyValue instanceof Boolean && (Boolean)(propertyValue); } else { return false; } } - private boolean isRelatedElement(String propertyName) { - return SpdxConstants.PROP_RELATED_SPDX_ELEMENT.equals(propertyName); + private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { + return SpdxConstants.PROP_RELATED_SPDX_ELEMENT.equals(propertyDescriptor.getName()); } private boolean isEmptyModelCollection(Object value) { @@ -860,14 +868,14 @@ private boolean isNoAssertion(Object propertyValue) { } /** - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @param valueA value to compare * @param valueB value to compare * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion * @return true if the property values are equivalent * @throws InvalidSPDXAnalysisException */ - private boolean propertyValuesEquivalent(String propertyName, Optional valueA, + private boolean propertyValuesEquivalent(PropertyDescriptor propertyDescriptor, Optional valueA, Optional valueB, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { if (!valueA.isPresent()) { if (valueB.isPresent()) { @@ -892,7 +900,7 @@ private boolean propertyValuesEquivalent(String propertyName, Optional v // Note: we must check the IndividualValue before the ModelObject types since the IndividualValue takes precedence } else if (valueA.get() instanceof ModelObject && valueB.get() instanceof ModelObject) { if (!((ModelObject)valueA.get()).equivalent(((ModelObject)valueB.get()), - isRelatedElement(propertyName) ? true : ignoreRelatedElements)) { + isRelatedElement(propertyDescriptor) ? true : ignoreRelatedElements)) { return false; } @@ -1231,7 +1239,8 @@ public ExternalDocumentRef createExternalDocumentRef(String externalDocumentId, // Need to add this to the list of document URI's ModelObject.addValueToCollection(getModelStore(), getDocumentUri(), SpdxConstants.SPDX_DOCUMENT_ID, - SpdxConstants.PROP_SPDX_EXTERNAL_DOC_REF, retval, copyManager); + SpdxConstants.PROP_SPDX_EXTERNAL_DOC_REF, + retval, copyManager); return retval; } } finally { diff --git a/src/main/java/org/spdx/library/model/ModelSet.java b/src/main/java/org/spdx/library/model/ModelSet.java index 7a7c62703..0b032f5f7 100644 --- a/src/main/java/org/spdx/library/model/ModelSet.java +++ b/src/main/java/org/spdx/library/model/ModelSet.java @@ -28,6 +28,7 @@ import org.spdx.library.ModelCopyManager; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; +import org.spdx.storage.PropertyDescriptor; /** * A ModelCollection implemented as a set where all items in the collection are unique based @@ -44,14 +45,14 @@ public class ModelSet extends ModelCollection { * @param modelStore * @param documentUri * @param id - * @param propertyName + * @param propertyDescriptor * @param copyManager * @param type * @throws InvalidSPDXAnalysisException */ - public ModelSet(IModelStore modelStore, String documentUri, String id, String propertyName, + public ModelSet(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, propertyName, copyManager, type); + super(modelStore, documentUri, id, propertyDescriptor, copyManager, type); } @Override diff --git a/src/main/java/org/spdx/library/model/SpdxDocument.java b/src/main/java/org/spdx/library/model/SpdxDocument.java index 757a3b9ea..59a52a5e1 100644 --- a/src/main/java/org/spdx/library/model/SpdxDocument.java +++ b/src/main/java/org/spdx/library/model/SpdxDocument.java @@ -37,6 +37,7 @@ import org.spdx.library.model.license.SpdxListedLicense; import org.spdx.library.model.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; /** * An SpdxDocument is a summary of the contents, provenance, ownership and licensing @@ -82,7 +83,7 @@ public String getType() { } @Override - protected String getNamePropertyName() { + protected PropertyDescriptor getNamePropertyDescriptor() { return SpdxConstants.PROP_NAME; } diff --git a/src/main/java/org/spdx/library/model/SpdxElement.java b/src/main/java/org/spdx/library/model/SpdxElement.java index 8a914994d..0938534d0 100644 --- a/src/main/java/org/spdx/library/model/SpdxElement.java +++ b/src/main/java/org/spdx/library/model/SpdxElement.java @@ -33,6 +33,7 @@ import org.spdx.library.SpdxVerificationHelper; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.PropertyDescriptor; /** * An SpdxElement is any thing described in SPDX, either a document or an SpdxItem. @@ -263,7 +264,7 @@ public void setComment(String comment) throws InvalidSPDXAnalysisException { /** * @return the property name used for the Name property. Override this function if using a subproperty of SPDX Name */ - protected String getNamePropertyName() { + protected PropertyDescriptor getNamePropertyDescriptor() { return SpdxConstants.PROP_NAME; } @@ -271,7 +272,7 @@ protected String getNamePropertyName() { * @return the name */ public Optional getName() throws InvalidSPDXAnalysisException { - return this.getStringPropertyValue(getNamePropertyName()); + return this.getStringPropertyValue(getNamePropertyDescriptor()); } /** @@ -281,7 +282,7 @@ public Optional getName() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public SpdxElement setName(String name) throws InvalidSPDXAnalysisException { - this.setPropertyValue(getNamePropertyName(), name); + this.setPropertyValue(getNamePropertyDescriptor(), name); return this; } } diff --git a/src/main/java/org/spdx/library/model/SpdxFile.java b/src/main/java/org/spdx/library/model/SpdxFile.java index 0d74129d2..a3c6a0b22 100644 --- a/src/main/java/org/spdx/library/model/SpdxFile.java +++ b/src/main/java/org/spdx/library/model/SpdxFile.java @@ -38,6 +38,7 @@ import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.PropertyDescriptor; /** * A File represents a named sequence of information @@ -168,12 +169,12 @@ public SpdxFile setLicenseComments(String licenseComments) throws InvalidSPDXAna } @Override - protected String getLicenseInfoFromFilesPropertyName() { + protected PropertyDescriptor getLicenseInfoFromFilesPropertyName() { return SpdxConstants.PROP_FILE_SEEN_LICENSE; } @Override - protected String getNamePropertyName() { + protected PropertyDescriptor getNamePropertyDescriptor() { return SpdxConstants.PROP_FILE_NAME; } diff --git a/src/main/java/org/spdx/library/model/SpdxItem.java b/src/main/java/org/spdx/library/model/SpdxItem.java index 8a1576986..e69e71fbc 100644 --- a/src/main/java/org/spdx/library/model/SpdxItem.java +++ b/src/main/java/org/spdx/library/model/SpdxItem.java @@ -31,6 +31,7 @@ import org.spdx.library.model.license.SpdxNoAssertionLicense; import org.spdx.library.model.license.AnyLicenseInfo; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; /** * An SpdxItem is a potentially copyrightable work. @@ -70,7 +71,7 @@ public SpdxItem(IModelStore modelStore, String documentUri, String id, /** * @return Property name for licenseInfoFromFiles. Override if using a subproperty of "licenseDeclared". */ - protected String getLicenseInfoFromFilesPropertyName() { + protected PropertyDescriptor getLicenseInfoFromFilesPropertyName() { return SpdxConstants.PROP_PACKAGE_LICENSE_INFO_FROM_FILES; } diff --git a/src/main/java/org/spdx/library/model/SpdxPackage.java b/src/main/java/org/spdx/library/model/SpdxPackage.java index b44b5dbaa..1796a2800 100644 --- a/src/main/java/org/spdx/library/model/SpdxPackage.java +++ b/src/main/java/org/spdx/library/model/SpdxPackage.java @@ -42,6 +42,7 @@ import org.spdx.library.model.license.WithExceptionOperator; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; +import org.spdx.storage.PropertyDescriptor; /** * A Package represents a collection of software files that are @@ -129,7 +130,7 @@ public String getType() { } @Override - protected String getNamePropertyName() { + protected PropertyDescriptor getNamePropertyDescriptor() { return SpdxConstants.PROP_NAME; } diff --git a/src/main/java/org/spdx/library/model/SpdxSnippet.java b/src/main/java/org/spdx/library/model/SpdxSnippet.java index ba74d0e33..76bccc691 100644 --- a/src/main/java/org/spdx/library/model/SpdxSnippet.java +++ b/src/main/java/org/spdx/library/model/SpdxSnippet.java @@ -38,6 +38,7 @@ import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.PropertyDescriptor; /** * Snippets can optionally be used when a file is known to have some content that has been included from another original source. @@ -121,7 +122,7 @@ public String getType() { } @Override - public String getLicenseInfoFromFilesPropertyName() { + public PropertyDescriptor getLicenseInfoFromFilesPropertyName() { return SpdxConstants.PROP_LICENSE_INFO_FROM_SNIPPETS; } diff --git a/src/main/java/org/spdx/storage/IModelStore.java b/src/main/java/org/spdx/storage/IModelStore.java index 1c201759e..f32ee9f64 100644 --- a/src/main/java/org/spdx/storage/IModelStore.java +++ b/src/main/java/org/spdx/storage/IModelStore.java @@ -84,29 +84,29 @@ public enum IdType { /** * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @return Property names for all properties having a value for a given id within a document + * @return Property descriptors for all properties having a value for a given id within a document * @throws InvalidSPDXAnalysisException */ - public List getPropertyValueNames(String documentUri, String id) throws InvalidSPDXAnalysisException; + public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException; /** - * Sets a property value for a String or Boolean type of value creating the propertyName if it does not exist + * Sets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property + * @param propertyDescriptor descriptor for the property * @param value value to set * @throws InvalidSPDXAnalysisException */ - public void setValue(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException; + public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property - * @return the single value associated with the id, propertyName and document + * @param propertyDescriptor descriptor for the property + * @return the single value associated with the id, propertyDescriptor and document * @throws InvalidSPDXAnalysisException */ - public Optional getValue(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException; + public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * Generate a unique ID for use within the document @@ -118,13 +118,13 @@ public enum IdType { public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException; /** - * Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyName does not exist + * Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyDescriptor does not exist * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property + * @param propertyDescriptor descriptor for the property * @throws InvalidSPDXAnalysisException */ - public void removeProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException; + public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * @return a list of all Document URI's stored in the model store @@ -155,85 +155,85 @@ public enum IdType { * Removes a value from a collection of values associated with a property * @param documentUri Unique document URI * @param id ID of the item to associate the property with - * @param propertyName name of the property + * @param propertyDescriptor descriptor for the property * @param value Value to be removed * @return */ - public boolean removeValueFromCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException; + public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** * @param documentUri Unique document URI * @param id ID of the item to associate the property with - * @param propertyName name of the property + * @param propertyDescriptor descriptor for the property * @return size of a collection associated with a property. 0 if the property does not exist. */ - public int collectionSize(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException; + public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * @param documentUri Unique document URI * @param id ID of the item to associate the property with - * @param propertyName name of the property + * @param propertyDescriptor descriptor for the property * @param value * @return true if the collection associated with a property contains the value */ - public boolean collectionContains(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException; + public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** - * Sets the value collection for the property to an empty collection creating the propertyName if it does not exist + * Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not exist * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property + * @param propertyDescriptor descriptor for the property * @throws InvalidSPDXAnalysisException */ - void clearValueCollection(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException; + void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** - * Adds a value to a property collection creating the propertyName if it does not exist + * Adds a value to a property collection creating the propertyDescriptor if it does not exist * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property + * @param propertyDescriptor descriptor for the property * @param value value to add * @return true if the collection was modified * @throws InvalidSPDXAnalysisException */ - public boolean addValueToCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException; + public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property - * @return Iterator over the list of values associated with the id, propertyName and document + * @param propertyDescriptor descriptor for the property + * @return Iterator over the list of values associated with the id, propertyDescriptor and document * @throws InvalidSPDXAnalysisException */ - public Iterator listValues(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException; + public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property + * @param propertyDescriptor descriptor for the property * @param clazz Class to test compatibility with - * @return true if all members of a collection associated with the id and propertyName can be assigned to the clazz + * @return true if all members of a collection associated with the id and propertyDescriptor can be assigned to the clazz * @throws InvalidSPDXAnalysisException */ - public boolean isCollectionMembersAssignableTo(String documentUri, String id, String propertyName, Class clazz) throws InvalidSPDXAnalysisException; + public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; /** * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property + * @param propertyDescriptor descriptor for the property * @param clazz Class to test compatibility with - * @return true if the value associated with the id and propertyName can be assigned to the clazz + * @return true if the value associated with the id and propertyDescriptor can be assigned to the clazz * @throws InvalidSPDXAnalysisException */ - public boolean isPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class clazz) throws InvalidSPDXAnalysisException; + public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; /** * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param propertyName Name of the property - * @return true if the propertyName represents multiple values + * @param propertyDescriptor descriptor for the property + * @return true if the propertyDescriptor represents multiple values */ - public boolean isCollectionProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException; + public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * @param id diff --git a/src/main/java/org/spdx/storage/PropertyDescriptor.java b/src/main/java/org/spdx/storage/PropertyDescriptor.java new file mode 100644 index 000000000..06dbf84e5 --- /dev/null +++ b/src/main/java/org/spdx/storage/PropertyDescriptor.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage; + +import java.util.Objects; + +/** + * Holds a description of a property including the property name and property + * nameSpace. Includes a helper function to default the namespace. + * @author Gary O'Neall + * + */ +public class PropertyDescriptor { + + private String name; + private String nameSpace; + + /** + * @param name Property name as defined in the SPDX specification + * @param nameSpace Property nameSpace as defined in the SPDX specification + */ + public PropertyDescriptor(String name, String nameSpace) { + Objects.requireNonNull(name); + Objects.requireNonNull(nameSpace); + this.name = name; + this.nameSpace = nameSpace; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + Objects.requireNonNull(name, "Can not set name to null"); + this.name = name; + } + + /** + * @return the nameSpace + */ + public String getNameSpace() { + return nameSpace; + } + + /** + * @param nameSpace the nameSpace to set + */ + public void setNameSpace(String nameSpace) { + Objects.requireNonNull(nameSpace, "Can not set nameSpace to null"); + this.nameSpace = nameSpace; + } + + @Override + public boolean equals(Object compare) { + return compare instanceof PropertyDescriptor && + Objects.equals(this.name, ((PropertyDescriptor)(compare)).name) && + Objects.equals(this.nameSpace, ((PropertyDescriptor)(compare)).nameSpace); + } + + @Override + public int hashCode() { + return 11 ^ this.name.hashCode() ^ this.nameSpace.hashCode(); + } + + @Override + public String toString() { + return this.nameSpace + this.name; + } +} diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java index 7d231cb07..d76a3241d 100644 --- a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java @@ -265,14 +265,14 @@ public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) } public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - if (!SpdxConstants.RDFS_PROP_SEE_ALSO.equals(propertyName)) { + if (!SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { return false; } return String.class.isAssignableFrom(clazz); } public boolean isCollectionProperty(String propertyName) { - return SpdxConstants.RDFS_PROP_SEE_ALSO.equals(propertyName); + return SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName); } } diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java index 321e029b8..58d28bf7b 100644 --- a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java @@ -192,7 +192,7 @@ public void clearPropertyValueList(String propertyName) throws InvalidSpdxProper * @throws InvalidSPDXAnalysisException */ public boolean addCrossRefValueToList(String propertyName, CrossRefJson value) throws InvalidSPDXAnalysisException { - if (SpdxConstants.PROP_CROSS_REF.equals(propertyName)) { + if (SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName)) { return crossRef.add(value); } else { throw new InvalidSpdxPropertyException(propertyName + "is not a crossRef list type"); @@ -212,7 +212,7 @@ public boolean addPrimitiveValueToList(String propertyName, Object value) throws throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); } return seeAlso.add((String)value); - } else if (SpdxConstants.PROP_CROSS_REF.equals(propertyName)) { + } else if (SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName)) { if (!(value instanceof CrossRefJson)) { throw new InvalidSpdxPropertyException("Expected CrossRefJson type for "+propertyName); } @@ -371,9 +371,9 @@ public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) } public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - if (SpdxConstants.RDFS_PROP_SEE_ALSO.equals(propertyName)) { + if (SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { return String.class.isAssignableFrom(clazz); - } else if (SpdxConstants.PROP_CROSS_REF.equals(propertyName)) { + } else if (SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName)) { return CrossRef.class.isAssignableFrom(clazz); } else { return false; @@ -381,6 +381,7 @@ public boolean isCollectionMembersAssignableTo(String propertyName, Class cla } public boolean isCollectionProperty(String propertyName) { - return SpdxConstants.RDFS_PROP_SEE_ALSO.equals(propertyName) || SpdxConstants.PROP_CROSS_REF.equals(propertyName); + return SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName) || + SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName); } } diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index 1f0395977..b7e9d5485 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -46,6 +46,7 @@ import org.spdx.library.model.TypedValue; import org.spdx.library.model.license.LicenseInfoFactory; import org.spdx.library.model.license.SpdxListedLicenseException; +import org.spdx.storage.PropertyDescriptor; import com.google.gson.Gson; @@ -246,7 +247,7 @@ public void create(String documentUri, String id, String type) throws InvalidSPD * @see org.spdx.storage.IModelStore#getPropertyValueNames(java.lang.String, java.lang.String) */ @Override - public List getPropertyValueNames(String documentUri, String id) throws InvalidSPDXAnalysisException { + public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -265,18 +266,23 @@ public List getPropertyValueNames(String documentUri, String id) throws } else if (crossRefs.containsKey(id)) { crossRef = crossRefs.get(id); } + List retval = new ArrayList<>(); if (isLicenseId) { LicenseJson license = fetchLicenseJson(licenseIds.get(id.toLowerCase())); - return license.getPropertyValueNames(); + license.getPropertyValueNames().spliterator().forEachRemaining( + s -> retval.add(new PropertyDescriptor(s, SpdxConstants.SPDX_NAMESPACE))); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(exceptionIds.get(id.toLowerCase())); - return exc.getPropertyValueNames(); + exc.getPropertyValueNames().spliterator().forEachRemaining( + s -> retval.add(new PropertyDescriptor(s, SpdxConstants.SPDX_NAMESPACE))); } else if (Objects.nonNull(crossRef)) { - return crossRef.getPropertyValueNames(); + crossRef.getPropertyValueNames().spliterator().forEachRemaining( + s -> retval.add(new PropertyDescriptor(s, SpdxConstants.SPDX_NAMESPACE))); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID"); } + return retval; } finally { listedLicenseModificationLock.readLock().unlock(); } @@ -429,7 +435,7 @@ private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws Invali * @see org.spdx.storage.IModelStore#setPrimitiveValue(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public void setValue(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException { + public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -453,12 +459,12 @@ public void setValue(String documentUri, String id, String propertyName, Object } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - license.setPrimativeValue(propertyName, value); + license.setPrimativeValue(propertyDescriptor.getName(), value); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - exc.setPrimativeValue(propertyName, value); + exc.setPrimativeValue(propertyDescriptor.getName(), value); } else if (Objects.nonNull(crossRef)) { - crossRef.setPrimativeValue(propertyName, value); + crossRef.setPrimativeValue(propertyDescriptor.getName(), value); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -469,7 +475,7 @@ public void setValue(String documentUri, String id, String propertyName, Object * @see org.spdx.storage.IModelStore#clearPropertyValueList(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void clearValueCollection(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { + public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -493,12 +499,12 @@ public void clearValueCollection(String documentUri, String id, String propertyN } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - license.clearPropertyValueList(propertyName); + license.clearPropertyValueList(propertyDescriptor.getName()); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - exc.clearPropertyValueList(propertyName); + exc.clearPropertyValueList(propertyDescriptor.getName()); }else if (Objects.nonNull(crossRef)) { - crossRef.clearPropertyValueList(propertyName); + crossRef.clearPropertyValueList(propertyDescriptor.getName()); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -509,7 +515,7 @@ public void clearValueCollection(String documentUri, String id, String propertyN * @see org.spdx.storage.IModelStore#addPrimitiveValueToList(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean addValueToCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException { + public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -533,7 +539,7 @@ public boolean addValueToCollection(String documentUri, String id, String proper } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - if (SpdxConstants.PROP_CROSS_REF.equals(propertyName)) { + if (SpdxConstants.PROP_CROSS_REF.equals(propertyDescriptor)) { if (!(value instanceof TypedValue)) { logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); @@ -548,15 +554,15 @@ public boolean addValueToCollection(String documentUri, String id, String proper logger.error("CrossRef with ID "+tv.getId()+" does not exist in the store."); throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getId()+" does not exist in the store."); } - return license.addCrossRefValueToList(propertyName, crj); + return license.addCrossRefValueToList(propertyDescriptor.getName(), crj); } else { - return license.addPrimitiveValueToList(propertyName, value); + return license.addPrimitiveValueToList(propertyDescriptor.getName(), value); } } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return exc.addPrimitiveValueToList(propertyName, value); + return exc.addPrimitiveValueToList(propertyDescriptor.getName(), value); } else if (Objects.nonNull(crossRef)) { - return crossRef.addPrimitiveValueToList(propertyName, value); + return crossRef.addPrimitiveValueToList(propertyDescriptor.getName(), value); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -564,7 +570,7 @@ public boolean addValueToCollection(String documentUri, String id, String proper } @Override - public boolean removeValueFromCollection(String documentUri, String id, String propertyName, Object value) + public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ @@ -589,7 +595,7 @@ public boolean removeValueFromCollection(String documentUri, String id, String p } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - if (SpdxConstants.PROP_CROSS_REF.equals(propertyName)) { + if (SpdxConstants.PROP_CROSS_REF.equals(propertyDescriptor)) { if (!(value instanceof TypedValue)) { logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); @@ -604,15 +610,15 @@ public boolean removeValueFromCollection(String documentUri, String id, String p logger.error("CrossRef with ID "+tv.getId()+" does not exist in the store."); throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getId()+" does not exist in the store."); } - return license.removePrimitiveValueToList(propertyName, crj); + return license.removePrimitiveValueToList(propertyDescriptor.getName(), crj); } else { - return license.removePrimitiveValueToList(propertyName, value); + return license.removePrimitiveValueToList(propertyDescriptor.getName(), value); } } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return exc.removePrimitiveValueToList(propertyName, value); + return exc.removePrimitiveValueToList(propertyDescriptor.getName(), value); } else if (Objects.nonNull(crossRef)) { - return crossRef.removePrimitiveValueToList(propertyName, value); + return crossRef.removePrimitiveValueToList(propertyDescriptor.getName(), value); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -624,7 +630,7 @@ public boolean removeValueFromCollection(String documentUri, String id, String p */ @SuppressWarnings("unchecked") @Override - public Iterator listValues(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { + public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -648,8 +654,8 @@ public Iterator listValues(String documentUri, String id, String propert } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - List valueList = (List)(List)license.getValueList(propertyName); - if (SpdxConstants.PROP_CROSS_REF.equals(propertyName)) { + List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); + if (SpdxConstants.PROP_CROSS_REF.equals(propertyDescriptor)) { final Iterator crossRefJsonIter = valueList.iterator(); return new Iterator() { @@ -665,7 +671,7 @@ public Object next() { return null; } if (!(nextVal instanceof CrossRefJson)) { - throw new RuntimeException(new InvalidSPDXAnalysisException("Invalid type for "+propertyName+". Must be of type CrossRefJson")); + throw new RuntimeException(new InvalidSPDXAnalysisException("Invalid type for "+propertyDescriptor+". Must be of type CrossRefJson")); } CrossRefJson nextCrossRef = (CrossRefJson)nextVal; String crossRefId = nextCrossRef.getId(); @@ -698,9 +704,9 @@ public Object next() { } } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return ((List)(List)exc.getValueList(propertyName)).iterator(); + return ((List)(List)exc.getValueList(propertyDescriptor.getName())).iterator(); } else if (Objects.nonNull(crossRef)) { - return ((List)(List)crossRef.getValueList(propertyName)).iterator(); + return ((List)(List)crossRef.getValueList(propertyDescriptor.getName())).iterator(); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -711,7 +717,7 @@ public Object next() { * @see org.spdx.storage.IModelStore#getValue(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Optional getValue(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { + public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -735,12 +741,12 @@ public Optional getValue(String documentUri, String id, String propertyN } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - return Optional.ofNullable(license.getValue(propertyName)); + return Optional.ofNullable(license.getValue(propertyDescriptor.getName())); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return Optional.ofNullable(exc.getValue(propertyName)); + return Optional.ofNullable(exc.getValue(propertyDescriptor.getName())); } else if (Objects.nonNull(crossRef)) { - return Optional.ofNullable(crossRef.getValue(propertyName)); + return Optional.ofNullable(crossRef.getValue(propertyDescriptor.getName())); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -850,7 +856,7 @@ public Optional getTypedValue(String documentUri, String id) throws } @Override - public void removeProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { + public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -874,12 +880,12 @@ public void removeProperty(String documentUri, String id, String propertyName) t } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - license.removeProperty(propertyName); + license.removeProperty(propertyDescriptor.getName()); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - exc.removeProperty(propertyName); + exc.removeProperty(propertyDescriptor.getName()); } else if (Objects.nonNull(crossRef)) { - crossRef.removeProperty(propertyName); + crossRef.removeProperty(propertyDescriptor.getName()); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -923,7 +929,7 @@ public Stream getAllItems(String documentUri, @Nullable String typeF @SuppressWarnings("unchecked") @Override - public int collectionSize(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { + public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); @@ -947,12 +953,12 @@ public int collectionSize(String documentUri, String id, String propertyName) th } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - return ((List)(List)license.getValueList(propertyName)).size(); + return ((List)(List)license.getValueList(propertyDescriptor.getName())).size(); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return ((List)(List)exc.getValueList(propertyName)).size(); + return ((List)(List)exc.getValueList(propertyDescriptor.getName())).size(); } else if (Objects.nonNull(crossRef)) { - return ((List)(List)crossRef.getValueList(propertyName)).size(); + return ((List)(List)crossRef.getValueList(propertyDescriptor.getName())).size(); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -961,7 +967,7 @@ public int collectionSize(String documentUri, String id, String propertyName) th @SuppressWarnings("unchecked") @Override - public boolean collectionContains(String documentUri, String id, String propertyName, Object value) + public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ @@ -986,7 +992,7 @@ public boolean collectionContains(String documentUri, String id, String property } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - List valueList = (List)(List)license.getValueList(propertyName); + List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); if (value instanceof TypedValue && SpdxConstants.CLASS_CROSS_REF.equals(((TypedValue)value).getType())) { CrossRefJson compareValue = crossRefs.get(((TypedValue)value).getId()); if (Objects.isNull(compareValue)) { @@ -999,9 +1005,9 @@ public boolean collectionContains(String documentUri, String id, String property } } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return ((List)(List)exc.getValueList(propertyName)).contains(value); + return ((List)(List)exc.getValueList(propertyDescriptor.getName())).contains(value); } else if (Objects.nonNull(crossRef)) { - return ((List)(List)crossRef.getValueList(propertyName)).contains(value); + return ((List)(List)crossRef.getValueList(propertyDescriptor.getName())).contains(value); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -1009,7 +1015,7 @@ public boolean collectionContains(String documentUri, String id, String property } @Override - public boolean isCollectionMembersAssignableTo(String documentUri, String id, String propertyName, Class clazz) + public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ @@ -1034,12 +1040,12 @@ public boolean isCollectionMembersAssignableTo(String documentUri, String id, St } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - return license.isCollectionMembersAssignableTo(propertyName, clazz); + return license.isCollectionMembersAssignableTo(propertyDescriptor.getName(), clazz); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return exc.isCollectionMembersAssignableTo(propertyName, clazz); + return exc.isCollectionMembersAssignableTo(propertyDescriptor.getName(), clazz); } else if (Objects.nonNull(crossRef)) { - return crossRef.isCollectionMembersAssignableTo(propertyName, clazz); + return crossRef.isCollectionMembersAssignableTo(propertyDescriptor.getName(), clazz); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); @@ -1047,7 +1053,7 @@ public boolean isCollectionMembersAssignableTo(String documentUri, String id, St } @Override - public boolean isPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class clazz) + public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ @@ -1072,12 +1078,12 @@ public boolean isPropertyValueAssignableTo(String documentUri, String id, String } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - return license.isPropertyValueAssignableTo(propertyName, clazz); + return license.isPropertyValueAssignableTo(propertyDescriptor.getName(), clazz); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return exc.isPropertyValueAssignableTo(propertyName, clazz); + return exc.isPropertyValueAssignableTo(propertyDescriptor.getName(), clazz); } else if (Objects.nonNull(crossRef)) { - return crossRef.isPropertyValueAssignableTo(propertyName, clazz); + return crossRef.isPropertyValueAssignableTo(propertyDescriptor.getName(), clazz); } else { logger.error("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID"); @@ -1085,7 +1091,7 @@ public boolean isPropertyValueAssignableTo(String documentUri, String id, String } @Override - public boolean isCollectionProperty(String documentUri, String id, String propertyName) + public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ @@ -1110,12 +1116,12 @@ public boolean isCollectionProperty(String documentUri, String id, String proper } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - return license.isCollectionProperty(propertyName); + return license.isCollectionProperty(propertyDescriptor.getName()); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(id); - return exc.isCollectionProperty(propertyName); + return exc.isCollectionProperty(propertyDescriptor.getName()); } else if (Objects.nonNull(crossRef)) { - return crossRef.isCollectionProperty(propertyName); + return crossRef.isCollectionProperty(propertyDescriptor.getName()); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); diff --git a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java index 9c8e03424..ec8da8756 100644 --- a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java @@ -26,6 +26,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.model.TypedValue; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; /** * A simple abstract SPDX store that stores everything in an underlying model store which is initialized in the @@ -68,26 +69,26 @@ public void create(String documentUri, String id, String type) throws InvalidSPD * @see org.spdx.storage.IModelStore#getPropertyValueNames(java.lang.String, java.lang.String) */ @Override - public List getPropertyValueNames(String documentUri, String id) throws InvalidSPDXAnalysisException { - return baseStore.getPropertyValueNames(documentUri, id); + public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { + return baseStore.getPropertyValueDescriptors(documentUri, id); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#setValue(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public void setValue(String documentUri, String id, String propertyName, Object value) + public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - baseStore.setValue(documentUri, id, propertyName, value); + baseStore.setValue(documentUri, id, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#getValue(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Optional getValue(String documentUri, String id, String propertyName) + public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.getValue(documentUri, id, propertyName); + return baseStore.getValue(documentUri, id, propertyDescriptor); } /* (non-Javadoc) @@ -102,8 +103,8 @@ public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAna * @see org.spdx.storage.IModelStore#removeProperty(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void removeProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { - baseStore.removeProperty(documentUri, id, propertyName); + public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + baseStore.removeProperty(documentUri, id, propertyDescriptor); } /* (non-Javadoc) @@ -143,80 +144,80 @@ public void leaveCriticalSection(IModelStoreLock lock) { * @see org.spdx.storage.IModelStore#removeValueFromCollection(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean removeValueFromCollection(String documentUri, String id, String propertyName, Object value) + public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return baseStore.removeValueFromCollection(documentUri, id, propertyName, value); + return baseStore.removeValueFromCollection(documentUri, id, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#collectionSize(java.lang.String, java.lang.String, java.lang.String) */ @Override - public int collectionSize(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { - return baseStore.collectionSize(documentUri, id, propertyName); + public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + return baseStore.collectionSize(documentUri, id, propertyDescriptor); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#collectionContains(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean collectionContains(String documentUri, String id, String propertyName, Object value) + public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return baseStore.collectionContains(documentUri, id, propertyName, value); + return baseStore.collectionContains(documentUri, id, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#clearValueCollection(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void clearValueCollection(String documentUri, String id, String propertyName) + public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - baseStore.clearValueCollection(documentUri, id, propertyName); + baseStore.clearValueCollection(documentUri, id, propertyDescriptor); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#addValueToCollection(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean addValueToCollection(String documentUri, String id, String propertyName, Object value) + public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return baseStore.addValueToCollection(documentUri, id, propertyName, value); + return baseStore.addValueToCollection(documentUri, id, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#listValues(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Iterator listValues(String documentUri, String id, String propertyName) + public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.listValues(documentUri, id, propertyName); + return baseStore.listValues(documentUri, id, propertyDescriptor); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#isCollectionMembersAssignableTo(java.lang.String, java.lang.String, java.lang.String, java.lang.Class) */ @Override - public boolean isCollectionMembersAssignableTo(String documentUri, String id, String propertyName, Class clazz) + public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return baseStore.isCollectionMembersAssignableTo(documentUri, id, propertyName, clazz); + return baseStore.isCollectionMembersAssignableTo(documentUri, id, propertyDescriptor, clazz); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#isPropertyValueAssignableTo(java.lang.String, java.lang.String, java.lang.String, java.lang.Class) */ @Override - public boolean isPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class clazz) + public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return baseStore.isPropertyValueAssignableTo(documentUri, id, propertyName, clazz); + return baseStore.isPropertyValueAssignableTo(documentUri, id, propertyDescriptor, clazz); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#isCollectionProperty(java.lang.String, java.lang.String, java.lang.String) */ @Override - public boolean isCollectionProperty(String documentUri, String id, String propertyName) + public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.isCollectionProperty(documentUri, id, propertyName); + return baseStore.isCollectionProperty(documentUri, id, propertyDescriptor); } /* (non-Javadoc) @@ -252,8 +253,8 @@ protected void clear(String documentUri) throws InvalidSPDXAnalysisException { IModelStoreLock lock = this.enterCriticalSection(documentUri, false); try { for (TypedValue item:this.getAllItems(documentUri, null).collect(Collectors.toList())) { - for (String propertyName:this.getPropertyValueNames(documentUri, item.getId())) { - this.removeProperty(documentUri, item.getId(), propertyName); + for (PropertyDescriptor propertyDescriptor:this.getPropertyValueDescriptors(documentUri, item.getId())) { + this.removeProperty(documentUri, item.getId(), propertyDescriptor); } } } finally { diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index 794ee8b0c..e4a2e6424 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -46,6 +46,7 @@ import org.spdx.library.model.TypedValue; import org.spdx.library.model.license.LicenseInfoFactory; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; /** * @author Gary O'Neall @@ -206,101 +207,99 @@ protected StoredTypedItem getItem(String documentUri, String id) throws InvalidS } @Override - public List getPropertyValueNames(String documentUri, String id) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).getPropertyValueNames(); + public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { + return getItem(documentUri, id).getPropertyValueDescriptors(); } @Override - public void setValue(String documentUri, String id, String propertyName, Object value) + public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (value instanceof TypedValue) { - referenceCountLock.writeLock().lock(); - try { - StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); - getItem(documentUri, id).setValue(propertyName, value); - itemToBeStored.incReferenceCount(); - } finally { - referenceCountLock.writeLock().unlock(); - } - } else { - getItem(documentUri, id).setValue(propertyName, value); - } + if (value instanceof TypedValue) { + referenceCountLock.writeLock().lock(); + try { + StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); + getItem(documentUri, id).setValue(propertyDescriptor, value); + itemToBeStored.incReferenceCount(); + } finally { + referenceCountLock.writeLock().unlock(); + } + } else { + getItem(documentUri, id).setValue(propertyDescriptor, value); + } } @Override - public void clearValueCollection(String documentUri, String id, String propertyName) + public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - referenceCountLock.writeLock().lock(); - try { - List removedItems = new ArrayList<>(); - Iterator iter = getItem(documentUri, id).getValueList(propertyName); - while (iter.hasNext()) { - Object nextItem = iter.next(); - if (nextItem instanceof TypedValue) { - removedItems.add(getItem(documentUri, ((TypedValue)nextItem).getId())); - } - } - getItem(documentUri, id).clearPropertyValueList(propertyName); - for (StoredTypedItem item:removedItems) { - item.decReferenceCount(); - } - } finally { - referenceCountLock.writeLock().unlock(); - } - + referenceCountLock.writeLock().lock(); + try { + List removedItems = new ArrayList<>(); + Iterator iter = getItem(documentUri, id).getValueList(propertyDescriptor); + while (iter.hasNext()) { + Object nextItem = iter.next(); + if (nextItem instanceof TypedValue) { + removedItems.add(getItem(documentUri, ((TypedValue)nextItem).getId())); + } + } + getItem(documentUri, id).clearPropertyValueList(propertyDescriptor); + for (StoredTypedItem item:removedItems) { + item.decReferenceCount(); + } + } finally { + referenceCountLock.writeLock().unlock(); + } } @Override - public boolean addValueToCollection(String documentUri, String id, String propertyName, Object value) + public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (value instanceof TypedValue) { - referenceCountLock.writeLock().lock(); - try { - StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); - boolean result = getItem(documentUri, id).addValueToList(propertyName, value); - itemToBeStored.incReferenceCount(); - return result; - } finally { - referenceCountLock.writeLock().unlock(); - } - } else { - return getItem(documentUri, id).addValueToList(propertyName, value); - } + if (value instanceof TypedValue) { + referenceCountLock.writeLock().lock(); + try { + StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); + boolean result = getItem(documentUri, id).addValueToList(propertyDescriptor, value); + itemToBeStored.incReferenceCount(); + return result; + } finally { + referenceCountLock.writeLock().unlock(); + } + } else { + return getItem(documentUri, id).addValueToList(propertyDescriptor, value); + } } - @Override - public boolean removeValueFromCollection(String documentUri, String id, String propertyName, Object value) + public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (value instanceof TypedValue) { - referenceCountLock.writeLock().lock(); - try { - StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); - boolean result = getItem(documentUri, id).removeValueFromList(propertyName, value); - itemToBeStored.decReferenceCount(); - return result; - } finally { - referenceCountLock.writeLock().unlock(); - } - } else { - return getItem(documentUri, id).removeValueFromList(propertyName, value); - } + if (value instanceof TypedValue) { + referenceCountLock.writeLock().lock(); + try { + StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); + boolean result = getItem(documentUri, id).removeValueFromList(propertyDescriptor, value); + itemToBeStored.decReferenceCount(); + return result; + } finally { + referenceCountLock.writeLock().unlock(); + } + } else { + return getItem(documentUri, id).removeValueFromList(propertyDescriptor, value); + } } @Override - public Iterator listValues(String documentUri, String id, String propertyName) + public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).getValueList(propertyName); + return getItem(documentUri, id).getValueList(propertyDescriptor); } @Override - public Optional getValue(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { + public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { StoredTypedItem item = getItem(documentUri, id); - if (item.isCollectionProperty(propertyName)) { - logger.warn("Returning a collection for a getValue call for property "+propertyName); - return Optional.of(new ModelCollection<>(this, documentUri, id, propertyName, null ,null)); + if (item.isCollectionProperty(propertyDescriptor)) { + logger.warn("Returning a collection for a getValue call for property "+propertyDescriptor); + return Optional.of(new ModelCollection<>(this, documentUri, id, propertyDescriptor, null ,null)); } else { - return Optional.ofNullable(item.getValue(propertyName)); + return Optional.ofNullable(item.getValue(propertyDescriptor)); } } @@ -318,17 +317,17 @@ public synchronized String getNextId(IdType idType, String documentUri) throws I } @Override - public void removeProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { - referenceCountLock.writeLock().lock(); - try { - Object itemToBeRemoved = getItem(documentUri, id).getValue(propertyName); - getItem(documentUri, id).removeProperty(propertyName); - if (itemToBeRemoved instanceof TypedValue) { - getItem(documentUri, ((TypedValue)itemToBeRemoved).getId()).decReferenceCount(); - } - } finally { - referenceCountLock.writeLock().unlock(); - } + public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + referenceCountLock.writeLock().lock(); + try { + Object itemToBeRemoved = getItem(documentUri, id).getValue(propertyDescriptor); + getItem(documentUri, id).removeProperty(propertyDescriptor); + if (itemToBeRemoved instanceof TypedValue) { + getItem(documentUri, ((TypedValue)itemToBeRemoved).getId()).decReferenceCount(); + } + } finally { + referenceCountLock.writeLock().unlock(); + } } @Override @@ -355,32 +354,32 @@ public Stream getAllItems(String documentUri, String typeFilter) } @Override - public int collectionSize(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).collectionSize(propertyName); + public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + return getItem(documentUri, id).collectionSize(propertyDescriptor); } @Override - public boolean collectionContains(String documentUri, String id, String propertyName, Object value) + public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).collectionContains(propertyName, value); + return getItem(documentUri, id).collectionContains(propertyDescriptor, value); } @Override - public boolean isCollectionMembersAssignableTo(String documentUri, String id, String propertyName, + public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).isCollectionMembersAssignableTo(propertyName, clazz); + return getItem(documentUri, id).isCollectionMembersAssignableTo(propertyDescriptor, clazz); } @Override - public boolean isPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class clazz) + public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).isPropertyValueAssignableTo(propertyName, clazz); + return getItem(documentUri, id).isPropertyValueAssignableTo(propertyDescriptor, clazz); } @Override - public boolean isCollectionProperty(String documentUri, String id, String propertyName) + public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).isCollectionProperty(propertyName); + return getItem(documentUri, id).isCollectionProperty(propertyDescriptor); } @Override @@ -464,38 +463,38 @@ public void delete(String documentUri, String id) throws InvalidSPDXAnalysisExce throw new SpdxIdNotFoundException("Error deleting - documentUri "+documentUri+" does not exits."); } referenceCountLock.writeLock().lock(); - try { - if (getItem(documentUri, id).getReferenceCount() > 0) { - // find the element it is used by - logger.error("Can not delete ID "+id+". It is in use"); - throw new SpdxIdInUseException("Can not delete ID "+id+". It is in use."); - } - List propertyNames = this.getPropertyValueNames(documentUri, id); - for (String property:propertyNames) { - if (this.isCollectionProperty(documentUri, id, property)) { - Iterator iter = this.listValues(documentUri, id, property); - while (iter.hasNext()) { - Object val = iter.next(); - if (val instanceof TypedValue) { - getItem(documentUri, ((TypedValue)val).getId()).decReferenceCount(); - } - } - } else { - Optional val = getValue(documentUri, id, property); - if (val.isPresent()) { - if (val.get() instanceof TypedValue) { - getItem(documentUri, ((TypedValue)val.get()).getId()).decReferenceCount(); - } - } - } - } - if (Objects.isNull(idMap.remove(id.toLowerCase()))) { - logger.error("Error deleting - ID "+id+" does not exist."); - throw new SpdxIdNotFoundException("Error deleting - ID "+id+" does not exist."); - } - } finally { - referenceCountLock.writeLock().unlock(); - } + try { + if (getItem(documentUri, id).getReferenceCount() > 0) { + // find the element it is used by + logger.error("Can not delete ID "+id+". It is in use"); + throw new SpdxIdInUseException("Can not delete ID "+id+". It is in use."); + } + List propertyDescriptors = this.getPropertyValueDescriptors(documentUri, id); + for (PropertyDescriptor property:propertyDescriptors) { + if (this.isCollectionProperty(documentUri, id, property)) { + Iterator iter = this.listValues(documentUri, id, property); + while (iter.hasNext()) { + Object val = iter.next(); + if (val instanceof TypedValue) { + getItem(documentUri, ((TypedValue)val).getId()).decReferenceCount(); + } + } + } else { + Optional val = getValue(documentUri, id, property); + if (val.isPresent()) { + if (val.get() instanceof TypedValue) { + getItem(documentUri, ((TypedValue)val.get()).getId()).decReferenceCount(); + } + } + } + } + if (Objects.isNull(idMap.remove(id.toLowerCase()))) { + logger.error("Error deleting - ID "+id+" does not exist."); + throw new SpdxIdNotFoundException("Error deleting - ID "+id+" does not exist."); + } + } finally { + referenceCountLock.writeLock().unlock(); + } } @Override diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index 41275396b..cae892406 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -26,6 +26,7 @@ import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.library.model.IndividualUriValue; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; /** * Individual item to be stored in memory @@ -41,7 +42,7 @@ public class StoredTypedItem extends TypedValue { static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstants.ALL_SPDX_CLASSES)); - private ConcurrentHashMap properties = new ConcurrentHashMap<>(); + private ConcurrentHashMap properties = new ConcurrentHashMap<>(); private int referenceCount = 0; @@ -52,13 +53,13 @@ public StoredTypedItem(String documentUri, String id, String type) throws Invali } /** - * @return Property names for all properties having a value + * @return property descriptors for all properties having a value */ - public List getPropertyValueNames() { - Iterator> iter = this.properties.entrySet().iterator(); - List retval = new ArrayList<>(); + public List getPropertyValueDescriptors() { + Iterator> iter = this.properties.entrySet().iterator(); + List retval = new ArrayList<>(); while (iter.hasNext()) { - Entry entry = iter.next(); + Entry entry = iter.next(); retval.add(entry.getKey()); } return Collections.unmodifiableList(retval); @@ -110,12 +111,12 @@ public int getReferenceCount() throws SpdxInvalidTypeException { } /** - * @param propertyName Name of the property + * @param propertyDescriptor Descriptor for the property * @param value Value to be set * @throws SpdxInvalidTypeException */ - public void setValue(String propertyName, Object value) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); + public void setValue(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(value, "Value can not be null"); if (value instanceof ModelObject) { throw new SpdxInvalidTypeException("Can not store Model Object in store. Convert to TypedValue first"); @@ -129,36 +130,36 @@ public void setValue(String propertyName, Object value) throws SpdxInvalidTypeEx !(value instanceof IndividualUriValue)) { throw new SpdxInvalidTypeException(value.getClass().toString()+" is not a supported class to be stored."); } - properties.put(propertyName, value); + properties.put(propertyDescriptor, value); } /** - * Sets the value list for the property to an empty list creating the propertyName if it does not exist - * @param propertyName Name of the property + * Sets the value list for the property to an empty list creating the propertyDescriptor if it does not exist + * @param propertyDescriptor descriptor for the property * @throws SpdxInvalidTypeException */ - public void clearPropertyValueList(String propertyName) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); - Object value = properties.get(propertyName); + public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); + Object value = properties.get(propertyDescriptor); if (value == null) { return; } if (value instanceof ConcurrentHashMap) { ((ConcurrentHashMap)value).clear(); } else { - throw new SpdxInvalidTypeException("Trying to clear a list for non list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to clear a list for non list type for property "+propertyDescriptor); } } /** - * Adds a value to a property list for a String or Boolean type of value creating the propertyName if it does not exist - * @param propertyName Name of the property + * Adds a value to a property list for a String or Boolean type of value creating the propertyDescriptor if it does not exist + * @param propertyDescriptor Descriptor for the property * @param value Value to be set * @throws SpdxInvalidTypeException */ - public boolean addValueToList(String propertyName, Object value) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); + public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(value, "Value can not be null"); if (value instanceof ModelObject) { throw new SpdxInvalidTypeException("Can not store Model Object in store. Convert to TypedValue first"); @@ -170,17 +171,17 @@ public boolean addValueToList(String propertyName, Object value) throws SpdxInva !(value instanceof IndividualUriValue)) { throw new SpdxInvalidTypeException(value.getClass().toString()+" is not a supported class to be stored."); } - Object map = properties.get(propertyName); + Object map = properties.get(propertyDescriptor); if (map == null) { - properties.putIfAbsent(propertyName, new ConcurrentHashMap>()); - map = properties.get(propertyName); + properties.putIfAbsent(propertyDescriptor, new ConcurrentHashMap>()); + map = properties.get(propertyDescriptor); //Note: there is a small timing window where the property could be removed if (map == null) { return true; } } if (!(map instanceof ConcurrentHashMap)) { - throw new SpdxInvalidTypeException("Trying to add a list for non list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to add a list for non list type for property "+propertyDescriptor); } try { @SuppressWarnings("unchecked") @@ -200,18 +201,24 @@ public boolean addValueToList(String propertyName, Object value) throws SpdxInva } return list.add(value); } catch (Exception ex) { - throw new SpdxInvalidTypeException("Invalid list type for "+propertyName); + throw new SpdxInvalidTypeException("Invalid list type for "+propertyDescriptor); } } - public boolean removeTypedValueFromList(String propertyName, TypedValue value) throws SpdxInvalidTypeException { - Object map = properties.get(propertyName); + /** + * @param propertyDescriptor descriptor for the property + * @param value to be removed + * @return true if the value was removed, false if the value did not exist + * @throws SpdxInvalidTypeException for an invalid type + */ + public boolean removeTypedValueFromList(PropertyDescriptor propertyDescriptor, TypedValue value) throws SpdxInvalidTypeException { + Object map = properties.get(propertyDescriptor); if (map == null) { return false; } if (!(map instanceof ConcurrentHashMap)) { - throw new SpdxInvalidTypeException("Trying to remove from a list for non typed value list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to remove from a list for non typed value list type for property "+propertyDescriptor); } try { @SuppressWarnings("unchecked") @@ -222,25 +229,25 @@ public boolean removeTypedValueFromList(String propertyName, TypedValue value) t } return list.remove(value); } catch (Exception ex) { - throw new SpdxInvalidTypeException("Invalid list type for "+propertyName); + throw new SpdxInvalidTypeException("Invalid list type for "+propertyDescriptor); } } /** * Removes a property from a list if it exists - * @param propertyName + * @param propertyDescriptor descriptor for the property * @param value * @throws SpdxInvalidTypeException */ - public boolean removeValueFromList(String propertyName, Object value) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); + public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); Objects.requireNonNull(value, "Value can not be null"); - Object map = properties.get(propertyName); + Object map = properties.get(propertyDescriptor); if (map == null) { return false; } if (!(map instanceof ConcurrentHashMap)) { - throw new SpdxInvalidTypeException("Trying to remove from a list for non list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to remove from a list for non list type for property "+propertyDescriptor); } try { @SuppressWarnings("unchecked") @@ -257,18 +264,18 @@ public boolean removeValueFromList(String propertyName, Object value) throws Spd } return list.remove(value); } catch (Exception ex) { - throw new SpdxInvalidTypeException("Invalid list type for "+propertyName); + throw new SpdxInvalidTypeException("Invalid list type for "+propertyDescriptor); } } /** - * @param propertyName Name of the property - * @return List of values associated with the id, propertyName and document + * @param propertyDescriptor Descriptor for the property + * @return List of values associated with the id, propertyDescriptor and document * @throws SpdxInvalidTypeException */ - public Iterator getValueList(String propertyName) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); - Object list = properties.get(propertyName); + public Iterator getValueList(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); + Object list = properties.get(propertyDescriptor); if (list == null) { return Collections.emptyIterator(); } @@ -283,26 +290,26 @@ public Iterator getValueList(String propertyName) throws SpdxInvalidType } return valueList.iterator(); } else { - throw new SpdxInvalidTypeException("Trying to get a list for non list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to get a list for non list type for property "+propertyDescriptor); } } /** - * @param propertyName Name of the property - * @return the single value associated with the id, propertyName and document + * @param propertyDescriptor Descriptor for the property + * @return the single value associated with the id, propertyDescriptor and document */ - public Object getValue(String propertyName) { - Objects.requireNonNull(propertyName, "Property name can not be null"); - return properties.get(propertyName); + public Object getValue(PropertyDescriptor propertyDescriptor) { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); + return properties.get(propertyDescriptor); } /** - * Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyName does not exist - * @param propertyName Name of the property + * Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyDescriptor does not exist + * @param propertyDescriptor Descriptor for the property */ - public void removeProperty(String propertyName) { - Objects.requireNonNull(propertyName, "Property name can not be null"); - properties.remove(propertyName); + public void removeProperty(PropertyDescriptor propertyDescriptor) { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); + properties.remove(propertyDescriptor); } /** @@ -314,27 +321,27 @@ public void removeProperty(String propertyName) { public void copyValuesFrom(String fromDocumentUri, IModelStore store) throws InvalidSPDXAnalysisException { Objects.requireNonNull(fromDocumentUri, "From document URI can not be null"); Objects.requireNonNull(store, "Store can not be null"); - List propertyNames = store.getPropertyValueNames(fromDocumentUri, this.getId()); - for (String propertyName:propertyNames) { - Optional value = store.getValue(fromDocumentUri, getId(), propertyName); + List propertyDiscriptors = store.getPropertyValueDescriptors(fromDocumentUri, this.getId()); + for (PropertyDescriptor propertydescriptor:propertyDiscriptors) { + Optional value = store.getValue(fromDocumentUri, getId(), propertydescriptor); if (value.isPresent()) { - this.setValue(propertyName, value.get()); + this.setValue(propertydescriptor, value.get()); } } } /** - * @param propertyName + * @param propertyDescriptor descriptor for the property * @return Size of the collection * @throws SpdxInvalidTypeException */ @SuppressWarnings("rawtypes") - public int collectionSize(String propertyName) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); - Object map = properties.get(propertyName); + public int collectionSize(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); + Object map = properties.get(propertyDescriptor); if (map == null) { - properties.putIfAbsent(propertyName, new ConcurrentHashMap>()); - map = properties.get(propertyName); + properties.putIfAbsent(propertyDescriptor, new ConcurrentHashMap>()); + map = properties.get(propertyDescriptor); //Note: there is a small timing window where the property could be removed if (map == null) { return 0; @@ -351,23 +358,23 @@ public int collectionSize(String propertyName) throws SpdxInvalidTypeException { } return count; } else { - throw new SpdxInvalidTypeException("Trying to get size for a non list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to get size for a non list type for property "+propertyDescriptor); } } /** - * @param propertyName property name + * @param propertyDescriptor descriptor for the property * @param value value to be checked - * @return true if value is in the list associated with the property name + * @return true if value is in the list associated with the property descriptor * @throws SpdxInvalidTypeException */ - public boolean collectionContains(String propertyName, Object value) throws SpdxInvalidTypeException { - Objects.requireNonNull(propertyName, "Property name can not be null"); + public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException { + Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); Objects.requireNonNull(value, "Value can not be null"); - Object map = properties.get(propertyName); + Object map = properties.get(propertyDescriptor); if (map == null) { - properties.putIfAbsent(propertyName, new ConcurrentHashMap>()); - map = properties.get(propertyName); + properties.putIfAbsent(propertyDescriptor, new ConcurrentHashMap>()); + map = properties.get(propertyDescriptor); //Note: there is a small timing window where the property could be removed if (map == null) { return false; @@ -388,14 +395,19 @@ public boolean collectionContains(String propertyName, Object value) throws Spdx } return valueList.contains(value); } else { - throw new SpdxInvalidTypeException("Trying to find contains for non list type for property "+propertyName); + throw new SpdxInvalidTypeException("Trying to find contains for non list type for property "+propertyDescriptor); } } - public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - Objects.requireNonNull(propertyName, "Property name can not be null"); + /** + * @param propertyDescriptor descriptor for the property + * @param clazz class to test against + * @return true if the property with the propertyDescriptor can be assigned to clazz + */ + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); - Object map = properties.get(propertyName); + Object map = properties.get(propertyDescriptor); if (map == null) { return true; // It is still assignable to since it is unassigned } @@ -436,10 +448,15 @@ public boolean isCollectionMembersAssignableTo(String propertyName, Class cla return true; } - public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) { - Objects.requireNonNull(propertyName, "Property name can not be null"); + /** + * @param propertyDescriptor descriptor for the property + * @param clazz class to test against + * @return true if the property can be assigned to type clazz + */ + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); - Object value = properties.get(propertyName); + Object value = properties.get(propertyDescriptor); if (value == null) { return false; } @@ -473,12 +490,12 @@ public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) } /** - * @param propertyName property name - * @return true if there is a list associated with the property name + * @param propertyDescriptor property descriptor + * @return true if there is a list associated with the property descriptor */ - public boolean isCollectionProperty(String propertyName) { - Objects.requireNonNull(propertyName, "Property name can not be null"); - Object value = properties.get(propertyName); + public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) { + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); + Object value = properties.get(propertyDescriptor); return value instanceof ConcurrentHashMap; } diff --git a/src/test/java/org/spdx/library/model/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/ModelCollectionTest.java index b2efc3633..b60015ec4 100644 --- a/src/test/java/org/spdx/library/model/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/ModelCollectionTest.java @@ -6,12 +6,14 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants; +import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; public class ModelCollectionTest extends TestCase { - static final String PROPERTY_NAME = "property"; + static final PropertyDescriptor PROPERTY_NAME = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); static final String[] ELEMENTS = new String[] {"e1", "e2", "e3", "e4"}; GenericModelObject gmo; diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/ModelObjectTest.java index 80ab3b381..eed88403d 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/ModelObjectTest.java @@ -45,6 +45,7 @@ import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.ModelUpdate; +import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -57,29 +58,52 @@ public class ModelObjectTest extends TestCase { private static final String TEST_ID = "testId"; private static final Object TEST_VALUE1 = "value1"; - private static final String TEST_PROPERTY1 = "property1"; - private static final String TEST_PROPERTY2 = "property2"; + private static final PropertyDescriptor TEST_PROPERTY1 = new PropertyDescriptor("property1", SpdxConstants.SPDX_NAMESPACE); + private static final PropertyDescriptor TEST_PROPERTY2 = new PropertyDescriptor("property2", SpdxConstants.SPDX_NAMESPACE); static final String TEST_TYPE1 = SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION; static final String TEST_TYPE2 = SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO; - static final String[] TEST_STRING_VALUE_PROPERTIES = new String[] {"valueProp1", "valueProp2", "valueProp3"}; + static final PropertyDescriptor[] TEST_STRING_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("valueProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstants.SPDX_NAMESPACE)}; static final Object[] TEST_STRING_VALUE_PROPERTY_VALUES = new Object[] {"value1", "value2", "value3"}; - static final String[] TEST_INTEGER_VALUE_PROPERTIES = new String[] {"intProp1", "intProp2", "Intprop3"}; + static final PropertyDescriptor[] TEST_INTEGER_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("intProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("intProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("Intprop3", SpdxConstants.SPDX_NAMESPACE)}; static final Object[] TEST_INTEGER_VALUE_PROPERTY_VALUES = new Object[] {Integer.valueOf(3), Integer.valueOf(0), Integer.valueOf(-1)}; - static final String[] TEST_BOOLEAN_VALUE_PROPERTIES = new String[] {"boolProp1", "boolProp2"}; + static final PropertyDescriptor[] TEST_BOOLEAN_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("boolProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("boolProp2", SpdxConstants.SPDX_NAMESPACE)}; static final Object[] TEST_BOOLEAN_VALUE_PROPERTY_VALUES = new Object[] {true, false}; - static final String[] TEST_LIST_PROPERTIES = new String[] {"listProp1", "listProp2", "listProp3", "listProp4", "listProp5"}; - static final String[] TEST_MODEL_OJBECT_PROPERTIES = new String[] {"typeProp1", "typeProp2"}; - static final String[] TEST_ENUM_PROPERTIES = new String[] {"enumProp1", "enumProp2"}; + static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("listProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp4", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp5", SpdxConstants.SPDX_NAMESPACE)}; + static final PropertyDescriptor[] TEST_MODEL_OJBECT_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("typeProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("typeProp2", SpdxConstants.SPDX_NAMESPACE)}; + static final PropertyDescriptor[] TEST_ENUM_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("enumProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("enumProp2", SpdxConstants.SPDX_NAMESPACE)}; static final ChecksumAlgorithm[] TEST_ENUM_VALUES = new ChecksumAlgorithm[] {ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1}; - static final String[] TEST_ANYLICENSEINFO_PROPERTIES = new String[] {"anylicenseProp1", "anylicenseProp2", "anylicenseProp3"}; - static final String[] TEST_ANYLICENSEINFO_LIST_PROPERTIES = new String[] {"anylicenseListProp1", "anylicensListProp2", "anylicenseListProp3"}; + static final PropertyDescriptor[] TEST_ANYLICENSEINFO_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("anylicenseProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("anylicenseProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("anylicenseProp3", SpdxConstants.SPDX_NAMESPACE)}; + static final PropertyDescriptor[] TEST_ANYLICENSEINFO_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("anylicenseListProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("anylicensListProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("anylicenseListProp3", SpdxConstants.SPDX_NAMESPACE)}; ModelObject[] TEST_MODEL_OBJECT_PROP_VALUES; List[] TEST_LIST_PROPERTY_VALUES; AnyLicenseInfo[] TEST_ANYLICENSEINFO_PROP_VALUES; List[] TEST_ANYLICENSEINFO_LIST_PROP_VALUES; - Map ALL_PROPERTY_VALUES; + Map ALL_PROPERTY_VALUES; IModelStore store; String docUri; @@ -115,28 +139,36 @@ protected void setUp() throws Exception { ALL_PROPERTY_VALUES = new HashMap<>(); for (int i = 0; i < TEST_STRING_VALUE_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_STRING_VALUE_PROPERTIES[i], TEST_STRING_VALUE_PROPERTY_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_STRING_VALUE_PROPERTIES[i], + TEST_STRING_VALUE_PROPERTY_VALUES[i]); } for (int i = 0; i < TEST_BOOLEAN_VALUE_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_BOOLEAN_VALUE_PROPERTIES[i], TEST_BOOLEAN_VALUE_PROPERTY_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_BOOLEAN_VALUE_PROPERTIES[i], + TEST_BOOLEAN_VALUE_PROPERTY_VALUES[i]); } for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_LIST_PROPERTIES[i], TEST_LIST_PROPERTY_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_LIST_PROPERTIES[i], + TEST_LIST_PROPERTY_VALUES[i]); } for (int i = 0; i < TEST_MODEL_OJBECT_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_MODEL_OJBECT_PROPERTIES[i], TEST_MODEL_OBJECT_PROP_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_MODEL_OJBECT_PROPERTIES[i], + TEST_MODEL_OBJECT_PROP_VALUES[i]); } for (int i = 0; i < TEST_ENUM_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_ENUM_PROPERTIES[i], TEST_ENUM_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_ENUM_PROPERTIES[i], + TEST_ENUM_VALUES[i]); } for (int i = 0; i < TEST_ANYLICENSEINFO_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_PROPERTIES[i], TEST_ANYLICENSEINFO_PROP_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_PROPERTIES[i], + TEST_ANYLICENSEINFO_PROP_VALUES[i]); } for (int i = 0; i < TEST_ANYLICENSEINFO_LIST_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_LIST_PROPERTIES[i], TEST_ANYLICENSEINFO_LIST_PROP_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_LIST_PROPERTIES[i], + TEST_ANYLICENSEINFO_LIST_PROP_VALUES[i]); } for (int i = 0; i < TEST_INTEGER_VALUE_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_INTEGER_VALUE_PROPERTIES[i], TEST_INTEGER_VALUE_PROPERTY_VALUES[i]); + ALL_PROPERTY_VALUES.put(TEST_INTEGER_VALUE_PROPERTIES[i], + TEST_INTEGER_VALUE_PROPERTY_VALUES[i]); } } /* (non-Javadoc) @@ -147,7 +179,7 @@ protected void tearDown() throws Exception { } protected void addTestValues(ModelObject mo) throws InvalidSPDXAnalysisException { - for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { + for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { mo.setPropertyValue(entry.getKey(), entry.getValue()); } } @@ -254,16 +286,16 @@ public void testGetModelStore() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getPropertyValueNames()}. + * Test method for {@link org.spdx.library.model.ModelObject#getPropertyValueDescriptors()}. */ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - List result = gmo.getPropertyValueNames(); + List result = gmo.getPropertyValueDescriptors(); assertEquals(0, result.size()); addTestValues(gmo); - result = gmo.getPropertyValueNames(); + result = gmo.getPropertyValueDescriptors(); assertEquals(ALL_PROPERTY_VALUES.size(), result.size()); - for (String property:ALL_PROPERTY_VALUES.keySet()) { + for (PropertyDescriptor property:ALL_PROPERTY_VALUES.keySet()) { assertTrue(result.contains(property)); } } @@ -273,9 +305,9 @@ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { */ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - assertEquals(0, gmo.getPropertyValueNames().size()); + assertEquals(0, gmo.getPropertyValueDescriptors().size()); addTestValues(gmo); - for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { + for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { Optional result = gmo.getObjectPropertyValue(entry.getKey()); assertTrue(result.isPresent()); if (result.get() instanceof List) { @@ -296,7 +328,7 @@ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { */ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - String prop = "property"; + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); gmo.setPropertyValue(prop, val); @@ -309,7 +341,7 @@ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { */ public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - String prop = "property"; + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); ModelUpdate mu = gmo.updatePropertyValue(prop, val); @@ -372,7 +404,7 @@ public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { */ public void testRemovePropertyIModelStoreStringStringString() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - String prop = "property"; + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); gmo.setPropertyValue(prop, val); @@ -387,7 +419,7 @@ public void testRemovePropertyIModelStoreStringStringString() throws InvalidSPDX */ public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - String prop = "property"; + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); gmo.setPropertyValue(prop, val); @@ -633,7 +665,7 @@ public void testEquivalentModelObjectProp() throws InvalidSPDXAnalysisException String id1 = "id1"; String id2 = "id2"; String text = "licenseText"; - String prop = "prop"; + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); ExtractedLicenseInfo eli = new ExtractedLicenseInfo(id1, text); ExtractedLicenseInfo eli2 = new ExtractedLicenseInfo(id2, text); assertTrue(eli.equivalent(eli2)); @@ -657,7 +689,7 @@ public void testEquivalentModelObjectList() throws InvalidSPDXAnalysisException String id1 = "id1"; String id2 = "id2"; String text = "licenseText"; - String prop = "prop"; + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); ExtractedLicenseInfo eli = new ExtractedLicenseInfo(id1, text); ExtractedLicenseInfo eli2 = new ExtractedLicenseInfo(id2, text); String id3 = "id3"; @@ -693,7 +725,7 @@ public void testEquivalentModelObjectList() throws InvalidSPDXAnalysisException public void testListEquivalenceIsSymmetric() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); GenericModelObject gmo2 = new GenericModelObject(store, docUri, "TestId2", copyManager, true); - String property = "property"; + PropertyDescriptor property = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); ExtractedLicenseInfo equivalentLicense = new ExtractedLicenseInfo("id", "licenseText"); ExtractedLicenseInfo equivalentLicense2 = new ExtractedLicenseInfo("id2", "licenseText"); ExtractedLicenseInfo equivalentLicense3 = new ExtractedLicenseInfo("id3", "licenseText"); diff --git a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java index 62e02de1a..fa454bf9d 100644 --- a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java @@ -19,17 +19,17 @@ public class CrossRefJsonTest extends TestCase { static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_CROSS_REF_MATCH, - SpdxConstants.PROP_CROSS_REF_TIMESTAMP, - SpdxConstants.PROP_CROSS_REF_URL); + SpdxConstants.PROP_CROSS_REF_MATCH.getName(), + SpdxConstants.PROP_CROSS_REF_TIMESTAMP.getName(), + SpdxConstants.PROP_CROSS_REF_URL.getName()); static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_CROSS_REF_IS_LIVE, - SpdxConstants.PROP_CROSS_REF_IS_VALID, - SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK + SpdxConstants.PROP_CROSS_REF_IS_LIVE.getName(), + SpdxConstants.PROP_CROSS_REF_IS_VALID.getName(), + SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK.getName() ); - static final List INTEGER_PROPERTY_VALUE_NAMES = Arrays.asList(SpdxConstants.PROP_CROSS_REF_ORDER); + static final List INTEGER_PROPERTY_VALUE_NAMES = Arrays.asList(SpdxConstants.PROP_CROSS_REF_ORDER.getName()); static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java index 1e9b78a09..c8d1a4055 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java @@ -45,16 +45,18 @@ public class ExceptionJsonTest extends TestCase { */ static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_LICENSE_EXCEPTION_ID, SpdxConstants.PROP_EXCEPTION_TEXT, - SpdxConstants.PROP_STD_LICENSE_NAME, SpdxConstants.RDFS_PROP_COMMENT, SpdxConstants.PROP_EXCEPTION_TEMPLATE, - SpdxConstants.PROP_EXAMPLE, SpdxConstants.PROP_LIC_DEPRECATED_VERSION, SpdxConstants.PROP_EXCEPTION_TEXT_HTML + SpdxConstants.PROP_LICENSE_EXCEPTION_ID.getName(), SpdxConstants.PROP_EXCEPTION_TEXT.getName(), + SpdxConstants.PROP_STD_LICENSE_NAME.getName(), SpdxConstants.RDFS_PROP_COMMENT.getName(), + SpdxConstants.PROP_EXCEPTION_TEMPLATE.getName(), + SpdxConstants.PROP_EXAMPLE.getName(), SpdxConstants.PROP_LIC_DEPRECATED_VERSION.getName(), + SpdxConstants.PROP_EXCEPTION_TEXT_HTML.getName() ); static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_LIC_ID_DEPRECATED + SpdxConstants.PROP_LIC_ID_DEPRECATED.getName() ); - static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstants.RDFS_PROP_SEE_ALSO); + static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstants.RDFS_PROP_SEE_ALSO.getName()); static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); static { PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); @@ -258,20 +260,20 @@ public void testLegacyJson() throws Exception { public void testIsCollectionMembersAssignableTo() throws Exception { String exceptionId = "excId"; ExceptionJson ej = new ExceptionJson(exceptionId); - assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO, String.class)); - assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO, Boolean.class)); - assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT, String.class)); + assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); + assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT.getName(), String.class)); } public void testIsPropertyValueAssignableTo() throws Exception { String exceptionId = "excId"; ExceptionJson ej = new ExceptionJson(exceptionId); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO, String.class)); - assertTrue(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT, String.class)); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT, Boolean.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertTrue(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT.getName(), String.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT.getName(), Boolean.class)); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED, String.class)); - assertTrue(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED, Boolean.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), String.class)); + assertTrue(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); } @SuppressWarnings("deprecation") diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java index 3ddfb2c14..2070ae5f3 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java @@ -42,17 +42,22 @@ public class LicenseJsonTest extends TestCase { static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_LICENSE_ID, SpdxConstants.PROP_LICENSE_TEXT, SpdxConstants.PROP_LICENSE_TEXT_HTML, - SpdxConstants.PROP_STD_LICENSE_NAME, SpdxConstants.RDFS_PROP_COMMENT, SpdxConstants.PROP_STD_LICENSE_NOTICE,SpdxConstants.PROP_STD_LICENSE_HEADER_TEMPLATE, - SpdxConstants.PROP_LICENSE_HEADER_HTML, SpdxConstants.PROP_STD_LICENSE_TEMPLATE, SpdxConstants.PROP_EXAMPLE, SpdxConstants.PROP_LIC_DEPRECATED_VERSION + SpdxConstants.PROP_LICENSE_ID.getName(), SpdxConstants.PROP_LICENSE_TEXT.getName(), + SpdxConstants.PROP_LICENSE_TEXT_HTML.getName(), + SpdxConstants.PROP_STD_LICENSE_NAME.getName(), SpdxConstants.RDFS_PROP_COMMENT.getName(), + SpdxConstants.PROP_STD_LICENSE_NOTICE.getName(), SpdxConstants.PROP_STD_LICENSE_HEADER_TEMPLATE.getName(), + SpdxConstants.PROP_LICENSE_HEADER_HTML.getName(), SpdxConstants.PROP_STD_LICENSE_TEMPLATE.getName(), + SpdxConstants.PROP_EXAMPLE.getName(), SpdxConstants.PROP_LIC_DEPRECATED_VERSION.getName() ); static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_STD_LICENSE_OSI_APPROVED, SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE, SpdxConstants.PROP_LIC_ID_DEPRECATED + SpdxConstants.PROP_STD_LICENSE_OSI_APPROVED.getName(), SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE.getName(), + SpdxConstants.PROP_LIC_ID_DEPRECATED.getName() ); static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); - static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstants.RDFS_PROP_SEE_ALSO, SpdxConstants.PROP_CROSS_REF); + static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), + SpdxConstants.PROP_CROSS_REF.getName()); static { PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); PROPERTY_VALUE_NAMES.addAll(BOOLEAN_PROPERTY_VALUE_NAMES); @@ -358,21 +363,21 @@ public void testRemoveProperty() throws InvalidSpdxPropertyException { public void testIsCollectionMembersAssignableTo() throws Exception { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO, String.class)); - assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO, Boolean.class)); - assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstants.PROP_LICENSE_TEXT, String.class)); - assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstants.PROP_CROSS_REF, CrossRef.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); + assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstants.PROP_LICENSE_TEXT.getName(), String.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstants.PROP_CROSS_REF.getName(), CrossRef.class)); } public void testIsPropertyValueAssignableTo() throws Exception { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO, String.class)); - assertTrue(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LICENSE_TEXT, String.class)); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LICENSE_TEXT, Boolean.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertTrue(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LICENSE_TEXT.getName(), String.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LICENSE_TEXT.getName(), Boolean.class)); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED, String.class)); - assertTrue(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED, Boolean.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), String.class)); + assertTrue(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); } public void testCopyFromLicense() throws Exception { diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index 632cfa1cb..19901c519 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -37,6 +37,7 @@ import org.spdx.library.SpdxConstants; import org.spdx.library.model.SpdxIdInUseException; import org.spdx.library.model.TypedValue; +import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -61,9 +62,16 @@ public class InMemSpdxStoreTest extends TestCase { static final String TEST_TYPE1 = SpdxConstants.CLASS_ANNOTATION; static final String TEST_TYPE2 = SpdxConstants.CLASS_RELATIONSHIP; - static final String[] TEST_VALUE_PROPERTIES = new String[] {"valueProp1", "valueProp2", "valueProp3", "valueProp4"}; + static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("valueProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp4", SpdxConstants.SPDX_NAMESPACE)}; static final Object[] TEST_VALUE_PROPERTY_VALUES = new Object[] {"value1", true, "value2", null}; - static final String[] TEST_LIST_PROPERTIES = new String[] {"listProp1", "listProp2", "listProp3"}; + static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("listProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstants.SPDX_NAMESPACE)}; protected static final int MAX_RETRIES = 10; TypedValue[] TEST_TYPED_PROP_VALUES; @@ -161,9 +169,9 @@ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); - assertEquals(0, store.getPropertyValueNames(TEST_DOCUMENT_URI1, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueNames(TEST_DOCUMENT_URI2, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueNames(TEST_DOCUMENT_URI1, TEST_ID2).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { if (TEST_VALUE_PROPERTY_VALUES[i] instanceof TypedValue) { TypedValue tv = (TypedValue)TEST_VALUE_PROPERTY_VALUES[i]; @@ -180,16 +188,16 @@ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[i], value); } } - List result = store.getPropertyValueNames(TEST_DOCUMENT_URI1, TEST_ID1); + List result = store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1); assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, result.size()); - for (String prop:TEST_VALUE_PROPERTIES) { + for (PropertyDescriptor prop:TEST_VALUE_PROPERTIES) { assertTrue(result.contains(prop)); } - for (String prop:TEST_LIST_PROPERTIES) { + for (PropertyDescriptor prop:TEST_LIST_PROPERTIES) { assertTrue(result.contains(prop)); } - assertEquals(0, store.getPropertyValueNames(TEST_DOCUMENT_URI2, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueNames(TEST_DOCUMENT_URI1, TEST_ID2).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); } @@ -546,19 +554,19 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio InMemSpdxStore store = new InMemSpdxStore(); store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); // String - String sProperty = "stringprop"; + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); // Boolean - String bProperty = "boolprop"; + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); // TypedValue - String tvProperty = "tvprop"; + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); TypedValue tv = new TypedValue(TEST_ID2, TEST_TYPE2); store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); @@ -566,7 +574,7 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); // Empty - String emptyProperty = "emptyprop"; + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); } @@ -574,21 +582,21 @@ public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisExcept InMemSpdxStore store = new InMemSpdxStore(); store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); // String - String sProperty = "stringprop"; + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 2"); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); // Boolean - String bProperty = "boolprop"; + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(false)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); // TypedValue - String tvProperty = "tvprop"; + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); TypedValue tv = new TypedValue(TEST_ID2, TEST_TYPE2); store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); @@ -596,14 +604,14 @@ public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisExcept assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); // Mixed - String mixedProperty = "mixedprop"; + PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstants.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.valueOf(true)); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, "mixed value"); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, String.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, TypedValue.class)); // Empty - String emptyProperty = "emptyprop"; + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, Boolean.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, TypedValue.class)); @@ -613,9 +621,9 @@ public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); // String - String sProperty = "stringprop"; + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - String listProperty = "listProp"; + PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstants.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, listProperty, "testValue"); assertTrue(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, listProperty)); assertFalse(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, sProperty)); @@ -690,10 +698,14 @@ public void testDeleteInUse() throws InvalidSPDXAnalysisException { store.create(TEST_DOCUMENT_URI1, id3, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); store.create(TEST_DOCUMENT_URI1, id4, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); TypedValue tv3 = new TypedValue(id3, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.addValueToCollection(TEST_DOCUMENT_URI1, id2, "listProperty", tv3); + store.addValueToCollection(TEST_DOCUMENT_URI1, id2, + new PropertyDescriptor("listProperty", SpdxConstants.SPDX_NAMESPACE), tv3); TypedValue tv4 = new TypedValue(id4, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.addValueToCollection(TEST_DOCUMENT_URI1, id2, "listProperty", tv4); - store.setValue(TEST_DOCUMENT_URI1, id3, "property", new TypedValue(id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); + store.addValueToCollection(TEST_DOCUMENT_URI1, id2, + new PropertyDescriptor("listProperty", SpdxConstants.SPDX_NAMESPACE), tv4); + store.setValue(TEST_DOCUMENT_URI1, id3, + new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE), + new TypedValue(id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); try { store.delete(TEST_DOCUMENT_URI1, id3); @@ -713,7 +725,8 @@ public void testDeleteInUse() throws InvalidSPDXAnalysisException { } catch (SpdxIdInUseException ex) { // expected - id1 is in the property for id3 } - store.removeValueFromCollection(TEST_DOCUMENT_URI1, id2, "listProperty", tv4); + store.removeValueFromCollection(TEST_DOCUMENT_URI1, id2, + new PropertyDescriptor("listProperty", SpdxConstants.SPDX_NAMESPACE), tv4); store.delete(TEST_DOCUMENT_URI1, id4); assertFalse(store.exists(TEST_DOCUMENT_URI1, id4)); try { @@ -722,7 +735,8 @@ public void testDeleteInUse() throws InvalidSPDXAnalysisException { } catch (SpdxIdInUseException ex) { // expected - id3 is in the listProperty for id2 } - store.removeProperty(TEST_DOCUMENT_URI1, id3, "property"); + store.removeProperty(TEST_DOCUMENT_URI1, id3, + new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE)); store.delete(TEST_DOCUMENT_URI1, id1); assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); store.delete(TEST_DOCUMENT_URI1, id2); @@ -738,17 +752,23 @@ public void testReferenceCounts() throws Exception { StoredTypedItem item = store.getItem(TEST_DOCUMENT_URI1, TEST_ID1); assertEquals(0, item.getReferenceCount()); TypedValue tv = new TypedValue(TEST_ID1, TEST_TYPE1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, "prop1", tv); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop1", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, "prop2", tv); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(2, item.getReferenceCount()); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, "prop3", tv); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop3", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(3, item.getReferenceCount()); - store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID2, "prop2"); + store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE)); assertEquals(2, item.getReferenceCount()); - store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID2, "prop2", tv); + store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); - store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID2, "prop1"); + store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop1", SpdxConstants.SPDX_NAMESPACE)); assertEquals(0, item.getReferenceCount()); store.delete(TEST_DOCUMENT_URI1, TEST_ID1); } @@ -760,11 +780,14 @@ public void testReferenceCountsDelete() throws Exception { StoredTypedItem item = store.getItem(TEST_DOCUMENT_URI1, TEST_ID1); assertEquals(0, item.getReferenceCount()); TypedValue tv = new TypedValue(TEST_ID1, TEST_TYPE1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, "prop1", tv); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop1", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, "prop2", tv); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(2, item.getReferenceCount()); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, "prop3", tv); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, + new PropertyDescriptor("prop3", SpdxConstants.SPDX_NAMESPACE), tv); assertEquals(3, item.getReferenceCount()); store.delete(TEST_DOCUMENT_URI1, TEST_ID2); assertEquals(0, item.getReferenceCount()); diff --git a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java index 5ecb45cf6..46cb687f2 100644 --- a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java +++ b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java @@ -24,6 +24,7 @@ import org.spdx.library.SpdxConstants; import org.spdx.library.model.Relationship; import org.spdx.library.model.TypedValue; +import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; @@ -39,9 +40,16 @@ public class StoredTypedItemTest extends TestCase { static final String TEST_TYPE2 = SpdxConstants.CLASS_RELATIONSHIP; static final String TEST_DOCUMENTURI1 = "https://test.doc.uri1"; static final String TEST_DOCUMENTURI2 = "https://test.doc.uri2"; - static final String[] TEST_VALUE_PROPERTIES = new String[] {"valueProp1", "valueProp2", "valueProp3", "valueProp4"}; + static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("valueProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp4", SpdxConstants.SPDX_NAMESPACE)}; static final Object[] TEST_VALUE_PROPERTY_VALUES = new Object[] {"value1", true, "value2", null}; - static final String[] TEST_LIST_PROPERTIES = new String[] {"listProp1", "listProp2", "listProp3"}; + static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("listProp1", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstants.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstants.SPDX_NAMESPACE)}; List[] TEST_LIST_PROPERTY_VALUES; /* (non-Javadoc) @@ -82,7 +90,7 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { */ public void testGetSetPropertyValueNames() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); - assertEquals(0, sti.getPropertyValueNames().size()); + assertEquals(0, sti.getPropertyValueDescriptors().size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { sti.setValue(TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); } @@ -91,12 +99,12 @@ public void testGetSetPropertyValueNames() throws InvalidSPDXAnalysisException { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); } } - List result = sti.getPropertyValueNames(); + List result = sti.getPropertyValueDescriptors(); assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, result.size()); - for (String prop:TEST_VALUE_PROPERTIES) { + for (PropertyDescriptor prop:TEST_VALUE_PROPERTIES) { assertTrue(result.contains(prop)); } - for (String prop:TEST_LIST_PROPERTIES) { + for (PropertyDescriptor prop:TEST_LIST_PROPERTIES) { assertTrue(result.contains(prop)); } } @@ -165,7 +173,7 @@ public void testGetValueList() throws InvalidSPDXAnalysisException { public void testRemove() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); - assertEquals(0, sti.getPropertyValueNames().size()); + assertEquals(0, sti.getPropertyValueDescriptors().size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { sti.setValue(TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); } @@ -174,10 +182,10 @@ public void testRemove() throws InvalidSPDXAnalysisException { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); } } - assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, sti.getPropertyValueNames().size()); + assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, sti.getPropertyValueDescriptors().size()); sti.removeProperty(TEST_VALUE_PROPERTIES[0]); sti.removeProperty(TEST_LIST_PROPERTIES[0]); - assertEquals(TEST_VALUE_PROPERTIES.length-1+TEST_LIST_PROPERTIES.length-1, sti.getPropertyValueNames().size()); + assertEquals(TEST_VALUE_PROPERTIES.length-1+TEST_LIST_PROPERTIES.length-1, sti.getPropertyValueDescriptors().size()); assertTrue(sti.getValue(TEST_VALUE_PROPERTIES[0]) == null); assertTrue(sti.getValue(TEST_LIST_PROPERTIES[0]) == null); } @@ -212,34 +220,34 @@ public void testCollectionContains() throws InvalidSPDXAnalysisException { public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); // String - String sProperty = "stringprop"; + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); sti.addValueToList(sProperty, "String 1"); sti.addValueToList(sProperty, "String 2"); assertTrue(sti.isCollectionMembersAssignableTo(sProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(sProperty, Boolean.class)); assertFalse(sti.isCollectionMembersAssignableTo(sProperty, TypedValue.class)); // Boolean - String bProperty = "boolprop"; + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); sti.addValueToList(bProperty, Boolean.valueOf(true)); sti.addValueToList(bProperty, Boolean.valueOf(false)); assertFalse(sti.isCollectionMembersAssignableTo(bProperty, String.class)); assertTrue(sti.isCollectionMembersAssignableTo(bProperty, Boolean.class)); assertFalse(sti.isCollectionMembersAssignableTo(bProperty, TypedValue.class)); // TypedValue - String tvProperty = "tvprop"; + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); sti.addValueToList(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, Boolean.class)); assertTrue(sti.isCollectionMembersAssignableTo(tvProperty, Relationship.class)); // Mixed - String mixedProperty = "mixedprop"; + PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstants.SPDX_NAMESPACE); sti.addValueToList(mixedProperty, Boolean.valueOf(true)); sti.addValueToList(mixedProperty, "mixed value"); assertFalse(sti.isCollectionMembersAssignableTo(mixedProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(mixedProperty, Boolean.class)); assertFalse(sti.isCollectionMembersAssignableTo(mixedProperty, TypedValue.class)); // Empty - String emptyProperty = "emptyprop"; + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); assertTrue(sti.isCollectionMembersAssignableTo(emptyProperty, String.class)); assertTrue(sti.isCollectionMembersAssignableTo(emptyProperty, Boolean.class)); assertTrue(sti.isCollectionMembersAssignableTo(emptyProperty, TypedValue.class)); @@ -248,34 +256,34 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); // String - String sProperty = "stringprop"; + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); assertTrue(sti.isPropertyValueAssignableTo(sProperty, String.class)); assertFalse(sti.isPropertyValueAssignableTo(sProperty, Boolean.class)); assertFalse(sti.isPropertyValueAssignableTo(sProperty, TypedValue.class)); // Boolean - String bProperty = "boolprop"; + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); sti.setValue(bProperty, Boolean.valueOf(true)); assertFalse(sti.isPropertyValueAssignableTo(bProperty, String.class)); assertTrue(sti.isPropertyValueAssignableTo(bProperty, Boolean.class)); assertFalse(sti.isPropertyValueAssignableTo(bProperty, TypedValue.class)); // TypedValue - String tvProperty = "tvprop"; + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); sti.setValue(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); assertFalse(sti.isPropertyValueAssignableTo(tvProperty, String.class)); assertFalse(sti.isPropertyValueAssignableTo(tvProperty, Boolean.class)); assertTrue(sti.isPropertyValueAssignableTo(tvProperty, TypedValue.class)); // Empty - String emptyProperty = "emptyprop"; + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); assertFalse(sti.isPropertyValueAssignableTo(emptyProperty, String.class)); } public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); // String - String sProperty = "stringprop"; + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); - String listProperty = "listProp"; + PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstants.SPDX_NAMESPACE); sti.addValueToList(listProperty, "testValue"); assertTrue(sti.isCollectionProperty(listProperty)); assertFalse(sti.isCollectionProperty(sProperty)); From a820f1bc3407a1d0c0649361cfe299190a364d40 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 2 Jun 2023 20:36:19 -0700 Subject: [PATCH 02/62] Rename existing model to compat.v2 Signed-off-by: Gary O'Neall --- .../org/spdx/library/ModelCopyManager.java | 12 +- src/main/java/org/spdx/library/Read.java | 14 +- ...stants.java => SpdxConstantsCompatV2.java} | 2 +- .../spdx/library/SpdxVerificationHelper.java | 18 +- src/main/java/org/spdx/library/Version.java | 2 +- .../spdx/library/model/SpdxModelFactory.java | 319 ------------------ .../model/{ => compat/v2}/Annotation.java | 28 +- .../model/{ => compat/v2}/Checksum.java | 20 +- .../v2}/DuplicateSpdxIdException.java | 2 +- .../{ => compat/v2}/ExternalDocumentRef.java | 42 +-- .../model/{ => compat/v2}/ExternalRef.java | 30 +- .../{ => compat/v2}/ExternalSpdxElement.java | 29 +- .../{ => compat/v2}/GenericModelObject.java | 6 +- .../{ => compat/v2}/GenericSpdxElement.java | 4 +- .../{ => compat/v2}/GenericSpdxItem.java | 4 +- .../{ => compat/v2}/IndividualUriValue.java | 2 +- .../v2}/InvalidSpdxPropertyException.java | 2 +- .../{ => compat/v2}/ModelCollection.java | 12 +- .../model/{ => compat/v2}/ModelObject.java | 78 ++--- .../model/{ => compat/v2}/ModelSet.java | 2 +- .../v2}/ModelStorageClassConverter.java | 2 +- .../model/{ => compat/v2}/ReferenceType.java | 2 +- .../v2}/RelatedElementCollection.java | 8 +- .../model/{ => compat/v2}/Relationship.java | 24 +- .../model/{ => compat/v2}/SimpleUriValue.java | 24 +- .../{ => compat/v2}/SpdxConstantElement.java | 8 +- .../v2}/SpdxCreatorInformation.java | 26 +- .../model/{ => compat/v2}/SpdxDocument.java | 46 +-- .../model/{ => compat/v2}/SpdxElement.java | 18 +- .../model/{ => compat/v2}/SpdxFile.java | 32 +- .../{ => compat/v2}/SpdxIdInUseException.java | 2 +- .../v2}/SpdxIdNotFoundException.java | 2 +- .../v2}/SpdxInvalidTypeException.java | 2 +- .../model/{ => compat/v2}/SpdxItem.java | 28 +- .../model/compat/v2/SpdxModelFactory.java | 319 ++++++++++++++++++ .../v2}/SpdxNoAssertionElement.java | 8 +- .../{ => compat/v2}/SpdxNoneElement.java | 8 +- .../model/{ => compat/v2}/SpdxPackage.java | 104 +++--- .../v2}/SpdxPackageVerificationCode.java | 18 +- .../model/{ => compat/v2}/SpdxSnippet.java | 28 +- .../model/{ => compat/v2}/TypedValue.java | 6 +- .../v2}/enumerations/AnnotationType.java | 8 +- .../v2}/enumerations/ChecksumAlgorithm.java | 8 +- .../v2}/enumerations/FileType.java | 8 +- .../{ => compat/v2}/enumerations/Purpose.java | 8 +- .../v2}/enumerations/ReferenceCategory.java | 8 +- .../v2}/enumerations/RelationshipType.java | 8 +- .../v2}/enumerations/SpdxEnumFactory.java | 2 +- .../v2}/enumerations/package-info.java | 2 +- .../license/AbstractExtractedLicenseInfo.java | 4 +- .../v2}/license/AnyLicenseInfo.java | 4 +- .../v2}/license/ConjunctiveLicenseSet.java | 10 +- .../{ => compat/v2}/license/CrossRef.java | 66 ++-- .../v2}/license/DisjunctiveLicenseSet.java | 10 +- .../license/ExternalExtractedLicenseInfo.java | 54 +-- .../v2}/license/ExtractedLicenseInfo.java | 16 +- .../InvalidLicenseStringException.java | 2 +- .../{ => compat/v2}/license/License.java | 44 +-- .../v2}/license/LicenseException.java | 54 +-- .../v2}/license/LicenseExpressionParser.java | 24 +- .../v2}/license/LicenseInfoFactory.java | 2 +- .../v2}/license/LicenseParserException.java | 2 +- .../{ => compat/v2}/license/LicenseSet.java | 10 +- .../v2}/license/ListedLicenseException.java | 16 +- .../v2}/license/ListedLicenses.java | 14 +- .../v2}/license/OrLaterOperator.java | 12 +- .../v2}/license/SimpleLicensingInfo.java | 26 +- .../v2}/license/SpdxListedLicense.java | 28 +- .../license/SpdxListedLicenseException.java | 2 +- .../v2}/license/SpdxNoAssertionLicense.java | 14 +- .../v2}/license/SpdxNoneLicense.java | 14 +- .../v2}/license/WithExceptionOperator.java | 32 +- .../{ => compat/v2}/license/package-info.java | 2 +- .../model/{ => compat/v2}/package-info.java | 2 +- .../v2}/pointer/ByteOffsetPointer.java | 14 +- .../v2}/pointer/CompoundPointer.java | 16 +- .../v2}/pointer/LineCharPointer.java | 14 +- .../v2}/pointer/SinglePointer.java | 16 +- .../v2}/pointer/StartEndPointer.java | 16 +- .../{ => compat/v2}/pointer/package-info.java | 2 +- .../java/org/spdx/library/package-info.java | 2 +- .../{ => compat/v2}/ListedReferenceTypes.java | 14 +- .../v2}/listedreferencetypes.properties | 0 .../{ => compat/v2}/package-info.java | 2 +- .../java/org/spdx/storage/IModelStore.java | 4 +- .../storage/listedlicense/CrossRefJson.java | 4 +- .../storage/listedlicense/ExceptionJson.java | 10 +- .../listedlicense/ExceptionJsonTOC.java | 2 +- .../storage/listedlicense/LicenseJson.java | 20 +- .../storage/listedlicense/LicenseJsonTOC.java | 6 +- .../SpdxListedLicenseModelStore.java | 166 ++++----- .../SpdxListedLicenseWebStore.java | 8 +- .../storage/simple/ExtendedSpdxStore.java | 2 +- .../spdx/storage/simple/InMemSpdxStore.java | 34 +- .../spdx/storage/simple/StoredTypedItem.java | 24 +- .../utility/compare/LicenseCompareHelper.java | 20 +- .../spdx/utility/compare/SpdxComparer.java | 30 +- .../compare/SpdxExternalRefDifference.java | 6 +- .../utility/compare/SpdxFileComparer.java | 14 +- .../utility/compare/SpdxFileDifference.java | 12 +- .../utility/compare/SpdxItemComparer.java | 10 +- .../utility/compare/SpdxItemDifference.java | 8 +- .../compare/SpdxLicenseDifference.java | 2 +- .../utility/compare/SpdxPackageComparer.java | 12 +- .../utility/compare/SpdxSnippetComparer.java | 10 +- .../VerificationCodeGenerator.java | 4 +- .../library/SpdxVerificationHelperTest.java | 8 +- .../model/{ => compat/v2}/AnnotationTest.java | 26 +- .../v2}/ByteOffsetPointerTest.java | 7 +- .../model/{ => compat/v2}/ChecksumTest.java | 26 +- .../v2}/ExternalDocumentRefTest.java | 31 +- .../{ => compat/v2}/ExternalRefTest.java | 36 +- .../v2}/ExternalSpdxElementTest.java | 26 +- .../v2}/IndividualUriValueTest.java | 33 +- .../{ => compat/v2}/LineCharPointerTest.java | 13 +- .../{ => compat/v2}/ModelCollectionTest.java | 8 +- .../{ => compat/v2}/ModelObjectTest.java | 170 +++++----- .../v2}/ModelStorageClassConverterTest.java | 38 ++- .../v2}/NoAssertionElementTest.java | 7 +- .../v2}/RelatedElementCollectionTest.java | 37 +- .../{ => compat/v2}/RelationshipTest.java | 42 ++- .../{ => compat/v2}/SimpleUriValueTest.java | 17 +- .../v2}/SpdxConstantElementTest.java | 33 +- .../v2}/SpdxCreatorInformationTest.java | 16 +- .../{ => compat/v2}/SpdxDocumentTest.java | 47 ++- .../{ => compat/v2}/SpdxElementTest.java | 25 +- .../model/{ => compat/v2}/SpdxFileTest.java | 57 ++-- .../{ => compat/v2}/SpdxModelFactoryTest.java | 38 ++- .../{ => compat/v2}/SpdxNoneElementTest.java | 7 +- .../{ => compat/v2}/SpdxPackageTest.java | 107 +++--- .../v2}/SpdxPackageVerificationCodeTest.java | 9 +- .../{ => compat/v2}/SpdxSnippetTest.java | 82 ++--- .../{ => compat/v2}/StartEndPointerTest.java | 21 +- .../license/ConjunctiveLicenseSetTest.java | 12 +- .../{ => compat/v2}/license/CrossRefTest.java | 6 +- .../v2}/license/DisjunctiveLiceseSetTest.java | 12 +- .../v2}/license/ExternalLicenseRefTest.java | 58 ++-- .../license/ExtractedLicensingInfoTest.java | 30 +- .../v2}/license/LicenseExceptionTest.java | 6 +- .../license/LicenseExpressionParserTest.java | 22 +- .../v2}/license/LicenseInfoFactoryTest.java | 12 +- .../v2}/license/ListedLicensesTest.java | 14 +- .../v2}/license/OrLaterOperatorTest.java | 2 +- .../v2}/license/SpdxListedLicenseTest.java | 10 +- .../license/SpdxNoAssertionLicenseTest.java | 2 +- .../v2}/license/SpdxNoneLicenseTest.java | 4 +- .../license/WithExceptionOperatorTest.java | 10 +- .../ListedReferenceTypesTest.java | 17 +- .../listedlicense/CrossRefJsonTest.java | 20 +- .../listedlicense/ExceptionJsonTOCTest.java | 4 +- .../listedlicense/ExceptionJsonTest.java | 40 +-- .../listedlicense/LicenseJsonTOCTest.java | 14 +- .../listedlicense/LicenseJsonTest.java | 50 +-- .../SpdxListedLicenseLocalStoreTest.java | 150 ++++---- .../SpdxListedLicenseWebStoreTest.java | 134 ++++---- .../storage/simple/InMemSpdxStoreTest.java | 186 +++++----- .../storage/simple/StoredTypedItemTest.java | 46 +-- .../compare/LicenseCompareHelperTest.java | 20 +- .../utility/compare/SpdxComparerTest.java | 120 +++---- .../utility/compare/SpdxFileComparerTest.java | 18 +- .../utility/compare/SpdxItemComparerTest.java | 24 +- .../compare/SpdxPackageComparerTest.java | 42 +-- .../compare/SpdxSnippetComparerTest.java | 28 +- .../spdx/utility/compare/UnitTestHelper.java | 4 +- .../VerificationCodeGeneratorTest.java | 10 +- 165 files changed, 2297 insertions(+), 2160 deletions(-) rename src/main/java/org/spdx/library/{SpdxConstants.java => SpdxConstantsCompatV2.java} (99%) delete mode 100644 src/main/java/org/spdx/library/model/SpdxModelFactory.java rename src/main/java/org/spdx/library/model/{ => compat/v2}/Annotation.java (90%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/Checksum.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/DuplicateSpdxIdException.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ExternalDocumentRef.java (88%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ExternalRef.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ExternalSpdxElement.java (91%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/GenericModelObject.java (91%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/GenericSpdxElement.java (94%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/GenericSpdxItem.java (93%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/IndividualUriValue.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/InvalidSpdxPropertyException.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ModelCollection.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ModelObject.java (95%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ModelSet.java (98%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ModelStorageClassConverter.java (99%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/ReferenceType.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/RelatedElementCollection.java (98%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/Relationship.java (89%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SimpleUriValue.java (82%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxConstantElement.java (94%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxCreatorInformation.java (89%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxDocument.java (88%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxElement.java (93%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxFile.java (93%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxIdInUseException.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxIdNotFoundException.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxInvalidTypeException.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxItem.java (85%) create mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxNoAssertionElement.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxNoneElement.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxPackage.java (91%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxPackageVerificationCode.java (85%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/SpdxSnippet.java (95%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/TypedValue.java (91%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/AnnotationType.java (85%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/ChecksumAlgorithm.java (89%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/FileType.java (87%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/Purpose.java (87%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/ReferenceCategory.java (86%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/RelationshipType.java (94%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/SpdxEnumFactory.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/package-info.java (94%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/AbstractExtractedLicenseInfo.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/AnyLicenseInfo.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/ConjunctiveLicenseSet.java (95%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/CrossRef.java (82%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/DisjunctiveLicenseSet.java (95%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/ExternalExtractedLicenseInfo.java (81%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/ExtractedLicenseInfo.java (90%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/InvalidLicenseStringException.java (88%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/License.java (87%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/LicenseException.java (78%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/LicenseExpressionParser.java (94%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/LicenseInfoFactory.java (99%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/LicenseParserException.java (88%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/LicenseSet.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/ListedLicenseException.java (90%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/ListedLicenses.java (94%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/OrLaterOperator.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/SimpleLicensingInfo.java (78%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/SpdxListedLicense.java (93%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/SpdxListedLicenseException.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/SpdxNoAssertionLicense.java (85%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/SpdxNoneLicense.java (85%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/WithExceptionOperator.java (87%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/license/package-info.java (93%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/package-info.java (95%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/pointer/ByteOffsetPointer.java (90%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/pointer/CompoundPointer.java (87%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/pointer/LineCharPointer.java (90%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/pointer/SinglePointer.java (90%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/pointer/StartEndPointer.java (92%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/pointer/package-info.java (96%) rename src/main/java/org/spdx/library/referencetype/{ => compat/v2}/ListedReferenceTypes.java (93%) rename src/main/java/org/spdx/library/referencetype/{ => compat/v2}/listedreferencetypes.properties (100%) rename src/main/java/org/spdx/library/referencetype/{ => compat/v2}/package-info.java (94%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/AnnotationTest.java (83%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ByteOffsetPointerTest.java (93%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ChecksumTest.java (89%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ExternalDocumentRefTest.java (83%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ExternalRefTest.java (79%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ExternalSpdxElementTest.java (84%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/IndividualUriValueTest.java (72%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/LineCharPointerTest.java (84%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ModelCollectionTest.java (95%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ModelObjectTest.java (81%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/ModelStorageClassConverterTest.java (84%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/NoAssertionElementTest.java (87%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/RelatedElementCollectionTest.java (88%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/RelationshipTest.java (85%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SimpleUriValueTest.java (78%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxConstantElementTest.java (66%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxCreatorInformationTest.java (85%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxDocumentTest.java (92%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxElementTest.java (90%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxFileTest.java (91%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxModelFactoryTest.java (73%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxNoneElementTest.java (87%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxPackageTest.java (92%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxPackageVerificationCodeTest.java (90%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/SpdxSnippetTest.java (85%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/StartEndPointerTest.java (83%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/ConjunctiveLicenseSetTest.java (93%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/CrossRefTest.java (97%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/DisjunctiveLiceseSetTest.java (92%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/ExternalLicenseRefTest.java (72%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/ExtractedLicensingInfoTest.java (87%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/LicenseExceptionTest.java (98%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/LicenseExpressionParserTest.java (93%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/LicenseInfoFactoryTest.java (93%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/ListedLicensesTest.java (90%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/OrLaterOperatorTest.java (99%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/SpdxListedLicenseTest.java (98%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/SpdxNoAssertionLicenseTest.java (93%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/SpdxNoneLicenseTest.java (91%) rename src/test/java/org/spdx/library/model/{ => compat/v2}/license/WithExceptionOperatorTest.java (95%) diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index d26c2a836..08426f289 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -25,9 +25,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.model.IndividualUriValue; -import org.spdx.library.model.SimpleUriValue; -import org.spdx.library.model.TypedValue; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.SimpleUriValue; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -171,8 +171,8 @@ public void copy(IModelStore toStore, String toDocumentUri, String toId, } putCopiedId(fromStore, fromDocumentUri, fromId, toStore, toDocumentUri, toId); if (!(excludeLicenseDetails && - (SpdxConstants.CLASS_SPDX_LISTED_LICENSE.equals(type) || - SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)))) { + (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(type) || + SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)))) { List propertyDescriptors = fromStore.getPropertyValueDescriptors(fromDocumentUri, fromId); for (PropertyDescriptor propDesc:propertyDescriptors) { if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propDesc)) { @@ -311,7 +311,7 @@ public TypedValue copy(IModelStore toStore, String toDocumentUri, IModelStore fr String toId = getCopiedId(fromStore, fromDocumentUri, sourceId, toStore, toDocumentUri); if (Objects.isNull(toId)) { if (fromStore.getIdType(sourceId) == IdType.Anonymous || toStore.exists(toDocumentUri, sourceId)) { - if (SpdxConstants.CLASS_EXTERNAL_DOC_REF.equals(type)) { + if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { toId = toStore.getNextId(IdType.DocumentRef, toDocumentUri); } else { switch (fromStore.getIdType(sourceId)) { diff --git a/src/main/java/org/spdx/library/Read.java b/src/main/java/org/spdx/library/Read.java index cd2e5aec4..d5dec40ff 100644 --- a/src/main/java/org/spdx/library/Read.java +++ b/src/main/java/org/spdx/library/Read.java @@ -27,11 +27,11 @@ import java.util.Objects; import java.util.stream.Stream; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.SpdxPackage; -import org.spdx.library.model.TypedValue; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.ISerializableModelStore; @@ -89,7 +89,7 @@ public static SpdxDocument get(IModelStore modelStore, String documentUri) throw * @return true if the document exists in the model store */ public static boolean documentExists(IModelStore modelStore, String documentUri) { - return modelStore.exists(documentUri, SpdxConstants.SPDX_DOCUMENT_ID); + return modelStore.exists(documentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID); } } @@ -159,7 +159,7 @@ public static Stream getAllItems(IModelStore modelStore, */ @SuppressWarnings("unchecked") public static Stream getAllPackages(IModelStore modelStore, String documentUri) throws InvalidSPDXAnalysisException { - return (Stream)(getAllItems(modelStore, documentUri, SpdxConstants.CLASS_SPDX_PACKAGE)); + return (Stream)(getAllItems(modelStore, documentUri, SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE)); } /** The following can be achieve by fetching the list of relationships from the element diff --git a/src/main/java/org/spdx/library/SpdxConstants.java b/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java similarity index 99% rename from src/main/java/org/spdx/library/SpdxConstants.java rename to src/main/java/org/spdx/library/SpdxConstantsCompatV2.java index 1120f9a09..1e1dae572 100644 --- a/src/main/java/org/spdx/library/SpdxConstants.java +++ b/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java @@ -26,7 +26,7 @@ * @author Gary O'Neall * */ -public class SpdxConstants { +public class SpdxConstantsCompatV2 { // Namespaces public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; diff --git a/src/main/java/org/spdx/library/SpdxVerificationHelper.java b/src/main/java/org/spdx/library/SpdxVerificationHelper.java index 344d7afef..064724ab5 100644 --- a/src/main/java/org/spdx/library/SpdxVerificationHelper.java +++ b/src/main/java/org/spdx/library/SpdxVerificationHelper.java @@ -26,7 +26,7 @@ import java.util.Objects; import java.util.Set; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; /** * Holds static methods used for verify various property values @@ -71,12 +71,12 @@ public class SpdxVerificationHelper { CHECKSUM_ALGORITHMS_ADDED_23 = Collections.unmodifiableSet(set); } - static final String[] VALID_CREATOR_PREFIXES = new String[] {SpdxConstants.CREATOR_PREFIX_PERSON, - SpdxConstants.CREATOR_PREFIX_ORGANIZATION, SpdxConstants.CREATOR_PREFIX_TOOL}; - static final String[] VALID_ORIGINATOR_SUPPLIER_PREFIXES = new String[] {SpdxConstants.NOASSERTION_VALUE, "Person:", "Organization:"}; + static final String[] VALID_CREATOR_PREFIXES = new String[] {SpdxConstantsCompatV2.CREATOR_PREFIX_PERSON, + SpdxConstantsCompatV2.CREATOR_PREFIX_ORGANIZATION, SpdxConstantsCompatV2.CREATOR_PREFIX_TOOL}; + static final String[] VALID_ORIGINATOR_SUPPLIER_PREFIXES = new String[] {SpdxConstantsCompatV2.NOASSERTION_VALUE, "Person:", "Organization:"}; public static String verifyNonStdLicenseid(String licenseId) { - if (SpdxConstants.LICENSE_ID_PATTERN.matcher(licenseId).matches()) { + if (SpdxConstantsCompatV2.LICENSE_ID_PATTERN.matcher(licenseId).matches()) { return null; } else { return "Invalid license id '"+licenseId+"'. Must start with 'LicenseRef-' " + @@ -246,7 +246,7 @@ public static String verifyAnnotator(String annotator) { * @return */ public static boolean isValidExternalDocRef(String externalDocumentId) { - return SpdxConstants.EXTERNAL_DOC_REF_PATTERN.matcher(externalDocumentId).matches(); + return SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.matcher(externalDocumentId).matches(); } public static boolean isValidUri(String uri) { @@ -286,11 +286,11 @@ public static String verifyChecksumString(String checksum, ChecksumAlgorithm alg public static String verifyDownloadLocation(String downloadLocation) { if (Objects.isNull(downloadLocation)) { return "Download location is null"; - } else if (SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher(downloadLocation).matches()) { + } else if (SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher(downloadLocation).matches()) { return null; } else { return "Invalid download location "+downloadLocation+". Must match the pattern "+ - SpdxConstants.DOWNLOAD_LOCATION_PATTERN.pattern(); + SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.pattern(); } } @@ -299,6 +299,6 @@ public static String verifyDownloadLocation(String downloadLocation) { * @return true if the ID is a valid SPDX ID reference */ public static boolean verifySpdxId(String id) { - return SpdxConstants.SPDX_ELEMENT_REF_PATTERN.matcher(id).matches(); + return SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PATTERN.matcher(id).matches(); } } diff --git a/src/main/java/org/spdx/library/Version.java b/src/main/java/org/spdx/library/Version.java index c3a0d506c..fd58e17cf 100644 --- a/src/main/java/org/spdx/library/Version.java +++ b/src/main/java/org/spdx/library/Version.java @@ -53,7 +53,7 @@ public static String verifySpdxVersion(String spdxVersion) { if (!spdxVersion.startsWith("SPDX-")) { return "Invalid spdx version - must start with 'SPDX-'"; } - Matcher docSpecVersionMatcher = SpdxConstants.SPDX_VERSION_PATTERN.matcher(spdxVersion); + Matcher docSpecVersionMatcher = SpdxConstantsCompatV2.SPDX_VERSION_PATTERN.matcher(spdxVersion); if (!docSpecVersionMatcher.matches()) { return "Invalid spdx version format - must match 'SPDX-M.N'"; } diff --git a/src/main/java/org/spdx/library/model/SpdxModelFactory.java b/src/main/java/org/spdx/library/model/SpdxModelFactory.java deleted file mode 100644 index 83759abe9..000000000 --- a/src/main/java/org/spdx/library/model/SpdxModelFactory.java +++ /dev/null @@ -1,319 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.Purpose; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.CrossRef; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.LicenseException; -import org.spdx.library.model.license.ListedLicenseException; -import org.spdx.library.model.license.ListedLicenses; -import org.spdx.library.model.license.OrLaterOperator; -import org.spdx.library.model.license.SimpleLicensingInfo; -import org.spdx.library.model.license.SpdxListedLicense; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; -import org.spdx.library.model.license.WithExceptionOperator; -import org.spdx.library.model.license.License; -import org.spdx.library.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.CompoundPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.SinglePointer; -import org.spdx.library.model.pointer.StartEndPointer; - -/** - * Factory class to create ModelObjects based on the type - * Types are defined classes in the SpdxConstants class and map to the standard SPDX model - * - * @author Gary O'Neall - * - */ -public class SpdxModelFactory { - - static final Logger logger = LoggerFactory.getLogger(SpdxModelFactory.class); - - public static Map> SPDX_TYPE_TO_CLASS; - public static Map, String> SPDX_CLASS_TO_TYPE; - static { - Map> typeToClass = new HashMap<>(); - typeToClass.put(SpdxConstants.CLASS_SPDX_DOCUMENT, SpdxDocument.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_PACKAGE, SpdxPackage.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_CREATION_INFO, SpdxCreatorInformation.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_CHECKSUM, Checksum.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_ANY_LICENSE_INFO, AnyLicenseInfo.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_SIMPLE_LICENSE_INFO, SimpleLicensingInfo.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, ConjunctiveLicenseSet.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, DisjunctiveLicenseSet.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, ExtractedLicenseInfo.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_LICENSE, License.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_LISTED_LICENSE, SpdxListedLicense.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION, LicenseException.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, ListedLicenseException.class); - typeToClass.put(SpdxConstants.CLASS_OR_LATER_OPERATOR, OrLaterOperator.class); - typeToClass.put(SpdxConstants.CLASS_WITH_EXCEPTION_OPERATOR, WithExceptionOperator.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_FILE, SpdxFile.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_VERIFICATIONCODE, SpdxPackageVerificationCode.class); - typeToClass.put(SpdxConstants.CLASS_ANNOTATION, Annotation.class); - typeToClass.put(SpdxConstants.CLASS_RELATIONSHIP, Relationship.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_ITEM, SpdxItem.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_ELEMENT, SpdxElement.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_NONE_ELEMENT, SpdxNoneElement.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_NOASSERTION_ELEMENT, SpdxNoAssertionElement.class); - typeToClass.put(SpdxConstants.CLASS_EXTERNAL_DOC_REF, ExternalDocumentRef.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_EXTERNAL_REFERENCE, ExternalRef.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_REFERENCE_TYPE, ReferenceType.class); - typeToClass.put(SpdxConstants.CLASS_SPDX_SNIPPET, SpdxSnippet.class); - typeToClass.put(SpdxConstants.CLASS_NOASSERTION_LICENSE, SpdxNoAssertionLicense.class); - typeToClass.put(SpdxConstants.CLASS_NONE_LICENSE, SpdxNoneLicense.class); - typeToClass.put(GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, GenericModelObject.class); - typeToClass.put(GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, GenericSpdxElement.class); - typeToClass.put(GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, GenericSpdxItem.class); - typeToClass.put(SpdxConstants.CLASS_EXTERNAL_SPDX_ELEMENT, ExternalSpdxElement.class); - typeToClass.put(SpdxConstants.CLASS_POINTER_START_END_POINTER, StartEndPointer.class); - typeToClass.put(SpdxConstants.CLASS_POINTER_BYTE_OFFSET_POINTER, ByteOffsetPointer.class); - typeToClass.put(SpdxConstants.CLASS_POINTER_LINE_CHAR_POINTER, LineCharPointer.class); - typeToClass.put(SpdxConstants.CLASS_POINTER_COMPOUNT_POINTER, CompoundPointer.class); - typeToClass.put(SpdxConstants.CLASS_SINGLE_POINTER, SinglePointer.class); - typeToClass.put(SpdxConstants.CLASS_CROSS_REF, CrossRef.class); - typeToClass.put(SpdxConstants.ENUM_FILE_TYPE, FileType.class); - typeToClass.put(SpdxConstants.ENUM_ANNOTATION_TYPE, AnnotationType.class); - typeToClass.put(SpdxConstants.ENUM_CHECKSUM_ALGORITHM_TYPE, ChecksumAlgorithm.class); - typeToClass.put(SpdxConstants.ENUM_REFERENCE_CATEGORY_TYPE, ReferenceCategory.class); - typeToClass.put(SpdxConstants.ENUM_REFERENCE_RELATIONSHIP_TYPE, RelationshipType.class); - typeToClass.put(SpdxConstants.CLASS_EXTERNAL_EXTRACTED_LICENSE, ExternalExtractedLicenseInfo.class); - typeToClass.put(SpdxConstants.ENUM_PURPOSE, Purpose.class); - SPDX_TYPE_TO_CLASS = Collections.unmodifiableMap(typeToClass); - - Map, String> classToType = new HashMap<>(); - for (Entry> entry:typeToClass.entrySet()) { - classToType.put(entry.getValue(), entry.getKey()); - } - - SPDX_CLASS_TO_TYPE = Collections.unmodifiableMap(classToType); - } - - - /** - * Create an SPDX document with default values for creator, created, licenseListVersion, data license and specVersion - * @param modelStore Where to store the SPDX Document - * @param documentUri unique URI for the SPDX document - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @return - * @throws InvalidSPDXAnalysisException - */ - public static SpdxDocument createSpdxDocument(IModelStore modelStore, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SpdxDocument retval = new SpdxDocument(modelStore, documentUri, copyManager, true); - String date = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT).format(new Date()); - SpdxCreatorInformation creationInfo = new SpdxCreatorInformation( - modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - creationInfo.getCreators().add("Tool: SPDX Tools"); - creationInfo.setCreated(date); - creationInfo.setLicenseListVersion(ListedLicenses.getListedLicenses().getLicenseListVersion()); - retval.setCreationInfo(creationInfo); - retval.setDataLicense(ListedLicenses.getListedLicenses().getListedLicenseById(SpdxConstants.SPDX_DATA_LICENSE_ID)); - retval.setSpecVersion(Version.CURRENT_SPDX_VERSION); - return retval; - } - - /** - * Create a model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param documentUri document URI for the stored item - * @param id ID for the item - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static ModelObject createModelObject(IModelStore modelStore, String documentUri, String id, - String type, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - return getModelObject(modelStore, documentUri, id, type, copyManager, true); - } - - /** - * Create a model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param documentUri document URI for the stored item - * @param id ID for the item - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @param create if true, create the model object if it does not already exist - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static ModelObject getModelObject(IModelStore modelStore, String documentUri, String id, - String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - switch (type) { - case SpdxConstants.CLASS_SPDX_DOCUMENT: return new SpdxDocument(modelStore, documentUri, copyManager, create); //Note: the ID is ignored - case SpdxConstants.CLASS_SPDX_PACKAGE: return new SpdxPackage(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_CREATION_INFO: return new SpdxCreatorInformation(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_CHECKSUM: return new Checksum(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_ANY_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract AnyLicensing Info. Must specify one of the concrete classes"); - case SpdxConstants.CLASS_SPDX_SIMPLE_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract SimpleLicensingInfo. Must specify one of the concrete classes"); - case SpdxConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET: return new ConjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET: return new DisjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO: return new ExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_LICENSE: throw new InvalidSPDXAnalysisException("Can not create abstract License. Must specify one of the concrete classes"); - case SpdxConstants.CLASS_SPDX_LISTED_LICENSE: return new SpdxListedLicense(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION: return new LicenseException(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION: return new ListedLicenseException(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_OR_LATER_OPERATOR: return new OrLaterOperator(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_WITH_EXCEPTION_OPERATOR: return new WithExceptionOperator(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_FILE: return new SpdxFile(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_REVIEW: throw new RuntimeException("SPDX Review class is no longer supported"); - case SpdxConstants.CLASS_SPDX_VERIFICATIONCODE: return new SpdxPackageVerificationCode(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_ANNOTATION: return new Annotation(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_RELATIONSHIP: return new Relationship(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_ITEM: throw new RuntimeException("SPDX item is an abstract item and can not be created."); - case SpdxConstants.CLASS_SPDX_ELEMENT: throw new RuntimeException("SPDX element is an abstract item and can not be created."); - case SpdxConstants.CLASS_SPDX_NONE_ELEMENT: return new SpdxNoneElement(modelStore, documentUri); - case SpdxConstants.CLASS_SPDX_NOASSERTION_ELEMENT: return new SpdxNoAssertionElement(modelStore, documentUri); - case SpdxConstants.CLASS_EXTERNAL_DOC_REF: return new ExternalDocumentRef(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_EXTERNAL_REFERENCE: return new ExternalRef(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_EXTERNAL_EXTRACTED_LICENSE: return new ExternalExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_SPDX_REFERENCE_TYPE: throw new RuntimeException("Reference type can only be created with a type supplied."); - case SpdxConstants.CLASS_SPDX_SNIPPET: return new SpdxSnippet(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_NOASSERTION_LICENSE: return new SpdxNoAssertionLicense(modelStore, documentUri); - case SpdxConstants.CLASS_NONE_LICENSE: return new SpdxNoneLicense(modelStore, documentUri); - case GenericModelObject.GENERIC_MODEL_OBJECT_TYPE: return new GenericModelObject(modelStore, documentUri, id, copyManager, create); - case GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE: return new GenericSpdxElement(modelStore, documentUri, id, copyManager, create); - case GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE: return new GenericSpdxItem(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_EXTERNAL_SPDX_ELEMENT: return new ExternalSpdxElement(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_POINTER_START_END_POINTER: return new StartEndPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_POINTER_BYTE_OFFSET_POINTER: return new ByteOffsetPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_POINTER_LINE_CHAR_POINTER: return new LineCharPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstants.CLASS_CROSS_REF: return new CrossRef(modelStore, documentUri, id, copyManager, create); - default: throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); - } - } - - /** - * @param type SPDX Type - * @return class associated with the type - * @throws InvalidSPDXAnalysisException - */ - public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { - Class retval = SPDX_TYPE_TO_CLASS.get(type); - if (Objects.isNull(retval)) { - throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); - } - return retval; - } - - public static Stream getElements(IModelStore store, String documentUri, ModelCopyManager copyManager, - Class spdxClass) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(documentUri, "documentUri must not be null"); - Objects.requireNonNull(spdxClass, "spdxClass must not be null"); - String type = SPDX_CLASS_TO_TYPE.get(spdxClass); - if (Objects.isNull(type)) { - throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); - } - return store.getAllItems(documentUri, type).map(tv -> { - try { - return createModelObject(store, documentUri, tv.getId(), tv.getType(), copyManager); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error creating model object",e); - throw new RuntimeException(e); - } - }); - } - - /** - * @param classUri URI for the class type - * @return class represented by the URI - * @throws InvalidSPDXAnalysisException - */ - public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(classUri, "Missing required class URI"); - int indexOfPound = classUri.lastIndexOf('#'); - if (indexOfPound < 1) { - throw new InvalidSPDXAnalysisException("Invalid class URI: "+classUri); - } - String type = classUri.substring(indexOfPound+1); - return typeToClass(type); - } - - /** - * @param modelStore Store for the model - * @param documentUri Document URI for for the ID - * @param copyManager Optional copy manager for copying any properties from other model - * @param id ID for the model object - * @return ModelObject with the ID in the model store - * @throws InvalidSPDXAnalysisException - */ - public static Optional getModelObject(IModelStore modelStore, String documentUri, - String id, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (id.contains(":")) { - // External document ref - try { - return Optional.of(new ExternalSpdxElement(modelStore, documentUri, id, copyManager, true)); - } catch(InvalidSPDXAnalysisException ex) { - logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty"); - return Optional.empty(); - } - } - Optional tv = modelStore.getTypedValue(documentUri, id); - if (tv.isPresent()) { - String type = tv.get().getType(); - try { - return Optional.of(getModelObject(modelStore, documentUri, id, type, copyManager, false)); - } catch(SpdxIdNotFoundException ex) { - return Optional.empty(); // There is a window where the ID disappears between getTypedValue and getModelObject - } - } else { - if (SpdxConstants.NOASSERTION_VALUE.equals(id)) { - return Optional.of(new SpdxNoAssertionElement()); - } else if (SpdxConstants.NONE_VALUE.equals(id)) { - return Optional.of(new SpdxNoneElement()); - } else { - return Optional.empty(); - } - } - } -} diff --git a/src/main/java/org/spdx/library/model/Annotation.java b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java similarity index 90% rename from src/main/java/org/spdx/library/model/Annotation.java rename to src/main/java/org/spdx/library/model/compat/v2/Annotation.java index a8dbf54fd..bf030fdbb 100644 --- a/src/main/java/org/spdx/library/model/Annotation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.List; @@ -26,9 +26,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.storage.IModelStore; /** @@ -68,11 +68,11 @@ public Annotation(IModelStore modelStore, String documentUri, String id, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_ANNOTATION; + return SpdxConstantsCompatV2.CLASS_ANNOTATION; } /** @@ -80,7 +80,7 @@ public String getType() { * @throws InvalidSPDXAnalysisException */ public AnnotationType getAnnotationType() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.PROP_ANNOTATION_TYPE); + Optional> retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_TYPE); if (retval.isPresent() && !(retval.get() instanceof AnnotationType)) { throw new SpdxInvalidTypeException("Invalid enum type for "+retval.get().toString()); } @@ -109,7 +109,7 @@ public Annotation setAnnotationType(AnnotationType type) throws InvalidSPDXAnaly if (AnnotationType.MISSING.equals(type)) { throw new InvalidSPDXAnalysisException("Can not set value to MISSING for annotation type. This is reserved for when the value is not present in the store."); } - setPropertyValue(SpdxConstants.PROP_ANNOTATION_TYPE, type); + setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_TYPE, type); return this; } @@ -118,7 +118,7 @@ public Annotation setAnnotationType(AnnotationType type) throws InvalidSPDXAnaly * @throws InvalidSPDXAnalysisException */ public String getAnnotator() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_ANNOTATOR); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATOR); if (retval.isPresent()) { return retval.get(); } else { @@ -142,7 +142,7 @@ public Annotation setAnnotator(String annotator) throws InvalidSPDXAnalysisExcep throw new InvalidSPDXAnalysisException(verify); } } - setPropertyValue(SpdxConstants.PROP_ANNOTATOR, annotator); + setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATOR, annotator); return this; } @@ -150,7 +150,7 @@ public Annotation setAnnotator(String annotator) throws InvalidSPDXAnalysisExcep * @return the comment */ public String getComment() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); if (retval.isPresent()) { return retval.get(); } else { @@ -171,7 +171,7 @@ public Annotation setComment(String comment) throws InvalidSPDXAnalysisException throw new InvalidSPDXAnalysisException("Comment is required - can not be null or empty"); } } - setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); return this; } @@ -179,7 +179,7 @@ public Annotation setComment(String comment) throws InvalidSPDXAnalysisException * @return the date */ public String getAnnotationDate() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_ANNOTATION_DATE); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_DATE); if (retval.isPresent()) { return retval.get(); } else { @@ -204,12 +204,12 @@ public Annotation setAnnotationDate(String date) throws InvalidSPDXAnalysisExcep throw new InvalidSPDXAnalysisException(dateVerify); } } - setPropertyValue(SpdxConstants.PROP_ANNOTATION_DATE, date); + setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_DATE, date); return this; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override public List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/Checksum.java b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java similarity index 92% rename from src/main/java/org/spdx/library/model/Checksum.java rename to src/main/java/org/spdx/library/model/compat/v2/Checksum.java index 31e85bde7..a34badb20 100644 --- a/src/main/java/org/spdx/library/model/Checksum.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.List; @@ -27,10 +27,10 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -96,15 +96,15 @@ public static Checksum create(IModelStore modelStore, String documentUri, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_CHECKSUM; + return SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -143,7 +143,7 @@ protected List _verify(Set verifiedIds, String specVersion) { * @throws InvalidSPDXAnalysisException */ public ChecksumAlgorithm getAlgorithm() throws InvalidSPDXAnalysisException { - Optional retval = getEnumPropertyValue(SpdxConstants.PROP_CHECKSUM_ALGORITHM); + Optional retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_ALGORITHM); if (retval.isPresent()) { if (!(retval.get() instanceof ChecksumAlgorithm)) { logger.error("Invalid type for checksum algorithm: "+retval.get().getClass().toString()); @@ -171,7 +171,7 @@ protected void setAlgorithm(ChecksumAlgorithm algorithm) throws InvalidSPDXAnaly if (ChecksumAlgorithm.MISSING.equals(algorithm)) { throw new InvalidSPDXAnalysisException("Can not set required checksum algorithm to MISSING. This is only used when no algorithm value was found."); } - setPropertyValue(SpdxConstants.PROP_CHECKSUM_ALGORITHM, algorithm); + setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_ALGORITHM, algorithm); } /** @@ -179,7 +179,7 @@ protected void setAlgorithm(ChecksumAlgorithm algorithm) throws InvalidSPDXAnaly * @throws InvalidSPDXAnalysisException */ public String getValue() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_CHECKSUM_VALUE); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_VALUE); if (retval.isPresent()) { return retval.get(); } else { @@ -205,7 +205,7 @@ protected void setValue(String value) throws InvalidSPDXAnalysisException { } } } - setPropertyValue(SpdxConstants.PROP_CHECKSUM_VALUE, value); + setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_VALUE, value); } @Override diff --git a/src/main/java/org/spdx/library/model/DuplicateSpdxIdException.java b/src/main/java/org/spdx/library/model/compat/v2/DuplicateSpdxIdException.java similarity index 97% rename from src/main/java/org/spdx/library/model/DuplicateSpdxIdException.java rename to src/main/java/org/spdx/library/model/compat/v2/DuplicateSpdxIdException.java index 09dbc77a4..39c95f4db 100644 --- a/src/main/java/org/spdx/library/model/DuplicateSpdxIdException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/DuplicateSpdxIdException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java similarity index 88% rename from src/main/java/org/spdx/library/model/ExternalDocumentRef.java rename to src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index a29f56cce..90476e6cd 100644 --- a/src/main/java/org/spdx/library/model/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.HashSet; @@ -29,10 +29,10 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -61,7 +61,7 @@ public static Optional getExternalDocRefByDocNamespace(IMod IModelStoreLock lock = stModelStore.enterCriticalSection(stDocumentUri, false); try { ModelCollection existingExternalRefs = new ModelCollection(stModelStore,stDocumentUri, - SpdxConstants.SPDX_DOCUMENT_ID, SpdxConstants.PROP_SPDX_EXTERNAL_DOC_REF, copyManager, ExternalDocumentRef.class); + SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, copyManager, ExternalDocumentRef.class); for (Object externalRef:existingExternalRefs) { if (!(externalRef instanceof ExternalDocumentRef)) { logger.warn("Incorrect type for an external document ref: "+externalRef.getClass().toString()); @@ -80,8 +80,8 @@ public static Optional getExternalDocRefByDocNamespace(IMod ExternalDocumentRef retval = new ExternalDocumentRef(stModelStore, stDocumentUri, stModelStore.getNextId(IdType.DocumentRef, stDocumentUri), copyManager, true); retval.setSpdxDocumentNamespace(externalDocUri); - ModelObject.addValueToCollection(stModelStore, stDocumentUri, SpdxConstants.SPDX_DOCUMENT_ID, - SpdxConstants.PROP_SPDX_EXTERNAL_DOC_REF, retval, copyManager); + ModelObject.addValueToCollection(stModelStore, stDocumentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, + SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, retval, copyManager); return Optional.of(retval); } else { return Optional.empty(); @@ -107,7 +107,7 @@ public ExternalDocumentRef(String id) throws InvalidSPDXAnalysisException { super(id); if (!SpdxVerificationHelper.isValidExternalDocRef(id)) { logger.warn("Invalid external document reference ID "+id+ - ". Must be of the format "+SpdxConstants.EXTERNAL_DOC_REF_PATTERN.pattern()); + ". Must be of the format "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.pattern()); } } @@ -125,16 +125,16 @@ public ExternalDocumentRef(IModelStore modelStore, String documentUri, String id super(modelStore, documentUri, id, copyManager, create); if (!SpdxVerificationHelper.isValidExternalDocRef(id)) { logger.warn("Invalid external document reference ID "+id+ - ". Must be of the format "+SpdxConstants.EXTERNAL_DOC_REF_PATTERN.pattern()); + ". Must be of the format "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.pattern()); } } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_EXTERNAL_DOC_REF; + return SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF; } /** @@ -157,7 +157,7 @@ private String documentToDocumentUri(SpdxDocument document) { */ @SuppressWarnings("unchecked") public Optional getChecksum() throws InvalidSPDXAnalysisException { - return (Optional)(Optional)getObjectPropertyValue(SpdxConstants.PROP_EXTERNAL_DOC_CHECKSUM); + return (Optional)(Optional)getObjectPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_DOC_CHECKSUM); } /** @@ -175,7 +175,7 @@ public ExternalDocumentRef setChecksum(Checksum checksum) throws InvalidSPDXAnal throw new InvalidSPDXAnalysisException("Invalid checksum: "+verify.get(0)); } } - setPropertyValue(SpdxConstants.PROP_EXTERNAL_DOC_CHECKSUM, checksum); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_DOC_CHECKSUM, checksum); return this; } @@ -183,7 +183,7 @@ public ExternalDocumentRef setChecksum(Checksum checksum) throws InvalidSPDXAnal * @return the spdxDocumentNamespace or empty string if no namespace */ public String getSpdxDocumentNamespace() throws InvalidSPDXAnalysisException { - Optional docNamespace = getModelStore().getValue(getDocumentUri(), getId(), SpdxConstants.PROP_EXTERNAL_SPDX_DOCUMENT); + Optional docNamespace = getModelStore().getValue(getDocumentUri(), getId(), SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); if (!docNamespace.isPresent()) { logger.warn("SPDX document namespace not found"); return ""; @@ -214,13 +214,13 @@ public ExternalDocumentRef setSpdxDocumentNamespace(String documentNamespace) th if (strict) { throw new InvalidSPDXAnalysisException("Null value for a required docment namespace"); } else { - setPropertyValue(SpdxConstants.PROP_EXTERNAL_SPDX_DOCUMENT, null); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT, null); } } else { if (strict && !SpdxVerificationHelper.isValidUri(documentNamespace)) { throw new InvalidSPDXAnalysisException("Invalid document namespace. Must be a valid URI."); } - setPropertyValue(SpdxConstants.PROP_EXTERNAL_SPDX_DOCUMENT, + setPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT, new IndividualUriValue() { @Override public String getIndividualURI() { @@ -252,10 +252,10 @@ public Optional getSpdxDocument() throws InvalidSPDXAnalysisExcept if (docNamespace.isEmpty()) { return Optional.empty(); } - if (this.getModelStore().exists(docNamespace, SpdxConstants.SPDX_DOCUMENT_ID)) { + if (this.getModelStore().exists(docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID)) { return (Optional)(Optional)Optional.of(SpdxModelFactory.createModelObject( - getModelStore(), docNamespace, SpdxConstants.SPDX_DOCUMENT_ID, - SpdxConstants.CLASS_SPDX_DOCUMENT, getCopyManager())); + getModelStore(), docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, + SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, getCopyManager())); } else { return Optional.empty(); } @@ -272,13 +272,13 @@ public ExternalDocumentRef setSpdxDocument(SpdxDocument spdxDocument) throws Inv } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { List retval = new ArrayList<>(); - if (!getId().startsWith(SpdxConstants.EXTERNAL_DOC_REF_PRENUM)) { - retval.add("Invalid external ref ID: "+getId()+". Must start with "+SpdxConstants.EXTERNAL_DOC_REF_PRENUM+"."); + if (!getId().startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { + retval.add("Invalid external ref ID: "+getId()+". Must start with "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"."); } String spdxDocumentNamespace = "UNKNOWN"; try { diff --git a/src/main/java/org/spdx/library/model/ExternalRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java similarity index 92% rename from src/main/java/org/spdx/library/model/ExternalRef.java rename to src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java index 07972d239..c72b4a0e1 100644 --- a/src/main/java/org/spdx/library/model/ExternalRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.List; @@ -27,9 +27,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; import org.spdx.storage.IModelStore; /** @@ -71,15 +71,15 @@ public ExternalRef(IModelStore modelStore, String documentUri, String id, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_EXTERNAL_REFERENCE; + return SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -195,7 +195,7 @@ public int compareTo(ExternalRef o) { * @throws InvalidSPDXAnalysisException */ public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + return getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); } /** @@ -204,7 +204,7 @@ public Optional getComment() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public ExternalRef setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); return this; } @@ -212,7 +212,7 @@ public ExternalRef setComment(String comment) throws InvalidSPDXAnalysisExceptio * @return the referenceCategory */ public ReferenceCategory getReferenceCategory() throws InvalidSPDXAnalysisException { - Optional retval = this.getEnumPropertyValue(SpdxConstants.PROP_REFERENCE_CATEGORY); + Optional retval = this.getEnumPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_CATEGORY); if (retval.isPresent()) { if (!(retval.get() instanceof ReferenceCategory)) { throw new InvalidSPDXAnalysisException("Invalid type for reference category: "+retval.get().getClass().toString()); @@ -238,7 +238,7 @@ public ExternalRef setReferenceCategory(ReferenceCategory referenceCategory) thr if (ReferenceCategory.MISSING.equals(referenceCategory)) { throw new InvalidSPDXAnalysisException("Can not set required referenceCategory to MISSING"); } - setPropertyValue(SpdxConstants.PROP_REFERENCE_CATEGORY, referenceCategory); + setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_CATEGORY, referenceCategory); return this; } @@ -247,7 +247,7 @@ public ExternalRef setReferenceCategory(ReferenceCategory referenceCategory) thr * @throws InvalidSPDXAnalysisException */ public ReferenceType getReferenceType() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_REFERENCE_TYPE); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE); if (!retval.isPresent()) { return ReferenceType.getMissingReferenceType(); } @@ -271,7 +271,7 @@ public ExternalRef setReferenceType(ReferenceType referenceType) throws InvalidS if (strict) { throw new InvalidSPDXAnalysisException("Can not set required referenceType to null"); } else { - setPropertyValue(SpdxConstants.PROP_REFERENCE_TYPE, null); + setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE, null); } } else { if (ReferenceType.MISSING_REFERENCE_TYPE_URI.equals(referenceType.getIndividualURI())) { @@ -280,7 +280,7 @@ public ExternalRef setReferenceType(ReferenceType referenceType) throws InvalidS if (strict && !SpdxVerificationHelper.isValidUri(referenceType.getIndividualURI())) { throw new InvalidSPDXAnalysisException("Invalid URI for referenceType"); } - setPropertyValue(SpdxConstants.PROP_REFERENCE_TYPE, referenceType); + setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE, referenceType); } return this; } @@ -289,7 +289,7 @@ public ExternalRef setReferenceType(ReferenceType referenceType) throws InvalidS * @return the referenceLocator. If not found, a blank string is returned */ public String getReferenceLocator() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_REFERENCE_LOCATOR); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_LOCATOR); if (retval.isPresent()) { return retval.get(); } else { @@ -315,7 +315,7 @@ public ExternalRef setReferenceLocator(String referenceLocator) throws InvalidSP throw new InvalidSPDXAnalysisException("Reference locator contains spaces"); } } - setPropertyValue(SpdxConstants.PROP_REFERENCE_LOCATOR, referenceLocator); + setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_LOCATOR, referenceLocator); return this; } diff --git a/src/main/java/org/spdx/library/model/ExternalSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java similarity index 91% rename from src/main/java/org/spdx/library/model/ExternalSpdxElement.java rename to src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java index 4a210db60..8a9fd6313 100644 --- a/src/main/java/org/spdx/library/model/ExternalSpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -30,12 +30,12 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; /** - * This is an SPDX element which is in an external document. The ID must be in the form SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.pattern() + * This is an SPDX element which is in an external document. The ID must be in the form SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern() * * @author Gary O'Neall */ @@ -63,7 +63,7 @@ public ExternalSpdxElement(IModelStore modelStore, String documentUri, String id @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - if (!SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id).matches()) { + if (!SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id).matches()) { throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } getExternalSpdxElementURI(); //this will check to make sure the external document reference is available @@ -74,7 +74,7 @@ public ExternalSpdxElement(IModelStore modelStore, String documentUri, String id * @throws InvalidSPDXAnalysisException */ public String getExternalDocumentId() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); if (!matcher.matches()) { throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } @@ -86,7 +86,7 @@ public String getExternalDocumentId() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public String getExternalElementId() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); if (!matcher.matches()) { throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } @@ -94,24 +94,24 @@ public String getExternalElementId() throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_EXTERNAL_SPDX_ELEMENT; + return SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT; } /* (non-Javadoc) - * @see org.spdx.library.model.SpdxElement#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { // we don't want to call super.verify since we really don't require those fields List retval = new ArrayList<>(); String id = this.getId(); - Matcher matcher = SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id); if (!matcher.matches()) { - retval.add("Invalid id format for an external document reference. Must be of the form "+SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); + retval.add("Invalid id format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); } else { try { externalDocumentIdToNamespace(matcher.group(1), getModelStore(), getDocumentUri(), getCopyManager()); @@ -140,7 +140,7 @@ public String getExternalSpdxElementURI() throws InvalidSPDXAnalysisException { */ public static String externalSpdxElementIdToURI(String externalSpdxElementId, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.matcher(externalSpdxElementId); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(externalSpdxElementId); if (!matcher.matches()) { logger.error("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); @@ -166,7 +166,7 @@ public static String externalSpdxElementIdToURI(String externalSpdxElementId, public static String uriToExternalSpdxElementId(String uri, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(uri, "URI can not be null"); - Matcher matcher = SpdxConstants.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri); if (!matcher.matches()) { throw new InvalidSPDXAnalysisException("Invalid URI format: "+uri+". Expects namespace#SPDXRef-XXX"); } @@ -196,8 +196,7 @@ public static ExternalSpdxElement uriToExternalSpdxElement(String uri, public static String externalDocumentIdToNamespace(String externalDocumentId, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - - Optional retval = stModelStore.getValue(stDocumentUri, externalDocumentId, SpdxConstants.PROP_EXTERNAL_SPDX_DOCUMENT); + Optional retval = stModelStore.getValue(stDocumentUri, externalDocumentId, SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); if (!retval.isPresent()) { throw new InvalidSPDXAnalysisException("No external document reference exists for document ID "+externalDocumentId); } diff --git a/src/main/java/org/spdx/library/model/GenericModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java similarity index 91% rename from src/main/java/org/spdx/library/model/GenericModelObject.java rename to src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java index fe24e0113..17225e013 100644 --- a/src/main/java/org/spdx/library/model/GenericModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.List; @@ -68,7 +68,7 @@ public GenericModelObject(IModelStore modelStore, String documentUri, String id, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { @@ -76,7 +76,7 @@ public String getType() { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/GenericSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java similarity index 94% rename from src/main/java/org/spdx/library/model/GenericSpdxElement.java rename to src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java index f05959877..99fcff09a 100644 --- a/src/main/java/org/spdx/library/model/GenericSpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import javax.annotation.Nullable; @@ -63,7 +63,7 @@ public GenericSpdxElement(IModelStore modelStore, String documentUri, String id, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { diff --git a/src/main/java/org/spdx/library/model/GenericSpdxItem.java b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java similarity index 93% rename from src/main/java/org/spdx/library/model/GenericSpdxItem.java rename to src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java index 721d130fe..6f22e8a2c 100644 --- a/src/main/java/org/spdx/library/model/GenericSpdxItem.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -58,7 +58,7 @@ public GenericSpdxItem(IModelStore modelStore, String documentUri, String id, Mo } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { diff --git a/src/main/java/org/spdx/library/model/IndividualUriValue.java b/src/main/java/org/spdx/library/model/compat/v2/IndividualUriValue.java similarity index 96% rename from src/main/java/org/spdx/library/model/IndividualUriValue.java rename to src/main/java/org/spdx/library/model/compat/v2/IndividualUriValue.java index b174a5424..34eb6b070 100644 --- a/src/main/java/org/spdx/library/model/IndividualUriValue.java +++ b/src/main/java/org/spdx/library/model/compat/v2/IndividualUriValue.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; /** * Classes which implement the IndividuallUriValue interface will be stored as a single value. Theses classes diff --git a/src/main/java/org/spdx/library/model/InvalidSpdxPropertyException.java b/src/main/java/org/spdx/library/model/compat/v2/InvalidSpdxPropertyException.java similarity index 97% rename from src/main/java/org/spdx/library/model/InvalidSpdxPropertyException.java rename to src/main/java/org/spdx/library/model/compat/v2/InvalidSpdxPropertyException.java index 5d7fcb760..7991222da 100644 --- a/src/main/java/org/spdx/library/model/InvalidSpdxPropertyException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/InvalidSpdxPropertyException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/ModelCollection.java b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java similarity index 96% rename from src/main/java/org/spdx/library/model/ModelCollection.java rename to src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java index ca3115700..7d7a4ef28 100644 --- a/src/main/java/org/spdx/library/model/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Collection; import java.util.Collections; @@ -32,10 +32,10 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxObjectNotInStoreException; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -148,9 +148,9 @@ private Object checkConvertTypedValue(Object value) { Object retval = ModelStorageClassConverter.storedObjectToModelObject(value, documentUri, modelStore, copyManager); if (licensePrimitiveAssignable && retval instanceof IndividualUriValue) { String uri = ((IndividualUriValue)retval).getIndividualURI(); - if (SpdxConstants.URI_VALUE_NOASSERTION.equals(uri)) { + if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { retval = new SpdxNoAssertionLicense(); - } else if (SpdxConstants.URI_VALUE_NONE.equals(uri)) { + } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { retval = new SpdxNoneLicense(); } } diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java similarity index 95% rename from src/main/java/org/spdx/library/model/ModelObject.java rename to src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 61872574a..e498917c3 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -32,25 +32,25 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.ReferenceCategory; -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.ConjunctiveLicenseSet; -import org.spdx.library.model.license.CrossRef.CrossRefBuilder; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ListedLicenses; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; -import org.spdx.library.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.SinglePointer; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ListedLicenses; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.license.CrossRef.CrossRefBuilder; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.SinglePointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -426,10 +426,10 @@ protected Optional getStringPropertyValue(PropertyDescriptor propertyDes return Optional.of((String)result.get()); } else if (result.get() instanceof IndividualUriValue) { String uri = ((IndividualUriValue)result.get()).getIndividualURI(); - if (SpdxConstants.URI_VALUE_NONE.equals(uri)) { - return Optional.of(SpdxConstants.NONE_VALUE); - } else if (SpdxConstants.URI_VALUE_NOASSERTION.equals(uri)) { - return Optional.of(SpdxConstants.NOASSERTION_VALUE); + if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { + return Optional.of(SpdxConstantsCompatV2.NONE_VALUE); + } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { + return Optional.of(SpdxConstantsCompatV2.NOASSERTION_VALUE); } else { logger.error("Can not convert a URI value to String: "+uri); throw new SpdxInvalidTypeException("Can not convert a URI value to String: "+uri); @@ -531,9 +531,9 @@ protected Optional getAnyLicenseInfoPropertyValue(PropertyDescri return (Optional)(Optional)result; } else if (result.get() instanceof IndividualUriValue) { String uri = ((IndividualUriValue)result.get()).getIndividualURI(); - if (SpdxConstants.URI_VALUE_NONE.equals(uri)) { + if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { return Optional.of(new SpdxNoneLicense()); - } else if (SpdxConstants.URI_VALUE_NOASSERTION.equals(uri)) { + } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { return Optional.of(new SpdxNoAssertionLicense()); } else { logger.error("Can not convert a URI value to a license: "+uri); @@ -560,9 +560,9 @@ protected Optional getElementPropertyValue(PropertyDescriptor prope return (Optional)(Optional)result; } else if (result.get() instanceof IndividualUriValue) { String uri = ((IndividualUriValue)result.get()).getIndividualURI(); - if (SpdxConstants.URI_VALUE_NONE.equals(uri)) { + if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { return Optional.of(new SpdxNoneElement()); - } else if (SpdxConstants.URI_VALUE_NOASSERTION.equals(uri)) { + } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { return Optional.of(new SpdxNoAssertionElement()); } else { logger.error("Can not convert a URI value to an SPDX element: "+uri); @@ -846,7 +846,7 @@ private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor prop return ((ModelCollection) propertyValue).size() == 0; } else if (isNoAssertion(propertyValue)) { return true; - } else if (SpdxConstants.PROP_PACKAGE_FILES_ANALYZED.equals(propertyDescriptor.getName())) { + } else if (SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED.equals(propertyDescriptor.getName())) { return propertyValue instanceof Boolean && (Boolean)(propertyValue); } else { return false; @@ -854,7 +854,7 @@ private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor prop } private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { - return SpdxConstants.PROP_RELATED_SPDX_ELEMENT.equals(propertyDescriptor.getName()); + return SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.equals(propertyDescriptor.getName()); } private boolean isEmptyModelCollection(Object value) { @@ -864,7 +864,7 @@ private boolean isEmptyModelCollection(Object value) { private boolean isNoAssertion(Object propertyValue) { return propertyValue instanceof SpdxNoAssertionLicense || - propertyValue.equals(SpdxConstants.NOASSERTION_VALUE); + propertyValue.equals(SpdxConstantsCompatV2.NOASSERTION_VALUE); } /** @@ -927,18 +927,18 @@ private boolean OptionalObjectsEquivalent(Optional valueA, Optional(owningElement.getModelStore(), - owningElement.getDocumentUri(), owningElement.getId(), SpdxConstants.PROP_RELATIONSHIP, + owningElement.getDocumentUri(), owningElement.getId(), SpdxConstantsCompatV2.PROP_RELATIONSHIP, owningElement.getCopyManager(), Relationship.class); this.relationshipTypeFilter = relationshipTypeFilter; this.relatedElementTypeFilter = relatedElementTypeFilter; diff --git a/src/main/java/org/spdx/library/model/Relationship.java b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java similarity index 89% rename from src/main/java/org/spdx/library/model/Relationship.java rename to src/main/java/org/spdx/library/model/compat/v2/Relationship.java index cac507fd2..9cbe46467 100644 --- a/src/main/java/org/spdx/library/model/Relationship.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.List; @@ -24,9 +24,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; /** @@ -66,15 +66,15 @@ public Relationship(IModelStore modelStore, String documentUri, String id, Model } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_RELATIONSHIP; + return SpdxConstantsCompatV2.CLASS_RELATIONSHIP; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -113,7 +113,7 @@ protected List _verify(Set verifiedIds, String specVersion) { * @throws InvalidSPDXAnalysisException */ public RelationshipType getRelationshipType() throws InvalidSPDXAnalysisException { - Optional retval = getEnumPropertyValue(SpdxConstants.PROP_RELATIONSHIP_TYPE); + Optional retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE); if (retval.isPresent()) { if (!(retval.get() instanceof RelationshipType)) { throw new SpdxInvalidTypeException("Invalid type for relationship type individual value: "+retval.get().toString()); @@ -137,7 +137,7 @@ public Relationship setRelationshipType(RelationshipType type) throws InvalidSPD if (strict && type == null) { throw new InvalidSPDXAnalysisException("Can not set required relationshipType to null"); } - setPropertyValue(SpdxConstants.PROP_RELATIONSHIP_TYPE, type); + setPropertyValue(SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE, type); return this; } @@ -145,7 +145,7 @@ public Relationship setRelationshipType(RelationshipType type) throws InvalidSPD * @return the comment */ public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + return getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); } /** @@ -154,7 +154,7 @@ public Optional getComment() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Relationship setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); return this; } @@ -162,7 +162,7 @@ public Relationship setComment(String comment) throws InvalidSPDXAnalysisExcepti * @return the relatedSpdxElement */ public Optional getRelatedSpdxElement() throws InvalidSPDXAnalysisException { - return getElementPropertyValue(SpdxConstants.PROP_RELATED_SPDX_ELEMENT); + return getElementPropertyValue(SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT); } /** @@ -171,7 +171,7 @@ public Optional getRelatedSpdxElement() throws InvalidSPDXAnalysisE * @throws InvalidSPDXAnalysisException */ public Relationship setRelatedSpdxElement(SpdxElement relatedSpdxElement) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_RELATED_SPDX_ELEMENT, relatedSpdxElement); + setPropertyValue(SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT, relatedSpdxElement); return this; } diff --git a/src/main/java/org/spdx/library/model/SimpleUriValue.java b/src/main/java/org/spdx/library/model/compat/v2/SimpleUriValue.java similarity index 82% rename from src/main/java/org/spdx/library/model/SimpleUriValue.java rename to src/main/java/org/spdx/library/model/compat/v2/SimpleUriValue.java index 64dd0e7d5..47e409bb0 100644 --- a/src/main/java/org/spdx/library/model/SimpleUriValue.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SimpleUriValue.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Objects; @@ -23,11 +23,11 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.SpdxEnumFactory; -import org.spdx.library.model.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; +import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; /** @@ -76,7 +76,7 @@ public SimpleUriValue(String uri) throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.IndividualValue#getIndividualURI() + * @see org.spdx.library.model.compat.v2.compat.v2.IndividualValue#getIndividualURI() */ @Override public String getIndividualURI() { @@ -96,17 +96,17 @@ public Object toModelObject(IModelStore store, String documentUri, ModelCopyMana Object retval = SpdxEnumFactory.uriToEnum.get(uri); if (Objects.nonNull(retval)) { return retval; - } else if (SpdxConstants.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri).matches()) { + } else if (SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri).matches()) { return ExternalSpdxElement.uriToExternalSpdxElement(uri, store, documentUri, copyManager); - } else if (SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri).matches()) { + } else if (SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri).matches()) { return ExternalExtractedLicenseInfo.uriToExternalExtractedLicense(uri, store, documentUri, copyManager); - } else if (SpdxConstants.REFERENCE_TYPE_URI_PATTERN.matcher(uri).matches()) { + } else if (SpdxConstantsCompatV2.REFERENCE_TYPE_URI_PATTERN.matcher(uri).matches()) { return new ReferenceType(this); - } else if (SpdxConstants.URI_VALUE_NONE.equals(uri)) { + } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { // Default value is a license, although it can also be a string or an SpdxElement // the caller should override the type based on the type expected return new SpdxNoneLicense(store, documentUri); - } else if (SpdxConstants.URI_VALUE_NOASSERTION.equals(uri)) { + } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { return new SpdxNoAssertionLicense(store, documentUri); } else { logger.warn("URI "+uri+" does not match any model object or enumeration"); diff --git a/src/main/java/org/spdx/library/model/SpdxConstantElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java similarity index 94% rename from src/main/java/org/spdx/library/model/SpdxConstantElement.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java index 315e8ec8c..13a870dca 100644 --- a/src/main/java/org/spdx/library/model/SpdxConstantElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -24,7 +24,7 @@ import java.util.Set; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; /** @@ -59,11 +59,11 @@ protected List _verify(Set verifiedIds, String specVersion) { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_NONE_ELEMENT; + return SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT; } @Override diff --git a/src/main/java/org/spdx/library/model/SpdxCreatorInformation.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java similarity index 89% rename from src/main/java/org/spdx/library/model/SpdxCreatorInformation.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java index a452330b6..39528e3db 100644 --- a/src/main/java/org/spdx/library/model/SpdxCreatorInformation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -28,7 +28,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.storage.IModelStore; @@ -70,7 +70,7 @@ public SpdxCreatorInformation(IModelStore modelStore, String documentUri, String * @throws InvalidSPDXAnalysisException */ public Collection getCreators() throws InvalidSPDXAnalysisException { - return this.getStringCollection(SpdxConstants.PROP_CREATION_CREATOR); + return this.getStringCollection(SpdxConstantsCompatV2.PROP_CREATION_CREATOR); } /** @@ -78,7 +78,7 @@ public Collection getCreators() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Optional getLicenseListVersion() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_LICENSE_LIST_VERSION); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_LIST_VERSION); } /** @@ -87,7 +87,7 @@ public Optional getLicenseListVersion() throws InvalidSPDXAnalysisExcept * @throws InvalidSPDXAnalysisException */ public SpdxCreatorInformation setLicenseListVersion(String licenseListVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_LIST_VERSION, licenseListVersion); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_LIST_VERSION, licenseListVersion); return this; } @@ -96,7 +96,7 @@ public SpdxCreatorInformation setLicenseListVersion(String licenseListVersion) t * @return the comment */ public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + return getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); } /** @@ -105,7 +105,7 @@ public Optional getComment() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public SpdxCreatorInformation setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); return this; } @@ -114,7 +114,7 @@ public SpdxCreatorInformation setComment(String comment) throws InvalidSPDXAnaly * @throws InvalidSPDXAnalysisException */ public String getCreated() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_CREATION_CREATED); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CREATION_CREATED); if (retval.isPresent()) { return retval.get(); } else { @@ -138,16 +138,16 @@ public SpdxCreatorInformation setCreated(String created) throws InvalidSPDXAnaly throw new InvalidSPDXAnalysisException(verify); } } - setPropertyValue(SpdxConstants.PROP_CREATION_CREATED, created); + setPropertyValue(SpdxConstantsCompatV2.PROP_CREATION_CREATED, created); return this; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_CREATION_INFO; + return SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO; } @Override @@ -200,7 +200,7 @@ public String toString() { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -257,7 +257,7 @@ protected List _verify(Set verifiedIds, String specVersion) { if (Objects.isNull(version)) { return null; } else { - if (SpdxConstants.LICENSE_LIST_VERSION_PATTERN.matcher(version).matches()) { + if (SpdxConstantsCompatV2.LICENSE_LIST_VERSION_PATTERN.matcher(version).matches()) { return null; } else { return "License list version does not match the pattern M.N"; diff --git a/src/main/java/org/spdx/library/model/SpdxDocument.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java similarity index 88% rename from src/main/java/org/spdx/library/model/SpdxDocument.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java index 59a52a5e1..26de8b879 100644 --- a/src/main/java/org/spdx/library/model/SpdxDocument.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -29,13 +29,13 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.SpdxListedLicense; -import org.spdx.library.model.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -61,10 +61,10 @@ public class SpdxDocument extends SpdxElement { */ @SuppressWarnings("unchecked") public SpdxDocument(IModelStore modelStore, String documentUri, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, SpdxConstants.SPDX_DOCUMENT_ID, copyManager, create); + super(modelStore, documentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, copyManager, create); documentDescribes = new RelatedElementCollection(this, RelationshipType.DESCRIBES, null); - externalDocumentRefs = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_SPDX_EXTERNAL_DOC_REF, ExternalDocumentRef.class); - extractedLicenseInfos = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_SPDX_EXTRACTED_LICENSES, ExtractedLicenseInfo.class); + externalDocumentRefs = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, ExternalDocumentRef.class); + extractedLicenseInfos = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_SPDX_EXTRACTED_LICENSES, ExtractedLicenseInfo.class); } /** @@ -79,12 +79,12 @@ public SpdxDocument(String documentUri) throws InvalidSPDXAnalysisException { @Override public String getType() { - return SpdxConstants.CLASS_SPDX_DOCUMENT; + return SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT; } @Override protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstants.PROP_NAME; + return SpdxConstantsCompatV2.PROP_NAME; } @@ -114,7 +114,7 @@ public SpdxDocument setDocumentDescribes(List documentDescribes) { * @throws InvalidSPDXAnalysisException */ public @Nullable SpdxCreatorInformation getCreationInfo() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_SPDX_CREATION_INFO); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_CREATION_INFO); if (retval.isPresent()) { if (!(retval.get() instanceof SpdxCreatorInformation)) { throw new SpdxInvalidTypeException("Invalid tpe for CreationInfo: "+retval.get().getClass().toString()); @@ -135,7 +135,7 @@ public void setCreationInfo(SpdxCreatorInformation creationInfo) throws InvalidS throw new InvalidSPDXAnalysisException("Can not set required creation info to null"); } } - setPropertyValue(SpdxConstants.PROP_SPDX_CREATION_INFO, creationInfo); + setPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_CREATION_INFO, creationInfo); } /** @@ -143,7 +143,7 @@ public void setCreationInfo(SpdxCreatorInformation creationInfo) throws InvalidS * @throws InvalidSPDXAnalysisException */ public AnyLicenseInfo getDataLicense() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_SPDX_DATA_LICENSE); + Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_DATA_LICENSE); if (retval.isPresent()) { return retval.get(); } else { @@ -163,11 +163,11 @@ public void setDataLicense(AnyLicenseInfo dataLicense) throws InvalidSPDXAnalysi } if (!(dataLicense instanceof SpdxListedLicense)) { throw new InvalidSPDXAnalysisException("Invalid license type for data license - must be an SPDX Listed license"); - } else if (!((SpdxListedLicense)dataLicense).getLicenseId().equals(SpdxConstants.SPDX_DATA_LICENSE_ID)) { - throw new InvalidSPDXAnalysisException("Incorrect data license. Must be "+SpdxConstants.SPDX_DATA_LICENSE_ID); + } else if (!((SpdxListedLicense)dataLicense).getLicenseId().equals(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)) { + throw new InvalidSPDXAnalysisException("Incorrect data license. Must be "+SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID); } } - setPropertyValue(SpdxConstants.PROP_SPDX_DATA_LICENSE, dataLicense); + setPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_DATA_LICENSE, dataLicense); } /** @@ -212,7 +212,7 @@ public SpdxDocument setExtractedLicenseInfos(List extracte * @return the specVersion */ public String getSpecVersion() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_SPDX_SPEC_VERSION); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_SPEC_VERSION); if (retval.isPresent()) { return retval.get(); } else { @@ -233,13 +233,13 @@ public void setSpecVersion(String specVersion) throws InvalidSPDXAnalysisExcepti throw new InvalidSPDXAnalysisException(verify); } } - setPropertyValue(SpdxConstants.PROP_SPDX_SPEC_VERSION, specVersion); + setPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_SPEC_VERSION, specVersion); } /* (non-Javadoc) - * @see org.spdx.library.model.SpdxElement#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String verifySpecVersion) { @@ -299,10 +299,10 @@ protected List _verify(Set verifiedIds, String verifySpecVersion retval.add("Missing required data license"); } else if (!(dataLicense instanceof SpdxListedLicense)) { retval.add("Invalid license type for data license - must be an SPDX Listed license"); - } else if (!((SpdxListedLicense)dataLicense).getLicenseId().equals(SpdxConstants.SPDX_DATA_LICENSE_ID)) { + } else if (!((SpdxListedLicense)dataLicense).getLicenseId().equals(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)) { retval.add("Incorrect data license for SPDX version 1.0 document - found "+ ((SpdxListedLicense)dataLicense).getLicenseId()+", expected "+ - SpdxConstants.SPDX_DATA_LICENSE_ID); + SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting data license: "+e.getMessage()); diff --git a/src/main/java/org/spdx/library/model/SpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java similarity index 93% rename from src/main/java/org/spdx/library/model/SpdxElement.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java index 0938534d0..50276b51f 100644 --- a/src/main/java/org/spdx/library/model/SpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -29,7 +29,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -80,7 +80,7 @@ public SpdxElement(IModelStore modelStore, String documentUri, String id, ModelC } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedElementIds, String specVersion) { @@ -93,7 +93,7 @@ protected List _verify(Set verifiedElementIds, String specVersio IdType idType = this.getModelStore().getIdType(this.getId()); if (IdType.SpdxId.equals(idType)) { if (!SpdxVerificationHelper.verifySpdxId(this.getId())) { - retval.add("Invalid SPDX ID: "+this.getId()+". Must match the pattern "+SpdxConstants.SPDX_ELEMENT_REF_PATTERN); + retval.add("Invalid SPDX ID: "+this.getId()+". Must match the pattern "+SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PATTERN); } } else if (!IdType.Anonymous.equals(idType)) { retval.add("Invalid ID for SPDX Element: "+this.getId()+". Must be either a valid SPDX ID or Anonymous."); @@ -115,14 +115,14 @@ protected List _verify(Set verifiedElementIds, String specVersio @SuppressWarnings("unchecked") private synchronized void checkCreateAnnotations() throws InvalidSPDXAnalysisException { if (Objects.isNull(this.annotations)) { - this.annotations = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_ANNOTATION, Annotation.class); + this.annotations = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_ANNOTATION, Annotation.class); } } @SuppressWarnings("unchecked") private synchronized void checkCreateRelationships() throws InvalidSPDXAnalysisException { if (Objects.isNull(this.relationships)) { - this.relationships = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_RELATIONSHIP, Relationship.class); + this.relationships = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_RELATIONSHIP, Relationship.class); } } @@ -248,7 +248,7 @@ public boolean removeRelationship(Relationship relationship) throws InvalidSPDXA * @throws InvalidSPDXAnalysisException */ public Optional getComment() throws InvalidSPDXAnalysisException { - return this.getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + return this.getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); } /** @@ -257,7 +257,7 @@ public Optional getComment() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setComment(String comment) throws InvalidSPDXAnalysisException { - this.setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + this.setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); } @@ -265,7 +265,7 @@ public void setComment(String comment) throws InvalidSPDXAnalysisException { * @return the property name used for the Name property. Override this function if using a subproperty of SPDX Name */ protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstants.PROP_NAME; + return SpdxConstantsCompatV2.PROP_NAME; } /** diff --git a/src/main/java/org/spdx/library/model/SpdxFile.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java similarity index 93% rename from src/main/java/org/spdx/library/model/SpdxFile.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java index a3c6a0b22..6f9d727d1 100644 --- a/src/main/java/org/spdx/library/model/SpdxFile.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -30,11 +30,11 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -79,9 +79,9 @@ public SpdxFile(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - fileTypes = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_FILE_TYPE, FileType.class); - checksums = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_FILE_CHECKSUM, Checksum.class); - fileContributors = this.getStringCollection(SpdxConstants.PROP_FILE_CONTRIBUTOR); + fileTypes = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_FILE_TYPE, FileType.class); + checksums = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_FILE_CHECKSUM, Checksum.class); + fileContributors = this.getStringCollection(SpdxConstantsCompatV2.PROP_FILE_CONTRIBUTOR); } protected SpdxFile(SpdxFileBuilder spdxFileBuilder) throws InvalidSPDXAnalysisException { @@ -117,11 +117,11 @@ protected SpdxFile(SpdxFileBuilder spdxFileBuilder) throws InvalidSPDXAnalysisEx } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_FILE; + return SpdxConstantsCompatV2.CLASS_SPDX_FILE; } /** @@ -170,12 +170,12 @@ public SpdxFile setLicenseComments(String licenseComments) throws InvalidSPDXAna @Override protected PropertyDescriptor getLicenseInfoFromFilesPropertyName() { - return SpdxConstants.PROP_FILE_SEEN_LICENSE; + return SpdxConstantsCompatV2.PROP_FILE_SEEN_LICENSE; } @Override protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstants.PROP_FILE_NAME; + return SpdxConstantsCompatV2.PROP_FILE_NAME; } /** @@ -237,7 +237,7 @@ public boolean addFileContributor(String contributor) { * @return the noticeText */ public Optional getNoticeText() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_FILE_NOTICE); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_FILE_NOTICE); } /** @@ -245,7 +245,7 @@ public Optional getNoticeText() throws InvalidSPDXAnalysisException { * @return this so you can chain setters */ public SpdxFile setNoticeText(@Nullable String noticeText) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_FILE_NOTICE, noticeText); + setPropertyValue(SpdxConstantsCompatV2.PROP_FILE_NOTICE, noticeText); return this; } @@ -256,11 +256,11 @@ public SpdxFile setNoticeText(@Nullable String noticeText) throws InvalidSPDXAna @Deprecated @SuppressWarnings("unchecked") public Collection getFileDependency() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_FILE_FILE_DEPENDENCY, SpdxFile.class); + return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_FILE_FILE_DEPENDENCY, SpdxFile.class); } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/SpdxIdInUseException.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxIdInUseException.java similarity index 97% rename from src/main/java/org/spdx/library/model/SpdxIdInUseException.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxIdInUseException.java index 041a5730d..3d9e87973 100644 --- a/src/main/java/org/spdx/library/model/SpdxIdInUseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxIdInUseException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/SpdxIdNotFoundException.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxIdNotFoundException.java similarity index 97% rename from src/main/java/org/spdx/library/model/SpdxIdNotFoundException.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxIdNotFoundException.java index d2c0e7575..213ff04ba 100644 --- a/src/main/java/org/spdx/library/model/SpdxIdNotFoundException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxIdNotFoundException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/SpdxInvalidTypeException.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxInvalidTypeException.java similarity index 97% rename from src/main/java/org/spdx/library/model/SpdxInvalidTypeException.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxInvalidTypeException.java index cb2b8e830..1718d7b72 100644 --- a/src/main/java/org/spdx/library/model/SpdxInvalidTypeException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxInvalidTypeException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/SpdxItem.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java similarity index 85% rename from src/main/java/org/spdx/library/model/SpdxItem.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java index e69e71fbc..43445fd47 100644 --- a/src/main/java/org/spdx/library/model/SpdxItem.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Collection; import java.util.List; @@ -26,10 +26,10 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -72,14 +72,14 @@ public SpdxItem(IModelStore modelStore, String documentUri, String id, * @return Property name for licenseInfoFromFiles. Override if using a subproperty of "licenseDeclared". */ protected PropertyDescriptor getLicenseInfoFromFilesPropertyName() { - return SpdxConstants.PROP_PACKAGE_LICENSE_INFO_FROM_FILES; + return SpdxConstantsCompatV2.PROP_PACKAGE_LICENSE_INFO_FROM_FILES; } /** * @return the licenseConcluded */ public AnyLicenseInfo getLicenseConcluded() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_LICENSE_CONCLUDED); + Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_CONCLUDED); if (retval.isPresent()) { return retval.get(); } else { @@ -95,7 +95,7 @@ public AnyLicenseInfo getLicenseConcluded() throws InvalidSPDXAnalysisException * @throws InvalidSPDXAnalysisException */ public SpdxItem setLicenseConcluded(@Nullable AnyLicenseInfo license) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_CONCLUDED, license); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_CONCLUDED, license); return this; } @@ -108,7 +108,7 @@ public Collection getLicenseInfoFromFiles() throws InvalidSPDXAn * @return the copyrightText, empty string if no copyright was set */ public String getCopyrightText() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_COPYRIGHT_TEXT); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_COPYRIGHT_TEXT); if (retval.isPresent()) { return retval.get(); } else { @@ -121,7 +121,7 @@ public String getCopyrightText() throws InvalidSPDXAnalysisException { * @return myself - so you can chain setters */ public SpdxItem setCopyrightText(@Nullable String copyrightText) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_COPYRIGHT_TEXT, copyrightText); + setPropertyValue(SpdxConstantsCompatV2.PROP_COPYRIGHT_TEXT, copyrightText); return this; } @@ -130,7 +130,7 @@ public SpdxItem setCopyrightText(@Nullable String copyrightText) throws InvalidS * @throws InvalidSPDXAnalysisException */ public Collection getAttributionText() throws InvalidSPDXAnalysisException { - return getStringCollection(SpdxConstants.PROP_ATTRIBUTION_TEXT); + return getStringCollection(SpdxConstantsCompatV2.PROP_ATTRIBUTION_TEXT); } @Override @@ -143,7 +143,7 @@ public SpdxItem setName(String name) throws InvalidSPDXAnalysisException { * @return the licenseComment */ public Optional getLicenseComments() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_LIC_COMMENTS); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_LIC_COMMENTS); } /** @@ -151,12 +151,12 @@ public Optional getLicenseComments() throws InvalidSPDXAnalysisException * @return this so you chan chain setters */ public SpdxItem setLicenseComments(String licenseComments) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LIC_COMMENTS, licenseComments); + setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_COMMENTS, licenseComments); return this; } /* (non-Javadoc) - * @see org.spdx.library.model.SpdxElement#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -174,7 +174,7 @@ protected List _verify(Set verifiedIds, String specVersion) { Optional concluded; try { - concluded = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_LICENSE_CONCLUDED); + concluded = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_CONCLUDED); if (!concluded.isPresent()) { if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { retval.add("Missing required concluded license for "+name); diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java new file mode 100644 index 000000000..6b752b1ff --- /dev/null +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java @@ -0,0 +1,319 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model.compat.v2; + +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; + +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.Version; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.Purpose; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.CrossRef; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.License; +import org.spdx.library.model.compat.v2.license.LicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenses; +import org.spdx.library.model.compat.v2.license.OrLaterOperator; +import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.license.WithExceptionOperator; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.CompoundPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.SinglePointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; + +/** + * Factory class to create ModelObjects based on the type + * Types are defined classes in the SpdxConstantsCompatV2 class and map to the standard SPDX model + * + * @author Gary O'Neall + * + */ +public class SpdxModelFactory { + + static final Logger logger = LoggerFactory.getLogger(SpdxModelFactory.class); + + public static Map> SPDX_TYPE_TO_CLASS; + public static Map, String> SPDX_CLASS_TO_TYPE; + static { + Map> typeToClass = new HashMap<>(); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, SpdxDocument.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, SpdxPackage.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO, SpdxCreatorInformation.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, Checksum.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO, AnyLicenseInfo.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO, SimpleLicensingInfo.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, ConjunctiveLicenseSet.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, DisjunctiveLicenseSet.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, ExtractedLicenseInfo.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE, License.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, SpdxListedLicense.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, LicenseException.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, ListedLicenseException.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR, OrLaterOperator.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, WithExceptionOperator.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_FILE, SpdxFile.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE, SpdxPackageVerificationCode.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_ANNOTATION, Annotation.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_RELATIONSHIP, Relationship.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ITEM, SpdxItem.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT, SpdxElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT, SpdxNoneElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT, SpdxNoAssertionElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, ExternalDocumentRef.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE, ExternalRef.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE, ReferenceType.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, SpdxSnippet.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE, SpdxNoAssertionLicense.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_NONE_LICENSE, SpdxNoneLicense.class); + typeToClass.put(GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, GenericModelObject.class); + typeToClass.put(GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, GenericSpdxElement.class); + typeToClass.put(GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, GenericSpdxItem.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT, ExternalSpdxElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER, StartEndPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER, ByteOffsetPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER, LineCharPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, CompoundPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, SinglePointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, CrossRef.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, FileType.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, AnnotationType.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, ChecksumAlgorithm.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, ReferenceCategory.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, RelationshipType.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, ExternalExtractedLicenseInfo.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_PURPOSE, Purpose.class); + SPDX_TYPE_TO_CLASS = Collections.unmodifiableMap(typeToClass); + + Map, String> classToType = new HashMap<>(); + for (Entry> entry:typeToClass.entrySet()) { + classToType.put(entry.getValue(), entry.getKey()); + } + + SPDX_CLASS_TO_TYPE = Collections.unmodifiableMap(classToType); + } + + + /** + * Create an SPDX document with default values for creator, created, licenseListVersion, data license and specVersion + * @param modelStore Where to store the SPDX Document + * @param documentUri unique URI for the SPDX document + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @return + * @throws InvalidSPDXAnalysisException + */ + public static SpdxDocument createSpdxDocument(IModelStore modelStore, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SpdxDocument retval = new SpdxDocument(modelStore, documentUri, copyManager, true); + String date = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); + SpdxCreatorInformation creationInfo = new SpdxCreatorInformation( + modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); + creationInfo.getCreators().add("Tool: SPDX Tools"); + creationInfo.setCreated(date); + creationInfo.setLicenseListVersion(ListedLicenses.getListedLicenses().getLicenseListVersion()); + retval.setCreationInfo(creationInfo); + retval.setDataLicense(ListedLicenses.getListedLicenses().getListedLicenseById(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)); + retval.setSpecVersion(Version.CURRENT_SPDX_VERSION); + return retval; + } + + /** + * Create a model object in a model store given the document URI, ID and type + * @param modelStore model store where the object is to be created + * @param documentUri document URI for the stored item + * @param id ID for the item + * @param type SPDX class or type + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @return a ModelObject of type type + * @throws InvalidSPDXAnalysisException + */ + public static ModelObject createModelObject(IModelStore modelStore, String documentUri, String id, + String type, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + return getModelObject(modelStore, documentUri, id, type, copyManager, true); + } + + /** + * Create a model object in a model store given the document URI, ID and type + * @param modelStore model store where the object is to be created + * @param documentUri document URI for the stored item + * @param id ID for the item + * @param type SPDX class or type + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @param create if true, create the model object if it does not already exist + * @return a ModelObject of type type + * @throws InvalidSPDXAnalysisException + */ + public static ModelObject getModelObject(IModelStore modelStore, String documentUri, String id, + String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { + switch (type) { + case SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT: return new SpdxDocument(modelStore, documentUri, copyManager, create); //Note: the ID is ignored + case SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE: return new SpdxPackage(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO: return new SpdxCreatorInformation(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM: return new Checksum(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract AnyLicensing Info. Must specify one of the concrete classes"); + case SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract SimpleLicensingInfo. Must specify one of the concrete classes"); + case SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET: return new ConjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET: return new DisjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO: return new ExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE: throw new InvalidSPDXAnalysisException("Can not create abstract License. Must specify one of the concrete classes"); + case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE: return new SpdxListedLicense(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION: return new LicenseException(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION: return new ListedLicenseException(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR: return new OrLaterOperator(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR: return new WithExceptionOperator(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_FILE: return new SpdxFile(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_REVIEW: throw new RuntimeException("SPDX Review class is no longer supported"); + case SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE: return new SpdxPackageVerificationCode(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_ANNOTATION: return new Annotation(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_RELATIONSHIP: return new Relationship(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_ITEM: throw new RuntimeException("SPDX item is an abstract item and can not be created."); + case SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT: throw new RuntimeException("SPDX element is an abstract item and can not be created."); + case SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT: return new SpdxNoneElement(modelStore, documentUri); + case SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT: return new SpdxNoAssertionElement(modelStore, documentUri); + case SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF: return new ExternalDocumentRef(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE: return new ExternalRef(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE: return new ExternalExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE: throw new RuntimeException("Reference type can only be created with a type supplied."); + case SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET: return new SpdxSnippet(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE: return new SpdxNoAssertionLicense(modelStore, documentUri); + case SpdxConstantsCompatV2.CLASS_NONE_LICENSE: return new SpdxNoneLicense(modelStore, documentUri); + case GenericModelObject.GENERIC_MODEL_OBJECT_TYPE: return new GenericModelObject(modelStore, documentUri, id, copyManager, create); + case GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE: return new GenericSpdxElement(modelStore, documentUri, id, copyManager, create); + case GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE: return new GenericSpdxItem(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT: return new ExternalSpdxElement(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER: return new StartEndPointer(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER: return new ByteOffsetPointer(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER: return new LineCharPointer(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_CROSS_REF: return new CrossRef(modelStore, documentUri, id, copyManager, create); + default: throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); + } + } + + /** + * @param type SPDX Type + * @return class associated with the type + * @throws InvalidSPDXAnalysisException + */ + public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { + Class retval = SPDX_TYPE_TO_CLASS.get(type); + if (Objects.isNull(retval)) { + throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); + } + return retval; + } + + public static Stream getElements(IModelStore store, String documentUri, ModelCopyManager copyManager, + Class spdxClass) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(store, "Store must not be null"); + Objects.requireNonNull(documentUri, "documentUri must not be null"); + Objects.requireNonNull(spdxClass, "spdxClass must not be null"); + String type = SPDX_CLASS_TO_TYPE.get(spdxClass); + if (Objects.isNull(type)) { + throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); + } + return store.getAllItems(documentUri, type).map(tv -> { + try { + return createModelObject(store, documentUri, tv.getId(), tv.getType(), copyManager); + } catch (InvalidSPDXAnalysisException e) { + logger.error("Error creating model object",e); + throw new RuntimeException(e); + } + }); + } + + /** + * @param classUri URI for the class type + * @return class represented by the URI + * @throws InvalidSPDXAnalysisException + */ + public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(classUri, "Missing required class URI"); + int indexOfPound = classUri.lastIndexOf('#'); + if (indexOfPound < 1) { + throw new InvalidSPDXAnalysisException("Invalid class URI: "+classUri); + } + String type = classUri.substring(indexOfPound+1); + return typeToClass(type); + } + + /** + * @param modelStore Store for the model + * @param documentUri Document URI for for the ID + * @param copyManager Optional copy manager for copying any properties from other model + * @param id ID for the model object + * @return ModelObject with the ID in the model store + * @throws InvalidSPDXAnalysisException + */ + public static Optional getModelObject(IModelStore modelStore, String documentUri, + String id, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (id.contains(":")) { + // External document ref + try { + return Optional.of(new ExternalSpdxElement(modelStore, documentUri, id, copyManager, true)); + } catch(InvalidSPDXAnalysisException ex) { + logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty"); + return Optional.empty(); + } + } + Optional tv = modelStore.getTypedValue(documentUri, id); + if (tv.isPresent()) { + String type = tv.get().getType(); + try { + return Optional.of(getModelObject(modelStore, documentUri, id, type, copyManager, false)); + } catch(SpdxIdNotFoundException ex) { + return Optional.empty(); // There is a window where the ID disappears between getTypedValue and getModelObject + } + } else { + if (SpdxConstantsCompatV2.NOASSERTION_VALUE.equals(id)) { + return Optional.of(new SpdxNoAssertionElement()); + } else if (SpdxConstantsCompatV2.NONE_VALUE.equals(id)) { + return Optional.of(new SpdxNoneElement()); + } else { + return Optional.empty(); + } + } + } +} diff --git a/src/main/java/org/spdx/library/model/SpdxNoAssertionElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java similarity index 92% rename from src/main/java/org/spdx/library/model/SpdxNoAssertionElement.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java index 1967cf9ef..9f00dddc8 100644 --- a/src/main/java/org/spdx/library/model/SpdxNoAssertionElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; /** @@ -58,7 +58,7 @@ public SpdxNoAssertionElement(IModelStore modelStore, String documentUri) @Override public String toString() { - return SpdxConstants.NOASSERTION_VALUE; + return SpdxConstantsCompatV2.NOASSERTION_VALUE; } @Override @@ -73,6 +73,6 @@ public Optional getComment() throws InvalidSPDXAnalysisException { @Override public String getIndividualURI() { - return SpdxConstants.URI_VALUE_NOASSERTION; + return SpdxConstantsCompatV2.URI_VALUE_NOASSERTION; } } diff --git a/src/main/java/org/spdx/library/model/SpdxNoneElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java similarity index 92% rename from src/main/java/org/spdx/library/model/SpdxNoneElement.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java index 6ae20834f..cb9536b59 100644 --- a/src/main/java/org/spdx/library/model/SpdxNoneElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; /** @@ -58,7 +58,7 @@ public SpdxNoneElement(IModelStore modelStore, String documentUri) @Override public String toString() { - return SpdxConstants.NONE_VALUE; + return SpdxConstantsCompatV2.NONE_VALUE; } @Override @@ -73,7 +73,7 @@ public Optional getComment() throws InvalidSPDXAnalysisException { @Override public String getIndividualURI() { - return SpdxConstants.URI_VALUE_NONE; + return SpdxConstantsCompatV2.URI_VALUE_NONE; } } diff --git a/src/main/java/org/spdx/library/model/SpdxPackage.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java similarity index 91% rename from src/main/java/org/spdx/library/model/SpdxPackage.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java index 1796a2800..f0c409f75 100644 --- a/src/main/java/org/spdx/library/model/SpdxPackage.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -28,18 +28,18 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.Purpose; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.OrLaterOperator; -import org.spdx.library.model.license.SimpleLicensingInfo; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; -import org.spdx.library.model.license.WithExceptionOperator; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.Purpose; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.OrLaterOperator; +import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.license.WithExceptionOperator; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.PropertyDescriptor; @@ -58,7 +58,7 @@ public class SpdxPackage extends SpdxItem implements Comparable { */ public SpdxPackage() throws InvalidSPDXAnalysisException { super(); - files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstants.CLASS_SPDX_FILE); + files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstantsCompatV2.CLASS_SPDX_FILE); } /** @@ -73,7 +73,7 @@ public SpdxPackage(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstants.CLASS_SPDX_FILE); + files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstantsCompatV2.CLASS_SPDX_FILE); } /** @@ -82,7 +82,7 @@ public SpdxPackage(IModelStore modelStore, String documentUri, String id, */ public SpdxPackage(String id) throws InvalidSPDXAnalysisException { super(id); - files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstants.CLASS_SPDX_FILE); + files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstantsCompatV2.CLASS_SPDX_FILE); } protected SpdxPackage(SpdxPackageBuilder spdxPackageBuilder) throws InvalidSPDXAnalysisException { @@ -126,12 +126,12 @@ protected SpdxPackage(SpdxPackageBuilder spdxPackageBuilder) throws InvalidSPDXA @Override public String getType() { - return SpdxConstants.CLASS_SPDX_PACKAGE; + return SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE; } @Override protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstants.PROP_NAME; + return SpdxConstantsCompatV2.PROP_NAME; } /** @@ -139,7 +139,7 @@ protected PropertyDescriptor getNamePropertyDescriptor() { * @throws InvalidSPDXAnalysisException */ public boolean isFilesAnalyzed() throws InvalidSPDXAnalysisException { - Optional filesAnalyzed = getBooleanPropertyValue(SpdxConstants.PROP_PACKAGE_FILES_ANALYZED); + Optional filesAnalyzed = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED); if (!filesAnalyzed.isPresent()) { return true; } else { @@ -153,7 +153,7 @@ public boolean isFilesAnalyzed() throws InvalidSPDXAnalysisException { * @return this to build additional options */ public SpdxPackage setFilesAnalyzed(@Nullable Boolean filesAnalyzed) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_FILES_ANALYZED, filesAnalyzed); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED, filesAnalyzed); return this; } @@ -162,7 +162,7 @@ public SpdxPackage setFilesAnalyzed(@Nullable Boolean filesAnalyzed) throws Inva * @throws InvalidSPDXAnalysisException */ public Optional getBuiltDate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_BUILT_DATE); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_BUILT_DATE); } /** @@ -173,7 +173,7 @@ public void setBuiltDate(String builtDate) throws InvalidSPDXAnalysisException { if (strict && Objects.nonNull(builtDate) && Objects.nonNull(SpdxVerificationHelper.verifyDate(builtDate))) { throw new InvalidSPDXAnalysisException("Invalid built date"); } - setPropertyValue(SpdxConstants.PROP_BUILT_DATE, builtDate); + setPropertyValue(SpdxConstantsCompatV2.PROP_BUILT_DATE, builtDate); } /** @@ -181,7 +181,7 @@ public void setBuiltDate(String builtDate) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Optional getReleaseDate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_RELEASE_DATE); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_RELEASE_DATE); } /** @@ -192,7 +192,7 @@ public void setReleaseDate(String releaseDate) throws InvalidSPDXAnalysisExcepti if (strict && Objects.nonNull(releaseDate) && Objects.nonNull(SpdxVerificationHelper.verifyDate(releaseDate))) { throw new InvalidSPDXAnalysisException("Invalid release date"); } - setPropertyValue(SpdxConstants.PROP_RELEASE_DATE, releaseDate); + setPropertyValue(SpdxConstantsCompatV2.PROP_RELEASE_DATE, releaseDate); } /** @@ -200,7 +200,7 @@ public void setReleaseDate(String releaseDate) throws InvalidSPDXAnalysisExcepti * @throws InvalidSPDXAnalysisException */ public Optional getValidUntilDate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_VALID_UNTIL_DATE); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_VALID_UNTIL_DATE); } /** @@ -211,7 +211,7 @@ public void setValidUntilDate(String validUntilDate) throws InvalidSPDXAnalysisE if (strict && Objects.nonNull(validUntilDate) && Objects.nonNull(SpdxVerificationHelper.verifyDate(validUntilDate))) { throw new InvalidSPDXAnalysisException("Invalid valid until date"); } - setPropertyValue(SpdxConstants.PROP_VALID_UNTIL_DATE, validUntilDate); + setPropertyValue(SpdxConstantsCompatV2.PROP_VALID_UNTIL_DATE, validUntilDate); } @@ -220,7 +220,7 @@ public void setValidUntilDate(String validUntilDate) throws InvalidSPDXAnalysisE * @throws InvalidSPDXAnalysisException */ public @Nullable AnyLicenseInfo getLicenseDeclared() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_PACKAGE_DECLARED_LICENSE); + Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DECLARED_LICENSE); if (retval.isPresent()) { return retval.get(); } else { @@ -236,7 +236,7 @@ public void setValidUntilDate(String validUntilDate) throws InvalidSPDXAnalysisE * @throws InvalidSPDXAnalysisException */ public SpdxPackage setLicenseDeclared(@Nullable AnyLicenseInfo licenseDeclared) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_DECLARED_LICENSE, licenseDeclared); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DECLARED_LICENSE, licenseDeclared); return this; } @@ -246,7 +246,7 @@ public SpdxPackage setLicenseDeclared(@Nullable AnyLicenseInfo licenseDeclared) */ @SuppressWarnings("unchecked") public Collection getChecksums() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_PACKAGE_CHECKSUM, Checksum.class); + return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_PACKAGE_CHECKSUM, Checksum.class); } /** @@ -264,7 +264,7 @@ public SpdxPackage addChecksum(Checksum checksum) throws InvalidSPDXAnalysisExce * @return the description */ public Optional getDescription() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_DESCRIPTION); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DESCRIPTION); } /** @@ -273,7 +273,7 @@ public Optional getDescription() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public SpdxPackage setDescription(String description) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_DESCRIPTION, description); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DESCRIPTION, description); return this; } @@ -281,7 +281,7 @@ public SpdxPackage setDescription(String description) throws InvalidSPDXAnalysis * @return the downloadLocation */ public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_DOWNLOAD_URL); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DOWNLOAD_URL); } /** @@ -296,7 +296,7 @@ public SpdxPackage setDownloadLocation(String downloadLocation) throws InvalidSP throw new InvalidSPDXAnalysisException(verify); } } - setPropertyValue(SpdxConstants.PROP_PACKAGE_DOWNLOAD_URL, downloadLocation); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DOWNLOAD_URL, downloadLocation); return this; } @@ -304,7 +304,7 @@ public SpdxPackage setDownloadLocation(String downloadLocation) throws InvalidSP * @return the homepage */ public Optional getHomepage() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PROJECT_HOMEPAGE); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PROJECT_HOMEPAGE); } /** @@ -318,7 +318,7 @@ public SpdxPackage setHomepage(String homepage) throws InvalidSPDXAnalysisExcept throw new InvalidSPDXAnalysisException(homepage + " is not a valid URI"); } } - setPropertyValue(SpdxConstants.PROP_PROJECT_HOMEPAGE, homepage); + setPropertyValue(SpdxConstantsCompatV2.PROP_PROJECT_HOMEPAGE, homepage); return this; } @@ -326,7 +326,7 @@ public SpdxPackage setHomepage(String homepage) throws InvalidSPDXAnalysisExcept * @return the originator */ public Optional getOriginator() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_ORIGINATOR); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_ORIGINATOR); } /** @@ -342,7 +342,7 @@ public SpdxPackage setOriginator(String originator) throws InvalidSPDXAnalysisEx } } - setPropertyValue(SpdxConstants.PROP_PACKAGE_ORIGINATOR, originator); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_ORIGINATOR, originator); return this; } @@ -350,7 +350,7 @@ public SpdxPackage setOriginator(String originator) throws InvalidSPDXAnalysisEx * @return the packageFileName */ public Optional getPackageFileName() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_FILE_NAME); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILE_NAME); } /** @@ -359,7 +359,7 @@ public Optional getPackageFileName() throws InvalidSPDXAnalysisException * @throws InvalidSPDXAnalysisException */ public SpdxPackage setPackageFileName(String packageFileName) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_FILE_NAME, packageFileName); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILE_NAME, packageFileName); return this; } @@ -368,7 +368,7 @@ public SpdxPackage setPackageFileName(String packageFileName) throws InvalidSPDX * @throws InvalidSPDXAnalysisException */ public Optional getPackageVerificationCode() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_PACKAGE_VERIFICATION_CODE); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERIFICATION_CODE); if (!retval.isPresent()) { return Optional.empty(); } @@ -387,7 +387,7 @@ public SpdxPackage setPackageVerificationCode(SpdxPackageVerificationCode verifi if (strict && Objects.isNull(verificationCode) && isFilesAnalyzed()) { throw new InvalidSPDXAnalysisException("Can not set required verificationCode to null"); } - setPropertyValue(SpdxConstants.PROP_PACKAGE_VERIFICATION_CODE, verificationCode); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERIFICATION_CODE, verificationCode); return this; } @@ -395,7 +395,7 @@ public SpdxPackage setPackageVerificationCode(SpdxPackageVerificationCode verifi * @return the sourceInfo */ public Optional getSourceInfo() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_SOURCE_INFO); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SOURCE_INFO); } /** @@ -404,7 +404,7 @@ public Optional getSourceInfo() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public SpdxPackage setSourceInfo(String sourceInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_SOURCE_INFO, sourceInfo); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SOURCE_INFO, sourceInfo); return this; } @@ -412,7 +412,7 @@ public SpdxPackage setSourceInfo(String sourceInfo) throws InvalidSPDXAnalysisEx * @return the summary */ public Optional getSummary() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_SHORT_DESC); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SHORT_DESC); } /** @@ -421,7 +421,7 @@ public Optional getSummary() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public SpdxPackage setSummary(String summary) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_SHORT_DESC, summary); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SHORT_DESC, summary); return this; } @@ -429,7 +429,7 @@ public SpdxPackage setSummary(String summary) throws InvalidSPDXAnalysisExceptio * @return the supplier */ public Optional getSupplier() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_SUPPLIER); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SUPPLIER); } /** @@ -444,7 +444,7 @@ public SpdxPackage setSupplier(String supplier) throws InvalidSPDXAnalysisExcept throw new InvalidSPDXAnalysisException(verify); } } - setPropertyValue(SpdxConstants.PROP_PACKAGE_SUPPLIER, supplier); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SUPPLIER, supplier); return this; } @@ -452,7 +452,7 @@ public SpdxPackage setSupplier(String supplier) throws InvalidSPDXAnalysisExcept * @return the versionInfo */ public Optional getVersionInfo() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_PACKAGE_VERSION_INFO); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERSION_INFO); } /** @@ -461,7 +461,7 @@ public Optional getVersionInfo() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public SpdxPackage setVersionInfo(String versionInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PACKAGE_VERSION_INFO, versionInfo); + setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERSION_INFO, versionInfo); return this; } @@ -471,7 +471,7 @@ public SpdxPackage setVersionInfo(String versionInfo) throws InvalidSPDXAnalysis */ @SuppressWarnings("unchecked") public Collection getExternalRefs() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_EXTERNAL_REF, ExternalRef.class); + return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_EXTERNAL_REF, ExternalRef.class); } /** @@ -512,7 +512,7 @@ public SpdxPackage addFile(SpdxFile file) throws InvalidSPDXAnalysisException { */ @SuppressWarnings("unchecked") public Optional getPrimaryPurpose() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.PROP_PRIMARY_PACKAGE_PURPOSE); + Optional> retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_PRIMARY_PACKAGE_PURPOSE); if (retval.isPresent() && !(retval.get() instanceof Purpose)) { throw new SpdxInvalidTypeException("Invalid enum type for "+retval.get().toString()); } @@ -524,11 +524,11 @@ public Optional getPrimaryPurpose() throws InvalidSPDXAnalysisException * @throws InvalidSPDXAnalysisException */ public void setPrimaryPurpose(Purpose purpose) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_PRIMARY_PACKAGE_PURPOSE, purpose); + setPropertyValue(SpdxConstantsCompatV2.PROP_PRIMARY_PACKAGE_PURPOSE, purpose); } /* (non-Javadoc) - * @see org.spdx.library.model.SpdxItem#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.SpdxItem#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -586,7 +586,7 @@ protected List _verify(Set verifiedIds, String specVersion) { // license declared try { - Optional declaredLicense = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_PACKAGE_DECLARED_LICENSE); + Optional declaredLicense = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DECLARED_LICENSE); if (!declaredLicense.isPresent()) { if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { retval.add("Missing required declared license for package "+pkgName); diff --git a/src/main/java/org/spdx/library/model/SpdxPackageVerificationCode.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java similarity index 85% rename from src/main/java/org/spdx/library/model/SpdxPackageVerificationCode.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java index ead4848c7..704981789 100644 --- a/src/main/java/org/spdx/library/model/SpdxPackageVerificationCode.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -28,9 +28,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; /** @@ -69,11 +69,11 @@ public SpdxPackageVerificationCode(IModelStore modelStore, String documentUri, S } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_VERIFICATIONCODE; + return SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE; } @@ -82,7 +82,7 @@ public String getType() { * @throws InvalidSPDXAnalysisException */ public String getValue() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.PROP_VERIFICATIONCODE_VALUE); + Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_VERIFICATIONCODE_VALUE); if (retval.isPresent()) { return retval.get(); } else { @@ -100,7 +100,7 @@ public void setValue(String value) throws InvalidSPDXAnalysisException { if (strict && (Objects.isNull(value) || value.isEmpty())) { throw new InvalidSPDXAnalysisException("Can not set required verification code value to null or empty string"); } - setPropertyValue(SpdxConstants.PROP_VERIFICATIONCODE_VALUE, value); + setPropertyValue(SpdxConstantsCompatV2.PROP_VERIFICATIONCODE_VALUE, value); } /** @@ -108,11 +108,11 @@ public void setValue(String value) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Collection getExcludedFileNames() throws InvalidSPDXAnalysisException { - return this.getStringCollection(SpdxConstants.PROP_VERIFICATIONCODE_IGNORED_FILES); + return this.getStringCollection(SpdxConstantsCompatV2.PROP_VERIFICATIONCODE_IGNORED_FILES); } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/SpdxSnippet.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java similarity index 95% rename from src/main/java/org/spdx/library/model/SpdxSnippet.java rename to src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java index 76bccc691..25d4f0dfa 100644 --- a/src/main/java/org/spdx/library/model/SpdxSnippet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Collection; @@ -29,12 +29,12 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.SinglePointer; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.SinglePointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -81,7 +81,7 @@ public SpdxSnippet(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - allRanges = new ModelCollection(modelStore, documentUri, id, SpdxConstants.PROP_SNIPPET_RANGE, copyManager, StartEndPointer.class); + allRanges = new ModelCollection(modelStore, documentUri, id, SpdxConstantsCompatV2.PROP_SNIPPET_RANGE, copyManager, StartEndPointer.class); } /** @@ -114,16 +114,16 @@ public SpdxSnippet(SpdxSnippetBuilder spdxSnippetBuilder) throws InvalidSPDXAnal } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_SNIPPET; + return SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET; } @Override public PropertyDescriptor getLicenseInfoFromFilesPropertyName() { - return SpdxConstants.PROP_LICENSE_INFO_FROM_SNIPPETS; + return SpdxConstantsCompatV2.PROP_LICENSE_INFO_FROM_SNIPPETS; } @@ -132,7 +132,7 @@ public PropertyDescriptor getLicenseInfoFromFilesPropertyName() { * @throws InvalidSPDXAnalysisException */ public @Nullable SpdxFile getSnippetFromFile() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_SNIPPET_FROM_FILE); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_SNIPPET_FROM_FILE); if (!retval.isPresent()) { return null; } @@ -151,7 +151,7 @@ public SpdxSnippet setSnippetFromFile(SpdxFile snippetFromFile) throws InvalidSP if (strict && Objects.isNull(snippetFromFile)) { throw new InvalidSPDXAnalysisException("Can not set required snippetFromFile to null"); } - setPropertyValue(SpdxConstants.PROP_SNIPPET_FROM_FILE, snippetFromFile); + setPropertyValue(SpdxConstantsCompatV2.PROP_SNIPPET_FROM_FILE, snippetFromFile); // Update the references in the ranges StartEndPointer byteRange = getByteRange(); if (byteRange != null) { @@ -301,7 +301,7 @@ private void setPointerReferences(@Nullable StartEndPointer pointer) throws Inva } /* (non-Javadoc) - * @see org.spdx.library.model.SpdxItem#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.SpdxItem#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/TypedValue.java b/src/main/java/org/spdx/library/model/compat/v2/TypedValue.java similarity index 91% rename from src/main/java/org/spdx/library/model/TypedValue.java rename to src/main/java/org/spdx/library/model/compat/v2/TypedValue.java index f346f13ad..3f736ba60 100644 --- a/src/main/java/org/spdx/library/model/TypedValue.java +++ b/src/main/java/org/spdx/library/model/compat/v2/TypedValue.java @@ -1,10 +1,10 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidIdException; @@ -13,7 +13,7 @@ */ public class TypedValue { - static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstants.ALL_SPDX_CLASSES)); + static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); String id; String type; diff --git a/src/main/java/org/spdx/library/model/enumerations/AnnotationType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java similarity index 85% rename from src/main/java/org/spdx/library/model/enumerations/AnnotationType.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java index 4b944e75f..24c9f5fd2 100644 --- a/src/main/java/org/spdx/library/model/enumerations/AnnotationType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Annotation types for the Annotation Class @@ -47,7 +47,7 @@ public String getLongName() { } public String getNameSpace() { - return SpdxConstants.SPDX_NAMESPACE; + return SpdxConstantsCompatV2.SPDX_NAMESPACE; } } diff --git a/src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java similarity index 89% rename from src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java index 9bd752898..5cbba9514 100644 --- a/src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Enum constants for Checksum Algorithms @@ -62,7 +62,7 @@ public String getLongName() { } public String getNameSpace() { - return SpdxConstants.SPDX_NAMESPACE; + return SpdxConstantsCompatV2.SPDX_NAMESPACE; } } diff --git a/src/main/java/org/spdx/library/model/enumerations/FileType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java similarity index 87% rename from src/main/java/org/spdx/library/model/enumerations/FileType.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java index 0901303a0..c9239c7bb 100644 --- a/src/main/java/org/spdx/library/model/enumerations/FileType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; /** * File Type is intrinsic to the file, independent of how the file is being used. @@ -56,7 +56,7 @@ public String getLongName() { } public String getNameSpace() { - return SpdxConstants.SPDX_NAMESPACE; + return SpdxConstantsCompatV2.SPDX_NAMESPACE; } } diff --git a/src/main/java/org/spdx/library/model/enumerations/Purpose.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java similarity index 87% rename from src/main/java/org/spdx/library/model/enumerations/Purpose.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java index 03e1a34c5..1667dce9e 100644 --- a/src/main/java/org/spdx/library/model/enumerations/Purpose.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Package Purpose is intrinsic to how the package is being used rather than the content of the package. @@ -56,7 +56,7 @@ public String getLongName() { } public String getNameSpace() { - return SpdxConstants.SPDX_NAMESPACE; + return SpdxConstantsCompatV2.SPDX_NAMESPACE; } } diff --git a/src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java similarity index 86% rename from src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java index 9f6001735..8d074e42d 100644 --- a/src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Reference category for external refs @@ -49,6 +49,6 @@ public String getLongName() { } public String getNameSpace() { - return SpdxConstants.SPDX_NAMESPACE; + return SpdxConstantsCompatV2.SPDX_NAMESPACE; } } diff --git a/src/main/java/org/spdx/library/model/enumerations/RelationshipType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java similarity index 94% rename from src/main/java/org/spdx/library/model/enumerations/RelationshipType.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java index b6744d110..aefa76343 100644 --- a/src/main/java/org/spdx/library/model/enumerations/RelationshipType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Relationship types @@ -91,6 +91,6 @@ public String getLongName() { } public String getNameSpace() { - return SpdxConstants.SPDX_NAMESPACE; + return SpdxConstantsCompatV2.SPDX_NAMESPACE; } } diff --git a/src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactory.java similarity index 97% rename from src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactory.java index 31b654f90..896e4150e 100644 --- a/src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactory.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import java.util.Collections; import java.util.HashMap; diff --git a/src/main/java/org/spdx/library/model/enumerations/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java similarity index 94% rename from src/main/java/org/spdx/library/model/enumerations/package-info.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java index e0270e935..3f6bce7f5 100644 --- a/src/main/java/org/spdx/library/model/enumerations/package-info.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java @@ -24,4 +24,4 @@ * * @author Gary O'Neall */ -package org.spdx.library.model.enumerations; \ No newline at end of file +package org.spdx.library.model.compat.v2.enumerations; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/license/AbstractExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java similarity index 96% rename from src/main/java/org/spdx/library/model/license/AbstractExtractedLicenseInfo.java rename to src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java index dcb142797..7d40c5853 100644 --- a/src/main/java/org/spdx/library/model/license/AbstractExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/license/AnyLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java similarity index 96% rename from src/main/java/org/spdx/library/model/license/AnyLicenseInfo.java rename to src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java index af3f2a363..575ab7e04 100644 --- a/src/main/java/org/spdx/library/model/license/AnyLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import javax.annotation.Nullable; @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.ModelObject; +import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/license/ConjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java similarity index 95% rename from src/main/java/org/spdx/library/model/license/ConjunctiveLicenseSet.java rename to src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java index 442e7fe60..a26220ca5 100644 --- a/src/main/java/org/spdx/library/model/license/ConjunctiveLicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.HashSet; @@ -25,9 +25,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -211,6 +211,6 @@ protected boolean setsEquivalent(ConjunctiveLicenseSet compare) throws InvalidSP @Override public String getType() { - return SpdxConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET; + return SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET; } } diff --git a/src/main/java/org/spdx/library/model/license/CrossRef.java b/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java similarity index 82% rename from src/main/java/org/spdx/library/model/license/CrossRef.java rename to src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java index 5f2495056..99615cd81 100644 --- a/src/main/java/org/spdx/library/model/license/CrossRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; @@ -27,8 +27,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; @@ -84,22 +84,22 @@ protected CrossRef(CrossRefBuilder builder) throws InvalidSPDXAnalysisException } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_CROSS_REF; + return SpdxConstantsCompatV2.CLASS_CROSS_REF; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { List retval = new ArrayList<>(); Optional url; try { - url = getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_URL); + url = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL); if (!url.isPresent()) { retval.add("Missing required URL"); } @@ -114,7 +114,7 @@ protected List _verify(Set verifiedIds, String specVersion) { * @throws InvalidSPDXAnalysisException */ public Optional getMatch() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_MATCH); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH); } /** @@ -122,7 +122,7 @@ public Optional getMatch() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setMatch(@Nullable String match) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_CROSS_REF_MATCH, match); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH, match); } /** @@ -130,7 +130,7 @@ public void setMatch(@Nullable String match) throws InvalidSPDXAnalysisException * @throws InvalidSPDXAnalysisException */ public Optional getUrl() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_URL); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL); } /** @@ -141,7 +141,7 @@ public void setUrl(String url) throws InvalidSPDXAnalysisException { if (strict) { Objects.requireNonNull(url, "URL must not be null"); } - setPropertyValue(SpdxConstants.PROP_CROSS_REF_URL, url); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL, url); } /** @@ -149,7 +149,7 @@ public void setUrl(String url) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Optional getValid() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.PROP_CROSS_REF_IS_VALID); + return getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID); } /** @@ -157,7 +157,7 @@ public Optional getValid() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setValid(@Nullable Boolean isValid) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_CROSS_REF_IS_VALID, isValid); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID, isValid); } /** @@ -165,7 +165,7 @@ public void setValid(@Nullable Boolean isValid) throws InvalidSPDXAnalysisExcept * @throws InvalidSPDXAnalysisException */ public Optional getLive() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.PROP_CROSS_REF_IS_LIVE); + return getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE); } /** @@ -173,7 +173,7 @@ public Optional getLive() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setLive(Boolean isLive) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_CROSS_REF_IS_LIVE, isLive); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE, isLive); } /** @@ -181,7 +181,7 @@ public void setLive(Boolean isLive) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Optional getTimestamp() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_TIMESTAMP); + return getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP); } /** @@ -189,7 +189,7 @@ public Optional getTimestamp() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setTimestamp(String timestamp) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_CROSS_REF_TIMESTAMP, timestamp); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP, timestamp); } /** @@ -197,7 +197,7 @@ public void setTimestamp(String timestamp) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public Optional getIsWayBackLink() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK); + return getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK); } /** @@ -205,7 +205,7 @@ public Optional getIsWayBackLink() throws InvalidSPDXAnalysisException * @throws InvalidSPDXAnalysisException */ public void setIsWayBackLink(Boolean isWayBackLink) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK, isWayBackLink); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK, isWayBackLink); } /** @@ -213,7 +213,7 @@ public void setIsWayBackLink(Boolean isWayBackLink) throws InvalidSPDXAnalysisEx * @throws InvalidSPDXAnalysisException */ public Optional getOrder() throws InvalidSPDXAnalysisException { - return getIntegerPropertyValue(SpdxConstants.PROP_CROSS_REF_ORDER); + return getIntegerPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER); } /** @@ -221,7 +221,7 @@ public Optional getOrder() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setOrder(Integer order) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_CROSS_REF_ORDER, order); + setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER, order); } /** @@ -249,7 +249,7 @@ public void setDetails(@Nullable Boolean isValid, @Nullable Boolean isLive, @Nul public String toString(){ String url; try { - Optional oUrl = getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_URL); + Optional oUrl = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL); if (oUrl.isPresent()) { url = oUrl.get(); } else { @@ -261,7 +261,7 @@ public String toString(){ String isValid; try { - Optional oIsValid = getBooleanPropertyValue(SpdxConstants.PROP_CROSS_REF_IS_VALID); + Optional oIsValid = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID); if (oIsValid.isPresent()) { isValid = oIsValid.get().toString(); } else { @@ -272,7 +272,7 @@ public String toString(){ } String isLive; try { - Optional oIsLive = getBooleanPropertyValue(SpdxConstants.PROP_CROSS_REF_IS_LIVE); + Optional oIsLive = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE); if (oIsLive.isPresent()) { isLive = oIsLive.get().toString(); @@ -284,7 +284,7 @@ public String toString(){ } String isWayBackLink; try { - Optional oWayback = getBooleanPropertyValue(SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK); + Optional oWayback = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK); if (oWayback.isPresent()) { isWayBackLink = oWayback.get().toString(); } else { @@ -295,7 +295,7 @@ public String toString(){ } String match; try { - Optional oMatch = getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_MATCH); + Optional oMatch = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH); if (oMatch.isPresent()) { match = oMatch.get(); @@ -307,7 +307,7 @@ public String toString(){ } String timestamp; try { - Optional oTimestamp = getStringPropertyValue(SpdxConstants.PROP_CROSS_REF_TIMESTAMP); + Optional oTimestamp = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP); if (oTimestamp.isPresent()) { timestamp = oTimestamp.get(); } else { @@ -317,12 +317,12 @@ public String toString(){ timestamp = "N/A"; } String crossRefDetails = String.format("{%s: %s,%s: %s,%s: %s,%s: %s,%s: %s,%s: %s}", - SpdxConstants.PROP_CROSS_REF_URL, url, - SpdxConstants.PROP_CROSS_REF_IS_VALID, isValid, - SpdxConstants.PROP_CROSS_REF_IS_LIVE, isLive, - SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK, isWayBackLink, - SpdxConstants.PROP_CROSS_REF_MATCH, match, - SpdxConstants.PROP_CROSS_REF_TIMESTAMP, timestamp); + SpdxConstantsCompatV2.PROP_CROSS_REF_URL, url, + SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID, isValid, + SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE, isLive, + SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK, isWayBackLink, + SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH, match, + SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP, timestamp); return crossRefDetails; } diff --git a/src/main/java/org/spdx/library/model/license/DisjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java similarity index 95% rename from src/main/java/org/spdx/library/model/license/DisjunctiveLicenseSet.java rename to src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java index 63e5277d0..a4cd25f22 100644 --- a/src/main/java/org/spdx/library/model/license/DisjunctiveLicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.HashSet; @@ -25,9 +25,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -205,6 +205,6 @@ private boolean setsEquivalent(DisjunctiveLicenseSet compare) throws InvalidSPDX @Override public String getType() { - return SpdxConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET; + return SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET; } } diff --git a/src/main/java/org/spdx/library/model/license/ExternalExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java similarity index 81% rename from src/main/java/org/spdx/library/model/license/ExternalExtractedLicenseInfo.java rename to src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java index 4fccef3a9..49529150e 100644 --- a/src/main/java/org/spdx/library/model/license/ExternalExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.Collection; @@ -30,12 +30,12 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -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.ModelObject; -import org.spdx.library.model.SimpleUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SimpleUriValue; import org.spdx.storage.IModelStore; /** @@ -51,7 +51,7 @@ * The getExtractedText() will return text that indicates the actual license text * is in an external document. * - * The ID must be in the form SpdxConstants.EXTERNAL_LICENSE_REF_PATTERN.pattern() + * The ID must be in the form SpdxConstantsCompatV2.EXTERNAL_LICENSE_REF_PATTERN.pattern() * */ public class ExternalExtractedLicenseInfo extends AbstractExtractedLicenseInfo implements IndividualUriValue { @@ -75,7 +75,7 @@ public ExternalExtractedLicenseInfo(IModelStore modelStore, String documentUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - if (!SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id).matches()) { + if (!SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id).matches()) { throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } getExternalExtractedLicenseURI(); //this will check to make sure the external document reference is available @@ -86,7 +86,7 @@ public ExternalExtractedLicenseInfo(IModelStore modelStore, String documentUri, * @throws InvalidSPDXAnalysisException */ public String getExternalDocumentId() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); if (!matcher.matches()) { throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } @@ -98,7 +98,7 @@ public String getExternalDocumentId() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public String getExternalLicenseRef() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); if (!matcher.matches()) { throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } @@ -106,24 +106,24 @@ public String getExternalLicenseRef() throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_EXTERNAL_EXTRACTED_LICENSE; + return SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE; } /* (non-Javadoc) - * @see org.spdx.library.model.SpdxElement#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { // we don't want to call super.verify since we really don't require those fields List retval = new ArrayList<>(); String id = this.getId(); - Matcher matcher = SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id); if (!matcher.matches()) { - retval.add("Invalid id format for an external document reference. Must be of the form "+SpdxConstants.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); + retval.add("Invalid id format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); } else { try { ExternalSpdxElement.externalDocumentIdToNamespace(matcher.group(1), getModelStore(), getDocumentUri(), getCopyManager()); @@ -152,7 +152,7 @@ public String getExternalExtractedLicenseURI() throws InvalidSPDXAnalysisExcepti */ public static String externalExtractedLicenseIdToURI(String externalExtractedLicenseId, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(externalExtractedLicenseId); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(externalExtractedLicenseId); if (!matcher.matches()) { logger.error("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); @@ -195,7 +195,7 @@ public static ExternalExtractedLicenseInfo uriToExternalExtractedLicense(String public static String uriToExternalExtractedLicenseId(String uri, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(uri, "URI can not be null"); - Matcher matcher = SpdxConstants.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri); + Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri); if (!matcher.matches()) { throw new InvalidSPDXAnalysisException("Invalid URI format: "+uri+". Expects namespace#LicenseRef-XXXX"); } @@ -209,7 +209,7 @@ public static String uriToExternalExtractedLicenseId(String uri, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#equivalent(org.spdx.library.model.ModelObject) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject) */ @Override public boolean equivalent(ModelObject compare) { @@ -220,7 +220,7 @@ public boolean equivalent(ModelObject compare) { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#equivalent(org.spdx.library.model.ModelObject, boolean) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject, boolean) */ @Override public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { @@ -229,7 +229,7 @@ public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) th /* (non-Javadoc) - * @see org.spdx.library.model.IndividualUriValue#getIndividualURI() + * @see org.spdx.library.model.compat.v2.compat.v2.IndividualUriValue#getIndividualURI() */ @Override public String getIndividualURI() { @@ -242,7 +242,7 @@ public String getIndividualURI() { } /* (non-Javadoc) - * @see org.spdx.library.model.license.AbstractExtractedLicenseInfo#getExtractedText() + * @see org.spdx.library.model.compat.v2.compat.v2.license.AbstractExtractedLicenseInfo#getExtractedText() */ @Override public String getExtractedText() throws InvalidSPDXAnalysisException { @@ -254,7 +254,7 @@ public String getExtractedText() throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.license.SimpleLicensingInfo#getComment() + * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getComment() */ @Override public String getComment() throws InvalidSPDXAnalysisException { @@ -272,7 +272,7 @@ public void setComment(String comment) throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.license.SimpleLicensingInfo#getSeeAlso() + * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getSeeAlso() */ @Override public Collection getSeeAlso() throws InvalidSPDXAnalysisException { @@ -280,7 +280,7 @@ public Collection getSeeAlso() throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.license.SimpleLicensingInfo#setSeeAlso(java.util.Collection) + * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#setSeeAlso(java.util.Collection) */ @Override public void setSeeAlso(Collection seeAlsoUrl) throws InvalidSPDXAnalysisException { @@ -289,7 +289,7 @@ public void setSeeAlso(Collection seeAlsoUrl) throws InvalidSPDXAnalysis } /* (non-Javadoc) - * @see org.spdx.library.model.license.SimpleLicensingInfo#getName() + * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getName() */ @Override public String getName() throws InvalidSPDXAnalysisException { @@ -297,7 +297,7 @@ public String getName() throws InvalidSPDXAnalysisException { } /* (non-Javadoc) - * @see org.spdx.library.model.license.SimpleLicensingInfo#setName(java.lang.String) + * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#setName(java.lang.String) */ @Override public void setName(String name) throws InvalidSPDXAnalysisException { diff --git a/src/main/java/org/spdx/library/model/license/ExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java similarity index 90% rename from src/main/java/org/spdx/library/model/license/ExtractedLicenseInfo.java rename to src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java index c28b19822..2033b76a3 100644 --- a/src/main/java/org/spdx/library/model/license/ExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java @@ -16,7 +16,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; @@ -28,10 +28,10 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.utility.compare.LicenseCompareHelper; @@ -80,11 +80,11 @@ public ExtractedLicenseInfo(String id, String text) throws InvalidSPDXAnalysisEx } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO; + return SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO; } /** @@ -92,7 +92,7 @@ public String getType() { * @throws SpdxInvalidTypeException */ public String getExtractedText() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_EXTRACTED_TEXT); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXTRACTED_TEXT); if (o.isPresent()) { return o.get(); } else { @@ -105,7 +105,7 @@ public String getExtractedText() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setExtractedText(String text) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_EXTRACTED_TEXT, text); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXTRACTED_TEXT, text); } /** diff --git a/src/main/java/org/spdx/library/model/license/InvalidLicenseStringException.java b/src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java similarity index 88% rename from src/main/java/org/spdx/library/model/license/InvalidLicenseStringException.java rename to src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java index 7cfcaab72..ec24787ee 100644 --- a/src/main/java/org/spdx/library/model/license/InvalidLicenseStringException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java @@ -1,4 +1,4 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/license/License.java b/src/main/java/org/spdx/library/model/compat/v2/license/License.java similarity index 87% rename from src/main/java/org/spdx/library/model/license/License.java rename to src/main/java/org/spdx/library/model/compat/v2/license/License.java index b71bfb6a5..373de4f08 100644 --- a/src/main/java/org/spdx/library/model/license/License.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/License.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; @@ -26,9 +26,9 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.ModelUpdate; @@ -83,7 +83,7 @@ public License(String id) throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public String getLicenseText() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_LICENSE_TEXT); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT); if (o.isPresent()) { return o.get(); } else { @@ -96,7 +96,7 @@ public String getLicenseText() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setLicenseText(String text) throws InvalidSPDXAnalysisException { - this.setPropertyValue(SpdxConstants.PROP_LICENSE_TEXT, text); + this.setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT, text); } /** @@ -104,7 +104,7 @@ public void setLicenseText(String text) throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public String getStandardLicenseHeader() throws InvalidSPDXAnalysisException { - Optional standardLicenseHeader = getStringPropertyValue(SpdxConstants.PROP_STD_LICENSE_NOTICE); + Optional standardLicenseHeader = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE); if (standardLicenseHeader.isPresent()) { return StringEscapeUtils.unescapeHtml4(standardLicenseHeader.get()); } else { @@ -117,7 +117,7 @@ public String getStandardLicenseHeader() throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public String getStandardLicenseHeaderTemplate() throws InvalidSPDXAnalysisException { - Optional standardLicenseHeaderTemplate = getStringPropertyValue(SpdxConstants.PROP_STD_LICENSE_HEADER_TEMPLATE); + Optional standardLicenseHeaderTemplate = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE); if (standardLicenseHeaderTemplate.isPresent()) { return StringEscapeUtils.unescapeHtml4(standardLicenseHeaderTemplate.get()); } else { @@ -130,7 +130,7 @@ public String getStandardLicenseHeaderTemplate() throws InvalidSPDXAnalysisExcep * @throws InvalidSPDXAnalysisException */ public void setStandardLicenseHeaderTemplate(String standardLicenseHeaderTemplate) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_HEADER_TEMPLATE, standardLicenseHeaderTemplate); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE, standardLicenseHeaderTemplate); } /** @@ -138,14 +138,14 @@ public void setStandardLicenseHeaderTemplate(String standardLicenseHeaderTemplat * @throws InvalidSPDXAnalysisException */ public void setStandardLicenseHeader(String standardLicenseHeader) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_NOTICE, standardLicenseHeader); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE, standardLicenseHeader); } /** * @return the template * @throws SpdxInvalidTypeException */ public String getStandardLicenseTemplate() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_STD_LICENSE_TEMPLATE); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE); if (!o.isPresent()) { return ""; } @@ -163,7 +163,7 @@ public String getStandardLicenseTemplate() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setStandardLicenseTemplate(String template) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_TEMPLATE, template); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE, template); } @Override @@ -178,7 +178,7 @@ public String toString() { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -241,7 +241,7 @@ protected List _verify(Set verifiedIds, String specVersion) { * @throws InvalidSPDXAnalysisException */ public boolean isFsfLibre() throws InvalidSPDXAnalysisException { - Optional libre = getBooleanPropertyValue(SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE); + Optional libre = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); if (!libre.isPresent()) { return false; } @@ -253,7 +253,7 @@ public boolean isFsfLibre() throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public boolean isNotFsfLibre() throws InvalidSPDXAnalysisException { - Optional fsfLibre = getBooleanPropertyValue(SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE); + Optional fsfLibre = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); return fsfLibre.isPresent() && !fsfLibre.get(); } @@ -262,7 +262,7 @@ public boolean isNotFsfLibre() throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public Boolean getFsfLibre() throws InvalidSPDXAnalysisException { - Optional libre = getBooleanPropertyValue(SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE); + Optional libre = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); if (libre.isPresent()) { return libre.get(); } else { @@ -276,7 +276,7 @@ public Boolean getFsfLibre() throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public boolean isOsiApproved() throws InvalidSPDXAnalysisException { - Optional osiApproved = getBooleanPropertyValue(SpdxConstants.PROP_STD_LICENSE_OSI_APPROVED); + Optional osiApproved = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED); return osiApproved.isPresent() && osiApproved.get(); } @@ -285,12 +285,12 @@ public boolean isOsiApproved() throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public boolean isDeprecated() throws InvalidSPDXAnalysisException { - Optional deprecated = getBooleanPropertyValue(SpdxConstants.PROP_LIC_ID_DEPRECATED); + Optional deprecated = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED); return deprecated.isPresent() && deprecated.get(); } public void setOsiApproved(Boolean osiApproved) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_OSI_APPROVED, osiApproved); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED, osiApproved); } /** @@ -298,7 +298,7 @@ public void setOsiApproved(Boolean osiApproved) throws InvalidSPDXAnalysisExcept * @throws InvalidSPDXAnalysisException */ public void setFsfLibre(Boolean fsfLibre) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE, fsfLibre); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE, fsfLibre); } /** @@ -306,7 +306,7 @@ public void setFsfLibre(Boolean fsfLibre) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LIC_ID_DEPRECATED, deprecated); + setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, deprecated); } /** @@ -315,7 +315,7 @@ public void setDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisExceptio * @throws InvalidSPDXAnalysisException */ public ModelUpdate updateSetDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisException { - return updatePropertyValue(SpdxConstants.PROP_LIC_ID_DEPRECATED, deprecated); + return updatePropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, deprecated); } @Override diff --git a/src/main/java/org/spdx/library/model/license/LicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java similarity index 78% rename from src/main/java/org/spdx/library/model/license/LicenseException.java rename to src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java index 4de344b1f..ceaa76bfd 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.Collection; @@ -27,10 +27,10 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -57,7 +57,7 @@ public LicenseException(IModelStore modelStore, String documentUri, String id, throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstants.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec } } @@ -79,7 +79,7 @@ public LicenseException(String id, String name, String text) throws InvalidSPDXA setName(name); setLicenseExceptionText(text); if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstants.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec } } @@ -88,7 +88,7 @@ public LicenseException(String id, String name, String text) throws InvalidSPDXA * @throws InvalidSPDXAnalysisException */ public String getComment() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); if (o.isPresent()) { return o.get(); } else { @@ -101,7 +101,7 @@ public String getComment() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); } /** @@ -111,7 +111,7 @@ public void setComment(String comment) throws InvalidSPDXAnalysisException { */ @Deprecated public String getExample() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_EXAMPLE); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXAMPLE); if (o.isPresent()) { return o.get(); } else { @@ -126,7 +126,7 @@ public String getExample() throws InvalidSPDXAnalysisException { */ @Deprecated public void setExample(String example) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_EXAMPLE, example); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXAMPLE, example); } /** @@ -141,7 +141,7 @@ public String getLicenseExceptionId() { * @throws InvalidSPDXAnalysisException */ public String getLicenseExceptionTemplate() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_EXCEPTION_TEMPLATE); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE); if (o.isPresent()) { return o.get(); } else { @@ -155,7 +155,7 @@ public String getLicenseExceptionTemplate() throws InvalidSPDXAnalysisException * @throws InvalidSPDXAnalysisException */ public void setLicenseExceptionTemplate(String template) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_EXCEPTION_TEMPLATE, template); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE, template); } /** @@ -163,7 +163,7 @@ public void setLicenseExceptionTemplate(String template) throws InvalidSPDXAnaly * @throws InvalidSPDXAnalysisException */ public String getLicenseExceptionText() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_EXCEPTION_TEXT); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT); if (o.isPresent()) { return o.get(); } else { @@ -177,7 +177,7 @@ public String getLicenseExceptionText() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setLicenseExceptionText(String text) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_EXCEPTION_TEXT, text); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, text); } @@ -186,7 +186,7 @@ public void setLicenseExceptionText(String text) throws InvalidSPDXAnalysisExcep * @throws SpdxInvalidTypeException */ public String getName() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_STD_LICENSE_NAME); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME); if (o.isPresent()) { return o.get(); } else { @@ -199,7 +199,7 @@ public String getName() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setName(String name) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_NAME, name); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME, name); } /** @@ -207,7 +207,7 @@ public void setName(String name) throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public Collection getSeeAlso() throws InvalidSPDXAnalysisException { - return getStringCollection(SpdxConstants.RDFS_PROP_SEE_ALSO); + return getStringCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); } /** * @param seeAlso the urls which are references to the same license to set @@ -215,9 +215,9 @@ public Collection getSeeAlso() throws InvalidSPDXAnalysisException { */ public void setSeeAlso(Collection seeAlso) throws InvalidSPDXAnalysisException { if (seeAlso == null) { - clearValueCollection(SpdxConstants.RDFS_PROP_SEE_ALSO); + clearValueCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); } else { - setPropertyValue(SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso); } } @@ -226,7 +226,7 @@ public void setSeeAlso(Collection seeAlso) throws InvalidSPDXAnalysisExc * @throws SpdxInvalidTypeException */ public boolean isDeprecated() throws InvalidSPDXAnalysisException { - Optional deprecated = getBooleanPropertyValue(SpdxConstants.PROP_LIC_ID_DEPRECATED); + Optional deprecated = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED); return deprecated.isPresent() && deprecated.get(); } @@ -235,7 +235,7 @@ public boolean isDeprecated() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LIC_ID_DEPRECATED, deprecated); + setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, deprecated); } /** @@ -243,7 +243,7 @@ public void setDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisExceptio * @throws SpdxInvalidTypeException */ public String getDeprecatedVersion() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_LIC_DEPRECATED_VERSION); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION); if (o.isPresent()) { return o.get(); } else { @@ -256,19 +256,19 @@ public String getDeprecatedVersion() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setDeprecatedVersion(String deprecatedVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LIC_DEPRECATED_VERSION, deprecatedVersion); + setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, deprecatedVersion); } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION; + return SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java similarity index 94% rename from src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java rename to src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java index 79cc6a3c0..7b77459e3 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.Arrays; @@ -29,10 +29,10 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelStorageClassConverter; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.TypedValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelStorageClassConverter; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -82,9 +82,9 @@ static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore stor Objects.requireNonNull(store, "Model store can not be null"); Objects.requireNonNull(documentUri, "Document URI can not be null"); String[] tokens = tokenizeExpression(expression); - if (tokens.length == 1 && tokens[0].equals(SpdxConstants.NOASSERTION_VALUE)) { + if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) { return new SpdxNoAssertionLicense(); - } else if (tokens.length == 1 && tokens[0].equals(SpdxConstants.NONE_VALUE)) { + } else if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NONE_VALUE)) { return new SpdxNoneLicense(); } else { try { @@ -184,11 +184,11 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor } if (exceptionId.isPresent()) { licenseException = LicenseInfoFactory.getListedExceptionById(exceptionId.get()); - } else if (token.startsWith(SpdxConstants.NON_STD_LICENSE_ID_PRENUM)) { + } else if (token.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { throw new LicenseParserException("WITH must be followed by a license exception. "+token+" is a Listed License type."); } else { licenseException = (ListedLicenseException) SpdxModelFactory.createModelObject(store, - documentUri, token, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, copyManager); + documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, copyManager); } AnyLicenseInfo operand = operandStack.pop(); if (operand == null) { @@ -278,11 +278,11 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore if (Objects.nonNull(copyManager)) { // copy to the local store copyManager.copy(store, documentUri, token, listedLicense.getModelStore(), - listedLicense.getDocumentUri(), token, SpdxConstants.CLASS_SPDX_LISTED_LICENSE); + listedLicense.getDocumentUri(), token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); } } return (AnyLicenseInfo) ModelStorageClassConverter.storedObjectToModelObject( - new TypedValue(licenseId.get(), SpdxConstants.CLASS_SPDX_LISTED_LICENSE), + new TypedValue(licenseId.get(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE), documentUri, store, copyManager); } else { // LicenseRef @@ -293,7 +293,7 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore } else { localLicense = (ExtractedLicenseInfo) SpdxModelFactory.createModelObject( - store, documentUri, token, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); + store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); localLicense.setExtractedText(UNINITIALIZED_LICENSE_TEXT); } return localLicense; diff --git a/src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java similarity index 99% rename from src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java rename to src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java index 4a2d5b547..16001d68b 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.List; import java.util.Objects; diff --git a/src/main/java/org/spdx/library/model/license/LicenseParserException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java similarity index 88% rename from src/main/java/org/spdx/library/model/license/LicenseParserException.java rename to src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java index ea15395d4..e827b0c76 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseParserException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java @@ -1,4 +1,4 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/license/LicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java similarity index 92% rename from src/main/java/org/spdx/library/model/license/LicenseSet.java rename to src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java index 645e47e38..7585ea3e8 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java @@ -14,13 +14,13 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -75,7 +75,7 @@ public LicenseSet(String id) throws InvalidSPDXAnalysisException { @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - members = (Collection)(Collection)getObjectPropertyValueSet(SpdxConstants.PROP_LICENSE_SET_MEMEBER, AnyLicenseInfo.class); + members = (Collection)(Collection)getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, AnyLicenseInfo.class); } /** @@ -84,7 +84,7 @@ public LicenseSet(String id) throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setMembers(Collection licenseInfos) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER, licenseInfos); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, licenseInfos); } /** diff --git a/src/main/java/org/spdx/library/model/license/ListedLicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java similarity index 90% rename from src/main/java/org/spdx/library/model/license/ListedLicenseException.java rename to src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java index 7ec03dfdb..4b5d085cd 100644 --- a/src/main/java/org/spdx/library/model/license/ListedLicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java @@ -15,15 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.Collection; import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.licenseTemplate.LicenseTemplateRuleException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; import org.spdx.storage.IModelStore; @@ -88,7 +88,7 @@ public ListedLicenseException(String id, String name, String text) throws Invali @Override public String getType() { - return SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION; + return SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION; } /** @@ -96,7 +96,7 @@ public String getType() { * @throws InvalidSPDXAnalysisException */ public void setExceptionTextHtml(String exceptionTextHtml) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_EXCEPTION_TEXT_HTML, exceptionTextHtml); + setPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML, exceptionTextHtml); } /** @@ -104,11 +104,11 @@ public void setExceptionTextHtml(String exceptionTextHtml) throws InvalidSPDXAna * @throws InvalidSPDXAnalysisException */ public String getExceptionTextHtml() throws InvalidSPDXAnalysisException { - Optional exceptionTextHtml = getStringPropertyValue(SpdxConstants.PROP_EXCEPTION_TEXT_HTML); + Optional exceptionTextHtml = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML); if (exceptionTextHtml.isPresent()) { return exceptionTextHtml.get(); } else { - Optional templateText = getStringPropertyValue(SpdxConstants.PROP_EXCEPTION_TEMPLATE); + Optional templateText = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE); if (templateText.isPresent()) { try { return SpdxLicenseTemplateHelper.templateTextToHtml(templateText.get()); @@ -116,7 +116,7 @@ public String getExceptionTextHtml() throws InvalidSPDXAnalysisException { throw new InvalidSPDXAnalysisException("Invalid license rule found in exception text for exception "+getName()+":"+ex.getMessage()); } } else { - Optional exceptionText = getStringPropertyValue(SpdxConstants.PROP_EXCEPTION_TEXT); + Optional exceptionText = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT); if (exceptionText.isPresent()) { return SpdxLicenseTemplateHelper.formatEscapeHTML(exceptionText.get()); } else { diff --git a/src/main/java/org/spdx/library/model/license/ListedLicenses.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java similarity index 94% rename from src/main/java/org/spdx/library/model/license/ListedLicenses.java rename to src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java index 79f9caecd..e9fbc8b8e 100644 --- a/src/main/java/org/spdx/library/model/license/ListedLicenses.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.io.IOException; import java.io.InputStream; @@ -29,8 +29,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.listedlicense.IListedLicenseStore; import org.spdx.storage.listedlicense.SpdxListedLicenseLocalStore; @@ -172,7 +172,7 @@ public static ListedLicenses resetListedLicenses() { * @return true if the licenseId belongs to an SPDX listed license */ public boolean isSpdxListedLicenseId(String licenseId) { - return this.licenseModelStore.isSpdxListedLicenseId(SpdxConstants.LISTED_LICENSE_URL, licenseId); + return this.licenseModelStore.isSpdxListedLicenseId(SpdxConstantsCompatV2.LISTED_LICENSE_URL, licenseId); } /** @@ -180,7 +180,7 @@ public boolean isSpdxListedLicenseId(String licenseId) { * @return true if the exceptionId belongs to an SPDX listed exception */ public boolean isSpdxListedExceptionId(String exceptionId) { - return this.licenseModelStore.isSpdxListedExceptionId(SpdxConstants.LISTED_LICENSE_URL, exceptionId); + return this.licenseModelStore.isSpdxListedExceptionId(SpdxConstantsCompatV2.LISTED_LICENSE_URL, exceptionId); } /** @@ -189,11 +189,11 @@ public boolean isSpdxListedExceptionId(String exceptionId) { * @throws InvalidSPDXAnalysisException */ public SpdxListedLicense getListedLicenseById(String licenseId) throws InvalidSPDXAnalysisException { - return (SpdxListedLicense)SpdxModelFactory.createModelObject(this.licenseModelStore, SpdxConstants.LISTED_LICENSE_URL, licenseId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE, null); + return (SpdxListedLicense)SpdxModelFactory.createModelObject(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); } public ListedLicenseException getListedExceptionById(String exceptionId) throws InvalidSPDXAnalysisException { - return (ListedLicenseException)SpdxModelFactory.createModelObject(this.licenseModelStore, SpdxConstants.LISTED_LICENSE_URL, exceptionId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + return (ListedLicenseException)SpdxModelFactory.createModelObject(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); } /** diff --git a/src/main/java/org/spdx/library/model/license/OrLaterOperator.java b/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java similarity index 92% rename from src/main/java/org/spdx/library/model/license/OrLaterOperator.java rename to src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java index 2cc7da0fc..73a548cd4 100644 --- a/src/main/java/org/spdx/library/model/license/OrLaterOperator.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; @@ -26,8 +26,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -70,7 +70,7 @@ public OrLaterOperator(SimpleLicensingInfo license) throws InvalidSPDXAnalysisEx * @throws SpdxInvalidTypeException */ public SimpleLicensingInfo getLicense() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER); + Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); if (!retval.isPresent()) { throw new SpdxInvalidTypeException("Missing required license for OrLater operator"); } @@ -85,7 +85,7 @@ public SimpleLicensingInfo getLicense() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setLicense(SimpleLicensingInfo license) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER, license); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, license); } /* (non-Javadoc) @@ -124,7 +124,7 @@ protected List _verify(Set verifiedIds, String specVersion) { @Override public String getType() { - return SpdxConstants.CLASS_OR_LATER_OPERATOR; + return SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR; } @Override diff --git a/src/main/java/org/spdx/library/model/license/SimpleLicensingInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java similarity index 78% rename from src/main/java/org/spdx/library/model/license/SimpleLicensingInfo.java rename to src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java index 25a42aee5..f2f452232 100644 --- a/src/main/java/org/spdx/library/model/license/SimpleLicensingInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java @@ -16,7 +16,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.Collection; import java.util.Optional; @@ -25,9 +25,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; @@ -48,7 +48,7 @@ public abstract class SimpleLicensingInfo extends AnyLicenseInfo { SimpleLicensingInfo(String id) throws InvalidSPDXAnalysisException { super(id); if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstants.PROP_LICENSE_ID, id); // Needs to be set as a property per spec + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_ID, id); // Needs to be set as a property per spec } } @@ -66,7 +66,7 @@ public abstract class SimpleLicensingInfo extends AnyLicenseInfo { throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstants.PROP_LICENSE_ID, id); // Needs to be set as a property per spec + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_ID, id); // Needs to be set as a property per spec } } @@ -82,7 +82,7 @@ public String getLicenseId() { * @throws SpdxInvalidTypeException */ public String getName() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.PROP_STD_LICENSE_NAME); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME); if (o.isPresent()) { return o.get(); } else { @@ -95,7 +95,7 @@ public String getName() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setName(String name) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_STD_LICENSE_NAME, name); + setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME, name); } /** @@ -103,7 +103,7 @@ public void setName(String name) throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public String getComment() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstants.RDFS_PROP_COMMENT); + Optional o = getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); if (o.isPresent()) { return o.get(); } else { @@ -116,7 +116,7 @@ public String getComment() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, comment); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); } /** @@ -124,7 +124,7 @@ public void setComment(String comment) throws InvalidSPDXAnalysisException { * @throws SpdxInvalidTypeException */ public Collection getSeeAlso() throws InvalidSPDXAnalysisException { - return getStringCollection(SpdxConstants.RDFS_PROP_SEE_ALSO); + return getStringCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); } /** * @param seeAlsoUrl the urls which are references to the same license to set @@ -132,9 +132,9 @@ public Collection getSeeAlso() throws InvalidSPDXAnalysisException { */ public void setSeeAlso(Collection seeAlsoUrl) throws InvalidSPDXAnalysisException { if (seeAlsoUrl == null) { - clearValueCollection(SpdxConstants.RDFS_PROP_SEE_ALSO); + clearValueCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); } else { - setPropertyValue(SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlsoUrl); + setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlsoUrl); } } } diff --git a/src/main/java/org/spdx/library/model/license/SpdxListedLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java similarity index 93% rename from src/main/java/org/spdx/library/model/license/SpdxListedLicense.java rename to src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java index 1ac7893cc..df2382198 100644 --- a/src/main/java/org/spdx/library/model/license/SpdxListedLicense.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.Collection; @@ -27,9 +27,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.licenseTemplate.LicenseTemplateRuleException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; @@ -52,7 +52,7 @@ public class SpdxListedLicense extends License { @SuppressWarnings("unchecked") public SpdxListedLicense(String id) throws InvalidSPDXAnalysisException { super(id); - crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_CROSS_REF, CrossRef.class); + crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); } /** @@ -69,7 +69,7 @@ public SpdxListedLicense(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_CROSS_REF, CrossRef.class); + crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); } /** @@ -103,7 +103,7 @@ public SpdxListedLicense(String name, String id, String text, Collection setLicenseTextHtml(licenseTextHtml); setDeprecated(isDeprecated); setDeprecatedVersion(deprecatedVersion); - crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstants.PROP_CROSS_REF, CrossRef.class); + crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); } /** @@ -136,7 +136,7 @@ protected List _verify(Set verifiedIds, String specVersion) { * @throws SpdxInvalidTypeException */ public String getLicenseTextHtml() throws InvalidLicenseTemplateException, InvalidSPDXAnalysisException { - Optional licenseTextHtml = getStringPropertyValue(SpdxConstants.PROP_LICENSE_TEXT_HTML); + Optional licenseTextHtml = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML); if (licenseTextHtml.isPresent()) { return licenseTextHtml.get(); } else { @@ -160,7 +160,7 @@ public String getLicenseTextHtml() throws InvalidLicenseTemplateException, Inval * @throws InvalidSPDXAnalysisException */ public void setLicenseTextHtml(String licenseTextHtml) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_TEXT_HTML, licenseTextHtml); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML, licenseTextHtml); } /** @@ -169,7 +169,7 @@ public void setLicenseTextHtml(String licenseTextHtml) throws InvalidSPDXAnalysi * @throws SpdxInvalidTypeException */ public String getLicenseHeaderHtml() throws InvalidLicenseTemplateException, InvalidSPDXAnalysisException { - Optional licenseHeaderHtml = getStringPropertyValue(SpdxConstants.PROP_LICENSE_HEADER_HTML); + Optional licenseHeaderHtml = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML); if (licenseHeaderHtml.isPresent()) { return licenseHeaderHtml.get(); } else { @@ -193,7 +193,7 @@ public String getLicenseHeaderHtml() throws InvalidLicenseTemplateException, Inv * @throws InvalidSPDXAnalysisException */ public void setLicenseHeaderHtml(String licenseHeaderHtml) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_HEADER_HTML, licenseHeaderHtml); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML, licenseHeaderHtml); } /** @@ -201,7 +201,7 @@ public void setLicenseHeaderHtml(String licenseHeaderHtml) throws InvalidSPDXAna * @throws SpdxInvalidTypeException */ public String getDeprecatedVersion() throws InvalidSPDXAnalysisException { - Optional depVersion = getStringPropertyValue(SpdxConstants.PROP_LIC_DEPRECATED_VERSION); + Optional depVersion = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION); if (depVersion.isPresent()) { return depVersion.get(); } else { @@ -214,7 +214,7 @@ public String getDeprecatedVersion() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setDeprecatedVersion(String deprecatedVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LIC_DEPRECATED_VERSION, deprecatedVersion); + setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, deprecatedVersion); } public Collection getCrossRef() throws InvalidSPDXAnalysisException { @@ -223,7 +223,7 @@ public Collection getCrossRef() throws InvalidSPDXAnalysisException { @Override public String getType() { - return SpdxConstants.CLASS_SPDX_LISTED_LICENSE; + return SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE; } @Override diff --git a/src/main/java/org/spdx/library/model/license/SpdxListedLicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java similarity index 96% rename from src/main/java/org/spdx/library/model/license/SpdxListedLicenseException.java rename to src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java index e34ce213a..b7d1a42ee 100644 --- a/src/main/java/org/spdx/library/model/license/SpdxListedLicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/library/model/license/SpdxNoAssertionLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java similarity index 85% rename from src/main/java/org/spdx/library/model/license/SpdxNoAssertionLicense.java rename to src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java index 202ce69af..58a007410 100644 --- a/src/main/java/org/spdx/library/model/license/SpdxNoAssertionLicense.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java @@ -14,16 +14,16 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; -import org.spdx.library.model.SimpleUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.SimpleUriValue; import org.spdx.storage.IModelStore; /** @@ -53,7 +53,7 @@ public SpdxNoAssertionLicense(IModelStore modelStore, String documentUri) */ @Override public String toString() { - return SpdxConstants.NOASSERTION_VALUE; + return SpdxConstantsCompatV2.NOASSERTION_VALUE; } @Override @@ -76,11 +76,11 @@ protected List _verify(Set verifiedIds, String specVersion) { @Override public String getType() { - return SpdxConstants.CLASS_NOASSERTION_LICENSE; + return SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE; } @Override public String getIndividualURI() { - return SpdxConstants.URI_VALUE_NOASSERTION; + return SpdxConstantsCompatV2.URI_VALUE_NOASSERTION; } } diff --git a/src/main/java/org/spdx/library/model/license/SpdxNoneLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java similarity index 85% rename from src/main/java/org/spdx/library/model/license/SpdxNoneLicense.java rename to src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java index c96d8051d..5639fd9d5 100644 --- a/src/main/java/org/spdx/library/model/license/SpdxNoneLicense.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java @@ -14,16 +14,16 @@ * limitations under the License. * */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.IndividualUriValue; -import org.spdx.library.model.SimpleUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.SimpleUriValue; import org.spdx.storage.IModelStore; /** @@ -53,7 +53,7 @@ public SpdxNoneLicense(IModelStore modelStore, String documentUri) */ @Override public String toString() { - return SpdxConstants.NONE_VALUE; + return SpdxConstantsCompatV2.NONE_VALUE; } @Override @@ -76,11 +76,11 @@ protected List _verify(Set verifiedIds, String specVersion) { @Override public String getType() { - return SpdxConstants.CLASS_NONE_LICENSE; + return SpdxConstantsCompatV2.CLASS_NONE_LICENSE; } @Override public String getIndividualURI() { - return SpdxConstants.URI_VALUE_NONE; + return SpdxConstantsCompatV2.URI_VALUE_NONE; } } diff --git a/src/main/java/org/spdx/library/model/license/WithExceptionOperator.java b/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java similarity index 87% rename from src/main/java/org/spdx/library/model/license/WithExceptionOperator.java rename to src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java index b4f5f4a83..f5e2ae6e9 100644 --- a/src/main/java/org/spdx/library/model/license/WithExceptionOperator.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.List; @@ -27,8 +27,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -73,11 +73,11 @@ public WithExceptionOperator(AnyLicenseInfo license, LicenseException exception) } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_WITH_EXCEPTION_OPERATOR; + return SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR; } /** @@ -85,7 +85,7 @@ public String getType() { * @throws InvalidSPDXAnalysisException */ public AnyLicenseInfo getLicense() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER); + Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); if (!retval.isPresent()) { throw new InvalidSPDXAnalysisException("Required license for exception is missing"); } @@ -97,14 +97,14 @@ public AnyLicenseInfo getLicense() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setLicense(AnyLicenseInfo license) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER, license); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, license); } /** * @return the exception */ public LicenseException getException() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_LICENSE_EXCEPTION); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION); if (!retval.isPresent()) { throw new InvalidSPDXAnalysisException("Required exception is missing for with exception operator"); } @@ -119,7 +119,7 @@ public LicenseException getException() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public void setException(LicenseException exception) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.PROP_LICENSE_EXCEPTION, exception); + setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION, exception); } /* (non-Javadoc) @@ -128,8 +128,8 @@ public void setException(LicenseException exception) throws InvalidSPDXAnalysisE @Override public String toString() { try { - Optional license = getObjectPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER); - Optional exception = getObjectPropertyValue(SpdxConstants.PROP_LICENSE_EXCEPTION); + Optional license = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); + Optional exception = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION); if (!license.isPresent() || !exception.isPresent()) { return "UNDEFINED WITH EXCEPTION"; } @@ -140,13 +140,13 @@ public String toString() { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { List retval = new ArrayList<>(); try { - Optional license = getObjectPropertyValue(SpdxConstants.PROP_LICENSE_SET_MEMEBER); + Optional license = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); if (license.isPresent()) { if (license.get() instanceof AnyLicenseInfo) { retval.addAll(((AnyLicenseInfo)(license.get())).verify(verifiedIds, specVersion)); @@ -160,7 +160,7 @@ protected List _verify(Set verifiedIds, String specVersion) { retval.add("Error getting license property of a With operator: "+e.getMessage()); } try { - Optional exception = getObjectPropertyValue(SpdxConstants.PROP_LICENSE_EXCEPTION); + Optional exception = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION); if (exception.isPresent()) { if (exception.get() instanceof LicenseException) { retval.addAll(((LicenseException)(exception.get())).verify(verifiedIds, specVersion)); @@ -177,7 +177,7 @@ protected List _verify(Set verifiedIds, String specVersion) { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#equals(java.lang.Object) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#equals(java.lang.Object) */ @Override public boolean equals(Object o) { @@ -219,7 +219,7 @@ public boolean equals(Object o) { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#hashCode() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#hashCode() */ @Override public int hashCode() { diff --git a/src/main/java/org/spdx/library/model/license/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java similarity index 93% rename from src/main/java/org/spdx/library/model/license/package-info.java rename to src/main/java/org/spdx/library/model/compat/v2/license/package-info.java index 56688b126..c3fe3feb2 100644 --- a/src/main/java/org/spdx/library/model/license/package-info.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java @@ -21,4 +21,4 @@ * Model for the SPDX license related objects * */ -package org.spdx.library.model.license; \ No newline at end of file +package org.spdx.library.model.compat.v2.license; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/package-info.java similarity index 95% rename from src/main/java/org/spdx/library/model/package-info.java rename to src/main/java/org/spdx/library/model/compat/v2/package-info.java index 9df654a18..8e56c0ba9 100644 --- a/src/main/java/org/spdx/library/model/package-info.java +++ b/src/main/java/org/spdx/library/model/compat/v2/package-info.java @@ -22,4 +22,4 @@ * See the SPDX spec model description for a UML diagram of the model * */ -package org.spdx.library.model; \ No newline at end of file +package org.spdx.library.model.compat.v2; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/pointer/ByteOffsetPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java similarity index 90% rename from src/main/java/org/spdx/library/model/pointer/ByteOffsetPointer.java rename to src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java index b2809e432..7efd1873c 100644 --- a/src/main/java/org/spdx/library/model/pointer/ByteOffsetPointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.pointer; +package org.spdx.library.model.compat.v2.pointer; import java.util.List; import java.util.Objects; @@ -24,7 +24,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; /** @@ -63,18 +63,18 @@ public ByteOffsetPointer(IModelStore modelStore, String documentUri, String id, } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_POINTER_BYTE_OFFSET_POINTER; + return SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER; } /** * @return the offset, -1 if no offset is stored */ public int getOffset() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstants.PROP_POINTER_OFFSET); + Optional retval = getIntegerPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_OFFSET); if (!retval.isPresent()) { return -1; } @@ -90,11 +90,11 @@ public void setOffset(Integer offset) throws InvalidSPDXAnalysisException { throw new InvalidSPDXAnalysisException("Can not set required offset to null or less than zero"); } } - setPropertyValue(SpdxConstants.PROP_POINTER_OFFSET, offset); + setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_OFFSET, offset); } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/pointer/CompoundPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java similarity index 87% rename from src/main/java/org/spdx/library/model/pointer/CompoundPointer.java rename to src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java index 3bd100914..d21f4899d 100644 --- a/src/main/java/org/spdx/library/model/pointer/CompoundPointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.pointer; +package org.spdx.library.model.compat.v2.pointer; import java.util.ArrayList; import java.util.List; @@ -27,9 +27,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -73,7 +73,7 @@ public CompoundPointer(IModelStore modelStore, String documentUri, String id, Mo * @throws InvalidSPDXAnalysisException */ public @Nullable SinglePointer getStartPointer() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_POINTER_START_POINTER); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_START_POINTER); if (!retval.isPresent()) { return null; } @@ -94,12 +94,12 @@ public CompoundPointer setStartPointer(SinglePointer startPointer) throws Invali throw new InvalidSPDXAnalysisException("Can not set required startPointer to null"); } } - setPropertyValue(SpdxConstants.PROP_POINTER_START_POINTER, startPointer); + setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_START_POINTER, startPointer); return this; } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -119,7 +119,7 @@ protected List _verify(Set verifiedIds, String specVersion) { @Override public String getType() { - return SpdxConstants.CLASS_POINTER_COMPOUNT_POINTER; + return SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER; } } diff --git a/src/main/java/org/spdx/library/model/pointer/LineCharPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java similarity index 90% rename from src/main/java/org/spdx/library/model/pointer/LineCharPointer.java rename to src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java index 7953c2a02..707a35270 100644 --- a/src/main/java/org/spdx/library/model/pointer/LineCharPointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.pointer; +package org.spdx.library.model.compat.v2.pointer; import java.util.List; import java.util.Objects; @@ -24,7 +24,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; /** @@ -65,7 +65,7 @@ public LineCharPointer(IModelStore modelStore, String documentUri, String id, Mo * @return the lineNumber, -1 if no lineNumber is stored */ public int getLineNumber() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstants.PROP_POINTER_LINE_NUMBER); + Optional retval = getIntegerPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_LINE_NUMBER); if (retval.isPresent()) { return retval.get(); } else { @@ -83,11 +83,11 @@ public void setLineNumber(Integer lineNumber) throws InvalidSPDXAnalysisExceptio throw new InvalidSPDXAnalysisException("Can not set required lineNumber to null"); } } - setPropertyValue(SpdxConstants.PROP_POINTER_LINE_NUMBER, lineNumber); + setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_LINE_NUMBER, lineNumber); } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { @@ -156,11 +156,11 @@ public String toString() { } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() */ @Override public String getType() { - return SpdxConstants.CLASS_POINTER_LINE_CHAR_POINTER; + return SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER; } } diff --git a/src/main/java/org/spdx/library/model/pointer/SinglePointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java similarity index 90% rename from src/main/java/org/spdx/library/model/pointer/SinglePointer.java rename to src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java index d3308eb2f..1ddc1d78d 100644 --- a/src/main/java/org/spdx/library/model/pointer/SinglePointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.pointer; +package org.spdx.library.model.compat.v2.pointer; import java.util.ArrayList; import java.util.List; @@ -29,10 +29,10 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxElement; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -79,7 +79,7 @@ public SinglePointer(IModelStore modelStore, String documentUri, String id, Mode * @throws InvalidSPDXAnalysisException */ public @Nullable SpdxElement getReference() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_POINTER_REFERENCE); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_REFERENCE); if (!retval.isPresent()) { return null; } @@ -99,11 +99,11 @@ public void setReference(SpdxElement reference) throws InvalidSPDXAnalysisExcept throw new InvalidSPDXAnalysisException("Can not set required reference to null"); } } - setPropertyValue(SpdxConstants.PROP_POINTER_REFERENCE, reference); + setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_REFERENCE, reference); } /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/pointer/StartEndPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java similarity index 92% rename from src/main/java/org/spdx/library/model/pointer/StartEndPointer.java rename to src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java index a8643cdc6..25d24813a 100644 --- a/src/main/java/org/spdx/library/model/pointer/StartEndPointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.pointer; +package org.spdx.library.model.compat.v2.pointer; import java.util.List; import java.util.Objects; @@ -28,8 +28,8 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxInvalidTypeException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** @@ -71,7 +71,7 @@ public StartEndPointer(IModelStore modelStore, String documentUri, String id, Mo @Override public String getType() { - return SpdxConstants.CLASS_POINTER_START_END_POINTER; + return SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER; } /** @@ -79,7 +79,7 @@ public String getType() { * @throws InvalidSPDXAnalysisException */ public @Nullable SinglePointer getEndPointer() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.PROP_POINTER_END_POINTER); + Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_END_POINTER); if (!retval.isPresent()) { return null; } @@ -106,7 +106,7 @@ public void setEndPointer(SinglePointer endPointer) throws InvalidSPDXAnalysisEx } //TODO: We could add a check to make sure the endpointer is greater than the startpointer } - setPropertyValue(SpdxConstants.PROP_POINTER_END_POINTER, endPointer); + setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_END_POINTER, endPointer); } @Override @@ -119,12 +119,12 @@ public StartEndPointer setStartPointer(SinglePointer startPointer) throws Invali } //TODO: We could add a check to make sure the startPointer is less than the endPointer } - setPropertyValue(SpdxConstants.PROP_POINTER_START_POINTER, startPointer); + setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_START_POINTER, startPointer); return this; } /* (non-Javadoc) - * @see org.spdx.library.model.pointer.CompoundPointer#_verify(java.util.List) + * @see org.spdx.library.model.compat.v2.compat.v2.pointer.CompoundPointer#_verify(java.util.List) */ @Override protected List _verify(Set verifiedIds, String specVersion) { diff --git a/src/main/java/org/spdx/library/model/pointer/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java similarity index 96% rename from src/main/java/org/spdx/library/model/pointer/package-info.java rename to src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java index e1293bcd0..a692fde31 100644 --- a/src/main/java/org/spdx/library/model/pointer/package-info.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java @@ -30,4 +30,4 @@ * * @author Gary O'Neall */ -package org.spdx.library.model.pointer; \ No newline at end of file +package org.spdx.library.model.compat.v2.pointer; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/package-info.java b/src/main/java/org/spdx/library/package-info.java index df871d30f..b33ff7122 100644 --- a/src/main/java/org/spdx/library/package-info.java +++ b/src/main/java/org/spdx/library/package-info.java @@ -19,7 +19,7 @@ * Package containing useful library functions for reading, writing, and manipulating * SPDX documents. * - * The org.spdx.library.model package represents the SPDX model as Java objects + * The org.spdx.library.model.compat.v2.compat.v2 package represents the SPDX model as Java objects * with getters and setters to support manipulating the SPDX documents. * * The org.spdx.storage package implements an interface to a storage framework diff --git a/src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java b/src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java similarity index 93% rename from src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java rename to src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java index f25990a22..d370436c9 100644 --- a/src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java +++ b/src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.referencetype; +package org.spdx.library.referencetype.compat.v2; import java.io.IOException; import java.io.InputStream; @@ -33,8 +33,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ReferenceType; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ReferenceType; /** * Singleton class that maintains the current SPDX listed reference types. @@ -145,8 +145,8 @@ public static ListedReferenceTypes resetListedReferenceTypes() { * @return */ public boolean isListedReferenceType(URI uri) { - if (uri.toString().startsWith(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX)) { - String referenceTypeName = uri.toString().substring(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX.length()); + if (uri.toString().startsWith(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX)) { + String referenceTypeName = uri.toString().substring(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX.length()); return this.listedReferenceNames.contains(referenceTypeName); } else { return false; @@ -162,7 +162,7 @@ public boolean isListedReferenceType(URI uri) { public URI getListedReferenceUri(String listedReferenceName) throws InvalidSPDXAnalysisException { URI retval; try { - retval = new URI(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + listedReferenceName); + retval = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + listedReferenceName); } catch (URISyntaxException e) { logger.error("Error forming listed license URI",e); throw new InvalidSPDXAnalysisException(listedReferenceName + " is not a valid SPDX listed reference type syntax."); @@ -196,7 +196,7 @@ public String getListedReferenceName(URI uri) throws InvalidSPDXAnalysisExceptio if (!this.isListedReferenceType(uri)) { throw new InvalidSPDXAnalysisException(uri.toString() + " is not a valid URI for an SPDX listed reference type."); } - return uri.toString().substring(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX.length()); + return uri.toString().substring(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX.length()); } //TODO: Implement accessing the SPDX reference type pages directly similar to the SpdxListedLicenses class diff --git a/src/main/java/org/spdx/library/referencetype/listedreferencetypes.properties b/src/main/java/org/spdx/library/referencetype/compat/v2/listedreferencetypes.properties similarity index 100% rename from src/main/java/org/spdx/library/referencetype/listedreferencetypes.properties rename to src/main/java/org/spdx/library/referencetype/compat/v2/listedreferencetypes.properties diff --git a/src/main/java/org/spdx/library/referencetype/package-info.java b/src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java similarity index 94% rename from src/main/java/org/spdx/library/referencetype/package-info.java rename to src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java index f0c21849b..4612fc69d 100644 --- a/src/main/java/org/spdx/library/referencetype/package-info.java +++ b/src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java @@ -21,4 +21,4 @@ * @author Gary O'Neall * */ -package org.spdx.library.referencetype; \ No newline at end of file +package org.spdx.library.referencetype.compat.v2; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/IModelStore.java b/src/main/java/org/spdx/storage/IModelStore.java index f32ee9f64..53483f0cf 100644 --- a/src/main/java/org/spdx/storage/IModelStore.java +++ b/src/main/java/org/spdx/storage/IModelStore.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.TypedValue; +import org.spdx.library.model.compat.v2.TypedValue; /** * Service Provider Interface for storing and retrieving SPDX properties for SPDX documents. @@ -76,7 +76,7 @@ public enum IdType { * Create a new object with ID * @param documentUri the SPDX Document URI * @param id unique ID within the SPDX document - * @param type SPDX model type as defined in the CLASS constants in SpdxConstants + * @param type SPDX model type as defined in the CLASS constants in SpdxConstantsCompatV2 * @throws InvalidSPDXAnalysisException */ public void create(String documentUri, String id, String type) throws InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java index 5eb7aae33..b98c96b8c 100644 --- a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java @@ -26,8 +26,8 @@ import javax.annotation.Nullable; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.InvalidSpdxPropertyException; -import org.spdx.library.model.license.CrossRef; +import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.model.compat.v2.license.CrossRef; /** * JSON Representation of a CrossRef diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java index d76a3241d..86b862f09 100644 --- a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java @@ -24,9 +24,9 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.InvalidSpdxPropertyException; -import org.spdx.library.model.license.ListedLicenseException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; /** * Simple POJO to hold the license exception data loaded from a JSON file @@ -265,14 +265,14 @@ public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) } public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - if (!SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { + if (!SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { return false; } return String.class.isAssignableFrom(clazz); } public boolean isCollectionProperty(String propertyName) { - return SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName); + return SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName); } } diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java index 934083394..6d485c528 100644 --- a/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java +++ b/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; /** diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java index 58d28bf7b..187a40c0d 100644 --- a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java @@ -24,10 +24,10 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.InvalidSpdxPropertyException; -import org.spdx.library.model.license.CrossRef; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.model.compat.v2.license.CrossRef; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; /** @@ -192,7 +192,7 @@ public void clearPropertyValueList(String propertyName) throws InvalidSpdxProper * @throws InvalidSPDXAnalysisException */ public boolean addCrossRefValueToList(String propertyName, CrossRefJson value) throws InvalidSPDXAnalysisException { - if (SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName)) { + if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { return crossRef.add(value); } else { throw new InvalidSpdxPropertyException(propertyName + "is not a crossRef list type"); @@ -212,7 +212,7 @@ public boolean addPrimitiveValueToList(String propertyName, Object value) throws throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); } return seeAlso.add((String)value); - } else if (SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName)) { + } else if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { if (!(value instanceof CrossRefJson)) { throw new InvalidSpdxPropertyException("Expected CrossRefJson type for "+propertyName); } @@ -371,9 +371,9 @@ public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) } public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - if (SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { + if (SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { return String.class.isAssignableFrom(clazz); - } else if (SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName)) { + } else if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { return CrossRef.class.isAssignableFrom(clazz); } else { return false; @@ -381,7 +381,7 @@ public boolean isCollectionMembersAssignableTo(String propertyName, Class cla } public boolean isCollectionProperty(String propertyName) { - return SpdxConstants.RDFS_PROP_SEE_ALSO.getName().equals(propertyName) || - SpdxConstants.PROP_CROSS_REF.getName().equals(propertyName); + return SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName) || + SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName); } } diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java index 90c1b181d..f106264c0 100644 --- a/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java @@ -23,8 +23,8 @@ import javax.annotation.Nullable; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; /** @@ -258,6 +258,6 @@ public void setReleaseDate(String releaseDate) { private static String toAbsoluteURL(String relURL) { String retval = relURL.startsWith("./") ? relURL.substring(2) : relURL; - return SpdxConstants.LISTED_LICENSE_URL + retval; + return SpdxConstantsCompatV2.LISTED_LICENSE_URL + retval; } } diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index b7e9d5485..2709318e5 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -40,12 +40,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.DuplicateSpdxIdException; -import org.spdx.library.model.SpdxIdNotFoundException; -import org.spdx.library.model.TypedValue; -import org.spdx.library.model.license.LicenseInfoFactory; -import org.spdx.library.model.license.SpdxListedLicenseException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.DuplicateSpdxIdException; +import org.spdx.library.model.compat.v2.SpdxIdNotFoundException; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.license.SpdxListedLicenseException; import org.spdx.storage.PropertyDescriptor; import com.google.gson.Gson; @@ -69,7 +69,7 @@ public abstract class SpdxListedLicenseModelStore implements IListedLicenseStore static final String LICENSE_TOC_FILENAME = "licenses.json"; static final String EXCEPTION_TOC_FILENAME = "exceptions.json"; static final String JSON_SUFFIX = ".json"; - private static final List DOCUMENT_URIS = Collections.unmodifiableList(Arrays.asList(new String[]{SpdxConstants.LISTED_LICENSE_URL})); + private static final List DOCUMENT_URIS = Collections.unmodifiableList(Arrays.asList(new String[]{SpdxConstantsCompatV2.LISTED_LICENSE_URL})); private static final String ANONYMOUS_ID_PREFIX = "SpdxLicenseGeneratedId-"; /** @@ -193,7 +193,7 @@ private void loadIds() throws InvalidSPDXAnalysisException { */ @Override public boolean exists(String documentUri, String id) { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { return false; } listedLicenseModificationLock.readLock().lock(); @@ -211,26 +211,26 @@ public boolean exists(String documentUri, String id) { */ @Override public void create(String documentUri, String id, String type) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } listedLicenseModificationLock.writeLock().lock(); try { - if (SpdxConstants.CLASS_CROSS_REF.equals(type)) { + if (SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(type)) { CrossRefJson crossRef = new CrossRefJson(); crossRef.setId(id); this.crossRefs.put(id, crossRef); - } else if (SpdxConstants.CLASS_SPDX_LISTED_LICENSE.equals(type)) { + } else if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(type)) { if (this.licenseIds.containsKey(id.toLowerCase()) || this.exceptionIds.containsKey(id.toLowerCase())) { logger.error("Duplicate SPDX ID on create: "+id);; throw new DuplicateSpdxIdException("ID "+id+" already exists."); } this.licenseIds.put(id.toLowerCase(), id); this.listedLicenseCache.put(id, new LicenseJson(id)); - } else if (SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)) { + } else if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)) { if (this.licenseIds.containsKey(id.toLowerCase()) || this.exceptionIds.containsKey(id.toLowerCase())) { logger.error("Duplicate SPDX ID on create: "+id);; throw new DuplicateSpdxIdException("ID "+id+" already exists."); @@ -248,11 +248,11 @@ public void create(String documentUri, String id, String type) throws InvalidSPD */ @Override public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -270,14 +270,14 @@ public List getPropertyValueDescriptors(String documentUri, if (isLicenseId) { LicenseJson license = fetchLicenseJson(licenseIds.get(id.toLowerCase())); license.getPropertyValueNames().spliterator().forEachRemaining( - s -> retval.add(new PropertyDescriptor(s, SpdxConstants.SPDX_NAMESPACE))); + s -> retval.add(new PropertyDescriptor(s, SpdxConstantsCompatV2.SPDX_NAMESPACE))); } else if (isExceptionId) { ExceptionJson exc = fetchExceptionJson(exceptionIds.get(id.toLowerCase())); exc.getPropertyValueNames().spliterator().forEachRemaining( - s -> retval.add(new PropertyDescriptor(s, SpdxConstants.SPDX_NAMESPACE))); + s -> retval.add(new PropertyDescriptor(s, SpdxConstantsCompatV2.SPDX_NAMESPACE))); } else if (Objects.nonNull(crossRef)) { crossRef.getPropertyValueNames().spliterator().forEachRemaining( - s -> retval.add(new PropertyDescriptor(s, SpdxConstants.SPDX_NAMESPACE))); + s -> retval.add(new PropertyDescriptor(s, SpdxConstantsCompatV2.SPDX_NAMESPACE))); } else { logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID"); @@ -436,11 +436,11 @@ private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws Invali */ @Override public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -476,11 +476,11 @@ public void setValue(String documentUri, String id, PropertyDescriptor propertyD */ @Override public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -516,11 +516,11 @@ public void clearValueCollection(String documentUri, String id, PropertyDescript */ @Override public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -539,15 +539,15 @@ public boolean addValueToCollection(String documentUri, String id, PropertyDescr } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - if (SpdxConstants.PROP_CROSS_REF.equals(propertyDescriptor)) { + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { if (!(value instanceof TypedValue)) { logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); } TypedValue tv = (TypedValue)value; - if (!SpdxConstants.CLASS_CROSS_REF.equals(tv.getType())) { - logger.error("Invalid type for CrossRef - expected"+SpdxConstants.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstants.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + if (!SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(tv.getType())) { + logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); } CrossRefJson crj = crossRefs.get(tv.getId()); if (Objects.isNull(crj)) { @@ -572,11 +572,11 @@ public boolean addValueToCollection(String documentUri, String id, PropertyDescr @Override public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -595,15 +595,15 @@ public boolean removeValueFromCollection(String documentUri, String id, Property } if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); - if (SpdxConstants.PROP_CROSS_REF.equals(propertyDescriptor)) { + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { if (!(value instanceof TypedValue)) { logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); } TypedValue tv = (TypedValue)value; - if (!SpdxConstants.CLASS_CROSS_REF.equals(tv.getType())) { - logger.error("Invalid type for CrossRef - expected"+SpdxConstants.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstants.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + if (!SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(tv.getType())) { + logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); } CrossRefJson crj = crossRefs.get(tv.getId()); if (Objects.isNull(crj)) { @@ -631,11 +631,11 @@ public boolean removeValueFromCollection(String documentUri, String id, Property @SuppressWarnings("unchecked") @Override public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -655,7 +655,7 @@ public Iterator listValues(String documentUri, String id, PropertyDescri if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); - if (SpdxConstants.PROP_CROSS_REF.equals(propertyDescriptor)) { + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { final Iterator crossRefJsonIter = valueList.iterator(); return new Iterator() { @@ -680,7 +680,7 @@ public Object next() { if (Objects.isNull(crossRefId)) { // Need to create an ID and store it in the cache try { - crossRefId = getNextId(IdType.Anonymous, SpdxConstants.LISTED_LICENSE_URL); + crossRefId = getNextId(IdType.Anonymous, SpdxConstantsCompatV2.LISTED_LICENSE_URL); } catch (InvalidSPDXAnalysisException e) { logger.error("Error getting next Anonymous ID",e); throw new RuntimeException(e); @@ -692,7 +692,7 @@ public Object next() { listedLicenseModificationLock.writeLock().unlock(); } try { - return new TypedValue(crossRefId, SpdxConstants.CLASS_CROSS_REF); + return new TypedValue(crossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); } catch (InvalidSPDXAnalysisException e) { logger.error("Error creating TypedValue for CrossRef",e); throw new RuntimeException(e); @@ -718,11 +718,11 @@ public Object next() { */ @Override public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -758,11 +758,11 @@ public Optional getValue(String documentUri, String id, PropertyDescript */ @Override public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } this.listedLicenseModificationLock.writeLock().lock(); try { @@ -842,11 +842,11 @@ public Optional getTypedValue(String documentUri, String id) throws listedLicenseModificationLock.readLock().lock(); try { if (licenseIds.containsKey(id.toLowerCase())) { - return Optional.of(new TypedValue(id, SpdxConstants.CLASS_SPDX_LISTED_LICENSE)); + return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE)); } else if (exceptionIds.containsKey(id.toLowerCase())) { - return Optional.of(new TypedValue(id, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION)); + return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION)); } else if (crossRefs.containsKey(id)) { - return Optional.of(new TypedValue(id, SpdxConstants.CLASS_CROSS_REF)); + return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_CROSS_REF)); } else { return Optional.empty(); } @@ -857,11 +857,11 @@ public Optional getTypedValue(String documentUri, String id) throws @Override public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -904,19 +904,19 @@ public Stream getAllItems(String documentUri, @Nullable String typeF listedLicenseModificationLock.readLock().lock(); try { List allItems = new ArrayList(); - if (Objects.isNull(typeFilter) || SpdxConstants.CLASS_SPDX_LISTED_LICENSE.equals(typeFilter)) { + if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(typeFilter)) { for (String licenseId:this.licenseIds.values()) { - allItems.add(new TypedValue(licenseId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE)); + allItems.add(new TypedValue(licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE)); } } - if (Objects.isNull(typeFilter) || SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(typeFilter)) { + if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(typeFilter)) { for (String exceptionId:this.exceptionIds.values()) { - allItems.add(new TypedValue(exceptionId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION)); + allItems.add(new TypedValue(exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION)); } } - if (Objects.isNull(typeFilter) || SpdxConstants.CLASS_CROSS_REF.equals(typeFilter)) { + if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(typeFilter)) { for (String crossRefId:crossRefs.keySet()) { - allItems.add(new TypedValue(crossRefId, SpdxConstants.CLASS_CROSS_REF)); + allItems.add(new TypedValue(crossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF)); } } return Collections.unmodifiableList(allItems).stream(); @@ -930,11 +930,11 @@ public Stream getAllItems(String documentUri, @Nullable String typeF @SuppressWarnings("unchecked") @Override public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -969,11 +969,11 @@ public int collectionSize(String documentUri, String id, PropertyDescriptor prop @Override public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -993,7 +993,7 @@ public boolean collectionContains(String documentUri, String id, PropertyDescrip if (isLicenseId) { LicenseJson license = fetchLicenseJson(id); List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); - if (value instanceof TypedValue && SpdxConstants.CLASS_CROSS_REF.equals(((TypedValue)value).getType())) { + if (value instanceof TypedValue && SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(((TypedValue)value).getType())) { CrossRefJson compareValue = crossRefs.get(((TypedValue)value).getId()); if (Objects.isNull(compareValue)) { return false; @@ -1017,11 +1017,11 @@ public boolean collectionContains(String documentUri, String id, PropertyDescrip @Override public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -1055,11 +1055,11 @@ public boolean isCollectionMembersAssignableTo(String documentUri, String id, Pr @Override public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -1093,11 +1093,11 @@ public boolean isPropertyValueAssignableTo(String documentUri, String id, Proper @Override public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } boolean isLicenseId = false; boolean isExceptionId = false; @@ -1189,11 +1189,11 @@ public Optional getCaseSensisitiveId(String documentUri, String caseInse @Override public void delete(String documentUri, String id) throws InvalidSPDXAnalysisException { - if (!SpdxConstants.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstants.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); } listedLicenseModificationLock.writeLock().lock(); try { diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java index 068974dbd..e776cfa9d 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java @@ -27,7 +27,7 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; /** * @author gary @@ -78,17 +78,17 @@ private InputStream getUrlInputStream(URL url) throws IOException { @Override InputStream getTocInputStream() throws IOException { - return getUrlInputStream(new URL(SpdxConstants.LISTED_LICENSE_URL + LICENSE_TOC_FILENAME)); + return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + LICENSE_TOC_FILENAME)); } @Override InputStream getLicenseInputStream(String licenseId) throws IOException { - return getUrlInputStream(new URL(SpdxConstants.LISTED_LICENSE_URL + licenseId + JSON_SUFFIX)); + return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId + JSON_SUFFIX)); } @Override InputStream getExceptionTocInputStream() throws IOException { - return getUrlInputStream(new URL(SpdxConstants.LISTED_LICENSE_URL + EXCEPTION_TOC_FILENAME)); + return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + EXCEPTION_TOC_FILENAME)); } @Override diff --git a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java index ec8da8756..52778bca3 100644 --- a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java @@ -24,7 +24,7 @@ import java.util.stream.Stream; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.TypedValue; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index e4a2e6424..c63aea0ea 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -38,13 +38,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.DuplicateSpdxIdException; -import org.spdx.library.model.ModelCollection; -import org.spdx.library.model.SpdxIdInUseException; -import org.spdx.library.model.SpdxIdNotFoundException; -import org.spdx.library.model.TypedValue; -import org.spdx.library.model.license.LicenseInfoFactory; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.DuplicateSpdxIdException; +import org.spdx.library.model.compat.v2.ModelCollection; +import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.model.compat.v2.SpdxIdNotFoundException; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -65,13 +65,13 @@ public class InMemSpdxStore implements IModelStore { static final String GENERATED = "gnrtd"; public static Pattern LICENSE_ID_PATTERN_GENERATED = - Pattern.compile(SpdxConstants.NON_STD_LICENSE_ID_PRENUM+GENERATED+"(\\d+)$"); // Pattern for generated license IDs + Pattern.compile(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+"(\\d+)$"); // Pattern for generated license IDs - static Pattern DOCUMENT_ID_PATTERN_GENERATED = Pattern.compile(SpdxConstants.EXTERNAL_DOC_REF_PRENUM+GENERATED+"(\\d+)$"); - static Pattern SPDX_ID_PATTERN_GENERATED = Pattern.compile(SpdxConstants.SPDX_ELEMENT_REF_PRENUM+GENERATED+"(\\d+)$"); + static Pattern DOCUMENT_ID_PATTERN_GENERATED = Pattern.compile(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+"(\\d+)$"); + static Pattern SPDX_ID_PATTERN_GENERATED = Pattern.compile(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+"(\\d+)$"); static final String ANON_PREFIX = "__anon__"; static Pattern ANON_ID_PATTERN_GENERATED = Pattern.compile(ANON_PREFIX+GENERATED+"(\\d+)$"); - private static final Set LITERAL_VALUE_SET = new HashSet(Arrays.asList(SpdxConstants.LITERAL_VALUES)); + private static final Set LITERAL_VALUE_SET = new HashSet(Arrays.asList(SpdxConstantsCompatV2.LITERAL_VALUES)); /** * Map of Document URI to items stored in the document. The key for the items map is the lowercase of the item ID. @@ -307,9 +307,9 @@ public Optional getValue(String documentUri, String id, PropertyDescript public synchronized String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException { switch (idType) { case Anonymous: return ANON_PREFIX+GENERATED+String.valueOf(nextAnonId++); - case LicenseRef: return SpdxConstants.NON_STD_LICENSE_ID_PRENUM+GENERATED+String.valueOf(nextNextLicenseId++); - case DocumentRef: return SpdxConstants.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); - case SpdxId: return SpdxConstants.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); + case LicenseRef: return SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+String.valueOf(nextNextLicenseId++); + case DocumentRef: return SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); + case SpdxId: return SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); case ListedLicense: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Listed License"); case Literal: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Literal"); default: throw new InvalidSPDXAnalysisException("Unknown ID type for next ID: "+idType.toString()); @@ -387,13 +387,13 @@ public IdType getIdType(String id) { if (id.startsWith(ANON_PREFIX+GENERATED)) { return IdType.Anonymous; } - if (id.startsWith(SpdxConstants.NON_STD_LICENSE_ID_PRENUM)) { + if (id.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { return IdType.LicenseRef; } - if (id.startsWith(SpdxConstants.EXTERNAL_DOC_REF_PRENUM)) { + if (id.startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { return IdType.DocumentRef; } - if (id.startsWith(SpdxConstants.SPDX_ELEMENT_REF_PRENUM)) { + if (id.startsWith(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { return IdType.SpdxId; } if (LITERAL_VALUE_SET.contains(id)) { diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index cae892406..efb1649d1 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -18,13 +18,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxInvalidTypeException; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.TypedValue; -import org.spdx.library.model.enumerations.SpdxEnumFactory; -import org.spdx.library.model.IndividualUriValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -40,7 +40,7 @@ public class StoredTypedItem extends TypedValue { private static final String NO_ID_ID = "__NO_ID__"; // ID to use in list has map for non-typed values - static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstants.ALL_SPDX_CLASSES)); + static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); private ConcurrentHashMap properties = new ConcurrentHashMap<>(); @@ -426,8 +426,8 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri if (!clazz.isAssignableFrom(spdxEnum.getClass())) { return false; } - } else if (!(SpdxConstants.URI_VALUE_NOASSERTION.equals(uri) || - SpdxConstants.URI_VALUE_NONE.equals(uri))) { + } else if (!(SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri) || + SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri))) { return false; } } else if (value instanceof TypedValue) { @@ -473,10 +473,10 @@ public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor } if (value instanceof IndividualUriValue) { String uri = ((IndividualUriValue)value).getIndividualURI(); - if (SpdxConstants.URI_VALUE_NOASSERTION.equals(uri)) { + if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { return true; } - if (SpdxConstants.URI_VALUE_NONE.equals(uri)) { + if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { return true; } Enum spdxEnum = SpdxEnumFactory.uriToEnum.get(uri); diff --git a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java index c0a0418ca..aeb1b7723 100644 --- a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java +++ b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java @@ -38,16 +38,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.License; -import org.spdx.library.model.license.LicenseException; -import org.spdx.library.model.license.LicenseSet; -import org.spdx.library.model.license.ListedLicenseException; -import org.spdx.library.model.license.ListedLicenses; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.License; +import org.spdx.library.model.compat.v2.license.LicenseException; +import org.spdx.library.model.compat.v2.license.LicenseSet; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenses; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.licenseTemplate.LicenseParserException; import org.spdx.licenseTemplate.LicenseTemplateRuleException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; diff --git a/src/main/java/org/spdx/utility/compare/SpdxComparer.java b/src/main/java/org/spdx/utility/compare/SpdxComparer.java index da488c67c..f12318b43 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxComparer.java @@ -34,21 +34,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.ExternalDocumentRef; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxCreatorInformation; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxElement; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.SpdxPackage; -import org.spdx.library.model.SpdxPackageVerificationCode; -import org.spdx.library.model.SpdxSnippet; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxCreatorInformation; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; /** * Performs a comparison between two or more SPDX documents and holds the results of the comparison * The main function to perform the comparison is compare(spdxdoc1, spdxdoc2) diff --git a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java index b8f3b3ec9..a4bbc3286 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java @@ -21,9 +21,9 @@ import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.ExternalRef; -import org.spdx.library.model.ReferenceType; -import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.ExternalRef; +import org.spdx.library.model.compat.v2.ReferenceType; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; /** * Contains information on differences between two different External Refs. diff --git a/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java b/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java index 711ca17d7..99659c8a0 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java @@ -26,13 +26,13 @@ import java.util.Map.Entry; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; /** * Compares two SPDX files. The compare(fileA, fileB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java index dce645883..7cf8e12b3 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java @@ -24,12 +24,12 @@ import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; /** * Contains the results of a comparison between two SPDX files with the same name diff --git a/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java b/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java index 8d6a92d41..58f0db064 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java @@ -27,11 +27,11 @@ import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; /** * Compares two SPDX items. The compare(itemA, itemB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java b/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java index 231bd6c44..739b29ef8 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java @@ -21,10 +21,10 @@ import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; /** * Contains the results of a comparison between two SPDX items with the same name diff --git a/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java b/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java index 290c20a45..d1ff9efb8 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java @@ -20,7 +20,7 @@ import java.util.Collection; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; /** * Contains the results of a comparison between two SPDX non-standard licenses diff --git a/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java b/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java index 4cd4ffadd..00fe7368d 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java @@ -30,12 +30,12 @@ import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.ExternalRef; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.SpdxPackage; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalRef; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.SpdxPackage; /** * Compares two SPDX package. The compare(pkgA, pkgB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java b/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java index 057e493d4..3600b2a38 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java @@ -25,11 +25,11 @@ import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.SpdxSnippet; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; /** * Compares two SPDX snippets. The compare(snippetA, snippetB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java b/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java index e75c42a69..2403423c9 100644 --- a/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java +++ b/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java @@ -30,8 +30,8 @@ import java.util.TreeSet; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java b/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java index 15b3fa4e9..ff101ff7b 100644 --- a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java +++ b/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java @@ -22,7 +22,7 @@ import java.util.Date; import java.util.Objects; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; @@ -50,7 +50,7 @@ protected void tearDown() throws Exception { * Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyNonStdLicenseid(java.lang.String)}. */ public void testVerifyNonStdLicenseid() { - assertTrue(Objects.isNull(SpdxVerificationHelper.verifyNonStdLicenseid(SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"something"))); + assertTrue(Objects.isNull(SpdxVerificationHelper.verifyNonStdLicenseid(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"something"))); assertFalse(Objects.isNull(SpdxVerificationHelper.verifyNonStdLicenseid("InvalidID"))); } @@ -88,7 +88,7 @@ public void testVerifySupplier() { * Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyDate(java.lang.String)}. */ public void testVerifyDate() { - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String fullDate = format.format(new Date()); assertTrue(Objects.isNull(SpdxVerificationHelper.verifyDate(fullDate))); assertFalse(Objects.isNull(SpdxVerificationHelper.verifyDate(new Date().toString()))); @@ -123,7 +123,7 @@ public void testIsValidUri() { } /** - * Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyChecksumString(java.lang.String, org.spdx.library.model.enumerations.ChecksumAlgorithm)}. + * Test method for {@link org.spdx.library.SpdxVerificationHelper#verifyChecksumString(java.lang.String, org.spdx.library.model.compat.v2.compat.v2.enumerations.ChecksumAlgorithm)}. */ public void testVerifyChecksumString() { assertTrue(Objects.isNull(SpdxVerificationHelper.verifyChecksumString("bc527343c7ffc103111f3a694b004e2f", ChecksumAlgorithm.MD5, Version.CURRENT_SPDX_VERSION))); diff --git a/src/test/java/org/spdx/library/model/AnnotationTest.java b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java similarity index 83% rename from src/test/java/org/spdx/library/model/AnnotationTest.java rename to src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java index 161c648fe..95ca913c8 100644 --- a/src/test/java/org/spdx/library/model/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -23,8 +23,10 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import junit.framework.TestCase; @@ -49,7 +51,7 @@ public class AnnotationTest extends TestCase { protected void setUp() throws Exception { super.setUp(); DefaultModelStore.reset(); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); date = format.format(new Date()); oldDate = format.format(new Date(10101)); } @@ -62,16 +64,16 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.Annotation#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Annotation#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { Annotation a = new GenericModelObject().createAnnotation(ANNOTATOR1, OTHER_ANNOTATION, date, COMMENT1); assertEquals(0, a.verify().size()); - a.setPropertyValue(SpdxConstants.PROP_ANNOTATION_TYPE, null); - a.setPropertyValue(SpdxConstants.PROP_ANNOTATOR, null); - a.setPropertyValue(SpdxConstants.PROP_ANNOTATION_DATE, null); - a.setPropertyValue(SpdxConstants.RDFS_PROP_COMMENT, null); + a.setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_TYPE, null); + a.setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATOR, null); + a.setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_DATE, null); + a.setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, null); assertEquals(4, a.verify().size()); } @@ -88,7 +90,7 @@ public void testSetAnnotationType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Annotation#setAnnotator(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Annotation#setAnnotator(java.lang.String)}. */ public void testSetAnnotator() throws InvalidSPDXAnalysisException { Annotation a = new GenericModelObject().createAnnotation(ANNOTATOR1, OTHER_ANNOTATION, date, COMMENT1); @@ -103,7 +105,7 @@ public void testSetAnnotator() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Annotation#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Annotation#setComment(java.lang.String)}. */ public void testSetComment() throws InvalidSPDXAnalysisException { Annotation a = new GenericModelObject().createAnnotation(ANNOTATOR1, OTHER_ANNOTATION, date, COMMENT1); @@ -118,7 +120,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Annotation#setAnnotationDate(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Annotation#setAnnotationDate(java.lang.String)}. */ public void testSetAnnotationDate() throws InvalidSPDXAnalysisException { Annotation a = new GenericModelObject().createAnnotation(ANNOTATOR1, OTHER_ANNOTATION, date, COMMENT1); diff --git a/src/test/java/org/spdx/library/model/ByteOffsetPointerTest.java b/src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java similarity index 93% rename from src/test/java/org/spdx/library/model/ByteOffsetPointerTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java index 3ce6ec29c..03c52426e 100644 --- a/src/test/java/org/spdx/library/model/ByteOffsetPointerTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java @@ -15,13 +15,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.List; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/ChecksumTest.java b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java similarity index 89% rename from src/test/java/org/spdx/library/model/ChecksumTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java index 9c4ecd5a2..fe9d01ba2 100644 --- a/src/test/java/org/spdx/library/model/ChecksumTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java @@ -15,15 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.List; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; @@ -103,17 +105,17 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Checksum#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Checksum#verify()}. */ public void testVerify() throws InvalidSPDXAnalysisException { Checksum checksum = gmo.createChecksum(ChecksumAlgorithm.SHA1, "0123456789abcdef0123456789abcdef01234567"); List verify = checksum.verify(); - checksum.setPropertyValue(SpdxConstants.PROP_CHECKSUM_VALUE, "Bad value"); + checksum.setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_VALUE, "Bad value"); assertEquals(1, checksum.verify().size()); checksum.setValue("0123456789abcdef0123456789abcdef01234567"); assertEquals(0, verify.size()); - checksum.setPropertyValue(SpdxConstants.PROP_CHECKSUM_ALGORITHM, null); + checksum.setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_ALGORITHM, null); assertEquals(1, checksum.verify().size()); for (Checksum cksum : TEST_CHECKSUMS) { assertEquals(0, cksum.verify().size()); @@ -121,7 +123,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Checksum#setAlgorithm(org.spdx.library.model.enumerations.ChecksumAlgorithm)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Checksum#setAlgorithm(org.spdx.library.model.compat.v2.compat.v2.enumerations.ChecksumAlgorithm)}. */ public void testSetAlgorithm() throws InvalidSPDXAnalysisException { Checksum[] checksumReferences = new Checksum[TEST_CHECKSUMS.length]; @@ -144,7 +146,7 @@ public void testSetAlgorithm() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Checksum#setValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Checksum#setValue(java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testSetValue() throws InvalidSPDXAnalysisException { @@ -168,7 +170,7 @@ public void testSetValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Checksum#toString()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Checksum#toString()}. * @throws InvalidSPDXAnalysisException */ public void testToString() throws InvalidSPDXAnalysisException { @@ -177,16 +179,16 @@ public void testToString() throws InvalidSPDXAnalysisException { assertTrue(TEST_CHECKSUMS[i].toString().contains(VALUES[i])); } Checksum checksum = gmo.createChecksum(ALGORITHMS[0], VALUES[0]); - checksum.setPropertyValue(SpdxConstants.PROP_CHECKSUM_ALGORITHM, null); + checksum.setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_ALGORITHM, null); assertTrue(checksum.toString().contains("EMPTY")); - checksum.setPropertyValue(SpdxConstants.PROP_CHECKSUM_VALUE, null); + checksum.setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_VALUE, null); assertTrue(checksum.toString().contains("EMPTY")); checksum.setAlgorithm(ALGORITHMS[0]); assertTrue(checksum.toString().contains("EMPTY")); } /** - * Test method for {@link org.spdx.library.model.Checksum#compareTo(org.spdx.library.model.Checksum)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Checksum#compareTo(org.spdx.library.model.compat.v2.compat.v2.Checksum)}. * @throws InvalidSPDXAnalysisException */ public void testCompareTo() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/ExternalDocumentRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java similarity index 83% rename from src/test/java/org/spdx/library/model/ExternalDocumentRefTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java index 0c524b7cb..c55d9b658 100644 --- a/src/test/java/org/spdx/library/model/ExternalDocumentRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java @@ -15,15 +15,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Optional; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; @@ -81,7 +86,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalDocumentRef#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalDocumentRef#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -95,7 +100,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalDocumentRef#setChecksum(org.spdx.library.model.Checksum)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalDocumentRef#setChecksum(org.spdx.library.model.compat.v2.compat.v2.Checksum)}. * @throws InvalidSPDXAnalysisException */ public void testSetChecksum() throws InvalidSPDXAnalysisException { @@ -115,7 +120,7 @@ public void testsetSpdxDocumentNamespace() throws InvalidSPDXAnalysisException { assertEquals(DOCUMENT_URI2, edf.getSpdxDocumentNamespace()); } /** - * Test method for {@link org.spdx.library.model.ExternalDocumentRef#setSpdxDocument(org.spdx.library.model.SpdxDocument)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalDocumentRef#setSpdxDocument(org.spdx.library.model.compat.v2.compat.v2.SpdxDocument)}. */ public void testSetSpdxDocument() throws InvalidSPDXAnalysisException { SpdxDocument doc1 = new SpdxDocument(gmo.getModelStore(), DOCUMENT_URI1, gmo.getCopyManager(), true); @@ -139,7 +144,7 @@ public void testSetSpdxDocument() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalDocumentRef#setExternalDocumentId(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalDocumentRef#setExternalDocumentId(java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testSetExternalDocumentId() throws InvalidSPDXAnalysisException { @@ -154,7 +159,7 @@ public void testSetExternalDocumentId() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalDocumentRef#compareTo(org.spdx.library.model.ExternalDocumentRef)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalDocumentRef#compareTo(org.spdx.library.model.compat.v2.compat.v2.ExternalDocumentRef)}. * @throws InvalidSPDXAnalysisException */ public void testCompareTo() throws InvalidSPDXAnalysisException { @@ -187,7 +192,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { public void testGetExternalDocRefByDocNamespace() throws InvalidSPDXAnalysisException { // need a document to tie the external refs to SpdxModelFactory.createModelObject(gmo.getModelStore(), gmo.getDocumentUri(), - SpdxConstants.SPDX_DOCUMENT_ID, SpdxConstants.CLASS_SPDX_DOCUMENT, gmo.getCopyManager()); + SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, gmo.getCopyManager()); // test empty Optional result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), DOCUMENT_URI1, null); @@ -196,7 +201,7 @@ public void testGetExternalDocRefByDocNamespace() throws InvalidSPDXAnalysisExce result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), DOCUMENT_URI1, gmo.getCopyManager()); assertTrue(result.isPresent()); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", result.get().getId()); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", result.get().getId()); // test non matching result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), DOCUMENT_URI2, null); @@ -205,16 +210,16 @@ public void testGetExternalDocRefByDocNamespace() throws InvalidSPDXAnalysisExce result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), DOCUMENT_URI2, gmo.getCopyManager()); assertTrue(result.isPresent()); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", result.get().getId()); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", result.get().getId()); // test match result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), DOCUMENT_URI1, null); assertTrue(result.isPresent()); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", result.get().getId()); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", result.get().getId()); result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), DOCUMENT_URI2, gmo.getCopyManager()); assertTrue(result.isPresent()); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", result.get().getId()); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", result.get().getId()); } } diff --git a/src/test/java/org/spdx/library/model/ExternalRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java similarity index 79% rename from src/test/java/org/spdx/library/model/ExternalRefTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java index a40b8a928..77e11fb6f 100644 --- a/src/test/java/org/spdx/library/model/ExternalRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.net.URI; import java.net.URISyntaxException; @@ -23,9 +23,11 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.referencetype.ListedReferenceTypes; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ExternalRef; +import org.spdx.library.model.compat.v2.ReferenceType; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.referencetype.compat.v2.ListedReferenceTypes; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -73,7 +75,7 @@ protected void setUp() throws Exception { for (int i = 0; i < REFERENCE_CATEGORIES.length; i++) { TEST_REFERENCES[i] = new ExternalRef(store, docUri, store.getNextId(IdType.Anonymous, docUri), copyManager, true); TEST_REFERENCES[i].setReferenceCategory(REFERENCE_CATEGORIES[i]); - TEST_REFERENCES[i].setReferenceType(new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[i])); + TEST_REFERENCES[i].setReferenceType(new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[i])); TEST_REFERENCES[i].setReferenceLocator(REFERENCE_LOCATORS[i]); TEST_REFERENCES[i].setComment(COMMENTS[i]); } @@ -87,7 +89,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.ExternalRef#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalRef#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -95,7 +97,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { assertEquals(0, TEST_REFERENCES[i].verify().size()); } ExternalRef noCategory = new ExternalRef(store, docUri, store.getNextId(IdType.Anonymous, docUri),copyManager, true); - noCategory.setReferenceType(new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0])); + noCategory.setReferenceType(new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0])); noCategory.setReferenceLocator(REFERENCE_LOCATORS[0]); noCategory.setComment(COMMENTS[0]); assertEquals(1, noCategory.verify().size()); @@ -106,18 +108,18 @@ public void testVerify() throws InvalidSPDXAnalysisException { assertEquals(1, noReferenceType.verify().size()); ExternalRef noRferenceLocator = new ExternalRef(store, docUri, store.getNextId(IdType.Anonymous, docUri),copyManager, true); noRferenceLocator.setReferenceCategory(REFERENCE_CATEGORIES[0]); - noRferenceLocator.setReferenceType(new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0])); + noRferenceLocator.setReferenceType(new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0])); noRferenceLocator.setComment(COMMENTS[0]); assertEquals(1, noRferenceLocator.verify().size()); ExternalRef noComment =new ExternalRef(store, docUri, store.getNextId(IdType.Anonymous, docUri),copyManager, true); noComment.setReferenceCategory(REFERENCE_CATEGORIES[0]); - noComment.setReferenceType(new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0])); + noComment.setReferenceType(new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0])); noComment.setReferenceLocator(REFERENCE_LOCATORS[0]); assertEquals(0, noComment.verify().size()); } /** - * Test method for {@link org.spdx.library.model.ExternalRef#compareTo(org.spdx.library.model.ExternalRef)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalRef#compareTo(org.spdx.library.model.compat.v2.compat.v2.ExternalRef)}. * @throws InvalidSPDXAnalysisException */ public void testCompareTo() throws InvalidSPDXAnalysisException { @@ -132,7 +134,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalRef#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalRef#setComment(java.lang.String)}. */ public void testSetComment() throws InvalidSPDXAnalysisException { String[] changedComments = new String[] { @@ -146,7 +148,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalRef#setReferenceCategory(org.spdx.library.model.enumerations.ReferenceCategory)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalRef#setReferenceCategory(org.spdx.library.model.compat.v2.compat.v2.enumerations.ReferenceCategory)}. */ public void testSetReferenceCategory() throws InvalidSPDXAnalysisException { ExternalRef er = new ExternalRef(store, docUri, store.getNextId(IdType.Anonymous, docUri),copyManager, true); @@ -164,14 +166,14 @@ public void testSetReferenceCategory() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ExternalRef#setReferenceType(org.spdx.library.model.ReferenceType)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalRef#setReferenceType(org.spdx.library.model.compat.v2.compat.v2.ReferenceType)}. * @throws URISyntaxException */ public void testSetReferenceType() throws InvalidSPDXAnalysisException, URISyntaxException { ReferenceType[] changedTypes = new ReferenceType[] { - new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[1]), - new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[2]), - new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0]) + new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[1]), + new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[2]), + new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[0]) }; for (int i = 0; i < TEST_REFERENCES.length; i++) { assertEquals(REFERENCE_TYPE_NAMES[i], ListedReferenceTypes.getListedReferenceTypes().getListedReferenceName(new URI(TEST_REFERENCES[i].getReferenceType().getIndividualURI()))); @@ -182,7 +184,7 @@ public void testSetReferenceType() throws InvalidSPDXAnalysisException, URISynta } /** - * Test method for {@link org.spdx.library.model.ExternalRef#setReferenceLocator(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ExternalRef#setReferenceLocator(java.lang.String)}. */ public void testSetReferenceLocator() throws InvalidSPDXAnalysisException { String[] changedLocators = new String[] { diff --git a/src/test/java/org/spdx/library/model/ExternalSpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java similarity index 84% rename from src/test/java/org/spdx/library/model/ExternalSpdxElementTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java index eb74d95a7..e73564a53 100644 --- a/src/test/java/org/spdx/library/model/ExternalSpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java @@ -1,30 +1,36 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Collection; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; public class ExternalSpdxElementTest extends TestCase { - static final String DOCID1 = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; - static final String SPDXID1 = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "SPDXID1"; + static final String DOCID1 = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; + static final String SPDXID1 = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "SPDXID1"; static final String DOCURI1 = "http://doc/uri/one"; static final String ID1 = DOCID1 + ":" + SPDXID1; - static final String DOCID2 = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; - static final String SPDXID2 = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "SPDXID2"; + static final String DOCID2 = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; + static final String SPDXID2 = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "SPDXID2"; static final String DOCURI2 = "http://doc/uri/two"; static final String ID2 = DOCID2 + ":" + SPDXID2; - static final String DOCID3 = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID3"; - static final String SPDXID3 = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "SPDXID3"; + static final String DOCID3 = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID3"; + static final String SPDXID3 = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "SPDXID3"; static final String DOCURI3 = "http://doc/uri/three"; static final String ID3 = DOCID3 + ":" + SPDXID3; diff --git a/src/test/java/org/spdx/library/model/IndividualUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java similarity index 72% rename from src/test/java/org/spdx/library/model/IndividualUriValueTest.java rename to src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java index 46354d435..bada5558e 100644 --- a/src/test/java/org/spdx/library/model/IndividualUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java @@ -1,12 +1,17 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.SimpleUriValue; +import org.spdx.library.model.compat.v2.SpdxNoAssertionElement; +import org.spdx.library.model.compat.v2.SpdxNoneElement; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -28,9 +33,9 @@ protected void tearDown() throws Exception { public void testEqualUriValueExternalExtractedLicenseInfo() throws InvalidSPDXAnalysisException { IModelStore modelStore = new InMemSpdxStore(); ModelCopyManager copyManager = new ModelCopyManager(); - String id = SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"ID"; + String id = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"ID"; String namespace = "http://example.namespace"; - String externalDocId = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "externalDoc"; + String externalDocId = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "externalDoc"; String externalDocNamespace = "http://example.external.namespace"; ExternalDocumentRef edr = new ExternalDocumentRef(modelStore, namespace, externalDocId, copyManager, true); edr.setChecksum(edr.createChecksum(ChecksumAlgorithm.SHA1, SHA1_CHECKSUM)); @@ -45,9 +50,9 @@ public void testEqualUriValueExternalExtractedLicenseInfo() throws InvalidSPDXAn public void testEqualUriValueExternalSpdxElement() throws InvalidSPDXAnalysisException { IModelStore modelStore = new InMemSpdxStore(); ModelCopyManager copyManager = new ModelCopyManager(); - String id = SpdxConstants.SPDX_ELEMENT_REF_PRENUM+"ID"; + String id = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"ID"; String namespace = "http://example.namespace"; - String externalDocId = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "externalDoc"; + String externalDocId = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "externalDoc"; String externalDocNamespace = "http://example.external.namespace"; ExternalDocumentRef edr = new ExternalDocumentRef(modelStore, namespace, externalDocId, copyManager, true); edr.setChecksum(edr.createChecksum(ChecksumAlgorithm.SHA1, SHA1_CHECKSUM)); @@ -61,7 +66,7 @@ public void testEqualUriValueExternalSpdxElement() throws InvalidSPDXAnalysisExc // Test if a simple URI value is equal to the NoAssertionLicense with the same URI value public void testEqualUriValueNoAssertionLicense() throws InvalidSPDXAnalysisException { SpdxNoAssertionLicense nal = new SpdxNoAssertionLicense(); - SimpleUriValue suv = new SimpleUriValue(SpdxConstants.URI_VALUE_NOASSERTION); + SimpleUriValue suv = new SimpleUriValue(SpdxConstantsCompatV2.URI_VALUE_NOASSERTION); assertTrue(nal.equals(suv)); assertTrue(suv.equals(nal)); } @@ -69,7 +74,7 @@ public void testEqualUriValueNoAssertionLicense() throws InvalidSPDXAnalysisExce // Test if a simple URI value is equal to the NoneLicense with the same URI value public void testEqualUriValueNoneLicense() throws InvalidSPDXAnalysisException { SpdxNoneLicense nl = new SpdxNoneLicense(); - SimpleUriValue suv = new SimpleUriValue(SpdxConstants.URI_VALUE_NONE); + SimpleUriValue suv = new SimpleUriValue(SpdxConstantsCompatV2.URI_VALUE_NONE); assertTrue(nl.equals(suv)); assertTrue(suv.equals(nl)); } @@ -77,7 +82,7 @@ public void testEqualUriValueNoneLicense() throws InvalidSPDXAnalysisException { // Test if a simple URI value is equal to the SpdxNoneElement with the same URI value public void testEqualUriValueNone() throws InvalidSPDXAnalysisException { SpdxNoneElement ne = new SpdxNoneElement(); - SimpleUriValue suv = new SimpleUriValue(SpdxConstants.URI_VALUE_NONE); + SimpleUriValue suv = new SimpleUriValue(SpdxConstantsCompatV2.URI_VALUE_NONE); assertTrue(ne.equals(suv)); assertTrue(suv.equals(ne)); } @@ -85,7 +90,7 @@ public void testEqualUriValueNone() throws InvalidSPDXAnalysisException { // Test if a simple URI value is equal to the SpdxNoAssertionElement with the same URI value public void testEqualUriValueNoAssertion() throws InvalidSPDXAnalysisException { SpdxNoAssertionElement na = new SpdxNoAssertionElement(); - SimpleUriValue suv = new SimpleUriValue(SpdxConstants.URI_VALUE_NOASSERTION); + SimpleUriValue suv = new SimpleUriValue(SpdxConstantsCompatV2.URI_VALUE_NOASSERTION); assertTrue(na.equals(suv)); assertTrue(suv.equals(na)); } diff --git a/src/test/java/org/spdx/library/model/LineCharPointerTest.java b/src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java similarity index 84% rename from src/test/java/org/spdx/library/model/LineCharPointerTest.java rename to src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java index 13f61e16d..db5f45dbe 100644 --- a/src/test/java/org/spdx/library/model/LineCharPointerTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java @@ -15,14 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.List; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import junit.framework.TestCase; @@ -59,7 +62,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.pointer.LineCharPointer#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.LineCharPointer#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -80,7 +83,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.pointer.LineCharPointer#setLineNumber(java.lang.Integer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.LineCharPointer#setLineNumber(java.lang.Integer)}. * @throws InvalidSPDXAnalysisException */ public void testSetLineNumber() throws InvalidSPDXAnalysisException { @@ -104,7 +107,7 @@ public void testSetReference() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.pointer.LineCharPointer#compareTo(org.spdx.library.model.SinglePointer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.LineCharPointer#compareTo(org.spdx.library.model.compat.v2.compat.v2.SinglePointer)}. * @throws InvalidSPDXAnalysisException */ public void testCompareTo() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java similarity index 95% rename from src/test/java/org/spdx/library/model/ModelCollectionTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java index b60015ec4..073720ea8 100644 --- a/src/test/java/org/spdx/library/model/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java @@ -1,4 +1,4 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Arrays; @@ -6,14 +6,16 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.ModelCollection; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; public class ModelCollectionTest extends TestCase { - static final PropertyDescriptor PROPERTY_NAME = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + static final PropertyDescriptor PROPERTY_NAME = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); static final String[] ELEMENTS = new String[] {"e1", "e2", "e3", "e4"}; GenericModelObject gmo; diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java similarity index 81% rename from src/test/java/org/spdx/library/model/ModelObjectTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index eed88403d..30a741ad7 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import static org.junit.Assert.assertThrows; @@ -31,17 +31,29 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.LicenseException; -import org.spdx.library.model.license.SimpleLicensingInfo; -import org.spdx.library.model.license.SpdxListedLicense; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.ModelCollection; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.ModelStorageClassConverter; +import org.spdx.library.model.compat.v2.SimpleUriValue; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.LicenseException; +import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.ModelUpdate; @@ -58,46 +70,46 @@ public class ModelObjectTest extends TestCase { private static final String TEST_ID = "testId"; private static final Object TEST_VALUE1 = "value1"; - private static final PropertyDescriptor TEST_PROPERTY1 = new PropertyDescriptor("property1", SpdxConstants.SPDX_NAMESPACE); - private static final PropertyDescriptor TEST_PROPERTY2 = new PropertyDescriptor("property2", SpdxConstants.SPDX_NAMESPACE); - static final String TEST_TYPE1 = SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION; - static final String TEST_TYPE2 = SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO; + private static final PropertyDescriptor TEST_PROPERTY1 = new PropertyDescriptor("property1", SpdxConstantsCompatV2.SPDX_NAMESPACE); + private static final PropertyDescriptor TEST_PROPERTY2 = new PropertyDescriptor("property2", SpdxConstantsCompatV2.SPDX_NAMESPACE); + static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION; + static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO; static final PropertyDescriptor[] TEST_STRING_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("valueProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp3", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("valueProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final Object[] TEST_STRING_VALUE_PROPERTY_VALUES = new Object[] {"value1", "value2", "value3"}; static final PropertyDescriptor[] TEST_INTEGER_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("intProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("intProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("Intprop3", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("intProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("intProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("Intprop3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final Object[] TEST_INTEGER_VALUE_PROPERTY_VALUES = new Object[] {Integer.valueOf(3), Integer.valueOf(0), Integer.valueOf(-1)}; static final PropertyDescriptor[] TEST_BOOLEAN_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("boolProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("boolProp2", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("boolProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("boolProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final Object[] TEST_BOOLEAN_VALUE_PROPERTY_VALUES = new Object[] {true, false}; static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("listProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp3", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp4", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp5", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("listProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp4", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp5", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final PropertyDescriptor[] TEST_MODEL_OJBECT_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("typeProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("typeProp2", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("typeProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("typeProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final PropertyDescriptor[] TEST_ENUM_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("enumProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("enumProp2", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("enumProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("enumProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final ChecksumAlgorithm[] TEST_ENUM_VALUES = new ChecksumAlgorithm[] {ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1}; static final PropertyDescriptor[] TEST_ANYLICENSEINFO_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("anylicenseProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("anylicenseProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("anylicenseProp3", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("anylicenseProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("anylicenseProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("anylicenseProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final PropertyDescriptor[] TEST_ANYLICENSEINFO_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("anylicenseListProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("anylicensListProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("anylicenseListProp3", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("anylicenseListProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("anylicensListProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("anylicenseListProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; ModelObject[] TEST_MODEL_OBJECT_PROP_VALUES; List[] TEST_LIST_PROPERTY_VALUES; @@ -259,7 +271,7 @@ public void testModelObjectCreate() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getDocumentUri()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getDocumentUri()}. * @throws InvalidSPDXAnalysisException */ public void testGetDocumentUri() throws InvalidSPDXAnalysisException { @@ -268,7 +280,7 @@ public void testGetDocumentUri() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getId()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getId()}. * @throws InvalidSPDXAnalysisException */ public void testGetId() throws InvalidSPDXAnalysisException { @@ -277,7 +289,7 @@ public void testGetId() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getModelStore()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getModelStore()}. */ public void testGetModelStore() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); @@ -286,7 +298,7 @@ public void testGetModelStore() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getPropertyValueDescriptors()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getPropertyValueDescriptors()}. */ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -301,7 +313,7 @@ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getObjectPropertyValue(java.lang.String)}. */ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -324,11 +336,11 @@ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { /** - * Test method for {@link org.spdx.library.model.ModelObject#setPropertyValue(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#setPropertyValue(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. */ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); gmo.setPropertyValue(prop, val); @@ -337,11 +349,11 @@ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#updatePropertyValue(java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updatePropertyValue(java.lang.String, java.lang.Object)}. */ public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); ModelUpdate mu = gmo.updatePropertyValue(prop, val); @@ -352,7 +364,7 @@ public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getStringPropertyValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getStringPropertyValue(java.lang.String)}. */ public void testGetStringPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -383,7 +395,7 @@ public void testGetIntegerPropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getBooleanPropertyValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getBooleanPropertyValue(java.lang.String)}. */ public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -400,11 +412,11 @@ public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#removeProperty(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#removeProperty(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. */ public void testRemovePropertyIModelStoreStringStringString() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); gmo.setPropertyValue(prop, val); @@ -415,11 +427,11 @@ public void testRemovePropertyIModelStoreStringStringString() throws InvalidSPDX } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateRemoveProperty(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateRemoveProperty(java.lang.String)}. */ public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); - PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); String val = "value"; assertFalse(gmo.getObjectPropertyValue(prop).isPresent()); gmo.setPropertyValue(prop, val); @@ -433,7 +445,7 @@ public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#clearValueCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#clearValueCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. */ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -446,7 +458,7 @@ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateClearValueCollection(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateClearValueCollection(java.lang.String)}. */ public void testUpdateClearPropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -463,7 +475,7 @@ public void testUpdateClearPropertyValueList() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.ModelObject#addValueToCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#addValueToCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. */ public void testAddPropertyValueToList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -481,7 +493,7 @@ public void testAddPropertyValueToList() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateAddPropertyValueToCollection(java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateAddPropertyValueToCollection(java.lang.String, java.lang.Object)}. */ public void testUpdateAddPropertyValueToList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -501,7 +513,7 @@ public void testUpdateAddPropertyValueToList() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.ModelObject#replacePropertyValueList(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.util.List)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#replacePropertyValueList(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.util.List)}. */ public void testReplacePropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -518,7 +530,7 @@ public void testReplacePropertyValueList() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateReplacePropertyValueList(java.lang.String, java.util.List)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateReplacePropertyValueList(java.lang.String, java.util.List)}. */ public void testUpdateReplacePropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -535,7 +547,7 @@ public void testUpdateReplacePropertyValueList() throws InvalidSPDXAnalysisExcep } /** - * Test method for {@link org.spdx.library.model.ModelObject#removePropertyValueFromCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#removePropertyValueFromCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. */ public void testRemovePropertyValueFromList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -553,7 +565,7 @@ public void testRemovePropertyValueFromList() throws InvalidSPDXAnalysisExceptio } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateRemovePropertyValueFromCollection(java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateRemovePropertyValueFromCollection(java.lang.String, java.lang.Object)}. */ public void testUpdateRemovePropertyValueFromList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -573,7 +585,7 @@ public void testUpdateRemovePropertyValueFromList() throws InvalidSPDXAnalysisEx } /** - * Test method for {@link org.spdx.library.model.ModelObject#getStringPropertyValueList(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getStringPropertyValueList(java.lang.String)}. */ public void testGetStringPropertyValueCollection() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -589,7 +601,7 @@ public void testGetStringPropertyValueCollection() throws InvalidSPDXAnalysisExc } /** - * Test method for {@link org.spdx.library.model.ModelObject#equivalent(org.spdx.library.model.ModelObject)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject)}. */ public void testEquivalent() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -654,7 +666,7 @@ public void testEquivalentIgnoresNoAssertion() throws InvalidSPDXAnalysisExcepti GenericModelObject firstObject = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); GenericModelObject secondObject = new GenericModelObject(store, docUri, "testId2", copyManager, true); firstObject.setPropertyValue(TEST_PROPERTY1, new SpdxNoAssertionLicense()); - secondObject.setPropertyValue(TEST_PROPERTY2, SpdxConstants.NOASSERTION_VALUE); + secondObject.setPropertyValue(TEST_PROPERTY2, SpdxConstantsCompatV2.NOASSERTION_VALUE); // Then assertTrue(firstObject.equivalent(secondObject)); @@ -665,7 +677,7 @@ public void testEquivalentModelObjectProp() throws InvalidSPDXAnalysisException String id1 = "id1"; String id2 = "id2"; String text = "licenseText"; - PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); ExtractedLicenseInfo eli = new ExtractedLicenseInfo(id1, text); ExtractedLicenseInfo eli2 = new ExtractedLicenseInfo(id2, text); assertTrue(eli.equivalent(eli2)); @@ -689,7 +701,7 @@ public void testEquivalentModelObjectList() throws InvalidSPDXAnalysisException String id1 = "id1"; String id2 = "id2"; String text = "licenseText"; - PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor prop = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); ExtractedLicenseInfo eli = new ExtractedLicenseInfo(id1, text); ExtractedLicenseInfo eli2 = new ExtractedLicenseInfo(id2, text); String id3 = "id3"; @@ -725,7 +737,7 @@ public void testEquivalentModelObjectList() throws InvalidSPDXAnalysisException public void testListEquivalenceIsSymmetric() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); GenericModelObject gmo2 = new GenericModelObject(store, docUri, "TestId2", copyManager, true); - PropertyDescriptor property = new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor property = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); ExtractedLicenseInfo equivalentLicense = new ExtractedLicenseInfo("id", "licenseText"); ExtractedLicenseInfo equivalentLicense2 = new ExtractedLicenseInfo("id2", "licenseText"); ExtractedLicenseInfo equivalentLicense3 = new ExtractedLicenseInfo("id3", "licenseText"); @@ -741,7 +753,7 @@ public void testListEquivalenceIsSymmetric() throws InvalidSPDXAnalysisException } /** - * Test method for {@link org.spdx.library.model.ModelObject#equals(java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#equals(java.lang.Object)}. */ public void testEqualsObject() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -761,7 +773,7 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#clone()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#clone()}. */ public void testClone() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -775,7 +787,7 @@ public void testClone() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#copyFrom(org.spdx.library.model.ModelObject)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#copyFrom(org.spdx.library.model.compat.v2.compat.v2.ModelObject)}. */ public void testCopyFrom() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -792,21 +804,21 @@ public void testCopyFrom() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#idToIdType(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#idToIdType(java.lang.String)}. */ public void testIdToIdType() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); assertEquals(IdType.Anonymous, gmo.idToIdType("anything")); - assertEquals(IdType.DocumentRef, gmo.idToIdType(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "12")); - assertEquals(IdType.LicenseRef, gmo.idToIdType(SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "12")); + assertEquals(IdType.DocumentRef, gmo.idToIdType(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "12")); + assertEquals(IdType.LicenseRef, gmo.idToIdType(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "12")); assertEquals(IdType.ListedLicense, gmo.idToIdType("Apache-2.0")); - assertEquals(IdType.Literal, gmo.idToIdType(SpdxConstants.NONE_VALUE)); - assertEquals(IdType.Literal, gmo.idToIdType(SpdxConstants.NOASSERTION_VALUE)); - assertEquals(IdType.SpdxId, gmo.idToIdType(SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "12")); + assertEquals(IdType.Literal, gmo.idToIdType(SpdxConstantsCompatV2.NONE_VALUE)); + assertEquals(IdType.Literal, gmo.idToIdType(SpdxConstantsCompatV2.NOASSERTION_VALUE)); + assertEquals(IdType.SpdxId, gmo.idToIdType(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "12")); } /** - * Test method for {@link org.spdx.library.model.ModelObject#toTypedValue()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#toTypedValue()}. */ public void testToTypeValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -831,7 +843,7 @@ public void testGetObjectValueIndividualValue() throws InvalidSPDXAnalysisExcep Enum TEST_ENUM = RelationshipType.DESCRIBES; String ENUM_URI = RelationshipType.DESCRIBES.getIndividualURI(); String EXTERNAL_DOC_NAMSPACE = "https://test/namespace1"; - String EXTERNAL_SPDX_ELEMENT_ID = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "TEST"; + String EXTERNAL_SPDX_ELEMENT_ID = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "TEST"; String EXTERNAL_SPDX_URI = EXTERNAL_DOC_NAMSPACE + "#" + EXTERNAL_SPDX_ELEMENT_ID; String NON_INTERESTING_URI = "https://nothing/to/see/here"; diff --git a/src/test/java/org/spdx/library/model/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java similarity index 84% rename from src/test/java/org/spdx/library/model/ModelStorageClassConverterTest.java rename to src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index d419efa6b..aa0c16a38 100644 --- a/src/test/java/org/spdx/library/model/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -1,4 +1,4 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -8,11 +8,21 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.ExternalExtractedLicenseInfo; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxItem; +import org.spdx.library.model.compat.v2.ModelStorageClassConverter; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SimpleUriValue; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -35,7 +45,7 @@ protected void tearDown() throws Exception { public void testStoredObjectToModelObject() throws InvalidSPDXAnalysisException { // TypedValue - TypedValue tv = new TypedValue("SPDXRef-10", SpdxConstants.CLASS_ANNOTATION); + TypedValue tv = new TypedValue("SPDXRef-10", SpdxConstantsCompatV2.CLASS_ANNOTATION); Object result = ModelStorageClassConverter.storedObjectToModelObject(tv, gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result instanceof Annotation); @@ -51,7 +61,7 @@ public void testStoredObjectToModelObject() throws InvalidSPDXAnalysisException Checksum checksum = gmo.createChecksum(ChecksumAlgorithm.SHA1, "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"); gmo.createExternalDocumentRef(gmo.getModelStore().getNextId(IdType.DocumentRef, gmo.getDocumentUri()), externalDocUri, checksum); - String externalDocElementId = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "11"; + String externalDocElementId = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "11"; String externalRefUri = externalDocUri + "#" + externalDocElementId; suv = new SimpleUriValue(externalRefUri); result = ModelStorageClassConverter.storedObjectToModelObject(suv, gmo.getDocumentUri(), @@ -60,7 +70,7 @@ public void testStoredObjectToModelObject() throws InvalidSPDXAnalysisException ExternalSpdxElement external = (ExternalSpdxElement)result; assertTrue(external.getId().contains(externalDocElementId)); // ExternalLicenseRef - String externalLicenseRefId = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "525"; + String externalLicenseRefId = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "525"; String externalLicenseRefUri = externalDocUri + "#" + externalLicenseRefId; suv = new SimpleUriValue(externalLicenseRefUri); result = ModelStorageClassConverter.storedObjectToModelObject(suv, gmo.getDocumentUri(), @@ -83,7 +93,7 @@ public void testStoredObjectToModelObject() throws InvalidSPDXAnalysisException public void testOptionalStoredObjectToModelObject() throws InvalidSPDXAnalysisException { // TypedValue - TypedValue tv = new TypedValue("SPDXRef-10", SpdxConstants.CLASS_ANNOTATION); + TypedValue tv = new TypedValue("SPDXRef-10", SpdxConstantsCompatV2.CLASS_ANNOTATION); Optional result = ModelStorageClassConverter.optionalStoredObjectToModelObject(Optional.of(tv), gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result.isPresent()); assertTrue(result.get() instanceof Annotation); @@ -99,7 +109,7 @@ public void testOptionalStoredObjectToModelObject() throws InvalidSPDXAnalysisEx Checksum checksum = gmo.createChecksum(ChecksumAlgorithm.SHA1, "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"); gmo.createExternalDocumentRef(gmo.getModelStore().getNextId(IdType.DocumentRef, gmo.getDocumentUri()), externalDocUri, checksum); - String externalDocElementId = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "11"; + String externalDocElementId = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "11"; String externalRefUri = externalDocUri + "#" + externalDocElementId; suv = new SimpleUriValue(externalRefUri); result = ModelStorageClassConverter.optionalStoredObjectToModelObject(Optional.of(suv), gmo.getDocumentUri(), @@ -153,13 +163,13 @@ public void testCopyIModelStoreStringIModelStoreStringStringString() throws Inva String id1 = "ID1"; String id2 = "ID2"; GenericSpdxItem element1 = new GenericSpdxItem(store1, docUri1, id1, copyManager, true); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String date = format.format(new Date()); Annotation annotation = element1.createAnnotation("Person: Annotator", AnnotationType.REVIEW, date, "Annotation Comment"); element1.addAnnotation(annotation); - String externalUri = "http://doc3/uri#" + SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "23"; + String externalUri = "http://doc3/uri#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "23"; ExternalSpdxElement externalElement = ExternalSpdxElement.uriToExternalSpdxElement(externalUri, store1, docUri1, copyManager); - String externalLicenseUri = "http://doc3/uri#" + SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "55"; + String externalLicenseUri = "http://doc3/uri#" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "55"; Relationship relationship = element1.createRelationship(externalElement, RelationshipType.BUILD_TOOL_OF, "relationshipComment"); element1.addRelationship(relationship); ExternalExtractedLicenseInfo externalLicense = ExternalExtractedLicenseInfo.uriToExternalExtractedLicense(externalLicenseUri, store1, docUri1, copyManager); diff --git a/src/test/java/org/spdx/library/model/NoAssertionElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/NoAssertionElementTest.java rename to src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java index 51975d801..44068a74c 100644 --- a/src/test/java/org/spdx/library/model/NoAssertionElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java @@ -15,11 +15,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxNoAssertionElement; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/RelatedElementCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java similarity index 88% rename from src/test/java/org/spdx/library/model/RelatedElementCollectionTest.java rename to src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java index 3f794bc3d..2989f6527 100644 --- a/src/test/java/org/spdx/library/model/RelatedElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Arrays; @@ -24,7 +24,12 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.RelatedElementCollection; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; + import junit.framework.TestCase; /** @@ -99,7 +104,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#toImmutableList()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#toImmutableList()}. * @throws InvalidSPDXAnalysisException */ public void testToImmutableList() throws InvalidSPDXAnalysisException { @@ -121,7 +126,7 @@ private void assertListsSame(List l1, List l2) { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#size()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#size()}. */ public void testSize() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -135,7 +140,7 @@ public void testSize() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#isEmpty()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#isEmpty()}. */ public void testIsEmpty() throws InvalidSPDXAnalysisException { SpdxElement ge = new GenericSpdxElement(); @@ -149,7 +154,7 @@ public void testIsEmpty() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#contains(java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#contains(java.lang.Object)}. */ public void testContains() throws InvalidSPDXAnalysisException { SpdxElement ge = new GenericSpdxElement(); @@ -163,7 +168,7 @@ public void testContains() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#iterator()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#iterator()}. */ public void testIterator() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -189,7 +194,7 @@ public void testIterator() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#toArray()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#toArray()}. */ public void testToArray() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -222,7 +227,7 @@ private boolean ArraysSameDifferentOrder(Object[] a1, Object[] a2) { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#add(org.spdx.library.model.SpdxElement)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#add(org.spdx.library.model.compat.v2.compat.v2.SpdxElement)}. */ public void testAdd() throws InvalidSPDXAnalysisException { SpdxElement ge = new GenericSpdxElement(); @@ -237,7 +242,7 @@ public void testAdd() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#remove(java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#remove(java.lang.Object)}. */ public void testRemove() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -257,7 +262,7 @@ public void testRemove() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#containsAll(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#containsAll(java.util.Collection)}. */ public void testContainsAll() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -271,7 +276,7 @@ public void testContainsAll() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#addAll(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#addAll(java.util.Collection)}. */ public void testAddAll() throws InvalidSPDXAnalysisException { RelatedElementCollection describeGe = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -292,7 +297,7 @@ public void testAddAll() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#removeAll(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#removeAll(java.util.Collection)}. */ public void testRemoveAll() throws InvalidSPDXAnalysisException { RelatedElementCollection describeGe = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -313,7 +318,7 @@ public void testRemoveAll() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#retainAll(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#retainAll(java.util.Collection)}. */ public void testRetainAll() throws InvalidSPDXAnalysisException { RelatedElementCollection describeGe = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -335,7 +340,7 @@ public void testRetainAll() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#clear()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#clear()}. */ public void testClear() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection = new RelatedElementCollection(element, RelationshipType.DESCRIBES); @@ -350,7 +355,7 @@ public void testClear() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.RelatedElementCollection#equals(java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.RelatedElementCollection#equals(java.lang.Object)}. */ public void testEqualsObject() throws InvalidSPDXAnalysisException { RelatedElementCollection describesCollection1 = new RelatedElementCollection(element, RelationshipType.DESCRIBES); diff --git a/src/test/java/org/spdx/library/model/RelationshipTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/RelationshipTest.java rename to src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java index 4237624cb..bb4b3b9a1 100644 --- a/src/test/java/org/spdx/library/model/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.SimpleDateFormat; @@ -27,15 +27,27 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.LicenseInfoFactory; -import org.spdx.library.model.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -54,7 +66,7 @@ public class RelationshipTest extends TestCase { static final String ELEMENT_COMMENT1 = "comment1"; static final String ELEMENT_COMMENT2 = "comment2"; - static final String DATE_NOW = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT).format(new Date()); + static final String DATE_NOW = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); Annotation ANNOTATION1; Annotation ANNOTATION2; SpdxElement RELATED_ELEMENT1; @@ -92,7 +104,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.Relationship#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Relationship#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -109,7 +121,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Relationship#setRelationshipType(org.spdx.library.model.enumerations.RelationshipType)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Relationship#setRelationshipType(org.spdx.library.model.compat.v2.compat.v2.enumerations.RelationshipType)}. * @throws InvalidSPDXAnalysisException */ public void testSetRelationshipType() throws InvalidSPDXAnalysisException { @@ -125,7 +137,7 @@ public void testSetRelationshipType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Relationship#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Relationship#setComment(java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testSetComment() throws InvalidSPDXAnalysisException { @@ -141,7 +153,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Relationship#setRelatedSpdxElement(org.spdx.library.model.SpdxElement)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Relationship#setRelatedSpdxElement(org.spdx.library.model.compat.v2.compat.v2.SpdxElement)}. * @throws InvalidSPDXAnalysisException */ public void testSetRelatedSpdxElement() throws InvalidSPDXAnalysisException { @@ -188,7 +200,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.Relationship#compareTo(org.spdx.library.model.Relationship)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.Relationship#compareTo(org.spdx.library.model.compat.v2.compat.v2.Relationship)}. * @throws InvalidSPDXAnalysisException */ public void testCompareTo() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java similarity index 78% rename from src/test/java/org/spdx/library/model/SimpleUriValueTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java index 86a01c72a..3837e561f 100644 --- a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java @@ -15,12 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.ExternalSpdxElement; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.IndividualUriValue; +import org.spdx.library.model.compat.v2.SimpleUriValue; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import junit.framework.TestCase; @@ -34,7 +39,7 @@ public class SimpleUriValueTest extends TestCase { static final String ENUM_URI = RelationshipType.DESCRIBES.getIndividualURI(); static final String EXTERNAL_DOC_NAMSPACE = "https://test/namespace1"; - static final String EXTERNAL_SPDX_ELEMENT_ID = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "TEST"; + static final String EXTERNAL_SPDX_ELEMENT_ID = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "TEST"; static final String EXTERNAL_SPDX_URI = EXTERNAL_DOC_NAMSPACE + "#" + EXTERNAL_SPDX_ELEMENT_ID; static final String NON_INTERESTING_URI = "https://nothing/to/see/here"; @@ -54,7 +59,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.SimpleUriValue#SimpleUriValue(org.spdx.library.model.IndividualUriValue)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SimpleUriValue#SimpleUriValue(org.spdx.library.model.compat.v2.compat.v2.IndividualUriValue)}. * @throws InvalidSPDXAnalysisException */ public void testSimpleUriValueIndividualValue() throws InvalidSPDXAnalysisException { @@ -73,7 +78,7 @@ public String getIndividualURI() { } /** - * Test method for {@link org.spdx.library.model.SimpleUriValue#toModelObject(org.spdx.storage.IModelStore, java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SimpleUriValue#toModelObject(org.spdx.storage.IModelStore, java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testToModelObject() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/SpdxConstantElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java similarity index 66% rename from src/test/java/org/spdx/library/model/SpdxConstantElementTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java index f3c250176..022fb18de 100644 --- a/src/test/java/org/spdx/library/model/SpdxConstantElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java @@ -15,11 +15,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxConstantElement; +import org.spdx.library.model.compat.v2.SpdxNoAssertionElement; +import org.spdx.library.model.compat.v2.SpdxNoneElement; import junit.framework.TestCase; @@ -44,7 +49,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#_verify(java.util.List)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#_verify(java.util.List)}. * @throws InvalidSPDXAnalysisException */ public void test_verify() throws InvalidSPDXAnalysisException { @@ -52,14 +57,14 @@ public void test_verify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#getAnnotations()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#getAnnotations()}. */ public void testGetAnnotations() throws InvalidSPDXAnalysisException { assertEquals(0, new SpdxNoneElement().getAnnotations().size()); } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#setAnnotations(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#setAnnotations(java.util.Collection)}. */ public void testSetAnnotations() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -72,7 +77,7 @@ public void testSetAnnotations() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#addAnnotation(org.spdx.library.model.Annotation)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#addAnnotation(org.spdx.library.model.compat.v2.compat.v2.Annotation)}. */ public void testAddAnnotation() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -85,7 +90,7 @@ public void testAddAnnotation() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#removeAnnotation(org.spdx.library.model.Annotation)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#removeAnnotation(org.spdx.library.model.compat.v2.compat.v2.Annotation)}. */ public void testRemoveAnnotation() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -98,14 +103,14 @@ public void testRemoveAnnotation() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#getRelationships()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#getRelationships()}. */ public void testGetRelationships() throws InvalidSPDXAnalysisException { assertEquals(0, new SpdxNoneElement().getRelationships().size()); } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#setRelationships(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#setRelationships(java.util.Collection)}. */ public void testSetRelationships() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -118,7 +123,7 @@ public void testSetRelationships() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#addRelationship(org.spdx.library.model.Relationship)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#addRelationship(org.spdx.library.model.compat.v2.compat.v2.Relationship)}. */ public void testAddRelationship() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -131,7 +136,7 @@ public void testAddRelationship() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#removeRelationship(org.spdx.library.model.Relationship)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#removeRelationship(org.spdx.library.model.compat.v2.compat.v2.Relationship)}. */ public void testRemoveRelationship() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -144,7 +149,7 @@ public void testRemoveRelationship() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#setComment(java.lang.String)}. */ public void testSetComment() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -157,7 +162,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxConstantElement#setName(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxConstantElement#setName(java.lang.String)}. */ public void testSetName() throws InvalidSPDXAnalysisException { SpdxConstantElement c = new SpdxNoneElement(); @@ -170,14 +175,14 @@ public void testSetName() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#getComment()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#getComment()}. */ public void testGetComment() throws InvalidSPDXAnalysisException { assertTrue(new SpdxNoAssertionElement().getComment().isPresent()); } /** - * Test method for {@link org.spdx.library.model.SpdxElement#getName()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#getName()}. */ public void testGetName() throws InvalidSPDXAnalysisException { assertTrue(new SpdxNoAssertionElement().getName().isPresent()); diff --git a/src/test/java/org/spdx/library/model/SpdxCreatorInformationTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/SpdxCreatorInformationTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java index 14cf87f6d..337623209 100644 --- a/src/test/java/org/spdx/library/model/SpdxCreatorInformationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java @@ -1,4 +1,4 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -10,7 +10,9 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.SpdxCreatorInformation; import junit.framework.TestCase; @@ -32,7 +34,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { SpdxCreatorInformation ci = new SpdxCreatorInformation(); ci.setStrict(false); assertEquals(2, ci.verify().size()); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String date = format.format(new Date()); ci.setCreated(date); assertEquals(1, ci.verify().size()); @@ -53,7 +55,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { public void testGetSetCreators() throws InvalidSPDXAnalysisException { List creators = new ArrayList<>(Arrays.asList(new String[] {"Person: me"})); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String date = format.format(new Date()); SpdxCreatorInformation ci = gmo.createCreationInfo(creators, date); assertEquals(0, ci.verify().size()); @@ -71,7 +73,7 @@ public void testGetSetCreators() throws InvalidSPDXAnalysisException { public void testGetSetLicenseListVersion() throws InvalidSPDXAnalysisException { List creators = new ArrayList<>(Arrays.asList(new String[] {"Person: me"})); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String date = format.format(new Date()); SpdxCreatorInformation ci = gmo.createCreationInfo(creators, date); assertEquals(0, ci.verify().size()); @@ -84,7 +86,7 @@ public void testGetSetLicenseListVersion() throws InvalidSPDXAnalysisException { public void testGetSetComment() throws InvalidSPDXAnalysisException { List creators = new ArrayList<>(Arrays.asList(new String[] {"Person: me"})); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String date = format.format(new Date()); SpdxCreatorInformation ci = gmo.createCreationInfo(creators, date); assertEquals(0, ci.verify().size()); @@ -97,7 +99,7 @@ public void testGetSetComment() throws InvalidSPDXAnalysisException { public void testGetSetCreated() throws InvalidSPDXAnalysisException { List creators = new ArrayList<>(Arrays.asList(new String[] {"Person: me"})); - DateFormat format = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); String date = format.format(new Date()); SpdxCreatorInformation ci = gmo.createCreationInfo(creators, date); assertEquals(0, ci.verify().size()); diff --git a/src/test/java/org/spdx/library/model/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java similarity index 92% rename from src/test/java/org/spdx/library/model/SpdxDocumentTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index 86c75193b..dfe0322fe 100644 --- a/src/test/java/org/spdx/library/model/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.ArrayList; import java.util.Arrays; @@ -28,15 +28,28 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.LicenseInfoFactory; -import org.spdx.library.model.license.SimpleLicensingInfo; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxCreatorInformation; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -332,7 +345,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -382,7 +395,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#getDocumentDescribes()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#getDocumentDescribes()}. */ public void testGetDocumentDescribes() throws InvalidSPDXAnalysisException { SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true); @@ -426,7 +439,7 @@ public void testGetDocumentDescribes() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#setCreationInfo(org.spdx.library.model.SpdxCreatorInformation)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#setCreationInfo(org.spdx.library.model.compat.v2.compat.v2.SpdxCreatorInformation)}. */ public void testSetCreationInfo() throws InvalidSPDXAnalysisException { SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true); @@ -462,7 +475,7 @@ public void testSetCreationInfo() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#setDataLicense(org.spdx.library.model.license.AnyLicenseInfo)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#setDataLicense(org.spdx.library.model.compat.v2.compat.v2.license.AnyLicenseInfo)}. */ public void testSetDataLicense() throws InvalidSPDXAnalysisException { SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true); @@ -500,7 +513,7 @@ public void testSetDataLicense() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#getExternalDocumentRefs()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#getExternalDocumentRefs()}. */ public void testGetExternalDocumentRefs() throws InvalidSPDXAnalysisException { SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true); @@ -539,7 +552,7 @@ public void testGetExternalDocumentRefs() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#getExtractedLicenseInfos()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#getExtractedLicenseInfos()}. */ public void testGetExtractedLicenseInfos() throws InvalidSPDXAnalysisException { SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true); @@ -618,7 +631,7 @@ public void testAddExtractedLicenseInfos() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxDocument#setSpecVersion(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxDocument#setSpecVersion(java.lang.String)}. */ public void testSetSpecVersion() throws InvalidSPDXAnalysisException { SpdxDocument doc = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), gmo.getCopyManager(), true); diff --git a/src/test/java/org/spdx/library/model/SpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java similarity index 90% rename from src/test/java/org/spdx/library/model/SpdxElementTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java index 4fd451d4f..210f7fe04 100644 --- a/src/test/java/org/spdx/library/model/SpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.SimpleDateFormat; @@ -24,9 +24,14 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; @@ -43,7 +48,7 @@ public class SpdxElementTest extends TestCase { static final String ELEMENT_COMMENT1 = "comment1"; static final String ELEMENT_COMMENT2 = "comment2"; - static final String DATE_NOW = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT).format(new Date()); + static final String DATE_NOW = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); Annotation ANNOTATION1; Annotation ANNOTATION2; SpdxElement RELATED_ELEMENT1; @@ -79,11 +84,11 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { - String id = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "elementId"; + String id = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "elementId"; SpdxElement element1 = new GenericSpdxElement(gmo.getModelStore(), gmo.getDocumentUri(), id, gmo.getCopyManager(), true); assertEquals(0, element1.verify().size()); element1.setName(ELEMENT_NAME1); @@ -120,7 +125,7 @@ public void testAddRemoveAnnotations() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#getRelationships()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#getRelationships()}. */ public void testGetRemoveRelationships() throws InvalidSPDXAnalysisException { String id = "elementId"; @@ -155,7 +160,7 @@ public void testGetRemoveRelationships() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#setComment(java.lang.String)}. */ public void testSetcomment() throws InvalidSPDXAnalysisException { String id = "elementId"; @@ -171,7 +176,7 @@ public void testSetcomment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#setName(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#setName(java.lang.String)}. */ public void testSetName() throws InvalidSPDXAnalysisException { String id = "elementId"; diff --git a/src/test/java/org/spdx/library/model/SpdxFileTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java similarity index 91% rename from src/test/java/org/spdx/library/model/SpdxFileTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java index 331217b22..a67ed7eaf 100644 --- a/src/test/java/org/spdx/library/model/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java @@ -1,4 +1,4 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -9,31 +9,36 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; public class SpdxFileTest extends TestCase { - static final String[] NONSTD_IDS = new String[] {SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"1", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"3", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"4"}; + static final String[] NONSTD_IDS = new String[] {SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"1", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"3", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"4"}; static final String[] NONSTD_TEXTS = new String[] {"text1", "text2", "text3", "text4"}; static final String[] STD_IDS = new String[] {"AFL-3.0", "CECILL-B", "EUPL-1.0"}; static final String[] STD_TEXTS = new String[] {"std text1", "std text2", "std text3"}; - static DateFormat DATEFORMAT = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + static DateFormat DATEFORMAT = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); static String DATE_NOW = DATEFORMAT.format(new Date()); Annotation ANNOTATION1; Annotation ANNOTATION2; @@ -190,7 +195,7 @@ public void testAddFileType() throws InvalidSPDXAnalysisException { FileType initialFileType = FileType.IMAGE; SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), - SpdxConstants.NOASSERTION_VALUE, SHA1) + SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .addFileType(initialFileType) .build(); assertCollectionsSame(Arrays.asList(new FileType[]{initialFileType}), file.getFileTypes()); @@ -351,7 +356,7 @@ public void testGetChecksums() throws InvalidSPDXAnalysisException { List checksumSingle = Arrays.asList(new Checksum[] {gmo.createChecksum(ChecksumAlgorithm.SHA1, "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12")}); SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, checksum1) + "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, checksum1) .setChecksums(checksums1) .build(); Collection result = file.getChecksums(); @@ -382,7 +387,7 @@ public void testGetFileContributors() throws InvalidSPDXAnalysisException { String CONTRIBUTOR4 = "Contributor 4"; List oneContributor = Arrays.asList(new String[] {CONTRIBUTOR4}); SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .setFileContributors(contributors) .build(); assertEquals(contributors.size(), file.getFileContributors().size()); @@ -403,7 +408,7 @@ public void testGetFileContributors() throws InvalidSPDXAnalysisException { public void testGetNoticeText() throws InvalidSPDXAnalysisException { String fileNotice = "This is a file notice"; SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .build(); if (file.getNoticeText().isPresent() && !file.getNoticeText().get().isEmpty()) { fail("nto null notice text"); @@ -425,13 +430,13 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { String fileName2 = "bfile"; SpdxFile file1 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - fileName1, COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + fileName1, COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .build(); SpdxFile file2 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - fileName2, COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + fileName2, COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .build(); SpdxFile file3 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - fileName1, COMPLEX_LICENSE,Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + fileName1, COMPLEX_LICENSE,Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .build(); assertEquals(-1, file1.compareTo(file2)); @@ -444,7 +449,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { String COMMENT2 = "comment2"; String COMMENT3 = "comment3"; SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .setComment(COMMENT1) .build(); assertEquals(file.getComment().get(), COMMENT1); @@ -460,7 +465,7 @@ public void testSetAttributionText() throws InvalidSPDXAnalysisException { String ATT1 = "attribution 1"; String ATT2 = "attribution 2"; SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .addAttributionText(ATT1) .build(); assertEquals(1, file.getAttributionText().size()); @@ -477,10 +482,10 @@ public void testSetAttributionText() throws InvalidSPDXAnalysisException { @SuppressWarnings("deprecation") public void testDependency() throws InvalidSPDXAnalysisException { SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstants.NOASSERTION_VALUE, SHA1) + "filename", COMPLEX_LICENSE, Arrays.asList(CONJUNCTIVE_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .build(); SpdxFile dep = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "dependency", STANDARD_LICENSES[0], Arrays.asList(STANDARD_LICENSES[0]), SpdxConstants.NOASSERTION_VALUE, SHA1) + "dependency", STANDARD_LICENSES[0], Arrays.asList(STANDARD_LICENSES[0]), SpdxConstantsCompatV2.NOASSERTION_VALUE, SHA1) .build(); Collection result = file.getFileDependency(); assertEquals(0, result.size()); diff --git a/src/test/java/org/spdx/library/model/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java similarity index 73% rename from src/test/java/org/spdx/library/model/SpdxModelFactoryTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index 3688df365..4b2bce495 100644 --- a/src/test/java/org/spdx/library/model/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -1,4 +1,4 @@ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.List; import java.util.Optional; @@ -7,7 +7,15 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxIdNotFoundException; +import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -16,8 +24,8 @@ public class SpdxModelFactoryTest extends TestCase { static final String DOCUMENT_URI = "http://www.spdx.org/documents"; - static final String ID1 = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "1"; - static final String ID2 = SpdxConstants.SPDX_ELEMENT_REF_PRENUM + "2"; + static final String ID1 = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "1"; + static final String ID2 = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "2"; IModelStore modelStore; ModelCopyManager copyManager; @@ -35,28 +43,28 @@ protected void tearDown() throws Exception { public void testCreateSpdxDocument() throws InvalidSPDXAnalysisException { SpdxDocument result = SpdxModelFactory.createSpdxDocument(modelStore, DOCUMENT_URI, copyManager); - assertEquals(SpdxConstants.SPDX_DOCUMENT_ID, result.getId()); + assertEquals(SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, result.getId()); } public void testCreateModelObject() throws InvalidSPDXAnalysisException { ModelObject result = SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, ID1, - SpdxConstants.CLASS_SPDX_CHECKSUM, copyManager); + SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); } public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoolean() throws InvalidSPDXAnalysisException { ModelObject result = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, - SpdxConstants.CLASS_SPDX_CHECKSUM, copyManager, true); + SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); ModelObject result2 = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, - SpdxConstants.CLASS_SPDX_CHECKSUM, copyManager, false); + SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, false); assertTrue(result2 instanceof Checksum); assertEquals(ID1, result2.getId()); try { result = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID2, - SpdxConstants.CLASS_SPDX_CHECKSUM, copyManager, false); + SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, false); fail("Expected id not found exception"); } catch(SpdxIdNotFoundException ex) { // expected @@ -64,16 +72,16 @@ public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoole } public void testTypeToClass() throws InvalidSPDXAnalysisException { - assertEquals(Checksum.class, SpdxModelFactory.typeToClass(SpdxConstants.CLASS_SPDX_CHECKSUM)); - assertEquals(SpdxFile.class, SpdxModelFactory.typeToClass(SpdxConstants.CLASS_SPDX_FILE)); + assertEquals(Checksum.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM)); + assertEquals(SpdxFile.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_FILE)); } @SuppressWarnings("unchecked") public void testGetElements() throws InvalidSPDXAnalysisException { ModelObject file1 = SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, ID1, - SpdxConstants.CLASS_SPDX_FILE, copyManager); + SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); ModelObject file2 = SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, ID2, - SpdxConstants.CLASS_SPDX_FILE, copyManager); + SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); try (Stream elementStream = (Stream)SpdxModelFactory.getElements(modelStore, DOCUMENT_URI, copyManager, SpdxFile.class)) { elementStream.forEach(element -> { assertTrue(element instanceof SpdxFile); @@ -97,12 +105,12 @@ public void testGetElements() throws InvalidSPDXAnalysisException { public void testClassUriToClass() throws InvalidSPDXAnalysisException { assertEquals(Annotation.class, - SpdxModelFactory.classUriToClass(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.CLASS_ANNOTATION)); + SpdxModelFactory.classUriToClass(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.CLASS_ANNOTATION)); } public void testGetModelObjectIModelStoreStringStringModelCopyManager() throws InvalidSPDXAnalysisException { ModelObject result = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, - SpdxConstants.CLASS_SPDX_CHECKSUM, copyManager, true); + SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); Optional result2 = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, copyManager); diff --git a/src/test/java/org/spdx/library/model/SpdxNoneElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/SpdxNoneElementTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java index 04ec2645f..8d6cb19b8 100644 --- a/src/test/java/org/spdx/library/model/SpdxNoneElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java @@ -15,11 +15,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxNoneElement; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java similarity index 92% rename from src/test/java/org/spdx/library/model/SpdxPackageTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java index 5f1d5169c..6ee749fbc 100644 --- a/src/test/java/org/spdx/library/model/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -27,16 +27,27 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.Purpose; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalRef; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.ReferenceType; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.Purpose; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; @@ -71,8 +82,8 @@ public class SpdxPackageTest extends TestCase { static final String VERSION1 = "V1"; static final String VERSION2 = "V2"; - static final String DATE_NOW = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT).format(new Date()); - static final String DATE_THEN = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT).format(new GregorianCalendar(2021, Calendar.JANUARY, 11).getTime()); + static final String DATE_NOW = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); + static final String DATE_THEN = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new GregorianCalendar(2021, Calendar.JANUARY, 11).getTime()); SpdxElement RELATED_ELEMENT1; SpdxElement RELATED_ELEMENT2; @@ -171,8 +182,8 @@ protected void setUp() throws Exception { RELATIONSHIP2 = gmo.createRelationship(RELATED_ELEMENT2, RelationshipType.DYNAMIC_LINK, "Relationship Comment2"); - REF_TYPE1 = new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "npm"); - REF_TYPE2 = new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "cpe23Type"); + REF_TYPE1 = new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "npm"); + REF_TYPE2 = new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + "cpe23Type"); EXTERNAL_REF1 = gmo.createExternalRef(ReferenceCategory.PACKAGE_MANAGER, REF_TYPE1, "locator1", "comment1"); EXTERNAL_REF2 = gmo.createExternalRef(ReferenceCategory.SECURITY, REF_TYPE2, "locator1", "comment2"); @@ -186,7 +197,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -373,7 +384,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setFilesAnalyzed(java.lang.Boolean)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setFilesAnalyzed(java.lang.Boolean)}. */ public void testSetFilesAnalyzed() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -414,7 +425,7 @@ public void testSetFilesAnalyzed() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setLicenseDeclared(org.spdx.library.model.license.AnyLicenseInfo)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setLicenseDeclared(org.spdx.library.model.compat.v2.compat.v2.license.AnyLicenseInfo)}. */ public void testSetLicenseDeclared() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -456,7 +467,7 @@ public void testSetLicenseDeclared() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#addChecksum(org.spdx.library.model.Checksum)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#addChecksum(org.spdx.library.model.compat.v2.compat.v2.Checksum)}. * @throws InvalidSPDXAnalysisException */ public void testAddChecksum() throws InvalidSPDXAnalysisException { @@ -507,7 +518,7 @@ private boolean collectionsSame(Collection c1, Collection annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -549,7 +560,7 @@ public void testSetDescription() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setDownloadLocation(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setDownloadLocation(java.lang.String)}. */ public void testSetDownloadLocation() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -591,7 +602,7 @@ public void testSetDownloadLocation() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setHomepage(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setHomepage(java.lang.String)}. */ public void testSetHomepage() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -633,7 +644,7 @@ public void testSetHomepage() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setOriginator(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setOriginator(java.lang.String)}. */ public void testSetOriginator() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -675,7 +686,7 @@ public void testSetOriginator() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setPackageFileName(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setPackageFileName(java.lang.String)}. */ public void testSetPackageFileName() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -716,7 +727,7 @@ public void testSetPackageFileName() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setPackageVerificationCode(org.spdx.library.model.SpdxPackageVerificationCode)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setPackageVerificationCode(org.spdx.library.model.compat.v2.compat.v2.SpdxPackageVerificationCode)}. */ public void testSetPackageVerificationCode() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -757,7 +768,7 @@ public void testSetPackageVerificationCode() throws InvalidSPDXAnalysisException } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setSourceInfo(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setSourceInfo(java.lang.String)}. */ public void testSetSourceInfo() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -798,7 +809,7 @@ public void testSetSourceInfo() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setSummary(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setSummary(java.lang.String)}. */ public void testSetSummary() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -839,7 +850,7 @@ public void testSetSummary() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setSupplier(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setSupplier(java.lang.String)}. */ public void testSetSupplier() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -880,7 +891,7 @@ public void testSetSupplier() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#setVersionInfo(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#setVersionInfo(java.lang.String)}. */ public void testSetVersionInfo() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -921,7 +932,7 @@ public void testSetVersionInfo() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#addExternalRef(org.spdx.library.model.ExternalRef)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#addExternalRef(org.spdx.library.model.compat.v2.compat.v2.ExternalRef)}. */ public void testAddExternalRef() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -963,7 +974,7 @@ public void testAddExternalRef() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#addFile(org.spdx.library.model.SpdxFile)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#addFile(org.spdx.library.model.compat.v2.compat.v2.SpdxFile)}. */ public void testAddFile() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1003,7 +1014,7 @@ public void testAddFile() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#compareTo(org.spdx.library.model.SpdxPackage)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#compareTo(org.spdx.library.model.compat.v2.compat.v2.SpdxPackage)}. */ public void testCompareTo() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1086,7 +1097,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackage#getSha1()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackage#getSha1()}. */ public void testGetSha1() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1129,7 +1140,7 @@ public void testGetSha1() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxItem#setLicenseConcluded(org.spdx.library.model.license.AnyLicenseInfo)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxItem#setLicenseConcluded(org.spdx.library.model.compat.v2.compat.v2.license.AnyLicenseInfo)}. */ public void testSetLicenseConcluded() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1169,7 +1180,7 @@ public void testSetLicenseConcluded() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxItem#setCopyrightText(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxItem#setCopyrightText(java.lang.String)}. */ public void testSetCopyrightText() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1210,7 +1221,7 @@ public void testSetCopyrightText() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxItem#setLicenseComments(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxItem#setLicenseComments(java.lang.String)}. */ public void testSetLicenseComments() throws InvalidSPDXAnalysisException{ List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1251,7 +1262,7 @@ public void testSetLicenseComments() throws InvalidSPDXAnalysisException{ } /** - * Test method for {@link org.spdx.library.model.SpdxElement#addAnnotation(org.spdx.library.model.Annotation)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#addAnnotation(org.spdx.library.model.compat.v2.compat.v2.Annotation)}. */ public void testAddAnnotation() throws InvalidSPDXAnalysisException { List annotations1 = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1293,7 +1304,7 @@ public void testAddAnnotation() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#addRelationship(org.spdx.library.model.Relationship)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#addRelationship(org.spdx.library.model.compat.v2.compat.v2.Relationship)}. */ public void testAddRelationship() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1332,7 +1343,7 @@ public void testAddRelationship() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#setComment(java.lang.String)}. */ public void testSetComment() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1418,7 +1429,7 @@ public void testSetAttributionText() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxElement#setName(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxElement#setName(java.lang.String)}. */ public void testSetNameString() throws InvalidSPDXAnalysisException { List annotations = Arrays.asList(new Annotation[] {ANNOTATION1}); @@ -1459,23 +1470,23 @@ public void testSetNameString() throws InvalidSPDXAnalysisException { } public void testDownloadPattern() { - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git://git.myproject.org/MyProject.git@master").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git://git.myproject.org/MyOrg/MyProject.git@master").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git+git@git.myproject.org:MyProject").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git+git@git.myproject.org:MyOrg/MyProject").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git+git@git.myproject.org:MyProject.git").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git+git@git.myproject.org:MyOrg/MyProject.git").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git+git@git.myproject.org:MyProject@main").matches()); - assertTrue(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertTrue(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "git+git@git.myproject.org:MyProject@6338c7a2525e055a05bae1580e4dd189c2feff7b").matches()); - assertFalse(SpdxConstants.DOWNLOAD_LOCATION_PATTERN.matcher( + assertFalse(SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher( "something@git.myproject.org:MyProject@6338c7a2525e055a05bae1580e4dd189c2feff7b").matches()); } diff --git a/src/test/java/org/spdx/library/model/SpdxPackageVerificationCodeTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java similarity index 90% rename from src/test/java/org/spdx/library/model/SpdxPackageVerificationCodeTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java index a3084d101..bb85bb0b6 100644 --- a/src/test/java/org/spdx/library/model/SpdxPackageVerificationCodeTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.Arrays; import java.util.List; @@ -23,6 +23,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -76,7 +77,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.SpdxPackageVerificationCode#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackageVerificationCode#verify()}. */ public void testVerify() { List verify = VERIFICATION_CODES[0].verify(); @@ -88,7 +89,7 @@ public void testVerify() { } /** - * Test method for {@link org.spdx.library.model.SpdxPackageVerificationCode#setValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackageVerificationCode#setValue(java.lang.String)}. */ public void testSetValue() throws InvalidSPDXAnalysisException { for (int i = 0; i < VERIFICATION_CODES.length; i++) { @@ -103,7 +104,7 @@ public void testSetValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxPackageVerificationCode#getExcludedFileNames()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxPackageVerificationCode#getExcludedFileNames()}. * @throws InvalidSPDXAnalysisException */ public void testGetExcludedFileNames() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/SpdxSnippetTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/SpdxSnippetTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java index 7872a7b28..554494987 100644 --- a/src/test/java/org/spdx/library/model/SpdxSnippetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -25,18 +25,22 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.SpdxListedLicense; -import org.spdx.library.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; @@ -47,14 +51,14 @@ */ public class SpdxSnippetTest extends TestCase { - static final String[] NONSTD_IDS = new String[] {SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"1", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"3", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"4"}; + static final String[] NONSTD_IDS = new String[] {SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"1", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"3", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"4"}; static final String[] NONSTD_TEXTS = new String[] {"text1", "text2", "text3", "text4"}; static final String[] STD_IDS = new String[] {"AFL-3.0", "CECILL-B", "EUPL-1.0"}; static final String[] STD_TEXTS = new String[] {"std text1", "std text2", "std text3"}; - static DateFormat DATEFORMAT = new SimpleDateFormat(SpdxConstants.SPDX_DATE_FORMAT); + static DateFormat DATEFORMAT = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); static String DATE_NOW = DATEFORMAT.format(new Date()); Annotation ANNOTATION1; Annotation ANNOTATION2; @@ -142,11 +146,11 @@ protected void setUp() throws Exception { })); FROM_FILE1 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "fromFile1", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "fromFile1", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, gmo.createChecksum(ChecksumAlgorithm.SHA1, "1123456789abcdef0123456789abcdef01234567")).build(); FROM_FILE2 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "fromFile2", STANDARD_LICENSES[0], Arrays.asList(STANDARD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "fromFile2", STANDARD_LICENSES[0], Arrays.asList(STANDARD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, gmo.createChecksum(ChecksumAlgorithm.SHA1, "5555556789abcdef0123456789abcdef01234567")).build(); BOP_POINTER1_1 = gmo.createByteOffsetPointer(FROM_FILE1, OFFSET1_1); @@ -171,11 +175,11 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.SpdxSnippet#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#verify()}. */ public void testVerify() throws InvalidSPDXAnalysisException { SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -184,7 +188,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { assertEquals(0, result.size()); // missing file SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -197,24 +201,24 @@ public void testVerify() throws InvalidSPDXAnalysisException { assertTrue(result.size() > 0); // missing byte range SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); snippet3.setStrict(false); - snippet3.setPropertyValue(SpdxConstants.PROP_SNIPPET_RANGE, null); + snippet3.setPropertyValue(SpdxConstantsCompatV2.PROP_SNIPPET_RANGE, null); result = snippet3.verify(); assertEquals(1, result.size()); } public void testEquivalent() throws InvalidSPDXAnalysisException { SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -222,7 +226,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(snippet2.equivalent(snippet)); // Different File SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE2, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -230,7 +234,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertFalse(snippet.equivalent(snippet3)); // different byte range SpdxSnippet snippet4 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET2_1, OFFSET2_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -239,11 +243,11 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxSnippet#setSnippetFromFile(org.spdx.library.model.SpdxFile)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#setSnippetFromFile(org.spdx.library.model.compat.v2.compat.v2.SpdxFile)}. */ public void testSetSnippetFromFile() throws InvalidSPDXAnalysisException { SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -266,11 +270,11 @@ public void testSetSnippetFromFile() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxSnippet#setByteRange(org.spdx.library.model.pointer.StartEndPointer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#setByteRange(org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer)}. */ public void testSetByteRange() throws InvalidSPDXAnalysisException { SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -287,11 +291,11 @@ public void testSetByteRange() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxSnippet#setLineRange(org.spdx.library.model.pointer.StartEndPointer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#setLineRange(org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer)}. */ public void testSetLineRange() throws InvalidSPDXAnalysisException { SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); @@ -308,38 +312,38 @@ public void testSetLineRange() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.SpdxSnippet#compareTo(org.spdx.library.model.SpdxSnippet)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#compareTo(org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet)}. */ public void testCompareTo() throws InvalidSPDXAnalysisException { SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); // same SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); assertEquals(0, snippet.compareTo(snippet2)); // different filename SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "AsnippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "AsnippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); assertTrue(snippet.compareTo(snippet3) > 0); // different from file SpdxSnippet snippet4 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE2, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); assertTrue(snippet.compareTo(snippet4) < 0); // different byterange SpdxSnippet snippet5 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), - "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstants.NOASSERTION_VALUE, + "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET2_1, OFFSET2_2) .setLineRange(LINE1_1, LINE1_2) .build(); diff --git a/src/test/java/org/spdx/library/model/StartEndPointerTest.java b/src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java similarity index 83% rename from src/test/java/org/spdx/library/model/StartEndPointerTest.java rename to src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java index 6dce1c5ae..56026017d 100644 --- a/src/test/java/org/spdx/library/model/StartEndPointerTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java @@ -15,16 +15,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model; +package org.spdx.library.model.compat.v2; import java.util.List; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.SinglePointer; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.SinglePointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; import junit.framework.TestCase; @@ -73,7 +76,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.pointer.StartEndPointer#verify()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer#verify()}. * @throws InvalidSPDXAnalysisException */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -105,7 +108,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.pointer.StartEndPointer#setEndPointer(org.spdx.library.model.pointer.SinglePointer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer#setEndPointer(org.spdx.library.model.compat.v2.compat.v2.pointer.SinglePointer)}. */ public void testSetEndPointer() throws InvalidSPDXAnalysisException { StartEndPointer sop = gmo.createStartEndPointer(BOP_POINTER1, BOP_POINTER2); @@ -138,7 +141,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.pointer.StartEndPointer#setStartPointer(org.spdx.library.model.pointer.SinglePointer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer#setStartPointer(org.spdx.library.model.compat.v2.compat.v2.pointer.SinglePointer)}. */ public void testSetStartPointerSinglePointer() throws InvalidSPDXAnalysisException { StartEndPointer sop = gmo.createStartEndPointer(BOP_POINTER1, BOP_POINTER2); @@ -157,7 +160,7 @@ public void testSetStartPointerSinglePointer() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.pointer.StartEndPointer#compareTo(org.spdx.library.model.pointer.StartEndPointer)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer#compareTo(org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer)}. */ public void testCompareTo() throws InvalidSPDXAnalysisException { StartEndPointer sop1 = gmo.createStartEndPointer(BOP_POINTER1, BOP_POINTER2); diff --git a/src/test/java/org/spdx/library/model/license/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java similarity index 93% rename from src/test/java/org/spdx/library/model/license/ConjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java index 93dc126d6..4097a41fa 100644 --- a/src/test/java/org/spdx/library/model/license/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java @@ -15,15 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -69,7 +69,7 @@ public void testCreateConjunctive() throws InvalidSPDXAnalysisException { String id = modelStore.getNextId(IdType.Anonymous, DOCUMENT_URI); ConjunctiveLicenseSet cls = new ConjunctiveLicenseSet(modelStore, DOCUMENT_URI, id, copyManager, true); cls.setMembers(Arrays.asList(NON_STD_LICENSES)); - ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); + ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); List verify = cls2.verify(); assertEquals(0, verify.size()); @@ -92,7 +92,7 @@ public void testAddMember() throws InvalidSPDXAnalysisException { assertEquals(0, verify.size()); assertEquals(NON_STD_LICENSES.length+1, cls.getMembers().size()); assertTrue(cls.getMembers().contains(eli)); - ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); + ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length+1, cls2.getMembers().size()); assertTrue(cls2.getMembers().contains(eli)); @@ -109,7 +109,7 @@ public void testRemoveMember() throws InvalidSPDXAnalysisException { cls.removeMember(NON_STD_LICENSES[0]); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); - ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstants.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); + ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); diff --git a/src/test/java/org/spdx/library/model/license/CrossRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java similarity index 97% rename from src/test/java/org/spdx/library/model/license/CrossRefTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java index 20500769e..7bb43d2e8 100644 --- a/src/test/java/org/spdx/library/model/license/CrossRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java @@ -1,8 +1,8 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -52,7 +52,7 @@ public void tearDown() throws Exception { } public void testGetType() { - assertEquals(SpdxConstants.CLASS_CROSS_REF, TEST_CROSSREF.getType()); + assertEquals(SpdxConstantsCompatV2.CLASS_CROSS_REF, TEST_CROSSREF.getType()); } public void testVerify() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/license/DisjunctiveLiceseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java similarity index 92% rename from src/test/java/org/spdx/library/model/license/DisjunctiveLiceseSetTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java index a8a10ce8f..66795bdde 100644 --- a/src/test/java/org/spdx/library/model/license/DisjunctiveLiceseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java @@ -15,15 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -70,7 +70,7 @@ public void testCreateDisjunctive() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet cls = new DisjunctiveLicenseSet(modelStore, DOCUMENT_URI, id, copyManager, true); cls.setMembers(Arrays.asList(NON_STD_LICENSES)); DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, - SpdxConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); + SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); List verify = cls2.verify(); assertEquals(0, verify.size()); @@ -94,7 +94,7 @@ public void testAddMember() throws InvalidSPDXAnalysisException { assertEquals(NON_STD_LICENSES.length+1, cls.getMembers().size()); assertTrue(cls.getMembers().contains(eli)); DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, - SpdxConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); + SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length+1, cls2.getMembers().size()); assertTrue(cls2.getMembers().contains(eli)); @@ -112,7 +112,7 @@ public void testRemoveMember() throws InvalidSPDXAnalysisException { assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, - id, SpdxConstants.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); + id, SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); diff --git a/src/test/java/org/spdx/library/model/license/ExternalLicenseRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java similarity index 72% rename from src/test/java/org/spdx/library/model/license/ExternalLicenseRefTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java index d6f64cf12..fa7b9bfc7 100644 --- a/src/test/java/org/spdx/library/model/license/ExternalLicenseRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java @@ -15,18 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.ExternalDocumentRef; -import org.spdx.library.model.GenericModelObject; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; @@ -36,22 +36,22 @@ */ public class ExternalLicenseRefTest extends TestCase { - static final String DOCID1 = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; - static final String LICENSEREF1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF1"; + static final String DOCID1 = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; + static final String LICENSEREF1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF1"; static final String DOCURI1 = "http://doc/uri/one"; static final String ID1 = DOCID1 + ":" + LICENSEREF1; - static final String DOCID2 = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; - static final String LICENSEREF2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF2"; + static final String DOCID2 = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; + static final String LICENSEREF2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF2"; static final String DOCURI2 = "http://doc/uri/two"; static final String ID2 = DOCID2 + ":" + LICENSEREF2; - static final String DOCID3 = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID3"; - static final String LICENSEREF3 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF3"; + static final String DOCID3 = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID3"; + static final String LICENSEREF3 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF3"; static final String DOCURI3 = "http://doc/uri/three"; static final String ID3 = DOCID3 + ":" + LICENSEREF3; - static final String LICENSEREF4 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF3"; + static final String LICENSEREF4 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF3"; static final String DOCURI4 = "http://doc/uri/four"; Checksum CHECKSUM1; @@ -83,7 +83,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#equivalent(org.spdx.library.model.ModelObject)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject)}. * @throws InvalidSPDXAnalysisException */ public void testEquivalentModelObject() throws InvalidSPDXAnalysisException { @@ -114,7 +114,7 @@ public void testUriToExternalLicenseRefId() throws InvalidSPDXAnalysisException result = ExternalExtractedLicenseInfo.uriToExternalExtractedLicenseId(uri, gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager()); assertEquals(expected, result); - String LicenseRef5 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF5"; + String LicenseRef5 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "LICENSEREF5"; uri = DOCURI4 + "#" + LicenseRef5; expected = generatedDocId + ":" + LicenseRef5; result = ExternalExtractedLicenseInfo.uriToExternalExtractedLicenseId(uri, gmo.getModelStore(), @@ -130,7 +130,7 @@ public void testUriToExternalLicenseRef() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getComment()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getComment()}. * @throws InvalidSPDXAnalysisException */ public void testGetComment() throws InvalidSPDXAnalysisException { @@ -143,7 +143,7 @@ public void testGetComment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#setComment(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#setComment(java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testSetComment() throws InvalidSPDXAnalysisException { @@ -157,7 +157,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getSeeAlso()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getSeeAlso()}. */ public void testGetSeeAlso() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); @@ -165,7 +165,7 @@ public void testGetSeeAlso() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#setSeeAlso(java.util.Collection)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#setSeeAlso(java.util.Collection)}. */ public void testSetSeeAlso() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); @@ -178,7 +178,7 @@ public void testSetSeeAlso() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getExtractedText()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getExtractedText()}. */ public void testGetExtractedText() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); @@ -186,7 +186,7 @@ public void testGetExtractedText() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getExternalDocumentId()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getExternalDocumentId()}. */ public void testGetExternalDocumentId() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); @@ -194,7 +194,7 @@ public void testGetExternalDocumentId() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getExternalLicenseRef()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getExternalLicenseRef()}. */ public void testGetExternalLicenseRef() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); @@ -202,7 +202,7 @@ public void testGetExternalLicenseRef() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getExternalExtractedLicenseURI()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getExternalExtractedLicenseURI()}. */ public void testGetExternalLicenseRefURI() throws InvalidSPDXAnalysisException { String expected = DOCURI1 + "#" + LICENSEREF1; @@ -211,7 +211,7 @@ public void testGetExternalLicenseRefURI() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#externalExtractedLicenseIdToURI(java.lang.String, org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#externalExtractedLicenseIdToURI(java.lang.String, org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager)}. */ public void testExternalLicenseRefIdToURI() throws InvalidSPDXAnalysisException { String expected = DOCURI1 + "#" + LICENSEREF1; @@ -222,7 +222,7 @@ public void testExternalLicenseRefIdToURI() throws InvalidSPDXAnalysisException } /** - * Test method for {@link org.spdx.library.model.license.ExternalExtractedLicenseInfo#getIndividualURI()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExternalExtractedLicenseInfo#getIndividualURI()}. */ public void testGetIndividualURI() throws InvalidSPDXAnalysisException { String expected = DOCURI1 + "#" + LICENSEREF1; @@ -231,7 +231,7 @@ public void testGetIndividualURI() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.ExtractedLicenseInfo#compareTo(org.spdx.library.model.license.ExtractedLicenseInfo)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ExtractedLicenseInfo#compareTo(org.spdx.library.model.compat.v2.compat.v2.license.ExtractedLicenseInfo)}. */ public void testCompareTo() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr1 = new ExternalExtractedLicenseInfo(ID1); @@ -242,7 +242,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.SimpleLicensingInfo#getName()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getName()}. */ public void testGetName() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); @@ -250,7 +250,7 @@ public void testGetName() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.license.SimpleLicensingInfo#setName(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#setName(java.lang.String)}. */ public void testSetName() throws InvalidSPDXAnalysisException { ExternalExtractedLicenseInfo elr = new ExternalExtractedLicenseInfo(ID1); diff --git a/src/test/java/org/spdx/library/model/license/ExtractedLicensingInfoTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/license/ExtractedLicensingInfoTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java index cf358bf3a..e9acdff72 100644 --- a/src/test/java/org/spdx/library/model/license/ExtractedLicensingInfoTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.io.File; import java.util.Arrays; @@ -23,9 +23,9 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.TypedValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -53,7 +53,7 @@ protected void tearDown() throws Exception { } static final String TEST_RDF_FILE_PATH = "TestFiles"+File.separator+"SPDXRdfExample.rdf"; - static final String ID1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "1"; + static final String ID1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "1"; static final String TEXT1 = "Text1"; static final String TEXT2 = "Text2"; static final String COMMENT1 = "Comment1"; @@ -89,9 +89,9 @@ public void testSPDXNonStandardLicenseModelNode() throws InvalidSPDXAnalysisExce lic.setComment(COMMENT1); IModelStore modelStore = new InMemSpdxStore(); ModelCopyManager copyManager = new ModelCopyManager(); - TypedValue copy = copyManager.copy(modelStore, DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + TypedValue copy = copyManager.copy(modelStore, DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), copy.getId(), SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), copy.getId(), SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); assertEquals(copy.getId(), lic2.getLicenseId()); assertEquals(TEXT1, lic2.getExtractedText()); assertEquals(COMMENT1, lic2.getComment()); @@ -117,14 +117,14 @@ public void testSetText() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setComment(COMMENT1); ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), - ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setExtractedText(TEXT2); assertEquals(ID1, lic2.getLicenseId()); assertEquals(TEXT2, lic2.getExtractedText()); assertEquals(COMMENT1, lic2.getComment()); IModelStore modelStore = new InMemSpdxStore(); ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, - DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic3.copyFrom(lic); assertEquals(TEXT2, lic3.getExtractedText()); } @@ -138,7 +138,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setComment(COMMENT1); ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), - ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setComment(COMMENT2); assertEquals(ID1, lic2.getLicenseId()); assertEquals(TEXT1, lic2.getExtractedText()); @@ -146,7 +146,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { IModelStore modelStore = new InMemSpdxStore(); ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), - ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic3.copyFrom(lic); assertEquals(COMMENT2, lic3.getComment()); } @@ -158,11 +158,11 @@ public void testSetLicenseName() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, - DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setName(LICENSENAME2); assertEquals(LICENSENAME2, lic2.getName()); ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, - DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); assertEquals(LICENSENAME2, lic3.getName()); } @@ -174,13 +174,13 @@ public void testSetSourceUrls() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), - ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setSeeAlso(Arrays.asList(SOURCEURLS2)); if (!compareArrayContent(SOURCEURLS2, (String[])lic2.getSeeAlso().toArray(new String[lic2.getSeeAlso().size()]))) { fail("Source URLS not the same"); } ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, - DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); + DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); if (!compareArrayContent(SOURCEURLS2, (String[])lic3.getSeeAlso().toArray(new String[lic2.getSeeAlso().size()]))) { fail("Source URLS not the same"); } diff --git a/src/test/java/org/spdx/library/model/license/LicenseExceptionTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java similarity index 98% rename from src/test/java/org/spdx/library/model/license/LicenseExceptionTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java index 2cfdaed90..2ea77e6c5 100644 --- a/src/test/java/org/spdx/library/model/license/LicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.Arrays; import java.util.Collection; @@ -24,7 +24,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -87,7 +87,7 @@ public void testCreateResource() throws InvalidSPDXAnalysisException { le.setDeprecated(true); InMemSpdxStore store = new InMemSpdxStore(); ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store, DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION); + copyManager.copy(store, DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION); LicenseException le2 = new LicenseException(store, DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, copyManager, false); assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId()); diff --git a/src/test/java/org/spdx/library/model/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java similarity index 93% rename from src/test/java/org/spdx/library/model/license/LicenseExpressionParserTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java index 4302e7d4c..43caef868 100644 --- a/src/test/java/org/spdx/library/model/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; @@ -23,11 +23,11 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.GenericModelObject; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,9 +36,9 @@ public class LicenseExpressionParserTest extends TestCase { static final String[] STD_IDS = new String[] {"AFL-3.0", "CECILL-B", "EUPL-1.0", "Afmparse"}; - static final String[] NONSTD_IDS = new String[] {SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"1", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"3", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"4"}; + static final String[] NONSTD_IDS = new String[] {SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"1", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"3", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"4"}; static final String[] STD_TEXTS = new String[] {"Academic Free License (", "CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B", "European Union Public Licence", "Afmparse License"}; static final String[] NONSTD_TEXTS = new String[] {"text1", "text2", "text3", "text4"}; @@ -48,7 +48,7 @@ public class LicenseExpressionParserTest extends TestCase { ExtractedLicenseInfo[] NON_STD_LICENSES; SpdxListedLicense[] STANDARD_LICENSES; LicenseException[] LICENSE_EXCEPTIONS; - static final String DOCID = SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; + static final String DOCID = SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "DOCID1"; IModelStore modelStore; static final String TEST_DOCUMENT_URI = "https://test.doc.uri"; GenericModelObject gmo; @@ -201,7 +201,7 @@ public void testAndOrPrecedence() throws InvalidSPDXAnalysisException { } public void testExternalLicenseRef() throws InvalidSPDXAnalysisException { - String externalExtractedId = DOCID + ":" + SpdxConstants.NON_STD_LICENSE_ID_PRENUM + "232"; + String externalExtractedId = DOCID + ":" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "232"; AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(externalExtractedId, modelStore, TEST_DOCUMENT_URI, null); assertTrue(result instanceof ExternalExtractedLicenseInfo); diff --git a/src/test/java/org/spdx/library/model/license/LicenseInfoFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java similarity index 93% rename from src/test/java/org/spdx/library/model/license/LicenseInfoFactoryTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java index 477ec0d8d..909cc0c8e 100644 --- a/src/test/java/org/spdx/library/model/license/LicenseInfoFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java @@ -15,15 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.GenericModelObject; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.GenericModelObject; import junit.framework.TestCase; @@ -33,9 +33,9 @@ */ public class LicenseInfoFactoryTest extends TestCase { - static final String[] NONSTD_IDS = new String[] {SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"1", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"3", - SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"4"}; + static final String[] NONSTD_IDS = new String[] {SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"1", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"2", SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"3", + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"4"}; static final String[] NONSTD_TEXTS = new String[] {"text1", "text2", "text3", "text4"}; static final String[] STD_IDS = new String[] {"AFL-3.0", "CECILL-B", "EUPL-1.0"}; static final String[] STD_TEXTS = new String[] {"Academic Free License (", "CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B", diff --git a/src/test/java/org/spdx/library/model/license/ListedLicensesTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java similarity index 90% rename from src/test/java/org/spdx/library/model/license/ListedLicensesTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java index 9360b9b40..4e3af4d2a 100644 --- a/src/test/java/org/spdx/library/model/license/ListedLicensesTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java @@ -1,10 +1,10 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.List; import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import junit.framework.TestCase; @@ -60,14 +60,14 @@ public void testLicenseListVersionFormat() { } /** - * Test method for {@link org.spdx.library.model.license.ListedLicenses#isSpdxListedLicenseId(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ListedLicenses#isSpdxListedLicenseId(java.lang.String)}. */ public void testIsSpdxListedLicenseID() { assertTrue(ListedLicenses.getListedLicenses().isSpdxListedLicenseId("Apache-2.0")); } /** - * Test method for {@link org.spdx.library.model.license.ListedLicenses#getListedLicenseById(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ListedLicenses#getListedLicenseById(java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testGetListedLicenseById() throws InvalidSPDXAnalysisException { @@ -89,7 +89,7 @@ public void testGetLicenseIbyIdLocal() throws InvalidSPDXAnalysisException { } } /** - * Test method for {@link org.spdx.library.model.license.ListedLicenses#getSpdxListedLicenseIds()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.license.ListedLicenses#getSpdxListedLicenseIds()}. */ public void testGetSpdxListedLicenseIds() { List result = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); @@ -140,7 +140,7 @@ public void testListedExceptionIdCaseSensitive() { public void testGetLicenseIdProperty() throws InvalidSPDXAnalysisException { String id = "Apache-2.0"; SpdxListedLicense lic = ListedLicenses.getListedLicenses().getListedLicenseById(id); - Optional idProp = lic.getModelStore().getValue(lic.getDocumentUri(), id, SpdxConstants.PROP_LICENSE_ID); + Optional idProp = lic.getModelStore().getValue(lic.getDocumentUri(), id, SpdxConstantsCompatV2.PROP_LICENSE_ID); assertTrue(idProp.isPresent()); assertTrue(idProp.get() instanceof String); assertEquals(id, idProp.get()); @@ -149,7 +149,7 @@ public void testGetLicenseIdProperty() throws InvalidSPDXAnalysisException { public void testGetExceptionIdProperty() throws InvalidSPDXAnalysisException { String id = "Classpath-exception-2.0"; ListedLicenseException ex = ListedLicenses.getListedLicenses().getListedExceptionById(id); - Optional idProp = ex.getModelStore().getValue(ex.getDocumentUri(), id, SpdxConstants.PROP_LICENSE_EXCEPTION_ID); + Optional idProp = ex.getModelStore().getValue(ex.getDocumentUri(), id, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID); assertTrue(idProp.isPresent()); assertTrue(idProp.get() instanceof String); assertEquals(id, idProp.get()); diff --git a/src/test/java/org/spdx/library/model/license/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java similarity index 99% rename from src/test/java/org/spdx/library/model/license/OrLaterOperatorTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java index 3b7b0a0bd..70c296001 100644 --- a/src/test/java/org/spdx/library/model/license/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; diff --git a/src/test/java/org/spdx/library/model/license/SpdxListedLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java similarity index 98% rename from src/test/java/org/spdx/library/model/license/SpdxListedLicenseTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java index 91d2ff250..e2f5eec1f 100644 --- a/src/test/java/org/spdx/library/model/license/SpdxListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import java.util.ArrayList; import java.util.Arrays; @@ -25,7 +25,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -225,7 +225,7 @@ public void testCopyOf() throws InvalidSPDXAnalysisException, InvalidLicenseTemp SpdxListedLicense stdl = new SpdxListedLicense(name, id, text, sourceUrls, notes, standardLicenseHeader, template, true, null, licenseHtml, true, deprecatedVersion); IModelStore store = new InMemSpdxStore(); - SpdxListedLicense lic2 = new SpdxListedLicense(store, SpdxConstants.LISTED_LICENSE_URL, id, stdl.getCopyManager(), true); + SpdxListedLicense lic2 = new SpdxListedLicense(store, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, stdl.getCopyManager(), true); lic2.copyFrom(stdl); assertEquals(id, lic2.getLicenseId()); @@ -280,7 +280,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { sourceUrls, notes, standardLicenseHeader, template, true,null, null, false, null); assertTrue(stdl.equivalent(stdl)); IModelStore store = new InMemSpdxStore(); - SpdxListedLicense stdl2 = new SpdxListedLicense(store, SpdxConstants.LISTED_LICENSE_URL, id, stdl.getCopyManager(), true); + SpdxListedLicense stdl2 = new SpdxListedLicense(store, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, stdl.getCopyManager(), true); stdl2.setLicenseText(text2); stdl2.setName(name2); stdl2.setSeeAlso(sourceUrls2); @@ -289,7 +289,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { stdl2.setStandardLicenseTemplate(template2); assertTrue(stdl2.equivalent(stdl)); - SpdxListedLicense stdl3 = new SpdxListedLicense(store, SpdxConstants.LISTED_LICENSE_URL, "Apache-2.0", stdl.getCopyManager(), true); + SpdxListedLicense stdl3 = new SpdxListedLicense(store, SpdxConstantsCompatV2.LISTED_LICENSE_URL, "Apache-2.0", stdl.getCopyManager(), true); stdl3.setLicenseText(text); stdl3.setSeeAlso(sourceUrls); stdl3.setComment(notes); diff --git a/src/test/java/org/spdx/library/model/license/SpdxNoAssertionLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java similarity index 93% rename from src/test/java/org/spdx/library/model/license/SpdxNoAssertionLicenseTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java index 9db140b36..a9ce2e0c5 100644 --- a/src/test/java/org/spdx/library/model/license/SpdxNoAssertionLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java @@ -1,4 +1,4 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.storage.IModelStore; diff --git a/src/test/java/org/spdx/library/model/license/SpdxNoneLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java similarity index 91% rename from src/test/java/org/spdx/library/model/license/SpdxNoneLicenseTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java index 8b0e3dde7..7a72dfe03 100644 --- a/src/test/java/org/spdx/library/model/license/SpdxNoneLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java @@ -1,8 +1,8 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.GenericSpdxItem; +import org.spdx.library.model.compat.v2.GenericSpdxItem; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/license/WithExceptionOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java similarity index 95% rename from src/test/java/org/spdx/library/model/license/WithExceptionOperatorTest.java rename to src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java index cd8997fd3..f565ee4d7 100644 --- a/src/test/java/org/spdx/library/model/license/WithExceptionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java @@ -1,11 +1,11 @@ -package org.spdx.library.model.license; +package org.spdx.library.model.compat.v2.license; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.TypedValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -84,7 +84,7 @@ public void testCopy() throws InvalidSPDXAnalysisException { TypedValue tv = copyManager.copy(store, DefaultModelStore.getDefaultDocumentUri(), weo1.getModelStore(), weo1.getDocumentUri(), weo1.getId(), weo1.getType()); WithExceptionOperator clone = (WithExceptionOperator) SpdxModelFactory.createModelObject(store, - DefaultModelStore.getDefaultDocumentUri(), tv.getId(), SpdxConstants.CLASS_WITH_EXCEPTION_OPERATOR, copyManager); + DefaultModelStore.getDefaultDocumentUri(), tv.getId(), SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, copyManager); ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)weo1.getLicense(); ExtractedLicenseInfo lic1FromClone = (ExtractedLicenseInfo)clone.getLicense(); assertEquals(lic1.getExtractedText(), lic1FromClone.getExtractedText()); diff --git a/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java b/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java index 46e61bbf6..0d2ce87a6 100644 --- a/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java +++ b/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java @@ -22,7 +22,8 @@ import java.net.URISyntaxException; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.referencetype.compat.v2.ListedReferenceTypes; import junit.framework.TestCase; @@ -52,33 +53,33 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.referencetype.ListedReferenceTypes#isListedReferenceType(java.net.URI)}. + * Test method for {@link org.spdx.library.referencetype.compat.v2.ListedReferenceTypes#isListedReferenceType(java.net.URI)}. */ public void testIsListedReferenceType() throws URISyntaxException { for (String refName:LISTED_REFERENCE_TYPE_NAMES) { - URI uri = new URI(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + refName); + URI uri = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + refName); assertTrue(ListedReferenceTypes.getListedReferenceTypes().isListedReferenceType(uri)); } URI wrongNamespace = new URI("http://wrong/"+LISTED_REFERENCE_TYPE_NAMES[0]); assertFalse(ListedReferenceTypes.getListedReferenceTypes().isListedReferenceType(wrongNamespace)); - URI notValidName = new URI(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX+"wrong"); + URI notValidName = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX+"wrong"); assertFalse(ListedReferenceTypes.getListedReferenceTypes().isListedReferenceType(notValidName)); } /** - * Test method for {@link org.spdx.library.referencetype.ListedReferenceTypes#getListedReferenceUri(java.lang.String)}. + * Test method for {@link org.spdx.library.referencetype.compat.v2.ListedReferenceTypes#getListedReferenceUri(java.lang.String)}. */ public void testGetListedReferenceUri() throws InvalidSPDXAnalysisException { URI result = ListedReferenceTypes.getListedReferenceTypes().getListedReferenceUri(LISTED_REFERENCE_TYPE_NAMES[0]); - assertEquals(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + LISTED_REFERENCE_TYPE_NAMES[0], result.toString()); + assertEquals(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + LISTED_REFERENCE_TYPE_NAMES[0], result.toString()); } /** - * Test method for {@link org.spdx.library.referencetype.ListedReferenceTypes#getListedReferenceName(java.net.URI)}. + * Test method for {@link org.spdx.library.referencetype.compat.v2.ListedReferenceTypes#getListedReferenceName(java.net.URI)}. */ public void testGetListedReferenceName() throws URISyntaxException, InvalidSPDXAnalysisException { for (String refName:LISTED_REFERENCE_TYPE_NAMES) { - URI uri = new URI(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + refName); + URI uri = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + refName); assertEquals(refName, ListedReferenceTypes.getListedReferenceTypes().getListedReferenceName(uri)); } } diff --git a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java index fa454bf9d..5218e645c 100644 --- a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java @@ -8,9 +8,9 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.InvalidSpdxPropertyException; -import org.spdx.library.model.license.CrossRef; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -19,17 +19,17 @@ public class CrossRefJsonTest extends TestCase { static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_CROSS_REF_MATCH.getName(), - SpdxConstants.PROP_CROSS_REF_TIMESTAMP.getName(), - SpdxConstants.PROP_CROSS_REF_URL.getName()); + SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH.getName(), + SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP.getName(), + SpdxConstantsCompatV2.PROP_CROSS_REF_URL.getName()); static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_CROSS_REF_IS_LIVE.getName(), - SpdxConstants.PROP_CROSS_REF_IS_VALID.getName(), - SpdxConstants.PROP_CROSS_REF_WAYBACK_LINK.getName() + SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE.getName(), + SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID.getName(), + SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK.getName() ); - static final List INTEGER_PROPERTY_VALUE_NAMES = Arrays.asList(SpdxConstants.PROP_CROSS_REF_ORDER.getName()); + static final List INTEGER_PROPERTY_VALUE_NAMES = Arrays.asList(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER.getName()); static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java index fb98cf2e0..355129b9c 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java @@ -22,7 +22,7 @@ import java.util.Map; import java.util.Objects; -import org.spdx.library.model.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -79,7 +79,7 @@ public void testGetReleaseDate() { } /** - * Test method for {@link org.spdx.storage.listedlicense.ExceptionJsonTOC#addException(org.spdx.library.model.license.ListedLicenseException, java.lang.String, java.lang.String, boolean)}. + * Test method for {@link org.spdx.storage.listedlicense.ExceptionJsonTOC#addException(org.spdx.library.model.compat.v2.compat.v2.license.ListedLicenseException, java.lang.String, java.lang.String, boolean)}. */ public void testAddException() throws Exception { ExceptionJsonTOC ejt = new ExceptionJsonTOC(); diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java index c8d1a4055..7a550d633 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java @@ -24,9 +24,9 @@ import java.util.Map; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.InvalidSpdxPropertyException; -import org.spdx.library.model.license.ListedLicenseException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -45,18 +45,18 @@ public class ExceptionJsonTest extends TestCase { */ static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_LICENSE_EXCEPTION_ID.getName(), SpdxConstants.PROP_EXCEPTION_TEXT.getName(), - SpdxConstants.PROP_STD_LICENSE_NAME.getName(), SpdxConstants.RDFS_PROP_COMMENT.getName(), - SpdxConstants.PROP_EXCEPTION_TEMPLATE.getName(), - SpdxConstants.PROP_EXAMPLE.getName(), SpdxConstants.PROP_LIC_DEPRECATED_VERSION.getName(), - SpdxConstants.PROP_EXCEPTION_TEXT_HTML.getName() + SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID.getName(), SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), + SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME.getName(), SpdxConstantsCompatV2.RDFS_PROP_COMMENT.getName(), + SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE.getName(), + SpdxConstantsCompatV2.PROP_EXAMPLE.getName(), SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION.getName(), + SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML.getName() ); static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_LIC_ID_DEPRECATED.getName() + SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName() ); - static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstants.RDFS_PROP_SEE_ALSO.getName()); + static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName()); static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); static { PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); @@ -100,7 +100,7 @@ public void testSetTypedProperty() { String exceptionId = "SpdxexceptionId1"; ExceptionJson ej = new ExceptionJson(exceptionId); try { - ej.setTypedProperty("TestPropertyName", "SpdxId22", SpdxConstants.CLASS_SPDX_ELEMENT); + ej.setTypedProperty("TestPropertyName", "SpdxId22", SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT); fail("This shouldn't work"); } catch (InvalidSPDXAnalysisException e) { // Expected @@ -213,7 +213,7 @@ public void testLegacyJson() throws Exception { for (String valueName:STRING_PROPERTY_VALUE_NAMES) { stringValues.put(valueName, "ValueFor"+valueName); json.append("\t\""); - if (SpdxConstants.RDFS_PROP_COMMENT.equals(valueName)) { + if (SpdxConstantsCompatV2.RDFS_PROP_COMMENT.equals(valueName)) { json.append("licenseComments"); // Legacy value } else { json.append(valueName); @@ -260,20 +260,20 @@ public void testLegacyJson() throws Exception { public void testIsCollectionMembersAssignableTo() throws Exception { String exceptionId = "excId"; ExceptionJson ej = new ExceptionJson(exceptionId); - assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); - assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT.getName(), String.class)); + assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); + assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), String.class)); } public void testIsPropertyValueAssignableTo() throws Exception { String exceptionId = "excId"; ExceptionJson ej = new ExceptionJson(exceptionId); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertTrue(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT.getName(), String.class)); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_EXCEPTION_TEXT.getName(), Boolean.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertTrue(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), String.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), Boolean.class)); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), String.class)); - assertTrue(ej.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), String.class)); + assertTrue(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); } @SuppressWarnings("deprecation") diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java index 3081b0fcf..97263368a 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java @@ -22,8 +22,8 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -81,7 +81,7 @@ public void testGetReleaseDate() { } /** - * Test method for {@link org.spdx.storage.listedlicense.LicenseJsonTOC#addLicense(org.spdx.library.model.license.SpdxListedLicense, java.lang.String, java.lang.String, boolean)}. + * Test method for {@link org.spdx.storage.listedlicense.LicenseJsonTOC#addLicense(org.spdx.library.model.compat.v2.compat.v2.license.SpdxListedLicense, java.lang.String, java.lang.String, boolean)}. * @throws InvalidSPDXAnalysisException */ public void testAddLicense() throws InvalidSPDXAnalysisException { @@ -112,22 +112,22 @@ public void testAddLicense() throws InvalidSPDXAnalysisException { assertEquals(2, ljt.getLicenses().size()); LicenseJsonTOC.LicenseJson l1 = ljt.getLicenses().get(0); - assertTrue(l1.getDetailsUrl().startsWith(SpdxConstants.LISTED_LICENSE_URL)); + assertTrue(l1.getDetailsUrl().startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)); assertEquals(licJSONReference1.substring(2), l1.getDetailsUrl().substring(l1.getDetailsUrl().lastIndexOf('/') + 1)); assertEquals(licenseId1, l1.getLicenseId()); assertEquals(name1, l1.getName()); assertEquals(licHTMLReference1.substring(2), l1.getReference().substring(l1.getDetailsUrl().lastIndexOf('/') + 1)); - assertTrue(l1.getReference().startsWith(SpdxConstants.LISTED_LICENSE_URL)); + assertTrue(l1.getReference().startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)); assertEquals(0, l1.getReferenceNumber()); assertTrue(UnitTestHelper.isListsEqual(seeAlso1, l1.getSeeAlso())); LicenseJsonTOC.LicenseJson l2 = ljt.getLicenses().get(1); assertEquals(licJSONReference2.substring(2), l2.getDetailsUrl().substring(l2.getDetailsUrl().lastIndexOf('/') + 1)); - assertTrue(l2.getDetailsUrl().startsWith(SpdxConstants.LISTED_LICENSE_URL)); + assertTrue(l2.getDetailsUrl().startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)); assertEquals(licenseId2, l2.getLicenseId()); assertEquals(name2, l2.getName()); assertEquals(licHTMLReference2.substring(2), l2.getReference().substring(l2.getDetailsUrl().lastIndexOf('/') + 1)); - assertTrue(l2.getReference().startsWith(SpdxConstants.LISTED_LICENSE_URL)); + assertTrue(l2.getReference().startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)); assertEquals(1, l2.getReferenceNumber()); assertTrue(UnitTestHelper.isListsEqual(seeAlso2, l2.getSeeAlso())); } diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java index 2070ae5f3..dae0e8ff5 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java @@ -24,10 +24,10 @@ import java.util.Map; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.InvalidSpdxPropertyException; -import org.spdx.library.model.license.CrossRef; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.model.compat.v2.license.CrossRef; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,22 +42,22 @@ public class LicenseJsonTest extends TestCase { static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_LICENSE_ID.getName(), SpdxConstants.PROP_LICENSE_TEXT.getName(), - SpdxConstants.PROP_LICENSE_TEXT_HTML.getName(), - SpdxConstants.PROP_STD_LICENSE_NAME.getName(), SpdxConstants.RDFS_PROP_COMMENT.getName(), - SpdxConstants.PROP_STD_LICENSE_NOTICE.getName(), SpdxConstants.PROP_STD_LICENSE_HEADER_TEMPLATE.getName(), - SpdxConstants.PROP_LICENSE_HEADER_HTML.getName(), SpdxConstants.PROP_STD_LICENSE_TEMPLATE.getName(), - SpdxConstants.PROP_EXAMPLE.getName(), SpdxConstants.PROP_LIC_DEPRECATED_VERSION.getName() + SpdxConstantsCompatV2.PROP_LICENSE_ID.getName(), SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), + SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML.getName(), + SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME.getName(), SpdxConstantsCompatV2.RDFS_PROP_COMMENT.getName(), + SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE.getName(), SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE.getName(), + SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML.getName(), SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE.getName(), + SpdxConstantsCompatV2.PROP_EXAMPLE.getName(), SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION.getName() ); static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstants.PROP_STD_LICENSE_OSI_APPROVED.getName(), SpdxConstants.PROP_STD_LICENSE_FSF_LIBRE.getName(), - SpdxConstants.PROP_LIC_ID_DEPRECATED.getName() + SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED.getName(), SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE.getName(), + SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName() ); static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); - static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), - SpdxConstants.PROP_CROSS_REF.getName()); + static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), + SpdxConstantsCompatV2.PROP_CROSS_REF.getName()); static { PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); PROPERTY_VALUE_NAMES.addAll(BOOLEAN_PROPERTY_VALUE_NAMES); @@ -110,7 +110,7 @@ public void testSetTypedProperty() { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); try { - lj.setTypedProperty("TestPropertyName", "SpdxId22", SpdxConstants.CLASS_SPDX_ELEMENT); + lj.setTypedProperty("TestPropertyName", "SpdxId22", SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT); fail("This shouldn't work"); } catch (InvalidSPDXAnalysisException e) { // Expected @@ -307,7 +307,7 @@ public void testLegacyJson() throws Exception { for (String valueName:STRING_PROPERTY_VALUE_NAMES) { stringValues.put(valueName, "ValueFor"+valueName); json.append("\t\""); - if (SpdxConstants.RDFS_PROP_COMMENT.equals(valueName)) { + if (SpdxConstantsCompatV2.RDFS_PROP_COMMENT.equals(valueName)) { json.append("licenseComments"); // Legacy value } else { json.append(valueName); @@ -363,21 +363,21 @@ public void testRemoveProperty() throws InvalidSpdxPropertyException { public void testIsCollectionMembersAssignableTo() throws Exception { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); - assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstants.PROP_LICENSE_TEXT.getName(), String.class)); - assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstants.PROP_CROSS_REF.getName(), CrossRef.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); + assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), String.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_CROSS_REF.getName(), CrossRef.class)); } public void testIsPropertyValueAssignableTo() throws Exception { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertTrue(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LICENSE_TEXT.getName(), String.class)); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LICENSE_TEXT.getName(), Boolean.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); + assertTrue(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), String.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), Boolean.class)); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), String.class)); - assertTrue(lj.isPropertyValueAssignableTo(SpdxConstants.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), String.class)); + assertTrue(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); } public void testCopyFromLicense() throws Exception { diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java index 7abd4b564..698e4130c 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java @@ -24,13 +24,13 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.TypedValue; -import org.spdx.library.model.license.CrossRef; -import org.spdx.library.model.license.LicenseException; -import org.spdx.library.model.license.ListedLicenseException; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.license.CrossRef; +import org.spdx.library.model.compat.v2.license.LicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -87,13 +87,13 @@ public void testExists() throws Exception { public void testCreate() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE); - String result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_ID).get(); + slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_EXCEPTION_ID).get(); + slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); slll.close(); } @@ -142,34 +142,34 @@ public void testGetLicenseListVersion() throws Exception { public void testGetValue() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME).get(); + String result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); - result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME).get(); + result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); slll.close(); } public void testSetValue() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME).get(); + String result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); String newName = "new name"; - slll.setValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME, newName); - result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME).get(); + slll.setValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); - result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME).get(); + result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); - slll.setValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME, newName); - result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME).get(); + slll.setValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); slll.close(); } public void testCreateLicense() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE, null); + SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); assertEquals(APACHE_ID, result.getLicenseId()); assertEquals(APACHE_LICENSE_NAME, result.getName()); String licenseText = result.getLicenseText(); @@ -188,12 +188,12 @@ public void testCreateLicense() throws InvalidSPDXAnalysisException, InvalidLice assertTrue(lResult.size() > 0); assertTrue(lResult.get(0).length() > 10); assertTrue(result.getStandardLicenseHeader().length() > 100); - assertEquals(SpdxConstants.CLASS_SPDX_LISTED_LICENSE, (result.getType())); + assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, (result.getType())); } public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - LicenseException result = (LicenseException)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + LicenseException result = (LicenseException)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); assertEquals(ECOS_EXCEPTION_ID, result.getLicenseExceptionId()); assertEquals(ECOS_EXCEPTION_ID, result.getId()); assertTrue(result.getComment().length() > 5); @@ -203,7 +203,7 @@ public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLi List lResult = new ArrayList(result.getSeeAlso()); assertTrue(lResult.size() > 0); assertTrue(lResult.get(0).length() > 10); - assertEquals(SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, (result.getType())); + assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, (result.getType())); assertFalse(result.isDeprecated()); } @@ -211,14 +211,14 @@ public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLi public void testList() throws InvalidSPDXAnalysisException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); // Exception - ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); String seeAlso1 = "seeAlso1"; String seeAlso2 = "seeAlso2"; List seeAlsos = Arrays.asList(new String[]{seeAlso1, seeAlso2}); exception.setSeeAlso(seeAlsos); // getValueList List result = new ArrayList<>(); - Iterator resultIter = slll.listValues(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO); + Iterator resultIter = slll.listValues(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -226,29 +226,29 @@ public void testList() throws InvalidSPDXAnalysisException { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection String seeAlso3 = "seeAlso3"; - assertFalse(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.addValueToCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.addValueToCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // License ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE, copyManager); + SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); license.setSeeAlso(seeAlsos); // getValueList result.clear(); - resultIter = slll.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO); + resultIter = slll.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -256,24 +256,24 @@ public void testList() throws InvalidSPDXAnalysisException { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection - assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // license crossRefs license.getCrossRef().clear(); - assertEquals(0, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF)); + assertEquals(0, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); IModelStore simpleModelStore = new InMemSpdxStore(); String docUri = "http://some.other.doc"; CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); @@ -284,7 +284,7 @@ public void testList() throws InvalidSPDXAnalysisException { license.getCrossRef().add(crossRef1); license.getCrossRef().add(crossRef2); result.clear(); - resultIter = slll.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF); + resultIter = slll.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); List tvResult = new ArrayList<>(); while (resultIter.hasNext()) { TypedValue tv = (TypedValue)resultIter.next(); @@ -294,11 +294,11 @@ public void testList() throws InvalidSPDXAnalysisException { List result2 = (List)(List)Arrays.asList(license.getCrossRef().toArray()); assertEquals(2, result.size()); assertEquals(2, result2.size()); - assertEquals(2, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF)); + assertEquals(2, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, (List)(List)result)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, result2)); for (TypedValue tv:tvResult) { - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, tv)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); } for (CrossRef crossRef:crossRefs) { // collectionContains @@ -307,12 +307,12 @@ public void testList() throws InvalidSPDXAnalysisException { CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); crossRef3.setUrl("http://url3"); String newCrossRefId = slll.getNextId(IdType.Anonymous, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, newCrossRefId, SpdxConstants.CLASS_CROSS_REF); - slll.setValue(LICENSE_LIST_URI, newCrossRefId, SpdxConstants.PROP_CROSS_REF_URL, "http://url3"); - TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstants.CLASS_CROSS_REF); - slll.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv); - assertEquals(3, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv)); + slll.create(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); + slll.setValue(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); + TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); + slll.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertEquals(3, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); boolean found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -321,8 +321,8 @@ public void testList() throws InvalidSPDXAnalysisException { } } assertTrue(found); - slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv); - assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv)); + slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -335,45 +335,45 @@ public void testList() throws InvalidSPDXAnalysisException { public void testIsCollectionMembersAssignableTo() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, String.class)); - assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, Boolean.class)); - assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LICENSE_TEXT, String.class)); - assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, CrossRef.class)); - assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, String.class)); + assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, Boolean.class)); + assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); + assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); + assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, String.class)); slll.close(); } public void testIsPropertyValueAssignableTo() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, String.class)); - assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LICENSE_TEXT, String.class)); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LICENSE_TEXT, Boolean.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, Boolean.class)); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LIC_ID_DEPRECATED, String.class)); - assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LIC_ID_DEPRECATED, Boolean.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class)); + assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class)); slll.close(); } public void testIsCollectionProperty() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertTrue(slll.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LIC_ID_DEPRECATED)); + assertTrue(slll.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED)); slll.close(); } public void testDelete() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE); - String result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_ID).get(); + slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); assertTrue(slll.exists(LICENSE_LIST_URI, nextId)); slll.delete(LICENSE_LIST_URI, nextId); assertFalse(slll.exists(LICENSE_LIST_URI, nextId)); nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_EXCEPTION_ID).get(); + slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); assertTrue(slll.exists(LICENSE_LIST_URI, nextId)); slll.delete(LICENSE_LIST_URI, nextId); diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java index 167519a5c..ba148b714 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java @@ -24,13 +24,13 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.TypedValue; -import org.spdx.library.model.license.CrossRef; -import org.spdx.library.model.license.LicenseException; -import org.spdx.library.model.license.ListedLicenseException; -import org.spdx.library.model.license.SpdxListedLicense; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.model.compat.v2.license.CrossRef; +import org.spdx.library.model.compat.v2.license.LicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -86,13 +86,13 @@ public void testExists() throws Exception { public void testCreate() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE); - String result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_ID).get(); + sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_EXCEPTION_ID).get(); + sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); sllw.close(); } @@ -165,34 +165,34 @@ int compareVersionStrings(String versionA, String versionB) { public void testGetValue() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME).get(); + String result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); - result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME).get(); + result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); sllw.close(); } public void testSetValue() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME).get(); + String result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); String newName = "new name"; - sllw.setValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME, newName); - result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_NAME).get(); + sllw.setValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); - result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME).get(); + result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); - sllw.setValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME, newName); - result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.PROP_NAME).get(); + sllw.setValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); sllw.close(); } public void testCreateLicense() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE, null); + SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); assertEquals(APACHE_ID, result.getLicenseId()); assertEquals(APACHE_LICENSE_NAME, result.getName()); String licenseText = result.getLicenseText(); @@ -212,13 +212,13 @@ public void testCreateLicense() throws Exception { assertTrue(lResult.size() > 0); assertTrue(lResult.get(0).length() > 10); assertTrue(result.getStandardLicenseHeader().length() > 100); - assertEquals(SpdxConstants.CLASS_SPDX_LISTED_LICENSE, (result.getType())); + assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, (result.getType())); } @SuppressWarnings("deprecation") public void testCreateException() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - LicenseException result = (LicenseException)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + LicenseException result = (LicenseException)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); assertEquals(ECOS_EXCEPTION_ID, result.getLicenseExceptionId()); assertEquals(ECOS_EXCEPTION_ID, result.getId()); assertTrue(result.getComment().length() > 5); @@ -231,7 +231,7 @@ public void testCreateException() throws Exception { List lResult = new ArrayList(result.getSeeAlso()); assertTrue(lResult.size() > 0); assertTrue(lResult.get(0).length() > 10); - assertEquals(SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, (result.getType())); + assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, (result.getType())); assertFalse(result.isDeprecated()); } @@ -239,14 +239,14 @@ public void testCreateException() throws Exception { public void testList() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); // Exception - ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); String seeAlso1 = "seeAlso1"; String seeAlso2 = "seeAlso2"; List seeAlsos = Arrays.asList(new String[]{seeAlso1, seeAlso2}); exception.setSeeAlso(seeAlsos); // getValueList List result = new ArrayList<>(); - Iterator resultIter = sllw.listValues(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO); + Iterator resultIter = sllw.listValues(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -254,29 +254,29 @@ public void testList() throws Exception { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection String seeAlso3 = "seeAlso3"; - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // License ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstants.CLASS_SPDX_LISTED_LICENSE, copyManager); + SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); license.setSeeAlso(seeAlsos); // getValueList result.clear(); - resultIter = sllw.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO); + resultIter = sllw.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -284,24 +284,24 @@ public void testList() throws Exception { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // license crossRefs license.getCrossRef().clear(); - assertEquals(0, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF)); + assertEquals(0, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); IModelStore simpleModelStore = new InMemSpdxStore(); String docUri = "http://some.other.doc"; CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); @@ -312,7 +312,7 @@ public void testList() throws Exception { license.getCrossRef().add(crossRef1); license.getCrossRef().add(crossRef2); result.clear(); - resultIter = sllw.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF); + resultIter = sllw.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); List tvResult = new ArrayList<>(); while (resultIter.hasNext()) { TypedValue tv = (TypedValue)resultIter.next(); @@ -322,11 +322,11 @@ public void testList() throws Exception { List result2 = (List)(List)Arrays.asList(license.getCrossRef().toArray()); assertEquals(2, result.size()); assertEquals(2, result2.size()); - assertEquals(2, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF)); + assertEquals(2, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, (List)(List)result)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, result2)); for (TypedValue tv:tvResult) { - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, tv)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); } for (CrossRef crossRef:crossRefs) { // collectionContains @@ -335,12 +335,12 @@ public void testList() throws Exception { CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); crossRef3.setUrl("http://url3"); String newCrossRefId = sllw.getNextId(IdType.Anonymous, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, newCrossRefId, SpdxConstants.CLASS_CROSS_REF); - sllw.setValue(LICENSE_LIST_URI, newCrossRefId, SpdxConstants.PROP_CROSS_REF_URL, "http://url3"); - TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstants.CLASS_CROSS_REF); - sllw.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv); - assertEquals(3, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv)); + sllw.create(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); + sllw.setValue(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); + TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); + sllw.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertEquals(3, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); boolean found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -349,8 +349,8 @@ public void testList() throws Exception { } } assertTrue(found); - sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, newCrossRefTv)); + sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -364,26 +364,26 @@ public void testList() throws Exception { public void testIsCollectionProperty() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - assertTrue(sllw.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_LIC_ID_DEPRECATED)); - assertTrue(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, CrossRef.class)); - assertFalse(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstants.PROP_CROSS_REF, String.class)); + assertTrue(sllw.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED)); + assertTrue(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); + assertFalse(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, String.class)); sllw.close(); } public void testDelete() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE); - String result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_ID).get(); + sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); assertTrue(sllw.exists(LICENSE_LIST_URI, nextId)); sllw.delete(LICENSE_LIST_URI, nextId); assertFalse(sllw.exists(LICENSE_LIST_URI, nextId)); nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstants.PROP_LICENSE_EXCEPTION_ID).get(); + sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); assertTrue(sllw.exists(LICENSE_LIST_URI, nextId)); sllw.delete(LICENSE_LIST_URI, nextId); diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index 19901c519..b263a54f7 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -34,9 +34,9 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.SpdxIdInUseException; -import org.spdx.library.model.TypedValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -60,18 +60,18 @@ public class InMemSpdxStoreTest extends TestCase { static final String TEST_ID1 = "id1"; static final String TEST_ID2 = "id2"; - static final String TEST_TYPE1 = SpdxConstants.CLASS_ANNOTATION; - static final String TEST_TYPE2 = SpdxConstants.CLASS_RELATIONSHIP; + static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_ANNOTATION; + static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_RELATIONSHIP; static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("valueProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp3", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp4", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("valueProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp4", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final Object[] TEST_VALUE_PROPERTY_VALUES = new Object[] {"value1", true, "value2", null}; static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("listProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp3", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("listProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; protected static final int MAX_RETRIES = 10; TypedValue[] TEST_TYPED_PROP_VALUES; @@ -113,30 +113,30 @@ public void testUpdateNextIds() throws InvalidSPDXAnalysisException { // License ID's String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); assertEquals("LicenseRef-gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, "LicenseRef-gnrtd33", SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); assertEquals("LicenseRef-gnrtd34", nextId); // SPDX ID's nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); assertEquals("SPDXRef-gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, "SPDXRef-gnrtd33", SpdxConstants.CLASS_SPDX_FILE); + store.create(TEST_DOCUMENT_URI1, "SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE); nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); assertEquals("SPDXRef-gnrtd34", nextId); // Anonymous ID's nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstants.CLASS_SPDX_CHECKSUM); + store.create(TEST_DOCUMENT_URI1, InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM); nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd34", nextId); // Document ID's nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstants.CLASS_EXTERNAL_DOC_REF); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + store.create(TEST_DOCUMENT_URI1, SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF); nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); } public void testCreateExists() throws InvalidSPDXAnalysisException { @@ -147,17 +147,17 @@ public void testCreateExists() throws InvalidSPDXAnalysisException { assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI2, id2, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI2, id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); @@ -166,9 +166,9 @@ public void testCreateExists() throws InvalidSPDXAnalysisException { public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1).size()); assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); @@ -203,9 +203,9 @@ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { public void testGetSetValue() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); @@ -219,9 +219,9 @@ public void testGetSetValue() throws InvalidSPDXAnalysisException { public void testGetAddValueList() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); @@ -264,16 +264,16 @@ public void testGetNextId() throws InvalidSPDXAnalysisException { // Document ID's nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstants.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); } public void testRemoveProperty() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); @@ -337,9 +337,9 @@ private void assertCollectionsEquals(Object c1, Object c2) { public void testClearList() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); @@ -358,7 +358,7 @@ public void testClearList() throws InvalidSPDXAnalysisException { public void copyFrom() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); String value1 = "value1"; String value2 = "value2"; store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); @@ -366,7 +366,7 @@ public void copyFrom() throws InvalidSPDXAnalysisException { store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); InMemSpdxStore store2 = new InMemSpdxStore(); ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store2, TEST_DOCUMENT_URI2, store, TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + copyManager.copy(store2, TEST_DOCUMENT_URI2, store, TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0])); assertEquals(2, toImmutableList(store2.listValues(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); @@ -375,7 +375,7 @@ public void copyFrom() throws InvalidSPDXAnalysisException { public void testRemoveListItem() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); String value1 = "value1"; String value2 = "value2"; store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); @@ -393,7 +393,7 @@ public void testRemoveListItem() throws InvalidSPDXAnalysisException { //TODO: Fix the following test - it is flakey. Times out about 1 out of 5 times. Test problem, not a problem with the code under test public void testLock() throws InvalidSPDXAnalysisException, IOException, InterruptedException, TimeoutException { final InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); String value1 = "value1"; String value2 = "value2"; IModelStoreLock lock = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); @@ -517,9 +517,9 @@ public void run() { public void testCollectionSize() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); @@ -533,9 +533,9 @@ public void testCollectionSize() throws InvalidSPDXAnalysisException { public void testCollectionContains() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); @@ -552,21 +552,21 @@ public void testCollectionContains() throws InvalidSPDXAnalysisException { public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); TypedValue tv = new TypedValue(TEST_ID2, TEST_TYPE2); store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); @@ -574,29 +574,29 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); } public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 2"); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(false)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); TypedValue tv = new TypedValue(TEST_ID2, TEST_TYPE2); store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); @@ -604,14 +604,14 @@ public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisExcept assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); // Mixed - PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.valueOf(true)); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, "mixed value"); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, String.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, TypedValue.class)); // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, Boolean.class)); assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, TypedValue.class)); @@ -619,11 +619,11 @@ public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisExcept public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, listProperty, "testValue"); assertTrue(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, listProperty)); assertFalse(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, sProperty)); @@ -632,24 +632,24 @@ public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { public void testIdType() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); assertEquals(IdType.Anonymous, store.getIdType(InMemSpdxStore.ANON_PREFIX+"gnrtd23")); - assertEquals(IdType.DocumentRef, store.getIdType(SpdxConstants.EXTERNAL_DOC_REF_PRENUM+"gnrtd23")); - assertEquals(IdType.LicenseRef, store.getIdType(SpdxConstants.NON_STD_LICENSE_ID_PRENUM+"gnrtd23")); + assertEquals(IdType.DocumentRef, store.getIdType(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"gnrtd23")); + assertEquals(IdType.LicenseRef, store.getIdType(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"gnrtd23")); assertEquals(IdType.ListedLicense, store.getIdType("Apache-2.0")); assertEquals(IdType.ListedLicense, store.getIdType("LLVM-exception")); assertEquals(IdType.Literal, store.getIdType("NONE")); assertEquals(IdType.Literal, store.getIdType("NOASSERTION")); - assertEquals(IdType.SpdxId, store.getIdType(SpdxConstants.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); + assertEquals(IdType.SpdxId, store.getIdType(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); } public void testGetCaseSensisitiveId() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); String expected = "TestIdOne"; String lower = expected.toLowerCase(); - store.create(TEST_DOCUMENT_URI1, expected, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, expected, SpdxConstantsCompatV2.CLASS_ANNOTATION); assertEquals(expected, store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, lower).get()); assertFalse(store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, "somethingNotThere").isPresent()); try { - store.create(TEST_DOCUMENT_URI1, lower, SpdxConstants.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, lower, SpdxConstantsCompatV2.CLASS_ANNOTATION); fail("This should be a duplicate ID failure"); } catch (InvalidSPDXAnalysisException e) { // expected @@ -658,8 +658,8 @@ public void testGetCaseSensisitiveId() throws InvalidSPDXAnalysisException { public void testGetTypedValue() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstants.CLASS_ANNOTATION); - assertEquals(SpdxConstants.CLASS_ANNOTATION, store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID1).get().getType()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertEquals(SpdxConstantsCompatV2.CLASS_ANNOTATION, store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID1).get().getType()); assertFalse(store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID2).isPresent()); assertFalse(store.getTypedValue(TEST_DOCUMENT_URI2, TEST_ID1).isPresent()); } @@ -672,9 +672,9 @@ public void testDelete() throws InvalidSPDXAnalysisException { assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI2, id2, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI2, id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); @@ -693,19 +693,19 @@ public void testDeleteInUse() throws InvalidSPDXAnalysisException { String id2 = "testId2"; String id3 = "testId3"; String id4 = "testId4"; - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id2, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id3, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id4, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - TypedValue tv3 = new TypedValue(id3, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + TypedValue tv3 = new TypedValue(id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); store.addValueToCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstants.SPDX_NAMESPACE), tv3); - TypedValue tv4 = new TypedValue(id4, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv3); + TypedValue tv4 = new TypedValue(id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); store.addValueToCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstants.SPDX_NAMESPACE), tv4); + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); store.setValue(TEST_DOCUMENT_URI1, id3, - new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE), - new TypedValue(id1, SpdxConstants.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); + new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new TypedValue(id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); try { store.delete(TEST_DOCUMENT_URI1, id3); @@ -726,7 +726,7 @@ public void testDeleteInUse() throws InvalidSPDXAnalysisException { // expected - id1 is in the property for id3 } store.removeValueFromCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstants.SPDX_NAMESPACE), tv4); + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); store.delete(TEST_DOCUMENT_URI1, id4); assertFalse(store.exists(TEST_DOCUMENT_URI1, id4)); try { @@ -736,7 +736,7 @@ public void testDeleteInUse() throws InvalidSPDXAnalysisException { // expected - id3 is in the listProperty for id2 } store.removeProperty(TEST_DOCUMENT_URI1, id3, - new PropertyDescriptor("property", SpdxConstants.SPDX_NAMESPACE)); + new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE)); store.delete(TEST_DOCUMENT_URI1, id1); assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); store.delete(TEST_DOCUMENT_URI1, id2); @@ -753,22 +753,22 @@ public void testReferenceCounts() throws Exception { assertEquals(0, item.getReferenceCount()); TypedValue tv = new TypedValue(TEST_ID1, TEST_TYPE1); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop1", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(2, item.getReferenceCount()); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop3", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop3", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(3, item.getReferenceCount()); store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE)); + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE)); assertEquals(2, item.getReferenceCount()); store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop1", SpdxConstants.SPDX_NAMESPACE)); + new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE)); assertEquals(0, item.getReferenceCount()); store.delete(TEST_DOCUMENT_URI1, TEST_ID1); } @@ -781,13 +781,13 @@ public void testReferenceCountsDelete() throws Exception { assertEquals(0, item.getReferenceCount()); TypedValue tv = new TypedValue(TEST_ID1, TEST_TYPE1); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop1", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(2, item.getReferenceCount()); store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop3", SpdxConstants.SPDX_NAMESPACE), tv); + new PropertyDescriptor("prop3", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(3, item.getReferenceCount()); store.delete(TEST_DOCUMENT_URI1, TEST_ID2); assertEquals(0, item.getReferenceCount()); diff --git a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java index 46cb687f2..f14616455 100644 --- a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java +++ b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java @@ -21,9 +21,9 @@ import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.TypedValue; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; @@ -36,20 +36,20 @@ public class StoredTypedItemTest extends TestCase { static final String TEST_ID1 = "TestID1"; static final String TEST_ID2 = "TestID2"; - static final String TEST_TYPE1 = SpdxConstants.CLASS_ANNOTATION; - static final String TEST_TYPE2 = SpdxConstants.CLASS_RELATIONSHIP; + static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_ANNOTATION; + static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_RELATIONSHIP; static final String TEST_DOCUMENTURI1 = "https://test.doc.uri1"; static final String TEST_DOCUMENTURI2 = "https://test.doc.uri2"; static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("valueProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp3", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp4", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("valueProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp4", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; static final Object[] TEST_VALUE_PROPERTY_VALUES = new Object[] {"value1", true, "value2", null}; static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("listProp1", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp2", SpdxConstants.SPDX_NAMESPACE), - new PropertyDescriptor("listProp3", SpdxConstants.SPDX_NAMESPACE)}; + new PropertyDescriptor("listProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; List[] TEST_LIST_PROPERTY_VALUES; /* (non-Javadoc) @@ -220,34 +220,34 @@ public void testCollectionContains() throws InvalidSPDXAnalysisException { public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(sProperty, "String 1"); sti.addValueToList(sProperty, "String 2"); assertTrue(sti.isCollectionMembersAssignableTo(sProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(sProperty, Boolean.class)); assertFalse(sti.isCollectionMembersAssignableTo(sProperty, TypedValue.class)); // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(bProperty, Boolean.valueOf(true)); sti.addValueToList(bProperty, Boolean.valueOf(false)); assertFalse(sti.isCollectionMembersAssignableTo(bProperty, String.class)); assertTrue(sti.isCollectionMembersAssignableTo(bProperty, Boolean.class)); assertFalse(sti.isCollectionMembersAssignableTo(bProperty, TypedValue.class)); // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, Boolean.class)); assertTrue(sti.isCollectionMembersAssignableTo(tvProperty, Relationship.class)); // Mixed - PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(mixedProperty, Boolean.valueOf(true)); sti.addValueToList(mixedProperty, "mixed value"); assertFalse(sti.isCollectionMembersAssignableTo(mixedProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(mixedProperty, Boolean.class)); assertFalse(sti.isCollectionMembersAssignableTo(mixedProperty, TypedValue.class)); // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); assertTrue(sti.isCollectionMembersAssignableTo(emptyProperty, String.class)); assertTrue(sti.isCollectionMembersAssignableTo(emptyProperty, Boolean.class)); assertTrue(sti.isCollectionMembersAssignableTo(emptyProperty, TypedValue.class)); @@ -256,34 +256,34 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); assertTrue(sti.isPropertyValueAssignableTo(sProperty, String.class)); assertFalse(sti.isPropertyValueAssignableTo(sProperty, Boolean.class)); assertFalse(sti.isPropertyValueAssignableTo(sProperty, TypedValue.class)); // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(bProperty, Boolean.valueOf(true)); assertFalse(sti.isPropertyValueAssignableTo(bProperty, String.class)); assertTrue(sti.isPropertyValueAssignableTo(bProperty, Boolean.class)); assertFalse(sti.isPropertyValueAssignableTo(bProperty, TypedValue.class)); // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); assertFalse(sti.isPropertyValueAssignableTo(tvProperty, String.class)); assertFalse(sti.isPropertyValueAssignableTo(tvProperty, Boolean.class)); assertTrue(sti.isPropertyValueAssignableTo(tvProperty, TypedValue.class)); // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); assertFalse(sti.isPropertyValueAssignableTo(emptyProperty, String.class)); } public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); - PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstants.SPDX_NAMESPACE); + PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(listProperty, "testValue"); assertTrue(sti.isCollectionProperty(listProperty)); assertFalse(sti.isCollectionProperty(sProperty)); diff --git a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java index 3419e331a..2840957f6 100644 --- a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java +++ b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java @@ -31,16 +31,16 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.LicenseInfoFactory; -import org.spdx.library.model.license.ListedLicenses; -import org.spdx.library.model.license.ListedLicenseException; -import org.spdx.library.model.license.SpdxListedLicense; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.library.model.compat.v2.license.ListedLicenses; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.utility.compare.CompareTemplateOutputHandler.DifferenceDescription; import org.spdx.utility.compare.FilterTemplateOutputHandler.VarTextHandling; diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index 1625e0501..ce7c5b519 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -32,40 +32,40 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.ExternalDocumentRef; -import org.spdx.library.model.GenericModelObject; -import org.spdx.library.model.GenericSpdxElement; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxCreatorInformation; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxElement; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.SpdxModelFactory; -import org.spdx.library.model.SpdxPackage; -import org.spdx.library.model.SpdxPackageVerificationCode; -import org.spdx.library.model.SpdxSnippet; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ConjunctiveLicenseSet; -import org.spdx.library.model.license.DisjunctiveLicenseSet; -import org.spdx.library.model.license.ExtractedLicenseInfo; -import org.spdx.library.model.license.InvalidLicenseStringException; -import org.spdx.library.model.license.License; -import org.spdx.library.model.license.LicenseInfoFactory; -import org.spdx.library.model.license.LicenseSet; -import org.spdx.library.model.license.SpdxListedLicense; -import org.spdx.library.model.license.SpdxNoAssertionLicense; -import org.spdx.library.model.license.SpdxNoneLicense; -import org.spdx.library.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalDocumentRef; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxCreatorInformation; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.license.InvalidLicenseStringException; +import org.spdx.library.model.compat.v2.license.License; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.license.LicenseSet; +import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; @@ -238,7 +238,7 @@ public void setUp() throws Exception { DefaultModelStore.reset(); GenericModelObject gmo = new GenericModelObject(); - DATALICENSE = LicenseInfoFactory.parseSPDXLicenseString(SpdxConstants.SPDX_DATA_LICENSE_ID); + DATALICENSE = LicenseInfoFactory.parseSPDXLicenseString(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID); LICENSEA1 = new ExtractedLicenseInfo("LicenseRef-1", "License1"); LICENSEA2 = new ExtractedLicenseInfo("LicenseRef-2", "License2"); LICENSEA3 = new ExtractedLicenseInfo("LicenseRef-3", "License3"); @@ -937,7 +937,7 @@ public void testIsDataLicenseEqual() throws IOException, InvalidSPDXAnalysisExce assertFalse(comparer.isDifferenceFound()); assertTrue(comparer.isDataLicenseEqual()); doc2.setSpecVersion("SPDX-1.0"); - doc2.setDataLicense(LicenseInfoFactory.getListedLicenseById(SpdxConstants.SPDX_DATA_LICENSE_ID_VERSION_1_0)); + doc2.setDataLicense(LicenseInfoFactory.getListedLicenseById(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID_VERSION_1_0)); comparer.compare(doc1, doc2); assertTrue(comparer.isDifferenceFound()); assertFalse(comparer.isDataLicenseEqual()); @@ -980,7 +980,7 @@ public void testIsExtractedLicensingInfosEqual() throws IOException, InvalidSPDX int doc1id = 100; int doc2id = 200; - String id1_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id1_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text1 = "License text 1"; String name1 = "licname1"; Collection crossReff1 = new HashSet<>(Arrays.asList(new String[] {"http://cross.ref.one"})); @@ -990,14 +990,14 @@ public void testIsExtractedLicensingInfosEqual() throws IOException, InvalidSPDX lic1_1.setName(name1); lic1_1.setSeeAlso(crossReff1); lic1_1.setComment(comment1); - String id1_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id1_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic1_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id1_2, doc2.getCopyManager(), true); lic1_2.setExtractedText(text1); lic1_2.setName(name1); lic1_2.setSeeAlso(crossReff1); lic1_2.setComment(comment1); - String id2_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id2_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text2 = "License text 2"; String name2 = "licname2"; Collection crossReff2 = new HashSet<>(Arrays.asList(new String[] {"http://cross.ref.one", "http://cross.ref.two"})); @@ -1007,14 +1007,14 @@ public void testIsExtractedLicensingInfosEqual() throws IOException, InvalidSPDX lic2_1.setName(name2); lic2_1.setSeeAlso(crossReff2); lic2_1.setComment(comment2); - String id2_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id2_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic2_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id2_2, doc2.getCopyManager(), true); lic2_2.setExtractedText(text2); lic2_2.setName(name2); lic2_2.setSeeAlso(crossReff2); lic2_2.setComment(comment2); - String id3_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id3_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text3 = "License text 3"; String name3 = ""; Collection crossReff3 = new HashSet<>(); @@ -1025,14 +1025,14 @@ public void testIsExtractedLicensingInfosEqual() throws IOException, InvalidSPDX lic3_1.setSeeAlso(crossReff3); lic3_1.setComment(comment3); - String id3_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id3_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic3_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id3_2, doc2.getCopyManager(), true); lic3_2.setExtractedText(text3); lic3_2.setName(name3); lic3_2.setSeeAlso(crossReff3); lic3_2.setComment(comment3); - String id4_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id4_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text4 = "License text 4"; String name4 = ""; Collection crossReff4 = new HashSet<>(); @@ -1043,7 +1043,7 @@ public void testIsExtractedLicensingInfosEqual() throws IOException, InvalidSPDX lic4_1.setSeeAlso(crossReff4); lic4_1.setComment(comment4); - String id4_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id4_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic4_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id4_2, doc2.getCopyManager(), true); lic4_2.setExtractedText(text4); lic4_2.setName(name4); @@ -1199,7 +1199,7 @@ public void testGetUniqueExtractedLicenses() throws IOException, InvalidSPDXAnal int doc1id = 100; int doc2id = 200; - String id1_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id1_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text1 = "License text 1"; String name1 = "licname1"; Collection crossReff1 = new HashSet<>(Arrays.asList(new String[] {"http://cross.ref.one"})); @@ -1208,13 +1208,13 @@ public void testGetUniqueExtractedLicenses() throws IOException, InvalidSPDXAnal lic1_1.setName(name1); lic1_1.setSeeAlso(crossReff1); lic1_1.setComment(comment1); - String id1_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id1_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic1_2 = new ExtractedLicenseInfo(id1_2, text1); lic1_1.setName(name1); lic1_1.setSeeAlso(crossReff1); lic1_1.setComment(comment1); - String id2_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id2_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text2 = "License text 2"; String name2 = "licname2"; Collection crossReff2 = new HashSet<>(Arrays.asList(new String[] {"http://cross.ref.one", "http://cross.ref.two"})); @@ -1223,13 +1223,13 @@ public void testGetUniqueExtractedLicenses() throws IOException, InvalidSPDXAnal lic1_1.setName(name2); lic1_1.setSeeAlso(crossReff2); lic1_1.setComment(comment2); - String id2_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id2_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic2_2 = new ExtractedLicenseInfo(id2_2, text2); lic1_1.setName(name2); lic1_1.setSeeAlso(crossReff2); lic1_1.setComment(comment2); - String id3_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id3_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text3 = "License text 3"; String name3 = ""; Collection crossReff3 = new HashSet<>(); @@ -1239,13 +1239,13 @@ public void testGetUniqueExtractedLicenses() throws IOException, InvalidSPDXAnal lic1_1.setSeeAlso(crossReff3); lic1_1.setComment(comment3); - String id3_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id3_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic3_2 = new ExtractedLicenseInfo(id3_2, text3); lic1_1.setName(name3); lic1_1.setSeeAlso(crossReff3); lic1_1.setComment(comment3); - String id4_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id4_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text4 = "License text 4"; String name4 = ""; Collection crossReff4 = new HashSet<>(); @@ -1255,7 +1255,7 @@ public void testGetUniqueExtractedLicenses() throws IOException, InvalidSPDXAnal lic1_1.setSeeAlso(crossReff4); lic1_1.setComment(comment4); - String id4_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id4_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic4_2 = new ExtractedLicenseInfo(id4_2, text4); lic1_1.setName(name4); lic1_1.setSeeAlso(crossReff4); @@ -1347,7 +1347,7 @@ public void testGetExtractedLicenseDifferences() throws IOException, InvalidSPDX int doc1id = 100; int doc2id = 200; - String id1_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id1_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text1 = "License text 1"; String name1 = "licname1"; Collection crossReff1 = new HashSet<>(Arrays.asList(new String[] {"http://cross.ref.one"})); @@ -1357,14 +1357,14 @@ public void testGetExtractedLicenseDifferences() throws IOException, InvalidSPDX lic1_1.setName(name1); lic1_1.setSeeAlso(crossReff1); lic1_1.setComment(comment1); - String id1_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id1_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic1_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id1_2, doc2.getCopyManager(), true); lic1_2.setExtractedText(text1); lic1_2.setName(name1); lic1_2.setSeeAlso(crossReff1); lic1_2.setComment(comment1); - String id2_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id2_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text2 = "License text 2"; String name2 = "licname2"; Collection crossReff2 = new HashSet<>(Arrays.asList(new String[] {"http://cross.ref.one", "http://cross.ref.two"})); @@ -1374,14 +1374,14 @@ public void testGetExtractedLicenseDifferences() throws IOException, InvalidSPDX lic2_1.setName(name2); lic2_1.setSeeAlso(crossReff2); lic2_1.setComment(comment2); - String id2_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id2_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic2_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id2_2, doc2.getCopyManager(), true); lic2_2.setExtractedText(text2); lic2_2.setName(name2); lic2_2.setSeeAlso(crossReff2); lic2_2.setComment(comment2); - String id3_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id3_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text3 = "License text 3"; String name3 = ""; Collection crossReff3 = new HashSet<>(); @@ -1392,14 +1392,14 @@ public void testGetExtractedLicenseDifferences() throws IOException, InvalidSPDX lic3_1.setSeeAlso(crossReff3); lic3_1.setComment(comment3); - String id3_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id3_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic3_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id3_2, doc2.getCopyManager(), true); lic3_2.setExtractedText(text3); lic3_2.setName(name3); lic3_2.setSeeAlso(crossReff3); lic3_2.setComment(comment3); - String id4_1 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); + String id4_1 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc1id++); String text4 = "License text 4"; String name4 = ""; Collection crossReff4 = new HashSet<>(); @@ -1410,7 +1410,7 @@ public void testGetExtractedLicenseDifferences() throws IOException, InvalidSPDX lic4_1.setSeeAlso(crossReff4); lic4_1.setComment(comment4); - String id4_2 = SpdxConstants.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); + String id4_2 = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + Integer.toString(doc2id++); ExtractedLicenseInfo lic4_2 = new ExtractedLicenseInfo(doc2.getModelStore(), doc2.getDocumentUri(), id4_2, doc2.getCopyManager(), true); lic4_2.setExtractedText(text4); lic4_2.setName(name4); diff --git a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java index 24fdb39ea..fabccc7fe 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java @@ -27,15 +27,15 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.InvalidLicenseStringException; -import org.spdx.library.model.license.License; -import org.spdx.library.model.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.InvalidLicenseStringException; +import org.spdx.library.model.compat.v2.license.License; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java index 50308a479..e79940c99 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java @@ -23,18 +23,18 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.GenericModelObject; -import org.spdx.library.model.GenericSpdxElement; -import org.spdx.library.model.GenericSpdxItem; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxElement; -import org.spdx.library.model.SpdxItem; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.GenericSpdxItem; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java index 8069d9a2c..eeea55a4a 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java @@ -25,26 +25,26 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.Annotation; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.ExternalRef; -import org.spdx.library.model.GenericModelObject; -import org.spdx.library.model.GenericSpdxItem; -import org.spdx.library.model.ReferenceType; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxElement; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxPackage; -import org.spdx.library.model.SpdxPackageVerificationCode; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.license.AnyLicenseInfo; -import org.spdx.library.model.license.ExtractedLicenseInfo; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ExternalRef; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxItem; +import org.spdx.library.model.compat.v2.ReferenceType; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import junit.framework.TestCase; @@ -324,7 +324,7 @@ public void setUp() throws Exception { TEST_REFERENCES = new ExternalRef[REFERENCE_CATEGORIES.length]; for (int i = 0; i < REFERENCE_CATEGORIES.length; i++) { TEST_REFERENCES[i] = gmo.createExternalRef(REFERENCE_CATEGORIES[i], - new ReferenceType(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[i]), + new ReferenceType(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + REFERENCE_TYPE_NAMES[i]), REFERENCE_LOCATORS[i], COMMENTS[i]); } Arrays.sort(TEST_REFERENCES); diff --git a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java index bf22de2f5..2885581a5 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java @@ -24,20 +24,20 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.Checksum; -import org.spdx.library.model.GenericModelObject; -import org.spdx.library.model.Relationship; -import org.spdx.library.model.SpdxDocument; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxSnippet; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -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.model.pointer.ByteOffsetPointer; -import org.spdx.library.model.pointer.LineCharPointer; -import org.spdx.library.model.pointer.StartEndPointer; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; +import org.spdx.library.model.compat.v2.pointer.LineCharPointer; +import org.spdx.library.model.compat.v2.pointer.StartEndPointer; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java index 34fc7d6db..b2c25efb9 100644 --- a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java +++ b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java @@ -31,8 +31,8 @@ import java.net.URLConnection; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.ModelObject; -import org.spdx.library.model.SpdxDocument; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; /** * Helper class for unit tests diff --git a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java index b8e2c8281..c09520383 100644 --- a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java +++ b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java @@ -7,11 +7,11 @@ import java.util.Collection; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.SpdxFile; -import org.spdx.library.model.SpdxPackageVerificationCode; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.license.SpdxNoAssertionLicense; +import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; From e51a0739dea9cd87598364c2f286eea1b16d71a7 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sun, 4 Jun 2023 11:03:01 -0700 Subject: [PATCH 03/62] Change model factory to take into account SPDX versions Signed-off-by: Gary O'Neall --- README-V3-UPGRADE.md | 23 ++ README.md | 7 +- .../v2 => }/InvalidSpdxPropertyException.java | 4 +- .../org/spdx/library/ModelCopyManager.java | 1 - src/main/java/org/spdx/library/Read.java | 2 - .../v2 => }/SpdxIdNotFoundException.java | 4 +- .../v2 => }/SpdxInvalidTypeException.java | 4 +- .../org/spdx/library/SpdxModelFactory.java | 288 ++++++++++++++++ .../{model/compat/v2 => }/TypedValue.java | 7 +- src/main/java/org/spdx/library/Version.java | 7 +- .../library/model/compat/v2/Annotation.java | 1 + .../library/model/compat/v2/Checksum.java | 1 + .../model/compat/v2/ExternalDocumentRef.java | 2 + .../model/compat/v2/ModelCollection.java | 2 + .../library/model/compat/v2/ModelObject.java | 4 + .../compat/v2/ModelStorageClassConverter.java | 3 + .../library/model/compat/v2/Relationship.java | 1 + .../library/model/compat/v2/SpdxDocument.java | 1 + .../model/compat/v2/SpdxModelFactory.java | 319 ------------------ .../library/model/compat/v2/SpdxPackage.java | 1 + .../library/model/compat/v2/SpdxSnippet.java | 1 + .../license/AbstractExtractedLicenseInfo.java | 2 +- .../v2/license/ConjunctiveLicenseSet.java | 2 +- .../v2/license/DisjunctiveLicenseSet.java | 2 +- .../v2/license/ExtractedLicenseInfo.java | 2 +- .../model/compat/v2/license/License.java | 2 +- .../compat/v2/license/LicenseException.java | 2 +- .../v2/license/LicenseExpressionParser.java | 4 +- .../model/compat/v2/license/LicenseSet.java | 2 +- .../compat/v2/license/ListedLicenses.java | 2 +- .../compat/v2/license/OrLaterOperator.java | 2 +- .../v2/license/SimpleLicensingInfo.java | 2 +- .../compat/v2/license/SpdxListedLicense.java | 2 +- .../v2/license/WithExceptionOperator.java | 2 +- .../compat/v2/pointer/CompoundPointer.java | 2 +- .../compat/v2/pointer/SinglePointer.java | 2 +- .../compat/v2/pointer/StartEndPointer.java | 2 +- .../java/org/spdx/storage/IModelStore.java | 2 +- .../storage/listedlicense/CrossRefJson.java | 2 +- .../storage/listedlicense/ExceptionJson.java | 2 +- .../storage/listedlicense/LicenseJson.java | 2 +- .../SpdxListedLicenseModelStore.java | 4 +- .../storage/simple/ExtendedSpdxStore.java | 2 +- .../spdx/storage/simple/InMemSpdxStore.java | 4 +- .../spdx/storage/simple/StoredTypedItem.java | 6 +- .../spdx/utility/compare/SpdxComparer.java | 2 +- .../compat/v2/ExternalDocumentRefTest.java | 2 +- .../model/compat/v2/ModelObjectTest.java | 4 +- .../v2/ModelStorageClassConverterTest.java | 2 +- .../model/compat/v2/RelationshipTest.java | 4 +- .../model/compat/v2/SpdxDocumentTest.java | 20 +- .../model/compat/v2/SpdxModelFactoryTest.java | 18 +- .../v2/license/ConjunctiveLicenseSetTest.java | 2 +- .../v2/license/DisjunctiveLiceseSetTest.java | 2 +- .../license/ExtractedLicensingInfoTest.java | 4 +- .../v2/license/WithExceptionOperatorTest.java | 4 +- .../listedlicense/CrossRefJsonTest.java | 2 +- .../listedlicense/ExceptionJsonTest.java | 2 +- .../listedlicense/LicenseJsonTest.java | 2 +- .../SpdxListedLicenseLocalStoreTest.java | 4 +- .../SpdxListedLicenseWebStoreTest.java | 4 +- .../storage/simple/InMemSpdxStoreTest.java | 2 +- .../storage/simple/StoredTypedItemTest.java | 2 +- .../utility/compare/SpdxComparerTest.java | 2 +- 64 files changed, 410 insertions(+), 415 deletions(-) create mode 100644 README-V3-UPGRADE.md rename src/main/java/org/spdx/library/{model/compat/v2 => }/InvalidSpdxPropertyException.java (94%) rename src/main/java/org/spdx/library/{model/compat/v2 => }/SpdxIdNotFoundException.java (93%) rename src/main/java/org/spdx/library/{model/compat/v2 => }/SpdxInvalidTypeException.java (93%) create mode 100644 src/main/java/org/spdx/library/SpdxModelFactory.java rename src/main/java/org/spdx/library/{model/compat/v2 => }/TypedValue.java (87%) delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java diff --git a/README-V3-UPGRADE.md b/README-V3-UPGRADE.md new file mode 100644 index 000000000..8d928505d --- /dev/null +++ b/README-V3-UPGRADE.md @@ -0,0 +1,23 @@ +# Upgrading from version 2 to version 3 + +With the support of SPDX 3.0, several changes have been made to the library codebase that will break previous API's. +Although we tried to keep breaking changes to a minimum, some of the changes were necessary due to breaking changes in the spec. itself. +We also took advantage of the changes to fix some annoying design flaws in the previous implementation of the library. + +## Changes to the SPI for the Model Store + +### Change propertyName to propertyDescriptor + +One significant change to the model store which impacts most of the API's. +All `String` `propertyName` properties are replaced by a `propertyDescriptor` of type `ProperyDescriptor`. +The `PropertyDescriptor` has a `name` property and a `nameSpace` property. +The property constants defined in `org.spdx.library.SpdxConstants` have all been changed to use constant `PropertyDescriptor`s. +If you're using the constants, you may not need to change much beyond the method signatures for anything that was passing along the `propertyName`. + +### Make DocumentNamespace Optional +In SPDX 3.0, not all elements are contained within an SPDX document and we can't be guaranteed that a namespace is available for all `TypedValue` typed properties. Methods that are passed a `DocumentNamespace` and an `id` now are passed a URI. + +To translate from SPDX 2.X, the `DocumentNamespace` concatenated with the `id` can be used for the URI. + +### Change TypedValue structure +`TypedValue` \ No newline at end of file diff --git a/README.md b/README.md index b6e6d4144..30665da72 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ Java library which implements the Java object model for SPDX and provides useful | [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=java-spdx-library&metric=bugs)](https://sonarcloud.io/dashboard?id=java-spdx-library) | [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=java-spdx-library&metric=security_rating)](https://sonarcloud.io/dashboard?id=java-spdx-library) | [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=java-spdx-library&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=java-spdx-library) | [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=java-spdx-library&metric=sqale_index)](https://sonarcloud.io/dashboard?id=java-spdx-library) | +## Library Version Compatibility + +Library version 3.0.0 and higher is not compatible with previous versions of the library due to breaking changes introduced in SPDX 3.0. + +See the [README-V3-UPGRADE.md](README-V3-UPGRADE.md) file for information on how to upgrade. ## Storage Interface The Spdx-Java-Library allows for different implementations of SPDX object storage. The storage facility implements the org.spdx.storage.IModelStore interface. This is a low level Service Provider Interface (SPI). The ISerializableModelStore extends the IModelStore and supports serializing and de-serializing the store to an I/O Stream. This interface is currently used to implement JSON, XML, YAML, and RDF/XML formats. The default storage interface is an in-memory Map which should be sufficient for light weight usage of the library. @@ -44,4 +49,4 @@ To update Spdx-Java-Library, the following is a very brief checklist: 4. Update unit tests ## Development Status -Note: This library is mostly stable, but and contains some defects. Reviews, suggestions are welcome. Please enter an issue with any suggestions. +Note: This library is mostly stable, but may contain some defects. Reviews, suggestions are welcome. Please enter an issue with any suggestions. diff --git a/src/main/java/org/spdx/library/model/compat/v2/InvalidSpdxPropertyException.java b/src/main/java/org/spdx/library/InvalidSpdxPropertyException.java similarity index 94% rename from src/main/java/org/spdx/library/model/compat/v2/InvalidSpdxPropertyException.java rename to src/main/java/org/spdx/library/InvalidSpdxPropertyException.java index 7991222da..9d8492e7b 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/InvalidSpdxPropertyException.java +++ b/src/main/java/org/spdx/library/InvalidSpdxPropertyException.java @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.InvalidSPDXAnalysisException; +package org.spdx.library; /** * @author Gary O'Neall diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index 08426f289..f0e016634 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -27,7 +27,6 @@ import org.slf4j.LoggerFactory; import org.spdx.library.model.compat.v2.IndividualUriValue; import org.spdx.library.model.compat.v2.SimpleUriValue; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/Read.java b/src/main/java/org/spdx/library/Read.java index d5dec40ff..12a3dd334 100644 --- a/src/main/java/org/spdx/library/Read.java +++ b/src/main/java/org/spdx/library/Read.java @@ -29,9 +29,7 @@ import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.library.model.compat.v2.SpdxPackage; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.ISerializableModelStore; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxIdNotFoundException.java b/src/main/java/org/spdx/library/SpdxIdNotFoundException.java similarity index 93% rename from src/main/java/org/spdx/library/model/compat/v2/SpdxIdNotFoundException.java rename to src/main/java/org/spdx/library/SpdxIdNotFoundException.java index 213ff04ba..93f860a45 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxIdNotFoundException.java +++ b/src/main/java/org/spdx/library/SpdxIdNotFoundException.java @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.InvalidSPDXAnalysisException; +package org.spdx.library; /** * @author Gary O'Neall diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxInvalidTypeException.java b/src/main/java/org/spdx/library/SpdxInvalidTypeException.java similarity index 93% rename from src/main/java/org/spdx/library/model/compat/v2/SpdxInvalidTypeException.java rename to src/main/java/org/spdx/library/SpdxInvalidTypeException.java index 1718d7b72..c6c390340 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxInvalidTypeException.java +++ b/src/main/java/org/spdx/library/SpdxInvalidTypeException.java @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.InvalidSPDXAnalysisException; +package org.spdx.library; /** * @author Gary O'Neall diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java new file mode 100644 index 000000000..709b70509 --- /dev/null +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -0,0 +1,288 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; + +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Factory class to create ModelObjects based on the type and SPDX Spec Version + * Types are defined classes in the SpdxConstantsCompatV2 class and map to the standard SPDX model + * + * @author Gary O'Neall + * + */ +public class SpdxModelFactory { + + static final Logger logger = LoggerFactory.getLogger(SpdxModelFactory.class); + + public static Map> SPDX_TYPE_TO_CLASS_V2; + public static Map, String> SPDX_CLASS_TO_TYPE; + static { + Map> typeToClass = new HashMap<>(); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, org.spdx.library.model.compat.v2.SpdxDocument.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, org.spdx.library.model.compat.v2.SpdxPackage.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO, org.spdx.library.model.compat.v2.SpdxCreatorInformation.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, org.spdx.library.model.compat.v2.Checksum.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO, org.spdx.library.model.compat.v2.license.AnyLicenseInfo.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO, org.spdx.library.model.compat.v2.license.SimpleLicensingInfo.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE, org.spdx.library.model.compat.v2.license.License.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, org.spdx.library.model.compat.v2.license.SpdxListedLicense.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.LicenseException.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.ListedLicenseException.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR, org.spdx.library.model.compat.v2.license.OrLaterOperator.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, org.spdx.library.model.compat.v2.license.WithExceptionOperator.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_FILE, org.spdx.library.model.compat.v2.SpdxFile.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE, org.spdx.library.model.compat.v2.SpdxPackageVerificationCode.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_ANNOTATION, org.spdx.library.model.compat.v2.Annotation.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_RELATIONSHIP, org.spdx.library.model.compat.v2.Relationship.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ITEM, org.spdx.library.model.compat.v2.SpdxItem.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT, org.spdx.library.model.compat.v2.SpdxElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoneElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoAssertionElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, org.spdx.library.model.compat.v2.ExternalDocumentRef.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE, org.spdx.library.model.compat.v2.ExternalRef.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE, org.spdx.library.model.compat.v2.ReferenceType.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, org.spdx.library.model.compat.v2.SpdxSnippet.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_NONE_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoneLicense.class); + typeToClass.put(org.spdx.library.model.compat.v2.GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, org.spdx.library.model.compat.v2.GenericModelObject.class); + typeToClass.put(org.spdx.library.model.compat.v2.GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, org.spdx.library.model.compat.v2.GenericSpdxElement.class); + typeToClass.put(org.spdx.library.model.compat.v2.GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, org.spdx.library.model.compat.v2.GenericSpdxItem.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT, org.spdx.library.model.compat.v2.ExternalSpdxElement.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER, org.spdx.library.model.compat.v2.pointer.StartEndPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER, org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER, org.spdx.library.model.compat.v2.pointer.LineCharPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, org.spdx.library.model.compat.v2.pointer.CompoundPointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, org.spdx.library.model.compat.v2.pointer.SinglePointer.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, org.spdx.library.model.compat.v2.license.CrossRef.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.compat.v2.enumerations.FileType.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.compat.v2.enumerations.AnnotationType.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.compat.v2.enumerations.ReferenceCategory.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.compat.v2.enumerations.RelationshipType.class); + typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.class); + typeToClass.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.compat.v2.enumerations.Purpose.class); + SPDX_TYPE_TO_CLASS_V2 = Collections.unmodifiableMap(typeToClass); + + Map, String> classToType = new HashMap<>(); + for (Entry> entry:typeToClass.entrySet()) { + classToType.put(entry.getValue(), entry.getKey()); + } + + SPDX_CLASS_TO_TYPE = Collections.unmodifiableMap(classToType); + } + + + /** + * Create an SPDX version 2.X document with default values for creator, created, licenseListVersion, data license and specVersion + * @param modelStore Where to store the SPDX Document + * @param documentUri unique URI for the SPDX document + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @return + * @throws InvalidSPDXAnalysisException + */ + public static org.spdx.library.model.compat.v2.SpdxDocument createSpdxDocumentV2(IModelStore modelStore, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + org.spdx.library.model.compat.v2.SpdxDocument retval = new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, true); + String date = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); + org.spdx.library.model.compat.v2.SpdxCreatorInformation creationInfo = new org.spdx.library.model.compat.v2.SpdxCreatorInformation( + modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); + creationInfo.getCreators().add("Tool: SPDX Tools"); + creationInfo.setCreated(date); + creationInfo.setLicenseListVersion(org.spdx.library.model.compat.v2.license.ListedLicenses.getListedLicenses().getLicenseListVersion()); + retval.setCreationInfo(creationInfo); + retval.setDataLicense(org.spdx.library.model.compat.v2.license.ListedLicenses.getListedLicenses().getListedLicenseById(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)); + retval.setSpecVersion(Version.CURRENT_SPDX_VERSION); + return retval; + } + + /** + * Create a model object in a model store given the document URI, ID and type + * @param modelStore model store where the object is to be created + * @param documentUri document URI for the stored item + * @param id ID for the item + * @param type SPDX class or type + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @return a ModelObject of type type + * @throws InvalidSPDXAnalysisException + */ + public static org.spdx.library.model.compat.v2.ModelObject createModelObject(IModelStore modelStore, String documentUri, String id, + String type, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + return getModelObjectV2(modelStore, documentUri, id, type, copyManager, true); + } + + /** + * Create an SPDX spec version 2.X model object in a model store given the document URI, ID and type + * @param modelStore model store where the object is to be created + * @param documentUri document URI for the stored item + * @param id ID for the item + * @param type SPDX class or type + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @param create if true, create the model object if it does not already exist + * @return a ModelObject of type type + * @throws InvalidSPDXAnalysisException + */ + public static org.spdx.library.model.compat.v2.ModelObject getModelObjectV2(IModelStore modelStore, String documentUri, String id, + String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { + switch (type) { + case SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT: return new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, create); //Note: the ID is ignored + case SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE: return new org.spdx.library.model.compat.v2.SpdxPackage(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO: return new org.spdx.library.model.compat.v2.SpdxCreatorInformation(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM: return new org.spdx.library.model.compat.v2.Checksum(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract AnyLicensing Info. Must specify one of the concrete classes"); + case SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract SimpleLicensingInfo. Must specify one of the concrete classes"); + case SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET: return new org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET: return new org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO: return new org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE: throw new InvalidSPDXAnalysisException("Can not create abstract License. Must specify one of the concrete classes"); + case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE: return new org.spdx.library.model.compat.v2.license.SpdxListedLicense(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION: return new org.spdx.library.model.compat.v2.license.LicenseException(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION: return new org.spdx.library.model.compat.v2.license.ListedLicenseException(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR: return new org.spdx.library.model.compat.v2.license.OrLaterOperator(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR: return new org.spdx.library.model.compat.v2.license.WithExceptionOperator(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_FILE: return new org.spdx.library.model.compat.v2.SpdxFile(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_REVIEW: throw new RuntimeException("SPDX Review class is no longer supported"); + case SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE: return new org.spdx.library.model.compat.v2.SpdxPackageVerificationCode(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_ANNOTATION: return new org.spdx.library.model.compat.v2.Annotation(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_RELATIONSHIP: return new org.spdx.library.model.compat.v2.Relationship(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_ITEM: throw new RuntimeException("SPDX item is an abstract item and can not be created."); + case SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT: throw new RuntimeException("SPDX element is an abstract item and can not be created."); + case SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT: return new org.spdx.library.model.compat.v2.SpdxNoneElement(modelStore, documentUri); + case SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT: return new org.spdx.library.model.compat.v2.SpdxNoAssertionElement(modelStore, documentUri); + case SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF: return new org.spdx.library.model.compat.v2.ExternalDocumentRef(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE: return new org.spdx.library.model.compat.v2.ExternalRef(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE: return new org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE: throw new RuntimeException("Reference type can only be created with a type supplied."); + case SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET: return new org.spdx.library.model.compat.v2.SpdxSnippet(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE: return new org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense(modelStore, documentUri); + case SpdxConstantsCompatV2.CLASS_NONE_LICENSE: return new org.spdx.library.model.compat.v2.license.SpdxNoneLicense(modelStore, documentUri); + case org.spdx.library.model.compat.v2.GenericModelObject.GENERIC_MODEL_OBJECT_TYPE: return new org.spdx.library.model.compat.v2.GenericModelObject(modelStore, documentUri, id, copyManager, create); + case org.spdx.library.model.compat.v2.GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE: return new org.spdx.library.model.compat.v2.GenericSpdxElement(modelStore, documentUri, id, copyManager, create); + case org.spdx.library.model.compat.v2.GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE: return new org.spdx.library.model.compat.v2.GenericSpdxItem(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT: return new org.spdx.library.model.compat.v2.ExternalSpdxElement(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER: return new org.spdx.library.model.compat.v2.pointer.StartEndPointer(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER: return new org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER: return new org.spdx.library.model.compat.v2.pointer.LineCharPointer(modelStore, documentUri, id, copyManager, create); + case SpdxConstantsCompatV2.CLASS_CROSS_REF: return new org.spdx.library.model.compat.v2.license.CrossRef(modelStore, documentUri, id, copyManager, create); + default: throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); + } + } + + /** + * @param type SPDX Type + * @return class associated with the type + * @throws InvalidSPDXAnalysisException + */ + public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { + Class retval = SPDX_TYPE_TO_CLASS_V2.get(type); + if (Objects.isNull(retval)) { + throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); + } + return retval; + } + + public static Stream getElements(IModelStore store, String documentUri, ModelCopyManager copyManager, + Class spdxClass) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(store, "Store must not be null"); + Objects.requireNonNull(documentUri, "documentUri must not be null"); + Objects.requireNonNull(spdxClass, "spdxClass must not be null"); + String type = SPDX_CLASS_TO_TYPE.get(spdxClass); + if (Objects.isNull(type)) { + throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); + } + return store.getAllItems(documentUri, type).map(tv -> { + try { + return createModelObject(store, documentUri, tv.getId(), tv.getType(), copyManager); + } catch (InvalidSPDXAnalysisException e) { + logger.error("Error creating model object",e); + throw new RuntimeException(e); + } + }); + } + + /** + * @param classUri URI for the class type + * @return class represented by the URI + * @throws InvalidSPDXAnalysisException + */ + public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(classUri, "Missing required class URI"); + int indexOfPound = classUri.lastIndexOf('#'); + if (indexOfPound < 1) { + throw new InvalidSPDXAnalysisException("Invalid class URI: "+classUri); + } + String type = classUri.substring(indexOfPound+1); + return typeToClass(type); + } + + /** + * @param modelStore Store for the SPDX Spec version 2 model + * @param documentUri Document URI for for the ID + * @param copyManager Optional copy manager for copying any properties from other model + * @param id ID for the model object + * @return SPDX Version 2 compatibile ModelObject with the ID in the model store + * @throws InvalidSPDXAnalysisException + */ + public static Optional getModelObjectV2(IModelStore modelStore, String documentUri, + String id, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (id.contains(":")) { + // External document ref + try { + return Optional.of(new org.spdx.library.model.compat.v2.ExternalSpdxElement(modelStore, documentUri, id, copyManager, true)); + } catch(InvalidSPDXAnalysisException ex) { + logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty"); + return Optional.empty(); + } + } + Optional tv = modelStore.getTypedValue(documentUri, id); + if (tv.isPresent()) { + String type = tv.get().getType(); + try { + return Optional.of(getModelObjectV2(modelStore, documentUri, id, type, copyManager, false)); + } catch(SpdxIdNotFoundException ex) { + return Optional.empty(); // There is a window where the ID disappears between getTypedValue and getModelObject + } + } else { + if (SpdxConstantsCompatV2.NOASSERTION_VALUE.equals(id)) { + return Optional.of(new org.spdx.library.model.compat.v2.SpdxNoAssertionElement()); + } else if (SpdxConstantsCompatV2.NONE_VALUE.equals(id)) { + return Optional.of(new org.spdx.library.model.compat.v2.SpdxNoneElement()); + } else { + return Optional.empty(); + } + } + } +} diff --git a/src/main/java/org/spdx/library/model/compat/v2/TypedValue.java b/src/main/java/org/spdx/library/TypedValue.java similarity index 87% rename from src/main/java/org/spdx/library/model/compat/v2/TypedValue.java rename to src/main/java/org/spdx/library/TypedValue.java index 3f736ba60..ec7ea9020 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/TypedValue.java +++ b/src/main/java/org/spdx/library/TypedValue.java @@ -1,11 +1,12 @@ -package org.spdx.library.model.compat.v2; +package org.spdx.library; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidIdException; +import org.spdx.library.model.compat.v2.GenericModelObject; +import org.spdx.library.model.compat.v2.GenericSpdxElement; +import org.spdx.library.model.compat.v2.GenericSpdxItem; /** diff --git a/src/main/java/org/spdx/library/Version.java b/src/main/java/org/spdx/library/Version.java index fd58e17cf..b1c5704b6 100644 --- a/src/main/java/org/spdx/library/Version.java +++ b/src/main/java/org/spdx/library/Version.java @@ -40,14 +40,15 @@ public class Version { public static final String TWO_POINT_ONE_VERSION = "SPDX-2.1"; public static final String TWO_POINT_TWO_VERSION = "SPDX-2.2"; public static final String TWO_POINT_THREE_VERSION = "SPDX-2.3"; - public static final String CURRENT_SPDX_VERSION = TWO_POINT_THREE_VERSION; + public static final String THREE_POINT_ZERO_VERSION = "SPDX-3.0"; + public static final String CURRENT_SPDX_VERSION = THREE_POINT_ZERO_VERSION; public static final List SUPPORTED_SPDX_VERSIONS = Collections.unmodifiableList(new ArrayList(Arrays.asList(new String[]{ ONE_DOT_ZERO_SPDX_VERSION, ONE_DOT_ONE_SPDX_VERSION, ONE_DOT_TWO_SPDX_VERSION, TWO_POINT_ZERO_VERSION, - TWO_POINT_ONE_VERSION, TWO_POINT_TWO_VERSION, TWO_POINT_THREE_VERSION + TWO_POINT_ONE_VERSION, TWO_POINT_TWO_VERSION, TWO_POINT_THREE_VERSION, THREE_POINT_ZERO_VERSION }))); - public static final String CURRENT_IMPLEMENTATION_VERSION = "1.1.6"; + public static final String CURRENT_IMPLEMENTATION_VERSION = "2.0.0"; public static String verifySpdxVersion(String spdxVersion) { if (!spdxVersion.startsWith("SPDX-")) { diff --git a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java index bf030fdbb..09f4f33ee 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java @@ -27,6 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.storage.IModelStore; diff --git a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java index a34badb20..d0b8f7613 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java @@ -28,6 +28,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index 90476e6cd..158fccda1 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -30,6 +30,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java index 7d7a4ef28..b45a2e524 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java @@ -33,6 +33,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxObjectNotInStoreException; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index e498917c3..6ffdd50ad 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -33,7 +33,11 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxVerificationHelper; +import org.spdx.library.TypedValue; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index efa84ebfc..01182f91e 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -24,7 +24,10 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxObjectNotInStoreException; +import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java index 9cbe46467..bd46d6c95 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java @@ -25,6 +25,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java index 26de8b879..b6522c897 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java @@ -30,6 +30,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java deleted file mode 100644 index 6b752b1ff..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxModelFactory.java +++ /dev/null @@ -1,319 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.Purpose; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.CrossRef; -import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.License; -import org.spdx.library.model.compat.v2.license.LicenseException; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; -import org.spdx.library.model.compat.v2.license.ListedLicenses; -import org.spdx.library.model.compat.v2.license.OrLaterOperator; -import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.library.model.compat.v2.license.WithExceptionOperator; -import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; -import org.spdx.library.model.compat.v2.pointer.CompoundPointer; -import org.spdx.library.model.compat.v2.pointer.LineCharPointer; -import org.spdx.library.model.compat.v2.pointer.SinglePointer; -import org.spdx.library.model.compat.v2.pointer.StartEndPointer; - -/** - * Factory class to create ModelObjects based on the type - * Types are defined classes in the SpdxConstantsCompatV2 class and map to the standard SPDX model - * - * @author Gary O'Neall - * - */ -public class SpdxModelFactory { - - static final Logger logger = LoggerFactory.getLogger(SpdxModelFactory.class); - - public static Map> SPDX_TYPE_TO_CLASS; - public static Map, String> SPDX_CLASS_TO_TYPE; - static { - Map> typeToClass = new HashMap<>(); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, SpdxDocument.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, SpdxPackage.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO, SpdxCreatorInformation.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, Checksum.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO, AnyLicenseInfo.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO, SimpleLicensingInfo.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, ConjunctiveLicenseSet.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, DisjunctiveLicenseSet.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, ExtractedLicenseInfo.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE, License.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, SpdxListedLicense.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, LicenseException.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, ListedLicenseException.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR, OrLaterOperator.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, WithExceptionOperator.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_FILE, SpdxFile.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE, SpdxPackageVerificationCode.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_ANNOTATION, Annotation.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_RELATIONSHIP, Relationship.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ITEM, SpdxItem.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT, SpdxElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT, SpdxNoneElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT, SpdxNoAssertionElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, ExternalDocumentRef.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE, ExternalRef.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE, ReferenceType.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, SpdxSnippet.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE, SpdxNoAssertionLicense.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_NONE_LICENSE, SpdxNoneLicense.class); - typeToClass.put(GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, GenericModelObject.class); - typeToClass.put(GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, GenericSpdxElement.class); - typeToClass.put(GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, GenericSpdxItem.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT, ExternalSpdxElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER, StartEndPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER, ByteOffsetPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER, LineCharPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, CompoundPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, SinglePointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, CrossRef.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, FileType.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, AnnotationType.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, ChecksumAlgorithm.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, ReferenceCategory.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, RelationshipType.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, ExternalExtractedLicenseInfo.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_PURPOSE, Purpose.class); - SPDX_TYPE_TO_CLASS = Collections.unmodifiableMap(typeToClass); - - Map, String> classToType = new HashMap<>(); - for (Entry> entry:typeToClass.entrySet()) { - classToType.put(entry.getValue(), entry.getKey()); - } - - SPDX_CLASS_TO_TYPE = Collections.unmodifiableMap(classToType); - } - - - /** - * Create an SPDX document with default values for creator, created, licenseListVersion, data license and specVersion - * @param modelStore Where to store the SPDX Document - * @param documentUri unique URI for the SPDX document - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @return - * @throws InvalidSPDXAnalysisException - */ - public static SpdxDocument createSpdxDocument(IModelStore modelStore, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SpdxDocument retval = new SpdxDocument(modelStore, documentUri, copyManager, true); - String date = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); - SpdxCreatorInformation creationInfo = new SpdxCreatorInformation( - modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - creationInfo.getCreators().add("Tool: SPDX Tools"); - creationInfo.setCreated(date); - creationInfo.setLicenseListVersion(ListedLicenses.getListedLicenses().getLicenseListVersion()); - retval.setCreationInfo(creationInfo); - retval.setDataLicense(ListedLicenses.getListedLicenses().getListedLicenseById(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)); - retval.setSpecVersion(Version.CURRENT_SPDX_VERSION); - return retval; - } - - /** - * Create a model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param documentUri document URI for the stored item - * @param id ID for the item - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static ModelObject createModelObject(IModelStore modelStore, String documentUri, String id, - String type, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - return getModelObject(modelStore, documentUri, id, type, copyManager, true); - } - - /** - * Create a model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param documentUri document URI for the stored item - * @param id ID for the item - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @param create if true, create the model object if it does not already exist - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static ModelObject getModelObject(IModelStore modelStore, String documentUri, String id, - String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - switch (type) { - case SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT: return new SpdxDocument(modelStore, documentUri, copyManager, create); //Note: the ID is ignored - case SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE: return new SpdxPackage(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO: return new SpdxCreatorInformation(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM: return new Checksum(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract AnyLicensing Info. Must specify one of the concrete classes"); - case SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract SimpleLicensingInfo. Must specify one of the concrete classes"); - case SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET: return new ConjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET: return new DisjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO: return new ExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE: throw new InvalidSPDXAnalysisException("Can not create abstract License. Must specify one of the concrete classes"); - case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE: return new SpdxListedLicense(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION: return new LicenseException(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION: return new ListedLicenseException(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR: return new OrLaterOperator(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR: return new WithExceptionOperator(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_FILE: return new SpdxFile(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_REVIEW: throw new RuntimeException("SPDX Review class is no longer supported"); - case SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE: return new SpdxPackageVerificationCode(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_ANNOTATION: return new Annotation(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_RELATIONSHIP: return new Relationship(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_ITEM: throw new RuntimeException("SPDX item is an abstract item and can not be created."); - case SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT: throw new RuntimeException("SPDX element is an abstract item and can not be created."); - case SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT: return new SpdxNoneElement(modelStore, documentUri); - case SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT: return new SpdxNoAssertionElement(modelStore, documentUri); - case SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF: return new ExternalDocumentRef(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE: return new ExternalRef(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE: return new ExternalExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE: throw new RuntimeException("Reference type can only be created with a type supplied."); - case SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET: return new SpdxSnippet(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE: return new SpdxNoAssertionLicense(modelStore, documentUri); - case SpdxConstantsCompatV2.CLASS_NONE_LICENSE: return new SpdxNoneLicense(modelStore, documentUri); - case GenericModelObject.GENERIC_MODEL_OBJECT_TYPE: return new GenericModelObject(modelStore, documentUri, id, copyManager, create); - case GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE: return new GenericSpdxElement(modelStore, documentUri, id, copyManager, create); - case GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE: return new GenericSpdxItem(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT: return new ExternalSpdxElement(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER: return new StartEndPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER: return new ByteOffsetPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER: return new LineCharPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_CROSS_REF: return new CrossRef(modelStore, documentUri, id, copyManager, create); - default: throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); - } - } - - /** - * @param type SPDX Type - * @return class associated with the type - * @throws InvalidSPDXAnalysisException - */ - public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { - Class retval = SPDX_TYPE_TO_CLASS.get(type); - if (Objects.isNull(retval)) { - throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); - } - return retval; - } - - public static Stream getElements(IModelStore store, String documentUri, ModelCopyManager copyManager, - Class spdxClass) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(documentUri, "documentUri must not be null"); - Objects.requireNonNull(spdxClass, "spdxClass must not be null"); - String type = SPDX_CLASS_TO_TYPE.get(spdxClass); - if (Objects.isNull(type)) { - throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); - } - return store.getAllItems(documentUri, type).map(tv -> { - try { - return createModelObject(store, documentUri, tv.getId(), tv.getType(), copyManager); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error creating model object",e); - throw new RuntimeException(e); - } - }); - } - - /** - * @param classUri URI for the class type - * @return class represented by the URI - * @throws InvalidSPDXAnalysisException - */ - public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(classUri, "Missing required class URI"); - int indexOfPound = classUri.lastIndexOf('#'); - if (indexOfPound < 1) { - throw new InvalidSPDXAnalysisException("Invalid class URI: "+classUri); - } - String type = classUri.substring(indexOfPound+1); - return typeToClass(type); - } - - /** - * @param modelStore Store for the model - * @param documentUri Document URI for for the ID - * @param copyManager Optional copy manager for copying any properties from other model - * @param id ID for the model object - * @return ModelObject with the ID in the model store - * @throws InvalidSPDXAnalysisException - */ - public static Optional getModelObject(IModelStore modelStore, String documentUri, - String id, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (id.contains(":")) { - // External document ref - try { - return Optional.of(new ExternalSpdxElement(modelStore, documentUri, id, copyManager, true)); - } catch(InvalidSPDXAnalysisException ex) { - logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty"); - return Optional.empty(); - } - } - Optional tv = modelStore.getTypedValue(documentUri, id); - if (tv.isPresent()) { - String type = tv.get().getType(); - try { - return Optional.of(getModelObject(modelStore, documentUri, id, type, copyManager, false)); - } catch(SpdxIdNotFoundException ex) { - return Optional.empty(); // There is a window where the ID disappears between getTypedValue and getModelObject - } - } else { - if (SpdxConstantsCompatV2.NOASSERTION_VALUE.equals(id)) { - return Optional.of(new SpdxNoAssertionElement()); - } else if (SpdxConstantsCompatV2.NONE_VALUE.equals(id)) { - return Optional.of(new SpdxNoneElement()); - } else { - return Optional.empty(); - } - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java index f0c409f75..64398e83b 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java @@ -29,6 +29,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java index 25d4f0dfa..570daadf7 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java @@ -30,6 +30,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java index 7d40c5853..1a196a070 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java @@ -19,7 +19,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java index a26220ca5..16d8b6ad2 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java @@ -26,8 +26,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java index a4cd25f22..8c5dc8f34 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java @@ -26,8 +26,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java index 2033b76a3..325fd0213 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java @@ -29,9 +29,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.utility.compare.LicenseCompareHelper; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/License.java b/src/main/java/org/spdx/library/model/compat/v2/license/License.java index 373de4f08..e071e70b6 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/License.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/License.java @@ -27,8 +27,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.ModelUpdate; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java index ceaa76bfd..8fd68a2c6 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java @@ -28,9 +28,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.IndividualUriValue; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java index 7b77459e3..15357d9a2 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java @@ -30,9 +30,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.ModelStorageClassConverter; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java index 7585ea3e8..52be6ff38 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java @@ -20,7 +20,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java index e9fbc8b8e..47e232bd2 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.listedlicense.IListedLicenseStore; import org.spdx.storage.listedlicense.SpdxListedLicenseLocalStore; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java b/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java index 73a548cd4..53c78d3ee 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java index f2f452232..84b3fc22c 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java @@ -26,8 +26,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.IndividualUriValue; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java index df2382198..bd573247b 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java @@ -28,8 +28,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.licenseTemplate.LicenseTemplateRuleException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java b/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java index f5e2ae6e9..d5b70430a 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java @@ -28,7 +28,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java index d21f4899d..4543a6b6d 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java @@ -28,8 +28,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java index 1ddc1d78d..bd3cec334 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java @@ -30,9 +30,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java index 25d24813a..27ba01595 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java +++ b/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java @@ -29,7 +29,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; +import org.spdx.library.SpdxInvalidTypeException; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/storage/IModelStore.java b/src/main/java/org/spdx/storage/IModelStore.java index 53483f0cf..084cea734 100644 --- a/src/main/java/org/spdx/storage/IModelStore.java +++ b/src/main/java/org/spdx/storage/IModelStore.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.TypedValue; /** * Service Provider Interface for storing and retrieving SPDX properties for SPDX documents. diff --git a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java index b98c96b8c..49a49c99b 100644 --- a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java @@ -26,7 +26,7 @@ import javax.annotation.Nullable; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; +import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.model.compat.v2.license.CrossRef; /** diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java index 86b862f09..2443e82b7 100644 --- a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java @@ -24,8 +24,8 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; import org.spdx.library.model.compat.v2.license.ListedLicenseException; /** diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java index 187a40c0d..3b199d104 100644 --- a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java @@ -24,8 +24,8 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index 2709318e5..9a032b1a6 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -41,9 +41,9 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.DuplicateSpdxIdException; -import org.spdx.library.model.compat.v2.SpdxIdNotFoundException; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.SpdxListedLicenseException; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java index 52778bca3..b41294f47 100644 --- a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java @@ -24,7 +24,7 @@ import java.util.stream.Stream; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index c63aea0ea..c86e072db 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -39,11 +39,11 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.DuplicateSpdxIdException; import org.spdx.library.model.compat.v2.ModelCollection; import org.spdx.library.model.compat.v2.SpdxIdInUseException; -import org.spdx.library.model.compat.v2.SpdxIdNotFoundException; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index efb1649d1..be96ef167 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -19,11 +19,11 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.IndividualUriValue; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/utility/compare/SpdxComparer.java b/src/main/java/org/spdx/utility/compare/SpdxComparer.java index f12318b43..eb7da549b 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxComparer.java @@ -34,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalDocumentRef; @@ -43,7 +44,6 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxElement; import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.library.model.compat.v2.SpdxSnippet; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java index c55d9b658..5a7476be7 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java @@ -23,11 +23,11 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalDocumentRef; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index 30a741ad7..cb268565f 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -32,6 +32,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.ExternalSpdxElement; import org.spdx.library.model.compat.v2.GenericModelObject; @@ -42,8 +44,6 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxIdInUseException; -import org.spdx.library.model.compat.v2.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index aa0c16a38..a65e21f6b 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -9,6 +9,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalSpdxElement; @@ -18,7 +19,6 @@ import org.spdx.library.model.compat.v2.Relationship; import org.spdx.library.model.compat.v2.SimpleUriValue; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java index bb4b3b9a1..df3a4596f 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java @@ -28,6 +28,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; @@ -39,7 +40,6 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxElement; import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; @@ -230,7 +230,7 @@ public void testDocumentDescribes() throws InvalidSPDXAnalysisException { String documentUri = "https://someuri"; ModelCopyManager copyManager = new ModelCopyManager(); IModelStore modelStore = new InMemSpdxStore(); - SpdxDocument document = SpdxModelFactory.createSpdxDocument(modelStore, documentUri, copyManager); + SpdxDocument document = SpdxModelFactory.createSpdxDocumentV2(modelStore, documentUri, copyManager); document.setSpecVersion(Version.TWO_POINT_THREE_VERSION); document.setName("SPDX-tool-test"); Checksum sha1Checksum = Checksum.create(modelStore, documentUri, ChecksumAlgorithm.SHA1, "d6a770ba38583ed4bb4525bd96e50461655d2758"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index dfe0322fe..20ba9192d 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -27,20 +27,8 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalDocumentRef; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxCreatorInformation; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.FileType; @@ -252,7 +240,7 @@ private boolean collectionsSame(Collection c1, Collection licenseListVersion = doc.getCreationInfo().getLicenseListVersion(); @@ -260,7 +248,7 @@ public void testDefaultCreationInfo() throws InvalidSPDXAnalysisException { } public void testEquivalent() throws InvalidSPDXAnalysisException { - SpdxDocument doc = SpdxModelFactory.createSpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager()); + SpdxDocument doc = SpdxModelFactory.createSpdxDocumentV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager()); doc.setStrict(false); List annotations = Arrays.asList(new Annotation[] { ANNOTATION1, ANNOTATION2 @@ -304,7 +292,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { String doc2Uri = "http://spdx.org/spdx/2ndoc/2342"; IModelStore model2 = new InMemSpdxStore(); - SpdxDocument doc2 = SpdxModelFactory.createSpdxDocument(model2, doc2Uri, gmo.getCopyManager()); + SpdxDocument doc2 = SpdxModelFactory.createSpdxDocumentV2(model2, doc2Uri, gmo.getCopyManager()); doc2.setStrict(false); doc2.setAnnotations(annotations); doc2.setComment(DOC_COMMENT1); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index 4b2bce495..c6ff22869 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -8,14 +8,14 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxElement; import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxIdNotFoundException; -import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -42,7 +42,7 @@ protected void tearDown() throws Exception { } public void testCreateSpdxDocument() throws InvalidSPDXAnalysisException { - SpdxDocument result = SpdxModelFactory.createSpdxDocument(modelStore, DOCUMENT_URI, copyManager); + SpdxDocument result = SpdxModelFactory.createSpdxDocumentV2(modelStore, DOCUMENT_URI, copyManager); assertEquals(SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, result.getId()); } @@ -54,16 +54,16 @@ public void testCreateModelObject() throws InvalidSPDXAnalysisException { } public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoolean() throws InvalidSPDXAnalysisException { - ModelObject result = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, + ModelObject result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); - ModelObject result2 = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, + ModelObject result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, false); assertTrue(result2 instanceof Checksum); assertEquals(ID1, result2.getId()); try { - result = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID2, + result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID2, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, false); fail("Expected id not found exception"); } catch(SpdxIdNotFoundException ex) { @@ -109,15 +109,15 @@ public void testClassUriToClass() throws InvalidSPDXAnalysisException { } public void testGetModelObjectIModelStoreStringStringModelCopyManager() throws InvalidSPDXAnalysisException { - ModelObject result = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, + ModelObject result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); - Optional result2 = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID1, copyManager); + Optional result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, copyManager); assertTrue(result2.isPresent()); assertTrue(result2.get() instanceof Checksum); assertEquals(ID1, result2.get().getId()); - result2 = SpdxModelFactory.getModelObject(modelStore, DOCUMENT_URI, ID2, copyManager); + result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID2, copyManager); assertFalse(result2.isPresent()); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java index 4097a41fa..33b7198f2 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java @@ -23,7 +23,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java index 66795bdde..da1f1f7a6 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java @@ -23,7 +23,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; +import org.spdx.library.SpdxModelFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java index e9acdff72..7c1dfb733 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java @@ -24,8 +24,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java index f565ee4d7..0188b1338 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java @@ -4,8 +4,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java index 5218e645c..cf7df8d1e 100644 --- a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java @@ -8,8 +8,8 @@ import java.util.Objects; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java index 7a550d633..3b522509d 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java @@ -24,8 +24,8 @@ import java.util.Map; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; import org.spdx.library.model.compat.v2.license.ListedLicenseException; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java index dae0e8ff5..1928d9c7b 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java @@ -24,8 +24,8 @@ import java.util.Map; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.InvalidSpdxPropertyException; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java index 698e4130c..04bf1088c 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java @@ -25,8 +25,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.library.model.compat.v2.license.LicenseException; import org.spdx.library.model.compat.v2.license.ListedLicenseException; diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java index ba148b714..deaeec818 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java @@ -25,8 +25,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.SpdxModelFactory; -import org.spdx.library.model.compat.v2.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.library.model.compat.v2.license.LicenseException; import org.spdx.library.model.compat.v2.license.ListedLicenseException; diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index b263a54f7..bbe0d51cc 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -35,8 +35,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.SpdxIdInUseException; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java index f14616455..446973048 100644 --- a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java +++ b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java @@ -22,8 +22,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.TypedValue; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index ce7c5b519..9b63fe261 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -33,6 +33,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalDocumentRef; @@ -44,7 +45,6 @@ import org.spdx.library.model.compat.v2.SpdxElement; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.SpdxModelFactory; import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.library.model.compat.v2.SpdxSnippet; From beac830c4d8ac8be2675df707f851291b75b7ebd Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Mon, 12 Jun 2023 15:14:45 -0700 Subject: [PATCH 04/62] Intermediate checkin - restructure storage interface Still many unit tests are failing - but at least it compiles. Change the storage interface to use object URI's - getting rid of the requirement for SPDX document containers - causes a major redesign Signed-off-by: Gary O'Neall --- README-V3-UPGRADE.md | 12 +- .../org/spdx/library/DefaultModelStore.java | 9 +- .../compat/v2 => }/IndividualUriValue.java | 2 +- .../org/spdx/library/ModelCopyManager.java | 241 ++-- .../org/spdx/library/ModelObjectHelper.java | 28 + .../{model/compat/v2 => }/SimpleUriValue.java | 38 +- .../java/org/spdx/library/SpdxConstants.java | 37 + .../spdx/library/SpdxConstantsCompatV2.java | 5 +- .../org/spdx/library/SpdxModelFactory.java | 167 ++- .../spdx/library/SpdxVerificationHelper.java | 8 +- .../java/org/spdx/library/TypedValue.java | 18 +- .../library/model/compat/v2/Annotation.java | 4 +- .../library/model/compat/v2/Checksum.java | 4 +- .../model/compat/v2/ExternalDocumentRef.java | 8 +- .../library/model/compat/v2/ExternalRef.java | 5 +- .../model/compat/v2/ExternalSpdxElement.java | 18 +- .../model/compat/v2/GenericModelObject.java | 4 +- .../model/compat/v2/GenericSpdxElement.java | 4 +- .../model/compat/v2/GenericSpdxItem.java | 4 +- .../model/compat/v2/ModelCollection.java | 23 +- .../library/model/compat/v2/ModelObject.java | 62 +- .../library/model/compat/v2/ModelSet.java | 2 +- .../compat/v2/ModelStorageClassConverter.java | 16 +- .../library/{ => model/compat/v2}/Read.java | 25 +- .../model/compat/v2/ReferenceType.java | 2 + .../compat/v2/RelatedElementCollection.java | 5 +- .../library/model/compat/v2/Relationship.java | 4 +- .../model/compat/v2/SpdxConstantElement.java | 4 +- .../compat/v2/SpdxCreatorInformation.java | 4 +- .../library/model/compat/v2/SpdxElement.java | 4 +- .../library/model/compat/v2/SpdxFile.java | 8 +- .../library/model/compat/v2/SpdxItem.java | 4 +- .../library/model/compat/v2/SpdxPackage.java | 8 +- .../v2/SpdxPackageVerificationCode.java | 4 +- .../library/model/compat/v2/SpdxSnippet.java | 8 +- .../library/{ => model/compat/v2}/Write.java | 7 +- .../v2/enumerations/AnnotationType.java | 2 +- .../v2/enumerations/ChecksumAlgorithm.java | 2 +- .../compat/v2/enumerations/FileType.java | 2 +- .../model/compat/v2/enumerations/Purpose.java | 2 +- .../v2/enumerations/ReferenceCategory.java | 2 +- .../v2/enumerations/RelationshipType.java | 2 +- .../license/AbstractExtractedLicenseInfo.java | 4 +- .../compat/v2/license/AnyLicenseInfo.java | 4 +- .../v2/license/ConjunctiveLicenseSet.java | 2 +- .../model/compat/v2/license/CrossRef.java | 8 +- .../v2/license/DisjunctiveLicenseSet.java | 2 +- .../license/ExternalExtractedLicenseInfo.java | 18 +- .../v2/license/ExtractedLicenseInfo.java | 4 +- .../model/compat/v2/license/License.java | 4 +- .../compat/v2/license/LicenseException.java | 6 +- .../v2/license/LicenseExpressionParser.java | 13 +- .../compat/v2/license/LicenseInfoFactory.java | 4 +- .../model/compat/v2/license/LicenseSet.java | 4 +- .../v2/license/ListedLicenseException.java | 8 +- .../v2/license/SimpleLicensingInfo.java | 8 +- .../compat/v2/license/SpdxListedLicense.java | 8 +- .../v2/license/SpdxNoAssertionLicense.java | 4 +- .../compat/v2/license/SpdxNoneLicense.java | 4 +- .../v2/license/WithExceptionOperator.java | 4 +- .../compat/v2/pointer/ByteOffsetPointer.java | 4 +- .../compat/v2/pointer/CompoundPointer.java | 4 +- .../compat/v2/pointer/LineCharPointer.java | 4 +- .../compat/v2/pointer/SinglePointer.java | 4 +- .../compat/v2/pointer/StartEndPointer.java | 4 +- .../HtmlTemplateOutputHandler.java | 10 +- .../java/org/spdx/storage/IModelStore.java | 132 +- .../v2/CompatibleModelStoreWrapper.java | 359 +++++ .../SpdxListedLicenseLocalStore.java | 1 + .../SpdxListedLicenseModelStore.java | 195 +-- .../storage/simple/ExtendedSpdxStore.java | 92 +- .../spdx/storage/simple/InMemSpdxStore.java | 276 ++-- .../spdx/storage/simple/StoredTypedItem.java | 62 +- .../spdx/utility/compare/SpdxComparer.java | 8 +- .../model/compat/v2/AnnotationTest.java | 5 +- .../compat/v2/ByteOffsetPointerTest.java | 6 +- .../library/model/compat/v2/ChecksumTest.java | 5 +- .../compat/v2/ExternalDocumentRefTest.java | 7 +- .../model/compat/v2/ExternalRefTest.java | 5 +- .../compat/v2/ExternalSpdxElementTest.java | 9 +- .../compat/v2/IndividualUriValueTest.java | 6 +- .../model/compat/v2/LineCharPointerTest.java | 6 +- .../model/compat/v2/ModelCollectionTest.java | 5 +- .../model/compat/v2/ModelObjectTest.java | 20 +- .../v2/ModelStorageClassConverterTest.java | 23 +- .../compat/v2/NoAssertionElementTest.java | 8 +- .../v2/RelatedElementCollectionTest.java | 7 +- .../model/compat/v2/RelationshipTest.java | 16 +- .../model/compat/v2/SimpleUriValueTest.java | 20 +- .../compat/v2/SpdxConstantElementTest.java | 5 - .../compat/v2/SpdxCreatorInformationTest.java | 5 +- .../model/compat/v2/SpdxDocumentTest.java | 6 +- .../model/compat/v2/SpdxElementTest.java | 15 +- .../library/model/compat/v2/SpdxFileTest.java | 11 +- .../model/compat/v2/SpdxModelFactoryTest.java | 10 +- .../model/compat/v2/SpdxNoneElementTest.java | 8 +- .../model/compat/v2/SpdxPackageTest.java | 15 +- .../v2/SpdxPackageVerificationCodeTest.java | 5 +- .../model/compat/v2/SpdxSnippetTest.java | 8 +- .../model/compat/v2/StartEndPointerTest.java | 7 +- .../v2/license/ExternalLicenseRefTest.java | 3 +- .../license/ExtractedLicensingInfoTest.java | 23 +- .../v2/license/LicenseExceptionTest.java | 12 +- .../license/LicenseExpressionParserTest.java | 4 +- .../v2/license/LicenseInfoFactoryTest.java | 4 +- .../v2/license/OrLaterOperatorTest.java | 4 +- .../v2/license/SpdxListedLicenseTest.java | 4 +- .../v2/license/SpdxNoneLicenseTest.java | 5 +- .../v2/license/WithExceptionOperatorTest.java | 15 +- .../TestHtmlTemplateOutputHandler.java | 12 +- .../TestSpdxLicenseTemplateHelper.java | 4 +- .../v2/CompatibleModelStoreWrapperTest.java | 732 +++++++++++ .../listedlicense/CrossRefJsonTest.java | 2 +- .../listedlicense/LicenseJsonTest.java | 7 +- .../SpdxListedLicenseLocalStoreTest.java | 142 +- .../SpdxListedLicenseWebStoreTest.java | 126 +- .../storage/simple/InMemSpdxStoreTest.java | 1161 ++++++++--------- .../storage/simple/StoredTypedItemTest.java | 39 +- .../compare/LicenseCompareHelperTest.java | 4 +- .../utility/compare/SpdxComparerTest.java | 5 +- .../utility/compare/SpdxFileComparerTest.java | 5 +- .../utility/compare/SpdxItemComparerTest.java | 4 +- .../compare/SpdxPackageComparerTest.java | 5 +- .../compare/SpdxSnippetComparerTest.java | 5 +- .../spdx/utility/compare/UnitTestHelper.java | 6 +- .../VerificationCodeGeneratorTest.java | 3 +- 126 files changed, 2901 insertions(+), 1760 deletions(-) rename src/main/java/org/spdx/library/{model/compat/v2 => }/IndividualUriValue.java (96%) create mode 100644 src/main/java/org/spdx/library/ModelObjectHelper.java rename src/main/java/org/spdx/library/{model/compat/v2 => }/SimpleUriValue.java (72%) create mode 100644 src/main/java/org/spdx/library/SpdxConstants.java rename src/main/java/org/spdx/library/{ => model/compat/v2}/Read.java (88%) rename src/main/java/org/spdx/library/{ => model/compat/v2}/Write.java (94%) create mode 100644 src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java create mode 100644 src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java diff --git a/README-V3-UPGRADE.md b/README-V3-UPGRADE.md index 8d928505d..12c596ced 100644 --- a/README-V3-UPGRADE.md +++ b/README-V3-UPGRADE.md @@ -15,9 +15,19 @@ The property constants defined in `org.spdx.library.SpdxConstants` have all bee If you're using the constants, you may not need to change much beyond the method signatures for anything that was passing along the `propertyName`. ### Make DocumentNamespace Optional + In SPDX 3.0, not all elements are contained within an SPDX document and we can't be guaranteed that a namespace is available for all `TypedValue` typed properties. Methods that are passed a `DocumentNamespace` and an `id` now are passed a URI. To translate from SPDX 2.X, the `DocumentNamespace` concatenated with the `id` can be used for the URI. ### Change TypedValue structure -`TypedValue` \ No newline at end of file + +`TypedValue` now takes an ObjectURI rather than an ID. +Note that the method signature has not changed, so you may need to manually search for usage in order to change. +There is a convenience helper method `CompatibleModelStoreWrapper.typedValueFromDocUri(String documentUri, String id, boolean anonymous, String type)` that will convert from the SPDX V2 TypedValue to the current version. + +### CompatibleModelStoreWrapper + +To help with the migration, the `CompatibleModelStoreWrapper` class was introduced supporting the `IModelStore` interface taking a base store as a parameter in the constructor. This class "wraps" the base store and supports the SPDX 2 methods which take the document namespace parameters. + +There is also a convenience static method to convert a namespace and ID to an Object URI. \ No newline at end of file diff --git a/src/main/java/org/spdx/library/DefaultModelStore.java b/src/main/java/org/spdx/library/DefaultModelStore.java index 6122ced7d..0b55997b4 100644 --- a/src/main/java/org/spdx/library/DefaultModelStore.java +++ b/src/main/java/org/spdx/library/DefaultModelStore.java @@ -21,6 +21,7 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -33,8 +34,8 @@ * */ public class DefaultModelStore { - - static IModelStore defaultModelStore = new InMemSpdxStore(); + + static IModelStore defaultModelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_3); static String defaultDocumentUri = "http://www.spdx.org/documents/default_doc_uri_for_SPDX_tools"; static ModelCopyManager defaultCopyManager = new ModelCopyManager(); private static final ReadWriteLock lock = new ReentrantReadWriteLock(); @@ -64,7 +65,7 @@ public static String getDefaultDocumentUri() { /** * Clears the default model store by replacing the default model store with a new one */ - public static final void reset() { + public static final void reset(SpdxMajorVersion spdxSpecVersion) { lock.writeLock().lock(); try { if (Objects.nonNull(defaultModelStore)) { @@ -74,7 +75,7 @@ public static final void reset() { throw new RuntimeException(e); } } - defaultModelStore = new InMemSpdxStore(); + defaultModelStore = new InMemSpdxStore(spdxSpecVersion); defaultCopyManager = new ModelCopyManager(); } finally { lock.writeLock().unlock(); diff --git a/src/main/java/org/spdx/library/model/compat/v2/IndividualUriValue.java b/src/main/java/org/spdx/library/IndividualUriValue.java similarity index 96% rename from src/main/java/org/spdx/library/model/compat/v2/IndividualUriValue.java rename to src/main/java/org/spdx/library/IndividualUriValue.java index 34eb6b070..810621e51 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/IndividualUriValue.java +++ b/src/main/java/org/spdx/library/IndividualUriValue.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; +package org.spdx.library; /** * Classes which implement the IndividuallUriValue interface will be stored as a single value. Theses classes diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index f0e016634..7cd03c75f 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -23,10 +23,11 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.model.compat.v2.IndividualUriValue; -import org.spdx.library.model.compat.v2.SimpleUriValue; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -48,15 +49,15 @@ public class ModelCopyManager { static final Logger logger = LoggerFactory.getLogger(ModelCopyManager.class); /** - * Map of copied ID's fromModelStore, toModelStore, fromDocUri, toDocUri, fromId, toId + * Map of copied ID's fromModelStore, toModelStore, fromObjectUri, toObjectUri * Used to keep track of copied ID's to make sure we don't copy them more than once */ private ConcurrentHashMap>>>> COPIED_IDS = + String>>> COPIED_IDS = new ConcurrentHashMap<>(); /** - * Create a ModelCopyManager with default options + * Create a CompatV2ModelCopyManager with default options */ public ModelCopyManager() { // Required empty constructor @@ -64,80 +65,61 @@ public ModelCopyManager() { /** * @param fromStore Store copied from - * @param fromDocumentUri document copied from - * @param fromId ID copied from + * @param fromObjectUri * @param toStore store copied to - * @param toDocumentUri document copied to - * @return the ID which has already been copied, or null if it has not been copied + * @return the objectId which has already been copied, or null if it has not been copied */ - public String getCopiedId(IModelStore fromStore, String fromDocumentUri, String fromId, - IModelStore toStore, String toDocumentUri) { - ConcurrentHashMap>>> fromStoreMap = COPIED_IDS.get(fromStore); + public String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri, + IModelStore toStore) { + ConcurrentHashMap> fromStoreMap = COPIED_IDS.get(fromStore); if (Objects.isNull(fromStoreMap)) { return null; } - ConcurrentHashMap>> toStoreMap = fromStoreMap.get(toStore); + ConcurrentHashMap toStoreMap = fromStoreMap.get(toStore); if (Objects.isNull(toStoreMap)) { return null; } - ConcurrentHashMap> fromDocumentMap = toStoreMap.get(fromDocumentUri); - if (Objects.isNull(fromDocumentMap)) { - return null; - } - ConcurrentHashMap idMap = fromDocumentMap.get(toDocumentUri); - if (Objects.isNull(idMap)) { - return null; - } - return idMap.get(fromId); + return toStoreMap.get(fromObjectUri); } /** * Record a copied ID between model stores * @param fromStore Store copied from - * @param fromDocumentUri document copied from - * @param fromId ID copied from - * @param toStore store copied to - * @param toDocumentUri document copied to + * @param fromObjectUri URI for the from Object + * @param toObjectUri URI for the to Object * @param toId ID copied to * @return any copied to ID for the same stores, URI's and fromID */ - public String putCopiedId(IModelStore fromStore, String fromDocumentUri, String fromId, IModelStore toStore, - String toDocumentUri, String toId) { - ConcurrentHashMap>>> fromStoreMap = COPIED_IDS.get(fromStore); + public String putCopiedId(IModelStore fromStore, String fromObjectUri, IModelStore toStore, + String toObjectUri) { + ConcurrentHashMap> fromStoreMap = COPIED_IDS.get(fromStore); while (Objects.isNull(fromStoreMap)) { fromStoreMap = COPIED_IDS.putIfAbsent(fromStore, new ConcurrentHashMap<>()); } - ConcurrentHashMap>> toStoreMap = fromStoreMap.get(toStore); + ConcurrentHashMap toStoreMap = fromStoreMap.get(toStore); while (Objects.isNull(toStoreMap)) { toStoreMap = fromStoreMap.putIfAbsent(toStore, new ConcurrentHashMap<>()); } - ConcurrentHashMap> fromDocumentMap = toStoreMap.get(fromDocumentUri); - while (Objects.isNull(fromDocumentMap)) { - fromDocumentMap = toStoreMap.putIfAbsent(fromDocumentUri, new ConcurrentHashMap<>()); + if (toStoreMap.containsKey(fromObjectUri)) { + logger.warn("Object URI already exists for the originating "+ fromObjectUri); } - ConcurrentHashMap idMap = fromDocumentMap.get(toDocumentUri); - while (Objects.isNull(idMap)) { - idMap = fromDocumentMap.putIfAbsent(toDocumentUri, new ConcurrentHashMap<>()); - } - if (idMap.containsKey(fromId)) { - logger.warn("ID already exists for the originating "+fromDocumentUri+"#"+fromId + ":" + toDocumentUri + "#"); - } - return idMap.put(fromId, toId); + return toStoreMap.put(fromObjectUri, toObjectUri); } /** * Copy an item from one Model Object Store to another * @param toStore Model Store to copy to - * @param toId Id to use in the copy - * @param toDocumentUri Target document URI + * @param toObjectUri URI for the destination object * @param fromStore Model Store containing the source item - * @param fromDocumentUri Document URI for the source item - * @param fromId ID source ID + * @param fromObjectUri Object URI for the source item * @param type Type to copy + * @param fromNamespace optional namespace of the from property + * @param toNamespace optional namespace of the to property * @throws InvalidSPDXAnalysisException */ - public void copy(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, String fromDocumentUri, String fromId, String type) throws InvalidSPDXAnalysisException { - copy(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, type, false); + public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri, String type, + @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + copy(toStore, toObjectUri, fromStore, fromObjectUri, type, false, fromNamespace, toNamespace); } /** @@ -150,34 +132,37 @@ public void copy(IModelStore toStore, String toDocumentUri, String toId, IModelS * @param fromId ID source ID * @param type Type to copy * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses + * @param fromNamespace optional namespace of the from property + * @param toNamespace optional namespace of the to property * @throws InvalidSPDXAnalysisException */ - public void copy(IModelStore toStore, String toDocumentUri, String toId, - IModelStore fromStore, String fromDocumentUri, String fromId, - String type, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { + public void copy(IModelStore toStore, String toObjectUri, + IModelStore fromStore, String fromObjectUri, + String type, boolean excludeLicenseDetails, + @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { Objects.requireNonNull(toStore, "ToStore can not be null"); - Objects.requireNonNull(toDocumentUri, "To Document URI can not be null"); + Objects.requireNonNull(toObjectUri, "To Object URI can not be null"); Objects.requireNonNull(fromStore, "FromStore can not be null"); - Objects.requireNonNull(fromDocumentUri, "From Document URI can not be null"); - Objects.requireNonNull(fromId, "From ID can not be null"); - Objects.requireNonNull(toId, "To ID can not be null"); + Objects.requireNonNull(fromObjectUri, "From ObjectUri can not be null"); Objects.requireNonNull(type, "Type can not be null"); - if (fromStore.equals(toStore) && fromDocumentUri.equals(toDocumentUri) && fromId.equals(toId)) { + if (fromStore.equals(toStore) && fromObjectUri.equals(toObjectUri)) { return; // trying to copy the same thing! } - if (!toStore.exists(toDocumentUri, toId)) { - toStore.create(toDocumentUri, toId, type); + if (!toStore.exists(toObjectUri)) { + toStore.create(toObjectUri, type); } - putCopiedId(fromStore, fromDocumentUri, fromId, toStore, toDocumentUri, toId); + putCopiedId(fromStore, fromObjectUri, toStore, toObjectUri); if (!(excludeLicenseDetails && (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(type) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)))) { - List propertyDescriptors = fromStore.getPropertyValueDescriptors(fromDocumentUri, fromId); + List propertyDescriptors = fromStore.getPropertyValueDescriptors(fromObjectUri); for (PropertyDescriptor propDesc:propertyDescriptors) { - if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propDesc)) { - copyCollectionProperty(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, propDesc, excludeLicenseDetails); + if (fromStore.isCollectionProperty(fromObjectUri, propDesc)) { + copyCollectionProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, excludeLicenseDetails, + fromNamespace, toNamespace); } else { - copyIndividualProperty(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, fromId, propDesc, excludeLicenseDetails); + copyIndividualProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, excludeLicenseDetails, + fromNamespace, toNamespace); } } } @@ -186,42 +171,43 @@ public void copy(IModelStore toStore, String toDocumentUri, String toId, /** * Copies an individual property value (non-collection property value) * @param toStore Model Store to copy to - * @param toId Id to use in the copy - * @param toDocumentUri Target document URI + * @param toObjectUri to object URI to copy to * @param fromStore Model Store containing the source item - * @param fromDocumentUri Document URI for the source item - * @param fromId ID source ID + * @param fromObjectUri object to copy from * @param propDescriptor Descriptor for the property * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses + * @param fromNamespace optional namespace of the from property + * @param toNamespace optional namespace of the to property * @throws InvalidSPDXAnalysisException */ - private void copyIndividualProperty(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, - String fromDocumentUri, String fromId, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { - IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(fromDocumentUri, false); + private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IModelStore fromStore, + String fromObjectUri, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails, + @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(false); //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection Optional result = Optional.empty(); try { - if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propDescriptor)) { + if (fromStore.isCollectionProperty(fromObjectUri, propDescriptor)) { throw new InvalidSPDXAnalysisException("Property "+propDescriptor+" is a collection type"); } - result = fromStore.getValue(fromDocumentUri, fromId, propDescriptor); + result = fromStore.getValue(fromObjectUri, propDescriptor); } finally { fromStoreLock.unlock(); } if (result.isPresent()) { if (result.get() instanceof IndividualUriValue) { - toStore.setValue(toDocumentUri, toId, propDescriptor, new SimpleUriValue((IndividualUriValue)result.get())); + toStore.setValue(toObjectUri, propDescriptor, new SimpleUriValue((IndividualUriValue)result.get())); } else if (result.get() instanceof TypedValue) { TypedValue tv = (TypedValue)result.get(); - if (fromStore.equals(toStore) && fromDocumentUri.equals(toDocumentUri)) { - toStore.setValue(toDocumentUri, toId, propDescriptor, tv); + if (fromStore.equals(toStore)) { + toStore.setValue(toObjectUri, propDescriptor, tv); } else { - toStore.setValue(toDocumentUri, toId, propDescriptor, - copy(toStore, toDocumentUri, fromStore, fromDocumentUri, - tv.getId(), tv.getType(), excludeLicenseDetails)); + toStore.setValue(toObjectUri, propDescriptor, + copy(toStore, fromStore, tv.getObjectUri(), tv.getType(), excludeLicenseDetails, + fromNamespace, toNamespace)); } } else { - toStore.setValue(toDocumentUri, toId, propDescriptor, result.get()); + toStore.setValue(toObjectUri, propDescriptor, result.get()); } } } @@ -229,25 +215,26 @@ private void copyIndividualProperty(IModelStore toStore, String toDocumentUri, S /** * Copies a property which is is a collection * @param toStore Model Store to copy to - * @param toId Id to use in the copy - * @param toDocumentUri Target document URI + * @param toObjectUri URI to copy to * @param fromStore Model Store containing the source item - * @param fromDocumentUri Document URI for the source item - * @param fromId ID source ID + * @param fromDocumentUri Object URI to copy from * @param propDescriptor Descriptor for the property * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses + * * @param fromNamespace optional namespace of the from property + * @param toNamespace optional namespace of the to property * @throws InvalidSPDXAnalysisException */ - private void copyCollectionProperty(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, - String fromDocumentUri, String fromId, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { - IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(fromDocumentUri, false); + private void copyCollectionProperty(IModelStore toStore, String toObjectUri, IModelStore fromStore, + String fromObjectUri, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails, + @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(false); //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection Iterator fromListIter = null; try { - if (!fromStore.isCollectionProperty(fromDocumentUri, fromId, propDescriptor)) { + if (!fromStore.isCollectionProperty(fromObjectUri, propDescriptor)) { throw new InvalidSPDXAnalysisException("Property "+propDescriptor+" is not a collection type"); } - fromListIter = fromStore.listValues(fromDocumentUri, fromId, propDescriptor); + fromListIter = fromStore.listValues(fromObjectUri, propDescriptor); } finally { fromStoreLock.unlock(); } @@ -258,77 +245,89 @@ private void copyCollectionProperty(IModelStore toStore, String toDocumentUri, S toStoreItem = new SimpleUriValue((IndividualUriValue)listItem); } else if (listItem instanceof TypedValue) { TypedValue listItemTv = (TypedValue)listItem; - if (toStore.equals(fromStore) && toDocumentUri.equals(fromDocumentUri)) { + if (toStore.equals(fromStore)) { toStoreItem = listItemTv; } else { - toStoreItem = copy(toStore, toDocumentUri, fromStore, fromDocumentUri, - listItemTv.getId(), listItemTv.getType(), excludeLicenseDetails); + toStoreItem = copy(toStore, fromStore, listItemTv.getObjectUri(), + listItemTv.getType(), excludeLicenseDetails, fromNamespace, toNamespace); } } else { toStoreItem = listItem; } - toStore.addValueToCollection(toDocumentUri, toId, propDescriptor, toStoreItem); + toStore.addValueToCollection(toObjectUri, propDescriptor, toStoreItem); } } /** * Copy an item from one Model Object Store to another using the source ID for the target unless it is anonymous * @param toStore Model Store to copy to - * @param toDocumentUri Target document URI * @param fromStore Model Store containing the source item - * @param fromDocumentUri Document URI for the source item - * @param sourceId ID source ID + * @param sourceObjectUri source object URI * @param type Type to copy - * @return ID for the copied object + * @param fromNamespace optional namespace of the from property + * @param toNamespace optional namespace of the to property + * @return Object URI for the copied object * @throws InvalidSPDXAnalysisException */ - public TypedValue copy(IModelStore toStore, String toDocumentUri, IModelStore fromStore, - String fromDocumentUri, String sourceId, String type) throws InvalidSPDXAnalysisException { - return copy(toStore, toDocumentUri, fromStore, fromDocumentUri, sourceId, type, false); + public TypedValue copy(IModelStore toStore, IModelStore fromStore, + String sourceObjectUri, String type, + @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + return copy(toStore, fromStore, sourceObjectUri, type, false, fromNamespace, toNamespace); } /** * Copy an item from one Model Object Store to another using the source ID for the target unless it is anonymous * @param toStore Model Store to copy to - * @param toDocumentUri Target document URI * @param fromStore Model Store containing the source item - * @param fromDocumentUri Document URI for the source item - * @param sourceId ID source ID + * @param sourceUri URI for the Source object * @param type Type to copy * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses - * @return ID for the copied object + * @param fromNamespace optional namespace of the from property + * @param toNamespace optional namespace of the to property + * @return Object URI for the copied object * @throws InvalidSPDXAnalysisException */ - public TypedValue copy(IModelStore toStore, String toDocumentUri, IModelStore fromStore, - String fromDocumentUri, String sourceId, String type, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { + public TypedValue copy(IModelStore toStore, IModelStore fromStore, + String sourceUri, String type, boolean excludeLicenseDetails, + @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { Objects.requireNonNull(toStore, "To Store can not be null"); - Objects.requireNonNull(toDocumentUri, "To Document URI can not be null"); Objects.requireNonNull(fromStore, "From Store can not be null"); - Objects.requireNonNull(fromDocumentUri, "From Document URI can not be null"); - Objects.requireNonNull(sourceId, "Source ID can not be null"); + Objects.requireNonNull(sourceUri, "Source URI can not be null"); Objects.requireNonNull(type, "Type can not be null"); - String toId = getCopiedId(fromStore, fromDocumentUri, sourceId, toStore, toDocumentUri); - if (Objects.isNull(toId)) { - if (fromStore.getIdType(sourceId) == IdType.Anonymous || toStore.exists(toDocumentUri, sourceId)) { + if (fromStore.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) >= 0 && + toStore.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) < 0) { + throw new InvalidSPDXAnalysisException("Can not copy from SPDX spec version 3.0 to SPDX spec version less than 3.0"); + } + String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore); + if (Objects.isNull(toObjectUri)) { + if (!(fromStore.getIdType(sourceUri) == IdType.Anonymous)) { + if (Objects.nonNull(fromNamespace) && sourceUri.startsWith(fromNamespace) && Objects.nonNull(toNamespace)) { + toObjectUri = toNamespace + sourceUri.substring(fromNamespace.length()); + } else { + toObjectUri = sourceUri; + } + } + if (Objects.isNull(toObjectUri) || toStore.exists(toObjectUri)) { if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { - toId = toStore.getNextId(IdType.DocumentRef, toDocumentUri); + toObjectUri = toStore.getNextId(IdType.DocumentRef, toNamespace); } else { - switch (fromStore.getIdType(sourceId)) { - case Anonymous: toId = toStore.getNextId(IdType.Anonymous, toDocumentUri); break; - case LicenseRef: toId = toStore.getNextId(IdType.LicenseRef, toDocumentUri); break; - case DocumentRef: toId = toStore.getNextId(IdType.DocumentRef, toDocumentUri); break; - case SpdxId: toId = toStore.getNextId(IdType.SpdxId, toDocumentUri); break; + switch (fromStore.getIdType(sourceUri)) { + case Anonymous: toObjectUri = toStore.getNextId(IdType.Anonymous, toNamespace); break; + case LicenseRef: toObjectUri = toStore.getNextId(IdType.LicenseRef, toNamespace); break; + case DocumentRef: toObjectUri = toStore.getNextId(IdType.DocumentRef, toNamespace); break; + case SpdxId: toObjectUri = toStore.getNextId(IdType.SpdxId, toNamespace); break; case ListedLicense: case Literal: case Unkown: - default: toId = sourceId; + default: toObjectUri = sourceUri; } } - } else { - toId = sourceId; } - copy(toStore, toDocumentUri, toId, fromStore, fromDocumentUri, sourceId, type, excludeLicenseDetails); + if (Objects.isNull(toObjectUri)) { + toObjectUri = sourceUri; + } + copy(toStore, toObjectUri, fromStore, sourceUri, type, excludeLicenseDetails, fromNamespace, toNamespace); } - return new TypedValue(toId, type); + return new TypedValue(toObjectUri, type); } } diff --git a/src/main/java/org/spdx/library/ModelObjectHelper.java b/src/main/java/org/spdx/library/ModelObjectHelper.java new file mode 100644 index 000000000..4bb759e01 --- /dev/null +++ b/src/main/java/org/spdx/library/ModelObjectHelper.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +/** + * A set of static methods to help with common ModelObject functions + * + * @author Gary O'Neall + * + */ +public class ModelObjectHelper { + +} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SimpleUriValue.java b/src/main/java/org/spdx/library/SimpleUriValue.java similarity index 72% rename from src/main/java/org/spdx/library/model/compat/v2/SimpleUriValue.java rename to src/main/java/org/spdx/library/SimpleUriValue.java index 47e409bb0..30cbe4df5 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SimpleUriValue.java +++ b/src/main/java/org/spdx/library/SimpleUriValue.java @@ -15,19 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; +package org.spdx.library; import java.util.Objects; +import javax.annotation.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; -import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; /** @@ -87,27 +83,37 @@ public String getIndividualURI() { * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if it matches the pattern of an external SPDX element * or returns itself otherwise * @param store - * @param documentUri * @param copyManager if non-null, implicitly copy any referenced properties from other model stores * @return Enum, ExternalSpdxElement or itself depending on the pattern * @throws InvalidSPDXAnalysisException */ - public Object toModelObject(IModelStore store, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Object retval = SpdxEnumFactory.uriToEnum.get(uri); + public Object toModelObject(IModelStore store, ModelCopyManager copyManager, @Nullable String defaultNamespace) throws InvalidSPDXAnalysisException { + if (store.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) < 0) { + if (Objects.isNull(defaultNamespace)) { + logger.error("Default namespace can not be null for SPDX 2 model stores"); + throw new InvalidSPDXAnalysisException("Default namespace can not be null for SPDX 2 model stores"); + } + return toModelObjectV2Compat(store, defaultNamespace, copyManager); + } else { + throw new InvalidSPDXAnalysisException("Not implemented"); + } + } + private Object toModelObjectV2Compat(IModelStore store, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Object retval = org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory.uriToEnum.get(uri); if (Objects.nonNull(retval)) { return retval; } else if (SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri).matches()) { - return ExternalSpdxElement.uriToExternalSpdxElement(uri, store, documentUri, copyManager); + return org.spdx.library.model.compat.v2.ExternalSpdxElement.uriToExternalSpdxElement(uri, store, documentUri, copyManager); } else if (SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri).matches()) { - return ExternalExtractedLicenseInfo.uriToExternalExtractedLicense(uri, store, documentUri, copyManager); + return org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.uriToExternalExtractedLicense(uri, store, documentUri, copyManager); } else if (SpdxConstantsCompatV2.REFERENCE_TYPE_URI_PATTERN.matcher(uri).matches()) { - return new ReferenceType(this); + return new org.spdx.library.model.compat.v2.ReferenceType(this); } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { // Default value is a license, although it can also be a string or an SpdxElement // the caller should override the type based on the type expected - return new SpdxNoneLicense(store, documentUri); + return new org.spdx.library.model.compat.v2.license.SpdxNoneLicense(store, documentUri); } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - return new SpdxNoAssertionLicense(store, documentUri); + return new org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense(store, documentUri); } else { logger.warn("URI "+uri+" does not match any model object or enumeration"); return this; diff --git a/src/main/java/org/spdx/library/SpdxConstants.java b/src/main/java/org/spdx/library/SpdxConstants.java new file mode 100644 index 000000000..33da39733 --- /dev/null +++ b/src/main/java/org/spdx/library/SpdxConstants.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +/** + * Constants which map to the SPDX specifications + * @author Gary O'Neall + * + */ +public class SpdxConstants { + + public enum SpdxMajorVersion { + VERSION_1, + VERSION_2, + VERSION_3; + + public static SpdxMajorVersion latestVersion() { + return VERSION_3; + } + } + +} diff --git a/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java b/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java index 1e1dae572..bf05d211a 100644 --- a/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java +++ b/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java @@ -22,11 +22,13 @@ /** - * Constants which map to the SPDX specifications found at http://spdx.org/rdf/terms + * Constants which map to the SPDX specifications for versions prior to SPDX Spec version 3.0 * @author Gary O'Neall * */ public class SpdxConstantsCompatV2 { + + public static final String SPDX_VERSION_2 = "2"; // Namespaces public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; @@ -407,4 +409,5 @@ public class SpdxConstantsCompatV2 { public static final String LICENSEXML_ATTRIBUTE_ALT_MATCH = "match"; public static final String LICENSEXML_ELEMENT_BREAK = "br"; public static final String LICENSEXML_ELEMENT_TEXT = "text"; + } \ No newline at end of file diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index 709b70509..02ea8a193 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -17,8 +17,10 @@ */ package org.spdx.library; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import java.text.SimpleDateFormat; import java.util.Collections; @@ -47,59 +49,65 @@ public class SpdxModelFactory { static final Logger logger = LoggerFactory.getLogger(SpdxModelFactory.class); public static Map> SPDX_TYPE_TO_CLASS_V2; + public static Map> SPDX_TYPE_TO_CLASS_V3; public static Map, String> SPDX_CLASS_TO_TYPE; static { - Map> typeToClass = new HashMap<>(); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, org.spdx.library.model.compat.v2.SpdxDocument.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, org.spdx.library.model.compat.v2.SpdxPackage.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO, org.spdx.library.model.compat.v2.SpdxCreatorInformation.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, org.spdx.library.model.compat.v2.Checksum.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO, org.spdx.library.model.compat.v2.license.AnyLicenseInfo.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO, org.spdx.library.model.compat.v2.license.SimpleLicensingInfo.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE, org.spdx.library.model.compat.v2.license.License.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, org.spdx.library.model.compat.v2.license.SpdxListedLicense.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.LicenseException.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.ListedLicenseException.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR, org.spdx.library.model.compat.v2.license.OrLaterOperator.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, org.spdx.library.model.compat.v2.license.WithExceptionOperator.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_FILE, org.spdx.library.model.compat.v2.SpdxFile.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE, org.spdx.library.model.compat.v2.SpdxPackageVerificationCode.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_ANNOTATION, org.spdx.library.model.compat.v2.Annotation.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_RELATIONSHIP, org.spdx.library.model.compat.v2.Relationship.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ITEM, org.spdx.library.model.compat.v2.SpdxItem.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT, org.spdx.library.model.compat.v2.SpdxElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoneElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoAssertionElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, org.spdx.library.model.compat.v2.ExternalDocumentRef.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE, org.spdx.library.model.compat.v2.ExternalRef.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE, org.spdx.library.model.compat.v2.ReferenceType.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, org.spdx.library.model.compat.v2.SpdxSnippet.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_NONE_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoneLicense.class); - typeToClass.put(org.spdx.library.model.compat.v2.GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, org.spdx.library.model.compat.v2.GenericModelObject.class); - typeToClass.put(org.spdx.library.model.compat.v2.GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, org.spdx.library.model.compat.v2.GenericSpdxElement.class); - typeToClass.put(org.spdx.library.model.compat.v2.GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, org.spdx.library.model.compat.v2.GenericSpdxItem.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT, org.spdx.library.model.compat.v2.ExternalSpdxElement.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER, org.spdx.library.model.compat.v2.pointer.StartEndPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER, org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER, org.spdx.library.model.compat.v2.pointer.LineCharPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, org.spdx.library.model.compat.v2.pointer.CompoundPointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, org.spdx.library.model.compat.v2.pointer.SinglePointer.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, org.spdx.library.model.compat.v2.license.CrossRef.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.compat.v2.enumerations.FileType.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.compat.v2.enumerations.AnnotationType.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.compat.v2.enumerations.ReferenceCategory.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.compat.v2.enumerations.RelationshipType.class); - typeToClass.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.class); - typeToClass.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.compat.v2.enumerations.Purpose.class); - SPDX_TYPE_TO_CLASS_V2 = Collections.unmodifiableMap(typeToClass); - + Map> typeToClassV2 = new HashMap<>(); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, org.spdx.library.model.compat.v2.SpdxDocument.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, org.spdx.library.model.compat.v2.SpdxPackage.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO, org.spdx.library.model.compat.v2.SpdxCreatorInformation.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, org.spdx.library.model.compat.v2.Checksum.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO, org.spdx.library.model.compat.v2.license.AnyLicenseInfo.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO, org.spdx.library.model.compat.v2.license.SimpleLicensingInfo.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE, org.spdx.library.model.compat.v2.license.License.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, org.spdx.library.model.compat.v2.license.SpdxListedLicense.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.LicenseException.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.ListedLicenseException.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR, org.spdx.library.model.compat.v2.license.OrLaterOperator.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, org.spdx.library.model.compat.v2.license.WithExceptionOperator.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_FILE, org.spdx.library.model.compat.v2.SpdxFile.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE, org.spdx.library.model.compat.v2.SpdxPackageVerificationCode.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_ANNOTATION, org.spdx.library.model.compat.v2.Annotation.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_RELATIONSHIP, org.spdx.library.model.compat.v2.Relationship.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_ITEM, org.spdx.library.model.compat.v2.SpdxItem.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT, org.spdx.library.model.compat.v2.SpdxElement.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoneElement.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoAssertionElement.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, org.spdx.library.model.compat.v2.ExternalDocumentRef.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE, org.spdx.library.model.compat.v2.ExternalRef.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE, org.spdx.library.model.compat.v2.ReferenceType.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, org.spdx.library.model.compat.v2.SpdxSnippet.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_NONE_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoneLicense.class); + typeToClassV2.put(org.spdx.library.model.compat.v2.GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, org.spdx.library.model.compat.v2.GenericModelObject.class); + typeToClassV2.put(org.spdx.library.model.compat.v2.GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, org.spdx.library.model.compat.v2.GenericSpdxElement.class); + typeToClassV2.put(org.spdx.library.model.compat.v2.GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, org.spdx.library.model.compat.v2.GenericSpdxItem.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT, org.spdx.library.model.compat.v2.ExternalSpdxElement.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER, org.spdx.library.model.compat.v2.pointer.StartEndPointer.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER, org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER, org.spdx.library.model.compat.v2.pointer.LineCharPointer.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, org.spdx.library.model.compat.v2.pointer.CompoundPointer.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, org.spdx.library.model.compat.v2.pointer.SinglePointer.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, org.spdx.library.model.compat.v2.license.CrossRef.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.compat.v2.enumerations.FileType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.compat.v2.enumerations.AnnotationType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.compat.v2.enumerations.ReferenceCategory.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.compat.v2.enumerations.RelationshipType.class); + typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.compat.v2.enumerations.Purpose.class); + SPDX_TYPE_TO_CLASS_V2 = Collections.unmodifiableMap(typeToClassV2); + Map> typeToClassV3 = new HashMap<>(); + //TODO Add V3 class strings + SPDX_TYPE_TO_CLASS_V3 = Collections.unmodifiableMap(typeToClassV3); Map, String> classToType = new HashMap<>(); - for (Entry> entry:typeToClass.entrySet()) { + for (Entry> entry:typeToClassV2.entrySet()) { + classToType.put(entry.getValue(), entry.getKey()); + } + for (Entry> entry:typeToClassV3.entrySet()) { classToType.put(entry.getValue(), entry.getKey()); } @@ -130,10 +138,10 @@ public static org.spdx.library.model.compat.v2.SpdxDocument createSpdxDocumentV2 } /** - * Create a model object in a model store given the document URI, ID and type + * Create an SPDX version 2 model object in a model store given the document URI, ID and type * @param modelStore model store where the object is to be created * @param documentUri document URI for the stored item - * @param id ID for the item + * @param objectUri ID for the item * @param type SPDX class or type * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced * @return a ModelObject of type type @@ -148,7 +156,7 @@ public static org.spdx.library.model.compat.v2.ModelObject createModelObject(IMo * Create an SPDX spec version 2.X model object in a model store given the document URI, ID and type * @param modelStore model store where the object is to be created * @param documentUri document URI for the stored item - * @param id ID for the item + * @param objectUri ID for the item * @param type SPDX class or type * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced * @param create if true, create the model object if it does not already exist @@ -203,29 +211,51 @@ public static org.spdx.library.model.compat.v2.ModelObject getModelObjectV2(IMod /** * @param type SPDX Type + * @param specVersion Version of the SPDX Spec * @return class associated with the type * @throws InvalidSPDXAnalysisException */ - public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { - Class retval = SPDX_TYPE_TO_CLASS_V2.get(type); + public static Class typeToClass(String type, SpdxMajorVersion specVersion) throws InvalidSPDXAnalysisException { + Class retval; + if (specVersion.compareTo(SpdxMajorVersion.VERSION_3) < 0) { + retval = SPDX_TYPE_TO_CLASS_V2.get(type); + } else { + retval = SPDX_TYPE_TO_CLASS_V3.get(type); + } if (Objects.isNull(retval)) { throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); } return retval; } - public static Stream getElements(IModelStore store, String documentUri, ModelCopyManager copyManager, + /** + * @param type SPDX Type + * @return class associated with the type for the latest spec version + * @throws InvalidSPDXAnalysisException + */ + public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { + return typeToClass(type, SpdxMajorVersion.latestVersion()); + } + + /** + * @param store model store + * @param nameSpace optional namespace to filter elements on + * @param copyManager optional copy manager + * @param spdxClass class to filter elements on + * @return + * @throws InvalidSPDXAnalysisException + */ + public static Stream getElements(IModelStore store, @Nullable String nameSpace, @Nullable ModelCopyManager copyManager, Class spdxClass) throws InvalidSPDXAnalysisException { Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(documentUri, "documentUri must not be null"); Objects.requireNonNull(spdxClass, "spdxClass must not be null"); String type = SPDX_CLASS_TO_TYPE.get(spdxClass); if (Objects.isNull(type)) { throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); } - return store.getAllItems(documentUri, type).map(tv -> { + return store.getAllItems(nameSpace, type).map(tv -> { try { - return createModelObject(store, documentUri, tv.getId(), tv.getType(), copyManager); + return createModelObject(store, nameSpace, tv.getObjectUri(), tv.getType(), copyManager); } catch (InvalidSPDXAnalysisException e) { logger.error("Error creating model object",e); throw new RuntimeException(e); @@ -235,24 +265,34 @@ public static Stream getElements(IModelStore store, String documentUri, Model /** * @param classUri URI for the class type + * @param specVersion Version of the SPDX Spec * @return class represented by the URI * @throws InvalidSPDXAnalysisException */ - public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { + public static Class classUriToClass(String classUri, SpdxMajorVersion specVersion) throws InvalidSPDXAnalysisException { Objects.requireNonNull(classUri, "Missing required class URI"); int indexOfPound = classUri.lastIndexOf('#'); if (indexOfPound < 1) { throw new InvalidSPDXAnalysisException("Invalid class URI: "+classUri); } String type = classUri.substring(indexOfPound+1); - return typeToClass(type); + return typeToClass(type, specVersion); + } + + /** + * @param classUri URI for the class type + * @return class represented by the URI for the more recent spec version + * @throws InvalidSPDXAnalysisException + */ + public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { + return classUriToClass(classUri, SpdxMajorVersion.latestVersion()); } /** * @param modelStore Store for the SPDX Spec version 2 model * @param documentUri Document URI for for the ID * @param copyManager Optional copy manager for copying any properties from other model - * @param id ID for the model object + * @param objectUri ID for the model object * @return SPDX Version 2 compatibile ModelObject with the ID in the model store * @throws InvalidSPDXAnalysisException */ @@ -267,7 +307,8 @@ public static Optional getModelObj return Optional.empty(); } } - Optional tv = modelStore.getTypedValue(documentUri, id); + Optional tv = modelStore.getTypedValue( + CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore.getIdType(id).equals(IdType.Anonymous))); if (tv.isPresent()) { String type = tv.get().getType(); try { diff --git a/src/main/java/org/spdx/library/SpdxVerificationHelper.java b/src/main/java/org/spdx/library/SpdxVerificationHelper.java index 064724ab5..7abcdf014 100644 --- a/src/main/java/org/spdx/library/SpdxVerificationHelper.java +++ b/src/main/java/org/spdx/library/SpdxVerificationHelper.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.regex.Pattern; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; @@ -74,12 +75,13 @@ public class SpdxVerificationHelper { static final String[] VALID_CREATOR_PREFIXES = new String[] {SpdxConstantsCompatV2.CREATOR_PREFIX_PERSON, SpdxConstantsCompatV2.CREATOR_PREFIX_ORGANIZATION, SpdxConstantsCompatV2.CREATOR_PREFIX_TOOL}; static final String[] VALID_ORIGINATOR_SUPPLIER_PREFIXES = new String[] {SpdxConstantsCompatV2.NOASSERTION_VALUE, "Person:", "Organization:"}; + private static final Pattern SPDX_ELEMENT_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$"); public static String verifyNonStdLicenseid(String licenseId) { if (SpdxConstantsCompatV2.LICENSE_ID_PATTERN.matcher(licenseId).matches()) { return null; } else { - return "Invalid license id '"+licenseId+"'. Must start with 'LicenseRef-' " + + return "Invalid license objectUri '"+licenseId+"'. Must start with 'LicenseRef-' " + "and made up of the characters from the set 'a'-'z', 'A'-'Z', '0'-'9', '+', '_', '.', and '-'."; } } @@ -295,10 +297,10 @@ public static String verifyDownloadLocation(String downloadLocation) { } /** - * @param id + * @param objectUri * @return true if the ID is a valid SPDX ID reference */ public static boolean verifySpdxId(String id) { - return SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PATTERN.matcher(id).matches(); + return SPDX_ELEMENT_ID_PATTERN.matcher(id).matches(); } } diff --git a/src/main/java/org/spdx/library/TypedValue.java b/src/main/java/org/spdx/library/TypedValue.java index ec7ea9020..2f1a6e071 100644 --- a/src/main/java/org/spdx/library/TypedValue.java +++ b/src/main/java/org/spdx/library/TypedValue.java @@ -16,11 +16,11 @@ public class TypedValue { static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); - String id; + String objectUri; String type; - public TypedValue(String id, String type) throws SpdxInvalidIdException, SpdxInvalidTypeException { - if (id == null) { + public TypedValue(String objectUri, String type) throws SpdxInvalidIdException, SpdxInvalidTypeException { + if (objectUri == null) { throw new SpdxInvalidIdException("Null value Id"); } // TODO: can add some additional checks for different string formats based on the type @@ -32,15 +32,15 @@ public TypedValue(String id, String type) throws SpdxInvalidIdException, SpdxInv &&!GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE.equals(type)) { throw new SpdxInvalidTypeException(type + " is not a valid SPDX class"); } - this.id = id; + this.objectUri = objectUri; this.type = type; } /** - * @return the id + * @return the objectUri */ - public String getId() { - return id; + public String getObjectUri() { + return objectUri; } /** @@ -59,11 +59,11 @@ public boolean equals(Object o) { return false; } TypedValue tv = (TypedValue)o; - return tv.getId().equals(this.id) && tv.getType().equals(this.type); + return tv.getObjectUri().equals(this.objectUri) && tv.getType().equals(this.type); } @Override public int hashCode() { - return 181 ^ this.id.hashCode() ^ this.type.hashCode(); + return 181 ^ this.objectUri.hashCode() ^ this.type.hashCode(); } } \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java index 09f4f33ee..2b0aa737f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java @@ -47,7 +47,7 @@ public Annotation() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public Annotation(String id) throws InvalidSPDXAnalysisException { @@ -57,7 +57,7 @@ public Annotation(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java index d0b8f7613..e033bc270 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java @@ -53,7 +53,7 @@ public Checksum() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public Checksum(String id) throws InvalidSPDXAnalysisException { @@ -63,7 +63,7 @@ public Checksum(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index 158fccda1..a40c9dc2a 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -27,8 +27,10 @@ import javax.annotation.Nullable; import org.spdx.library.DefaultModelStore; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxModelFactory; @@ -60,7 +62,7 @@ public static Optional getExternalDocRefByDocNamespace(IMod Objects.requireNonNull(stModelStore, "Model store can not be null"); Objects.requireNonNull(stDocumentUri, "Document URI can not be null"); Objects.requireNonNull(externalDocUri, "External document URI can not be null"); - IModelStoreLock lock = stModelStore.enterCriticalSection(stDocumentUri, false); + IModelStoreLock lock = stModelStore.enterCriticalSection(false); try { ModelCollection existingExternalRefs = new ModelCollection(stModelStore,stDocumentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, copyManager, ExternalDocumentRef.class); @@ -102,7 +104,7 @@ public ExternalDocumentRef() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public ExternalDocumentRef(String id) throws InvalidSPDXAnalysisException { @@ -116,7 +118,7 @@ public ExternalDocumentRef(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @param copyManager - if supplied, model objects will be implicitly copied into this model store and document URI when referenced by setting methods * @param create - if true, the object will be created in the store if it is not already present * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java index c72b4a0e1..354dcccc9 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java @@ -27,6 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; @@ -49,7 +50,7 @@ public ExternalRef() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public ExternalRef(String id) throws InvalidSPDXAnalysisException { @@ -59,7 +60,7 @@ public ExternalRef(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param create * @param copyManager * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java index 8a9fd6313..b9f8fb912 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java @@ -28,8 +28,10 @@ import javax.annotation.Nullable; import org.spdx.library.DefaultModelStore; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; @@ -44,7 +46,7 @@ public class ExternalSpdxElement extends SpdxElement implements IndividualUriVal // Note: the default empty constructor is not allowed since the element ID must follow a specific pattern /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public ExternalSpdxElement(String id) throws InvalidSPDXAnalysisException { @@ -55,7 +57,7 @@ public ExternalSpdxElement(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param create * @throws InvalidSPDXAnalysisException */ @@ -64,7 +66,7 @@ public ExternalSpdxElement(IModelStore modelStore, String documentUri, String id throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); if (!SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id).matches()) { - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } getExternalSpdxElementURI(); //this will check to make sure the external document reference is available } @@ -76,7 +78,7 @@ public ExternalSpdxElement(IModelStore modelStore, String documentUri, String id public String getExternalDocumentId() throws InvalidSPDXAnalysisException { Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } return matcher.group(1); } @@ -88,7 +90,7 @@ public String getExternalDocumentId() throws InvalidSPDXAnalysisException { public String getExternalElementId() throws InvalidSPDXAnalysisException { Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } return matcher.group(2); } @@ -111,7 +113,7 @@ protected List _verify(Set verifiedIds, String specVersion) { String id = this.getId(); Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id); if (!matcher.matches()) { - retval.add("Invalid id format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); + retval.add("Invalid objectUri format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); } else { try { externalDocumentIdToNamespace(matcher.group(1), getModelStore(), getDocumentUri(), getCopyManager()); @@ -142,8 +144,8 @@ public static String externalSpdxElementIdToURI(String externalSpdxElementId, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(externalSpdxElementId); if (!matcher.matches()) { - logger.error("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); + logger.error("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); } String externalDocumentUri; externalDocumentUri = externalDocumentIdToNamespace(matcher.group(1), stModelStore, stDocumentUri, copyManager); diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java index 17225e013..7416da3f6 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java @@ -46,7 +46,7 @@ public GenericModelObject() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public GenericModelObject(String id) throws InvalidSPDXAnalysisException { @@ -56,7 +56,7 @@ public GenericModelObject(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java index 99fcff09a..77146c696 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java @@ -41,7 +41,7 @@ public GenericSpdxElement() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public GenericSpdxElement(String id) throws InvalidSPDXAnalysisException { @@ -51,7 +51,7 @@ public GenericSpdxElement(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java index 6f22e8a2c..b2af9825b 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java @@ -37,7 +37,7 @@ public GenericSpdxItem() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public GenericSpdxItem(String id) throws InvalidSPDXAnalysisException { @@ -47,7 +47,7 @@ public GenericSpdxItem(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java index b45a2e524..99bf9a31d 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java @@ -30,6 +30,7 @@ import javax.annotation.Nullable; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; @@ -40,6 +41,7 @@ import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * Collection of elements stored in a ModelStore @@ -49,7 +51,7 @@ */ public class ModelCollection implements Collection { - private IModelStore modelStore; + private CompatibleModelStoreWrapper modelStore; private String documentUri; private String id; private PropertyDescriptor propertyDescriptor; @@ -80,17 +82,24 @@ public Object next() { /** * @param modelStore Storage for the model collection * @param documentUri SPDX Document URI for a document associated with this model collection - * @param id ID for this collection - must be unique within the SPDX document + * @param objectUri ID for this collection - must be unique within the SPDX document * @param propertyDescriptor descriptor for the property use for the model collections * @param copyManager if non-null, use this to copy properties when referenced outside this model store * @param type The class of the elements to be stored in the collection if none, null if not known * @throws InvalidSPDXAnalysisException */ - public ModelCollection(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, + public ModelCollection(IModelStore baseStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - this.modelStore = modelStore; + Objects.requireNonNull(baseStore, "Model store can not be null"); + if (baseStore instanceof CompatibleModelStoreWrapper) { + this.modelStore = (CompatibleModelStoreWrapper)baseStore; + } else { + // we need to wrap the model store for compatibility. Note - we don't want to + // wrap already wrapped model stores as it will force copies to be made into the same + // base model store + this.modelStore = new CompatibleModelStoreWrapper(baseStore); + } Objects.requireNonNull(documentUri, "Document URI can not be null"); this.documentUri = documentUri; Objects.requireNonNull(id, "ID can not be null"); @@ -277,7 +286,7 @@ public void clear() { /** * @return the modelStore */ - public IModelStore getModelStore() { + public CompatibleModelStoreWrapper getModelStore() { return modelStore; } @@ -289,7 +298,7 @@ public String getDocumentUri() { } /** - * @return the id + * @return the objectUri */ public String getId() { return id; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 6ffdd50ad..7e9741721 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -30,8 +30,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.DefaultModelStore; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxInvalidTypeException; @@ -60,6 +62,7 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.ModelUpdate; import org.spdx.storage.PropertyDescriptor; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * @author Gary O'Neall @@ -100,7 +103,7 @@ public abstract class ModelObject { static final Logger logger = LoggerFactory.getLogger(ModelObject.class); - private IModelStore modelStore; + private CompatibleModelStoreWrapper modelStore; private String documentUri; private String id; @@ -174,7 +177,7 @@ public ModelObject() throws InvalidSPDXAnalysisException { /** * Open or create a model object with the default store and default document URI - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @throws InvalidSPDXAnalysisException */ public ModelObject(String id) throws InvalidSPDXAnalysisException { @@ -183,19 +186,26 @@ public ModelObject(String id) throws InvalidSPDXAnalysisException { } /** - * @param modelStore Storage for the model objects + * @param baseModelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods * @param create - if true, the object will be created in the store if it is not already present * @throws InvalidSPDXAnalysisException */ - public ModelObject(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, + public ModelObject(IModelStore baseModelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model Store can not be null"); + Objects.requireNonNull(baseModelStore, "Model Store can not be null"); Objects.requireNonNull(documentUri, "Document URI can not be null"); Objects.requireNonNull(id, "ID can not be null"); - this.modelStore = modelStore; + if (baseModelStore instanceof CompatibleModelStoreWrapper) { + this.modelStore = (CompatibleModelStoreWrapper)baseModelStore; + } else { + // we need to wrap the model store for compatibility. Note - we don't want to + // wrap already wrapped model stores as it will force copies to be made into the same + // base model store + this.modelStore = new CompatibleModelStoreWrapper(baseModelStore); + } this.documentUri = documentUri; this.id = id; this.copyManager = copyManager; @@ -281,7 +291,7 @@ public String getId() { /** * @return the model store for this object */ - public IModelStore getModelStore() { + public CompatibleModelStoreWrapper getModelStore() { return this.modelStore; } @@ -350,15 +360,16 @@ protected Optional getObjectPropertyValue(PropertyDescriptor propertyDes */ protected static Optional getObjectPropertyValue(IModelStore stModelStore, String stDocumentUri, String stId, PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - IModelStoreLock lock = stModelStore.enterCriticalSection(stDocumentUri, false); + IModelStoreLock lock = stModelStore.enterCriticalSection(false); // NOTE: we use a write lock since the ModelStorageClassConverter may end up creating objects in the store try { - if (!stModelStore.exists(stDocumentUri, stId)) { + if (!stModelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore))) { return Optional.empty(); - } else if (stModelStore.isCollectionProperty(stDocumentUri, stId, propertyDescriptor)) { + } else if (stModelStore.isCollectionProperty(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor)) { return Optional.of(new ModelCollection<>(stModelStore, stDocumentUri, stId, propertyDescriptor, copyManager, null)); } else { - return ModelStorageClassConverter.optionalStoredObjectToModelObject(stModelStore.getValue(stDocumentUri, stId, propertyDescriptor), + return ModelStorageClassConverter.optionalStoredObjectToModelObject(stModelStore.getValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), + propertyDescriptor), stDocumentUri, stModelStore, copyManager); } } finally { @@ -388,7 +399,7 @@ protected static void setPropertyValue(IModelStore stModelStore, String stDocume } else if (value instanceof Collection) { replacePropertyValueCollection(stModelStore, stDocumentUri, stId, propertyDescriptor, (Collection)value, copyManager); } else { - stModelStore.setValue(stDocumentUri, stId, propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject( + stModelStore.setValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject( value, stDocumentUri, stModelStore, copyManager)); } } @@ -588,7 +599,7 @@ protected Optional getElementPropertyValue(PropertyDescriptor prope */ protected static void removeProperty(IModelStore stModelStore, String stDocumentUri, String stId, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - stModelStore.removeProperty(stDocumentUri, stId, propertyDescriptor); + stModelStore.removeProperty(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor); } /** @@ -622,7 +633,7 @@ protected ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor */ protected static void clearValueCollection(IModelStore stModelStore, String stDocumentUri, String stId, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - stModelStore.clearValueCollection(stDocumentUri, stId, propertyDescriptor); + stModelStore.clearValueCollection(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor); } /** @@ -660,7 +671,7 @@ protected ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDesc protected static void addValueToCollection(IModelStore stModelStore, String stDocumentUri, String stId, PropertyDescriptor propertyDescriptor, Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(value, "Value can not be null"); - stModelStore.addValueToCollection(stDocumentUri, stId, propertyDescriptor, + stModelStore.addValueToCollection(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(value, stDocumentUri, stModelStore, copyManager)); } @@ -718,7 +729,7 @@ protected static void replacePropertyValueCollection(IModelStore stModelStore, S */ protected static void removePropertyValueFromCollection(IModelStore stModelStore, String stDocumentUri, String stId, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - stModelStore.removeValueFromCollection(stDocumentUri, stId, propertyDescriptor, + stModelStore.removeValueFromCollection(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(value, stDocumentUri, stModelStore, null)); } @@ -1051,7 +1062,7 @@ public ModelObject clone(IModelStore modelStore) { throw new IllegalStateException("Can not clone to the same model store"); } Objects.requireNonNull(modelStore, "Model store for clone must not be null"); - if (modelStore.exists(this.documentUri, this.id)) { + if (modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore))) { throw new IllegalStateException("Can not clone - "+this.id+" already exists."); } try { @@ -1072,8 +1083,9 @@ public void copyFrom(ModelObject source) throws InvalidSPDXAnalysisException { if (Objects.isNull(copyManager)) { throw new InvalidSPDXAnalysisException("Copying is not enabled for "+id); } - copyManager.copy(this.modelStore, this.documentUri, this.id, - source.getModelStore(), source.getDocumentUri(), source.getId(), this.getType()); + copyManager.copy(this.modelStore, CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, this.modelStore), + source.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(source.getDocumentUri(), source.getId(), source.getModelStore()), + this.getType(), this.documentUri, source.getDocumentUri()); } public void setCopyManager(ModelCopyManager copyManager) { @@ -1088,7 +1100,7 @@ public ModelCopyManager getCopyManager() { } /** - * @param id String for the object + * @param objectUri String for the object * @return type of the ID */ protected IdType idToIdType(String id) { @@ -1108,7 +1120,7 @@ protected IdType idToIdType(String id) { } protected TypedValue toTypedValue() throws InvalidSPDXAnalysisException { - return new TypedValue(this.id, this.getType()); + return CompatibleModelStoreWrapper.typedValueFromDocUri(this.documentUri, this.id, modelStore.getIdType(id).equals(IdType.Anonymous), this.getType()); } /** @@ -1292,7 +1304,7 @@ public ExternalRef createExternalRef(ReferenceCategory category, ReferenceType r /** * Create an SpdxFileBuilder with all of the required properties - the build() method will build the file - * @param id - ID - must be an SPDX ID type + * @param objectUri - ID - must be an SPDX ID type * @param name - File name * @param concludedLicense license concluded * @param seenLicense collection of seen licenses @@ -1312,7 +1324,7 @@ public SpdxFile.SpdxFileBuilder createSpdxFile(String id, String name, AnyLicens /** * Create an SpdxPackageBuilder with all required fields for a filesAnalyzed=false using this objects model store and document URI - * @param id - ID - must be an SPDX ID type + * @param objectUri - ID - must be an SPDX ID type * @param name - File name * @param concludedLicense license concluded * @param copyrightText Copyright text @@ -1376,7 +1388,7 @@ public StartEndPointer createStartEndPointer(SinglePointer startPointer, SingleP /** * Create an SpdxSnippetBuilder with all of the required properties - the build() method will build the file - * @param id - ID - must be an SPDX ID type + * @param objectUri - ID - must be an SPDX ID type * @param name - File name * @param concludedLicense license concluded * @param seenLicense collection of seen licenses diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java index 5cc6e63a0..2598a7161 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java @@ -44,7 +44,7 @@ public class ModelSet extends ModelCollection { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param propertyDescriptor * @param copyManager * @param type diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index 01182f91e..a6f9aaf30 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -22,13 +22,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxObjectNotInStoreException; import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * This static helper class converts objects used in the model to and from objects used by the SPI / storage class. @@ -69,10 +72,10 @@ public static Object storedObjectToModelObject(Object value, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (value instanceof IndividualUriValue) { // Note: this must be before the check for TypedValue SimpleUriValue suv = new SimpleUriValue((IndividualUriValue)value); - return suv.toModelObject(modelStore, documentUri, null); + return suv.toModelObject(modelStore, null, documentUri); } else if (value instanceof TypedValue) { TypedValue tv = (TypedValue)value; - return SpdxModelFactory.createModelObject(modelStore, documentUri, tv.getId(), tv.getType(), copyManager); + return SpdxModelFactory.createModelObject(modelStore, documentUri, tv.getObjectUri(), tv.getType(), copyManager); } else { return value; } @@ -94,10 +97,10 @@ public static Object storedObjectToModelObject(Object value, String documentUri, public static Optional optionalStoredObjectToModelObject(Optional value, String stDocumentUri, IModelStore stModelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (value.isPresent() && value.get() instanceof IndividualUriValue) { - return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(stModelStore, stDocumentUri, copyManager)); + return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(stModelStore, copyManager, stDocumentUri)); } else if (value.isPresent() && value.get() instanceof TypedValue) { TypedValue tv = (TypedValue)value.get(); - return Optional.of(SpdxModelFactory.createModelObject(stModelStore, stDocumentUri, tv.getId(), tv.getType(), copyManager)); + return Optional.of(SpdxModelFactory.createModelObject(stModelStore, stDocumentUri, tv.getObjectUri(), tv.getType(), copyManager)); } else { return value; } @@ -121,8 +124,9 @@ public static Object modelObjectToStoredObject(Object value, String stDocumentUr ModelObject mValue = (ModelObject)value; if (!mValue.getModelStore().equals(stModelStore) || !mValue.getDocumentUri().equals(stDocumentUri)) { if (Objects.nonNull(copyManager)) { - return copyManager.copy(stModelStore, stDocumentUri, - mValue.getModelStore(), mValue.getDocumentUri(), mValue.getId(), mValue.getType()); + return copyManager.copy(stModelStore, mValue.getModelStore(), + CompatibleModelStoreWrapper.documentUriIdToUri(mValue.getDocumentUri(), mValue.getId(), mValue.getModelStore()), + mValue.getType(), mValue.getDocumentUri(), stDocumentUri); } else { throw new SpdxObjectNotInStoreException("Can not set a property value to a Model Object stored in a different model store"); } diff --git a/src/main/java/org/spdx/library/Read.java b/src/main/java/org/spdx/library/model/compat/v2/Read.java similarity index 88% rename from src/main/java/org/spdx/library/Read.java rename to src/main/java/org/spdx/library/model/compat/v2/Read.java index 12a3dd334..8def889ac 100644 --- a/src/main/java/org/spdx/library/Read.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Read.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library; +package org.spdx.library.model.compat.v2; import java.io.FileOutputStream; import java.io.IOException; @@ -27,12 +27,14 @@ import java.util.Objects; import java.util.stream.Stream; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.ISerializableModelStore; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * Supports reading SPDX documents from an existing ModelStore @@ -57,11 +59,9 @@ public static class Document { * @throws IOException */ public static List get(IModelStore modelStore) throws InvalidSPDXAnalysisException, IOException { - List documentUris = modelStore.getDocumentUris(); List retval = new ArrayList(); - for (String documentUri:documentUris) { - retval.add(new SpdxDocument(modelStore, documentUri, null, false)); - } + SpdxModelFactory.getElements(modelStore, null, null, SpdxDocument.class).forEach( + spdxDoc -> retval.add((SpdxDocument)spdxDoc)); return retval; } @@ -73,7 +73,7 @@ public static List get(IModelStore modelStore) throws InvalidSPDXA * @throws IOException */ public static SpdxDocument get(IModelStore modelStore, String documentUri) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, true); + IModelStoreLock lock = modelStore.enterCriticalSection(true); try { return new SpdxDocument(modelStore, documentUri, null, false); } finally { @@ -87,7 +87,8 @@ public static SpdxDocument get(IModelStore modelStore, String documentUri) throw * @return true if the document exists in the model store */ public static boolean documentExists(IModelStore modelStore, String documentUri) { - return modelStore.exists(documentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID); + return modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, + SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false)); } } @@ -103,7 +104,7 @@ public static boolean documentExists(IModelStore modelStore, String documentUri) * @throws IOException */ public static void serialize(ISerializableModelStore modelStore, String documentUri, OutputStream stream) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, true); + IModelStoreLock lock = modelStore.enterCriticalSection(true); try { modelStore.serialize(documentUri, stream); } finally { @@ -142,7 +143,7 @@ public static Stream getAllItems(IModelStore modelStore, String typeFilter) throws InvalidSPDXAnalysisException { return modelStore.getAllItems(documentUri, typeFilter).map((TypedValue tv) -> { try { - return SpdxModelFactory.createModelObject(modelStore, documentUri, tv.getId(), tv.getType(), null); + return SpdxModelFactory.createModelObject(modelStore, documentUri, tv.getObjectUri(), tv.getType(), null); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java b/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java index 13f2756a5..4c8504d45 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java @@ -17,7 +17,9 @@ */ package org.spdx.library.model.compat.v2; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SimpleUriValue; /** * Type of external reference diff --git a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java index 3310fa95c..5d089ca3e 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java @@ -36,6 +36,7 @@ import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * Collection of SPDX elements related to an SpdxElement @@ -241,13 +242,13 @@ public boolean remove(Object o) { relationship.getRelationshipType().equals(relationshipTypeFilter)) { IModelStore modelStore = relationship.getModelStore(); String documentUri = relationship.getDocumentUri(); - final IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + final IModelStoreLock lock = modelStore.enterCriticalSection(false); try { if (relationshipCollection.remove(relationship)) { try { if (createdRelationshipIds.contains(relationship.getId())) { createdRelationshipIds.remove(relationship.getId()); - modelStore.delete(documentUri, relationship.getId()); + modelStore.delete(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, relationship.getId(), modelStore)); } } catch (SpdxIdInUseException ex) { // This is possible if the relationship is in use diff --git a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java index bd46d6c95..9e40dfaf4 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java @@ -46,7 +46,7 @@ public Relationship() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public Relationship(String id) throws InvalidSPDXAnalysisException { @@ -56,7 +56,7 @@ public Relationship(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java index 13a870dca..aac1bbb73 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java @@ -23,7 +23,9 @@ import java.util.List; import java.util.Set; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; @@ -45,7 +47,7 @@ public SpdxConstantElement(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore where the model is stored * @param documentUri Unique document URI - * @param id ID for the constant element + * @param objectUri ID for the constant element * @throws InvalidSPDXAnalysisException */ public SpdxConstantElement(IModelStore modelStore, String documentUri, String id) diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java index 39528e3db..ca7a44f61 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java @@ -46,7 +46,7 @@ public SpdxCreatorInformation() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxCreatorInformation(String id) throws InvalidSPDXAnalysisException { @@ -56,7 +56,7 @@ public SpdxCreatorInformation(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param create * @throws InvalidSPDXAnalysisException */ diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java index 50276b51f..8b628119a 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java @@ -58,7 +58,7 @@ public SpdxElement() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxElement(String id) throws InvalidSPDXAnalysisException { @@ -69,7 +69,7 @@ public SpdxElement(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param create * @throws InvalidSPDXAnalysisException */ diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java index 6f9d727d1..fdda006aa 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java @@ -59,7 +59,7 @@ public SpdxFile() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxFile(String id) throws InvalidSPDXAnalysisException { @@ -70,7 +70,7 @@ public SpdxFile(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param create * @throws InvalidSPDXAnalysisException */ @@ -356,7 +356,7 @@ public static class SpdxFileBuilder { * Build a file with the required parameters * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param name - File name * @param concludedLicense license concluded @@ -533,7 +533,7 @@ public SpdxFileBuilder addAttributionText(String attribution) { } public SpdxFile build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { return new SpdxFile(this); } finally { diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java index 43445fd47..bfc3a18e4 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java @@ -47,7 +47,7 @@ public SpdxItem() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxItem(String id) throws InvalidSPDXAnalysisException { @@ -57,7 +57,7 @@ public SpdxItem(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java index 64398e83b..1e73523fa 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java @@ -65,7 +65,7 @@ public SpdxPackage() throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException @@ -78,7 +78,7 @@ public SpdxPackage(IModelStore modelStore, String documentUri, String id, } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxPackage(String id) throws InvalidSPDXAnalysisException { @@ -873,7 +873,7 @@ public static class SpdxPackageBuilder { * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this * model - * @param id ID for this object - must be unique within the SPDX + * @param objectUri ID for this object - must be unique within the SPDX * document * @param name File name * @param copyManager @@ -1208,7 +1208,7 @@ public SpdxPackageBuilder setReleaseDate(String releaseDate) { * @throws InvalidSPDXAnalysisException */ public SpdxPackage build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { return new SpdxPackage(this); } finally { diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java index 704981789..b7afc3f0f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java @@ -47,7 +47,7 @@ public SpdxPackageVerificationCode() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxPackageVerificationCode(String id) throws InvalidSPDXAnalysisException { @@ -57,7 +57,7 @@ public SpdxPackageVerificationCode(String id) throws InvalidSPDXAnalysisExceptio /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java index 570daadf7..943e475f0 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java @@ -61,7 +61,7 @@ public SpdxSnippet() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public SpdxSnippet(String id) throws InvalidSPDXAnalysisException { @@ -72,7 +72,7 @@ public SpdxSnippet(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException @@ -484,7 +484,7 @@ public static class SpdxSnippetBuilder { * Build a snippet with the required parameters * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param name - File name * @param concludedLicense license concluded @@ -608,7 +608,7 @@ public SpdxSnippetBuilder setLineRange(int startLine, int endLine) { } public SpdxSnippet build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { return new SpdxSnippet(this); } finally { diff --git a/src/main/java/org/spdx/library/Write.java b/src/main/java/org/spdx/library/model/compat/v2/Write.java similarity index 94% rename from src/main/java/org/spdx/library/Write.java rename to src/main/java/org/spdx/library/model/compat/v2/Write.java index eb172602b..864fbfc81 100644 --- a/src/main/java/org/spdx/library/Write.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Write.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library; +package org.spdx.library.model.compat.v2; import java.io.IOException; import java.io.InputStream; @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Objects; +import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.storage.IModelStore; import org.spdx.storage.ISerializableModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; @@ -59,7 +60,7 @@ public static void applyUpdatesInOneTransaction(String documentUri, IModelStore * @throws IOException */ public static void applyUpdatesInOneTransaction(String documentUri, IModelStore modelStore, Iterable updates) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { for (ModelUpdate update : updates) { update.apply(); @@ -78,7 +79,7 @@ public static void applyUpdatesInOneTransaction(String documentUri, IModelStore * @throws IOException */ public static void deSerialize(ISerializableModelStore modelStore, String documentUri, InputStream stream) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { modelStore.deSerialize(stream, false); } finally { diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java index 24c9f5fd2..8786b163f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java @@ -17,8 +17,8 @@ */ package org.spdx.library.model.compat.v2.enumerations; +import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Annotation types for the Annotation Class diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java index 5cbba9514..1d2482e0e 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java @@ -17,8 +17,8 @@ */ package org.spdx.library.model.compat.v2.enumerations; +import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Enum constants for Checksum Algorithms diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java index c9239c7bb..e95f0406f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java @@ -17,8 +17,8 @@ */ package org.spdx.library.model.compat.v2.enumerations; +import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.IndividualUriValue; /** * File Type is intrinsic to the file, independent of how the file is being used. diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java index 1667dce9e..c193c1604 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java @@ -17,8 +17,8 @@ */ package org.spdx.library.model.compat.v2.enumerations; +import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Package Purpose is intrinsic to how the package is being used rather than the content of the package. diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java index 8d074e42d..f787f53ba 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java @@ -17,8 +17,8 @@ */ package org.spdx.library.model.compat.v2.enumerations; +import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Reference category for external refs diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java index aefa76343..762f32fd8 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java @@ -17,8 +17,8 @@ */ package org.spdx.library.model.compat.v2.enumerations; +import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.IndividualUriValue; /** * Relationship types diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java index 1a196a070..4fe8f034d 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java @@ -35,7 +35,7 @@ public abstract class AbstractExtractedLicenseInfo extends SimpleLicensingInfo /** * Create a new ExtractedLicenseInfo using the ID - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public AbstractExtractedLicenseInfo(String id) @@ -47,7 +47,7 @@ public AbstractExtractedLicenseInfo(String id) * Create a new ExtractedLicenseInfo object * @param modelStore container which includes the license * @param documentUri URI for the SPDX document containing the license - * @param id identifier for the license + * @param objectUri identifier for the license * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param create if true, create the license if it does not exist * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java index 575ab7e04..5e62677f4 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java @@ -48,7 +48,7 @@ public AnyLicenseInfo() throws InvalidSPDXAnalysisException { /** * Open or create a model object with the default store and default document URI - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @throws InvalidSPDXAnalysisException */ public AnyLicenseInfo(String id) throws InvalidSPDXAnalysisException { @@ -59,7 +59,7 @@ public AnyLicenseInfo(String id) throws InvalidSPDXAnalysisException { * Create a new LicenseInfo object * @param modelStore container which includes the license * @param documentUri URI for the SPDX document containing the license - * @param id identifier for the license + * @param objectUri identifier for the license * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param create if true, create the license if it does not exist * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java index 16d8b6ad2..23d6334c5 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java @@ -48,7 +48,7 @@ public ConjunctiveLicenseSet(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java b/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java index 99615cd81..a143159b3 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java @@ -48,7 +48,7 @@ public CrossRef() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public CrossRef(String id) throws InvalidSPDXAnalysisException { @@ -58,7 +58,7 @@ public CrossRef(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException @@ -348,7 +348,7 @@ public static class CrossRefBuilder { * Create a CrossRef with the required parameters * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param url URL for the CrossRef */ @@ -424,7 +424,7 @@ public CrossRefBuilder setOrder(@Nullable Integer order) { * @throws InvalidSPDXAnalysisException */ public CrossRef build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(documentUri, false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { return new CrossRef(this); } finally { diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java index 8c5dc8f34..2abb833e8 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java @@ -48,7 +48,7 @@ public DisjunctiveLicenseSet(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java index 49529150e..4862a95fb 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java @@ -28,14 +28,14 @@ import javax.annotation.Nullable; import org.spdx.library.DefaultModelStore; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.model.compat.v2.ExternalDocumentRef; import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.IndividualUriValue; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SimpleUriValue; import org.spdx.storage.IModelStore; /** @@ -66,7 +66,7 @@ public ExternalExtractedLicenseInfo(String id) throws InvalidSPDXAnalysisExcepti /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException @@ -76,7 +76,7 @@ public ExternalExtractedLicenseInfo(IModelStore modelStore, String documentUri, throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); if (!SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id).matches()) { - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } getExternalExtractedLicenseURI(); //this will check to make sure the external document reference is available } @@ -88,7 +88,7 @@ public ExternalExtractedLicenseInfo(IModelStore modelStore, String documentUri, public String getExternalDocumentId() throws InvalidSPDXAnalysisException { Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } return matcher.group(1); } @@ -100,7 +100,7 @@ public String getExternalDocumentId() throws InvalidSPDXAnalysisException { public String getExternalLicenseRef() throws InvalidSPDXAnalysisException { Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } return matcher.group(2); } @@ -123,7 +123,7 @@ protected List _verify(Set verifiedIds, String specVersion) { String id = this.getId(); Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id); if (!matcher.matches()) { - retval.add("Invalid id format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); + retval.add("Invalid objectUri format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); } else { try { ExternalSpdxElement.externalDocumentIdToNamespace(matcher.group(1), getModelStore(), getDocumentUri(), getCopyManager()); @@ -154,8 +154,8 @@ public static String externalExtractedLicenseIdToURI(String externalExtractedLic IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(externalExtractedLicenseId); if (!matcher.matches()) { - logger.error("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); - throw new InvalidSPDXAnalysisException("Invalid id format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); + logger.error("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); + throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); } String externalDocumentUri; externalDocumentUri = ExternalSpdxElement.externalDocumentIdToNamespace(matcher.group(1), stModelStore, stDocumentUri, copyManager); diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java index 325fd0213..67b20c84d 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java @@ -57,7 +57,7 @@ public ExtractedLicenseInfo(String id) throws InvalidSPDXAnalysisException { * Create a new ExtractedLicenseInfo object * @param modelStore container which includes the license * @param documentUri URI for the SPDX document containing the license - * @param id identifier for the license + * @param objectUri identifier for the license * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param create if true, create the license if it does not exist * @throws InvalidSPDXAnalysisException @@ -70,7 +70,7 @@ public ExtractedLicenseInfo(IModelStore modelStore, String documentUri, String i /** * Create a new ExtractedLicenseInfo using the ID and text - * @param id + * @param objectUri * @param text * @throws InvalidSPDXAnalysisException */ diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/License.java b/src/main/java/org/spdx/library/model/compat/v2/license/License.java index e071e70b6..4f7641ada 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/License.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/License.java @@ -56,7 +56,7 @@ public abstract class License extends SimpleLicensingInfo { /** * Open or create a model object with the default store and default document URI - * @param id ID for this object - must be unique within the SPDX document + * @param objectUri ID for this object - must be unique within the SPDX document * @throws InvalidSPDXAnalysisException */ public License(String id) throws InvalidSPDXAnalysisException { @@ -67,7 +67,7 @@ public License(String id) throws InvalidSPDXAnalysisException { * Create a new License object * @param modelStore container which includes the license * @param documentUri URI for the SPDX document containing the license - * @param id identifier for the license + * @param objectUri identifier for the license * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param create if true, create the license if it does not exist * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java index 8fd68a2c6..0d81d7834 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java @@ -25,11 +25,11 @@ import javax.annotation.Nullable; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.IndividualUriValue; import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.storage.IModelStore; @@ -47,7 +47,7 @@ public class LicenseException extends ModelObject { * Create a new LicenseException object * @param modelStore container which includes the license exception * @param documentUri URI for the SPDX document containing the license exception - * @param id identifier for the license exception + * @param objectUri identifier for the license exception * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @param create if true, create the license exception if it does not exist * @throws InvalidSPDXAnalysisException @@ -130,7 +130,7 @@ public void setExample(String example) throws InvalidSPDXAnalysisException { } /** - * @return the id + * @return the objectUri */ public String getLicenseExceptionId() { return getId(); diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java index 15357d9a2..0ee4961eb 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java @@ -35,6 +35,7 @@ import org.spdx.library.model.compat.v2.ModelStorageClassConverter; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * A parser for the SPDX License Expressions as documented in the SPDX appendix. @@ -252,17 +253,18 @@ private static int findMatchingParen(String[] tokens, int startToken) { * Converts a string token into its equivalent license * checking for a listed license * @param token - * @param store + * @param baseStore * @param documentUri * @param copyManager * @return * @throws InvalidSPDXAnalysisException */ - private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String documentUri, + private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore baseStore, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(token, "Token can not be null"); - Objects.requireNonNull(store, "Model store can not be null"); + Objects.requireNonNull(baseStore, "Model store can not be null"); Objects.requireNonNull(documentUri, "Document URI can not be null"); + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(baseStore); if (token.contains(":")) { // External License Ref return new ExternalExtractedLicenseInfo(store, documentUri, token, copyManager, true); @@ -277,8 +279,9 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore SpdxListedLicense listedLicense = LicenseInfoFactory.getListedLicenseById(licenseId.get()); if (Objects.nonNull(copyManager)) { // copy to the local store - copyManager.copy(store, documentUri, token, listedLicense.getModelStore(), - listedLicense.getDocumentUri(), token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + copyManager.copy(store, CompatibleModelStoreWrapper.documentUriIdToUri(listedLicense.getDocumentUri(), token, false), listedLicense.getModelStore(), + CompatibleModelStoreWrapper.documentUriIdToUri(listedLicense.getDocumentUri(), token, false), + SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, listedLicense.getDocumentUri(), listedLicense.getDocumentUri()); } } return (AnyLicenseInfo) ModelStorageClassConverter.storedObjectToModelObject( diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java index 16001d68b..385dc8299 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java @@ -136,7 +136,7 @@ public static String getLicenseListVersion() { } /** - * @param id exception ID + * @param objectUri exception ID * @return true if the exception ID is a supported SPDX listed exception */ public static boolean isSpdxListedExceptionId(String id) { @@ -144,7 +144,7 @@ public static boolean isSpdxListedExceptionId(String id) { } /** - * @param id + * @param objectUri * @return the standard SPDX license exception or null if the ID is not in the SPDX license list * @throws InvalidSPDXAnalysisException */ diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java index 52be6ff38..dc946c0a7 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java @@ -54,7 +54,7 @@ public LicenseSet() throws InvalidSPDXAnalysisException { } /** - * @param id + * @param objectUri * @throws InvalidSPDXAnalysisException */ public LicenseSet(String id) throws InvalidSPDXAnalysisException { @@ -65,7 +65,7 @@ public LicenseSet(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param create * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java index 4b5d085cd..645e8d8b2 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java @@ -39,7 +39,7 @@ public class ListedLicenseException extends LicenseException { /** * @param modelStore * @param documentUri - * @param id + * @param objectUri * @param copyManager * @param create * @throws InvalidSPDXAnalysisException @@ -50,7 +50,7 @@ public ListedLicenseException(IModelStore modelStore, String documentUri, String } /** - * @param id + * @param objectUri * @param name * @param text * @param seeAlso @@ -63,7 +63,7 @@ public ListedLicenseException(String id, String name, String text, Collection getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException; + public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException; /** * Sets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @param value value to set * @throws InvalidSPDXAnalysisException */ - public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; + public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property - * @return the single value associated with the id, propertyDescriptor and document + * @return the single value associated with the objectUri, propertyDescriptor and document * @throws InvalidSPDXAnalysisException */ - public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; + public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * Generate a unique ID for use within the document * @param idType Type of ID - * @param documentUri the SPDX Document URI + * @param nameSpace the SPDX namespace to use for the ID * @return next available unique ID for the specific idType * @throws InvalidSPDXAnalysisException */ - public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException; + public String getNextId(IdType idType, @Nullable String nameSpace) throws InvalidSPDXAnalysisException; /** * Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyDescriptor does not exist - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @throws InvalidSPDXAnalysisException */ - public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; + public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** - * @return a list of all Document URI's stored in the model store - */ - public List getDocumentUris(); - - /** - * @param documentUri SPDX Document URI for a document associated with this model + * @param nameSpace Optional SPDX namespace to filter items by * @param typeFilter Optional parameter to specify the type of objects to be retrieved * @return Stream of all items store within the document * @throws InvalidSPDXAnalysisException */ - public Stream getAllItems(String documentUri, @Nullable String typeFilter) throws InvalidSPDXAnalysisException; + public Stream getAllItems(@Nullable String nameSpace, @Nullable String typeFilter) throws InvalidSPDXAnalysisException; /** * Enter a critical section. leaveCriticialSection must be called. * @param readLockRequested true implies a read lock, false implies write lock. * @throws InvalidSPDXAnalysisException */ - public IModelStoreLock enterCriticalSection(String documentUri, boolean readLockRequested) throws InvalidSPDXAnalysisException; + public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException; /** * Leave a critical section. Releases the lock form the matching enterCriticalSection @@ -153,114 +143,108 @@ public enum IdType { /** * Removes a value from a collection of values associated with a property - * @param documentUri Unique document URI - * @param id ID of the item to associate the property with + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @param value Value to be removed * @return */ - public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; + public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** - * @param documentUri Unique document URI - * @param id ID of the item to associate the property with + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @return size of a collection associated with a property. 0 if the property does not exist. */ - public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; + public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** - * @param documentUri Unique document URI - * @param id ID of the item to associate the property with + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @param value * @return true if the collection associated with a property contains the value */ - public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; + public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** * Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not exist - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @throws InvalidSPDXAnalysisException */ - void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; + void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** * Adds a value to a property collection creating the propertyDescriptor if it does not exist - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @param value value to add * @return true if the collection was modified * @throws InvalidSPDXAnalysisException */ - public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; + public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; /** - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property - * @return Iterator over the list of values associated with the id, propertyDescriptor and document + * @return Iterator over the list of values associated with the objectUri, propertyDescriptor and document * @throws InvalidSPDXAnalysisException */ - public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; + public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @param clazz Class to test compatibility with - * @return true if all members of a collection associated with the id and propertyDescriptor can be assigned to the clazz + * @return true if all members of a collection associated with the objectUri and propertyDescriptor can be assigned to the clazz * @throws InvalidSPDXAnalysisException */ - public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; + public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; /** - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @param clazz Class to test compatibility with - * @return true if the value associated with the id and propertyDescriptor can be assigned to the clazz + * @return true if the value associated with the objectUri and propertyDescriptor can be assigned to the clazz * @throws InvalidSPDXAnalysisException */ - public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; /** - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @param propertyDescriptor descriptor for the property * @return true if the propertyDescriptor represents multiple values */ - public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; + public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** - * @param id + * @param objectUri * @return The type of ID based on the string format */ - public IdType getIdType(String id); + public IdType getIdType(String objectUri); /** * In SPDX 2.2 license refs are allowed to be matched case insensitive. This function will return * the case sensitivie ID (e.g. if you have LicenseRef-ABC, calling this function with licenseref-abc will return LicenseRef-ABC - * @param documentUri the SPDX Document URI + * @param nameSpace the nameSpace used for the ID - the URI is formed by the nameSpace + "#" + caseInsensisitiveId * @param caseInsensisitiveId * @return the case sensitive ID if it exists */ - public Optional getCaseSensisitiveId(String documentUri, String caseInsensisitiveId); + public Optional getCaseSensisitiveId(String nameSpace, String caseInsensisitiveId); /** - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @return type TypedValue containing the type of the ModelObject related to the ID */ - public Optional getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException; + public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException; /** * Deletes an item from the document - * @param documentUri the SPDX Document URI - * @param id unique ID within the SPDX document + * @param objectUri unique URI within the SPDX model store for the objects * @throws InvalidSPDXAnalysisException */ - public void delete(String documentUri, String id) throws InvalidSPDXAnalysisException; + public void delete(String objectUri) throws InvalidSPDXAnalysisException; + + /** + * @return the major SPDX version for the model store (e.g. "2" or "3") + */ + public SpdxMajorVersion getSpdxVersion(); } diff --git a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java new file mode 100644 index 000000000..77e3e138e --- /dev/null +++ b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java @@ -0,0 +1,359 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.compat.v2; + +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.SpdxInvalidIdException; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.TypedValue; +import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; + +/** + * @author gary + * + */ +public class CompatibleModelStoreWrapper implements IModelStore { + + private IModelStore baseStore; + + public CompatibleModelStoreWrapper(IModelStore baseStore) { + Objects.requireNonNull(baseStore, "A base store must be provided for the CompatibileModelStoreWrapper"); + this.baseStore = baseStore; + } + + @Override + public void close() throws Exception { + baseStore.close(); + } + + /** + * @param documentUri a nameSpace for the ID + * @param objectUri unique ID within the SPDX document + * @return true if the objectUri already exists for the documentUri + */ + public boolean exists(String documentUri, String id) { + return exists(documentUriIdToUri(documentUri, id, baseStore)); + } + + /** + * @param documentUri SPDX v2 Document URI + * @param id ID consistent with SPDX v2 spec + * @param store store used for the Document URI + * @return true if the objectUri already exists for the documentUri + */ + public static String documentUriIdToUri(String documentUri, String id, IModelStore store) { + return documentUriIdToUri(documentUri, id, store.getIdType(id).equals(IdType.Anonymous)); + } + + /** + * @param documentUri SPDX v2 Document URI + * @param id ID consistent with SPDX v2 spec + * @param anonymous true of this is an anonymous ID + * @return a URI based on the document URI and ID - if anonymous is true, the ID is returned + */ + public static String documentUriIdToUri(String documentUri, String id, boolean anonymous) { + if (anonymous) { + return id; + } else if (documentUri.contains("://spdx.org/licenses/")) { + return documentUri + id; + } else { + return documentUri + "#" + id; + } + } + + /** + * Convenience method to convert an SPDX 2.X style typed value to the current TypedValue + * @param documentUri SPDX v2 Document URI + * @param id ID consistent with SPDX v2 spec + * @param anonymous true of this is an anonymous ID + * @param type SPDX type + * @return TypedValue with the proper Object URI formed by the documentUri and ID + * @throws SpdxInvalidIdException + * @throws SpdxInvalidTypeException + */ + public static TypedValue typedValueFromDocUri(String documentUri, String id, boolean anonymous, String type) throws SpdxInvalidIdException, SpdxInvalidTypeException { + return new TypedValue(documentUriIdToUri(documentUri, id, anonymous), type); + } + + @Override + public boolean exists(String uri) { + return baseStore.exists(uri); + } + + /** + * @param documentUri SPDX v2 spec document URI + * @param objectUri SPDX ID + * @param type type + * @throws InvalidSPDXAnalysisException + */ + public void create(String documentUri, String id, String type) + throws InvalidSPDXAnalysisException { + baseStore.create(documentUriIdToUri(documentUri, id, baseStore), type); + } + + @Override + public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { + baseStore.create(objectUri, type); + } + + @Override + public List getPropertyValueDescriptors( + String objectUri) throws InvalidSPDXAnalysisException { + return baseStore.getPropertyValueDescriptors(objectUri); + } + + public List getPropertyValueDescriptors( + String documentUri, String id) throws InvalidSPDXAnalysisException { + return getPropertyValueDescriptors(documentUriIdToUri(documentUri, id, baseStore)); + } + + @Override + public void setValue(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + baseStore.setValue(objectUri, propertyDescriptor, value); + } + + public void setValue(String documentUri, String id, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + setValue(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); + } + + @Override + public Optional getValue(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return baseStore.getValue(objectUri, propertyDescriptor); + } + + public Optional getValue(String documentUri, String id, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return getValue(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); + } + + @Override + public String getNextId(IdType idType, String documentUri) + throws InvalidSPDXAnalysisException { + Objects.requireNonNull(documentUri, "SPDX V2 requires a namespace for generating next ID's"); + if (documentUri.contains("://spdx.org/licenses")) { + return baseStore.getNextId(idType, documentUri); + } else { + return baseStore.getNextId(idType, documentUri + "#"); + } + } + + @Override + public void removeProperty(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + baseStore.removeProperty(objectUri, propertyDescriptor); + } + + public void removeProperty(String documentUri, String id, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + removeProperty(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); + } + + @Override + public Stream getAllItems(String nameSpace, String typeFilter) + throws InvalidSPDXAnalysisException { + return baseStore.getAllItems(nameSpace, typeFilter); + } + + @Override + public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { + return baseStore.enterCriticalSection(readLockRequested); + } + + public IModelStoreLock enterCriticalSection(String documentUri, + boolean readLockRequested) throws InvalidSPDXAnalysisException { + return enterCriticalSection(readLockRequested); + } + + @Override + public void leaveCriticalSection(IModelStoreLock lock) { + baseStore.leaveCriticalSection(lock); + } + + @Override + public boolean removeValueFromCollection(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + return baseStore.removeValueFromCollection(objectUri, propertyDescriptor, value); + } + + public boolean removeValueFromCollection(String documentUri, String id, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + return removeValueFromCollection(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); + } + + @Override + public int collectionSize(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return baseStore.collectionSize(objectUri, propertyDescriptor); + } + + public int collectionSize(String documentUri, String id, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return collectionSize(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); + } + + @Override + public boolean collectionContains(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + return baseStore.collectionContains(objectUri, propertyDescriptor, value); + } + + public boolean collectionContains(String documentUri, String id, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + return collectionContains(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); + } + + @Override + public void clearValueCollection(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + baseStore.clearValueCollection(objectUri, propertyDescriptor); + } + + public void clearValueCollection(String documentUri, String id, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + clearValueCollection(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); + } + + @Override + public boolean addValueToCollection(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + return baseStore.addValueToCollection(objectUri, propertyDescriptor, value); + } + + public boolean addValueToCollection(String documentUri, String id, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + return addValueToCollection(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); + } + + @Override + public Iterator listValues(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return baseStore.listValues(objectUri, propertyDescriptor); + } + + public Iterator listValues(String documentUri, String id, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return listValues(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); + } + + @Override + public boolean isCollectionMembersAssignableTo(String objectUri, + PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + return baseStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, clazz); + } + + public boolean isCollectionMembersAssignableTo(String documentUri, + String id, PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + return isCollectionMembersAssignableTo(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, clazz); + } + + @Override + public boolean isPropertyValueAssignableTo(String objectUri, + PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz); + } + + public boolean isPropertyValueAssignableTo(String documentUri, String id, + PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + return isPropertyValueAssignableTo(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, clazz); + } + + @Override + public boolean isCollectionProperty(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return baseStore.isCollectionProperty(objectUri, propertyDescriptor); + } + + public boolean isCollectionProperty(String documentUri, String id, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + return isCollectionProperty(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); + } + + @Override + public IdType getIdType(String objectUri) { + return baseStore.getIdType(objectUri); + } + + @Override + public Optional getCaseSensisitiveId(String documentUri, + String caseInsensisitiveId) { + return baseStore.getCaseSensisitiveId(documentUri, caseInsensisitiveId); + } + + @Override + public Optional getTypedValue(String objectUri) + throws InvalidSPDXAnalysisException { + return baseStore.getTypedValue(objectUri); + } + + public Optional getTypedValue(String documentUri, String id) + throws InvalidSPDXAnalysisException { + return getTypedValue(documentUriIdToUri(documentUri, id, baseStore)); + } + + @Override + public void delete(String documentUri) + throws InvalidSPDXAnalysisException { + baseStore.delete(documentUri); + } + + public void delete(String documentUri, String id) + throws InvalidSPDXAnalysisException { + delete(documentUriIdToUri(documentUri, id, baseStore)); + } + + @Override + public SpdxMajorVersion getSpdxVersion() { + return SpdxMajorVersion.VERSION_2; + } + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java index 625605df9..c98ecf1d4 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java @@ -21,6 +21,7 @@ import java.io.InputStream; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstantsCompatV2; /** * @author Gary O'Neall diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index 9a032b1a6..e79a03d74 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -23,7 +23,6 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -40,6 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.TypedValue; @@ -69,7 +69,6 @@ public abstract class SpdxListedLicenseModelStore implements IListedLicenseStore static final String LICENSE_TOC_FILENAME = "licenses.json"; static final String EXCEPTION_TOC_FILENAME = "exceptions.json"; static final String JSON_SUFFIX = ".json"; - private static final List DOCUMENT_URIS = Collections.unmodifiableList(Arrays.asList(new String[]{SpdxConstantsCompatV2.LISTED_LICENSE_URL})); private static final String ANONYMOUS_ID_PREFIX = "SpdxLicenseGeneratedId-"; /** @@ -192,8 +191,14 @@ private void loadIds() throws InvalidSPDXAnalysisException { * @see org.spdx.storage.IModelStore#exists(java.lang.String, java.lang.String) */ @Override - public boolean exists(String documentUri, String id) { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { + public boolean exists(String objectUri) { + Objects.requireNonNull(objectUri, "Object URI can not be null"); + String id; + if (objectUri.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { + id = objectUri.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()); + } else if (getIdType(objectUri) == IdType.Anonymous) { + id = objectUri; + } else { return false; } listedLicenseModificationLock.readLock().lock(); @@ -205,18 +210,29 @@ public boolean exists(String documentUri, String id) { listedLicenseModificationLock.readLock().unlock(); } } + + private String objectUriToId(String objectUri) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(objectUri, "Object URI can not be null"); + String id; + if (objectUri.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { + id = objectUri.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()); + } else if (getIdType(objectUri) == IdType.Anonymous) { + id = objectUri; + } else { + logger.error("Namespace for SPDX listed licenses is expected to be "+ + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied URI was "+objectUri); + throw new SpdxIdNotFoundException("Namespace for SPDX listed licenses is expected to be "+ + SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied URI was "+objectUri); + } + return id; + } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#create(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void create(String documentUri, String id, String type) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); listedLicenseModificationLock.writeLock().lock(); try { if (SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(type)) { @@ -247,13 +263,8 @@ public void create(String documentUri, String id, String type) throws InvalidSPD * @see org.spdx.storage.IModelStore#getPropertyValueNames(java.lang.String, java.lang.String) */ @Override - public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -435,13 +446,8 @@ private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws Invali * @see org.spdx.storage.IModelStore#setPrimitiveValue(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -475,13 +481,8 @@ public void setValue(String documentUri, String id, PropertyDescriptor propertyD * @see org.spdx.storage.IModelStore#clearPropertyValueList(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -515,13 +516,8 @@ public void clearValueCollection(String documentUri, String id, PropertyDescript * @see org.spdx.storage.IModelStore#addPrimitiveValueToList(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -549,10 +545,10 @@ public boolean addValueToCollection(String documentUri, String id, PropertyDescr logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); } - CrossRefJson crj = crossRefs.get(tv.getId()); + CrossRefJson crj = crossRefs.get(tv.getObjectUri()); if (Objects.isNull(crj)) { - logger.error("CrossRef with ID "+tv.getId()+" does not exist in the store."); - throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getId()+" does not exist in the store."); + logger.error("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); + throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); } return license.addCrossRefValueToList(propertyDescriptor.getName(), crj); } else { @@ -570,14 +566,9 @@ public boolean addValueToCollection(String documentUri, String id, PropertyDescr } @Override - public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -605,10 +596,10 @@ public boolean removeValueFromCollection(String documentUri, String id, Property logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); } - CrossRefJson crj = crossRefs.get(tv.getId()); + CrossRefJson crj = crossRefs.get(tv.getObjectUri()); if (Objects.isNull(crj)) { - logger.error("CrossRef with ID "+tv.getId()+" does not exist in the store."); - throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getId()+" does not exist in the store."); + logger.error("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); + throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); } return license.removePrimitiveValueToList(propertyDescriptor.getName(), crj); } else { @@ -630,13 +621,8 @@ public boolean removeValueFromCollection(String documentUri, String id, Property */ @SuppressWarnings("unchecked") @Override - public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -717,13 +703,8 @@ public Object next() { * @see org.spdx.storage.IModelStore#getValue(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -838,7 +819,8 @@ public boolean isSpdxListedExceptionId(String listedLicenseDocumentUri, String e } @Override - public Optional getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException { + public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); listedLicenseModificationLock.readLock().lock(); try { if (licenseIds.containsKey(id.toLowerCase())) { @@ -856,13 +838,8 @@ public Optional getTypedValue(String documentUri, String id) throws } @Override - public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -891,12 +868,7 @@ public void removeProperty(String documentUri, String id, PropertyDescriptor pro throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); } } - - @Override - public List getDocumentUris() { - return DOCUMENT_URIS; - } - + @Override public Stream getAllItems(String documentUri, @Nullable String typeFilter) throws InvalidSPDXAnalysisException { @@ -929,13 +901,8 @@ public Stream getAllItems(String documentUri, @Nullable String typeF @SuppressWarnings("unchecked") @Override - public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -967,14 +934,9 @@ public int collectionSize(String documentUri, String id, PropertyDescriptor prop @SuppressWarnings("unchecked") @Override - public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -994,7 +956,7 @@ public boolean collectionContains(String documentUri, String id, PropertyDescrip LicenseJson license = fetchLicenseJson(id); List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); if (value instanceof TypedValue && SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(((TypedValue)value).getType())) { - CrossRefJson compareValue = crossRefs.get(((TypedValue)value).getId()); + CrossRefJson compareValue = crossRefs.get(((TypedValue)value).getObjectUri()); if (Objects.isNull(compareValue)) { return false; } else { @@ -1015,14 +977,9 @@ public boolean collectionContains(String documentUri, String id, PropertyDescrip } @Override - public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) + public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -1053,14 +1010,9 @@ public boolean isCollectionMembersAssignableTo(String documentUri, String id, Pr } @Override - public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -1091,14 +1043,9 @@ public boolean isPropertyValueAssignableTo(String documentUri, String id, Proper } @Override - public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + String id = objectUriToId(objectUri); boolean isLicenseId = false; boolean isExceptionId = false; CrossRefJson crossRef = null; @@ -1142,7 +1089,7 @@ public IdType getIdType(String id) { @Override - public IModelStoreLock enterCriticalSection(String documentUri, boolean readLockRequested) { + public IModelStoreLock enterCriticalSection(boolean readLockRequested) { if (readLockRequested) { this.listedLicenseModificationLock.readLock().lock(); return readLock; @@ -1188,13 +1135,8 @@ public Optional getCaseSensisitiveId(String documentUri, String caseInse } @Override - public void delete(String documentUri, String id) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } + public void delete(String objectUri) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); listedLicenseModificationLock.writeLock().lock(); try { if (licenseIds.containsKey(id.toLowerCase())) { @@ -1213,4 +1155,9 @@ public void delete(String documentUri, String id) throws InvalidSPDXAnalysisExce listedLicenseModificationLock.writeLock().unlock(); } } + + @Override + public SpdxMajorVersion getSpdxVersion() { + return SpdxMajorVersion.VERSION_2; + } } diff --git a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java index b41294f47..1bc72d9e2 100644 --- a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java @@ -53,42 +53,42 @@ public ExtendedSpdxStore(IModelStore baseStore) { * @see org.spdx.storage.IModelStore#exists(java.lang.String, java.lang.String) */ @Override - public boolean exists(String documentUri, String id) { - return baseStore.exists(documentUri, id); + public boolean exists(String objectUri) { + return baseStore.exists(objectUri); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#create(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void create(String documentUri, String id, String type) throws InvalidSPDXAnalysisException { - baseStore.create(documentUri, id, type); + public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { + baseStore.create(objectUri, type); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#getPropertyValueNames(java.lang.String, java.lang.String) */ @Override - public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { - return baseStore.getPropertyValueDescriptors(documentUri, id); + public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException { + return baseStore.getPropertyValueDescriptors(objectUri); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#setValue(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - baseStore.setValue(documentUri, id, propertyDescriptor, value); + baseStore.setValue(objectUri, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#getValue(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.getValue(documentUri, id, propertyDescriptor); + return baseStore.getValue(objectUri, propertyDescriptor); } /* (non-Javadoc) @@ -103,16 +103,8 @@ public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAna * @see org.spdx.storage.IModelStore#removeProperty(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - baseStore.removeProperty(documentUri, id, propertyDescriptor); - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#getDocumentUris() - */ - @Override - public List getDocumentUris() { - return baseStore.getDocumentUris(); + public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + baseStore.removeProperty(objectUri, propertyDescriptor); } /* (non-Javadoc) @@ -127,9 +119,9 @@ public Stream getAllItems(String documentUri, String typeFilter) thr * @see org.spdx.storage.IModelStore#enterCriticalSection(java.lang.String, boolean) */ @Override - public IModelStoreLock enterCriticalSection(String documentUri, boolean readLockRequested) + public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { - return baseStore.enterCriticalSection(documentUri, readLockRequested); + return baseStore.enterCriticalSection(readLockRequested); } /* (non-Javadoc) @@ -144,80 +136,80 @@ public void leaveCriticalSection(IModelStoreLock lock) { * @see org.spdx.storage.IModelStore#removeValueFromCollection(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return baseStore.removeValueFromCollection(documentUri, id, propertyDescriptor, value); + return baseStore.removeValueFromCollection(objectUri, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#collectionSize(java.lang.String, java.lang.String, java.lang.String) */ @Override - public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.collectionSize(documentUri, id, propertyDescriptor); + public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + return baseStore.collectionSize(objectUri, propertyDescriptor); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#collectionContains(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return baseStore.collectionContains(documentUri, id, propertyDescriptor, value); + return baseStore.collectionContains(objectUri, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#clearValueCollection(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - baseStore.clearValueCollection(documentUri, id, propertyDescriptor); + baseStore.clearValueCollection(objectUri, propertyDescriptor); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#addValueToCollection(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) */ @Override - public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return baseStore.addValueToCollection(documentUri, id, propertyDescriptor, value); + return baseStore.addValueToCollection(objectUri, propertyDescriptor, value); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#listValues(java.lang.String, java.lang.String, java.lang.String) */ @Override - public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.listValues(documentUri, id, propertyDescriptor); + return baseStore.listValues(objectUri, propertyDescriptor); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#isCollectionMembersAssignableTo(java.lang.String, java.lang.String, java.lang.String, java.lang.Class) */ @Override - public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) + public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return baseStore.isCollectionMembersAssignableTo(documentUri, id, propertyDescriptor, clazz); + return baseStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, clazz); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#isPropertyValueAssignableTo(java.lang.String, java.lang.String, java.lang.String, java.lang.Class) */ @Override - public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return baseStore.isPropertyValueAssignableTo(documentUri, id, propertyDescriptor, clazz); + return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz); } /* (non-Javadoc) * @see org.spdx.storage.IModelStore#isCollectionProperty(java.lang.String, java.lang.String, java.lang.String) */ @Override - public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return baseStore.isCollectionProperty(documentUri, id, propertyDescriptor); + return baseStore.isCollectionProperty(objectUri, propertyDescriptor); } /* (non-Javadoc) @@ -240,22 +232,22 @@ public Optional getCaseSensisitiveId(String documentUri, String caseInse * @see org.spdx.storage.IModelStore#getTypedValue(java.lang.String, java.lang.String) */ @Override - public Optional getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException { - return baseStore.getTypedValue(documentUri, id); + public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException { + return baseStore.getTypedValue(objectUri); } /** * Clear all values for the document - * @param documentUri * @throws InvalidSPDXAnalysisException */ - protected void clear(String documentUri) throws InvalidSPDXAnalysisException { - IModelStoreLock lock = this.enterCriticalSection(documentUri, false); + protected void clear() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = this.enterCriticalSection(false); try { - for (TypedValue item:this.getAllItems(documentUri, null).collect(Collectors.toList())) { - for (PropertyDescriptor propertyDescriptor:this.getPropertyValueDescriptors(documentUri, item.getId())) { - this.removeProperty(documentUri, item.getId(), propertyDescriptor); + for (TypedValue item:this.getAllItems(null, null).collect(Collectors.toList())) { + for (PropertyDescriptor propertyDescriptor:this.getPropertyValueDescriptors(item.getObjectUri())) { + this.removeProperty(item.getObjectUri(), propertyDescriptor); } + this.delete(item.getObjectUri()); } } finally { this.leaveCriticalSection(lock); @@ -264,8 +256,8 @@ protected void clear(String documentUri) throws InvalidSPDXAnalysisException { } @Override - public void delete(String documentUri, String elementId) throws InvalidSPDXAnalysisException { - baseStore.delete(documentUri, elementId); + public void delete(String objectUri) throws InvalidSPDXAnalysisException { + baseStore.delete(objectUri); } @Override diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index c86e072db..cfd53a897 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -28,16 +28,18 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; +import javax.annotation.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.TypedValue; @@ -65,18 +67,18 @@ public class InMemSpdxStore implements IModelStore { static final String GENERATED = "gnrtd"; public static Pattern LICENSE_ID_PATTERN_GENERATED = - Pattern.compile(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+"(\\d+)$"); // Pattern for generated license IDs + Pattern.compile(".*"+SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+"(\\d+)$"); // Pattern for generated license IDs - static Pattern DOCUMENT_ID_PATTERN_GENERATED = Pattern.compile(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+"(\\d+)$"); - static Pattern SPDX_ID_PATTERN_GENERATED = Pattern.compile(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+"(\\d+)$"); - static final String ANON_PREFIX = "__anon__"; + static Pattern DOCUMENT_ID_PATTERN_GENERATED = Pattern.compile(".*"+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+"(\\d+)$"); + static Pattern SPDX_ID_PATTERN_GENERATED = Pattern.compile(".*"+SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+"(\\d+)$"); + public static final String ANON_PREFIX = "__anon__"; static Pattern ANON_ID_PATTERN_GENERATED = Pattern.compile(ANON_PREFIX+GENERATED+"(\\d+)$"); private static final Set LITERAL_VALUE_SET = new HashSet(Arrays.asList(SpdxConstantsCompatV2.LITERAL_VALUES)); /** - * Map of Document URI to items stored in the document. The key for the items map is the lowercase of the item ID. + * Map of property object URI's to typed value items */ - protected Map> documentValues = Collections.synchronizedMap(new LinkedHashMap<>()); + protected Map typedValueMap = Collections.synchronizedMap(new LinkedHashMap<>()); private int nextNextLicenseId = 0; private int nextNextDocumentId = 0; private int nextNextSpdxId = 0; @@ -102,53 +104,58 @@ public void unlock() { } }; + + private SpdxMajorVersion spdxVersion; + + public InMemSpdxStore() { + this(SpdxMajorVersion.VERSION_3); + } + + /** + * @param spdxVersion the major SPDX version for the model store (e.g. "2" or "3") + */ + public InMemSpdxStore(SpdxMajorVersion spdxVersion) { + this.spdxVersion = spdxVersion; + } @Override - public boolean exists(String documentUri, String id) { - Map idMap = documentValues.get(documentUri); - if (idMap == null) { - return false; - } - return idMap.containsKey(id.toLowerCase()); + public boolean exists(String objectUri) { + return typedValueMap.containsKey(objectUri.toLowerCase()); } @Override - public void create(String documentUri, String id, String type) throws InvalidSPDXAnalysisException { - StoredTypedItem value = new StoredTypedItem(documentUri, id, type); - Map idMap = documentValues.get(documentUri); - while (idMap == null) { - idMap = documentValues.putIfAbsent(documentUri, Collections.synchronizedMap(new LinkedHashMap())); - } - updateNextIds(id); - if (Objects.nonNull(idMap.putIfAbsent(id.toLowerCase(), value))) { - throw new DuplicateSpdxIdException("ID "+id+" already exists."); + public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { + StoredTypedItem value = new StoredTypedItem(objectUri, type); + updateNextIds(objectUri); + if (Objects.nonNull(this.typedValueMap.putIfAbsent(objectUri.toLowerCase(), value))) { + throw new DuplicateSpdxIdException("Object URI "+objectUri+" already exists."); } } /** * Check to see if the next ID indexes need to be updated based on the name provided - * @param id + * @param objectUri */ - void updateNextIds(String id) { - if (id == null) { + void updateNextIds(String objectUri) { + if (objectUri == null) { return; } - Matcher licenseRefMatcher = LICENSE_ID_PATTERN_GENERATED.matcher(id); + Matcher licenseRefMatcher = LICENSE_ID_PATTERN_GENERATED.matcher(objectUri); if (licenseRefMatcher.matches()) { checkUpdateNextLicenseId(licenseRefMatcher); return; } - Matcher documentRefMatcher = DOCUMENT_ID_PATTERN_GENERATED.matcher(id); + Matcher documentRefMatcher = DOCUMENT_ID_PATTERN_GENERATED.matcher(objectUri); if (documentRefMatcher.matches()) { checkUpdateNextDocumentId(documentRefMatcher); return; } - Matcher spdxRefMatcher = SPDX_ID_PATTERN_GENERATED.matcher(id); + Matcher spdxRefMatcher = SPDX_ID_PATTERN_GENERATED.matcher(objectUri); if (spdxRefMatcher.matches()) { checkUpdateNextSpdxId(spdxRefMatcher); return; } - Matcher anonRefMatcher = ANON_ID_PATTERN_GENERATED.matcher(id); + Matcher anonRefMatcher = ANON_ID_PATTERN_GENERATED.matcher(objectUri); if (anonRefMatcher.matches()) { checkUpdateNextAnonId(anonRefMatcher); return; @@ -189,59 +196,54 @@ private synchronized void checkUpdateNextLicenseId(Matcher licenseRefMatcher) { /** * Gets the item from the hashmap - * @param documentUri - * @param id + * @param objectUri * @return * @throws InvalidSPDXAnalysisException */ - protected StoredTypedItem getItem(String documentUri, String id) throws InvalidSPDXAnalysisException { - Map idMap = documentValues.get(documentUri); - if (idMap == null) { - throw new SpdxIdNotFoundException("Document URI "+documentUri+" was not found in the memory store. The ID must first be created before getting or setting property values."); - } - StoredTypedItem item = idMap.get(id.toLowerCase()); + protected StoredTypedItem getItem(String objectUri) throws InvalidSPDXAnalysisException { + StoredTypedItem item = this.typedValueMap.get(objectUri.toLowerCase()); if (item == null) { - throw new SpdxIdNotFoundException("ID "+id+" was not found in the memory store. The ID must first be created before getting or setting property values."); + throw new SpdxIdNotFoundException("Object URI "+objectUri+" was not found in the memory store. The ID must first be created before getting or setting property values."); } return item; } @Override - public List getPropertyValueDescriptors(String documentUri, String id) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).getPropertyValueDescriptors(); + public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException { + return getItem(objectUri).getPropertyValueDescriptors(); } @Override - public void setValue(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (value instanceof TypedValue) { referenceCountLock.writeLock().lock(); try { - StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); - getItem(documentUri, id).setValue(propertyDescriptor, value); + StoredTypedItem itemToBeStored = getItem(((TypedValue)value).getObjectUri()); + getItem(objectUri).setValue(propertyDescriptor, value); itemToBeStored.incReferenceCount(); } finally { referenceCountLock.writeLock().unlock(); } } else { - getItem(documentUri, id).setValue(propertyDescriptor, value); + getItem(objectUri).setValue(propertyDescriptor, value); } } @Override - public void clearValueCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { referenceCountLock.writeLock().lock(); try { List removedItems = new ArrayList<>(); - Iterator iter = getItem(documentUri, id).getValueList(propertyDescriptor); + Iterator iter = getItem(objectUri).getValueList(propertyDescriptor); while (iter.hasNext()) { Object nextItem = iter.next(); if (nextItem instanceof TypedValue) { - removedItems.add(getItem(documentUri, ((TypedValue)nextItem).getId())); + removedItems.add(getItem(((TypedValue)nextItem).getObjectUri())); } } - getItem(documentUri, id).clearPropertyValueList(propertyDescriptor); + getItem(objectUri).clearPropertyValueList(propertyDescriptor); for (StoredTypedItem item:removedItems) { item.decReferenceCount(); } @@ -251,65 +253,74 @@ public void clearValueCollection(String documentUri, String id, PropertyDescript } @Override - public boolean addValueToCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (value instanceof TypedValue) { referenceCountLock.writeLock().lock(); try { - StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); - boolean result = getItem(documentUri, id).addValueToList(propertyDescriptor, value); + StoredTypedItem itemToBeStored = getItem(((TypedValue)value).getObjectUri()); + boolean result = getItem(objectUri).addValueToList(propertyDescriptor, value); itemToBeStored.incReferenceCount(); return result; } finally { referenceCountLock.writeLock().unlock(); } } else { - return getItem(documentUri, id).addValueToList(propertyDescriptor, value); + return getItem(objectUri).addValueToList(propertyDescriptor, value); } } @Override - public boolean removeValueFromCollection(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { if (value instanceof TypedValue) { referenceCountLock.writeLock().lock(); try { - StoredTypedItem itemToBeStored = getItem(documentUri, ((TypedValue)value).getId()); - boolean result = getItem(documentUri, id).removeValueFromList(propertyDescriptor, value); + StoredTypedItem itemToBeStored = getItem(((TypedValue)value).getObjectUri()); + boolean result = getItem(objectUri).removeValueFromList(propertyDescriptor, value); itemToBeStored.decReferenceCount(); return result; } finally { referenceCountLock.writeLock().unlock(); } } else { - return getItem(documentUri, id).removeValueFromList(propertyDescriptor, value); + return getItem(objectUri).removeValueFromList(propertyDescriptor, value); } } @Override - public Iterator listValues(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).getValueList(propertyDescriptor); + return getItem(objectUri).getValueList(propertyDescriptor); } @Override - public Optional getValue(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - StoredTypedItem item = getItem(documentUri, id); + public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + StoredTypedItem item = getItem(objectUri); if (item.isCollectionProperty(propertyDescriptor)) { - logger.warn("Returning a collection for a getValue call for property "+propertyDescriptor); - return Optional.of(new ModelCollection<>(this, documentUri, id, propertyDescriptor, null ,null)); + if (this.spdxVersion.compareTo(SpdxMajorVersion.VERSION_3) < 0) { + int indexOfPound = item.getObjectUri().lastIndexOf('#'); + if (indexOfPound < 0) { + throw new InvalidSPDXAnalysisException("Object URIs in SPDX 2 compatible stores must contain a '#' to determine the document URI"); + } + String documentUri = item.getObjectUri().substring(0, indexOfPound); + String id = item.getObjectUri().substring(indexOfPound + 1); + return Optional.of(new ModelCollection<>(this, documentUri, id, propertyDescriptor, null ,null)); + } else { + throw new InvalidSPDXAnalysisException("Unimplemented version 3"); + } } else { return Optional.ofNullable(item.getValue(propertyDescriptor)); } } @Override - public synchronized String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException { + public synchronized String getNextId(IdType idType, @Nullable String nameSpace) throws InvalidSPDXAnalysisException { switch (idType) { case Anonymous: return ANON_PREFIX+GENERATED+String.valueOf(nextAnonId++); - case LicenseRef: return SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+String.valueOf(nextNextLicenseId++); - case DocumentRef: return SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); - case SpdxId: return SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); + case LicenseRef: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+String.valueOf(nextNextLicenseId++); + case DocumentRef: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); + case SpdxId: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); case ListedLicense: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Listed License"); case Literal: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Literal"); default: throw new InvalidSPDXAnalysisException("Unknown ID type for next ID: "+idType.toString()); @@ -317,13 +328,13 @@ public synchronized String getNextId(IdType idType, String documentUri) throws I } @Override - public void removeProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { referenceCountLock.writeLock().lock(); try { - Object itemToBeRemoved = getItem(documentUri, id).getValue(propertyDescriptor); - getItem(documentUri, id).removeProperty(propertyDescriptor); + Object itemToBeRemoved = getItem(objectUri).getValue(propertyDescriptor); + getItem(objectUri).removeProperty(propertyDescriptor); if (itemToBeRemoved instanceof TypedValue) { - getItem(documentUri, ((TypedValue)itemToBeRemoved).getId()).decReferenceCount(); + getItem(((TypedValue)itemToBeRemoved).getObjectUri()).decReferenceCount(); } } finally { referenceCountLock.writeLock().unlock(); @@ -331,55 +342,47 @@ public void removeProperty(String documentUri, String id, PropertyDescriptor pro } @Override - public List getDocumentUris() { - return Collections.unmodifiableList(new ArrayList(this.documentValues.keySet())); - } - - @Override - public Stream getAllItems(String documentUri, String typeFilter) + public Stream getAllItems(@Nullable String nameSpace, String typeFilter) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(documentUri, "Document URi can not be null"); + Iterator valueIter = typedValueMap.values().iterator(); List allItems = new ArrayList<>(); - Map itemMap = this.documentValues.get(documentUri); - if (Objects.nonNull(itemMap)) { - Iterator valueIter = itemMap.values().iterator(); - while (valueIter.hasNext()) { - StoredTypedItem item = valueIter.next(); - if (Objects.isNull(typeFilter) || typeFilter.equals(item.getType())) { - allItems.add(item); - } + while (valueIter.hasNext()) { + StoredTypedItem item = valueIter.next(); + if ((Objects.isNull(typeFilter) || typeFilter.equals(item.getType())) && + (Objects.isNull(nameSpace) || item.getObjectUri().startsWith(nameSpace))) { + allItems.add(item); } } return Collections.unmodifiableList(allItems).stream(); } @Override - public int collectionSize(String documentUri, String id, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).collectionSize(propertyDescriptor); + public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + return getItem(objectUri).collectionSize(propertyDescriptor); } @Override - public boolean collectionContains(String documentUri, String id, PropertyDescriptor propertyDescriptor, Object value) + public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).collectionContains(propertyDescriptor, value); + return getItem(objectUri).collectionContains(propertyDescriptor, value); } @Override - public boolean isCollectionMembersAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, + public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).isCollectionMembersAssignableTo(propertyDescriptor, clazz); + return getItem(objectUri).isCollectionMembersAssignableTo(propertyDescriptor, clazz, spdxVersion); } @Override - public boolean isPropertyValueAssignableTo(String documentUri, String id, PropertyDescriptor propertyDescriptor, Class clazz) + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).isPropertyValueAssignableTo(propertyDescriptor, clazz); + return getItem(objectUri).isPropertyValueAssignableTo(propertyDescriptor, clazz); } @Override - public boolean isCollectionProperty(String documentUri, String id, PropertyDescriptor propertyDescriptor) + public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - return getItem(documentUri, id).isCollectionProperty(propertyDescriptor); + return getItem(objectUri).isCollectionProperty(propertyDescriptor); } @Override @@ -387,19 +390,22 @@ public IdType getIdType(String id) { if (id.startsWith(ANON_PREFIX+GENERATED)) { return IdType.Anonymous; } - if (id.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { + if (id.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM) | + id.contains("#" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { return IdType.LicenseRef; } - if (id.startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { + if (id.startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM) | + id.contains("#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { return IdType.DocumentRef; } - if (id.startsWith(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { + if (id.startsWith(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM) | + id.contains("#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { return IdType.SpdxId; } if (LITERAL_VALUE_SET.contains(id)) { return IdType.Literal; } - if (LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) { + if (id.contains("://spdx.org/licenses/") || LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) { return IdType.ListedLicense; } else { return IdType.Unkown; @@ -407,7 +413,7 @@ public IdType getIdType(String id) { } @Override - public IModelStoreLock enterCriticalSection(String documentUri, boolean readLockRequested) { + public IModelStoreLock enterCriticalSection(boolean readLockRequested) { if (readLockRequested) { this.transactionLock.readLock().lock(); return readLock; @@ -423,82 +429,88 @@ public void leaveCriticalSection(IModelStoreLock lock) { } @Override - public Optional getCaseSensisitiveId(String documentUri, String caseInsensisitiveId) { - Map idMap = documentValues.get(documentUri); - if (Objects.isNull(idMap)) { - return Optional.empty(); - } - StoredTypedItem item = idMap.get(caseInsensisitiveId.toLowerCase()); + public Optional getCaseSensisitiveId(String nameSpace, String caseInsensisitiveId) { + Objects.requireNonNull(nameSpace, "Namespace can not be null"); + Objects.requireNonNull(caseInsensisitiveId, "CaseInsensisitiveId can not be null"); + String objectUri = nameSpace + "#" + caseInsensisitiveId; + StoredTypedItem item = typedValueMap.get(objectUri); if (Objects.isNull(item)) { return Optional.empty(); } - return Optional.of(item.getId()); + return Optional.of(item.getObjectUri().substring(nameSpace.length() + 1)); } @Override - public Optional getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException { + public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException { try { - return Optional.of(getItem(documentUri, id)); + return Optional.of(getItem(objectUri)); } catch(SpdxIdNotFoundException ex) { return Optional.empty(); } } /** - * Remove all existing elements, properties, and values for a document including the document itself + * Remove all existing elements, properties, and values * @param documentUri */ - public void clear(String documentUri) { - Objects.requireNonNull(documentUri, "Document uri can not be null"); - this.documentValues.put(documentUri, new ConcurrentHashMap()); + public void clear() { + this.typedValueMap.clear();; } @Override - public void delete(String documentUri, String id) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(documentUri, "Missing Document URI"); - Objects.requireNonNull(id, "Missing ID"); - Map idMap = documentValues.get(documentUri); - if (Objects.isNull(idMap)) { - logger.error("Error deleting - documentUri "+documentUri+" does not exits."); - throw new SpdxIdNotFoundException("Error deleting - documentUri "+documentUri+" does not exits."); + public void delete(String objectUri) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(objectUri, "Missing object URI"); + if (!this.typedValueMap.containsKey(objectUri.toLowerCase())) { + return; } referenceCountLock.writeLock().lock(); try { - if (getItem(documentUri, id).getReferenceCount() > 0) { + if (getItem(objectUri).getReferenceCount() > 0) { // find the element it is used by - logger.error("Can not delete ID "+id+". It is in use"); - throw new SpdxIdInUseException("Can not delete ID "+id+". It is in use."); + logger.error("Can not object URI "+objectUri+". It is in use"); + throw new SpdxIdInUseException("Can not object URI "+objectUri+". It is in use"); } - List propertyDescriptors = this.getPropertyValueDescriptors(documentUri, id); + List propertyDescriptors = this.getPropertyValueDescriptors(objectUri); for (PropertyDescriptor property:propertyDescriptors) { - if (this.isCollectionProperty(documentUri, id, property)) { - Iterator iter = this.listValues(documentUri, id, property); + if (this.isCollectionProperty(objectUri, property)) { + Iterator iter = this.listValues(objectUri, property); while (iter.hasNext()) { Object val = iter.next(); if (val instanceof TypedValue) { - getItem(documentUri, ((TypedValue)val).getId()).decReferenceCount(); + getItem(((TypedValue)val).getObjectUri()).decReferenceCount(); } } } else { - Optional val = getValue(documentUri, id, property); + Optional val = getValue(objectUri, property); if (val.isPresent()) { if (val.get() instanceof TypedValue) { - getItem(documentUri, ((TypedValue)val.get()).getId()).decReferenceCount(); + getItem(((TypedValue)val.get()).getObjectUri()).decReferenceCount(); } } } } - if (Objects.isNull(idMap.remove(id.toLowerCase()))) { - logger.error("Error deleting - ID "+id+" does not exist."); - throw new SpdxIdNotFoundException("Error deleting - ID "+id+" does not exist."); + if (Objects.isNull(typedValueMap.remove(objectUri.toLowerCase()))) { + logger.error("Error deleting - object URI "+objectUri+" does not exist."); + throw new SpdxIdNotFoundException("Error deleting - object URI "+objectUri+" does not exist."); } } finally { referenceCountLock.writeLock().unlock(); } } + /* (non-Javadoc) + * @see java.lang.AutoCloseable#close() + */ @Override public void close() throws Exception { // Nothing to do for the in-memory store } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getSpdxVersion() + */ + @Override + public SpdxMajorVersion getSpdxVersion() { + return this.spdxVersion; + } } diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index be96ef167..a7b1e10ed 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -17,12 +17,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.IndividualUriValue; import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; import org.spdx.storage.IModelStore; @@ -48,8 +49,8 @@ public class StoredTypedItem extends TypedValue { private final ReadWriteLock countLock = new ReentrantReadWriteLock(); - public StoredTypedItem(String documentUri, String id, String type) throws InvalidSPDXAnalysisException { - super(id, type); + public StoredTypedItem(String objectUri, String type) throws InvalidSPDXAnalysisException { + super(objectUri, type); } /** @@ -188,7 +189,7 @@ public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object valu ConcurrentHashMap> idValueMap = (ConcurrentHashMap>)map; String id; if (value instanceof TypedValue) { - id = ((TypedValue)value).getId(); + id = ((TypedValue)value).getObjectUri(); } else { id = NO_ID_ID; } @@ -223,7 +224,7 @@ public boolean removeTypedValueFromList(PropertyDescriptor propertyDescriptor, T try { @SuppressWarnings("unchecked") ConcurrentHashMap> typedValueMap = (ConcurrentHashMap>)map; - List list = typedValueMap.get(value.getId()); + List list = typedValueMap.get(value.getObjectUri()); if (list == null) { return false; } @@ -254,7 +255,7 @@ public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object ConcurrentHashMap> idValueMap = (ConcurrentHashMap>)map; String id; if (value instanceof TypedValue) { - id = ((TypedValue)value).getId(); + id = ((TypedValue)value).getObjectUri(); } else { id = NO_ID_ID; } @@ -270,7 +271,7 @@ public boolean removeValueFromList(PropertyDescriptor propertyDescriptor, Object /** * @param propertyDescriptor Descriptor for the property - * @return List of values associated with the id, propertyDescriptor and document + * @return List of values associated with the objectUri, propertyDescriptor and document * @throws SpdxInvalidTypeException */ public Iterator getValueList(PropertyDescriptor propertyDescriptor) throws SpdxInvalidTypeException { @@ -296,7 +297,7 @@ public Iterator getValueList(PropertyDescriptor propertyDescriptor) thro /** * @param propertyDescriptor Descriptor for the property - * @return the single value associated with the id, propertyDescriptor and document + * @return the single value associated with the objectUri, propertyDescriptor and document */ public Object getValue(PropertyDescriptor propertyDescriptor) { Objects.requireNonNull(propertyDescriptor, "property descriptor can not be null"); @@ -318,12 +319,11 @@ public void removeProperty(PropertyDescriptor propertyDescriptor) { * @param store * @throws InvalidSPDXAnalysisException */ - public void copyValuesFrom(String fromDocumentUri, IModelStore store) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(fromDocumentUri, "From document URI can not be null"); + public void copyValuesFrom(IModelStore store) throws InvalidSPDXAnalysisException { Objects.requireNonNull(store, "Store can not be null"); - List propertyDiscriptors = store.getPropertyValueDescriptors(fromDocumentUri, this.getId()); + List propertyDiscriptors = store.getPropertyValueDescriptors(this.getObjectUri()); for (PropertyDescriptor propertydescriptor:propertyDiscriptors) { - Optional value = store.getValue(fromDocumentUri, getId(), propertydescriptor); + Optional value = store.getValue(getObjectUri(), propertydescriptor); if (value.isPresent()) { this.setValue(propertydescriptor, value.get()); } @@ -383,7 +383,7 @@ public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object if (map instanceof ConcurrentHashMap) { String id; if (value instanceof TypedValue) { - id = ((TypedValue)value).getId(); + id = ((TypedValue)value).getObjectUri(); } else { id = NO_ID_ID; } @@ -398,13 +398,23 @@ public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object throw new SpdxInvalidTypeException("Trying to find contains for non list type for property "+propertyDescriptor); } } + + /** + * @param propertyDescriptor descriptor for the property + * @param clazz class to test against + * @return true if the property with the propertyDescriptor can be assigned to clazz for the latest SPDX version + */ + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + return isCollectionMembersAssignableTo(propertyDescriptor, clazz, SpdxMajorVersion.latestVersion()); + } /** * @param propertyDescriptor descriptor for the property * @param clazz class to test against + * @param specVersion Version of the SPDX Spec * @return true if the property with the propertyDescriptor can be assigned to clazz */ - public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, SpdxMajorVersion specVersion) { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); Object map = properties.get(propertyDescriptor); @@ -432,7 +442,7 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri } } else if (value instanceof TypedValue) { try { - if (clazz != TypedValue.class && !clazz.isAssignableFrom(SpdxModelFactory.typeToClass(((TypedValue)value).getType()))) { + if (clazz != TypedValue.class && !clazz.isAssignableFrom(SpdxModelFactory.typeToClass(((TypedValue)value).getType(), specVersion))) { return false; } } catch (InvalidSPDXAnalysisException e) { @@ -447,13 +457,23 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri } return true; } + + /** + * @param propertyDescriptor descriptor for the property + * @param clazz class to test against + * @return true if the property can be assigned to type clazz for the latest SPDX spec version + */ + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + return isPropertyValueAssignableTo(propertyDescriptor, clazz, SpdxMajorVersion.latestVersion()); + } /** * @param propertyDescriptor descriptor for the property * @param clazz class to test against + * @param specVersion Version of the SPDX Spec * @return true if the property can be assigned to type clazz */ - public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, SpdxMajorVersion specVersion) { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); Object value = properties.get(propertyDescriptor); @@ -465,7 +485,7 @@ public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor } if (value instanceof TypedValue) { try { - return clazz.isAssignableFrom(SpdxModelFactory.typeToClass(((TypedValue)value).getType())); + return clazz.isAssignableFrom(SpdxModelFactory.typeToClass(((TypedValue)value).getType(), specVersion)); } catch (InvalidSPDXAnalysisException e) { logger.error("Error converting typed value to class",e); return false; @@ -500,8 +520,8 @@ public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) { } /** - * @param elementId id for the element to check - * @return true if an element using the id is used as a value in a collection + * @param elementId objectUri for the element to check + * @return true if an element using the objectUri is used as a value in a collection */ public boolean usesId(String elementId) { if (Objects.isNull(elementId)) { @@ -512,12 +532,12 @@ public boolean usesId(String elementId) { Object value = allValues.next(); if (value instanceof List && ((List)value).size() > 0 && ((List)value).get(0) instanceof TypedValue) { for (Object listValue:(List)value) { - if (listValue instanceof TypedValue && ((TypedValue) listValue).getId().toLowerCase().equals(elementId.toLowerCase())) { + if (listValue instanceof TypedValue && ((TypedValue) listValue).getObjectUri().toLowerCase().equals(elementId.toLowerCase())) { return true; } } } else if (value instanceof TypedValue) { - if (((TypedValue)value).getId().toLowerCase().equals(elementId.toLowerCase())) { + if (((TypedValue)value).getObjectUri().toLowerCase().equals(elementId.toLowerCase())) { return true; } } diff --git a/src/main/java/org/spdx/utility/compare/SpdxComparer.java b/src/main/java/org/spdx/utility/compare/SpdxComparer.java index eb7da549b..2bd4e27a2 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxComparer.java @@ -92,7 +92,7 @@ public class SpdxComparer { */ private Map>> uniqueExtractedLicenses = new HashMap<>(); /** - * Map of any SPDX documents that have extraced license infos with equivalent text but different comments, id's or other fields + * Map of any SPDX documents that have extraced license infos with equivalent text but different comments, objectUri's or other fields */ private Map>> licenseDifferences = new HashMap<>(); /** @@ -834,11 +834,11 @@ public boolean compareLicense(int doc1, this.checkDocsIndex(doc2); Map> hm = this.extractedLicenseIdMap.get(this.spdxDocs.get(doc1)); if (hm == null) { - throw new SpdxCompareException("Compare License Error - Extracted license id map has not been initialized."); + throw new SpdxCompareException("Compare License Error - Extracted license objectUri map has not been initialized."); } Map xlationMap = hm.get(this.spdxDocs.get(doc2)); if (xlationMap == null) { - throw new SpdxCompareException("Compare License Exception - Extracted license id map has not been initialized."); + throw new SpdxCompareException("Compare License Exception - Extracted license objectUri map has not been initialized."); } try { return LicenseCompareHelper.isLicenseEqual(license1, license2, xlationMap); @@ -1056,7 +1056,7 @@ private void compareLicenses(Collection extractedLicensesA } /** - * Compares the non-license text and non-id fields and returns true + * Compares the non-license text and non-objectUri fields and returns true * if all relevant fields are equal * @param spdxNonStandardLicenseA * @param spdxNonStandardLicenseB diff --git a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java index 95ca913c8..dfbbe67ff 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java @@ -23,9 +23,8 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import junit.framework.TestCase; @@ -50,7 +49,7 @@ public class AnnotationTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); date = format.format(new Date()); oldDate = format.format(new Date(10101)); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java b/src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java index 03c52426e..04bab74a1 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ByteOffsetPointerTest.java @@ -21,9 +21,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import junit.framework.TestCase; @@ -45,7 +43,7 @@ public class ByteOffsetPointerTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); REFERENCED1 = new GenericSpdxElement(); REFERENCED1.setName("referenced1"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java index fe9d01ba2..b024c2f61 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java @@ -23,9 +23,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import junit.framework.TestCase; @@ -75,7 +74,7 @@ public class ChecksumTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); TEST_CHECKSUMS = new Checksum[ALGORITHMS.length]; for (int i = 0; i < ALGORITHMS.length; i++) { diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java index 5a7476be7..87a5b9c7a 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java @@ -24,10 +24,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalDocumentRef; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; @@ -54,7 +51,7 @@ public class ExternalDocumentRefTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); new SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); CHECKSUM1 = gmo.createChecksum(ChecksumAlgorithm.SHA1, SHA1_VALUE1); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java index 77e11fb6f..dd6cdbc33 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java @@ -24,8 +24,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ExternalRef; -import org.spdx.library.model.compat.v2.ReferenceType; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; import org.spdx.library.referencetype.compat.v2.ListedReferenceTypes; import org.spdx.storage.IModelStore; @@ -67,7 +66,7 @@ public class ExternalRefTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); store = DefaultModelStore.getDefaultModelStore(); docUri = DefaultModelStore.getDefaultDocumentUri(); copyManager = DefaultModelStore.getDefaultCopyManager(); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java index e73564a53..3c1589a53 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java @@ -5,12 +5,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; @@ -43,7 +38,7 @@ public class ExternalSpdxElementTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); doc = new SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); CHECKSUM1 = gmo.createChecksum(ChecksumAlgorithm.SHA1, "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java index bada5558e..205e10161 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java @@ -2,12 +2,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ExternalDocumentRef; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.SimpleUriValue; -import org.spdx.library.model.compat.v2.SpdxNoAssertionElement; -import org.spdx.library.model.compat.v2.SpdxNoneElement; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; diff --git a/src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java b/src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java index db5f45dbe..4e8a381bc 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/LineCharPointerTest.java @@ -22,9 +22,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import junit.framework.TestCase; @@ -46,7 +44,7 @@ public class LineCharPointerTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); REFERENCED1 = new GenericSpdxElement(); REFERENCED1.setName("referenced1"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java index 073720ea8..b465c9a5b 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java @@ -7,8 +7,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.ModelCollection; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; @@ -21,7 +20,7 @@ public class ModelCollectionTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index cb268565f..b84ff2a64 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -31,19 +31,11 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.ModelCollection; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.ModelStorageClassConverter; -import org.spdx.library.model.compat.v2.SimpleUriValue; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; @@ -125,7 +117,7 @@ public class ModelObjectTest extends TestCase { * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); ModelStorageClassConverter.reset(); store = DefaultModelStore.getDefaultModelStore(); docUri = DefaultModelStore.getDefaultDocumentUri(); @@ -280,7 +272,7 @@ public void testGetDocumentUri() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getId()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getObjectUri()}. * @throws InvalidSPDXAnalysisException */ public void testGetId() throws InvalidSPDXAnalysisException { @@ -738,7 +730,7 @@ public void testListEquivalenceIsSymmetric() throws InvalidSPDXAnalysisException GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); GenericModelObject gmo2 = new GenericModelObject(store, docUri, "TestId2", copyManager, true); PropertyDescriptor property = new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE); - ExtractedLicenseInfo equivalentLicense = new ExtractedLicenseInfo("id", "licenseText"); + ExtractedLicenseInfo equivalentLicense = new ExtractedLicenseInfo("objectUri", "licenseText"); ExtractedLicenseInfo equivalentLicense2 = new ExtractedLicenseInfo("id2", "licenseText"); ExtractedLicenseInfo equivalentLicense3 = new ExtractedLicenseInfo("id3", "licenseText"); ExtractedLicenseInfo differentLicense = new ExtractedLicenseInfo("id4", "differentText"); @@ -824,7 +816,7 @@ public void testToTypeValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); addTestValues(gmo); TypedValue result = gmo.toTypedValue(); - assertEquals(TEST_ID, result.getId()); + assertEquals(TEST_ID, result.getObjectUri()); assertEquals(gmo.getType(), result.getType()); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index a65e21f6b..694c6fb5c 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -8,23 +8,17 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxItem; -import org.spdx.library.model.compat.v2.ModelStorageClassConverter; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SimpleUriValue; -import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -35,7 +29,7 @@ public class ModelStorageClassConverterTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); } @@ -49,7 +43,7 @@ public void testStoredObjectToModelObject() throws InvalidSPDXAnalysisException Object result = ModelStorageClassConverter.storedObjectToModelObject(tv, gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result instanceof Annotation); - assertEquals(tv.getId(), ((Annotation)result).getId()); + assertEquals(tv.getObjectUri(), ((Annotation)result).getId()); // Enum SimpleUriValue suv = new SimpleUriValue(ChecksumAlgorithm.MD5); result = ModelStorageClassConverter.storedObjectToModelObject(suv, gmo.getDocumentUri(), @@ -97,7 +91,7 @@ public void testOptionalStoredObjectToModelObject() throws InvalidSPDXAnalysisEx Optional result = ModelStorageClassConverter.optionalStoredObjectToModelObject(Optional.of(tv), gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result.isPresent()); assertTrue(result.get() instanceof Annotation); - assertEquals(tv.getId(), ((Annotation)result.get()).getId()); + assertEquals(tv.getObjectUri(), ((Annotation)result.get()).getId()); // Enum SimpleUriValue suv = new SimpleUriValue(ChecksumAlgorithm.MD5); result = ModelStorageClassConverter.optionalStoredObjectToModelObject(Optional.of(suv), gmo.getDocumentUri(), @@ -136,7 +130,7 @@ public void testModelObjectToStoredObject() throws InvalidSPDXAnalysisException // ModelObject Object result = ModelStorageClassConverter.modelObjectToStoredObject(gmo, gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result instanceof TypedValue); - assertEquals(gmo.getId(), ((TypedValue)result).getId()); + assertEquals(gmo.getId(), ((TypedValue)result).getObjectUri()); assertEquals(gmo.getType(), ((TypedValue)result).getType()); // Uri value result = ModelStorageClassConverter.modelObjectToStoredObject(RelationshipType.BUILD_TOOL_OF, gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); @@ -175,7 +169,8 @@ public void testCopyIModelStoreStringIModelStoreStringStringString() throws Inva ExternalExtractedLicenseInfo externalLicense = ExternalExtractedLicenseInfo.uriToExternalExtractedLicense(externalLicenseUri, store1, docUri1, copyManager); element1.setLicenseConcluded(externalLicense); element1.setName("ElementName"); - copyManager.copy(store2, docUri2, id2, store1, docUri1, id1, element1.getType()); + copyManager.copy(store2, CompatibleModelStoreWrapper.documentUriIdToUri(docUri2, id2, false), store1, + CompatibleModelStoreWrapper.documentUriIdToUri(docUri1, id1, false), element1.getType(), docUri2, docUri1); GenericSpdxItem element2 = new GenericSpdxItem(store2, docUri2, id2, copyManager, false); assertTrue(element1.equivalent(element2)); assertTrue(element2.equivalent(element1)); diff --git a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java index 44068a74c..da9b22ccd 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java @@ -19,9 +19,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxNoAssertionElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -39,7 +37,7 @@ public class NoAssertionElementTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -47,7 +45,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testHashCodeEquals() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java index 2989f6527..063105a80 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java @@ -24,10 +24,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.RelatedElementCollection; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import junit.framework.TestCase; @@ -54,7 +51,7 @@ public class RelatedElementCollectionTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); element = new GenericSpdxElement(); relatedDescendentOfElements = new ArrayList<>(); descendedOfRelationships = new ArrayList<>(); diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java index df3a4596f..25ffbcfd7 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java @@ -30,17 +30,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalDocumentRef; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; @@ -78,7 +68,7 @@ public class RelationshipTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); new SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); Checksum checksum = gmo.createChecksum(ChecksumAlgorithm.SHA1, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); @@ -270,7 +260,7 @@ public void testDocumentDescribes() throws InvalidSPDXAnalysisException { public void testVerifyRelatedElement() throws InvalidSPDXAnalysisException { RelationshipType relationshipType1 = RelationshipType.CONTAINED_BY; String comment1 = "Comment1"; - AnyLicenseInfo badConcludedLicense = LicenseInfoFactory.parseSPDXLicenseString("bad-license-id"); + AnyLicenseInfo badConcludedLicense = LicenseInfoFactory.parseSPDXLicenseString("bad-license-objectUri"); assertTrue(badConcludedLicense instanceof ExtractedLicenseInfo); ((ExtractedLicenseInfo)badConcludedLicense).setExtractedText("text"); assertEquals(1, badConcludedLicense.verify().size()); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java index 3837e561f..0f583ea38 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java @@ -18,13 +18,11 @@ package org.spdx.library.model.compat.v2; import org.spdx.library.DefaultModelStore; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.IndividualUriValue; -import org.spdx.library.model.compat.v2.SimpleUriValue; -import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import junit.framework.TestCase; @@ -48,7 +46,7 @@ public class SimpleUriValueTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -59,7 +57,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SimpleUriValue#SimpleUriValue(org.spdx.library.model.compat.v2.compat.v2.IndividualUriValue)}. + * Test method for {@link org.spdx.library.compat.v2.SimpleUriValue#SimpleUriValue(org.spdx.library.compat.v2.IndividualUriValue)}. * @throws InvalidSPDXAnalysisException */ public void testSimpleUriValueIndividualValue() throws InvalidSPDXAnalysisException { @@ -78,22 +76,22 @@ public String getIndividualURI() { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SimpleUriValue#toModelObject(org.spdx.storage.IModelStore, java.lang.String)}. + * Test method for {@link org.spdx.library.compat.v2.SimpleUriValue#toModelObject(org.spdx.storage.IModelStore, java.lang.String)}. * @throws InvalidSPDXAnalysisException */ public void testToModelObject() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(); new SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); - Object result = new SimpleUriValue(EXTERNAL_SPDX_URI).toModelObject(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager()); + Object result = new SimpleUriValue(EXTERNAL_SPDX_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); assertTrue(result instanceof ExternalSpdxElement); ExternalSpdxElement externalElement = (ExternalSpdxElement)result; assertEquals(EXTERNAL_SPDX_ELEMENT_ID, externalElement.getExternalElementId()); assertEquals(EXTERNAL_SPDX_URI, externalElement.getExternalSpdxElementURI()); - result = new SimpleUriValue(ENUM_URI).toModelObject(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager()); + result = new SimpleUriValue(ENUM_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); assertEquals(TEST_ENUM, result); - result = new SimpleUriValue(NON_INTERESTING_URI).toModelObject(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager()); + result = new SimpleUriValue(NON_INTERESTING_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); assertTrue(result instanceof SimpleUriValue); assertEquals(NON_INTERESTING_URI, ((SimpleUriValue)result).getIndividualURI()); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java index 022fb18de..0dea69e19 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java @@ -20,11 +20,6 @@ import java.util.ArrayList; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxConstantElement; -import org.spdx.library.model.compat.v2.SpdxNoAssertionElement; -import org.spdx.library.model.compat.v2.SpdxNoneElement; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java index 337623209..27a0499c1 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxCreatorInformationTest.java @@ -10,9 +10,8 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.SpdxCreatorInformation; import junit.framework.TestCase; @@ -22,7 +21,7 @@ public class SpdxCreatorInformationTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index 20ba9192d..a6b426f5f 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -29,6 +29,7 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.FileType; @@ -40,6 +41,7 @@ import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -101,7 +103,7 @@ public class SpdxDocumentTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); CCO_DATALICENSE = LicenseInfoFactory.getListedLicenseById("CC0-1.0"); LICENSE1 = new ExtractedLicenseInfo("LicenseRef-1", "License Text 1"); @@ -671,7 +673,7 @@ public void testRemoveDescribes() throws InvalidSPDXAnalysisException { Relationship rel = doc.getRelationships().toArray(new Relationship[1])[0]; assertEquals(describedElement, rel.getRelatedSpdxElement().get()); doc.getDocumentDescribes().remove(describedElement); - modelStore.delete(docUri, describedElementId); + modelStore.delete(CompatibleModelStoreWrapper.documentUriIdToUri(docUri, describedElementId, false)); } } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java index 210f7fe04..25a65cfa3 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java @@ -21,15 +21,12 @@ import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; +import java.util.List; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; @@ -60,7 +57,7 @@ public class SpdxElementTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); ANNOTATION1 = gmo.createAnnotation("Person: Annotator1", AnnotationType.OTHER, DATE_NOW, "Comment1"); @@ -90,9 +87,11 @@ protected void tearDown() throws Exception { public void testVerify() throws InvalidSPDXAnalysisException { String id = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "elementId"; SpdxElement element1 = new GenericSpdxElement(gmo.getModelStore(), gmo.getDocumentUri(), id, gmo.getCopyManager(), true); - assertEquals(0, element1.verify().size()); + List result = element1.verify(); + assertEquals(0, result.size()); element1.setName(ELEMENT_NAME1); - assertEquals(0, element1.verify().size()); + result = element1.verify(); + assertEquals(0, result.size()); } public void testAddRemoveAnnotations() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java index a67ed7eaf..7819deb80 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java @@ -11,11 +11,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.FileType; @@ -58,7 +54,7 @@ public class SpdxFileTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); SHA1 = gmo.createChecksum(ChecksumAlgorithm.SHA1, "1123456789abcdef0123456789abcdef01234567"); ANNOTATION1 = gmo.createAnnotation("Organization: Annotator1", @@ -162,7 +158,8 @@ public void testVerify23Fields() throws InvalidSPDXAnalysisException { SpdxFile file = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), "name", null, Arrays.asList(new AnyLicenseInfo[] {}), null, SHA1) .build(); - assertEquals(0, file.verify().size()); + List ver = file.verify(); + assertEquals(0, ver.size()); assertTrue(file.verify(Version.TWO_POINT_ZERO_VERSION).size() > 0); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index c6ff22869..02a2faa71 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -1,8 +1,6 @@ package org.spdx.library.model.compat.v2; -import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.spdx.library.InvalidSPDXAnalysisException; @@ -10,12 +8,6 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxModelFactory; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -65,7 +57,7 @@ public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoole try { result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID2, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, false); - fail("Expected id not found exception"); + fail("Expected objectUri not found exception"); } catch(SpdxIdNotFoundException ex) { // expected } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java index 8d6cb19b8..195d67774 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java @@ -19,9 +19,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxNoneElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -39,7 +37,7 @@ public class SpdxNoneElementTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -47,7 +45,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testHashCodeEquals() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java index 6ee749fbc..e84423050 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java @@ -29,17 +29,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalRef; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.ReferenceType; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxPackage; -import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.enumerations.FileType; @@ -127,7 +117,7 @@ public class SpdxPackageTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); CHECKSUM1 = gmo.createChecksum(ChecksumAlgorithm.SHA1, "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"); @@ -194,6 +184,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java index bb85bb0b6..d129e9cac 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCodeTest.java @@ -23,7 +23,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -54,7 +54,7 @@ public class SpdxPackageVerificationCodeTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); IModelStore store = DefaultModelStore.getDefaultModelStore(); String docUri = DefaultModelStore.getDefaultDocumentUri(); ModelCopyManager copyManager = DefaultModelStore.getDefaultCopyManager(); @@ -74,6 +74,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java index 554494987..d9c7392a9 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java @@ -27,10 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; @@ -100,7 +97,7 @@ public class SpdxSnippetTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); ANNOTATION1 = gmo.createAnnotation("Organization: Annotator1", AnnotationType.OTHER, DATE_NOW, "Comment 1"); @@ -172,6 +169,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java b/src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java index 56026017d..1fd1134fb 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/StartEndPointerTest.java @@ -21,9 +21,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.SinglePointer; @@ -56,7 +54,7 @@ public class StartEndPointerTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); REFERENCED1 = new GenericSpdxElement(); REFERENCED1.setName(REFERENCED_ELEMENT_NAME1); @@ -73,6 +71,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java index fa7b9bfc7..14d4d180a 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java @@ -21,6 +21,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalDocumentRef; @@ -66,7 +67,7 @@ public class ExternalLicenseRefTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); doc = new SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); CHECKSUM1 = gmo.createChecksum(ChecksumAlgorithm.SHA1, "A94A8FE5CCB19BA61C4C0873D391E987982FBBD3"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java index 7c1dfb733..8e34342b1 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java @@ -26,7 +26,9 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -42,7 +44,7 @@ public class ExtractedLicensingInfoTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -50,6 +52,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } static final String TEST_RDF_FILE_PATH = "TestFiles"+File.separator+"SPDXRdfExample.rdf"; @@ -79,20 +82,20 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { } } - /** - * Test method for {@link org.spdx.rdfparser.license.ExtractedLicenseInfo#SPDXNonStandardLicense(org.apache.jena.rdf.model.Model, org.apache.jena.graph.Node)}. - * @throws InvalidSPDXAnalysisException - */ - public void testSPDXNonStandardLicenseModelNode() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setComment(COMMENT1); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); - TypedValue copy = copyManager.copy(modelStore, DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + @SuppressWarnings("unused") + TypedValue copy = copyManager.copy(modelStore, + DefaultModelStore.getDefaultModelStore(), + CompatibleModelStoreWrapper.documentUriIdToUri(DefaultModelStore.getDefaultDocumentUri(), ID1, false), + SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, + DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), copy.getId(), SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); - assertEquals(copy.getId(), lic2.getLicenseId()); + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); + assertEquals(ID1, lic2.getLicenseId()); assertEquals(TEXT1, lic2.getExtractedText()); assertEquals(COMMENT1, lic2.getComment()); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java index 2ea77e6c5..b62d7b3d3 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java @@ -25,7 +25,9 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -41,7 +43,7 @@ public class LicenseExceptionTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -49,6 +51,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } static final String EXCEPTION_ID1 = "id1"; @@ -85,9 +88,12 @@ public void testCreateResource() throws InvalidSPDXAnalysisException { EXCEPTION_NAME1, EXCEPTION_TEXT1, EXCEPTION_SEEALSO1, EXCEPTION_COMMENT1); le.setDeprecated(true); - InMemSpdxStore store = new InMemSpdxStore(); + InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store, DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION); + copyManager.copy(store, DefaultModelStore.getDefaultModelStore(), + CompatibleModelStoreWrapper.documentUriIdToUri(DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, false), + SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, + DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); LicenseException le2 = new LicenseException(store, DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, copyManager, false); assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId()); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java index 43caef868..5ae269be5 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java @@ -24,6 +24,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; @@ -56,7 +57,7 @@ public class LicenseExpressionParserTest extends TestCase { protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); NON_STD_LICENSES = new ExtractedLicenseInfo[NONSTD_IDS.length]; for (int i = 0; i < NONSTD_IDS.length; i++) { @@ -81,6 +82,7 @@ protected void setUp() throws Exception { protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testSingleStdLicense() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java index 909cc0c8e..2fc32c8d4 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactoryTest.java @@ -23,6 +23,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.GenericModelObject; import junit.framework.TestCase; @@ -55,7 +56,7 @@ public class LicenseInfoFactoryTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); NON_STD_LICENSES = new ExtractedLicenseInfo[NONSTD_IDS.length]; for (int i = 0; i < NONSTD_IDS.length; i++) { @@ -98,6 +99,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testParseSPDXLicenseString() throws InvalidLicenseStringException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java index 70c296001..091d3f6a3 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java @@ -19,6 +19,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -41,7 +42,7 @@ public class OrLaterOperatorTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); license1 = new ExtractedLicenseInfo(LICENSE_ID1, LICENSE_TEXT1); license2 = new ExtractedLicenseInfo(LICENSE_ID2, LICENSE_TEXT2); } @@ -51,6 +52,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** * Test method for {@link org.spdx.rdfparser.license.OrLaterOperator#hashCode()}. diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java index e2f5eec1f..0adea1817 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java @@ -26,6 +26,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -43,7 +44,7 @@ public class SpdxListedLicenseTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -51,6 +52,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testCreate() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java index 7a72dfe03..5150e0170 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java @@ -2,6 +2,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.GenericSpdxItem; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -12,12 +13,12 @@ public class SpdxNoneLicenseTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } protected void tearDown() throws Exception { super.tearDown(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testHashCodeEquals() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java index 0188b1338..793183015 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java @@ -6,7 +6,9 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -31,7 +33,7 @@ public class WithExceptionOperatorTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); license1 = new ExtractedLicenseInfo(LICENSE_ID1, LICENSE_TEXT1); license2 = new ExtractedLicenseInfo(LICENSE_ID2, LICENSE_TEXT2); exception1 = new LicenseException(EXCEPTION_ID1, EXCEPTION_NAME1, @@ -42,6 +44,7 @@ protected void setUp() throws Exception { protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testHashCode() throws InvalidSPDXAnalysisException { @@ -79,12 +82,14 @@ public void testVerify() throws InvalidSPDXAnalysisException { public void testCopy() throws InvalidSPDXAnalysisException { WithExceptionOperator weo1 = new WithExceptionOperator(license1, exception1); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); - TypedValue tv = copyManager.copy(store, DefaultModelStore.getDefaultDocumentUri(), - weo1.getModelStore(), weo1.getDocumentUri(), weo1.getId(), weo1.getType()); + @SuppressWarnings("unused") + TypedValue tv = copyManager.copy(store, weo1.getModelStore(), + CompatibleModelStoreWrapper.documentUriIdToUri(weo1.getDocumentUri(), weo1.getId(), false), + weo1.getType(), weo1.getDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); WithExceptionOperator clone = (WithExceptionOperator) SpdxModelFactory.createModelObject(store, - DefaultModelStore.getDefaultDocumentUri(), tv.getId(), SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, copyManager); + DefaultModelStore.getDefaultDocumentUri(), weo1.getId(), SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, copyManager); ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)weo1.getLicense(); ExtractedLicenseInfo lic1FromClone = (ExtractedLicenseInfo)clone.getLicense(); assertEquals(lic1.getExtractedText(), lic1FromClone.getExtractedText()); diff --git a/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java b/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java index 36ff9d69c..f8b92072c 100644 --- a/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java +++ b/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java @@ -83,7 +83,7 @@ public void testVariableRule() throws LicenseTemplateRuleException { String exampleText = "Example \\n text"; LicenseTemplateRule normalRule = new LicenseTemplateRule(ruleName, RuleType.VARIABLE, originalText, matchText, exampleText); - String expectedResult = "\n" + compareOriginalText + "\n"; HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); @@ -99,7 +99,7 @@ public void testFormatReplaceabledHTML() { String originalText = "Original \ntext"; String compareOriginalText = "Original
\ntext"; String ruleName = "testRule"; - String expectedResult = "\n" + compareOriginalText + "\n"; String result = HtmlTemplateOutputHandler.formatReplaceabledHTML(originalText, ruleName); @@ -139,7 +139,7 @@ public void testGetHtml() throws LicenseTemplateRuleException { htoh.beginOptional(beginRule); String optionalText = "Optional Text"; htoh.text(optionalText); - String escapedBeginRuleText = "\n
\n"; + String escapedBeginRuleText = "\n
\n"; String escapedOptionalText = optionalText; String varRuleName = "testRule"; @@ -149,7 +149,7 @@ public void testGetHtml() throws LicenseTemplateRuleException { String exampleText = "Example \\n text"; LicenseTemplateRule normalRule = new LicenseTemplateRule(varRuleName, RuleType.VARIABLE, originalText, matchText, exampleText); - String escapedVariableRuleText = "\n" + compareOriginalText + "\n"; htoh.variableRule(normalRule); @@ -178,7 +178,7 @@ public void testBeginOptional() throws LicenseTemplateRuleException { LicenseTemplateRule beginRule = new LicenseTemplateRule(optRuleName, RuleType.BEGIN_OPTIONAL); htoh.beginOptional(beginRule); - String escapedBeginRuleText = "\n
\n"; + String escapedBeginRuleText = "\n
\n"; assertEquals(escapedBeginRuleText, htoh.getHtml()); } @@ -189,7 +189,7 @@ public void testBeginOptional() throws LicenseTemplateRuleException { @Test public void testFormatStartOptionalHTML() throws LicenseTemplateRuleException { String optRuleName = "optionalRule"; - String escapedBeginRuleText = "\n
\n"; + String escapedBeginRuleText = "\n
\n"; assertEquals(escapedBeginRuleText, HtmlTemplateOutputHandler.formatStartOptionalHTML(optRuleName)); } diff --git a/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java b/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java index 44f596f8e..5d80ad09f 100644 --- a/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java +++ b/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java @@ -102,8 +102,8 @@ public void completeParsing() { static final String LINE3="\nLast line of the license"; static final String TEMPLATE_TEXT = LINE1+REQUIRED_RULE+LINE2+OPTIONAL_RULE+LINE3; - static final String HTML_COPYRIGHT="\nCopyright (c) <year> <owner>
\nAll rights reserved.
\n"; - static final String HTML_OPTIONAL_RULE="\n
\nOriginal Text
\n"; + static final String HTML_COPYRIGHT="\nCopyright (c) <year> <owner>
\nAll rights reserved.
\n"; + static final String HTML_OPTIONAL_RULE="\n
\nOriginal Text
\n"; static final String HTML_LICENSE = LINE1.replace("\n", "
\n")+ HTML_COPYRIGHT+ LINE2.replace("\n", "
\n")+ diff --git a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java new file mode 100644 index 000000000..c33df6184 --- /dev/null +++ b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java @@ -0,0 +1,732 @@ +package org.spdx.storage.compat.v2; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.TypedValue; +import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.storage.PropertyDescriptor; +import org.spdx.storage.IModelStore.IModelStoreLock; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.storage.simple.InMemSpdxStoreTest; + +import junit.framework.TestCase; +import net.jodah.concurrentunit.Waiter; + +public class CompatibleModelStoreWrapperTest extends TestCase { + +static final Logger logger = LoggerFactory.getLogger(InMemSpdxStoreTest.class); + + static final long TIMEOUT = 10000; + + static final String TEST_DOCUMENT_URI1 = "http://test.document.uri/1"; + static final String TEST_DOCUMENT_URI2 = "http://test.document.uri/2"; + + static final String TEST_ID1 = "id1"; + static final String TEST_ID2 = "id2"; + + static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_ANNOTATION; + static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_RELATIONSHIP; + static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("valueProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("valueProp4", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; + static final Object[] TEST_VALUE_PROPERTY_VALUES = new Object[] {"value1", true, "value2", null}; + static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("listProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; + + protected static final int MAX_RETRIES = 10; + TypedValue[] TEST_TYPED_PROP_VALUES; + ArrayList[] TEST_LIST_PROPERTY_VALUES; + + String state; // used to track state in the asynch tests (e.g. testTransaction) + + private synchronized String setTestState(String newState) { + logger.info("Setting state to "+state); + String retval = state; + state = newState; + return retval; + } + + private synchronized String getTestState() { + return state; + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + TEST_LIST_PROPERTY_VALUES = new ArrayList[] {new ArrayList<>(Arrays.asList("ListItem1", "listItem2", "listItem3")), + new ArrayList<>(Arrays.asList(true, false, true)), + new ArrayList<>(Arrays.asList(CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, "typeId1", false, TEST_TYPE1), + CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, "typeId2", false, TEST_TYPE2)))}; + TEST_VALUE_PROPERTY_VALUES[3] = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, "typeId3", false, TEST_TYPE1); + + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testUpdateNextIds() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + // License ID's + String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd0", nextId); + store.create(TEST_DOCUMENT_URI1, "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd34", nextId); + + // SPDX ID's + nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd0", nextId); + store.create(TEST_DOCUMENT_URI1, "SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE); + nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd34", nextId); + + // Anonymous ID's + nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); + store.create(TEST_DOCUMENT_URI1, InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM); + nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd34", nextId); + + // Document ID's + nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + store.create(TEST_DOCUMENT_URI1, SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF); + nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); + } + + public void testCreateExists() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + String id1 = "TestId1"; + String id2 = "testId2"; + assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); + store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); + store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); + store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); + } + + public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); + for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { + if (TEST_VALUE_PROPERTY_VALUES[i] instanceof TypedValue) { + TypedValue tv = (TypedValue)TEST_VALUE_PROPERTY_VALUES[i]; + store.create(tv.getObjectUri(), tv.getType()); + } + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); + } + for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { + for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { + if (value instanceof TypedValue) { + TypedValue tv = (TypedValue)value; + store.create(tv.getObjectUri(), tv.getType()); + } + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[i], value); + } + } + List result = store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1); + assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, result.size()); + for (PropertyDescriptor prop:TEST_VALUE_PROPERTIES) { + assertTrue(result.contains(prop)); + } + for (PropertyDescriptor prop:TEST_LIST_PROPERTIES) { + assertTrue(result.contains(prop)); + } + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); + assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); + } + + + public void testGetSetValue() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); + assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[1]); + assertEquals(TEST_VALUE_PROPERTY_VALUES[1], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); + } + + public void testGetAddValueList() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + assertTrue(store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); + assertTrue(store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2)); + assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + } + + static List toImmutableList(Iterator listValues) { + return (List) Collections.unmodifiableList(StreamSupport.stream( + Spliterators.spliteratorUnknownSize(listValues, Spliterator.ORDERED), false) + .collect(Collectors.toList())); + } + + public void testGetNextId() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + // License ID's + String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd0", nextId); + nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd1", nextId); + + // SPDX ID's + nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd0", nextId); + nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd1", nextId); + + // Anonymous ID's + nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); + nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd1", nextId); + + // Document ID's + nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); + assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); + } + + public void testRemoveProperty() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore(SpdxMajorVersion.VERSION_2)); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { + try { + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], e); + } catch (InvalidSPDXAnalysisException e1) { + fail(e1.getMessage()); + } + } + for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { + try { + store.addValueToCollection(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0], e); + } catch (InvalidSPDXAnalysisException e1) { + fail(e1.getMessage()); + } + } + for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { + try { + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0], e); + } catch (InvalidSPDXAnalysisException e1) { + fail(e1.getMessage()); + } + } + + assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).get()); + assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).get()); + assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).get()); + store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { + try { + store.addValueToCollection(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0], e); + } catch (InvalidSPDXAnalysisException e1) { + fail(e1.getMessage()); + } + } + for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { + try { + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0], e); + } catch (InvalidSPDXAnalysisException e1) { + fail(e1.getMessage()); + } + } + } + + private void assertCollectionsEquals(Object c1, Object c2) { + if (!(c1 instanceof Collection)) { + fail("c1 is not a collection"); + } + if (!(c2 instanceof Collection)) { + fail("c2 is not a collection"); + } + Collection col1 = (Collection)c1; + Collection col2 = (Collection)c2; + assertEquals(col1.size(), col2.size()); + for (Object item:col1) { + assertTrue(col2.contains(item)); + } + } + + public void testClearList() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); + assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]); + assertEquals(0, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + } + + public void copyFrom() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + ModelCopyManager copyManager = new ModelCopyManager(); + copyManager.copy(store2, store, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION, null, null); + assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_VALUE_PROPERTIES[0])); + assertEquals(2, toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + } + + public void testRemoveListItem() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); + assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertTrue(store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); + assertEquals(1, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + assertFalse(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertFalse("Already removed - should return false",store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); + } + + //TODO: Fix the following test - it is flakey. Times out about 1 out of 5 times. Test problem, not a problem with the code under test + public void testLock() throws InvalidSPDXAnalysisException, IOException, InterruptedException, TimeoutException { + final CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + String value1 = "value1"; + String value2 = "value2"; + IModelStoreLock lock = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], value1); + lock.unlock(); + assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + /* Expected program flow + * Step1: thread1 run verifies that the property is still value1 + * thread1 starts a read transaction + * thread1 waits for step2 + * thread2 run verifies that the property is still value1 + * Step2: thread2 wakes up thread 1 + * Step3: thread1 wakes up thread 2 + * thread2 starts a write transaction + * thread2 is expected to block on the write transaction until thread1 finishes the read/verify + * step4: thread2 completes the write transaction, both threads verify value updated + */ + final Waiter waiter = new Waiter(); + @SuppressWarnings("unused") + final Thread thread1 = new Thread(null, null, "Thread1") { + @Override + public void run() { + try { + logger.info("thread1 started"); + logger.info("Waking up main thread"); + waiter.assertEquals("step0", setTestState("step1")); + waiter.resume(); // release the main thread + logger.info("Woke up main thread"); + waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + IModelStoreLock transactionLock = store.enterCriticalSection(TEST_DOCUMENT_URI1, true); + waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + int retries = 0; + while (!getTestState().equals("step2") && retries < MAX_RETRIES) { + logger.info("Thread 1 waiting for thread 2"); + waiter.await(TIMEOUT); // wait for thread 2 + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Thread1 awoke from thread 2"); + waiter.assertEquals("step2", setTestState("step3")); + logger.info("Waking up thread2"); + waiter.resume(); // wake thread 2 back up + logger.info("Woke up thread2"); + waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + transactionLock.unlock(); + retries = 0; + while (!getTestState().equals("step4") && retries < MAX_RETRIES) { + logger.info("Thread 1 waiting for thread 2"); + waiter.await(TIMEOUT); // wait for thread 2 to commit + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Thread1 awoke from thread 2"); + waiter.assertEquals("step4", getTestState()); + waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + } catch (Exception e) { + waiter.fail("Unexpected exception: "+e.getMessage()); + } + } + }; + + @SuppressWarnings("unused") + final Thread thread2 = new Thread(null ,null, "thread2") { + @Override + public void run() { + try { + waiter.assertEquals("step1", getTestState()); + waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + waiter.assertEquals("step1",setTestState("step2")); + logger.info("Waking up Thread1"); + waiter.resume(); // wakeup thread1 + logger.info("Woke up Thread1"); + int retries = 0; + while (!getTestState().equals("step3") && retries < MAX_RETRIES) { + logger.info("Thread 2 waiting for thread 1"); + waiter.await(TIMEOUT); // wait for thread 1 + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Thread2 awoke from thread 1"); + waiter.assertEquals("step3", getTestState()); + IModelStoreLock transactionLock2 = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); // this should block waiting for thread1 transaction to complete + waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], value2); + waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + transactionLock2.unlock(); + waiter.assertEquals("step3",setTestState("step4")); + logger.info("Waking up Thread1"); + waiter.resume(); // wakeup thread1 + logger.info("Woke up Thread1"); + waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + } catch (Exception e) { + waiter.fail("Unexpected exception: "+e.getMessage()); + } + } + }; + /* + setTestState("step0"); + logger.info("Starting Thread1"); + thread1.start(); + int retries = 0; + while (getTestState().equals("step0")) { + logger.info("Waiting for Thread1"); + waiter.await(TIMEOUT); // wait for thread 1 to get going + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Starting Thread2"); + thread2.start(); + logger.info("Joining thread1"); + thread1.join(); + logger.info("Joining thread2"); + thread2.join(); + assertEquals("step4", getTestState()); + */ + } + + public void testCollectionSize() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); + assertEquals(2, store.collectionSize(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])); + assertEquals(0, store.collectionSize(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[1])); + } + + public void testCollectionContains() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); + assertTrue(store.collectionContains(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0],value1)); + assertTrue(store.collectionContains(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0],value2)); + assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + } + + public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { + + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + // String + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); + assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); + // Boolean + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); + assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); + // TypedValue + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + TypedValue tv = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, TEST_ID2, false, TEST_TYPE2); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, String.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); + assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); + // Empty + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); + } + + public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + // String + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 2"); + assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); + // Boolean + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(false)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); + // TypedValue + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + TypedValue tv = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, TEST_ID2, false, TEST_TYPE2); + store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, String.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); + // Mixed + PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.valueOf(true)); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, "mixed value"); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, String.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, TypedValue.class)); + // Empty + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, Boolean.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, TypedValue.class)); + } + + public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + // String + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); + PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, listProperty, "testValue"); + assertTrue(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, listProperty)); + assertFalse(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, sProperty)); + } + + public void testIdType() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + assertEquals(IdType.Anonymous, store.getIdType(InMemSpdxStore.ANON_PREFIX+"gnrtd23")); + assertEquals(IdType.DocumentRef, store.getIdType(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"gnrtd23")); + assertEquals(IdType.LicenseRef, store.getIdType(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"gnrtd23")); + assertEquals(IdType.ListedLicense, store.getIdType("Apache-2.0")); + assertEquals(IdType.ListedLicense, store.getIdType("https://spdx.org/licenses/somelicense")); + assertEquals(IdType.ListedLicense, store.getIdType("LLVM-exception")); + assertEquals(IdType.Literal, store.getIdType("NONE")); + assertEquals(IdType.Literal, store.getIdType("NOASSERTION")); + assertEquals(IdType.SpdxId, store.getIdType(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); + } + + public void testGetCaseSensisitiveId() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + String expected = "TestIdOne"; + String lower = expected.toLowerCase(); + store.create(TEST_DOCUMENT_URI1, expected, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertEquals(expected, store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, lower).get()); + assertFalse(store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, "somethingNotThere").isPresent()); + try { + store.create(TEST_DOCUMENT_URI1, lower, SpdxConstantsCompatV2.CLASS_ANNOTATION); + fail("This should be a duplicate ID failure"); + } catch (InvalidSPDXAnalysisException e) { + // expected + } + } + + public void testGetTypedValue() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertEquals(SpdxConstantsCompatV2.CLASS_ANNOTATION, store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID1).get().getType()); + assertFalse(store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID2).isPresent()); + assertFalse(store.getTypedValue(TEST_DOCUMENT_URI2, TEST_ID1).isPresent()); + } + + public void testDelete() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + String id1 = "TestId1"; + String id2 = "testId2"; + assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); + store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); + + store.delete(TEST_DOCUMENT_URI1, id1); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); + assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); + } + + public void testDeleteInUse() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + String id1 = "TestId1"; + String id2 = "testId2"; + String id3 = "testId3"; + String id4 = "testId4"; + store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_DOCUMENT_URI1, id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + TypedValue tv3 = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, id3, false, + SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.addValueToCollection(TEST_DOCUMENT_URI1, id2, + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv3); + TypedValue tv4 = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, id4, false, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.addValueToCollection(TEST_DOCUMENT_URI1, id2, + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); + store.setValue(TEST_DOCUMENT_URI1, id3, + new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE), + CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, id1, false, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); + + try { + store.delete(TEST_DOCUMENT_URI1, id3); + fail("id3 is in the listProperty for id2"); + } catch (SpdxIdInUseException ex) { + // expected - id3 is in the listProperty for id2 + } + try { + store.delete(TEST_DOCUMENT_URI1, id4); + fail("id4 is in the listProperty for id2"); + } catch (SpdxIdInUseException ex) { + // expected - id4 is in the listProperty for id2 + } + try { + store.delete(TEST_DOCUMENT_URI1, id1); + fail("id1 is in the property for id3"); + } catch (SpdxIdInUseException ex) { + // expected - id1 is in the property for id3 + } + store.removeValueFromCollection(TEST_DOCUMENT_URI1, id2, + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); + store.delete(TEST_DOCUMENT_URI1, id4); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id4)); + try { + store.delete(TEST_DOCUMENT_URI1, id3); + fail("id3 is in the listProperty for id2"); + } catch (SpdxIdInUseException ex) { + // expected - id3 is in the listProperty for id2 + } + store.removeProperty(TEST_DOCUMENT_URI1, id3, + new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + store.delete(TEST_DOCUMENT_URI1, id1); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); + store.delete(TEST_DOCUMENT_URI1, id2); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); + store.delete(TEST_DOCUMENT_URI1, id3); + assertFalse(store.exists(TEST_DOCUMENT_URI1, id3)); + } +} diff --git a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java index cf7df8d1e..e89c0c77c 100644 --- a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java @@ -132,7 +132,7 @@ public void testSetPrimativeValue() throws InvalidSpdxPropertyException { public void testGetId() { CrossRefJson crj = new CrossRefJson(); assertTrue(Objects.isNull(crj.getId())); - String id = "id"; + String id = "objectUri"; crj.setId(id); assertEquals(id, crj.getId()); } diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java index 1928d9c7b..0a3efc362 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java @@ -25,6 +25,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.InvalidSpdxPropertyException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; @@ -382,7 +384,7 @@ public void testIsPropertyValueAssignableTo() throws Exception { public void testCopyFromLicense() throws Exception { LicenseJson lj = new LicenseJson(); - InMemSpdxStore store = new InMemSpdxStore(); + InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://doc.uri"; String id = "licenseId"; boolean deprecated = true; @@ -398,8 +400,9 @@ public void testCopyFromLicense() throws Exception { Boolean fsfLibre = true; Boolean osiApproved = true; List seeAlsoUrl = Arrays.asList(new String[]{"http://url1", "http://url2"}); + ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = new SpdxListedLicense(store, docUri, id, null, true); + SpdxListedLicense license = new SpdxListedLicense(store, docUri, id, copyManager, true); List crossRefs = new ArrayList<>(); List crossRefUrls = Arrays.asList(new String[]{"http://crossref1", "http://crossref2"}); for (String crossRefUrl:crossRefUrls) { diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java index 04bf1088c..ff610ca69 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java @@ -74,9 +74,9 @@ protected void tearDown() throws Exception { */ public void testExists() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertTrue(slll.exists(LICENSE_LIST_URI, APACHE_ID)); - assertFalse(slll.exists(LICENSE_LIST_URI, "Unknown")); - assertTrue(slll.exists(LICENSE_LIST_URI, ECOS_EXCEPTION_ID)); + assertTrue(slll.exists(LICENSE_LIST_URI + APACHE_ID)); + assertFalse(slll.exists(LICENSE_LIST_URI + "Unknown")); + assertTrue(slll.exists(LICENSE_LIST_URI + ECOS_EXCEPTION_ID)); slll.close(); } @@ -87,13 +87,13 @@ public void testExists() throws Exception { public void testCreate() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); - String result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); + slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); + slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); slll.close(); } @@ -142,27 +142,27 @@ public void testGetLicenseListVersion() throws Exception { public void testGetValue() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + String result = (String)slll.getValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); - result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + result = (String)slll.getValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); slll.close(); } public void testSetValue() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + String result = (String)slll.getValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); String newName = "new name"; - slll.setValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME, newName); - result = (String)slll.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + slll.setValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)slll.getValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); - result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + result = (String)slll.getValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); - slll.setValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME, newName); - result = (String)slll.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + slll.setValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)slll.getValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); slll.close(); } @@ -218,7 +218,7 @@ public void testList() throws InvalidSPDXAnalysisException { exception.setSeeAlso(seeAlsos); // getValueList List result = new ArrayList<>(); - Iterator resultIter = slll.listValues(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + Iterator resultIter = slll.listValues(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -226,21 +226,21 @@ public void testList() throws InvalidSPDXAnalysisException { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection String seeAlso3 = "seeAlso3"; - assertFalse(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.addValueToCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.addValueToCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(slll.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // License ModelCopyManager copyManager = new ModelCopyManager(); @@ -248,7 +248,7 @@ public void testList() throws InvalidSPDXAnalysisException { license.setSeeAlso(seeAlsos); // getValueList result.clear(); - resultIter = slll.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + resultIter = slll.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -256,24 +256,24 @@ public void testList() throws InvalidSPDXAnalysisException { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection - assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // license crossRefs license.getCrossRef().clear(); - assertEquals(0, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertEquals(0, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); IModelStore simpleModelStore = new InMemSpdxStore(); String docUri = "http://some.other.doc"; CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); @@ -284,21 +284,21 @@ public void testList() throws InvalidSPDXAnalysisException { license.getCrossRef().add(crossRef1); license.getCrossRef().add(crossRef2); result.clear(); - resultIter = slll.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); + resultIter = slll.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); List tvResult = new ArrayList<>(); while (resultIter.hasNext()) { TypedValue tv = (TypedValue)resultIter.next(); tvResult.add(tv); - result.add(new CrossRef(slll, LICENSE_LIST_URI, tv.getId(), copyManager, false)); + result.add(new CrossRef(slll, LICENSE_LIST_URI, tv.getObjectUri(), copyManager, false)); } List result2 = (List)(List)Arrays.asList(license.getCrossRef().toArray()); assertEquals(2, result.size()); assertEquals(2, result2.size()); - assertEquals(2, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertEquals(2, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, (List)(List)result)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, result2)); for (TypedValue tv:tvResult) { - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); } for (CrossRef crossRef:crossRefs) { // collectionContains @@ -307,12 +307,12 @@ public void testList() throws InvalidSPDXAnalysisException { CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); crossRef3.setUrl("http://url3"); String newCrossRefId = slll.getNextId(IdType.Anonymous, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - slll.setValue(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); + slll.create(LICENSE_LIST_URI + newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); + slll.setValue(LICENSE_LIST_URI + newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - slll.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertEquals(3, slll.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + slll.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertEquals(3, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); boolean found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -321,8 +321,8 @@ public void testList() throws InvalidSPDXAnalysisException { } } assertTrue(found); - slll.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertFalse(slll.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + slll.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertFalse(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -335,49 +335,49 @@ public void testList() throws InvalidSPDXAnalysisException { public void testIsCollectionMembersAssignableTo() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); - assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, Boolean.class)); - assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); - assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); - assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, String.class)); + assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, Boolean.class)); + assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); + assertTrue(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); + assertFalse(slll.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, String.class)); slll.close(); } public void testIsPropertyValueAssignableTo() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); - assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, Boolean.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, Boolean.class)); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class)); - assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class)); + assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class)); slll.close(); } public void testIsCollectionProperty() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertTrue(slll.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED)); + assertTrue(slll.isCollectionProperty(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(slll.isCollectionProperty(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED)); slll.close(); } public void testDelete() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); - String result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); + slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); - assertTrue(slll.exists(LICENSE_LIST_URI, nextId)); - slll.delete(LICENSE_LIST_URI, nextId); - assertFalse(slll.exists(LICENSE_LIST_URI, nextId)); + assertTrue(slll.exists(LICENSE_LIST_URI + nextId)); + slll.delete(LICENSE_LIST_URI + nextId); + assertFalse(slll.exists(LICENSE_LIST_URI + nextId)); nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)slll.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); + slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); - assertTrue(slll.exists(LICENSE_LIST_URI, nextId)); - slll.delete(LICENSE_LIST_URI, nextId); - assertFalse(slll.exists(LICENSE_LIST_URI, nextId)); + assertTrue(slll.exists(LICENSE_LIST_URI + nextId)); + slll.delete(LICENSE_LIST_URI + nextId); + assertFalse(slll.exists(LICENSE_LIST_URI + nextId)); slll.close(); } diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java index deaeec818..25a395ff9 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java @@ -74,9 +74,9 @@ protected void tearDown() throws Exception { */ public void testExists() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - assertTrue(sllw.exists(LICENSE_LIST_URI, APACHE_ID)); - assertFalse(sllw.exists(LICENSE_LIST_URI, "Unknown")); - assertTrue(sllw.exists(LICENSE_LIST_URI, ECOS_EXCEPTION_ID)); + assertTrue(sllw.exists(LICENSE_LIST_URI + APACHE_ID)); + assertFalse(sllw.exists(LICENSE_LIST_URI + "Unknown")); + assertTrue(sllw.exists(LICENSE_LIST_URI + ECOS_EXCEPTION_ID)); sllw.close(); } @@ -86,13 +86,13 @@ public void testExists() throws Exception { public void testCreate() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); - String result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); + sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); + sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); sllw.close(); } @@ -165,27 +165,27 @@ int compareVersionStrings(String versionA, String versionB) { public void testGetValue() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + String result = (String)sllw.getValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); - result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + result = (String)sllw.getValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); sllw.close(); } public void testSetValue() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + String result = (String)sllw.getValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(APACHE_LICENSE_NAME, result); String newName = "new name"; - sllw.setValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME, newName); - result = (String)sllw.getValue(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + sllw.setValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)sllw.getValue(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); - result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + result = (String)sllw.getValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(ECOS_LICENSE_NAME, result); - sllw.setValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME, newName); - result = (String)sllw.getValue(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); + sllw.setValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME, newName); + result = (String)sllw.getValue(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_NAME).get(); assertEquals(newName, result); sllw.close(); } @@ -246,7 +246,7 @@ public void testList() throws Exception { exception.setSeeAlso(seeAlsos); // getValueList List result = new ArrayList<>(); - Iterator resultIter = sllw.listValues(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + Iterator resultIter = sllw.listValues(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -254,21 +254,21 @@ public void testList() throws Exception { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection String seeAlso3 = "seeAlso3"; - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // License ModelCopyManager copyManager = new ModelCopyManager(); @@ -276,7 +276,7 @@ public void testList() throws Exception { license.setSeeAlso(seeAlsos); // getValueList result.clear(); - resultIter = sllw.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + resultIter = sllw.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -284,24 +284,24 @@ public void testList() throws Exception { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // license crossRefs license.getCrossRef().clear(); - assertEquals(0, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertEquals(0, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); IModelStore simpleModelStore = new InMemSpdxStore(); String docUri = "http://some.other.doc"; CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); @@ -312,21 +312,21 @@ public void testList() throws Exception { license.getCrossRef().add(crossRef1); license.getCrossRef().add(crossRef2); result.clear(); - resultIter = sllw.listValues(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); + resultIter = sllw.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); List tvResult = new ArrayList<>(); while (resultIter.hasNext()) { TypedValue tv = (TypedValue)resultIter.next(); tvResult.add(tv); - result.add(new CrossRef(sllw, LICENSE_LIST_URI, tv.getId(), copyManager, false)); + result.add(new CrossRef(sllw, LICENSE_LIST_URI, tv.getObjectUri(), copyManager, false)); } List result2 = (List)(List)Arrays.asList(license.getCrossRef().toArray()); assertEquals(2, result.size()); assertEquals(2, result2.size()); - assertEquals(2, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertEquals(2, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, (List)(List)result)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, result2)); for (TypedValue tv:tvResult) { - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); } for (CrossRef crossRef:crossRefs) { // collectionContains @@ -335,12 +335,12 @@ public void testList() throws Exception { CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); crossRef3.setUrl("http://url3"); String newCrossRefId = sllw.getNextId(IdType.Anonymous, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - sllw.setValue(LICENSE_LIST_URI, newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); + sllw.create(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); + sllw.setValue(newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - sllw.addValueToCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertEquals(3, sllw.collectionSize(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + sllw.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertEquals(3, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); boolean found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -349,8 +349,8 @@ public void testList() throws Exception { } } assertTrue(found); - sllw.removeValueFromCollection(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + sllw.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertFalse(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -364,30 +364,30 @@ public void testList() throws Exception { public void testIsCollectionProperty() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - assertTrue(sllw.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.isCollectionProperty(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED)); - assertTrue(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); - assertFalse(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, String.class)); + assertTrue(sllw.isCollectionProperty(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(sllw.isCollectionProperty(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED)); + assertTrue(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); + assertFalse(sllw.isCollectionMembersAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, String.class)); sllw.close(); } public void testDelete() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); - String result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); + sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); - assertTrue(sllw.exists(LICENSE_LIST_URI, nextId)); - sllw.delete(LICENSE_LIST_URI, nextId); - assertFalse(sllw.exists(LICENSE_LIST_URI, nextId)); + assertTrue(sllw.exists(LICENSE_LIST_URI + nextId)); + sllw.delete(LICENSE_LIST_URI + nextId); + assertFalse(sllw.exists(LICENSE_LIST_URI + nextId)); nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); - result = (String)sllw.getValue(LICENSE_LIST_URI, nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); + sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); - assertTrue(sllw.exists(LICENSE_LIST_URI, nextId)); - sllw.delete(LICENSE_LIST_URI, nextId); - assertFalse(sllw.exists(LICENSE_LIST_URI, nextId)); + assertTrue(sllw.exists(LICENSE_LIST_URI + nextId)); + sllw.delete(LICENSE_LIST_URI + nextId); + assertFalse(sllw.exists(LICENSE_LIST_URI + nextId)); sllw.close(); } } diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index bbe0d51cc..6c22868b0 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -17,7 +17,6 @@ */ package org.spdx.storage.simple; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -26,7 +25,6 @@ import java.util.List; import java.util.Spliterator; import java.util.Spliterators; -import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -34,6 +32,7 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.SpdxIdInUseException; @@ -54,11 +53,14 @@ public class InMemSpdxStoreTest extends TestCase { static final long TIMEOUT = 10000; - static final String TEST_DOCUMENT_URI1 = "http://test.document.uri/1"; - static final String TEST_DOCUMENT_URI2 = "http://test.document.uri/2"; + static final String TEST_NAMESPACE1 = "http://test.document.uri/1"; + static final String TEST_NAMESPACE2 = "http://test.document.uri/2"; static final String TEST_ID1 = "id1"; static final String TEST_ID2 = "id2"; + + static final String TEST_OBJECT_URI1 = TEST_NAMESPACE1 + "#" + TEST_ID1; + static final String TEST_OBJECT_URI2 = TEST_NAMESPACE2 + "#" + TEST_ID2; static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_ANNOTATION; static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_RELATIONSHIP; @@ -108,132 +110,114 @@ protected void tearDown() throws Exception { super.tearDown(); } - public void testUpdateNextIds() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - // License ID's - String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals("LicenseRef-gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals("LicenseRef-gnrtd34", nextId); - - // SPDX ID's - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals("SPDXRef-gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, "SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE); - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals("SPDXRef-gnrtd34", nextId); - - // Anonymous ID's - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM); - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd34", nextId); - - // Document ID's - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF); - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); + public void testUpdateNextIds() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + // License ID's + String nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd0", nextId); + store.create(TEST_NAMESPACE1 + "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd34", nextId); + + // SPDX ID's + nextId = store.getNextId(IdType.SpdxId, null); + assertEquals("SPDXRef-gnrtd0", nextId); + store.create("SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE); + nextId = store.getNextId(IdType.SpdxId, null); + assertEquals("SPDXRef-gnrtd34", nextId); + + // Anonymous ID's + nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); + store.create(InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM); + nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd34", nextId); + + // Document ID's + nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + store.create(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF); + nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); + } } - public void testCreateExists() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - String id1 = "TestId1"; - String id2 = "testId2"; - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); + public void testCreateExists() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + assertFalse(store.exists(TEST_OBJECT_URI1)); + assertFalse(store.exists(TEST_OBJECT_URI2)); + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_OBJECT_URI1)); + assertFalse(store.exists(TEST_OBJECT_URI2)); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_OBJECT_URI1)); + assertTrue(store.exists(TEST_OBJECT_URI2)); + } } - public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); - for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { - if (TEST_VALUE_PROPERTY_VALUES[i] instanceof TypedValue) { - TypedValue tv = (TypedValue)TEST_VALUE_PROPERTY_VALUES[i]; - store.create(TEST_DOCUMENT_URI1, tv.getId(), tv.getType()); - } - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); - } - for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { - for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { - if (value instanceof TypedValue) { - TypedValue tv = (TypedValue)value; - store.create(TEST_DOCUMENT_URI1, tv.getId(), tv.getType()); + public void testGetPropertyValueNames() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { + if (TEST_VALUE_PROPERTY_VALUES[i] instanceof TypedValue) { + TypedValue tv = (TypedValue)TEST_VALUE_PROPERTY_VALUES[i]; + store.create(tv.getObjectUri(), tv.getType()); } - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[i], value); + store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); } + for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { + for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { + if (value instanceof TypedValue) { + TypedValue tv = (TypedValue)value; + store.create(tv.getObjectUri(), tv.getType()); + } + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[i], value); + } + } + List result = store.getPropertyValueDescriptors(TEST_OBJECT_URI1); + assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, result.size()); + for (PropertyDescriptor prop:TEST_VALUE_PROPERTIES) { + assertTrue(result.contains(prop)); + } + for (PropertyDescriptor prop:TEST_LIST_PROPERTIES) { + assertTrue(result.contains(prop)); + } + assertEquals(0, store.getPropertyValueDescriptors(TEST_OBJECT_URI2).size()); } - List result = store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1); - assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, result.size()); - for (PropertyDescriptor prop:TEST_VALUE_PROPERTIES) { - assertTrue(result.contains(prop)); - } - for (PropertyDescriptor prop:TEST_LIST_PROPERTIES) { - assertTrue(result.contains(prop)); - } - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); } - public void testGetSetValue() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); - assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[1]); - assertEquals(TEST_VALUE_PROPERTY_VALUES[1], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); + public void testGetSetValue() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_VALUE_PROPERTIES[0]).isPresent()); + store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); + assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[1]); + assertEquals(TEST_VALUE_PROPERTY_VALUES[1], store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_VALUE_PROPERTIES[0]).isPresent()); + } } - public void testGetAddValueList() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - assertTrue(store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); - assertTrue(store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2)); - assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + public void testGetAddValueList() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2)) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + assertTrue(store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1)); + assertTrue(store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2)); + assertEquals(2, toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertTrue(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + } } static List toImmutableList(Iterator listValues) { @@ -242,81 +226,53 @@ static List toImmutableList(Iterator listValues) { .collect(Collectors.toList())); } - public void testGetNextId() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - // License ID's - String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals("LicenseRef-gnrtd0", nextId); - nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals("LicenseRef-gnrtd1", nextId); - - // SPDX ID's - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals("SPDXRef-gnrtd0", nextId); - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals("SPDXRef-gnrtd1", nextId); - - // Anonymous ID's - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd1", nextId); - - // Document ID's - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); + public void testGetNextId() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + // License ID's + String nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd0", nextId); + nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd1", nextId); + + // SPDX ID's + nextId = store.getNextId(IdType.SpdxId, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + "SPDXRef-gnrtd0", nextId); + nextId = store.getNextId(IdType.SpdxId, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + "SPDXRef-gnrtd1", nextId); + + // Anonymous ID's + nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); + nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd1", nextId); + + // Document ID's + nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); + assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); + } } - public void testRemoveProperty() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); + public void testRemoveProperty() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2)) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { + try { + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], e); + } catch (InvalidSPDXAnalysisException e1) { + fail(e1.getMessage()); + } } - } - assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).get()); - assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).get()); - assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).get()); - store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } + assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).get()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + store.removeProperty(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); } } @@ -335,462 +291,463 @@ private void assertCollectionsEquals(Object c1, Object c2) { } } - public void testClearList() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]); - assertEquals(0, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + public void testClearList() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2); + assertEquals(2, toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + store.clearValueCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]); + assertEquals(0, toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).size()); + } } - public void copyFrom() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); - InMemSpdxStore store2 = new InMemSpdxStore(); - ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store2, TEST_DOCUMENT_URI2, store, TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0])); - assertEquals(2, toImmutableList(store2.listValues(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + public void testCopyFrom() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2)) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2); + store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + ModelCopyManager copyManager = new ModelCopyManager(); + copyManager.copy(store2, store, TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, TEST_NAMESPACE1, TEST_NAMESPACE2); + assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); + assertEquals(2, toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); + } } - public void testRemoveListItem() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertTrue(store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); - assertEquals(1, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertFalse(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertFalse("Already removed - should return false",store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); + public void testRemoveListItem() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2); + assertEquals(2, toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).size()); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertTrue(store.removeValueFromCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1)); + assertEquals(1, toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).size()); + assertFalse(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value1)); + assertTrue(toImmutableList(store.listValues(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])).contains(value2)); + assertFalse("Already removed - should return false",store.removeValueFromCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1)); + } } //TODO: Fix the following test - it is flakey. Times out about 1 out of 5 times. Test problem, not a problem with the code under test - public void testLock() throws InvalidSPDXAnalysisException, IOException, InterruptedException, TimeoutException { - final InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - IModelStoreLock lock = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], value1); - lock.unlock(); - assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - /* Expected program flow - * Step1: thread1 run verifies that the property is still value1 - * thread1 starts a read transaction - * thread1 waits for step2 - * thread2 run verifies that the property is still value1 - * Step2: thread2 wakes up thread 1 - * Step3: thread1 wakes up thread 2 - * thread2 starts a write transaction - * thread2 is expected to block on the write transaction until thread1 finishes the read/verify - * step4: thread2 completes the write transaction, both threads verify value updated - */ - final Waiter waiter = new Waiter(); - @SuppressWarnings("unused") - final Thread thread1 = new Thread(null, null, "Thread1") { - @Override - public void run() { - try { - logger.info("thread1 started"); - logger.info("Waking up main thread"); - waiter.assertEquals("step0", setTestState("step1")); - waiter.resume(); // release the main thread - logger.info("Woke up main thread"); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - IModelStoreLock transactionLock = store.enterCriticalSection(TEST_DOCUMENT_URI1, true); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - int retries = 0; - while (!getTestState().equals("step2") && retries < MAX_RETRIES) { - logger.info("Thread 1 waiting for thread 2"); - waiter.await(TIMEOUT); // wait for thread 2 - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Thread1 awoke from thread 2"); - waiter.assertEquals("step2", setTestState("step3")); - logger.info("Waking up thread2"); - waiter.resume(); // wake thread 2 back up - logger.info("Woke up thread2"); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - transactionLock.unlock(); - retries = 0; - while (!getTestState().equals("step4") && retries < MAX_RETRIES) { - logger.info("Thread 1 waiting for thread 2"); - waiter.await(TIMEOUT); // wait for thread 2 to commit - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Thread1 awoke from thread 2"); - waiter.assertEquals("step4", getTestState()); - waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - } catch (Exception e) { - waiter.fail("Unexpected exception: "+e.getMessage()); - } + public void testLock() throws Exception { + try (final InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + String value1 = "value1"; + @SuppressWarnings("unused") + String value2 = "value2"; + IModelStoreLock lock = store.enterCriticalSection(false); + store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], value1); + lock.unlock(); + assertEquals(value1, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + /* Expected program flow + * Step1: thread1 run verifies that the property is still value1 + * thread1 starts a read transaction + * thread1 waits for step2 + * thread2 run verifies that the property is still value1 + * Step2: thread2 wakes up thread 1 + * Step3: thread1 wakes up thread 2 + * thread2 starts a write transaction + * thread2 is expected to block on the write transaction until thread1 finishes the read/verify + * step4: thread2 completes the write transaction, both threads verify value updated + */ + final Waiter waiter = new Waiter(); + @SuppressWarnings("unused") + final Thread thread1 = new Thread(null, null, "Thread1") { + @Override + public void run() { + try { + logger.info("thread1 started"); + logger.info("Waking up main thread"); + waiter.assertEquals("step0", setTestState("step1")); + waiter.resume(); // release the main thread + logger.info("Woke up main thread"); + waiter.assertEquals(value1, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + IModelStoreLock transactionLock = store.enterCriticalSection(true); + waiter.assertEquals(value1, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + int retries = 0; + while (!getTestState().equals("step2") && retries < MAX_RETRIES) { + logger.info("Thread 1 waiting for thread 2"); + waiter.await(TIMEOUT); // wait for thread 2 + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Thread1 awoke from thread 2"); + waiter.assertEquals("step2", setTestState("step3")); + logger.info("Waking up thread2"); + waiter.resume(); // wake thread 2 back up + logger.info("Woke up thread2"); + waiter.assertEquals(value1, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + transactionLock.unlock(); + retries = 0; + while (!getTestState().equals("step4") && retries < MAX_RETRIES) { + logger.info("Thread 1 waiting for thread 2"); + waiter.await(TIMEOUT); // wait for thread 2 to commit + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Thread1 awoke from thread 2"); + waiter.assertEquals("step4", getTestState()); + waiter.assertEquals(value2, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + } catch (Exception e) { + waiter.fail("Unexpected exception: "+e.getMessage()); + } + } + }; + + @SuppressWarnings("unused") + final Thread thread2 = new Thread(null ,null, "thread2") { + @Override + public void run() { + try { + waiter.assertEquals("step1", getTestState()); + waiter.assertEquals(value1, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + waiter.assertEquals("step1",setTestState("step2")); + logger.info("Waking up Thread1"); + waiter.resume(); // wakeup thread1 + logger.info("Woke up Thread1"); + int retries = 0; + while (!getTestState().equals("step3") && retries < MAX_RETRIES) { + logger.info("Thread 2 waiting for thread 1"); + waiter.await(TIMEOUT); // wait for thread 1 + } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); + } + logger.info("Thread2 awoke from thread 1"); + waiter.assertEquals("step3", getTestState()); + IModelStoreLock transactionLock2 = store.enterCriticalSection(false); // this should block waiting for thread1 transaction to complete + waiter.assertEquals(value1, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], value2); + waiter.assertEquals(value2, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + transactionLock2.unlock(); + waiter.assertEquals("step3",setTestState("step4")); + logger.info("Waking up Thread1"); + waiter.resume(); // wakeup thread1 + logger.info("Woke up Thread1"); + waiter.assertEquals(value2, store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).get()); + } catch (Exception e) { + waiter.fail("Unexpected exception: "+e.getMessage()); + } + } + }; + /* + setTestState("step0"); + logger.info("Starting Thread1"); + thread1.start(); + int retries = 0; + while (getTestState().equals("step0")) { + logger.info("Waiting for Thread1"); + waiter.await(TIMEOUT); // wait for thread 1 to get going } - }; - - @SuppressWarnings("unused") - final Thread thread2 = new Thread(null ,null, "thread2") { - @Override - public void run() { - try { - waiter.assertEquals("step1", getTestState()); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - waiter.assertEquals("step1",setTestState("step2")); - logger.info("Waking up Thread1"); - waiter.resume(); // wakeup thread1 - logger.info("Woke up Thread1"); - int retries = 0; - while (!getTestState().equals("step3") && retries < MAX_RETRIES) { - logger.info("Thread 2 waiting for thread 1"); - waiter.await(TIMEOUT); // wait for thread 1 - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Thread2 awoke from thread 1"); - waiter.assertEquals("step3", getTestState()); - IModelStoreLock transactionLock2 = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); // this should block waiting for thread1 transaction to complete - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], value2); - waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - transactionLock2.unlock(); - waiter.assertEquals("step3",setTestState("step4")); - logger.info("Waking up Thread1"); - waiter.resume(); // wakeup thread1 - logger.info("Woke up Thread1"); - waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - } catch (Exception e) { - waiter.fail("Unexpected exception: "+e.getMessage()); - } + if (retries >= MAX_RETRIES) { + waiter.fail("State never changed"); } - }; - /* - setTestState("step0"); - logger.info("Starting Thread1"); - thread1.start(); - int retries = 0; - while (getTestState().equals("step0")) { - logger.info("Waiting for Thread1"); - waiter.await(TIMEOUT); // wait for thread 1 to get going - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); + logger.info("Starting Thread2"); + thread2.start(); + logger.info("Joining thread1"); + thread1.join(); + logger.info("Joining thread2"); + thread2.join(); + assertEquals("step4", getTestState()); + */ } - logger.info("Starting Thread2"); - thread2.start(); - logger.info("Joining thread1"); - thread1.join(); - logger.info("Joining thread2"); - thread2.join(); - assertEquals("step4", getTestState()); - */ } - public void testCollectionSize() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertEquals(2, store.collectionSize(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])); - assertEquals(0, store.collectionSize(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[1])); + public void testCollectionSize() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2); + assertEquals(2, store.collectionSize(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0])); + assertEquals(0, store.collectionSize(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[1])); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + } } - public void testCollectionContains() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertTrue(store.collectionContains(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0],value1)); - assertTrue(store.collectionContains(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0],value2)); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); + public void testCollectionContains() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + String value1 = "value1"; + String value2 = "value2"; + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); + store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2); + assertTrue(store.collectionContains(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0],value1)); + assertTrue(store.collectionContains(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0],value2)); + assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); + } } - public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { + public void testIsPropertyValueAssignableTo() throws Exception { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); - // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); - assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); - // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - TypedValue tv = new TypedValue(TEST_ID2, TEST_TYPE2); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, String.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); - assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); - // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); + try(InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + // String + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.setValue(TEST_OBJECT_URI1, sProperty, "String 1"); + assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, String.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, Boolean.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, TypedValue.class)); + // Boolean + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.setValue(TEST_OBJECT_URI1, bProperty, Boolean.valueOf(true)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, String.class)); + assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, Boolean.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, TypedValue.class)); + // TypedValue + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + TypedValue tv = new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2); + store.create(TEST_OBJECT_URI2, TEST_TYPE2); + store.setValue(TEST_OBJECT_URI1, tvProperty, tv); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, String.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, Boolean.class)); + assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, TypedValue.class)); + // Empty + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, emptyProperty, String.class)); + } } - public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 2"); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); - // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(false)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); - // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - TypedValue tv = new TypedValue(TEST_ID2, TEST_TYPE2); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, String.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); - // Mixed - PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.valueOf(true)); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, "mixed value"); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, String.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, TypedValue.class)); - // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, Boolean.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, TypedValue.class)); + public void testCollectionMembersAssignableTo() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + // String + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_OBJECT_URI1, sProperty, "String 1"); + store.addValueToCollection(TEST_OBJECT_URI1, sProperty, "String 2"); + assertTrue(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, sProperty, String.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, sProperty, Boolean.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, sProperty, TypedValue.class)); + // Boolean + PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_OBJECT_URI1, bProperty, Boolean.valueOf(true)); + store.addValueToCollection(TEST_OBJECT_URI1, bProperty, Boolean.valueOf(false)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, bProperty, String.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, bProperty, Boolean.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, bProperty, TypedValue.class)); + // TypedValue + PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + TypedValue tv = new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2); + store.create(TEST_OBJECT_URI2, TEST_TYPE2); + store.addValueToCollection(TEST_OBJECT_URI1, tvProperty, tv); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, tvProperty, String.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, tvProperty, Boolean.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, tvProperty, TypedValue.class)); + // Mixed + PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_OBJECT_URI1, mixedProperty, Boolean.valueOf(true)); + store.addValueToCollection(TEST_OBJECT_URI1, mixedProperty, "mixed value"); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, mixedProperty, String.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, mixedProperty, Boolean.class)); + assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, mixedProperty, TypedValue.class)); + // Empty + PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + assertTrue(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, emptyProperty, String.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, emptyProperty, Boolean.class)); + assertTrue(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, emptyProperty, TypedValue.class)); + } } - public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, listProperty, "testValue"); - assertTrue(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, listProperty)); - assertFalse(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, sProperty)); + public void testIsCollectionProperty() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + // String + PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.setValue(TEST_OBJECT_URI1, sProperty, "String 1"); + PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstantsCompatV2.SPDX_NAMESPACE); + store.addValueToCollection(TEST_OBJECT_URI1, listProperty, "testValue"); + assertTrue(store.isCollectionProperty(TEST_OBJECT_URI1, listProperty)); + assertFalse(store.isCollectionProperty(TEST_OBJECT_URI1, sProperty)); + } } - public void testIdType() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - assertEquals(IdType.Anonymous, store.getIdType(InMemSpdxStore.ANON_PREFIX+"gnrtd23")); - assertEquals(IdType.DocumentRef, store.getIdType(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"gnrtd23")); - assertEquals(IdType.LicenseRef, store.getIdType(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"gnrtd23")); - assertEquals(IdType.ListedLicense, store.getIdType("Apache-2.0")); - assertEquals(IdType.ListedLicense, store.getIdType("LLVM-exception")); - assertEquals(IdType.Literal, store.getIdType("NONE")); - assertEquals(IdType.Literal, store.getIdType("NOASSERTION")); - assertEquals(IdType.SpdxId, store.getIdType(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); + public void testIdType() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + assertEquals(IdType.Anonymous, store.getIdType(InMemSpdxStore.ANON_PREFIX+"gnrtd23")); + assertEquals(IdType.DocumentRef, store.getIdType(TEST_NAMESPACE1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"gnrtd23")); + assertEquals(IdType.LicenseRef, store.getIdType(TEST_NAMESPACE1 + "#" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"gnrtd23")); + assertEquals(IdType.ListedLicense, store.getIdType("Apache-2.0")); + assertEquals(IdType.ListedLicense, store.getIdType("http://spdx.org/licenses/Apache-2.0")); + assertEquals(IdType.ListedLicense, store.getIdType("LLVM-exception")); + assertEquals(IdType.Literal, store.getIdType("NONE")); + assertEquals(IdType.Literal, store.getIdType("NOASSERTION")); + assertEquals(IdType.SpdxId, store.getIdType(TEST_NAMESPACE1 + "#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); + } } - public void testGetCaseSensisitiveId() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - String expected = "TestIdOne"; - String lower = expected.toLowerCase(); - store.create(TEST_DOCUMENT_URI1, expected, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(expected, store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, lower).get()); - assertFalse(store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, "somethingNotThere").isPresent()); - try { - store.create(TEST_DOCUMENT_URI1, lower, SpdxConstantsCompatV2.CLASS_ANNOTATION); - fail("This should be a duplicate ID failure"); - } catch (InvalidSPDXAnalysisException e) { - // expected + public void testGetCaseSensisitiveId() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + String expected = "TestIdOne"; + String lower = expected.toLowerCase(); + store.create(TEST_NAMESPACE1 + "#" + expected, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertEquals(expected, store.getCaseSensisitiveId(TEST_NAMESPACE1, lower).get()); + assertFalse(store.getCaseSensisitiveId(TEST_NAMESPACE1, "somethingNotThere").isPresent()); + try { + store.create(TEST_NAMESPACE1 + "#" + lower, SpdxConstantsCompatV2.CLASS_ANNOTATION); + fail("This should be a duplicate ID failure"); + } catch (InvalidSPDXAnalysisException e) { + // expected + } } } - public void testGetTypedValue() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(SpdxConstantsCompatV2.CLASS_ANNOTATION, store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID1).get().getType()); - assertFalse(store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID2).isPresent()); - assertFalse(store.getTypedValue(TEST_DOCUMENT_URI2, TEST_ID1).isPresent()); + public void testGetTypedValue() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + assertEquals(SpdxConstantsCompatV2.CLASS_ANNOTATION, store.getTypedValue(TEST_OBJECT_URI1).get().getType()); + assertFalse(store.getTypedValue(TEST_OBJECT_URI2).isPresent()); + } } - public void testDelete() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - String id1 = "TestId1"; - String id2 = "testId2"; - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - - store.delete(TEST_DOCUMENT_URI1, id1); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); + public void testDelete() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + assertFalse(store.exists(TEST_OBJECT_URI1)); + assertFalse(store.exists(TEST_OBJECT_URI2)); + store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + assertTrue(store.exists(TEST_OBJECT_URI1)); + assertTrue(store.exists(TEST_OBJECT_URI2)); + + store.delete(TEST_OBJECT_URI1); + assertFalse(store.exists(TEST_OBJECT_URI1)); + assertTrue(store.exists(TEST_OBJECT_URI2)); + } } - public void testDeleteInUse() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); - String id1 = "TestId1"; - String id2 = "testId2"; - String id3 = "testId3"; - String id4 = "testId4"; - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - TypedValue tv3 = new TypedValue(id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.addValueToCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv3); - TypedValue tv4 = new TypedValue(id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.addValueToCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); - store.setValue(TEST_DOCUMENT_URI1, id3, - new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new TypedValue(id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); - - try { - store.delete(TEST_DOCUMENT_URI1, id3); - fail("id3 is in the listProperty for id2"); - } catch (SpdxIdInUseException ex) { - // expected - id3 is in the listProperty for id2 - } - try { - store.delete(TEST_DOCUMENT_URI1, id4); - fail("id4 is in the listProperty for id2"); - } catch (SpdxIdInUseException ex) { - // expected - id4 is in the listProperty for id2 - } - try { - store.delete(TEST_DOCUMENT_URI1, id1); - fail("id1 is in the property for id3"); - } catch (SpdxIdInUseException ex) { - // expected - id1 is in the property for id3 - } - store.removeValueFromCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); - store.delete(TEST_DOCUMENT_URI1, id4); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id4)); - try { - store.delete(TEST_DOCUMENT_URI1, id3); - fail("id3 is in the listProperty for id2"); - } catch (SpdxIdInUseException ex) { - // expected - id3 is in the listProperty for id2 + public void testDeleteInUse() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + String id1 = "TestId1"; + String id2 = "testId2"; + String id3 = "testId3"; + String id4 = "testId4"; + store.create(TEST_NAMESPACE1 + "#" + id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_NAMESPACE1 + "#" + id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_NAMESPACE1 + "#" + id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(TEST_NAMESPACE1 + "#" + id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + TypedValue tv3 = new TypedValue(TEST_NAMESPACE1 + "#" + id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.addValueToCollection(TEST_NAMESPACE1 + "#" + id2, + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv3); + TypedValue tv4 = new TypedValue(TEST_NAMESPACE1 + "#" + id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.addValueToCollection(TEST_NAMESPACE1 + "#" + id2, + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); + store.setValue(TEST_NAMESPACE1 + "#" + id3, + new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE), + new TypedValue(TEST_NAMESPACE1 + "#" + id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); + + try { + store.delete(TEST_NAMESPACE1 + "#" + id3); + fail("id3 is in the listProperty for id2"); + } catch (SpdxIdInUseException ex) { + // expected - id3 is in the listProperty for id2 + } + try { + store.delete(TEST_NAMESPACE1 + "#" + id4); + fail("id4 is in the listProperty for id2"); + } catch (SpdxIdInUseException ex) { + // expected - id4 is in the listProperty for id2 + } + try { + store.delete(TEST_NAMESPACE1 + "#" + id1); + fail("id1 is in the property for id3"); + } catch (SpdxIdInUseException ex) { + // expected - id1 is in the property for id3 + } + store.removeValueFromCollection(TEST_NAMESPACE1 + "#" + id2, + new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); + store.delete(TEST_NAMESPACE1 + "#" + id4); + assertFalse(store.exists(TEST_NAMESPACE1 + "#" + id4)); + try { + store.delete(TEST_NAMESPACE1 + "#" + id3); + fail("id3 is in the listProperty for id2"); + } catch (SpdxIdInUseException ex) { + // expected - id3 is in the listProperty for id2 + } + store.removeProperty(TEST_NAMESPACE1 + "#" + id3, + new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + store.delete(TEST_OBJECT_URI1); + assertFalse(store.exists(TEST_OBJECT_URI1)); + store.delete(TEST_NAMESPACE1 + "#" + id2); + assertFalse(store.exists(TEST_NAMESPACE1 + "#" + id2)); + store.delete(TEST_NAMESPACE1 + "#" + id3); + assertFalse(store.exists(TEST_NAMESPACE1 + "#" + id3)); } - store.removeProperty(TEST_DOCUMENT_URI1, id3, - new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE)); - store.delete(TEST_DOCUMENT_URI1, id1); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - store.delete(TEST_DOCUMENT_URI1, id2); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - store.delete(TEST_DOCUMENT_URI1, id3); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id3)); } public void testReferenceCounts() throws Exception { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, TEST_TYPE1); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); - StoredTypedItem item = store.getItem(TEST_DOCUMENT_URI1, TEST_ID1); - assertEquals(0, item.getReferenceCount()); - TypedValue tv = new TypedValue(TEST_ID1, TEST_TYPE1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); - assertEquals(1, item.getReferenceCount()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); - assertEquals(2, item.getReferenceCount()); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop3", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); - assertEquals(3, item.getReferenceCount()); - store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE)); - assertEquals(2, item.getReferenceCount()); - store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); - assertEquals(1, item.getReferenceCount()); - store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID2, - new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE)); - assertEquals(0, item.getReferenceCount()); - store.delete(TEST_DOCUMENT_URI1, TEST_ID1); - } - - public void testReferenceCountsDelete() throws Exception { - InMemSpdxStore store = new InMemSpdxStore(); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, TEST_TYPE1); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); - StoredTypedItem item = store.getItem(TEST_DOCUMENT_URI1, TEST_ID1); + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, TEST_TYPE1); + store.create(TEST_NAMESPACE1 + "#" + TEST_ID2, TEST_TYPE2); + StoredTypedItem item = store.getItem(TEST_OBJECT_URI1); assertEquals(0, item.getReferenceCount()); - TypedValue tv = new TypedValue(TEST_ID1, TEST_TYPE1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, + TypedValue tv = new TypedValue(TEST_OBJECT_URI1, TEST_TYPE1); + store.addValueToCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID2, + store.setValue(TEST_NAMESPACE1 + "#" + TEST_ID2, new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(2, item.getReferenceCount()); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, + store.addValueToCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, new PropertyDescriptor("prop3", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(3, item.getReferenceCount()); - store.delete(TEST_DOCUMENT_URI1, TEST_ID2); + store.removeProperty(TEST_NAMESPACE1 + "#" + TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + assertEquals(2, item.getReferenceCount()); + store.removeValueFromCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); + assertEquals(1, item.getReferenceCount()); + store.clearValueCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, + new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE)); assertEquals(0, item.getReferenceCount()); - store.delete(TEST_DOCUMENT_URI1, TEST_ID1); + store.delete(TEST_OBJECT_URI1); + } + } + + public void testReferenceCountsDelete() throws Exception { + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(TEST_OBJECT_URI1, TEST_TYPE1); + store.create(TEST_NAMESPACE1 + "#" + TEST_ID2, TEST_TYPE2); + StoredTypedItem item = store.getItem(TEST_OBJECT_URI1); + assertEquals(0, item.getReferenceCount()); + TypedValue tv = new TypedValue(TEST_NAMESPACE1 + "#" + TEST_ID1, TEST_TYPE1); + store.addValueToCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, + new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); + assertEquals(1, item.getReferenceCount()); + store.setValue(TEST_NAMESPACE1 + "#" + TEST_ID2, + new PropertyDescriptor("prop2", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); + assertEquals(2, item.getReferenceCount()); + store.addValueToCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, + new PropertyDescriptor("prop3", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); + assertEquals(3, item.getReferenceCount()); + store.delete(TEST_NAMESPACE1 + "#" + TEST_ID2); + assertEquals(0, item.getReferenceCount()); + store.delete(TEST_OBJECT_URI1); + } } } diff --git a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java index 446973048..bf329fe74 100644 --- a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java +++ b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java @@ -21,6 +21,7 @@ import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.Relationship; @@ -38,8 +39,10 @@ public class StoredTypedItemTest extends TestCase { static final String TEST_ID2 = "TestID2"; static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_ANNOTATION; static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_RELATIONSHIP; - static final String TEST_DOCUMENTURI1 = "https://test.doc.uri1"; - static final String TEST_DOCUMENTURI2 = "https://test.doc.uri2"; + static final String TEST_NAMESPACE1 = "https://test.doc.uri1"; + static final String TEST_NAMESPACE2 = "https://test.doc.uri2"; + static final String TEST_OBJECT_URI1 = TEST_NAMESPACE1 + "#" + TEST_ID1; + static final String TEST_OBJECT_URI2 = TEST_NAMESPACE2 + "#" + TEST_ID2; static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { new PropertyDescriptor("valueProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), new PropertyDescriptor("valueProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), @@ -73,14 +76,14 @@ protected void tearDown() throws Exception { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#equals(java.lang.Object)}. */ public void testEqualsObject() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); - StoredTypedItem sti2 = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti2 = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); assertTrue(sti.equals(sti2)); assertTrue(sti2.equals(sti2)); - StoredTypedItem sti3 = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID2, TEST_TYPE1); + StoredTypedItem sti3 = new StoredTypedItem(TEST_OBJECT_URI2, TEST_TYPE1); assertFalse(sti.equals(sti3)); assertFalse(sti3.equals(sti)); - StoredTypedItem sti4 = new StoredTypedItem(TEST_DOCUMENTURI2, TEST_ID1, TEST_TYPE2); + StoredTypedItem sti4 = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE2); assertFalse(sti.equals(sti4)); assertFalse(sti4.equals(sti)); } @@ -89,7 +92,7 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#getPropertyValueNames(java.lang.String, java.lang.String)}. */ public void testGetSetPropertyValueNames() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); assertEquals(0, sti.getPropertyValueDescriptors().size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { sti.setValue(TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); @@ -113,7 +116,7 @@ public void testGetSetPropertyValueNames() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#setValue(java.lang.String, java.lang.Object)}. */ public void testGetSetValue() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); Object result = sti.getValue(TEST_VALUE_PROPERTIES[0]); assertTrue(result == null); sti.setValue(TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); @@ -126,7 +129,7 @@ public void testGetSetValue() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#clearPropertyValueList(java.lang.String)}. */ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -142,7 +145,7 @@ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#addValueToList(java.lang.String, java.lang.Object)}. */ public void testAddValueToList() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -159,7 +162,7 @@ public void testAddValueToList() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#getValueList(java.lang.String)}. */ public void testGetValueList() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -172,7 +175,7 @@ public void testGetValueList() throws InvalidSPDXAnalysisException { } public void testRemove() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); assertEquals(0, sti.getPropertyValueDescriptors().size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { sti.setValue(TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); @@ -191,7 +194,7 @@ public void testRemove() throws InvalidSPDXAnalysisException { } public void testCollectionSize() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -203,7 +206,7 @@ public void testCollectionSize() throws InvalidSPDXAnalysisException { } public void testCollectionContains() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -218,7 +221,7 @@ public void testCollectionContains() throws InvalidSPDXAnalysisException { } public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(sProperty, "String 1"); @@ -238,7 +241,7 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio sti.addValueToList(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, Boolean.class)); - assertTrue(sti.isCollectionMembersAssignableTo(tvProperty, Relationship.class)); + assertTrue(sti.isCollectionMembersAssignableTo(tvProperty, Relationship.class, SpdxMajorVersion.VERSION_2)); // Mixed PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(mixedProperty, Boolean.valueOf(true)); @@ -254,7 +257,7 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio } public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); @@ -279,7 +282,7 @@ public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisExcept } public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_DOCUMENTURI1, TEST_ID1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); diff --git a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java index 2840957f6..a82a731d9 100644 --- a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java +++ b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java @@ -31,6 +31,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -86,13 +87,14 @@ public class LicenseCompareHelperTest extends TestCase { * @throws java.lang.Exception */ public void setUp() throws Exception { + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /** * @throws java.lang.Exception */ public void tearDown() throws Exception { - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index 9b63fe261..6dcc5b31e 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -34,6 +34,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalDocumentRef; @@ -235,7 +236,7 @@ public class SpdxComparerTest extends TestCase { */ public void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); GenericModelObject gmo = new GenericModelObject(); DATALICENSE = LicenseInfoFactory.parseSPDXLicenseString(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID); @@ -539,6 +540,8 @@ public void setUp() throws Exception { * @throws java.lang.Exception */ public void tearDown() throws Exception { + super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } private SpdxDocument createTestSpdxDoc(String docUri) throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java index fabccc7fe..5b52d7972 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java @@ -27,6 +27,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxFile; @@ -58,7 +59,7 @@ public class SpdxFileComparerTest extends TestCase { * @throws java.lang.Exception */ public void setUp() throws Exception { - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); this.testRDFFile = new File(TEST_RDF_FILE_PATH); String uri1 = "http://doc/uri1"; DOCA = new SpdxDocument(DefaultModelStore.getDefaultModelStore(), uri1, DefaultModelStore.getDefaultCopyManager(), true); @@ -75,6 +76,8 @@ public void setUp() throws Exception { * @throws java.lang.Exception */ public void tearDown() throws Exception { + super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java index e79940c99..cf3f6bd6a 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java @@ -23,6 +23,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.GenericSpdxElement; @@ -113,7 +114,7 @@ public class SpdxItemComparerTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); GenericModelObject gmo = new GenericModelObject(); LICENSEA1 = new ExtractedLicenseInfo("LicenseRef-1", "License1"); LICENSEA2 = new ExtractedLicenseInfo("LicenseRef-2", "License2"); @@ -175,6 +176,7 @@ protected void setUp() throws Exception { */ protected void tearDown() throws Exception { super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testCompare() throws SpdxCompareException, InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java index eeea55a4a..5cacdd423 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java @@ -26,6 +26,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.ExternalRef; @@ -198,7 +199,7 @@ public static void tearDownAfterClass() throws Exception { */ public void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); GenericModelObject gmo = new GenericModelObject(); LICENSEA1 = new ExtractedLicenseInfo("LicenseRef-1", "License1"); LICENSEA2 = new ExtractedLicenseInfo("LicenseRef-2", "License2"); @@ -334,6 +335,8 @@ public void setUp() throws Exception { * @throws java.lang.Exception */ public void tearDown() throws Exception { + super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } /** diff --git a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java index 2885581a5..f3865094f 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java @@ -24,6 +24,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.Relationship; @@ -114,7 +115,7 @@ public class SpdxSnippetComparerTest extends TestCase { * @throws java.lang.Exception */ public void setUp() throws Exception { - DefaultModelStore.reset(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); GenericModelObject gmo = new GenericModelObject(); CHECKSUM1 = gmo.createChecksum(ChecksumAlgorithm.SHA1, "111bf72bf99b7e471f1a27989667a903658652bb"); @@ -162,6 +163,8 @@ public void setUp() throws Exception { * @throws java.lang.Exception */ public void tearDown() throws Exception { + super.tearDown(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); } public void testNoDifference() throws InvalidSPDXAnalysisException, SpdxCompareException { diff --git a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java index b2c25efb9..b1874588c 100644 --- a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java +++ b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java @@ -33,6 +33,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * Helper class for unit tests @@ -189,8 +190,9 @@ public static boolean isListsEquivalent(List expected, Li public static void copyObjectsToDoc(SpdxDocument doc, Collection modelObjects) throws InvalidSPDXAnalysisException { for (ModelObject mo:modelObjects) { - doc.getCopyManager().copy(doc.getModelStore(), doc.getDocumentUri(), mo.getModelStore(), - mo.getDocumentUri(), mo.getId(), mo.getType()); + doc.getCopyManager().copy(doc.getModelStore(), mo.getModelStore(), + CompatibleModelStoreWrapper.documentUriIdToUri(mo.getDocumentUri(), mo.getId(), mo.getModelStore()), + mo.getType(), mo.getDocumentUri(), doc.getDocumentUri()); } } diff --git a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java index c09520383..9e777e974 100644 --- a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java +++ b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java @@ -7,6 +7,7 @@ import java.util.Collection; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; @@ -48,7 +49,7 @@ public class VerificationCodeGeneratorTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - modelStore = new InMemSpdxStore(); + modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SPDX_FILES = new SpdxFile[SPDX_FILE_NAMES.length]; for (int i = 0; i < SPDX_FILES.length; i++) { SPDX_FILES[i] = new SpdxFile(modelStore, DOCUMENT_URI, modelStore.getNextId(IdType.Anonymous, DOCUMENT_URI), null, true); From 20c1b17fbae9970b8a32bac0c4752243a422e8cf Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 14 Jun 2023 12:43:29 -0700 Subject: [PATCH 05/62] Intermediate checkin Signed-off-by: Gary O'Neall --- .../spdx/library/SpdxVerificationHelper.java | 16 +++-- .../model/compat/v2/ExternalDocumentRef.java | 16 +++-- .../model/compat/v2/ModelCollection.java | 47 +++++++------ .../library/model/compat/v2/ModelObject.java | 70 +++++++++++-------- .../library/model/compat/v2/ModelSet.java | 4 +- .../compat/v2/ModelStorageClassConverter.java | 17 ++++- .../compat/v2/RelatedElementCollection.java | 2 +- .../v2/license/LicenseExpressionParser.java | 17 +++-- .../v2/license/SimpleLicensingInfo.java | 2 +- .../compat/v2/license/SpdxListedLicense.java | 6 +- .../java/org/spdx/storage/IModelStore.java | 4 +- .../v2/CompatibleModelStoreWrapper.java | 7 ++ .../spdx/storage/simple/InMemSpdxStore.java | 2 +- .../model/compat/v2/ModelObjectTest.java | 6 +- .../v2/license/ConjunctiveLicenseSetTest.java | 3 +- .../v2/license/DisjunctiveLiceseSetTest.java | 3 +- .../license/LicenseExpressionParserTest.java | 2 +- .../compat/v2/license/ListedLicensesTest.java | 7 +- .../SpdxListedLicenseLocalStoreTest.java | 3 +- .../SpdxListedLicenseWebStoreTest.java | 3 +- 20 files changed, 141 insertions(+), 96 deletions(-) diff --git a/src/main/java/org/spdx/library/SpdxVerificationHelper.java b/src/main/java/org/spdx/library/SpdxVerificationHelper.java index 7abcdf014..1e68206a7 100644 --- a/src/main/java/org/spdx/library/SpdxVerificationHelper.java +++ b/src/main/java/org/spdx/library/SpdxVerificationHelper.java @@ -75,13 +75,15 @@ public class SpdxVerificationHelper { static final String[] VALID_CREATOR_PREFIXES = new String[] {SpdxConstantsCompatV2.CREATOR_PREFIX_PERSON, SpdxConstantsCompatV2.CREATOR_PREFIX_ORGANIZATION, SpdxConstantsCompatV2.CREATOR_PREFIX_TOOL}; static final String[] VALID_ORIGINATOR_SUPPLIER_PREFIXES = new String[] {SpdxConstantsCompatV2.NOASSERTION_VALUE, "Person:", "Organization:"}; - private static final Pattern SPDX_ELEMENT_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$"); + static final Pattern SPDX_ELEMENT_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$"); + static final Pattern LICENSE_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"([0-9a-zA-Z\\.\\-\\_]+)\\+?$"); + static final Pattern EXTERNAL_DOC_REF_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$");; - public static String verifyNonStdLicenseid(String licenseId) { - if (SpdxConstantsCompatV2.LICENSE_ID_PATTERN.matcher(licenseId).matches()) { + public static String verifyNonStdLicenseid(String licenseUri) { + if (LICENSE_ID_PATTERN.matcher(licenseUri).matches()) { return null; } else { - return "Invalid license objectUri '"+licenseId+"'. Must start with 'LicenseRef-' " + + return "Invalid license objectUri '"+licenseUri+"'. Must start with 'LicenseRef-' " + "and made up of the characters from the set 'a'-'z', 'A'-'Z', '0'-'9', '+', '_', '.', and '-'."; } } @@ -248,7 +250,7 @@ public static String verifyAnnotator(String annotator) { * @return */ public static boolean isValidExternalDocRef(String externalDocumentId) { - return SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.matcher(externalDocumentId).matches(); + return EXTERNAL_DOC_REF_PATTERN.matcher(externalDocumentId).matches(); } public static boolean isValidUri(String uri) { @@ -300,7 +302,7 @@ public static String verifyDownloadLocation(String downloadLocation) { * @param objectUri * @return true if the ID is a valid SPDX ID reference */ - public static boolean verifySpdxId(String id) { - return SPDX_ELEMENT_ID_PATTERN.matcher(id).matches(); + public static boolean verifySpdxId(String objectUri) { + return SPDX_ELEMENT_ID_PATTERN.matcher(objectUri).matches(); } } diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index a40c9dc2a..9d60c67c1 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -40,6 +40,7 @@ import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * Information about an external SPDX document reference including the checksum. @@ -82,7 +83,7 @@ public static Optional getExternalDocRefByDocNamespace(IMod // if we got here, we didn't find an existing one, need to create one if (Objects.nonNull(copyManager)) { ExternalDocumentRef retval = new ExternalDocumentRef(stModelStore, stDocumentUri, - stModelStore.getNextId(IdType.DocumentRef, stDocumentUri), copyManager, true); + stModelStore.getNextId(IdType.DocumentRef, stDocumentUri + "#"), copyManager, true); retval.setSpdxDocumentNamespace(externalDocUri); ModelObject.addValueToCollection(stModelStore, stDocumentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, retval, copyManager); @@ -118,17 +119,17 @@ public ExternalDocumentRef(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param objectUri ID for this object - must be unique within the SPDX document + * @param objectUri URI for the object - must be unique within the SPDX store * @param copyManager - if supplied, model objects will be implicitly copied into this model store and document URI when referenced by setting methods * @param create - if true, the object will be created in the store if it is not already present * @throws InvalidSPDXAnalysisException */ - public ExternalDocumentRef(IModelStore modelStore, String documentUri, String id, + public ExternalDocumentRef(IModelStore modelStore, String documentUri, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - if (!SpdxVerificationHelper.isValidExternalDocRef(id)) { - logger.warn("Invalid external document reference ID "+id+ + super(modelStore, documentUri, objectUri, copyManager, create); + if (!SpdxVerificationHelper.isValidExternalDocRef(objectUri)) { + logger.warn("Invalid external document reference ID "+objectUri+ ". Must be of the format "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.pattern()); } } @@ -256,7 +257,8 @@ public Optional getSpdxDocument() throws InvalidSPDXAnalysisExcept if (docNamespace.isEmpty()) { return Optional.empty(); } - if (this.getModelStore().exists(docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID)) { + if (this.getModelStore().exists( + CompatibleModelStoreWrapper.documentUriIdToUri(docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false))) { return (Optional)(Optional)Optional.of(SpdxModelFactory.createModelObject( getModelStore(), docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, getCopyManager())); diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java index 99bf9a31d..27847efcf 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java @@ -51,7 +51,7 @@ */ public class ModelCollection implements Collection { - private CompatibleModelStoreWrapper modelStore; + private IModelStore modelStore; private String documentUri; private String id; private PropertyDescriptor propertyDescriptor; @@ -88,18 +88,11 @@ public Object next() { * @param type The class of the elements to be stored in the collection if none, null if not known * @throws InvalidSPDXAnalysisException */ - public ModelCollection(IModelStore baseStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, + public ModelCollection(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(baseStore, "Model store can not be null"); - if (baseStore instanceof CompatibleModelStoreWrapper) { - this.modelStore = (CompatibleModelStoreWrapper)baseStore; - } else { - // we need to wrap the model store for compatibility. Note - we don't want to - // wrap already wrapped model stores as it will force copies to be made into the same - // base model store - this.modelStore = new CompatibleModelStoreWrapper(baseStore); - } + Objects.requireNonNull(modelStore, "Model store can not be null"); + this.modelStore = modelStore; Objects.requireNonNull(documentUri, "Document URI can not be null"); this.documentUri = documentUri; Objects.requireNonNull(id, "ID can not be null"); @@ -107,13 +100,14 @@ public ModelCollection(IModelStore baseStore, String documentUri, String id, Pro Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); this.propertyDescriptor = propertyDescriptor; this.copyManager = copyManager; - if (!modelStore.exists(documentUri, id)) { + if (!modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore))) { throw new SpdxIdNotFoundException(id+" does not exist in document "+documentUri); } if (Objects.nonNull(type)) { this.type = type; licensePrimitiveAssignable = type.isAssignableFrom(SpdxNoneLicense.class); - if (!modelStore.isCollectionMembersAssignableTo(documentUri, id, propertyDescriptor, type)) { + if (!modelStore.isCollectionMembersAssignableTo(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), + propertyDescriptor, type)) { throw new SpdxInvalidTypeException("Incompatible type for property "+propertyDescriptor+": "+type.toString()); } } else { @@ -124,7 +118,9 @@ public ModelCollection(IModelStore baseStore, String documentUri, String id, Pro @Override public int size() { try { - return this.modelStore.collectionSize(this.documentUri, this.id, this.propertyDescriptor); + return this.modelStore.collectionSize( + CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), + this.propertyDescriptor); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -133,7 +129,9 @@ public int size() { @Override public boolean isEmpty() { try { - return this.modelStore.collectionSize(this.documentUri, this.id, this.propertyDescriptor) == 0; + return this.modelStore.collectionSize( + CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), + this.propertyDescriptor) == 0; } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -148,7 +146,9 @@ public boolean contains(Object o) { } catch (SpdxObjectNotInStoreException e1) { return false; // The exception is due to the model object not being in the store } - return this.modelStore.collectionContains(this.documentUri, this.id, this.propertyDescriptor, storedObject); + return this.modelStore.collectionContains( + CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), + this.propertyDescriptor, storedObject); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -195,7 +195,9 @@ public List toImmutableList() { @Override public Iterator iterator() { try { - return new ModelCollectionIterator(modelStore.listValues(documentUri, id, propertyDescriptor)); + return new ModelCollectionIterator( + modelStore.listValues(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), + propertyDescriptor)); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -214,7 +216,8 @@ public AT[] toArray(AT[] a) { @Override public boolean add(Object element) { try { - return modelStore.addValueToCollection(documentUri, id, propertyDescriptor, + return modelStore.addValueToCollection( + CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, copyManager)); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); @@ -224,8 +227,8 @@ public boolean add(Object element) { @Override public boolean remove(Object element) { try { - return modelStore.removeValueFromCollection(documentUri, id, propertyDescriptor, - ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, null)); + return modelStore.removeValueFromCollection(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), + propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, null)); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -277,7 +280,7 @@ public boolean retainAll(Collection c) { @Override public void clear() { try { - modelStore.clearValueCollection(documentUri, id, propertyDescriptor); + modelStore.clearValueCollection(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), propertyDescriptor); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -286,7 +289,7 @@ public void clear() { /** * @return the modelStore */ - public CompatibleModelStoreWrapper getModelStore() { + public IModelStore getModelStore() { return modelStore; } diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 7e9741721..2c0353793 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -49,6 +49,7 @@ import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.ListedLicenses; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; @@ -103,7 +104,7 @@ public abstract class ModelObject { static final Logger logger = LoggerFactory.getLogger(ModelObject.class); - private CompatibleModelStoreWrapper modelStore; + private IModelStore modelStore; private String documentUri; private String id; @@ -177,7 +178,7 @@ public ModelObject() throws InvalidSPDXAnalysisException { /** * Open or create a model object with the default store and default document URI - * @param objectUri ID for this object - must be unique within the SPDX document + * @param id ID for this object - must be unique within the SPDX document * @throws InvalidSPDXAnalysisException */ public ModelObject(String id) throws InvalidSPDXAnalysisException { @@ -186,30 +187,37 @@ public ModelObject(String id) throws InvalidSPDXAnalysisException { } /** - * @param baseModelStore Storage for the model objects + * @param modelStore Storage for the model objects * @param documentUri SPDX Document URI for a document associated with this model - * @param objectUri ID for this object - must be unique within the SPDX document + * @param identifier ID for this object - must be unique within the SPDX document * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods * @param create - if true, the object will be created in the store if it is not already present * @throws InvalidSPDXAnalysisException */ - public ModelObject(IModelStore baseModelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, + public ModelObject(IModelStore modelStore, String documentUri, String identifier, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(baseModelStore, "Model Store can not be null"); + Objects.requireNonNull(modelStore, "Model Store can not be null"); Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(id, "ID can not be null"); - if (baseModelStore instanceof CompatibleModelStoreWrapper) { - this.modelStore = (CompatibleModelStoreWrapper)baseModelStore; + Objects.requireNonNull(identifier, "ID can not be null"); + if (identifier.startsWith(documentUri)) { + logger.warn("document URI was passed in as an ID: "+identifier); + this.id = identifier.substring(documentUri.length()); + if (this.id.startsWith("#")) { + this.id = this.id.substring(1); + } + } else { + this.id = identifier; + } + if ((LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) && + !SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { + logger.warn("Listed license document URI changed to listed license URL for documentUri "+documentUri); + this.documentUri = SpdxConstantsCompatV2.LISTED_LICENSE_URL; } else { - // we need to wrap the model store for compatibility. Note - we don't want to - // wrap already wrapped model stores as it will force copies to be made into the same - // base model store - this.modelStore = new CompatibleModelStoreWrapper(baseModelStore); + this.documentUri = documentUri; } - this.documentUri = documentUri; - this.id = id; + this.modelStore = modelStore; this.copyManager = copyManager; - Optional existing = modelStore.getTypedValue(documentUri, id); + Optional existing = modelStore.getTypedValue(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore)); if (existing.isPresent()) { if (create && !existing.get().getType().equals(getType())) { throw new SpdxIdInUseException("Can not create "+id+". It is already in use with type "+existing.get().getType()+" which is incompatible with type "+getType()); @@ -219,8 +227,8 @@ public ModelObject(IModelStore baseModelStore, String documentUri, String id, @N IModelStoreLock lock = enterCriticalSection(false); // re-check since previous check was done outside of the lock try { - if (!modelStore.exists(documentUri, id)) { - modelStore.create(documentUri, id, getType()); + if (!modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore))) { + modelStore.create(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), getType()); } } finally { lock.unlock(); @@ -288,10 +296,16 @@ public String getId() { return id; } + public String getObjectUri() { + return modelStore.getIdType(id) == IdType.Anonymous ? id : + SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri) ? documentUri + id : + documentUri + "#" + id; + } + /** * @return the model store for this object */ - public CompatibleModelStoreWrapper getModelStore() { + public IModelStore getModelStore() { return this.modelStore; } @@ -315,7 +329,7 @@ public void setStrict(boolean strict) { * @throws InvalidSPDXAnalysisException */ public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { - return this.getModelStore().enterCriticalSection(this.getDocumentUri(), readLockRequested); + return modelStore.enterCriticalSection(readLockRequested); } /** @@ -332,7 +346,7 @@ public void leaveCriticalSection(IModelStoreLock lock) { * @throws InvalidSPDXAnalysisException */ public List getPropertyValueDescriptors() throws InvalidSPDXAnalysisException { - return modelStore.getPropertyValueDescriptors(documentUri, id); + return modelStore.getPropertyValueDescriptors(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore)); } /** @@ -785,7 +799,7 @@ protected Collection getStringCollection(PropertyDescriptor propertyDesc } protected boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return modelStore.isCollectionMembersAssignableTo(this.documentUri, this.id, propertyDescriptor, + return modelStore.isCollectionMembersAssignableTo(CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), propertyDescriptor, ModelStorageClassConverter.modelClassToStoredClass(clazz)); } @@ -1100,7 +1114,7 @@ public ModelCopyManager getCopyManager() { } /** - * @param objectUri String for the object + * @param id String for the object * @return type of the ID */ protected IdType idToIdType(String id) { @@ -1242,9 +1256,9 @@ public ExternalDocumentRef createExternalDocumentRef(String externalDocumentId, if (!SpdxVerificationHelper.isValidUri(externalDocumentUri)) { throw new InvalidSPDXAnalysisException("Invalid external document URI: "+externalDocumentUri); } - IModelStoreLock lock = getModelStore().enterCriticalSection( getDocumentUri(), false); + IModelStoreLock lock = modelStore.enterCriticalSection(false); try { - if (getModelStore().exists(getDocumentUri(), externalDocumentId)) { + if (modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(getDocumentUri(), externalDocumentId, modelStore))) { return new ExternalDocumentRef(getModelStore(), getDocumentUri(), externalDocumentId, this.copyManager, false); } else { @@ -1304,7 +1318,7 @@ public ExternalRef createExternalRef(ReferenceCategory category, ReferenceType r /** * Create an SpdxFileBuilder with all of the required properties - the build() method will build the file - * @param objectUri - ID - must be an SPDX ID type + * @param id - ID - must be an SPDX ID type * @param name - File name * @param concludedLicense license concluded * @param seenLicense collection of seen licenses @@ -1324,7 +1338,7 @@ public SpdxFile.SpdxFileBuilder createSpdxFile(String id, String name, AnyLicens /** * Create an SpdxPackageBuilder with all required fields for a filesAnalyzed=false using this objects model store and document URI - * @param objectUri - ID - must be an SPDX ID type + * @param id - ID - must be an SPDX ID type * @param name - File name * @param concludedLicense license concluded * @param copyrightText Copyright text @@ -1388,7 +1402,7 @@ public StartEndPointer createStartEndPointer(SinglePointer startPointer, SingleP /** * Create an SpdxSnippetBuilder with all of the required properties - the build() method will build the file - * @param objectUri - ID - must be an SPDX ID type + * @param id - ID - must be an SPDX ID type * @param name - File name * @param concludedLicense license concluded * @param seenLicense collection of seen licenses diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java index 2598a7161..0cd4a6641 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java @@ -59,7 +59,7 @@ public ModelSet(IModelStore modelStore, String documentUri, String id, PropertyD public boolean add(Object element) { IModelStoreLock lock; try { - lock = this.getModelStore().enterCriticalSection( getDocumentUri(), false); + lock = this.getModelStore().enterCriticalSection(false); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } @@ -78,7 +78,7 @@ public boolean add(Object element) { public boolean addAll(Collection c) { IModelStoreLock lock; try { - lock = this.getModelStore().enterCriticalSection( getDocumentUri(), false); + lock = this.getModelStore().enterCriticalSection(false); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index a6f9aaf30..f3b6c993f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -26,6 +26,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SimpleUriValue; +import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxObjectNotInStoreException; @@ -75,7 +76,14 @@ public static Object storedObjectToModelObject(Object value, String documentUri, return suv.toModelObject(modelStore, null, documentUri); } else if (value instanceof TypedValue) { TypedValue tv = (TypedValue)value; - return SpdxModelFactory.createModelObject(modelStore, documentUri, tv.getObjectUri(), tv.getType(), copyManager); + String id = tv.getObjectUri().startsWith(documentUri) ? tv.getObjectUri().substring(documentUri.length() + 1) : + tv.getObjectUri(); + if (id.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { + return SpdxModelFactory.getModelObjectV2(modelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, + id.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()), tv.getType(), copyManager, true); + } else { + return SpdxModelFactory.getModelObjectV2(modelStore, documentUri, id, tv.getType(), copyManager, true); + } } else { return value; } @@ -122,11 +130,14 @@ public static Object modelObjectToStoredObject(Object value, String stDocumentUr return new SimpleUriValue((IndividualUriValue)value); } else if (value instanceof ModelObject) { ModelObject mValue = (ModelObject)value; - if (!mValue.getModelStore().equals(stModelStore) || !mValue.getDocumentUri().equals(stDocumentUri)) { + String toNamespace = SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(mValue.getType()) || + SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(mValue.getType()) ? + SpdxConstantsCompatV2.LISTED_LICENSE_URL : stDocumentUri; + if (!mValue.getModelStore().equals(stModelStore) || !mValue.getDocumentUri().equals(toNamespace)) { if (Objects.nonNull(copyManager)) { return copyManager.copy(stModelStore, mValue.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(mValue.getDocumentUri(), mValue.getId(), mValue.getModelStore()), - mValue.getType(), mValue.getDocumentUri(), stDocumentUri); + mValue.getType(), mValue.getDocumentUri(), toNamespace); } else { throw new SpdxObjectNotInStoreException("Can not set a property value to a Model Object stored in a different model store"); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java index 5d089ca3e..f91a553be 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java @@ -205,7 +205,7 @@ public boolean add(SpdxElement e) { } try { IModelStoreLock lock = owningElement.getModelStore() - .enterCriticalSection(owningElement.getDocumentUri(), false); + .enterCriticalSection(false); try { Relationship relationship = owningElement.createRelationship(e, relationshipTypeFilter, null); createdRelationshipIds.add(relationship.getId()); diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java index 0ee4961eb..05df56cdf 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java @@ -35,7 +35,6 @@ import org.spdx.library.model.compat.v2.ModelStorageClassConverter; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * A parser for the SPDX License Expressions as documented in the SPDX appendix. @@ -259,12 +258,11 @@ private static int findMatchingParen(String[] tokens, int startToken) { * @return * @throws InvalidSPDXAnalysisException */ - private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore baseStore, String documentUri, + private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(token, "Token can not be null"); - Objects.requireNonNull(baseStore, "Model store can not be null"); + Objects.requireNonNull(store, "Model store can not be null"); Objects.requireNonNull(documentUri, "Document URI can not be null"); - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(baseStore); if (token.contains(":")) { // External License Ref return new ExternalExtractedLicenseInfo(store, documentUri, token, copyManager, true); @@ -275,17 +273,18 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore licenseId = LicenseInfoFactory.listedLicenseIdCaseSensitive(token); } if (licenseId.isPresent()) { - if (!store.exists(documentUri, licenseId.get())) { + if (!store.exists(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId.get())) { SpdxListedLicense listedLicense = LicenseInfoFactory.getListedLicenseById(licenseId.get()); if (Objects.nonNull(copyManager)) { // copy to the local store - copyManager.copy(store, CompatibleModelStoreWrapper.documentUriIdToUri(listedLicense.getDocumentUri(), token, false), listedLicense.getModelStore(), - CompatibleModelStoreWrapper.documentUriIdToUri(listedLicense.getDocumentUri(), token, false), - SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, listedLicense.getDocumentUri(), listedLicense.getDocumentUri()); + copyManager.copy(store, listedLicense.getObjectUri(), listedLicense.getModelStore(), + listedLicense.getObjectUri(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, + listedLicense.getDocumentUri(), listedLicense.getDocumentUri()); } } return (AnyLicenseInfo) ModelStorageClassConverter.storedObjectToModelObject( - new TypedValue(licenseId.get(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE), + new TypedValue(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId.get(), + SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE), documentUri, store, copyManager); } else { // LicenseRef diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java index 3d2f6cdaa..e442c1f76 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java @@ -71,7 +71,7 @@ public abstract class SimpleLicensingInfo extends AnyLicenseInfo { } /** - * @return the objectUri + * @return the license ID without the enclosing namespace */ public String getLicenseId() { return this.getId(); diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java index c3806cde1..5ec96be5b 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java @@ -25,6 +25,7 @@ import javax.annotation.Nullable; +import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; @@ -49,10 +50,9 @@ public class SpdxListedLicense extends License { * @param objectUri ID for this object - must be unique within the SPDX document * @throws InvalidSPDXAnalysisException */ - @SuppressWarnings("unchecked") public SpdxListedLicense(String id) throws InvalidSPDXAnalysisException { - super(id); - crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); + this(DefaultModelStore.getDefaultModelStore(), SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, + DefaultModelStore.getDefaultCopyManager(), true); } /** diff --git a/src/main/java/org/spdx/storage/IModelStore.java b/src/main/java/org/spdx/storage/IModelStore.java index bf6c973da..b43e9ac15 100644 --- a/src/main/java/org/spdx/storage/IModelStore.java +++ b/src/main/java/org/spdx/storage/IModelStore.java @@ -105,10 +105,10 @@ public enum IdType { public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; /** - * Generate a unique ID for use within the document + * Generate a unique ID within the document store * @param idType Type of ID * @param nameSpace the SPDX namespace to use for the ID - * @return next available unique ID for the specific idType + * @return next available unique ID for the specific idType as a full URI * @throws InvalidSPDXAnalysisException */ public String getNextId(IdType idType, @Nullable String nameSpace) throws InvalidSPDXAnalysisException; diff --git a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java index 77e3e138e..174521f9c 100644 --- a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java +++ b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java @@ -356,4 +356,11 @@ public SpdxMajorVersion getSpdxVersion() { return SpdxMajorVersion.VERSION_2; } + /** + * @return the store this store wraps + */ + public IModelStore getBaseModelStore() { + return this.baseStore; + } + } diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index cfd53a897..199b62882 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -433,7 +433,7 @@ public Optional getCaseSensisitiveId(String nameSpace, String caseInsens Objects.requireNonNull(nameSpace, "Namespace can not be null"); Objects.requireNonNull(caseInsensisitiveId, "CaseInsensisitiveId can not be null"); String objectUri = nameSpace + "#" + caseInsensisitiveId; - StoredTypedItem item = typedValueMap.get(objectUri); + StoredTypedItem item = typedValueMap.get(objectUri.toLowerCase()); if (Objects.isNull(item)) { return Optional.empty(); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index b84ff2a64..02419747a 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -272,7 +272,7 @@ public void testGetDocumentUri() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getObjectUri()}. + * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getId()}. * @throws InvalidSPDXAnalysisException */ public void testGetId() throws InvalidSPDXAnalysisException { @@ -605,7 +605,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(gmo.equivalent(gmo2)); assertTrue(gmo2.equivalent(gmo)); // different store - InMemSpdxStore store2 = new InMemSpdxStore(); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); GenericModelObject gmo3 = new GenericModelObject(store2, docUri, TEST_ID, copyManager, true); addTestValues(gmo3); assertTrue(gmo.equivalent(gmo3)); @@ -770,7 +770,7 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { public void testClone() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); addTestValues(gmo); - InMemSpdxStore store2 = new InMemSpdxStore(); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelObject result = gmo.clone(store2); assertTrue(result instanceof GenericModelObject); assertEquals(result, gmo); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java index 33b7198f2..08ec80d67 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java @@ -22,6 +22,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.storage.IModelStore; @@ -49,7 +50,7 @@ public class ConjunctiveLicenseSetTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - modelStore = new InMemSpdxStore(); + modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); copyManager = new ModelCopyManager(); NON_STD_LICENSES = new ExtractedLicenseInfo[IDS.length]; for (int i = 0; i < IDS.length; i++) { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java index da1f1f7a6..3a8db1c62 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java @@ -22,6 +22,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.storage.IModelStore; @@ -49,7 +50,7 @@ public class DisjunctiveLiceseSetTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - modelStore = new InMemSpdxStore(); + modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); copyManager = new ModelCopyManager(); NON_STD_LICENSES = new ExtractedLicenseInfo[IDS.length]; for (int i = 0; i < IDS.length; i++) { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java index 5ae269be5..7247d6884 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java @@ -56,7 +56,7 @@ public class LicenseExpressionParserTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - modelStore = new InMemSpdxStore(); + modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); gmo = new GenericModelObject(); NON_STD_LICENSES = new ExtractedLicenseInfo[NONSTD_IDS.length]; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java index 4e3af4d2a..0f20b2b9f 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ListedLicensesTest.java @@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import junit.framework.TestCase; @@ -140,7 +141,8 @@ public void testListedExceptionIdCaseSensitive() { public void testGetLicenseIdProperty() throws InvalidSPDXAnalysisException { String id = "Apache-2.0"; SpdxListedLicense lic = ListedLicenses.getListedLicenses().getListedLicenseById(id); - Optional idProp = lic.getModelStore().getValue(lic.getDocumentUri(), id, SpdxConstantsCompatV2.PROP_LICENSE_ID); + Optional idProp = lic.getModelStore().getValue( + CompatibleModelStoreWrapper.documentUriIdToUri(lic.getDocumentUri(), id, false), SpdxConstantsCompatV2.PROP_LICENSE_ID); assertTrue(idProp.isPresent()); assertTrue(idProp.get() instanceof String); assertEquals(id, idProp.get()); @@ -149,7 +151,8 @@ public void testGetLicenseIdProperty() throws InvalidSPDXAnalysisException { public void testGetExceptionIdProperty() throws InvalidSPDXAnalysisException { String id = "Classpath-exception-2.0"; ListedLicenseException ex = ListedLicenses.getListedLicenses().getListedExceptionById(id); - Optional idProp = ex.getModelStore().getValue(ex.getDocumentUri(), id, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID); + Optional idProp = ex.getModelStore().getValue( + CompatibleModelStoreWrapper.documentUriIdToUri(ex.getDocumentUri(), id, false), SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID); assertTrue(idProp.isPresent()); assertTrue(idProp.get() instanceof String); assertEquals(id, idProp.get()); diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java index ff610ca69..59b6665ad 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java @@ -24,6 +24,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; @@ -274,7 +275,7 @@ public void testList() throws InvalidSPDXAnalysisException { // license crossRefs license.getCrossRef().clear(); assertEquals(0, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - IModelStore simpleModelStore = new InMemSpdxStore(); + IModelStore simpleModelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://some.other.doc"; CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); crossRef1.setUrl("http://url1"); diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java index 25a395ff9..1a725a117 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java @@ -27,6 +27,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.library.model.compat.v2.license.LicenseException; import org.spdx.library.model.compat.v2.license.ListedLicenseException; @@ -302,7 +303,7 @@ public void testList() throws Exception { // license crossRefs license.getCrossRef().clear(); assertEquals(0, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - IModelStore simpleModelStore = new InMemSpdxStore(); + IModelStore simpleModelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://some.other.doc"; CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); crossRef1.setUrl("http://url1"); From 9e0d26d90e01ed273585dea7618bf50ff2d2797e Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 16 Jun 2023 17:19:58 -0700 Subject: [PATCH 06/62] Intermediate checkin All unit tests pass except compares Signed-off-by: Gary O'Neall --- .../library/model/compat/v2/ModelObject.java | 2 +- .../compat/v2/ModelStorageClassConverter.java | 12 ++++-- .../compat/v2/license/LicenseException.java | 6 ++- .../compat/v2/license/SpdxListedLicense.java | 2 +- .../v2/CompatibleModelStoreWrapper.java | 18 +++++---- .../SpdxListedLicenseModelStore.java | 2 +- .../compat/v2/IndividualUriValueTest.java | 5 ++- .../model/compat/v2/ModelObjectTest.java | 4 +- .../v2/ModelStorageClassConverterTest.java | 4 +- .../model/compat/v2/RelationshipTest.java | 2 +- .../model/compat/v2/SpdxDocumentTest.java | 4 +- .../model/compat/v2/SpdxModelFactoryTest.java | 10 +++-- .../model/compat/v2/SpdxSnippetTest.java | 38 +++++++++---------- .../v2/license/LicenseExceptionTest.java | 4 +- .../v2/license/OrLaterOperatorTest.java | 2 +- .../v2/license/WithExceptionOperatorTest.java | 7 +++- .../utility/compare/SpdxComparerTest.java | 3 +- 17 files changed, 72 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 2c0353793..dae3746fe 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -1099,7 +1099,7 @@ public void copyFrom(ModelObject source) throws InvalidSPDXAnalysisException { } copyManager.copy(this.modelStore, CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, this.modelStore), source.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(source.getDocumentUri(), source.getId(), source.getModelStore()), - this.getType(), this.documentUri, source.getDocumentUri()); + this.getType(), source.getDocumentUri(), this.documentUri); } public void setCopyManager(ModelCopyManager copyManager) { diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index f3b6c993f..d90569a50 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -32,6 +32,7 @@ import org.spdx.library.SpdxObjectNotInStoreException; import org.spdx.library.TypedValue; import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** @@ -130,14 +131,17 @@ public static Object modelObjectToStoredObject(Object value, String stDocumentUr return new SimpleUriValue((IndividualUriValue)value); } else if (value instanceof ModelObject) { ModelObject mValue = (ModelObject)value; - String toNamespace = SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(mValue.getType()) || + String toDocumentUri = SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(mValue.getType()) || + SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION.equals(mValue.getType()) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(mValue.getType()) ? SpdxConstantsCompatV2.LISTED_LICENSE_URL : stDocumentUri; - if (!mValue.getModelStore().equals(stModelStore) || !mValue.getDocumentUri().equals(toNamespace)) { + if (!mValue.getModelStore().equals(stModelStore) || !mValue.getDocumentUri().equals(toDocumentUri)) { if (Objects.nonNull(copyManager)) { + boolean anon = mValue.getModelStore().getIdType(mValue.getId()) == IdType.Anonymous; return copyManager.copy(stModelStore, mValue.getModelStore(), - CompatibleModelStoreWrapper.documentUriIdToUri(mValue.getDocumentUri(), mValue.getId(), mValue.getModelStore()), - mValue.getType(), mValue.getDocumentUri(), toNamespace); + CompatibleModelStoreWrapper.documentUriIdToUri(mValue.getDocumentUri(), mValue.getId(), anon), + mValue.getType(), CompatibleModelStoreWrapper.documentUriToNamespace(mValue.getDocumentUri(), anon), + CompatibleModelStoreWrapper.documentUriToNamespace(toDocumentUri, anon)); } else { throw new SpdxObjectNotInStoreException("Can not set a property value to a Model Object stored in a different model store"); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java index 0d81d7834..ef5c1ae14 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java @@ -25,6 +25,7 @@ import javax.annotation.Nullable; +import org.spdx.library.DefaultModelStore; import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -55,7 +56,7 @@ public class LicenseException extends ModelObject { public LicenseException(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); + super(modelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, copyManager, create); if (!(this instanceof IndividualUriValue)) { setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec } @@ -75,7 +76,8 @@ public LicenseException(String id, String name, String text, } public LicenseException(String id, String name, String text) throws InvalidSPDXAnalysisException { - super(id); + super(DefaultModelStore.getDefaultModelStore(), SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, + DefaultModelStore.getDefaultCopyManager(), true); setName(name); setLicenseExceptionText(text); if (!(this instanceof IndividualUriValue)) { diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java index 5ec96be5b..a540c0020 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java @@ -68,7 +68,7 @@ public SpdxListedLicense(String id) throws InvalidSPDXAnalysisException { public SpdxListedLicense(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); + super(modelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, copyManager, create); crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); } diff --git a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java index 174521f9c..f5562a542 100644 --- a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java +++ b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java @@ -68,6 +68,16 @@ public static String documentUriIdToUri(String documentUri, String id, IModelSto return documentUriIdToUri(documentUri, id, store.getIdType(id).equals(IdType.Anonymous)); } + public static String documentUriToNamespace(String documentUri, boolean anonymous) { + if (anonymous) { + return ""; + } else if (documentUri.contains("://spdx.org/licenses/")) { + return documentUri; + } else { + return documentUri + "#"; + } + } + /** * @param documentUri SPDX v2 Document URI * @param id ID consistent with SPDX v2 spec @@ -75,13 +85,7 @@ public static String documentUriIdToUri(String documentUri, String id, IModelSto * @return a URI based on the document URI and ID - if anonymous is true, the ID is returned */ public static String documentUriIdToUri(String documentUri, String id, boolean anonymous) { - if (anonymous) { - return id; - } else if (documentUri.contains("://spdx.org/licenses/")) { - return documentUri + id; - } else { - return documentUri + "#" + id; - } + return documentUriToNamespace(documentUri, anonymous) + id; } /** diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index e79a03d74..b4a1146c3 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -739,7 +739,7 @@ public Optional getValue(String objectUri, PropertyDescriptor propertyDe */ @Override public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { + if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri) && !IdType.Anonymous.equals(idType)) { logger.error("Document URI for SPDX listed licenses is expected to be "+ SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ diff --git a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java index 205e10161..31ef00fc5 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java @@ -3,6 +3,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SimpleUriValue; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; @@ -27,7 +28,7 @@ protected void tearDown() throws Exception { // Test if a simple URI value is equal to the ExternalExtracedLicenseInfo with the same URI value public void testEqualUriValueExternalExtractedLicenseInfo() throws InvalidSPDXAnalysisException { - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); String id = SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"ID"; String namespace = "http://example.namespace"; @@ -44,7 +45,7 @@ public void testEqualUriValueExternalExtractedLicenseInfo() throws InvalidSPDXAn // Test if a simple URI value is equal to the ExternalSpdxElement with the same URI value public void testEqualUriValueExternalSpdxElement() throws InvalidSPDXAnalysisException { - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); String id = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"ID"; String namespace = "http://example.namespace"; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index 02419747a..37f173148 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -788,7 +788,7 @@ public void testCopyFrom() throws InvalidSPDXAnalysisException { gmo2.copyFrom(gmo); assertTrue(gmo.equivalent(gmo2)); // different store - InMemSpdxStore store2 = new InMemSpdxStore(); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); GenericModelObject gmo3 = new GenericModelObject(store2, docUri, TEST_ID, copyManager, true); gmo3.copyFrom(gmo); assertTrue(gmo.equivalent(gmo3)); @@ -816,7 +816,7 @@ public void testToTypeValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); addTestValues(gmo); TypedValue result = gmo.toTypedValue(); - assertEquals(TEST_ID, result.getObjectUri()); + assertEquals(docUri + "#" + TEST_ID, result.getObjectUri()); assertEquals(gmo.getType(), result.getType()); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index 694c6fb5c..d09a41c90 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -147,8 +147,8 @@ public void testModelObjectToStoredObject() throws InvalidSPDXAnalysisException } public void testCopyIModelStoreStringIModelStoreStringStringString() throws InvalidSPDXAnalysisException { - IModelStore store1 = new InMemSpdxStore(); - IModelStore store2 = new InMemSpdxStore(); + IModelStore store1 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + IModelStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); String docUri1 = "http://doc1/uri"; String docUri2 = "http://doc2/uri"; diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java index 25ffbcfd7..e9db5a4ba 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java @@ -219,7 +219,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { public void testDocumentDescribes() throws InvalidSPDXAnalysisException { String documentUri = "https://someuri"; ModelCopyManager copyManager = new ModelCopyManager(); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxDocument document = SpdxModelFactory.createSpdxDocumentV2(modelStore, documentUri, copyManager); document.setSpecVersion(Version.TWO_POINT_THREE_VERSION); document.setName("SPDX-tool-test"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index a6b426f5f..70bbfc786 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -293,7 +293,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(doc.equivalent(doc)); String doc2Uri = "http://spdx.org/spdx/2ndoc/2342"; - IModelStore model2 = new InMemSpdxStore(); + IModelStore model2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxDocument doc2 = SpdxModelFactory.createSpdxDocumentV2(model2, doc2Uri, gmo.getCopyManager()); doc2.setStrict(false); doc2.setAnnotations(annotations); @@ -659,7 +659,7 @@ public void testSetSpecVersion() throws InvalidSPDXAnalysisException { // Test for issue 126 - removing a documentDescribes not properly decrementing use counts public void testRemoveDescribes() throws InvalidSPDXAnalysisException { - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "https://some.doc.uri"; ModelCopyManager copyManager = new ModelCopyManager(); SpdxDocument doc = new SpdxDocument(modelStore, docUri, copyManager, true); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index 02a2faa71..718965a50 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -5,6 +5,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxModelFactory; @@ -64,8 +65,10 @@ public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoole } public void testTypeToClass() throws InvalidSPDXAnalysisException { - assertEquals(Checksum.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM)); - assertEquals(SpdxFile.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_FILE)); + assertEquals(Checksum.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, + SpdxMajorVersion.VERSION_2)); + assertEquals(SpdxFile.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_FILE, + SpdxMajorVersion.VERSION_2)); } @SuppressWarnings("unchecked") @@ -97,7 +100,8 @@ public void testGetElements() throws InvalidSPDXAnalysisException { public void testClassUriToClass() throws InvalidSPDXAnalysisException { assertEquals(Annotation.class, - SpdxModelFactory.classUriToClass(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.CLASS_ANNOTATION)); + SpdxModelFactory.classUriToClass(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.CLASS_ANNOTATION, + SpdxMajorVersion.VERSION_2)); } public void testGetModelObjectIModelStoreStringStringModelCopyManager() throws InvalidSPDXAnalysisException { diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java index d9c7392a9..ebb945dbc 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java @@ -142,11 +142,11 @@ protected void setUp() throws Exception { DISJUNCTIVE_LICENSES[2], NON_STD_LICENSES[2], CONJUNCTIVE_LICENSES[1] })); - FROM_FILE1 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + FROM_FILE1 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, null), "fromFile1", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, gmo.createChecksum(ChecksumAlgorithm.SHA1, "1123456789abcdef0123456789abcdef01234567")).build(); - FROM_FILE2 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + FROM_FILE2 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, null), "fromFile2", STANDARD_LICENSES[0], Arrays.asList(STANDARD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, gmo.createChecksum(ChecksumAlgorithm.SHA1, "5555556789abcdef0123456789abcdef01234567")).build(); @@ -176,7 +176,7 @@ protected void tearDown() throws Exception { * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#verify()}. */ public void testVerify() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -185,7 +185,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { List result = snippet.verify(); assertEquals(0, result.size()); // missing file - SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -198,7 +198,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { result = snippet2.verify(); assertTrue(result.size() > 0); // missing byte range - SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -210,12 +210,12 @@ public void testVerify() throws InvalidSPDXAnalysisException { } public void testEquivalent() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); - SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -223,7 +223,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(snippet.equivalent(snippet2)); assertTrue(snippet2.equivalent(snippet)); // Different File - SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE2, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -231,7 +231,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertFalse(snippet3.equivalent(snippet)); assertFalse(snippet.equivalent(snippet3)); // different byte range - SpdxSnippet snippet4 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet4 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET2_1, OFFSET2_2) .setLineRange(LINE1_1, LINE1_2) @@ -244,7 +244,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#setSnippetFromFile(org.spdx.library.model.compat.v2.compat.v2.SpdxFile)}. */ public void testSetSnippetFromFile() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -271,7 +271,7 @@ public void testSetSnippetFromFile() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#setByteRange(org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer)}. */ public void testSetByteRange() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -292,7 +292,7 @@ public void testSetByteRange() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#setLineRange(org.spdx.library.model.compat.v2.compat.v2.pointer.StartEndPointer)}. */ public void testSetLineRange() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -313,34 +313,34 @@ public void testSetLineRange() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet#compareTo(org.spdx.library.model.compat.v2.compat.v2.SpdxSnippet)}. */ public void testCompareTo() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); // same - SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet2 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); assertEquals(0, snippet.compareTo(snippet2)); // different filename - SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet3 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "AsnippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); assertTrue(snippet.compareTo(snippet3) > 0); // different from file - SpdxSnippet snippet4 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet4 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE2, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) .build(); assertTrue(snippet.compareTo(snippet4) < 0); // different byterange - SpdxSnippet snippet5 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet5 = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", COMPLEX_LICENSE, Arrays.asList(NON_STD_LICENSES), SpdxConstantsCompatV2.NOASSERTION_VALUE, FROM_FILE1, OFFSET2_1, OFFSET2_2) .setLineRange(LINE1_1, LINE1_2) @@ -350,7 +350,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { // Test to verify spec versions prior to 2.3 fail verify for missing license or copyright fields public void testVerify23Fields() throws InvalidSPDXAnalysisException { - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", null, Arrays.asList(new AnyLicenseInfo[] {}), null, FROM_FILE1, OFFSET1_1, OFFSET1_2) .setLineRange(LINE1_1, LINE1_2) @@ -363,7 +363,7 @@ public void testVerify23Fields() throws InvalidSPDXAnalysisException { public void testSetAttributionText() throws InvalidSPDXAnalysisException { String ATT1 = "attribution 1"; String ATT2 = "attribution 2"; - SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + SpdxSnippet snippet = gmo.createSpdxSnippet(gmo.getModelStore().getNextId(IdType.SpdxId, null), "snippetName", null, Arrays.asList(new AnyLicenseInfo[] {}), null, FROM_FILE1, OFFSET1_1, OFFSET1_2) .addAttributionText(ATT1) diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java index b62d7b3d3..d7ec97f7a 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java @@ -91,9 +91,9 @@ public void testCreateResource() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); copyManager.copy(store, DefaultModelStore.getDefaultModelStore(), - CompatibleModelStoreWrapper.documentUriIdToUri(DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, false), + CompatibleModelStoreWrapper.documentUriIdToUri(SpdxConstantsCompatV2.LISTED_LICENSE_URL, EXCEPTION_ID1, false), SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, - DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); + SpdxConstantsCompatV2.LISTED_LICENSE_URL, SpdxConstantsCompatV2.LISTED_LICENSE_URL); LicenseException le2 = new LicenseException(store, DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, copyManager, false); assertEquals(EXCEPTION_ID1, le2.getLicenseExceptionId()); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java index 091d3f6a3..72908c68c 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/OrLaterOperatorTest.java @@ -90,7 +90,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { public void testCopyFrom() throws InvalidSPDXAnalysisException { OrLaterOperator olo1 = new OrLaterOperator(license1); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); OrLaterOperator clone = new OrLaterOperator(store, "https://different.uri", "orLaterId", olo1.getCopyManager(), true); clone.copyFrom(olo1); ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)olo1.getLicense(); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java index 793183015..d3d2fffbe 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java @@ -1,5 +1,7 @@ package org.spdx.library.model.compat.v2.license; +import java.util.List; + import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -86,7 +88,7 @@ public void testCopy() throws InvalidSPDXAnalysisException { ModelCopyManager copyManager = new ModelCopyManager(); @SuppressWarnings("unused") TypedValue tv = copyManager.copy(store, weo1.getModelStore(), - CompatibleModelStoreWrapper.documentUriIdToUri(weo1.getDocumentUri(), weo1.getId(), false), + CompatibleModelStoreWrapper.documentUriIdToUri(weo1.getDocumentUri(), weo1.getId(), weo1.getModelStore()), weo1.getType(), weo1.getDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); WithExceptionOperator clone = (WithExceptionOperator) SpdxModelFactory.createModelObject(store, DefaultModelStore.getDefaultDocumentUri(), weo1.getId(), SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, copyManager); @@ -142,6 +144,7 @@ public void testSetException() throws InvalidSPDXAnalysisException { } public void testClassPathException() throws InvalidSPDXAnalysisException, InvalidLicenseStringException { - assertTrue(LicenseInfoFactory.parseSPDXLicenseString("GPL-2.0-only WITH Classpath-exception-2.0").verify().isEmpty()); + List result = LicenseInfoFactory.parseSPDXLicenseString("GPL-2.0-only WITH Classpath-exception-2.0").verify(); + assertTrue(result.isEmpty()); } } diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index 6dcc5b31e..de1534510 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -788,7 +788,8 @@ private void alterExtractedLicenseInfoIds(SpdxDocument doc, int digit) throws In newLic.setExtractedText(lic.getExtractedText()); newLic.setName(lic.getName()); newLic.setSeeAlso(lic.getSeeAlso()); - assertEquals(0, newLic.verify().size()); + Listver = newLic.verify(); + assertEquals(0, ver.size()); newExtractedLicenseInfos.add(newLic); oldToNewLicIds.put(oldId, newLic); } From 2469ae3b38d50b492cff90fb33ac08c5ddd026d2 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sun, 18 Jun 2023 21:22:46 -0700 Subject: [PATCH 07/62] Intermediate checkin Still some unit test failures in compare Signed-off-by: Gary O'Neall --- .../org/spdx/library/ModelCopyManager.java | 83 ++++++++++++------- .../org/spdx/library/SpdxModelFactory.java | 19 +++-- .../model/compat/v2/ExternalDocumentRef.java | 2 +- .../library/model/compat/v2/ModelObject.java | 7 +- .../compat/v2/ModelStorageClassConverter.java | 7 +- .../spdx/library/model/compat/v2/Read.java | 2 +- .../v2/license/LicenseExpressionParser.java | 5 +- .../compat/v2/license/ListedLicenses.java | 4 +- .../v2/CompatibleModelStoreWrapper.java | 44 ++++++++++ .../compat/v2/ExternalDocumentRefTest.java | 2 +- .../v2/ModelStorageClassConverterTest.java | 3 +- .../model/compat/v2/SpdxModelFactoryTest.java | 6 +- .../v2/license/ConjunctiveLicenseSetTest.java | 6 +- .../v2/license/DisjunctiveLiceseSetTest.java | 6 +- .../license/ExtractedLicensingInfoTest.java | 19 +++-- .../v2/license/LicenseExceptionTest.java | 1 + .../v2/license/WithExceptionOperatorTest.java | 5 +- .../v2/CompatibleModelStoreWrapperTest.java | 19 ++++- .../SpdxListedLicenseLocalStoreTest.java | 8 +- .../SpdxListedLicenseWebStoreTest.java | 8 +- .../storage/simple/InMemSpdxStoreTest.java | 3 +- .../spdx/utility/compare/UnitTestHelper.java | 7 +- 22 files changed, 190 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index 7cd03c75f..403537d3d 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -53,7 +53,7 @@ public class ModelCopyManager { * Used to keep track of copied ID's to make sure we don't copy them more than once */ private ConcurrentHashMap>> COPIED_IDS = + ConcurrentHashMap>>> COPIED_IDS = new ConcurrentHashMap<>(); /** @@ -65,21 +65,26 @@ public ModelCopyManager() { /** * @param fromStore Store copied from - * @param fromObjectUri + * @param fromObjectUri Object URI in the from tsotre * @param toStore store copied to + * @param toNamespace Optional nameSpace used for the copied URI - can copy the same object to multiple namespaces in the same toStore * @return the objectId which has already been copied, or null if it has not been copied */ public String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri, - IModelStore toStore) { - ConcurrentHashMap> fromStoreMap = COPIED_IDS.get(fromStore); + IModelStore toStore, @Nullable String toNamespace) { + ConcurrentHashMap>> fromStoreMap = COPIED_IDS.get(fromStore); if (Objects.isNull(fromStoreMap)) { return null; } - ConcurrentHashMap toStoreMap = fromStoreMap.get(toStore); + ConcurrentHashMap> toStoreMap = fromStoreMap.get(toStore); if (Objects.isNull(toStoreMap)) { return null; } - return toStoreMap.get(fromObjectUri); + ConcurrentHashMap toNamespaceMap = toStoreMap.get(fromObjectUri); + if (Objects.isNull(toNamespaceMap)) { + return null; + } + return toNamespaceMap.get(toNamespace == null ? "" : toNamespace); } /** @@ -87,23 +92,28 @@ public String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri, * @param fromStore Store copied from * @param fromObjectUri URI for the from Object * @param toObjectUri URI for the to Object - * @param toId ID copied to - * @return any copied to ID for the same stores, URI's and fromID + * @param toNamespace Optional nameSpace used for the copied URI - can copy the same object to multiple namespaces in the same toStore + * @return any copied to ID for the same stores, URI's, nameSpace and fromID */ public String putCopiedId(IModelStore fromStore, String fromObjectUri, IModelStore toStore, - String toObjectUri) { - ConcurrentHashMap> fromStoreMap = COPIED_IDS.get(fromStore); + String toObjectUri, @Nullable String toNamespace) { + ConcurrentHashMap>> fromStoreMap = COPIED_IDS.get(fromStore); while (Objects.isNull(fromStoreMap)) { fromStoreMap = COPIED_IDS.putIfAbsent(fromStore, new ConcurrentHashMap<>()); } - ConcurrentHashMap toStoreMap = fromStoreMap.get(toStore); + ConcurrentHashMap> toStoreMap = fromStoreMap.get(toStore); while (Objects.isNull(toStoreMap)) { toStoreMap = fromStoreMap.putIfAbsent(toStore, new ConcurrentHashMap<>()); } - if (toStoreMap.containsKey(fromObjectUri)) { + ConcurrentHashMap toNamespaceMap = toStoreMap.get(fromObjectUri); + while (Objects.isNull(toNamespaceMap)) { + toNamespaceMap = toStoreMap.putIfAbsent(fromObjectUri, new ConcurrentHashMap<>()); + } + String ns = toNamespace == null ? "" : toNamespace; + if (toNamespaceMap.containsKey(ns)) { logger.warn("Object URI already exists for the originating "+ fromObjectUri); } - return toStoreMap.put(fromObjectUri, toObjectUri); + return toNamespaceMap.put(ns, toObjectUri); } /** @@ -115,11 +125,15 @@ public String putCopiedId(IModelStore fromStore, String fromObjectUri, IModelSto * @param type Type to copy * @param fromNamespace optional namespace of the from property * @param toNamespace optional namespace of the to property + * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace + * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace * @throws InvalidSPDXAnalysisException */ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri, String type, - @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { - copy(toStore, toObjectUri, fromStore, fromObjectUri, type, false, fromNamespace, toNamespace); + @Nullable String fromNamespace, @Nullable String toNamespace, + @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { + copy(toStore, toObjectUri, fromStore, fromObjectUri, type, false, fromNamespace, toNamespace, + fromCollectionNamespace, toCollectionNamespace); } /** @@ -134,12 +148,16 @@ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses * @param fromNamespace optional namespace of the from property * @param toNamespace optional namespace of the to property + * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace + * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace * @throws InvalidSPDXAnalysisException */ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri, String type, boolean excludeLicenseDetails, - @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + @Nullable String fromNamespace, @Nullable String toNamespace, + @Nullable String fromCollectionNamespace, + @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { Objects.requireNonNull(toStore, "ToStore can not be null"); Objects.requireNonNull(toObjectUri, "To Object URI can not be null"); Objects.requireNonNull(fromStore, "FromStore can not be null"); @@ -151,7 +169,7 @@ public void copy(IModelStore toStore, String toObjectUri, if (!toStore.exists(toObjectUri)) { toStore.create(toObjectUri, type); } - putCopiedId(fromStore, fromObjectUri, toStore, toObjectUri); + putCopiedId(fromStore, fromObjectUri, toStore, toObjectUri, toNamespace); if (!(excludeLicenseDetails && (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(type) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)))) { @@ -159,7 +177,8 @@ public void copy(IModelStore toStore, String toObjectUri, for (PropertyDescriptor propDesc:propertyDescriptors) { if (fromStore.isCollectionProperty(fromObjectUri, propDesc)) { copyCollectionProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, excludeLicenseDetails, - fromNamespace, toNamespace); + (fromCollectionNamespace == null ? fromNamespace : fromCollectionNamespace), + (toCollectionNamespace == null ? toNamespace : toCollectionNamespace)); } else { copyIndividualProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, excludeLicenseDetails, fromNamespace, toNamespace); @@ -199,12 +218,12 @@ private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IMo toStore.setValue(toObjectUri, propDescriptor, new SimpleUriValue((IndividualUriValue)result.get())); } else if (result.get() instanceof TypedValue) { TypedValue tv = (TypedValue)result.get(); - if (fromStore.equals(toStore)) { + if (fromStore.equals(toStore) && Objects.equals(fromNamespace, toNamespace)) { toStore.setValue(toObjectUri, propDescriptor, tv); } else { toStore.setValue(toObjectUri, propDescriptor, copy(toStore, fromStore, tv.getObjectUri(), tv.getType(), excludeLicenseDetails, - fromNamespace, toNamespace)); + fromNamespace, toNamespace, fromNamespace, toNamespace)); } } else { toStore.setValue(toObjectUri, propDescriptor, result.get()); @@ -220,7 +239,7 @@ private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IMo * @param fromDocumentUri Object URI to copy from * @param propDescriptor Descriptor for the property * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses - * * @param fromNamespace optional namespace of the from property + * @param fromNamespace optional namespace of the from property * @param toNamespace optional namespace of the to property * @throws InvalidSPDXAnalysisException */ @@ -245,11 +264,12 @@ private void copyCollectionProperty(IModelStore toStore, String toObjectUri, IMo toStoreItem = new SimpleUriValue((IndividualUriValue)listItem); } else if (listItem instanceof TypedValue) { TypedValue listItemTv = (TypedValue)listItem; - if (toStore.equals(fromStore)) { + if (toStore.equals(fromStore) && Objects.equals(fromNamespace, toNamespace)) { toStoreItem = listItemTv; } else { toStoreItem = copy(toStore, fromStore, listItemTv.getObjectUri(), - listItemTv.getType(), excludeLicenseDetails, fromNamespace, toNamespace); + listItemTv.getType(), excludeLicenseDetails, fromNamespace, toNamespace, + fromNamespace, toNamespace); } } else { toStoreItem = listItem; @@ -266,13 +286,16 @@ private void copyCollectionProperty(IModelStore toStore, String toObjectUri, IMo * @param type Type to copy * @param fromNamespace optional namespace of the from property * @param toNamespace optional namespace of the to property + * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace + * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace * @return Object URI for the copied object * @throws InvalidSPDXAnalysisException */ public TypedValue copy(IModelStore toStore, IModelStore fromStore, String sourceObjectUri, String type, - @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { - return copy(toStore, fromStore, sourceObjectUri, type, false, fromNamespace, toNamespace); + @Nullable String fromNamespace, @Nullable String toNamespace, + @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { + return copy(toStore, fromStore, sourceObjectUri, type, false, fromNamespace, toNamespace, fromCollectionNamespace, toCollectionNamespace); } /** @@ -284,12 +307,15 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses * @param fromNamespace optional namespace of the from property * @param toNamespace optional namespace of the to property + * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace + * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace * @return Object URI for the copied object * @throws InvalidSPDXAnalysisException */ public TypedValue copy(IModelStore toStore, IModelStore fromStore, String sourceUri, String type, boolean excludeLicenseDetails, - @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + @Nullable String fromNamespace, @Nullable String toNamespace, + @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { Objects.requireNonNull(toStore, "To Store can not be null"); Objects.requireNonNull(fromStore, "From Store can not be null"); Objects.requireNonNull(sourceUri, "Source URI can not be null"); @@ -298,7 +324,7 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, toStore.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) < 0) { throw new InvalidSPDXAnalysisException("Can not copy from SPDX spec version 3.0 to SPDX spec version less than 3.0"); } - String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore); + String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore, toNamespace); if (Objects.isNull(toObjectUri)) { if (!(fromStore.getIdType(sourceUri) == IdType.Anonymous)) { if (Objects.nonNull(fromNamespace) && sourceUri.startsWith(fromNamespace) && Objects.nonNull(toNamespace)) { @@ -326,7 +352,8 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, if (Objects.isNull(toObjectUri)) { toObjectUri = sourceUri; } - copy(toStore, toObjectUri, fromStore, sourceUri, type, excludeLicenseDetails, fromNamespace, toNamespace); + copy(toStore, toObjectUri, fromStore, sourceUri, type, excludeLicenseDetails, fromNamespace, toNamespace, + fromCollectionNamespace, toCollectionNamespace); } return new TypedValue(toObjectUri, type); } diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index 02ea8a193..76afdbd18 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -141,14 +141,17 @@ public static org.spdx.library.model.compat.v2.SpdxDocument createSpdxDocumentV2 * Create an SPDX version 2 model object in a model store given the document URI, ID and type * @param modelStore model store where the object is to be created * @param documentUri document URI for the stored item - * @param objectUri ID for the item + * @param id for the item * @param type SPDX class or type * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced * @return a ModelObject of type type * @throws InvalidSPDXAnalysisException */ - public static org.spdx.library.model.compat.v2.ModelObject createModelObject(IModelStore modelStore, String documentUri, String id, + public static org.spdx.library.model.compat.v2.ModelObject createModelObjectV2(IModelStore modelStore, String documentUri, String id, String type, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model store can not be null"); + Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); + Objects.requireNonNull(id, "ID must not be null"); return getModelObjectV2(modelStore, documentUri, id, type, copyManager, true); } @@ -156,7 +159,7 @@ public static org.spdx.library.model.compat.v2.ModelObject createModelObject(IMo * Create an SPDX spec version 2.X model object in a model store given the document URI, ID and type * @param modelStore model store where the object is to be created * @param documentUri document URI for the stored item - * @param objectUri ID for the item + * @param id ID for the item * @param type SPDX class or type * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced * @param create if true, create the model object if it does not already exist @@ -165,6 +168,9 @@ public static org.spdx.library.model.compat.v2.ModelObject createModelObject(IMo */ public static org.spdx.library.model.compat.v2.ModelObject getModelObjectV2(IModelStore modelStore, String documentUri, String id, String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model store can not be null"); + Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); + Objects.requireNonNull(id, "ID must not be null"); switch (type) { case SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT: return new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, create); //Note: the ID is ignored case SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE: return new org.spdx.library.model.compat.v2.SpdxPackage(modelStore, documentUri, id, copyManager, create); @@ -255,7 +261,7 @@ public static Stream getElements(IModelStore store, @Nullable String nameSpac } return store.getAllItems(nameSpace, type).map(tv -> { try { - return createModelObject(store, nameSpace, tv.getObjectUri(), tv.getType(), copyManager); + return createModelObjectV2(store, nameSpace, tv.getObjectUri(), tv.getType(), copyManager); } catch (InvalidSPDXAnalysisException e) { logger.error("Error creating model object",e); throw new RuntimeException(e); @@ -293,11 +299,14 @@ public static Class classUriToClass(String classUri) throws InvalidSPDXAnalys * @param documentUri Document URI for for the ID * @param copyManager Optional copy manager for copying any properties from other model * @param objectUri ID for the model object - * @return SPDX Version 2 compatibile ModelObject with the ID in the model store + * @return SPDX Version 2 compatible ModelObject with the ID in the model store * @throws InvalidSPDXAnalysisException */ public static Optional getModelObjectV2(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model store can not be null"); + Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); + Objects.requireNonNull(id, "ID must not be null"); if (id.contains(":")) { // External document ref try { diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index 9d60c67c1..127dfb54a 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -259,7 +259,7 @@ public Optional getSpdxDocument() throws InvalidSPDXAnalysisExcept } if (this.getModelStore().exists( CompatibleModelStoreWrapper.documentUriIdToUri(docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false))) { - return (Optional)(Optional)Optional.of(SpdxModelFactory.createModelObject( + return (Optional)(Optional)Optional.of(SpdxModelFactory.createModelObjectV2( getModelStore(), docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, getCopyManager())); } else { diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index dae3746fe..17ca084a5 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -1080,7 +1080,7 @@ public ModelObject clone(IModelStore modelStore) { throw new IllegalStateException("Can not clone - "+this.id+" already exists."); } try { - ModelObject retval = SpdxModelFactory.createModelObject(modelStore, this.documentUri, this.id, this.getType(), this.copyManager); + ModelObject retval = SpdxModelFactory.createModelObjectV2(modelStore, this.documentUri, this.id, this.getType(), this.copyManager); retval.copyFrom(this); return retval; } catch (InvalidSPDXAnalysisException e) { @@ -1099,7 +1099,10 @@ public void copyFrom(ModelObject source) throws InvalidSPDXAnalysisException { } copyManager.copy(this.modelStore, CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, this.modelStore), source.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(source.getDocumentUri(), source.getId(), source.getModelStore()), - this.getType(), source.getDocumentUri(), this.documentUri); + this.getType(), CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), source.getModelStore().getIdType(source.getId()) == IdType.Anonymous), + CompatibleModelStoreWrapper.documentUriToNamespace(this.documentUri, modelStore.getIdType(id) == IdType.Anonymous), + CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), false), + CompatibleModelStoreWrapper.documentUriToNamespace(this.documentUri, false)); } public void setCopyManager(ModelCopyManager copyManager) { diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index d90569a50..0abdca170 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -109,7 +109,8 @@ public static Optional optionalStoredObjectToModelObject(Optional getAllItems(IModelStore modelStore, String typeFilter) throws InvalidSPDXAnalysisException { return modelStore.getAllItems(documentUri, typeFilter).map((TypedValue tv) -> { try { - return SpdxModelFactory.createModelObject(modelStore, documentUri, tv.getObjectUri(), tv.getType(), null); + return SpdxModelFactory.createModelObjectV2(modelStore, documentUri, tv.getObjectUri(), tv.getType(), null); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java index 05df56cdf..2256904a8 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java @@ -187,7 +187,7 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor } else if (token.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { throw new LicenseParserException("WITH must be followed by a license exception. "+token+" is a Listed License type."); } else { - licenseException = (ListedLicenseException) SpdxModelFactory.createModelObject(store, + licenseException = (ListedLicenseException) SpdxModelFactory.createModelObjectV2(store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, copyManager); } AnyLicenseInfo operand = operandStack.pop(); @@ -279,6 +279,7 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore // copy to the local store copyManager.copy(store, listedLicense.getObjectUri(), listedLicense.getModelStore(), listedLicense.getObjectUri(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, + listedLicense.getDocumentUri(), listedLicense.getDocumentUri(), listedLicense.getDocumentUri(), listedLicense.getDocumentUri()); } } @@ -294,7 +295,7 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore localLicense = new ExtractedLicenseInfo(store, documentUri, caseSensitiveId.get(), copyManager, false); } else { - localLicense = (ExtractedLicenseInfo) SpdxModelFactory.createModelObject( + localLicense = (ExtractedLicenseInfo) SpdxModelFactory.createModelObjectV2( store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); localLicense.setExtractedText(UNINITIALIZED_LICENSE_TEXT); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java index 47e232bd2..5acfcd292 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java @@ -189,11 +189,11 @@ public boolean isSpdxListedExceptionId(String exceptionId) { * @throws InvalidSPDXAnalysisException */ public SpdxListedLicense getListedLicenseById(String licenseId) throws InvalidSPDXAnalysisException { - return (SpdxListedLicense)SpdxModelFactory.createModelObject(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); + return (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); } public ListedLicenseException getListedExceptionById(String exceptionId) throws InvalidSPDXAnalysisException { - return (ListedLicenseException)SpdxModelFactory.createModelObject(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + return (ListedLicenseException)SpdxModelFactory.createModelObjectV2(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); } /** diff --git a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java index f5562a542..4b3b12c0d 100644 --- a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java +++ b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java @@ -101,6 +101,38 @@ public static String documentUriIdToUri(String documentUri, String id, boolean a public static TypedValue typedValueFromDocUri(String documentUri, String id, boolean anonymous, String type) throws SpdxInvalidIdException, SpdxInvalidTypeException { return new TypedValue(documentUriIdToUri(documentUri, id, anonymous), type); } + + /** + * @param store Store storing the objet URI + * @param objectUri Object URI + * @param documentUri SPDX 2 document URI for the ID + * @return the SPDX 2 compatible ID + * @throws InvalidSPDXAnalysisException + */ + public static String objectUriToId(IModelStore store, String objectUri, String documentUri) throws InvalidSPDXAnalysisException { + return objectUriToId(store.getIdType(objectUri) == IdType.Anonymous, objectUri, documentUri); + } + + /** + * @param anon true if the ID type is anonymous + * @param objectUri Object URI + * @param documentUri SPDX 2 document URI for the ID + * @return the SPDX 2 compatible ID + * @throws InvalidSPDXAnalysisException + */ + public static String objectUriToId(boolean anon, String objectUri, String documentUri) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(objectUri, "Object URI can not be null"); + if (anon) { + return objectUri; + } + Objects.requireNonNull(documentUri, "Document URI can not be null"); + String nameSpace = documentUri + "#"; + if (!objectUri.startsWith(nameSpace)) { + throw new InvalidSPDXAnalysisException("Object URI must start with document URI + #. DocumentUri: " + + documentUri + ", Object URI: "+objectUri); + } + return objectUri.substring(nameSpace.length()); + } @Override public boolean exists(String uri) { @@ -366,5 +398,17 @@ public SpdxMajorVersion getSpdxVersion() { public IModelStore getBaseModelStore() { return this.baseStore; } + + @Override + public boolean equals(Object comp) { + return super.equals(comp); + // TODO: Return true the base is equal since this contains no properties + } + + @Override + public int hashCode() { + //TODO: Update once equals is updated + return super.hashCode(); + } } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java index 87a5b9c7a..b7e05be77 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java @@ -188,7 +188,7 @@ public void testCompareTo() throws InvalidSPDXAnalysisException { public void testGetExternalDocRefByDocNamespace() throws InvalidSPDXAnalysisException { // need a document to tie the external refs to - SpdxModelFactory.createModelObject(gmo.getModelStore(), gmo.getDocumentUri(), + SpdxModelFactory.createModelObjectV2(gmo.getModelStore(), gmo.getDocumentUri(), SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, gmo.getCopyManager()); // test empty Optional result = ExternalDocumentRef.getExternalDocRefByDocNamespace(gmo.getModelStore(), gmo.getDocumentUri(), diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index d09a41c90..4b7a64510 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -170,7 +170,8 @@ public void testCopyIModelStoreStringIModelStoreStringStringString() throws Inva element1.setLicenseConcluded(externalLicense); element1.setName("ElementName"); copyManager.copy(store2, CompatibleModelStoreWrapper.documentUriIdToUri(docUri2, id2, false), store1, - CompatibleModelStoreWrapper.documentUriIdToUri(docUri1, id1, false), element1.getType(), docUri2, docUri1); + CompatibleModelStoreWrapper.documentUriIdToUri(docUri1, id1, false), element1.getType(), + docUri2, docUri1, docUri2, docUri1); GenericSpdxItem element2 = new GenericSpdxItem(store2, docUri2, id2, copyManager, false); assertTrue(element1.equivalent(element2)); assertTrue(element2.equivalent(element1)); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index 718965a50..ca6217568 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -40,7 +40,7 @@ public void testCreateSpdxDocument() throws InvalidSPDXAnalysisException { } public void testCreateModelObject() throws InvalidSPDXAnalysisException { - ModelObject result = SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, ID1, + ModelObject result = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); @@ -73,9 +73,9 @@ public void testTypeToClass() throws InvalidSPDXAnalysisException { @SuppressWarnings("unchecked") public void testGetElements() throws InvalidSPDXAnalysisException { - ModelObject file1 = SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, ID1, + ModelObject file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); - ModelObject file2 = SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, ID2, + ModelObject file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); try (Stream elementStream = (Stream)SpdxModelFactory.getElements(modelStore, DOCUMENT_URI, copyManager, SpdxFile.class)) { elementStream.forEach(element -> { diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java index 08ec80d67..166bef093 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSetTest.java @@ -70,7 +70,7 @@ public void testCreateConjunctive() throws InvalidSPDXAnalysisException { String id = modelStore.getNextId(IdType.Anonymous, DOCUMENT_URI); ConjunctiveLicenseSet cls = new ConjunctiveLicenseSet(modelStore, DOCUMENT_URI, id, copyManager, true); cls.setMembers(Arrays.asList(NON_STD_LICENSES)); - ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); + ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); List verify = cls2.verify(); assertEquals(0, verify.size()); @@ -93,7 +93,7 @@ public void testAddMember() throws InvalidSPDXAnalysisException { assertEquals(0, verify.size()); assertEquals(NON_STD_LICENSES.length+1, cls.getMembers().size()); assertTrue(cls.getMembers().contains(eli)); - ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); + ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length+1, cls2.getMembers().size()); assertTrue(cls2.getMembers().contains(eli)); @@ -110,7 +110,7 @@ public void testRemoveMember() throws InvalidSPDXAnalysisException { cls.removeMember(NON_STD_LICENSES[0]); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); - ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); + ConjunctiveLicenseSet cls2 = (ConjunctiveLicenseSet) SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java index 3a8db1c62..b721045cc 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/DisjunctiveLiceseSetTest.java @@ -70,7 +70,7 @@ public void testCreateDisjunctive() throws InvalidSPDXAnalysisException { String id = modelStore.getNextId(IdType.Anonymous, DOCUMENT_URI); DisjunctiveLicenseSet cls = new DisjunctiveLicenseSet(modelStore, DOCUMENT_URI, id, copyManager, true); cls.setMembers(Arrays.asList(NON_STD_LICENSES)); - DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, + DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); List verify = cls2.verify(); @@ -94,7 +94,7 @@ public void testAddMember() throws InvalidSPDXAnalysisException { assertEquals(0, verify.size()); assertEquals(NON_STD_LICENSES.length+1, cls.getMembers().size()); assertTrue(cls.getMembers().contains(eli)); - DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, id, + DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length+1, cls2.getMembers().size()); @@ -112,7 +112,7 @@ public void testRemoveMember() throws InvalidSPDXAnalysisException { cls.removeMember(NON_STD_LICENSES[0]); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); assertFalse(cls.getMembers().contains(NON_STD_LICENSES[0])); - DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObject(modelStore, DOCUMENT_URI, + DisjunctiveLicenseSet cls2 = (DisjunctiveLicenseSet) SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, id, SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, copyManager); assertTrue(cls.equals(cls2)); assertEquals(NON_STD_LICENSES.length-1, cls.getMembers().size()); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java index 8e34342b1..cffc5dfa7 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java @@ -92,9 +92,10 @@ public void testSPDXNonStandardLicenseModelNode() throws InvalidSPDXAnalysisExce DefaultModelStore.getDefaultModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(DefaultModelStore.getDefaultDocumentUri(), ID1, false), SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, + DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); assertEquals(ID1, lic2.getLicenseId()); assertEquals(TEXT1, lic2.getExtractedText()); assertEquals(COMMENT1, lic2.getComment()); @@ -119,14 +120,14 @@ public void testSPDXNonStandardLicenseStringString() throws InvalidSPDXAnalysisE public void testSetText() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setComment(COMMENT1); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setExtractedText(TEXT2); assertEquals(ID1, lic2.getLicenseId()); assertEquals(TEXT2, lic2.getExtractedText()); assertEquals(COMMENT1, lic2.getComment()); IModelStore modelStore = new InMemSpdxStore(); - ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, + ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic3.copyFrom(lic); assertEquals(TEXT2, lic3.getExtractedText()); @@ -140,7 +141,7 @@ public void testSetText() throws InvalidSPDXAnalysisException { public void testSetComment() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setComment(COMMENT1); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setComment(COMMENT2); assertEquals(ID1, lic2.getLicenseId()); @@ -148,7 +149,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { assertEquals(COMMENT2, lic2.getComment()); IModelStore modelStore = new InMemSpdxStore(); - ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), + ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic3.copyFrom(lic); assertEquals(COMMENT2, lic3.getComment()); @@ -160,11 +161,11 @@ public void testSetLicenseName() throws InvalidSPDXAnalysisException { IModelStore modelStore = new InMemSpdxStore(); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setName(LICENSENAME2); assertEquals(LICENSENAME2, lic2.getName()); - ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, + ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); assertEquals(LICENSENAME2, lic3.getName()); } @@ -176,13 +177,13 @@ public void testSetSourceUrls() throws InvalidSPDXAnalysisException { IModelStore modelStore = new InMemSpdxStore(); - ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, DefaultModelStore.getDefaultDocumentUri(), + ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic2.setSeeAlso(Arrays.asList(SOURCEURLS2)); if (!compareArrayContent(SOURCEURLS2, (String[])lic2.getSeeAlso().toArray(new String[lic2.getSeeAlso().size()]))) { fail("Source URLS not the same"); } - ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObject(modelStore, + ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); if (!compareArrayContent(SOURCEURLS2, (String[])lic3.getSeeAlso().toArray(new String[lic2.getSeeAlso().size()]))) { fail("Source URLS not the same"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java index d7ec97f7a..6b628d514 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java @@ -93,6 +93,7 @@ public void testCreateResource() throws InvalidSPDXAnalysisException { copyManager.copy(store, DefaultModelStore.getDefaultModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(SpdxConstantsCompatV2.LISTED_LICENSE_URL, EXCEPTION_ID1, false), SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, + SpdxConstantsCompatV2.LISTED_LICENSE_URL, SpdxConstantsCompatV2.LISTED_LICENSE_URL, SpdxConstantsCompatV2.LISTED_LICENSE_URL, SpdxConstantsCompatV2.LISTED_LICENSE_URL); LicenseException le2 = new LicenseException(store, DefaultModelStore.getDefaultDocumentUri(), EXCEPTION_ID1, copyManager, false); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java index d3d2fffbe..10b9c65d5 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/WithExceptionOperatorTest.java @@ -89,8 +89,9 @@ public void testCopy() throws InvalidSPDXAnalysisException { @SuppressWarnings("unused") TypedValue tv = copyManager.copy(store, weo1.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(weo1.getDocumentUri(), weo1.getId(), weo1.getModelStore()), - weo1.getType(), weo1.getDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); - WithExceptionOperator clone = (WithExceptionOperator) SpdxModelFactory.createModelObject(store, + weo1.getType(), weo1.getDocumentUri(), DefaultModelStore.getDefaultDocumentUri(), + weo1.getDocumentUri(), DefaultModelStore.getDefaultDocumentUri()); + WithExceptionOperator clone = (WithExceptionOperator) SpdxModelFactory.createModelObjectV2(store, DefaultModelStore.getDefaultDocumentUri(), weo1.getId(), SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, copyManager); ExtractedLicenseInfo lic1 = (ExtractedLicenseInfo)weo1.getLicense(); ExtractedLicenseInfo lic1FromClone = (ExtractedLicenseInfo)clone.getLicense(); diff --git a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java index c33df6184..f4d8f48c9 100644 --- a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java +++ b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java @@ -91,6 +91,23 @@ protected void tearDown() throws Exception { super.tearDown(); } + public void testObjectUriToIdIdToUri() throws InvalidSPDXAnalysisException { + CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); + String documentUri = "http://doc.uri"; + String nameSpace = documentUri + "#"; + String anonId = store.getNextId(IdType.Anonymous, documentUri); + String spdxId = store.getNextId(IdType.SpdxId, documentUri); + + String objectUriId = CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, spdxId, store); + assertEquals(nameSpace + spdxId, objectUriId); + assertEquals(spdxId, CompatibleModelStoreWrapper.objectUriToId(store, objectUriId, documentUri)); + + String anonUriId = CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, anonId, store); + assertEquals(anonId, anonUriId); + assertEquals(anonId, CompatibleModelStoreWrapper.objectUriToId(store, anonUriId, documentUri)); + + } + public void testUpdateNextIds() throws InvalidSPDXAnalysisException { CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); // License ID's @@ -349,7 +366,7 @@ public void copyFrom() throws InvalidSPDXAnalysisException { store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store2, store, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION, null, null); + copyManager.copy(store2, store, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION, null, null, null, null); assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_VALUE_PROPERTIES[0])); assertEquals(2, toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java index 59b6665ad..48d1f393b 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java @@ -170,7 +170,7 @@ public void testSetValue() throws Exception { public void testCreateLicense() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); + SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); assertEquals(APACHE_ID, result.getLicenseId()); assertEquals(APACHE_LICENSE_NAME, result.getName()); String licenseText = result.getLicenseText(); @@ -194,7 +194,7 @@ public void testCreateLicense() throws InvalidSPDXAnalysisException, InvalidLice public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - LicenseException result = (LicenseException)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + LicenseException result = (LicenseException)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); assertEquals(ECOS_EXCEPTION_ID, result.getLicenseExceptionId()); assertEquals(ECOS_EXCEPTION_ID, result.getId()); assertTrue(result.getComment().length() > 5); @@ -212,7 +212,7 @@ public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLi public void testList() throws InvalidSPDXAnalysisException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); // Exception - ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); String seeAlso1 = "seeAlso1"; String seeAlso2 = "seeAlso2"; List seeAlsos = Arrays.asList(new String[]{seeAlso1, seeAlso2}); @@ -245,7 +245,7 @@ public void testList() throws InvalidSPDXAnalysisException { // License ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObject(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); + SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); license.setSeeAlso(seeAlsos); // getValueList result.clear(); diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java index 1a725a117..b8bae4d99 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java @@ -193,7 +193,7 @@ public void testSetValue() throws Exception { public void testCreateLicense() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); + SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); assertEquals(APACHE_ID, result.getLicenseId()); assertEquals(APACHE_LICENSE_NAME, result.getName()); String licenseText = result.getLicenseText(); @@ -219,7 +219,7 @@ public void testCreateLicense() throws Exception { @SuppressWarnings("deprecation") public void testCreateException() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - LicenseException result = (LicenseException)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + LicenseException result = (LicenseException)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); assertEquals(ECOS_EXCEPTION_ID, result.getLicenseExceptionId()); assertEquals(ECOS_EXCEPTION_ID, result.getId()); assertTrue(result.getComment().length() > 5); @@ -240,7 +240,7 @@ public void testCreateException() throws Exception { public void testList() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); // Exception - ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); String seeAlso1 = "seeAlso1"; String seeAlso2 = "seeAlso2"; List seeAlsos = Arrays.asList(new String[]{seeAlso1, seeAlso2}); @@ -273,7 +273,7 @@ public void testList() throws Exception { // License ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObject(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); + SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); license.setSeeAlso(seeAlsos); // getValueList result.clear(); diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index 6c22868b0..906ed2ea6 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -320,7 +320,8 @@ public void testCopyFrom() throws Exception { store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store2, store, TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, TEST_NAMESPACE1, TEST_NAMESPACE2); + copyManager.copy(store2, store, TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, TEST_NAMESPACE1, + TEST_NAMESPACE2, TEST_NAMESPACE1, TEST_NAMESPACE2); assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); assertEquals(2, toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); assertTrue(toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); diff --git a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java index b1874588c..98056cb2a 100644 --- a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java +++ b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java @@ -33,6 +33,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.model.compat.v2.ModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** @@ -192,7 +193,11 @@ public static void copyObjectsToDoc(SpdxDocument doc, Collection Date: Mon, 19 Jun 2023 09:00:35 -0700 Subject: [PATCH 08/62] Completed support for compat V2 All unit tests now pass Signed-off-by: Gary O'Neall --- .../org/spdx/library/SpdxModelFactory.java | 81 ++++++++++++++++--- .../compat/v2/ModelStorageClassConverter.java | 3 +- .../v2/CompatibleModelStoreWrapper.java | 8 +- .../v2/ModelStorageClassConverterTest.java | 4 +- .../model/compat/v2/SpdxModelFactoryTest.java | 27 +++++++ .../utility/compare/SpdxComparerTest.java | 5 +- 6 files changed, 114 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index 76afdbd18..c04a9f97c 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -243,31 +243,94 @@ public static Class typeToClass(String type) throws InvalidSPD return typeToClass(type, SpdxMajorVersion.latestVersion()); } + /** + * @param store model store + * @param documentUri Document URI for the elements to fetch + * @param copyManager optional copy manager + * @param type SPDX V2 type to filter on + * @return stream of elements of the compatible version 2 types + * @throws InvalidSPDXAnalysisException + */ + public static Stream getElementsV2(IModelStore store, String documentUri, @Nullable ModelCopyManager copyManager, + String type) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(store, "Store must not be null"); + Objects.requireNonNull(type, "type must not be null"); + Objects.requireNonNull(documentUri, "Document URI can not be null for SPDX V2 elements"); + if (!SPDX_TYPE_TO_CLASS_V2.containsKey(type)) { + logger.error("Can not get elements for a non-SPDX version 2 type: "+type); + throw new InvalidSPDXAnalysisException("Can not get elements for a non-SPDX version 2 type: "+type); + } + return store.getAllItems(CompatibleModelStoreWrapper.documentUriToNamespace(documentUri, false), type).map(tv -> { + //TODO: Change this a null namespace and filtering on anonomous or startswith document URI - this will catch the anon. types + try { + boolean anon = store.getIdType(tv.getObjectUri()) == IdType.Anonymous; + return createModelObjectV2(store, documentUri, + CompatibleModelStoreWrapper.objectUriToId(anon, tv.getObjectUri(), documentUri), + tv.getType(), copyManager); + } catch (InvalidSPDXAnalysisException e) { + logger.error("Error creating model object",e); + throw new RuntimeException(e); + } + }); + } + /** * @param store model store * @param nameSpace optional namespace to filter elements on * @param copyManager optional copy manager - * @param spdxClass class to filter elements on - * @return + * @param type SPDX V2 type to filter on + * @return SPDX spec version 3 elements matching the namespace and class * @throws InvalidSPDXAnalysisException */ - public static Stream getElements(IModelStore store, @Nullable String nameSpace, @Nullable ModelCopyManager copyManager, - Class spdxClass) throws InvalidSPDXAnalysisException { + public static Stream getElementsV3(IModelStore store, @Nullable String nameSpace, @Nullable ModelCopyManager copyManager, + String type) throws InvalidSPDXAnalysisException { Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(spdxClass, "spdxClass must not be null"); - String type = SPDX_CLASS_TO_TYPE.get(spdxClass); - if (Objects.isNull(type)) { - throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); + Objects.requireNonNull(type, "type must not be null"); + if (!SPDX_TYPE_TO_CLASS_V3.containsKey(type)) { + logger.error("Can not get elements for a non-SPDX version 3 type: "+type); + throw new InvalidSPDXAnalysisException("Can not get elements for a non-SPDX version 3 type: "+type); } return store.getAllItems(nameSpace, type).map(tv -> { try { - return createModelObjectV2(store, nameSpace, tv.getObjectUri(), tv.getType(), copyManager); + return createModelObjectV2(store, nameSpace, + CompatibleModelStoreWrapper.objectUriToId(store.getIdType(tv.getObjectUri()) == IdType.Anonymous, tv.getObjectUri(), nameSpace), + tv.getType(), copyManager); } catch (InvalidSPDXAnalysisException e) { logger.error("Error creating model object",e); throw new RuntimeException(e); } }); } + + /** + * @param store model store + * @param nameSpace optional namespace to filter elements on + * @param copyManager optional copy manager + * @param spdxClass class to filter elements on + * @return a stream of elements matching the namespace and class + * @throws InvalidSPDXAnalysisException + */ + public static Stream getElements(IModelStore store, @Nullable String nameSpace, @Nullable ModelCopyManager copyManager, + Class spdxClass) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(store, "Store must not be null"); + Objects.requireNonNull(spdxClass, "spdxClass must not be null"); + String type = SPDX_CLASS_TO_TYPE.get(spdxClass); + if (Objects.isNull(type)) { + logger.error("Unknow SPDX class: "+spdxClass.toString()); + throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); + } + if (SPDX_TYPE_TO_CLASS_V3.containsKey(type)) { + return getElementsV3(store, nameSpace, copyManager, type); + } else if (SPDX_TYPE_TO_CLASS_V2.containsKey(type)) { + return getElementsV2(store, nameSpace.endsWith("#") ? nameSpace.substring(0, nameSpace.length()-1) : nameSpace, + copyManager, type); + } else { + logger.error("Unknow SPDX class: "+spdxClass.toString()); + throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); + } + } + + /** * @param classUri URI for the class type diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index 0abdca170..3af851c21 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -110,7 +110,8 @@ public static Optional optionalStoredObjectToModelObject(Optional result = ModelStorageClassConverter.optionalStoredObjectToModelObject(Optional.of(tv), gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result.isPresent()); assertTrue(result.get() instanceof Annotation); - assertEquals(tv.getObjectUri(), ((Annotation)result.get()).getId()); + assertEquals("SPDXRef-10", ((Annotation)result.get()).getId()); // Enum SimpleUriValue suv = new SimpleUriValue(ChecksumAlgorithm.MD5); result = ModelStorageClassConverter.optionalStoredObjectToModelObject(Optional.of(suv), gmo.getDocumentUri(), diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index ca6217568..d7c7fd553 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -97,6 +97,33 @@ public void testGetElements() throws InvalidSPDXAnalysisException { }); } } + + @SuppressWarnings("unchecked") + public void testGetElementsNamespace() throws InvalidSPDXAnalysisException { + ModelObject file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, + SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); + ModelObject file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, + SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); + try (Stream elementStream = (Stream)SpdxModelFactory.getElements(modelStore, DOCUMENT_URI + "#", copyManager, SpdxFile.class)) { + elementStream.forEach(element -> { + assertTrue(element instanceof SpdxFile); + SpdxFile result = (SpdxFile)element; + if (result.getId().equals(ID1)) { + try { + assertTrue(file1.equivalent(result)); + } catch (InvalidSPDXAnalysisException e) { + fail("Error: "+e.getMessage()); + } + } else { + try { + assertTrue(file2.equivalent(result)); + } catch (InvalidSPDXAnalysisException e) { + fail("Error: "+e.getMessage()); + } + } + }); + } + } public void testClassUriToClass() throws InvalidSPDXAnalysisException { assertEquals(Annotation.class, diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index de1534510..941715b65 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -67,7 +67,9 @@ import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; +import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -545,7 +547,8 @@ public void tearDown() throws Exception { } private SpdxDocument createTestSpdxDoc(String docUri) throws InvalidSPDXAnalysisException { - SpdxDocument retval = new SpdxDocument(docUri); + IModelStore newStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + SpdxDocument retval = new SpdxDocument(newStore, docUri, DefaultModelStore.getDefaultCopyManager(), true); Relationship docDescribesPackage = retval.createRelationship(pkgA1, RelationshipType.DESCRIBES, "Package1 describes"); retval.addRelationship(docDescribesPackage); From 00390133b9b9048530dc79d231b9ad10eaf29a2d Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 23 Jun 2023 11:21:11 -0700 Subject: [PATCH 09/62] Add a check for the correct model store spdx version Signed-off-by: Gary O'Neall --- .../v2 => }/DuplicateSpdxIdException.java | 4 +- .../org/spdx/library/NotEquivalentReason.java | 74 +++++++ .../org/spdx/library/model/ModelObject.java | 184 ++++++++++++++++++ .../library/model/compat/v2/ModelObject.java | 55 +----- .../spdx/library/model/core/package-info.java | 26 +++ .../org/spdx/library/model/package-info.java | 28 +++ .../SpdxListedLicenseModelStore.java | 2 +- .../spdx/storage/simple/InMemSpdxStore.java | 2 +- .../model/compat/v2/ModelObjectTest.java | 8 +- .../compat/v2/NoAssertionElementTest.java | 7 +- .../compat/v2/SpdxConstantElementTest.java | 4 + .../model/compat/v2/SpdxModelFactoryTest.java | 2 +- .../model/compat/v2/SpdxNoneElementTest.java | 2 +- .../model/compat/v2/license/CrossRefTest.java | 3 +- .../license/ExtractedLicensingInfoTest.java | 10 +- .../v2/license/LicenseExceptionTest.java | 2 +- .../v2/license/SpdxListedLicenseTest.java | 4 +- .../license/SpdxNoAssertionLicenseTest.java | 3 +- .../v2/license/SpdxNoneLicenseTest.java | 2 +- .../listedlicense/CrossRefJsonTest.java | 3 +- .../listedlicense/ExceptionJsonTOCTest.java | 3 +- .../listedlicense/ExceptionJsonTest.java | 3 +- .../listedlicense/LicenseJsonTOCTest.java | 3 +- 23 files changed, 358 insertions(+), 76 deletions(-) rename src/main/java/org/spdx/library/{model/compat/v2 => }/DuplicateSpdxIdException.java (93%) create mode 100644 src/main/java/org/spdx/library/NotEquivalentReason.java create mode 100644 src/main/java/org/spdx/library/model/ModelObject.java create mode 100644 src/main/java/org/spdx/library/model/core/package-info.java create mode 100644 src/main/java/org/spdx/library/model/package-info.java diff --git a/src/main/java/org/spdx/library/model/compat/v2/DuplicateSpdxIdException.java b/src/main/java/org/spdx/library/DuplicateSpdxIdException.java similarity index 93% rename from src/main/java/org/spdx/library/model/compat/v2/DuplicateSpdxIdException.java rename to src/main/java/org/spdx/library/DuplicateSpdxIdException.java index 39c95f4db..8e1de22b3 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/DuplicateSpdxIdException.java +++ b/src/main/java/org/spdx/library/DuplicateSpdxIdException.java @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.InvalidSPDXAnalysisException; +package org.spdx.library; /** * @author gary diff --git a/src/main/java/org/spdx/library/NotEquivalentReason.java b/src/main/java/org/spdx/library/NotEquivalentReason.java new file mode 100644 index 000000000..edaf564a5 --- /dev/null +++ b/src/main/java/org/spdx/library/NotEquivalentReason.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import org.spdx.storage.PropertyDescriptor; + +/** + * @author Gary O'Neall + * + * Primarily used for debugging. Records details when two model objects are compared and are determined to not + * be equivalent + * + */ +public class NotEquivalentReason { + + public enum NotEquivalent { + DIFFERENT_CLASS, MISSING_PROPERTY, PROPERTY_NOT_EQUIVALENT, COMPARE_PROPERTY_MISSING}; + + NotEquivalent reason; + PropertyDescriptor property = null; + + public NotEquivalentReason(NotEquivalent reason) { + this.reason = reason; + } + + public NotEquivalentReason(NotEquivalent reason, PropertyDescriptor property) { + this(reason); + this.property = property; + } + + /** + * @return the reason + */ + public NotEquivalent getReason() { + return reason; + } + + /** + * @param reason the reason to set + */ + public void setReason(NotEquivalent reason) { + this.reason = reason; + } + + /** + * @return the property + */ + public PropertyDescriptor getProperty() { + return property; + } + + /** + * @param property the property to set + */ + public void setProperty(PropertyDescriptor property) { + this.property = property; + } + +} diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java new file mode 100644 index 000000000..1d67bb29a --- /dev/null +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -0,0 +1,184 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.NotEquivalentReason; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.TypedValue; +import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IModelStoreLock; +import org.spdx.storage.IModelStore.IdType; + +/** + * @author Gary O'Neall + * + * Superclass for all SPDX model objects + * + * Provides the primary interface to the storage class that access and stores the data for + * the model objects. + * + * This class includes several helper methods to manage the storage and retrieval of properties. + * + * Each model object is in itself stateless. All state is maintained in the Model Store. + * + * The concrete classes are expected to implements getters for the model class properties which translate + * into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property descriptor + * is passed as a parameter. + * + * There are 2 methods of setting values: + * - call the setPropertyValue, clearValueCollection or addValueToCollection methods - this will call the modelStore and store the + * value immediately + * - Gather a list of updates by calling the updatePropertyValue, updateClearValueList, or updateAddPropertyValue + * methods. These methods return a ModelUpdate which can be applied later by calling the apply() method. + * A convenience method Write.applyUpdatesInOneTransaction will perform all updates within + * a single transaction. This method may result in higher performance updates for some Model Store implementations. + * Note that none of the updates will be applied until the storage manager update method is invoked. + * + * Property values are restricted to the following types: + * - String - Java Strings + * - Booolean - Java Boolean or primitive boolean types + * - ModelObject - A concrete subclass of this type + * - {@literal Collection} - A Collection of type T where T is one of the supported non-collection types + * + * This class also handles the conversion of a ModelObject to and from a TypeValue for storage in the ModelStore. + * + */ +public abstract class ModelObject { + + static final Logger logger = LoggerFactory.getLogger(ModelObject.class); + private IModelStore modelStore; + private String objectUri; + + /** + * If non null, a reference made to a model object stored in a different modelStore and/or + * document will be copied to this modelStore and documentUri + */ + private ModelCopyManager copyManager = null; + /** + * if true, checks input values for setters to verify valid SPDX inputs + */ + protected boolean strict = true; + + NotEquivalentReason lastNotEquivalentReason = null; + + /** + * Create a new Model Object using an Anonymous ID with the defualt store and default document URI + * @throws InvalidSPDXAnalysisException + */ + public ModelObject() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); + } + + /** + * Open or create a model object with the default store and default document URI + * @param objectUri Anonymous ID or URI for the model object + * @throws InvalidSPDXAnalysisException + */ + public ModelObject(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, + DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * Creates a new model object + * @param modelStore Storage for the model objects - Must support model V3 classes + * @param objectUri Anonymous ID or URI for the model object + * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods + * @param create - if true, the object will be created in the store if it is not already present + * @throws InvalidSPDXAnalysisException + */ + public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model Store can not be null"); + Objects.requireNonNull(objectUri, "Object URI can not be null"); + + if (!SpdxMajorVersion.VERSION_3.equals(modelStore.getSpdxVersion())) { + logger.error("Trying to create an SPDX version 3 model object in an SPDX version 2 model store"); + throw new InvalidSPDXAnalysisException("Trying to create an SPDX version 3 model object in an SPDX version 2 model store"); + } + this.modelStore = modelStore; + this.copyManager = copyManager; + Optional existing = modelStore.getTypedValue(objectUri); + if (existing.isPresent()) { + if (create && !existing.get().getType().equals(getType())) { + logger.error("Can not create "+objectUri+". It is already in use with type "+existing.get().getType()+" which is incompatible with type "+getType()); + throw new SpdxIdInUseException("Can not create "+objectUri+". It is already in use with type "+existing.get().getType()+" which is incompatible with type "+getType()); + } + } else { + if (create) { + IModelStoreLock lock = enterCriticalSection(false); + // re-check since previous check was done outside of the lock + try { + if (!modelStore.exists(objectUri)) { + modelStore.create(objectUri, getType()); + } + } finally { + lock.unlock(); + } + } else { + logger.error(objectUri+" does not exist"); + throw new SpdxIdNotFoundException(objectUri+" does not exist"); + } + } + } + + // Abstract methods that must be implemented in the subclasses + /** + * @return The class name for this object. Class names are defined in the constants file + */ + public abstract String getType(); + + /** + * Implementation of the specific verifications for this model object + * @param specVersion Version of the SPDX spec to verify against + * @param verifiedElementIds list of all Element Id's which have already been verified - prevents infinite recursion + * @return Any verification errors or warnings associated with this object + */ + protected abstract List _verify(Set verifiedElementIds, String specVersion); + + /** + * Enter a critical section. leaveCriticialSection must be called. + * @param readLockRequested true implies a read lock, false implies write lock. + * @throws InvalidSPDXAnalysisException + */ + public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { + return modelStore.enterCriticalSection(readLockRequested); + } + + /** + * Leave a critical section. Releases the lock form the matching enterCriticalSection + */ + public void leaveCriticalSection(IModelStoreLock lock) { + modelStore.leaveCriticalSection(lock); + } + +} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 17ca084a5..42c8d195f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -33,7 +33,10 @@ import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.NotEquivalentReason; +import org.spdx.library.NotEquivalentReason.NotEquivalent; import org.spdx.library.SimpleUriValue; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxInvalidTypeException; @@ -68,7 +71,7 @@ /** * @author Gary O'Neall * - * Superclass for all SPDX model objects + * Superclass for all SPDX spec version 2 model objects * * Provides the primary interface to the storage class that access and stores the data for * the model objects. @@ -119,52 +122,6 @@ public abstract class ModelObject { */ protected boolean strict = true; - // the following fields are for debugging when equivalent returns false - enum NotEquivalent { - DIFFERENT_CLASS, MISSING_PROPERTY, PROPERTY_NOT_EQUIVALENT, COMPARE_PROPERTY_MISSING}; - static class NotEquivalentReason { - NotEquivalent reason; - PropertyDescriptor property = null; - - public NotEquivalentReason(NotEquivalent reason) { - this.reason = reason; - } - - public NotEquivalentReason(NotEquivalent reason, PropertyDescriptor property) { - this(reason); - this.property = property; - } - - /** - * @return the reason - */ - public NotEquivalent getReason() { - return reason; - } - - /** - * @param reason the reason to set - */ - public void setReason(NotEquivalent reason) { - this.reason = reason; - } - - /** - * @return the property - */ - public PropertyDescriptor getProperty() { - return property; - } - - /** - * @param property the property to set - */ - public void setProperty(PropertyDescriptor property) { - this.property = property; - } - } - - NotEquivalentReason lastNotEquivalentReason = null; @@ -199,6 +156,10 @@ public ModelObject(IModelStore modelStore, String documentUri, String identifier Objects.requireNonNull(modelStore, "Model Store can not be null"); Objects.requireNonNull(documentUri, "Document URI can not be null"); Objects.requireNonNull(identifier, "ID can not be null"); + if (!SpdxMajorVersion.VERSION_2.equals(modelStore.getSpdxVersion())) { + logger.error("Trying to create an SPDX version 2 model object in an SPDX version 3 model store"); + throw new InvalidSPDXAnalysisException("Trying to create an SPDX version 2 model object in an SPDX version 3 model store"); + } if (identifier.startsWith(documentUri)) { logger.warn("document URI was passed in as an ID: "+identifier); this.id = identifier.substring(documentUri.length()); diff --git a/src/main/java/org/spdx/library/model/core/package-info.java b/src/main/java/org/spdx/library/model/core/package-info.java new file mode 100644 index 000000000..68e847a8c --- /dev/null +++ b/src/main/java/org/spdx/library/model/core/package-info.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Classes for the implementation of the SPDX Core Profile + * + * The Core namespace defines foundational concepts serving as the basis for all SPDX-3.0 profiles. + * + * @author Gary O'Neall + * + */ +package org.spdx.library.model.core; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/package-info.java b/src/main/java/org/spdx/library/model/package-info.java new file mode 100644 index 000000000..2c7a4cb64 --- /dev/null +++ b/src/main/java/org/spdx/library/model/package-info.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Classes for the implementation of the SPDX Version 3 specification + * + * Sub packages are named by profile + * + * All model objects inherit the ModelObject abstract class which contains useful helper functions + * + * @author Gary O'Neall + * + */ +package org.spdx.library.model; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index b4a1146c3..05cd5dcc3 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -38,12 +38,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.spdx.library.DuplicateSpdxIdException; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.DuplicateSpdxIdException; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.SpdxListedLicenseException; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index 199b62882..d30a081a1 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -38,12 +38,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.spdx.library.DuplicateSpdxIdException; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.DuplicateSpdxIdException; import org.spdx.library.model.compat.v2.ModelCollection; import org.spdx.library.model.compat.v2.SpdxIdInUseException; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index 37f173148..636d209c3 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -284,7 +284,7 @@ public void testGetId() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getModelStore()}. */ public void testGetModelStore() throws InvalidSPDXAnalysisException { - InMemSpdxStore store = new InMemSpdxStore(); + InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); assertEquals(store, gmo.getModelStore()); } @@ -682,7 +682,7 @@ public void testEquivalentModelObjectProp() throws InvalidSPDXAnalysisException assertEquals(text, licenseText); assertTrue(gmo.equivalent(gmo)); // different store - InMemSpdxStore store2 = new InMemSpdxStore(); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); GenericModelObject gmo3 = new GenericModelObject(store2, docUri, TEST_ID, copyManager, true); gmo3.setPropertyValue(prop, eli2); assertTrue(gmo.equivalent(gmo3)); @@ -715,7 +715,7 @@ public void testEquivalentModelObjectList() throws InvalidSPDXAnalysisException assertTrue(gmo.equivalent(gmo2)); assertTrue(gmo2.equivalent(gmo)); // different store - InMemSpdxStore store2 = new InMemSpdxStore(); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); GenericModelObject gmo3 = new GenericModelObject(store2, docUri, TEST_ID, copyManager, true); gmo3.addPropertyValueToCollection(prop, eli2); gmo3.addPropertyValueToCollection(prop, nextEli2); @@ -757,7 +757,7 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { assertFalse(gmo.equals(gmo2)); assertFalse(gmo2.equals(gmo)); // same ID's, different store - InMemSpdxStore store2 = new InMemSpdxStore(); + InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); GenericModelObject gmo3 = new GenericModelObject(store2, docUri, TEST_ID, copyManager, true); addTestValues(gmo3); assertTrue(gmo.equals(gmo3)); diff --git a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java index da9b22ccd..28bbf383e 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java @@ -49,9 +49,10 @@ protected void tearDown() throws Exception { } public void testHashCodeEquals() throws InvalidSPDXAnalysisException { - SpdxNoAssertionElement e1 = new SpdxNoAssertionElement(); - IModelStore store = new InMemSpdxStore(); - SpdxNoAssertionElement e2 = new SpdxNoAssertionElement(store, "https://doc.uri"); + IModelStore store1 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + SpdxNoAssertionElement e1 = new SpdxNoAssertionElement(store1, "https://doc.uri1"); + IModelStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + SpdxNoAssertionElement e2 = new SpdxNoAssertionElement(store2, "https://doc.uri2"); assertEquals(e1.hashCode(), e2.hashCode()); assertEquals(e1, e2); assertTrue(e1.equals(e2)); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java index 0dea69e19..5b10e12e1 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxConstantElementTest.java @@ -19,7 +19,9 @@ import java.util.ArrayList; +import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import junit.framework.TestCase; @@ -34,12 +36,14 @@ public class SpdxConstantElementTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) * @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception { + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); super.tearDown(); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index d7c7fd553..38342ab86 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -26,7 +26,7 @@ public class SpdxModelFactoryTest extends TestCase { protected void setUp() throws Exception { super.setUp(); - modelStore = new InMemSpdxStore(); + modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); copyManager = new ModelCopyManager(); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java index 195d67774..c290a31eb 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java @@ -50,7 +50,7 @@ protected void tearDown() throws Exception { public void testHashCodeEquals() throws InvalidSPDXAnalysisException { SpdxNoneElement e1 = new SpdxNoneElement(); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxNoneElement e2 = new SpdxNoneElement(store, "https://doc.uri"); assertEquals(e1.hashCode(), e2.hashCode()); assertEquals(e1, e2); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java index 7bb43d2e8..542e47c96 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/CrossRefTest.java @@ -3,6 +3,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -34,7 +35,7 @@ public class CrossRefTest extends TestCase { public void setUp() throws Exception { super.setUp(); - modelStore = new InMemSpdxStore(); + modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); copyManager = new ModelCopyManager(); TEST_CROSSREF = new CrossRef.CrossRefBuilder(modelStore, DOCUMENT_URI, modelStore.getNextId(IdType.Anonymous, DOCUMENT_URI), copyManager, TEST_URL1) diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java index cffc5dfa7..3e0078284 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExtractedLicensingInfoTest.java @@ -126,7 +126,7 @@ public void testSetText() throws InvalidSPDXAnalysisException { assertEquals(ID1, lic2.getLicenseId()); assertEquals(TEXT2, lic2.getExtractedText()); assertEquals(COMMENT1, lic2.getComment()); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic3.copyFrom(lic); @@ -148,7 +148,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { assertEquals(TEXT1, lic2.getExtractedText()); assertEquals(COMMENT2, lic2.getComment()); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ExtractedLicenseInfo lic3 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), ID1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, DefaultModelStore.getDefaultCopyManager()); lic3.copyFrom(lic); @@ -158,7 +158,7 @@ public void testSetComment() throws InvalidSPDXAnalysisException { public void testSetLicenseName() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setName(LICENSENAME1); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, @@ -174,7 +174,7 @@ public void testSetLicenseName() throws InvalidSPDXAnalysisException { public void testSetSourceUrls() throws InvalidSPDXAnalysisException { ExtractedLicenseInfo lic = new ExtractedLicenseInfo(ID1, TEXT1); lic.setSeeAlso(Arrays.asList(SOURCEURLS1)); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); ExtractedLicenseInfo lic2 = (ExtractedLicenseInfo)SpdxModelFactory.createModelObjectV2(modelStore, DefaultModelStore.getDefaultDocumentUri(), @@ -221,7 +221,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { lic.setSeeAlso(Arrays.asList(SOURCEURLS1)); lic.setComment(COMMENT1); assertTrue(lic.equivalent(lic)); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri2 = "https://second.doc.uri"; ExtractedLicenseInfo lic2 = new ExtractedLicenseInfo(modelStore, docUri2, ID1, DefaultModelStore.getDefaultCopyManager(), true); lic2.setExtractedText(TEXT1+" "); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java index 6b628d514..722c6beed 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExceptionTest.java @@ -346,7 +346,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { EXCEPTION_NAME1, EXCEPTION_TEXT1, EXCEPTION_TEMPLATE1, EXCEPTION_SEEALSO1, EXCEPTION_COMMENT1); assertTrue(le.equivalent(le)); - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); LicenseException le2 = new LicenseException(modelStore, "http://newDocUri", EXCEPTION_ID1, DefaultModelStore.getDefaultCopyManager(), true); le2.setName(EXCEPTION_NAME1); le2.setLicenseExceptionText(EXCEPTION_TEXT1); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java index 0adea1817..1867f0e25 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseTest.java @@ -226,7 +226,7 @@ public void testCopyOf() throws InvalidSPDXAnalysisException, InvalidLicenseTemp String deprecatedVersion = "3.5"; SpdxListedLicense stdl = new SpdxListedLicense(name, id, text, sourceUrls, notes, standardLicenseHeader, template, true, null, licenseHtml, true, deprecatedVersion); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxListedLicense lic2 = new SpdxListedLicense(store, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, stdl.getCopyManager(), true); lic2.copyFrom(stdl); @@ -281,7 +281,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { SpdxListedLicense stdl = new SpdxListedLicense(name, id, text, sourceUrls, notes, standardLicenseHeader, template, true,null, null, false, null); assertTrue(stdl.equivalent(stdl)); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxListedLicense stdl2 = new SpdxListedLicense(store, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, stdl.getCopyManager(), true); stdl2.setLicenseText(text2); stdl2.setName(name2); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java index a9ce2e0c5..7564f8871 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicenseTest.java @@ -1,6 +1,7 @@ package org.spdx.library.model.compat.v2.license; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -18,7 +19,7 @@ protected void tearDown() throws Exception { public void testHashCodeEquals() throws InvalidSPDXAnalysisException { SpdxNoAssertionLicense l1 = new SpdxNoAssertionLicense(); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxNoAssertionLicense l2 = new SpdxNoAssertionLicense(store, "https://doc.uri"); assertEquals(l1.hashCode(), l2.hashCode()); assertEquals(l1, l2); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java index 5150e0170..dbc7fb5f6 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicenseTest.java @@ -23,7 +23,7 @@ protected void tearDown() throws Exception { public void testHashCodeEquals() throws InvalidSPDXAnalysisException { SpdxNoneLicense l1 = new SpdxNoneLicense(); - IModelStore store = new InMemSpdxStore(); + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); SpdxNoneLicense l2 = new SpdxNoneLicense(store, "https://doc.uri"); assertEquals(l1.hashCode(), l2.hashCode()); assertEquals(l1, l2); diff --git a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java index e89c0c77c..3ab53416e 100644 --- a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java @@ -10,6 +10,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.license.CrossRef; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -48,7 +49,7 @@ protected void tearDown() throws Exception { } public void testCrossRefJsonCrossRef() throws InvalidSPDXAnalysisException { - IModelStore modelStore = new InMemSpdxStore(); + IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://doc/uri"; String id = "tempid"; String url = "http://url"; diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java index 355129b9c..b30d22d7f 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Objects; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.license.ListedLicenseException; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -83,7 +84,7 @@ public void testGetReleaseDate() { */ public void testAddException() throws Exception { ExceptionJsonTOC ejt = new ExceptionJsonTOC(); - InMemSpdxStore store = new InMemSpdxStore(); + InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://temp.doc.uri"; String detailsUrl1 = "http://details1"; String exceptionId1 = "id1"; diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java index 3b522509d..592b1ac02 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java @@ -26,6 +26,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.InvalidSpdxPropertyException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.license.ListedLicenseException; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -278,7 +279,7 @@ public void testIsPropertyValueAssignableTo() throws Exception { @SuppressWarnings("deprecation") public void testCopyFrom() throws Exception { - InMemSpdxStore store = new InMemSpdxStore(); + InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://temp.uri"; String exceptionId = "exceptionId"; String comment = "comment"; diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java index 97263368a..70b45a67a 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java @@ -23,6 +23,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -86,7 +87,7 @@ public void testGetReleaseDate() { */ public void testAddLicense() throws InvalidSPDXAnalysisException { LicenseJsonTOC ljt = new LicenseJsonTOC(); - InMemSpdxStore store = new InMemSpdxStore(); + InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); String docUri = "http://docuri.temp1"; String licenseId1 = "licenseId1"; String licHTMLReference1 = "./licHTMLReference1"; From e6c53b569d2df4b7f726f62672c325b53b6cf751 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Tue, 27 Jun 2023 05:04:39 -0700 Subject: [PATCH 10/62] Intermediate commit - implement v3 model object core Unit tests are currently placeholders Signed-off-by: Gary O'Neall --- .../java/org/spdx/library/SimpleUriValue.java | 3 +- .../java/org/spdx/library/SpdxConstants.java | 8 + .../compat/v2 => }/SpdxIdInUseException.java | 4 +- .../org/spdx/library/SpdxModelFactory.java | 144 ++-- .../spdx/library/SpdxVerificationHelper.java | 2 +- .../library/model/GenericModelObject.java | 85 ++ .../spdx/library/model/ModelCollection.java | 294 +++++++ .../org/spdx/library/model/ModelObject.java | 736 +++++++++++++++++- .../spdx/library/model/ModelObjectHelper.java | 306 ++++++++ .../java/org/spdx/library/model/ModelSet.java | 99 +++ .../library/model/compat/v2/Annotation.java | 2 +- .../library/model/compat/v2/Checksum.java | 2 +- .../model/compat/v2/ExternalDocumentRef.java | 8 +- .../library/model/compat/v2/ExternalRef.java | 2 +- .../model/compat/v2/ExternalSpdxElement.java | 4 +- .../model/compat/v2/GenericModelObject.java | 4 +- ...Collection.java => ModelCollectionV2.java} | 10 +- .../library/model/compat/v2/ModelObject.java | 39 +- .../library/model/compat/v2/ModelSet.java | 2 +- .../compat/v2/ModelStorageClassConverter.java | 3 - .../compat/v2/RelatedElementCollection.java | 9 +- .../library/model/compat/v2/Relationship.java | 2 +- .../library/model/compat/v2/SpdxDocument.java | 2 +- .../library/model/compat/v2/SpdxFile.java | 4 +- .../library/model/compat/v2/SpdxPackage.java | 6 +- .../v2/SpdxPackageVerificationCode.java | 2 +- .../library/model/compat/v2/SpdxSnippet.java | 2 +- .../model/compat/v2/license/package-info.java | 2 +- .../org/spdx/library/model/core/Element.java | 72 ++ .../org/spdx/library/model/core/Payload.java | 66 ++ .../v2 => }/enumerations/AnnotationType.java | 2 +- .../enumerations/ChecksumAlgorithm.java | 2 +- .../v2 => }/enumerations/FileType.java | 2 +- .../{compat/v2 => }/enumerations/Purpose.java | 2 +- .../enumerations/ReferenceCategory.java | 2 +- .../enumerations/RelationshipType.java | 2 +- .../v2 => }/enumerations/SpdxEnumFactory.java | 2 +- .../v2 => }/enumerations/package-info.java | 2 +- .../model/licensing/AnyLicenseInfo.java | 75 ++ .../licensing/package-info.java} | 11 +- .../spdx/storage/simple/InMemSpdxStore.java | 6 +- .../spdx/storage/simple/StoredTypedItem.java | 2 +- .../compare/SpdxExternalRefDifference.java | 2 +- .../utility/compare/SpdxFileDifference.java | 2 +- .../compat/v2 => }/SpdxModelFactoryTest.java | 53 +- .../library/SpdxVerificationHelperTest.java | 2 +- .../library/model/ModelCollectionTest.java | 155 ++++ .../library/model/ModelObjectHelperTest.java | 133 ++++ .../spdx/library/model/ModelObjectTest.java | 294 +++++++ .../{compat/v2 => }/SimpleUriValueTest.java | 26 +- .../model/compat/v2/AnnotationTest.java | 2 +- .../library/model/compat/v2/ChecksumTest.java | 2 +- .../compat/v2/ExternalDocumentRefTest.java | 2 +- .../model/compat/v2/ExternalRefTest.java | 2 +- .../compat/v2/ExternalSpdxElementTest.java | 4 +- .../compat/v2/IndividualUriValueTest.java | 2 +- .../model/compat/v2/ModelCollectionTest.java | 22 +- .../model/compat/v2/ModelObjectTest.java | 14 +- .../v2/ModelStorageClassConverterTest.java | 6 +- .../compat/v2/NoAssertionElementTest.java | 2 +- .../v2/RelatedElementCollectionTest.java | 2 +- .../model/compat/v2/RelationshipTest.java | 6 +- .../model/compat/v2/SpdxDocumentTest.java | 8 +- .../model/compat/v2/SpdxElementTest.java | 4 +- .../library/model/compat/v2/SpdxFileTest.java | 8 +- .../model/compat/v2/SpdxNoneElementTest.java | 2 +- .../model/compat/v2/SpdxPackageTest.java | 12 +- .../model/compat/v2/SpdxSnippetTest.java | 4 +- .../v2/license/ExternalLicenseRefTest.java | 2 +- .../license/LicenseExpressionParserTest.java | 2 +- .../v2/CompatibleModelStoreWrapperTest.java | 2 +- .../storage/simple/InMemSpdxStoreTest.java | 2 +- .../utility/compare/SpdxComparerTest.java | 8 +- .../utility/compare/SpdxFileComparerTest.java | 4 +- .../utility/compare/SpdxItemComparerTest.java | 4 +- .../compare/SpdxPackageComparerTest.java | 10 +- .../compare/SpdxSnippetComparerTest.java | 6 +- .../VerificationCodeGeneratorTest.java | 4 +- 78 files changed, 2629 insertions(+), 220 deletions(-) rename src/main/java/org/spdx/library/{model/compat/v2 => }/SpdxIdInUseException.java (93%) create mode 100644 src/main/java/org/spdx/library/model/GenericModelObject.java create mode 100644 src/main/java/org/spdx/library/model/ModelCollection.java create mode 100644 src/main/java/org/spdx/library/model/ModelObjectHelper.java create mode 100644 src/main/java/org/spdx/library/model/ModelSet.java rename src/main/java/org/spdx/library/model/compat/v2/{ModelCollection.java => ModelCollectionV2.java} (96%) create mode 100644 src/main/java/org/spdx/library/model/core/Element.java create mode 100644 src/main/java/org/spdx/library/model/core/Payload.java rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/AnnotationType.java (96%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/ChecksumAlgorithm.java (97%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/FileType.java (96%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/Purpose.java (96%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/ReferenceCategory.java (96%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/RelationshipType.java (98%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/SpdxEnumFactory.java (97%) rename src/main/java/org/spdx/library/model/{compat/v2 => }/enumerations/package-info.java (94%) create mode 100644 src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java rename src/main/java/org/spdx/library/{ModelObjectHelper.java => model/licensing/package-info.java} (72%) rename src/test/java/org/spdx/library/{model/compat/v2 => }/SpdxModelFactoryTest.java (81%) create mode 100644 src/test/java/org/spdx/library/model/ModelCollectionTest.java create mode 100644 src/test/java/org/spdx/library/model/ModelObjectHelperTest.java create mode 100644 src/test/java/org/spdx/library/model/ModelObjectTest.java rename src/test/java/org/spdx/library/model/{compat/v2 => }/SimpleUriValueTest.java (78%) diff --git a/src/main/java/org/spdx/library/SimpleUriValue.java b/src/main/java/org/spdx/library/SimpleUriValue.java index 30cbe4df5..cb4a97654 100644 --- a/src/main/java/org/spdx/library/SimpleUriValue.java +++ b/src/main/java/org/spdx/library/SimpleUriValue.java @@ -98,8 +98,9 @@ public Object toModelObject(IModelStore store, ModelCopyManager copyManager, @Nu throw new InvalidSPDXAnalysisException("Not implemented"); } } + private Object toModelObjectV2Compat(IModelStore store, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Object retval = org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory.uriToEnum.get(uri); + Object retval = org.spdx.library.model.enumerations.SpdxEnumFactory.uriToEnum.get(uri); if (Objects.nonNull(retval)) { return retval; } else if (SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri).matches()) { diff --git a/src/main/java/org/spdx/library/SpdxConstants.java b/src/main/java/org/spdx/library/SpdxConstants.java index 33da39733..ba127e589 100644 --- a/src/main/java/org/spdx/library/SpdxConstants.java +++ b/src/main/java/org/spdx/library/SpdxConstants.java @@ -17,6 +17,8 @@ */ package org.spdx.library; +import org.spdx.storage.PropertyDescriptor; + /** * Constants which map to the SPDX specifications * @author Gary O'Neall @@ -34,4 +36,10 @@ public static SpdxMajorVersion latestVersion() { } } + /** + * Core namespace + */ + public static final String CORE_NAMESPACE = "https://rdf.spdx.org/v3/Core"; + public static final PropertyDescriptor CORE_PROP_RELATED_SPDX_ELEMENT = new PropertyDescriptor("to", CORE_NAMESPACE); + } diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxIdInUseException.java b/src/main/java/org/spdx/library/SpdxIdInUseException.java similarity index 93% rename from src/main/java/org/spdx/library/model/compat/v2/SpdxIdInUseException.java rename to src/main/java/org/spdx/library/SpdxIdInUseException.java index 3d9e87973..aeb9d4687 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxIdInUseException.java +++ b/src/main/java/org/spdx/library/SpdxIdInUseException.java @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.InvalidSPDXAnalysisException; +package org.spdx.library; /** * Exception when an SPDX element is in use (e.g. exception thrown when attempting to delete) diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index c04a9f97c..5526a14d2 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -18,10 +18,14 @@ package org.spdx.library; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; @@ -92,13 +96,13 @@ public class SpdxModelFactory { typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, org.spdx.library.model.compat.v2.pointer.CompoundPointer.class); typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, org.spdx.library.model.compat.v2.pointer.SinglePointer.class); typeToClassV2.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, org.spdx.library.model.compat.v2.license.CrossRef.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.compat.v2.enumerations.FileType.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.compat.v2.enumerations.AnnotationType.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.compat.v2.enumerations.ReferenceCategory.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.compat.v2.enumerations.RelationshipType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.enumerations.FileType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.enumerations.AnnotationType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.enumerations.ChecksumAlgorithm.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.enumerations.ReferenceCategory.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.enumerations.RelationshipType.class); typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.compat.v2.enumerations.Purpose.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.enumerations.Purpose.class); SPDX_TYPE_TO_CLASS_V2 = Collections.unmodifiableMap(typeToClassV2); Map> typeToClassV3 = new HashMap<>(); //TODO Add V3 class strings @@ -114,6 +118,51 @@ public class SpdxModelFactory { SPDX_CLASS_TO_TYPE = Collections.unmodifiableMap(classToType); } + /** + * Create an SPDX spec version 3 model object in a model store given the document URI, ID and type + * @param modelStore model store where the object is to be created + * @param objectUri Object URI or anonymous ID + * @param type SPDX class or type + * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced + * @param create if true, create the model object if it does not already exist + * @return a ModelObject of type type + * @throws InvalidSPDXAnalysisException + */ + public static ModelObject getModelObject(IModelStore modelStore, String objectUri, + String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model store can not be null"); + Objects.requireNonNull(objectUri, "An object URI or anonymous ID must be supplied for all SPDX version 2 model objects"); + + Class clazz = SPDX_TYPE_TO_CLASS_V3.get(type); + if (Objects.isNull(clazz)) { + throw new InvalidSPDXAnalysisException("Unknown SPDX version 3 type: "+type); + } + if (Modifier.isAbstract(clazz.getModifiers())) { + throw new InvalidSPDXAnalysisException("Can not instantiate an abstract class for the SPDX version 3 type: "+type); + } + try { + Constructor con = clazz.getDeclaredConstructor(IModelStore.class, String.class, ModelCopyManager.class, boolean.class); + return (ModelObject)con.newInstance(modelStore, objectUri, copyManager, create); + } catch (NoSuchMethodException e) { + throw new InvalidSPDXAnalysisException("Could not create the model object SPDX version 3 type: "+type); + } catch (SecurityException e) { + throw new InvalidSPDXAnalysisException("Unexpected security exception for SPDX version 3 type: "+type, e); + } catch (InstantiationException e) { + throw new InvalidSPDXAnalysisException("Unexpected instantiation exception for SPDX version 3 type: "+type, e); + } catch (IllegalAccessException e) { + throw new InvalidSPDXAnalysisException("Unexpected illegal access exception for SPDX version 3 type: "+type, e); + } catch (IllegalArgumentException e) { + throw new InvalidSPDXAnalysisException("Unexpected illegal argument exception for SPDX version 2 type: "+type, e); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof InvalidSPDXAnalysisException) { + throw (InvalidSPDXAnalysisException)e.getTargetException(); + } else { + throw new InvalidSPDXAnalysisException("Unexpected invocation target exception for SPDX version 3 type: "+type, e); + } + } + } + + /** * Create an SPDX version 2.X document with default values for creator, created, licenseListVersion, data license and specVersion @@ -170,48 +219,43 @@ public static org.spdx.library.model.compat.v2.ModelObject getModelObjectV2(IMod String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { Objects.requireNonNull(modelStore, "Model store can not be null"); Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); + if (SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT.equals(type)) { + // Special case since document does not have the same constructor method signature - the ID is ignored + return new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, create); + } + if (SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE.equals(type)) { + throw new InvalidSPDXAnalysisException("Reference type can only be created with a type supplied."); + } + if (SpdxConstantsCompatV2.CLASS_SPDX_REVIEW.equals(type)) { + throw new InvalidSPDXAnalysisException("Review class is no longer supported"); + } Objects.requireNonNull(id, "ID must not be null"); - switch (type) { - case SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT: return new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, create); //Note: the ID is ignored - case SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE: return new org.spdx.library.model.compat.v2.SpdxPackage(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO: return new org.spdx.library.model.compat.v2.SpdxCreatorInformation(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM: return new org.spdx.library.model.compat.v2.Checksum(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract AnyLicensing Info. Must specify one of the concrete classes"); - case SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO: throw new InvalidSPDXAnalysisException("Can not create abstract SimpleLicensingInfo. Must specify one of the concrete classes"); - case SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET: return new org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET: return new org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO: return new org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE: throw new InvalidSPDXAnalysisException("Can not create abstract License. Must specify one of the concrete classes"); - case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE: return new org.spdx.library.model.compat.v2.license.SpdxListedLicense(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION: return new org.spdx.library.model.compat.v2.license.LicenseException(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION: return new org.spdx.library.model.compat.v2.license.ListedLicenseException(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR: return new org.spdx.library.model.compat.v2.license.OrLaterOperator(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR: return new org.spdx.library.model.compat.v2.license.WithExceptionOperator(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_FILE: return new org.spdx.library.model.compat.v2.SpdxFile(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_REVIEW: throw new RuntimeException("SPDX Review class is no longer supported"); - case SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE: return new org.spdx.library.model.compat.v2.SpdxPackageVerificationCode(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_ANNOTATION: return new org.spdx.library.model.compat.v2.Annotation(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_RELATIONSHIP: return new org.spdx.library.model.compat.v2.Relationship(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_ITEM: throw new RuntimeException("SPDX item is an abstract item and can not be created."); - case SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT: throw new RuntimeException("SPDX element is an abstract item and can not be created."); - case SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT: return new org.spdx.library.model.compat.v2.SpdxNoneElement(modelStore, documentUri); - case SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT: return new org.spdx.library.model.compat.v2.SpdxNoAssertionElement(modelStore, documentUri); - case SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF: return new org.spdx.library.model.compat.v2.ExternalDocumentRef(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE: return new org.spdx.library.model.compat.v2.ExternalRef(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE: return new org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE: throw new RuntimeException("Reference type can only be created with a type supplied."); - case SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET: return new org.spdx.library.model.compat.v2.SpdxSnippet(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE: return new org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense(modelStore, documentUri); - case SpdxConstantsCompatV2.CLASS_NONE_LICENSE: return new org.spdx.library.model.compat.v2.license.SpdxNoneLicense(modelStore, documentUri); - case org.spdx.library.model.compat.v2.GenericModelObject.GENERIC_MODEL_OBJECT_TYPE: return new org.spdx.library.model.compat.v2.GenericModelObject(modelStore, documentUri, id, copyManager, create); - case org.spdx.library.model.compat.v2.GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE: return new org.spdx.library.model.compat.v2.GenericSpdxElement(modelStore, documentUri, id, copyManager, create); - case org.spdx.library.model.compat.v2.GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE: return new org.spdx.library.model.compat.v2.GenericSpdxItem(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT: return new org.spdx.library.model.compat.v2.ExternalSpdxElement(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER: return new org.spdx.library.model.compat.v2.pointer.StartEndPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER: return new org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER: return new org.spdx.library.model.compat.v2.pointer.LineCharPointer(modelStore, documentUri, id, copyManager, create); - case SpdxConstantsCompatV2.CLASS_CROSS_REF: return new org.spdx.library.model.compat.v2.license.CrossRef(modelStore, documentUri, id, copyManager, create); - default: throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); + Class clazz = SPDX_TYPE_TO_CLASS_V2.get(type); + if (Objects.isNull(clazz)) { + throw new InvalidSPDXAnalysisException("Unknown SPDX version 2 type: "+type); + } + if (Modifier.isAbstract(clazz.getModifiers())) { + throw new InvalidSPDXAnalysisException("Can not instantiate an abstract class for the SPDX version 2 type: "+type); + } + try { + Constructor con = clazz.getDeclaredConstructor(IModelStore.class, String.class, String.class, ModelCopyManager.class, boolean.class); + return (org.spdx.library.model.compat.v2.ModelObject)con.newInstance(modelStore, documentUri, id, copyManager, create); + } catch (NoSuchMethodException e) { + throw new InvalidSPDXAnalysisException("Could not create the model object SPDX version 2 type: "+type); + } catch (SecurityException e) { + throw new InvalidSPDXAnalysisException("Unexpected security exception for SPDX version 2 type: "+type, e); + } catch (InstantiationException e) { + throw new InvalidSPDXAnalysisException("Unexpected instantiation exception for SPDX version 2 type: "+type, e); + } catch (IllegalAccessException e) { + throw new InvalidSPDXAnalysisException("Unexpected illegal access exception for SPDX version 2 type: "+type, e); + } catch (IllegalArgumentException e) { + throw new InvalidSPDXAnalysisException("Unexpected illegal argument exception for SPDX version 2 type: "+type, e); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof InvalidSPDXAnalysisException) { + throw (InvalidSPDXAnalysisException)e.getTargetException(); + } else { + throw new InvalidSPDXAnalysisException("Unexpected invocation target exception for SPDX version 2 type: "+type, e); + } } } @@ -398,4 +442,10 @@ public static Optional getModelObj } } } + + public static ModelObject createModelObject(IModelStore stModelStore, + String objectUri, String type, ModelCopyManager copyManager) { + // TODO Auto-generated method stub + return null; + } } diff --git a/src/main/java/org/spdx/library/SpdxVerificationHelper.java b/src/main/java/org/spdx/library/SpdxVerificationHelper.java index 1e68206a7..fd763b9f2 100644 --- a/src/main/java/org/spdx/library/SpdxVerificationHelper.java +++ b/src/main/java/org/spdx/library/SpdxVerificationHelper.java @@ -27,7 +27,7 @@ import java.util.Set; import java.util.regex.Pattern; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; /** * Holds static methods used for verify various property values diff --git a/src/main/java/org/spdx/library/model/GenericModelObject.java b/src/main/java/org/spdx/library/model/GenericModelObject.java new file mode 100644 index 000000000..1aea7af42 --- /dev/null +++ b/src/main/java/org/spdx/library/model/GenericModelObject.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.storage.IModelStore; + +/** + * Primarily used for testing, this model object does not implement any unique getters and setters nor + * does it implement any verification. + * + * @author Gary O'Neall + * + */ +public class GenericModelObject extends ModelObject { + + public static final String GENERIC_MODEL_OBJECT_TYPE = "GenericModelObject"; + + /** + * @throws InvalidSPDXAnalysisException + */ + public GenericModelObject() throws InvalidSPDXAnalysisException { + super(); + } + + /** + * @param objectUri + * @throws InvalidSPDXAnalysisException + */ + public GenericModelObject(String id) throws InvalidSPDXAnalysisException { + super(id); + } + + /** + * @param modelStore + * @param documentUri + * @param objectUri + * @param copyManager + * @param create + * @throws InvalidSPDXAnalysisException + */ + public GenericModelObject(IModelStore modelStore, String objectUri, + @Nullable ModelCopyManager copyManager, boolean create) + throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() + */ + @Override + public String getType() { + return GENERIC_MODEL_OBJECT_TYPE; + } + + /* (non-Javadoc) + * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion) { + return new ArrayList<>(); + } +} diff --git a/src/main/java/org/spdx/library/model/ModelCollection.java b/src/main/java/org/spdx/library/model/ModelCollection.java new file mode 100644 index 000000000..dce5cdc02 --- /dev/null +++ b/src/main/java/org/spdx/library/model/ModelCollection.java @@ -0,0 +1,294 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import javax.annotation.Nullable; + +import org.spdx.library.IndividualUriValue; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxObjectNotInStoreException; +import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; + +/** + * Collection of elements stored in a ModelStore + * + * @author Gary O'Neall + * + */ +public class ModelCollection implements Collection { + + private IModelStore modelStore; + private String objectUri; + private PropertyDescriptor propertyDescriptor; + private ModelCopyManager copyManager; + private Class type; +// private boolean licensePrimitiveAssignable; // If true, NONE and NOASSERTION should be converted to NoneLicense and NoAssertionLicense + + class ModelCollectionIterator implements Iterator { + + private Iterator storageIterator; + + public ModelCollectionIterator(Iterator storageIterator) { + this.storageIterator = storageIterator; + } + + @Override + public boolean hasNext() { + return storageIterator.hasNext(); + } + + @Override + public Object next() { + return checkConvertTypedValue(storageIterator.next()); + } + + } + + /** + * @param modelStore Storage for the model collection + * @param objectUri Object URI or anonymous ID + * @param propertyDescriptor descriptor for the property use for the model collections + * @param copyManager if non-null, use this to copy properties when referenced outside this model store + * @param type The class of the elements to be stored in the collection if none, null if not known + * @throws InvalidSPDXAnalysisException + */ + public ModelCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, + @Nullable ModelCopyManager copyManager, + @Nullable Class type) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model store can not be null"); + this.modelStore = modelStore; + Objects.requireNonNull(objectUri, "Object URI or anonymous ID can not be null"); + this.objectUri = objectUri; + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); + this.propertyDescriptor = propertyDescriptor; + this.copyManager = copyManager; + if (!modelStore.exists(objectUri)) { + throw new SpdxIdNotFoundException(objectUri+" does not exist."); + } + if (Objects.nonNull(type)) { + this.type = type; +// licensePrimitiveAssignable = type.isAssignableFrom(SpdxNoneLicense.class) || type.isAssignableFrom(SpdxNoAssertionLicense.class); + if (!modelStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, type)) { + throw new SpdxInvalidTypeException("Incompatible type for property "+propertyDescriptor+": "+type.toString()); + } +// } else { +// licensePrimitiveAssignable = false; + } + } + + @Override + public int size() { + try { + return this.modelStore.collectionSize(objectUri, this.propertyDescriptor); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean isEmpty() { + try { + return this.modelStore.collectionSize(objectUri, this.propertyDescriptor) == 0; + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean contains(Object o) { + try { + Object storedObject = null; + try { + storedObject = ModelObjectHelper.modelObjectToStoredObject(o, modelStore, copyManager); + } catch (SpdxObjectNotInStoreException e1) { + return false; // The exception is due to the model object not being in the store + } + return this.modelStore.collectionContains( + objectUri, this.propertyDescriptor, storedObject); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + private Object checkConvertTypedValue(Object value) { + try { + Object retval = ModelObjectHelper.storedObjectToModelObject(value, modelStore, copyManager); +// if (licensePrimitiveAssignable && retval instanceof IndividualUriValue) { +// String uri = ((IndividualUriValue)retval).getIndividualURI(); +// if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { +// retval = new SpdxNoAssertionLicense(); +// } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { +// retval = new SpdxNoneLicense(); +// } +// } + if (Objects.nonNull(this.type) && !this.type.isAssignableFrom(retval.getClass())) { + if (retval instanceof IndividualUriValue) { + throw new SpdxInvalidTypeException("No enumeration was found for URI "+((IndividualUriValue)retval).getIndividualURI()+ + " for type "+type.toString()); + } else { + throw new SpdxInvalidTypeException("A collection element of type "+retval.getClass().toString()+ + " was found in a collection of type "+type.toString()); + } + } + return retval; + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + /** + * Converts any typed or individual value objects to a ModelObject + */ + private Function checkConvertTypedValue = value -> { + return checkConvertTypedValue(value); + }; + + public List toImmutableList() { + return (List) Collections.unmodifiableList(StreamSupport.stream( + Spliterators.spliteratorUnknownSize(this.iterator(), Spliterator.ORDERED), false).map(checkConvertTypedValue) + .collect(Collectors.toList())); + } + + @Override + public Iterator iterator() { + try { + return new ModelCollectionIterator( + modelStore.listValues(objectUri, propertyDescriptor)); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + @Override + public Object[] toArray() { + return toImmutableList().toArray(); + } + + @Override + public AT[] toArray(AT[] a) { + return toImmutableList().toArray(a); + } + + @Override + public boolean add(Object element) { + try { + return modelStore.addValueToCollection( + objectUri, propertyDescriptor, + ModelObjectHelper.modelObjectToStoredObject(element, modelStore, copyManager)); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean remove(Object element) { + try { + return modelStore.removeValueFromCollection(objectUri, propertyDescriptor, + ModelObjectHelper.modelObjectToStoredObject(element, modelStore, null)); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean containsAll(Collection c) { + return toImmutableList().containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + boolean retval = false; + Iterator iter = c.iterator(); + while (iter.hasNext()) { + if (add(iter.next())) { + retval = true; + } + } + return retval; + } + + @Override + public boolean removeAll(Collection c) { + boolean retval = false; + Iterator iter = c.iterator(); + while (iter.hasNext()) { + if (remove(iter.next())) { + retval = true; + } + } + return retval; + } + + @Override + public boolean retainAll(Collection c) { + List values = toImmutableList(); + boolean retval = false; + for (Object value:values) { + if (!c.contains(value)) { + if (remove(value)) { + retval = true; + } + } + } + return retval; + } + + @Override + public void clear() { + try { + modelStore.clearValueCollection(objectUri, propertyDescriptor); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + /** + * @return the modelStore + */ + public IModelStore getModelStore() { + return modelStore; + } + + /** + * @return the objectUri + */ + public String getObjectUri() { + return objectUri; + } + + /** + * @return the propertyDescriptor + */ + public PropertyDescriptor getPropertyDescriptor() { + return propertyDescriptor; + } +} diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 1d67bb29a..381f9ed4e 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -17,6 +17,9 @@ */ package org.spdx.library.model; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -27,16 +30,29 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.DefaultModelStore; +import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.NotEquivalentReason; +import org.spdx.library.SimpleUriValue; +import org.spdx.library.SpdxIdInUseException; import org.spdx.library.SpdxIdNotFoundException; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.Version; +import org.spdx.library.NotEquivalentReason.NotEquivalent; +import org.spdx.library.SpdxConstants; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Element; +import org.spdx.library.model.enumerations.SpdxEnumFactory; +import org.spdx.library.model.licensing.AnyLicenseInfo; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.ModelUpdate; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** * @author Gary O'Neall @@ -99,7 +115,7 @@ public ModelObject() throws InvalidSPDXAnalysisException { } /** - * Open or create a model object with the default store and default document URI + * Open or create a model object with the default store * @param objectUri Anonymous ID or URI for the model object * @throws InvalidSPDXAnalysisException */ @@ -180,5 +196,721 @@ public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws In public void leaveCriticalSection(IModelStoreLock lock) { modelStore.leaveCriticalSection(lock); } + + /** + * @param specVersion Version of the SPDX spec to verify against + * @param verifiedElementUris list of all element object URIs which have already been verified - prevents infinite recursion + * @return Any verification errors or warnings associated with this object + */ + public List verify(Set verifiedElementUris, String specVersion) { + if (verifiedElementUris.contains(this.objectUri)) { + return new ArrayList<>(); + } else { + // The verifiedElementId is added in the SpdxElement._verify method + return _verify(verifiedElementUris, specVersion); + } + } + + /** + * Verifies against the more recent supported specification version + * @return Any verification errors or warnings associated with this object + */ + public List verify() { + return verify(Version.CURRENT_SPDX_VERSION); + } + + /** + * @param specVersion Version of the SPDX spec to verify against + * @return Any verification errors or warnings associated with this object + */ + public List verify(String specVersion) { + return verify(new HashSet(), specVersion); + } + + /** + * @return the Object URI or anonymous ID + */ + public String getObjectUri() { + return this.objectUri; + } + + /** + * @return the model store for this object + */ + public IModelStore getModelStore() { + return this.modelStore; + } + + /** + * @return if strict input checking is enabled + */ + public boolean isStrict() { + return strict; + } + + /** + * @param strict if true, inputs will be validated against the SPDX spec + */ + public void setStrict(boolean strict) { + this.strict = strict; + } + + //The following methods are to manage the properties associated with the model object + /** + * @return all names of property descriptors currently associated with this object + * @throws InvalidSPDXAnalysisException + */ + public List getPropertyValueDescriptors() throws InvalidSPDXAnalysisException { + return modelStore.getPropertyValueDescriptors(this.objectUri); + } + + /** + * Get an object value for a property + * @param propertyDescriptor Descriptor for the property + * @return value associated with a property + */ + protected Optional getObjectPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional retval = ModelObjectHelper.getObjectPropertyValue(modelStore, objectUri, propertyDescriptor, copyManager); + if (retval.isPresent() && retval.get() instanceof ModelObject && !strict) { + ((ModelObject)retval.get()).setStrict(strict); + } + return retval; + } + + /** + * Set a property value for a property descriptor, creating the property if necessary + * @param propertyDescriptor Descriptor for the property associated with this object + * @param value Value to associate with the property + * @throws InvalidSPDXAnalysisException + */ + protected void setPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Object value) throws InvalidSPDXAnalysisException { + if (this instanceof IndividualUriValue) { + throw new InvalidSPDXAnalysisException("Can not set a property for the literal value "+((IndividualUriValue)this).getIndividualURI()); + } + ModelObjectHelper.setPropertyValue(this.modelStore, objectUri, propertyDescriptor, value, copyManager); + } + + /** + * Create an update when, when applied by the ModelStore, sets a property value for a property descriptor, creating the property if necessary + * @param propertyDescriptor Descriptor for the property associated with this object + * @param value Value to associate with the property + * @return an update which can be applied by invoking the apply method + */ + protected ModelUpdate updatePropertyValue(PropertyDescriptor propertyDescriptor, Object value) { + return () ->{ + ModelObjectHelper.setPropertyValue(this.modelStore, objectUri, propertyDescriptor, value, copyManager); + }; + } + + /** + * @param propertyDescriptor Descriptor for a property + * @return the Optional String value associated with a property, null if no value is present + * @throws SpdxInvalidTypeException + */ + protected Optional getStringPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); + if (result.isPresent()) { + if (result.get() instanceof String) { + return Optional.of((String)result.get()); + } else { + logger.error("Property "+propertyDescriptor+" is not of type String"); + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type String"); + } + } else { + return Optional.empty(); + } + } + + /** + * @param propertyDescriptor Descriptor for a property + * @return the Optional Integer value associated with a property, null if no value is present + * @throws InvalidSPDXAnalysisException + */ + protected Optional getIntegerPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); + Optional retval; + if (result.isPresent()) { + if (!(result.get() instanceof Integer)) { + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Integer"); + } + retval = Optional.of((Integer)result.get()); + } else { + retval = Optional.empty(); + } + return retval; + } + + /** + * @param propertyDescriptor descriptor for the property + * @return an enumeration value for the property + * @throws InvalidSPDXAnalysisException + */ + @SuppressWarnings("unchecked") + protected Optional> getEnumPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); + if (!result.isPresent()) { + return Optional.empty(); + } + if (result.get() instanceof Enum) { + return (Optional>)(Optional)result; + } + if (!(result.get() instanceof IndividualUriValue)) { + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Individual Value or enum"); + } + Enum retval = SpdxEnumFactory.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); + if (Objects.isNull(retval)) { + logger.error("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); + throw new InvalidSPDXAnalysisException("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); + } else { + return Optional.of(retval); + } + } + + /** + * @param propertyDescriptor Descriptor for the property + * @return the Optional Boolean value for a property + * @throws SpdxInvalidTypeException + */ + protected Optional getBooleanPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); + if (result.isPresent()) { + if (result.get() instanceof Boolean) { + return Optional.of((Boolean)result.get()); + } else if (result.get() instanceof String) { + // try to convert + String sResult = ((String)result.get()).toLowerCase(); + if ("true".equals(sResult)) { + return Optional.of(Boolean.valueOf(true)); + } else if ("false".equals(sResult)) { + return Optional.of(Boolean.valueOf(false)); + } else { + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); + } + } else { + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); + } + } else { + return Optional.empty(); + } + } + + /** + * Converts property values to an AnyLicenseInfo if possible - if NONE or NOASSERTION URI value, convert to the appropriate license + * @param propertyDescriptor descriptor for the property + * @return AnyLicenseInfo license info for the property + * @throws InvalidSPDXAnalysisException + */ + @SuppressWarnings("unchecked") + protected Optional getAnyLicenseInfoPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); + if (!result.isPresent()) { + return Optional.empty(); + } else if (result.get() instanceof AnyLicenseInfo) { + return (Optional)(Optional)result; + } else if (result.get() instanceof SimpleUriValue) { + Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null); + if (val instanceof AnyLicenseInfo) { + return Optional.of((AnyLicenseInfo)val); + } else { + logger.error("Invalid type for AnyLicenseInfo property: "+val.getClass().toString()); + throw new SpdxInvalidTypeException("Invalid type for AnyLicenseInfo property: "+val.getClass().toString()); + } + } else { + logger.error("Invalid type for AnyLicenseInfo property: "+result.get().getClass().toString()); + throw new SpdxInvalidTypeException("Invalid type for AnyLicenseInfo property: "+result.get().getClass().toString()); + } + } + + /** + * Converts property values to an SpdxElement if possible - if individual value, convert to the appropriate SpdxElement + * @param propertyDescriptor Descriptor for the property + * @return SpdxElement stored + * @throws InvalidSPDXAnalysisException + */ + @SuppressWarnings("unchecked") + protected Optional getElementPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + Optional result = getObjectPropertyValue(propertyDescriptor); + if (!result.isPresent()) { + return Optional.empty(); + } else if (result.get() instanceof Element) { + return (Optional)(Optional)result; + } else if (result.get() instanceof SimpleUriValue) { + Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null); + if (val instanceof Element) { + return Optional.of((Element)val); + } else { + logger.error("Invalid type for Element property: "+val.getClass().toString()); + throw new SpdxInvalidTypeException("Invalid type for Element property: "+val.getClass().toString()); + } + } else { + logger.error("Invalid type for SpdxElement property: "+result.get().getClass().toString()); + throw new SpdxInvalidTypeException("Invalid type for SpdxElement property: "+result.get().getClass().toString()); + } + } + + /** + * Removes a property and its value from the model store if it exists + * @param propertyDescriptor Descriptor for the property associated with this object to be removed + * @throws InvalidSPDXAnalysisException + */ + protected void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + ModelObjectHelper.removeProperty(modelStore, objectUri, propertyDescriptor); + } + + /** + * Create an update when, when applied by the ModelStore, removes a property and its value from the model store if it exists + * @param propertyDescriptor Descriptor for the property associated with this object to be removed + * @return an update which can be applied by invoking the apply method + */ + protected ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor) { + return () -> { + ModelObjectHelper.removeProperty(modelStore, objectUri, propertyDescriptor); + }; + } + + /** + * Clears a collection of values associated with a property + * @param propertyDescriptor Descriptor for the property + */ + protected void clearValueCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + ModelObjectHelper.clearValueCollection(modelStore, objectUri, propertyDescriptor); + } + + /** + * Create an update when, when applied by the ModelStore, clears a collection of values associated with a property + * @param propertyDescriptor Descriptor for the property + * @return an update which can be applied by invoking the apply method + */ + protected ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDescriptor) { + return () ->{ + ModelObjectHelper.clearValueCollection(modelStore, objectUri, propertyDescriptor); + }; + } + + /** + * Add a value to a collection of values associated with a property. If a value is a ModelObject and does not + * belong to the document, it will be copied into the object store + * @param propertyDescriptor Descriptor for the property + * @param value to add + * @throws InvalidSPDXAnalysisException + */ + protected void addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + ModelObjectHelper.addValueToCollection(modelStore, objectUri, propertyDescriptor, value, copyManager); + } + + /** + * Create an update when, when applied, adds a value to a collection of values associated with a property. If a value is a ModelObject and does not + * belong to the document, it will be copied into the object store + * @param propertyDescriptor Descriptor for the property + * @param value to add + * @return an update which can be applied by invoking the apply method + */ + protected ModelUpdate updateAddPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) { + return () ->{ + ModelObjectHelper.addValueToCollection(modelStore, objectUri, propertyDescriptor, value, copyManager); + }; + } + + /** + * Remove a property value from a collection + * @param propertyDescriptor Descriptor for the property + * @param value Value to be removed + * @throws InvalidSPDXAnalysisException + */ + protected void removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + ModelObjectHelper.removePropertyValueFromCollection(modelStore, objectUri, propertyDescriptor, value); + } + + /** + * Create an update when, when applied, removes a property value from a collection + * @param propertyDescriptor descriptor for the property + * @param value Value to be removed + * @return an update which can be applied by invoking the apply method + */ + protected ModelUpdate updateRemovePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) { + return () -> { + ModelObjectHelper.removePropertyValueFromCollection(modelStore, objectUri, propertyDescriptor, value); + }; + } + + /** + * @param propertyDescriptor Descriptor for the property + * @return Set of values associated with a property + */ + protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { + return new ModelSet(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type); + } + + /** + * @param propertyDescriptor Descriptor for the property + * @return Collection of values associated with a property + */ + protected ModelCollection getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { + return new ModelCollection(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type); + } + + /** + * @param propertyDescriptor Descriptor for property + * @return Collection of Strings associated with the property + * @throws SpdxInvalidTypeException + */ + @SuppressWarnings("unchecked") + protected Collection getStringCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + if (!isCollectionMembersAssignableTo(propertyDescriptor, String.class)) { + throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" does not contain a collection of Strings"); + } + return (Collection)(Collection)getObjectPropertyValueSet(propertyDescriptor, String.class); + } + + protected boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { + return modelStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, + ModelObjectHelper.modelClassToStoredClass(clazz)); + } + + /** + * @param compare + * @return true if all the properties have the same or equivalent values + */ + public boolean equivalent(ModelObject compare) throws InvalidSPDXAnalysisException { + return equivalent(compare, false); + } + + /** + * @param compare + * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion + * @return true if all the properties have the same or equivalent values + */ + public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { + if (!this.getClass().equals(compare.getClass())) { + lastNotEquivalentReason = new NotEquivalentReason(NotEquivalent.DIFFERENT_CLASS); + return false; + } + List propertyValueDescriptors = getPropertyValueDescriptors(); + List comparePropertyValueDescriptors = new ArrayList(compare.getPropertyValueDescriptors()); // create a copy since we're going to modify it + for (PropertyDescriptor propertyDescriptor:propertyValueDescriptors) { + if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { + continue; + } + if (comparePropertyValueDescriptors.contains(propertyDescriptor)) { + if (!propertyValuesEquivalent(propertyDescriptor, this.getObjectPropertyValue(propertyDescriptor), + compare.getObjectPropertyValue(propertyDescriptor), ignoreRelatedElements)) { + lastNotEquivalentReason = new NotEquivalentReason( + NotEquivalent.PROPERTY_NOT_EQUIVALENT, propertyDescriptor); + return false; + } + comparePropertyValueDescriptors.remove(propertyDescriptor); + } else { + // No property value + Optional propertyValueOptional = this.getObjectPropertyValue(propertyDescriptor); + if (propertyValueOptional.isPresent()) { + Object propertyValue = propertyValueOptional.get(); + if (isEquivalentToNull(propertyValue, propertyDescriptor)) { + continue; + } + lastNotEquivalentReason = new NotEquivalentReason( + NotEquivalent.COMPARE_PROPERTY_MISSING, propertyDescriptor); + return false; + } + } + } + for (PropertyDescriptor propertyDescriptor:comparePropertyValueDescriptors) { // check any remaining property values + if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { + continue; + } + Optional comparePropertyValueOptional = compare.getObjectPropertyValue(propertyDescriptor); + if (!comparePropertyValueOptional.isPresent()) { + continue; + } + Object comparePropertyValue = comparePropertyValueOptional.get(); + if (isEquivalentToNull(comparePropertyValue, propertyDescriptor)) { + continue; + } + lastNotEquivalentReason = new NotEquivalentReason( + NotEquivalent.MISSING_PROPERTY, propertyDescriptor); + return false; + } + return true; + } + + // Some values are treated like null in comparisons - in particular empty model collections and + // "no assertion" values and a filesAnalyzed filed with a value of true + private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor propertyDescriptor) { + if (propertyValue instanceof ModelCollection) { + return isEmptyModelCollection(propertyValue); + } else if (isNoAssertion(propertyValue)) { + return true; + } else { + return false; + } + } + + /** + * @param propertyDescriptor property descriptor for the object in question + * @return true if the object is "to" part of a relationships + */ + private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { + return SpdxConstants.CORE_PROP_RELATED_SPDX_ELEMENT.equals(propertyDescriptor); + } + + /** + * @param value value to test against an empty model collection + * @return true if the value is a model collection and it is empty + */ + private boolean isEmptyModelCollection(Object value) { + return (value instanceof ModelCollection) + && (((ModelCollection) value).size() == 0); + } + + private boolean isNoAssertion(Object propertyValue) { + return false; + //TODO: Implement + } + + /** + * @param propertyDescriptor Descriptor for the property + * @param valueA value to compare + * @param valueB value to compare + * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion + * @return true if the property values are equivalent + * @throws InvalidSPDXAnalysisException + */ + private boolean propertyValuesEquivalent(PropertyDescriptor propertyDescriptor, Optional valueA, + Optional valueB, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { + if (!valueA.isPresent()) { + if (valueB.isPresent()) { + return isEmptyModelCollection(valueB.get()); + } + } else if (!valueB.isPresent()) { + return isEmptyModelCollection(valueA.get()); + } else if (valueA.get() instanceof ModelCollection && valueB.get() instanceof ModelCollection) { + List myList = ((ModelCollection)valueA.get()).toImmutableList(); + List compareList = ((ModelCollection)valueB.get()).toImmutableList(); + if (!areEquivalent(myList, compareList, ignoreRelatedElements)) { + return false; + } + } else if (valueA.get() instanceof List && valueB.get() instanceof List) { + if (!areEquivalent((List)valueA.get(), (List)valueB.get(), ignoreRelatedElements)) { + return false; + } + } else if (valueA.get() instanceof IndividualUriValue && valueB.get() instanceof IndividualUriValue) { + if (!Objects.equals(((IndividualUriValue)valueA.get()).getIndividualURI(), ((IndividualUriValue)valueB.get()).getIndividualURI())) { + return false; + } + // Note: we must check the IndividualValue before the ModelObject types since the IndividualValue takes precedence + } else if (valueA.get() instanceof ModelObject && valueB.get() instanceof ModelObject) { + if (!((ModelObject)valueA.get()).equivalent(((ModelObject)valueB.get()), + isRelatedElement(propertyDescriptor) ? true : ignoreRelatedElements)) { + return false; + } + + } else if (!optionalObjectsEquivalent(valueA, valueB)) { // Present, not a list, and not a TypedValue + return false; + } + return true; + } + + /** + * Compares 2 simple optional objects considering NONE and NOASSERTION values which are equivalent to their strings + * @param valueA + * @param valueB + * @return + */ + private boolean optionalObjectsEquivalent(Optional valueA, Optional valueB) { + if (Objects.equals(valueA, valueB)) { + return true; + } + if (!valueA.isPresent()) { + return false; + } + if (!valueB.isPresent()) { + return false; + } + if (valueA.get() instanceof IndividualUriValue) { + if (!(valueB.get() instanceof IndividualUriValue)) { + return false; + } + + return ((IndividualUriValue)(valueA.get())).getIndividualURI().equals(((IndividualUriValue)(valueB.get())).getIndividualURI()); + } + if (valueA.get() instanceof String && valueB.get() instanceof String) { + return normalizeString((String)valueA.get()).equals(normalizeString((String)valueB.get())); + } + return false; + } + + /** + * Normalize a string for dos and linux linefeeds + * @param s + * @return DOS style only linefeeds + */ + private Object normalizeString(String s) { + return s.replaceAll("\r\n", "\n").trim(); + } + + /** + * Checks if for each item on either list, there is an item in the other list that is equivalent. + * @param ignoreRelatedElements Whether related elements should be ignored in the comparison + */ + private boolean areEquivalent(List firstList, List secondList, + boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { + if (firstList.size() != secondList.size()) { + return false; + } + for (Object item : firstList) { + if (!containsEqualOrEquivalentItem(secondList, item, ignoreRelatedElements)) { + return false; + } + } + for (Object item : secondList) { + if (!containsEqualOrEquivalentItem(firstList, item, ignoreRelatedElements)) { + return false; + } + } + return true; + } + + /** + * Searches a list for an equal or equivalent item + * @param list list to search + * @param itemToFind the item we're looking for + * @param ignoreRelatedElements if true, don't follow the to parts of relationships + * @return true if the list contains an equal or equivalent item + * @throws InvalidSPDXAnalysisException + */ + private boolean containsEqualOrEquivalentItem(List list, Object itemToFind, + boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { + if (list.contains(itemToFind)) { + return true; + } else if (itemToFind instanceof IndividualUriValue && list.contains(new SimpleUriValue((IndividualUriValue) itemToFind))) { + // Two IndividualUriValues are considered equal if their URI coincides + return true; + } + + if (!(itemToFind instanceof ModelObject)) { + return false; + } + + ModelObject objectToFind = (ModelObject) itemToFind; + for (Object objectToCompare : list) { + if (!(objectToCompare instanceof ModelObject)) { + continue; + } + if (objectToFind.equivalent((ModelObject) objectToCompare, ignoreRelatedElements)) { + return true; + } + } + return false; + } + + @Override + public int hashCode() { + if (modelStore.getIdType(objectUri) == IdType.Anonymous) { + return 11 ^ modelStore.hashCode() ^ objectUri.hashCode(); + } else { + return this.objectUri.hashCode(); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof ModelObject)) { + // covers o == null, as null is not an instance of anything + return false; + } + ModelObject comp = (ModelObject)o; + if (getModelStore().getIdType(objectUri).equals(IdType.Anonymous)) { + return Objects.equals(modelStore, comp.getModelStore()) && Objects.equals(objectUri, comp.getObjectUri()); + } else { + return Objects.equals(objectUri, comp.getObjectUri()); + } + } + + + /** + * Clone a new object using a different model store + * @param modelStore + * @return + */ + public ModelObject clone(IModelStore modelStore) { + if (Objects.isNull(this.copyManager)) { + throw new IllegalStateException("A copy manager must be provided to clone"); + } + if (this.modelStore.equals(modelStore)) { + throw new IllegalStateException("Can not clone to the same model store"); + } + Objects.requireNonNull(modelStore, "Model store for clone must not be null"); + if (modelStore.exists(objectUri)) { + throw new IllegalStateException("Can not clone - "+objectUri+" already exists."); + } + try { + ModelObject retval = SpdxModelFactory.createModelObject(modelStore, objectUri, this.getType(), this.copyManager); + retval.copyFrom(this); + return retval; + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + } + + /** + * Copy all the properties from the source object + * @param source + * @throws InvalidSPDXAnalysisException + */ + public void copyFrom(ModelObject source) throws InvalidSPDXAnalysisException { + if (Objects.isNull(copyManager)) { + throw new InvalidSPDXAnalysisException("Copying is not enabled for "+objectUri); + } + copyManager.copy(this.modelStore, objectUri, + source.getModelStore(), source.getObjectUri(), this.getType(), null, null, null, null); + } + + + /** + * Copy all the properties from the source SPDX version 2 model object + * @param source + * @throws InvalidSPDXAnalysisException + */ + public void copyFromV2(org.spdx.library.model.compat.v2.ModelObject source) throws InvalidSPDXAnalysisException { + if (Objects.isNull(copyManager)) { + throw new InvalidSPDXAnalysisException("Copying is not enabled for "+objectUri); + } + copyManager.copy(this.modelStore, objectUri, + source.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(source.getDocumentUri(), source.getId(), source.getModelStore()), + this.getType(), CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), source.getModelStore().getIdType(source.getId()) == IdType.Anonymous), + null, + CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), false), + null); + } + + /** + * Set the copy manager + * @param copyManager copy manager to set + */ + public void setCopyManager(ModelCopyManager copyManager) { + this.copyManager = copyManager; + } + + /** + * @return the copy manager - value may be null if copies are not allowd + */ + public ModelCopyManager getCopyManager() { + return this.copyManager; + } + + /** + * @return a typed value representation of this object suitable for storage in the model store + * @throws InvalidSPDXAnalysisException + */ + protected TypedValue toTypedValue() throws InvalidSPDXAnalysisException { + return new TypedValue(objectUri, getType()); + } + + @Override + public String toString() { + return this.getType() + ":" + objectUri; + } } diff --git a/src/main/java/org/spdx/library/model/ModelObjectHelper.java b/src/main/java/org/spdx/library/model/ModelObjectHelper.java new file mode 100644 index 000000000..2f647efb5 --- /dev/null +++ b/src/main/java/org/spdx/library/model/ModelObjectHelper.java @@ -0,0 +1,306 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.spdx.library.IndividualUriValue; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SimpleUriValue; +import org.spdx.library.SpdxInvalidTypeException; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.SpdxObjectNotInStoreException; +import org.spdx.library.TypedValue; +import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; +import org.spdx.storage.IModelStore.IModelStoreLock; + +/** + * A set of static methods to help with common ModelObject functions + * + * @author Gary O'Neall + * + */ +public class ModelObjectHelper { + + private ModelObjectHelper() { + // this is only a static helper class + } + + /** + * Get an object value for a property + * @param modelStore Model store for the object + * @param objectUri the Object URI or anonymous ID + * @param propertyDescriptor property descriptor for the property + * @param copyManager if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available + * @return value associated with a property + * @throws InvalidSPDXAnalysisException + */ + public static Optional getObjectPropertyValue(IModelStore modelStore, String objectUri, + PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + // NOTE: we use a write lock since the ModelStorageClassConverter may end up creating objects in the store + try { + if (!modelStore.exists(objectUri)) { + return Optional.empty(); + } else if (modelStore.isCollectionProperty(objectUri, propertyDescriptor)) { + return Optional.of(new ModelCollection<>(modelStore, objectUri, propertyDescriptor, copyManager, null)); + } else { + return optionalStoredObjectToModelObject(modelStore.getValue(objectUri, + propertyDescriptor), modelStore, copyManager); + } + } finally { + lock.unlock(); + } + } + + /** + * Set a property value for a property descriptor, creating the property if necessary + * @param modelStore Model store for the properties + * @param objectUri URI or anonymous ID for the object + * @param propertyDescriptor Descriptor for the property associated with this object + * @param value Value to associate with the property + * @param copyManager if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available + * @throws InvalidSPDXAnalysisException + */ + protected static void setPropertyValue(IModelStore modelStore, String objectUri, + PropertyDescriptor propertyDescriptor, @Nullable Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(modelStore, "Model Store can not be null"); + Objects.requireNonNull(objectUri, "Object Uri or anonymous ID can not be null"); + Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); + if (value == null) { + // we just remove the value + removeProperty(modelStore, objectUri, propertyDescriptor); + } else if (value instanceof Collection) { + replacePropertyValueCollection(modelStore, objectUri, propertyDescriptor, (Collection)value, copyManager); + } else { + modelStore.setValue(objectUri, propertyDescriptor, modelObjectToStoredObject(value, modelStore, copyManager)); + } + } + + /** + * Removes a property and its value from the model store if it exists + * @param modelStore Model store for the properties + * @param objectUri URI or anonymous ID for the object + * @param propertyDescriptor Descriptor for the property associated with this object to be removed + * @throws InvalidSPDXAnalysisException + */ + protected static void removeProperty(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + modelStore.removeProperty(objectUri, propertyDescriptor); + } + + /** + * Clears a collection of values associated with a property creating the property if it does not exist + * @param modelStore Model store for the properties + * @param objectUri URI or anonymous ID for the object + * @param propertyDescriptor Descriptor for the property + * @throws InvalidSPDXAnalysisException + */ + protected static void clearValueCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + modelStore.clearValueCollection(objectUri, propertyDescriptor); + } + + /** + * Add a value to a collection of values associated with a property. If a value + * is a ModelObject and does not belong to the document, it will be copied into + * the object store + * + * @param modelStore Model store for the properties + * @param objectUri URI or anonymous ID for the object + * @param propertyDescriptor Descriptor for the property + * @param value to add + * @param copyManager + * @throws InvalidSPDXAnalysisException + */ + protected static void addValueToCollection(IModelStore modelStore, String objectUri, + PropertyDescriptor propertyDescriptor, Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(value, "Value can not be null"); + modelStore.addValueToCollection(objectUri, propertyDescriptor, + modelObjectToStoredObject(value, modelStore, copyManager)); + } + + /** + * Replace the entire value collection for a property. If a value is a ModelObject and does not + * belong to the document, it will be copied into the object store + * @param modelStore Model store for the properties + * @param objectUri URI or anonymous ID for the object + * @param propertyDescriptor Descriptor for the property + * @param values collection of new properties + * @param copyManager if non-null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available + * @throws InvalidSPDXAnalysisException + */ + protected static void replacePropertyValueCollection(IModelStore modelStore, String objectUri, + PropertyDescriptor propertyDescriptor, Collection values, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + clearValueCollection(modelStore, objectUri, propertyDescriptor); + for (Object value:values) { + addValueToCollection(modelStore, objectUri, propertyDescriptor, value, copyManager); + } + } + + /** + * Remove a property value from a collection + * @param modelStore Model store for the properties + * @param objectUri URI or anonymous ID for the object + * @param propertyDescriptor descriptor for the property + * @param value Value to be removed + * @throws InvalidSPDXAnalysisException + */ + protected static void removePropertyValueFromCollection(IModelStore modelStore, String objectUri, + PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + modelStore.removeValueFromCollection(objectUri, propertyDescriptor, modelObjectToStoredObject(value, modelStore, null)); + } + + /** + * Converts any typed value or IndividualValue objects to a ModelObject, + * returning an existing ModelObject if it exists or creates a new ModelObject + * + * @param value Value which may be a TypedValue + * @param modelStore ModelStore to use in fetching or creating + * @param copyManager if not null, copy any referenced ID's outside of this + * document/model store + * @return the object itself unless it is a TypedValue, in which case a + * ModelObject is returned + * @throws InvalidSPDXAnalysisException + */ + public static Optional optionalStoredObjectToModelObject(Optional value, + IModelStore modelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (value.isPresent() && value.get() instanceof IndividualUriValue) { + return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(modelStore, copyManager, null)); + } else if (value.isPresent() && value.get() instanceof TypedValue) { + TypedValue tv = (TypedValue)value.get(); + return Optional.of(SpdxModelFactory.createModelObject(modelStore, + tv.getObjectUri(), tv.getType(), copyManager)); + } else { + return value; + } + } + + /** + * Converts a stored object to it's appropriate model object type + * @param value + * @param modelStore + * @param copyManager if not null, copy any referenced ID's outside of this document/model store + * @return Model Object appropriate type + * @throws InvalidSPDXAnalysisException + */ + public static Object modelObjectToStoredObject(Object value, IModelStore modelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (value instanceof IndividualUriValue) { + // Convert to a simple URI value to save storage + return new SimpleUriValue((IndividualUriValue)value); + } else if (value instanceof ModelObject) { + ModelObject mValue = (ModelObject)value; + if (!mValue.getModelStore().equals(modelStore)) { + if (Objects.nonNull(copyManager)) { + return copyManager.copy(modelStore, mValue.getModelStore(), mValue.getObjectUri(), mValue.getType(), null, null, null, null); + } else { + throw new SpdxObjectNotInStoreException("Can not set a property value to a Model Object stored in a different model store"); + } + } else { + return mValue.toTypedValue(); + } + } else if (value instanceof Integer || value instanceof String || value instanceof Boolean || value instanceof IndividualUriValue) { + return value; + } else if (Objects.isNull(value)) { + throw new SpdxInvalidTypeException("Property value is null"); + } else { + throw new SpdxInvalidTypeException("Property value type not supported: "+value.getClass().getName()); + } + } + + /** + * Converts any typed value or individual value objects to a ModelObject, + * returning an existing ModelObject if it exists or creates a new ModelObject + * + * @param value Value which may be a TypedValue + * @param modelStore ModelStore to use in fetching or creating + * @param copyManager if not null, copy any referenced ID's outside of this + * document/model store + * @return the object itself unless it is a TypedValue, in which case a + * ModelObject is returned + * @throws InvalidSPDXAnalysisException + */ + public static Object storedObjectToModelObject(Object value, IModelStore modelStore, + ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (value instanceof IndividualUriValue) { // Note: this must be before the check for TypedValue + SimpleUriValue suv = new SimpleUriValue((IndividualUriValue)value); + return suv.toModelObject(modelStore, copyManager, null); + } else if (value instanceof TypedValue) { + TypedValue tv = (TypedValue)value; + return SpdxModelFactory.getModelObject(modelStore, tv.getObjectUri(), tv.getType(), copyManager, true); + } else { + return value; + } + }; + + /** + * Convert the class to the appropriate stored class + * @param clazz Model class + * @return class compatible with stored classes + */ + public static Class modelClassToStoredClass(Class clazz) { + if (ModelObject.class.isAssignableFrom(clazz)) { + return TypedValue.class; + } else if (implementsIndividualUriValue(clazz)) { + return SimpleUriValue.class; + } else { + return clazz; + } + } + + /** + * @param clazz + * @return true if the clazz implements the IndividualUriValue interface + */ + public static boolean implementsIndividualUriValue(Class clazz) { + for (Class intefaceClass:clazz.getInterfaces()) { + if (intefaceClass.equals(IndividualUriValue.class)) { + return true; + } + } + return false; + } + + /** + * Verifies all elements in a collection + * @param specVersion version of the SPDX specification to verify against + * @param collection collection to be verifies + * @param verifiedIds verifiedIds list of all Id's which have already been verifieds - prevents infinite recursion + * @param warningPrefix String to prefix any warning messages + */ + public static List verifyCollection(Collection collection, String warningPrefix, Set verifiedIds, String specVersion) { + List retval = new ArrayList<>(); + for (ModelObject mo:collection) { + for (String warning:mo.verify(verifiedIds, specVersion)) { + if (Objects.nonNull(warningPrefix)) { + retval.add(warningPrefix + warning); + } else { + retval.add(warning); + } + } + } + return retval; + } +} diff --git a/src/main/java/org/spdx/library/model/ModelSet.java b/src/main/java/org/spdx/library/model/ModelSet.java new file mode 100644 index 000000000..05438cd18 --- /dev/null +++ b/src/main/java/org/spdx/library/model/ModelSet.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.Collection; +import java.util.Iterator; + +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IModelStoreLock; +import org.spdx.storage.PropertyDescriptor; + +/** + * A ModelCollection implemented as a set where all items in the collection are unique based + * on equality (not based on equivalence). + * + * @author Gary O'Neall + * + */ +public class ModelSet extends ModelCollection { + + static final Logger logger = LoggerFactory.getLogger(ModelSet.class); + + /** + * @param modelStore + * @param objectUri + * @param propertyDescriptor + * @param copyManager + * @param type + * @throws InvalidSPDXAnalysisException + */ + public ModelSet(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, + @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, propertyDescriptor, copyManager, type); + } + + @Override + public boolean add(Object element) { + IModelStoreLock lock; + try { + lock = this.getModelStore().enterCriticalSection(false); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + try { + if (!super.contains(element)) { + return super.add(element); + } else { + return false; + } + } finally { + this.getModelStore().leaveCriticalSection(lock); + } + } + + @Override + public boolean addAll(Collection c) { + IModelStoreLock lock; + try { + lock = this.getModelStore().enterCriticalSection(false); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + try { + boolean retval = false; + Iterator iter = c.iterator(); + while (iter.hasNext()) { + Object item = iter.next(); + if (!super.contains(item) && super.add(item)) { + retval = true; + } + } + return retval; + } finally { + this.getModelStore().leaveCriticalSection(lock); + } + } + +} diff --git a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java index 2b0aa737f..0fe5419c9 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java @@ -29,7 +29,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.AnnotationType; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java index e033bc270..7b1006fc0 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java @@ -31,7 +31,7 @@ import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index 127dfb54a..f4ea0fa98 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -36,7 +36,7 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -65,7 +65,7 @@ public static Optional getExternalDocRefByDocNamespace(IMod Objects.requireNonNull(externalDocUri, "External document URI can not be null"); IModelStoreLock lock = stModelStore.enterCriticalSection(false); try { - ModelCollection existingExternalRefs = new ModelCollection(stModelStore,stDocumentUri, + ModelCollectionV2 existingExternalRefs = new ModelCollectionV2(stModelStore,stDocumentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, copyManager, ExternalDocumentRef.class); for (Object externalRef:existingExternalRefs) { if (!(externalRef instanceof ExternalDocumentRef)) { @@ -188,7 +188,9 @@ public ExternalDocumentRef setChecksum(Checksum checksum) throws InvalidSPDXAnal * @return the spdxDocumentNamespace or empty string if no namespace */ public String getSpdxDocumentNamespace() throws InvalidSPDXAnalysisException { - Optional docNamespace = getModelStore().getValue(getDocumentUri(), getId(), SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); + Optional docNamespace = getModelStore().getValue( + CompatibleModelStoreWrapper.documentUriIdToUri(getDocumentUri(), getId(), getModelStore().getIdType(getId()) == IdType.Anonymous), + SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); if (!docNamespace.isPresent()) { logger.warn("SPDX document namespace not found"); return ""; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java index 354dcccc9..b6fb7a117 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java @@ -30,7 +30,7 @@ import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.enumerations.ReferenceCategory; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java index b9f8fb912..66d46c81e 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java @@ -34,6 +34,7 @@ import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; +import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** @@ -198,7 +199,8 @@ public static ExternalSpdxElement uriToExternalSpdxElement(String uri, public static String externalDocumentIdToNamespace(String externalDocumentId, IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Optional retval = stModelStore.getValue(stDocumentUri, externalDocumentId, SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); + Optional retval = stModelStore.getValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, externalDocumentId, false), + SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); if (!retval.isPresent()) { throw new InvalidSPDXAnalysisException("No external document reference exists for document ID "+externalDocumentId); } diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java index 7416da3f6..17225e013 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java @@ -46,7 +46,7 @@ public GenericModelObject() throws InvalidSPDXAnalysisException { } /** - * @param objectUri + * @param id * @throws InvalidSPDXAnalysisException */ public GenericModelObject(String id) throws InvalidSPDXAnalysisException { @@ -56,7 +56,7 @@ public GenericModelObject(String id) throws InvalidSPDXAnalysisException { /** * @param modelStore * @param documentUri - * @param objectUri + * @param id * @param copyManager * @param create * @throws InvalidSPDXAnalysisException diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java b/src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java similarity index 96% rename from src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java rename to src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java index 27847efcf..e5f117bbc 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java @@ -44,12 +44,12 @@ import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; /** - * Collection of elements stored in a ModelStore + * Collection of elements stored in an SPDX version 2 ModelStore * * @author Gary O'Neall * */ -public class ModelCollection implements Collection { +public class ModelCollectionV2 implements Collection { private IModelStore modelStore; private String documentUri; @@ -82,13 +82,13 @@ public Object next() { /** * @param modelStore Storage for the model collection * @param documentUri SPDX Document URI for a document associated with this model collection - * @param objectUri ID for this collection - must be unique within the SPDX document + * @param id ID for this collection - must be unique within the SPDX document * @param propertyDescriptor descriptor for the property use for the model collections * @param copyManager if non-null, use this to copy properties when referenced outside this model store * @param type The class of the elements to be stored in the collection if none, null if not known * @throws InvalidSPDXAnalysisException */ - public ModelCollection(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, + public ModelCollectionV2(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { Objects.requireNonNull(modelStore, "Model store can not be null"); @@ -301,7 +301,7 @@ public String getDocumentUri() { } /** - * @return the objectUri + * @return the id */ public String getId() { return id; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 42c8d195f..879cdfbdb 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -38,17 +38,13 @@ import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdInUseException; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.TypedValue; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -61,6 +57,11 @@ import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.SinglePointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -235,6 +236,7 @@ public List verify(Set verifiedIElementds, String specVersion) { public List verify() { return verify(Version.CURRENT_SPDX_VERSION); } + /** * @param specVersion Version of the SPDX spec to verify against * @return Any verification errors or warnings associated with this object @@ -257,6 +259,9 @@ public String getId() { return id; } + /** + * @return the Object URI or anonymous ID + */ public String getObjectUri() { return modelStore.getIdType(id) == IdType.Anonymous ? id : SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri) ? documentUri + id : @@ -341,7 +346,7 @@ protected static Optional getObjectPropertyValue(IModelStore stModelStor if (!stModelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore))) { return Optional.empty(); } else if (stModelStore.isCollectionProperty(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor)) { - return Optional.of(new ModelCollection<>(stModelStore, stDocumentUri, stId, propertyDescriptor, copyManager, null)); + return Optional.of(new ModelCollectionV2<>(stModelStore, stDocumentUri, stId, propertyDescriptor, copyManager, null)); } else { return ModelStorageClassConverter.optionalStoredObjectToModelObject(stModelStore.getValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor), @@ -742,8 +747,8 @@ protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescr * @param propertyDescriptor Descriptor for the property * @return Collection of values associated with a property */ - protected ModelCollection getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelCollection(this.modelStore, this.documentUri, this.id, propertyDescriptor, this.copyManager, type); + protected ModelCollectionV2 getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { + return new ModelCollectionV2(this.modelStore, this.documentUri, this.id, propertyDescriptor, this.copyManager, type); } /** @@ -832,8 +837,8 @@ public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) th // Some values are treated like null in comparisons - in particular empty model collections and // "no assertion" values and a filesAnalyzed filed with a value of true private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor propertyDescriptor) { - if (propertyValue instanceof ModelCollection) { - return ((ModelCollection) propertyValue).size() == 0; + if (propertyValue instanceof ModelCollectionV2) { + return ((ModelCollectionV2) propertyValue).size() == 0; } else if (isNoAssertion(propertyValue)) { return true; } else if (SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED.equals(propertyDescriptor.getName())) { @@ -848,8 +853,8 @@ private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { } private boolean isEmptyModelCollection(Object value) { - return (value instanceof ModelCollection) - && (((ModelCollection) value).size() == 0); + return (value instanceof ModelCollectionV2) + && (((ModelCollectionV2) value).size() == 0); } private boolean isNoAssertion(Object propertyValue) { @@ -873,9 +878,9 @@ private boolean propertyValuesEquivalent(PropertyDescriptor propertyDescriptor, } } else if (!valueB.isPresent()) { return isEmptyModelCollection(valueA.get()); - } else if (valueA.get() instanceof ModelCollection && valueB.get() instanceof ModelCollection) { - List myList = ((ModelCollection)valueA.get()).toImmutableList(); - List compareList = ((ModelCollection)valueB.get()).toImmutableList(); + } else if (valueA.get() instanceof ModelCollectionV2 && valueB.get() instanceof ModelCollectionV2) { + List myList = ((ModelCollectionV2)valueA.get()).toImmutableList(); + List compareList = ((ModelCollectionV2)valueB.get()).toImmutableList(); if (!areEquivalent(myList, compareList, ignoreRelatedElements)) { return false; } @@ -1021,9 +1026,7 @@ public boolean equals(Object o) { return Objects.equals(id, comp.getId()) && Objects.equals(documentUri, comp.getDocumentUri()); } } - - - + /** * Clone a new object using a different model store * @param modelStore diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java index 0cd4a6641..d954aefca 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java @@ -37,7 +37,7 @@ * @author Gary O'Neall * */ -public class ModelSet extends ModelCollection { +public class ModelSet extends ModelCollectionV2 { static final Logger logger = LoggerFactory.getLogger(ModelSet.class); diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index 3af851c21..e22cd88d6 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -54,9 +54,6 @@ public class ModelStorageClassConverter { static final Logger logger = LoggerFactory.getLogger(ModelStorageClassConverter.class); - public static void reset() {tempMgr = new ModelCopyManager();}//TODO: This should be removed - static ModelCopyManager tempMgr = new ModelCopyManager();//TODO: This is temporary - move to a parameter to ModelObject - this is not currently threadsafe - /** * Converts any typed value or individual value objects to a ModelObject, * returning an existing ModelObject if it exists or creates a new ModelObject diff --git a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java index f91a553be..0c43f4f17 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java @@ -33,7 +33,8 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.SpdxIdInUseException; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; @@ -52,7 +53,7 @@ public class RelatedElementCollection implements Collection { static final Logger logger = LoggerFactory.getLogger(RelatedElementCollection.class); - ModelCollection relationshipCollection; + ModelCollectionV2 relationshipCollection; private RelationshipType relationshipTypeFilter; private String relatedElementTypeFilter; /** @@ -85,7 +86,7 @@ public RelatedElementCollection(SpdxElement owningElement, @Nullable String relatedElementTypeFilter) throws InvalidSPDXAnalysisException { Objects.requireNonNull(owningElement, "Owning element can not be null"); this.owningElement = owningElement; - this.relationshipCollection = new ModelCollection(owningElement.getModelStore(), + this.relationshipCollection = new ModelCollectionV2(owningElement.getModelStore(), owningElement.getDocumentUri(), owningElement.getId(), SpdxConstantsCompatV2.PROP_RELATIONSHIP, owningElement.getCopyManager(), Relationship.class); this.relationshipTypeFilter = relationshipTypeFilter; @@ -372,7 +373,7 @@ public int hashCode() { /** * @return the relationshipCollection */ - public ModelCollection getRelationshipCollection() { + public ModelCollectionV2 getRelationshipCollection() { return relationshipCollection; } diff --git a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java index 9e40dfaf4..bfc9bb05a 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java @@ -27,7 +27,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java index b6522c897..9bf27bc9d 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java @@ -32,11 +32,11 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java index fdda006aa..2a1c447d9 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java @@ -32,9 +32,9 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java index 1e73523fa..6372b2538 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java @@ -32,15 +32,15 @@ import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.Purpose; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.OrLaterOperator; import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.library.model.compat.v2.license.WithExceptionOperator; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.Purpose; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java index b7afc3f0f..066f70665 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java @@ -30,7 +30,7 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java index 943e475f0..9afbc50bc 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java @@ -82,7 +82,7 @@ public SpdxSnippet(IModelStore modelStore, String documentUri, String id, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, documentUri, id, copyManager, create); - allRanges = new ModelCollection(modelStore, documentUri, id, SpdxConstantsCompatV2.PROP_SNIPPET_RANGE, copyManager, StartEndPointer.class); + allRanges = new ModelCollectionV2(modelStore, documentUri, id, SpdxConstantsCompatV2.PROP_SNIPPET_RANGE, copyManager, StartEndPointer.class); } /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java index c3fe3feb2..11887c897 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java +++ b/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java @@ -18,7 +18,7 @@ /** * @author Gary O'Neall * - * Model for the SPDX license related objects + * Model for the SPDX version 2 license related objects * */ package org.spdx.library.model.compat.v2.license; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/core/Element.java b/src/main/java/org/spdx/library/model/core/Element.java new file mode 100644 index 000000000..503f54f1e --- /dev/null +++ b/src/main/java/org/spdx/library/model/core/Element.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model.core; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.storage.IModelStore; + +/** + * + * Base domain class from which all other SPDX-3.0 domain classes derive. + * + * An Element is a representation of a fundamental concept either directly inherent + * to the Bill of Materials (BOM) domain or indirectly related to the BOM domain + * and necessary for contextually characterizing BOM concepts and relationships. + * Within SPDX-3.0 structure this is the base class acting as a consistent, + * unifying, and interoperable foundation for all explicit + * and inter-relatable content objects. + * + * @author Gary O'Neall + * + */ +public abstract class Element extends Payload { + + /** + * @throws InvalidSPDXAnalysisException + */ + public Element() throws InvalidSPDXAnalysisException { + super(); + } + + /** + * Creates a new Element object + * @param modelStore Storage for the model objects - Must support model V3 classes + * @param objectUri Anonymous ID or URI for the model object + * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods + * @param create - if true, the object will be created in the store if it is not already present + * @throws InvalidSPDXAnalysisException + */ + public Element(IModelStore modelStore, String objectUri, + ModelCopyManager copyManager, boolean create) + throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Open or create an Element object with the default store + * @param objectUri Anonymous ID or URI for the model object + * @throws InvalidSPDXAnalysisException + */ + public Element(String objectUri) throws InvalidSPDXAnalysisException { + super(objectUri); + } + + //TODO: Implement properties + +} diff --git a/src/main/java/org/spdx/library/model/core/Payload.java b/src/main/java/org/spdx/library/model/core/Payload.java new file mode 100644 index 000000000..4368866d0 --- /dev/null +++ b/src/main/java/org/spdx/library/model/core/Payload.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; + +/** + * TODO: Add description from model markdown once complete + * + * @author Gary O'Neall + * + */ +public abstract class Payload extends ModelObject { + + /** + * @throws InvalidSPDXAnalysisException + */ + public Payload() throws InvalidSPDXAnalysisException { + super(); + } + + /** + * Creates a new Payload object + * @param modelStore Storage for the model objects - Must support model V3 classes + * @param objectUri Anonymous ID or URI for the model object + * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods + * @param create - if true, the object will be created in the store if it is not already present + * @throws InvalidSPDXAnalysisException + */ + public Payload(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Open or create a Payload object with the default store + * @param objectUri Anonymous ID or URI for the model object + * @throws InvalidSPDXAnalysisException + */ + public Payload(String objectUri) throws InvalidSPDXAnalysisException { + super(objectUri); + } + + //TODO: Add in creationInfo and nameSpace maps + +} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java b/src/main/java/org/spdx/library/model/enumerations/AnnotationType.java similarity index 96% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java rename to src/main/java/org/spdx/library/model/enumerations/AnnotationType.java index 8786b163f..10815a26d 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java +++ b/src/main/java/org/spdx/library/model/enumerations/AnnotationType.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java b/src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java similarity index 97% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java rename to src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java index 1d2482e0e..c444a7792 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java +++ b/src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java b/src/main/java/org/spdx/library/model/enumerations/FileType.java similarity index 96% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java rename to src/main/java/org/spdx/library/model/enumerations/FileType.java index e95f0406f..772dbaeb3 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java +++ b/src/main/java/org/spdx/library/model/enumerations/FileType.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java b/src/main/java/org/spdx/library/model/enumerations/Purpose.java similarity index 96% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java rename to src/main/java/org/spdx/library/model/enumerations/Purpose.java index c193c1604..ca530a9f5 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java +++ b/src/main/java/org/spdx/library/model/enumerations/Purpose.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java b/src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java similarity index 96% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java rename to src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java index f787f53ba..a74c0d4c9 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java +++ b/src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java b/src/main/java/org/spdx/library/model/enumerations/RelationshipType.java similarity index 98% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java rename to src/main/java/org/spdx/library/model/enumerations/RelationshipType.java index 762f32fd8..6a9cf4185 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java +++ b/src/main/java/org/spdx/library/model/enumerations/RelationshipType.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactory.java b/src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java similarity index 97% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactory.java rename to src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java index 896e4150e..31b654f90 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactory.java +++ b/src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2.enumerations; +package org.spdx.library.model.enumerations; import java.util.Collections; import java.util.HashMap; diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java b/src/main/java/org/spdx/library/model/enumerations/package-info.java similarity index 94% rename from src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java rename to src/main/java/org/spdx/library/model/enumerations/package-info.java index 3f6bce7f5..e0270e935 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java +++ b/src/main/java/org/spdx/library/model/enumerations/package-info.java @@ -24,4 +24,4 @@ * * @author Gary O'Neall */ -package org.spdx.library.model.compat.v2.enumerations; \ No newline at end of file +package org.spdx.library.model.enumerations; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java b/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java new file mode 100644 index 000000000..99983b54e --- /dev/null +++ b/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model.licensing; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.core.Element; +import org.spdx.storage.IModelStore; + +/** + * + * Abstract class representing a license combination consisting of one or more + * licenses (optionally including additional text), which may be combined + * according to the SPDX license expression syntax. + * + * An AnyLicenseInfo is used by licensing properties of software artifacts. + * It can be a NoneLicense, a NoAssertionLicense, + * single license (either on the SPDX License List or a custom-defined license); + * a single license with an "or later" operator applied; the foregoing with + * additional text applied; or a set of licenses combined by applying "AND" and + * "OR" operators recursively. + * + * @author Gary O'Neall + * + */ +public abstract class AnyLicenseInfo extends Element { + + /** + * @throws InvalidSPDXAnalysisException + */ + public AnyLicenseInfo() throws InvalidSPDXAnalysisException { + super(); + } + + /** + * @param modelStore Storage for the model objects - Must support model V3 classes + * @param objectUri Anonymous ID or URI for the model object + * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods + * @param create - if true, the object will be created in the store if it is not already present + * @throws InvalidSPDXAnalysisException + */ + public AnyLicenseInfo(IModelStore modelStore, String objectUri, + ModelCopyManager copyManager, boolean create) + throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Open or create an Element object with the default store + * @param objectUri Anonymous ID or URI for the model object + * @throws InvalidSPDXAnalysisException + */ + public AnyLicenseInfo(String objectUri) + throws InvalidSPDXAnalysisException { + super(objectUri); + } + + //TODO: Implement properties + +} diff --git a/src/main/java/org/spdx/library/ModelObjectHelper.java b/src/main/java/org/spdx/library/model/licensing/package-info.java similarity index 72% rename from src/main/java/org/spdx/library/ModelObjectHelper.java rename to src/main/java/org/spdx/library/model/licensing/package-info.java index 4bb759e01..aa60d409b 100644 --- a/src/main/java/org/spdx/library/ModelObjectHelper.java +++ b/src/main/java/org/spdx/library/model/licensing/package-info.java @@ -15,14 +15,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library; - /** - * A set of static methods to help with common ModelObject functions + * + * The Licensing namespace defines metadata fields applicable to software + * licensing. It also defines the classes and properties that comprise the + * SPDX License Expression syntax and that relate to the SPDX License List. * * @author Gary O'Neall * */ -public class ModelObjectHelper { - -} +package org.spdx.library.model.licensing; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index d30a081a1..baf2bd487 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -42,10 +42,10 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdInUseException; import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.ModelCollection; -import org.spdx.library.model.compat.v2.SpdxIdInUseException; +import org.spdx.library.model.compat.v2.ModelCollectionV2; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -305,7 +305,7 @@ public Optional getValue(String objectUri, PropertyDescriptor propertyDe } String documentUri = item.getObjectUri().substring(0, indexOfPound); String id = item.getObjectUri().substring(indexOfPound + 1); - return Optional.of(new ModelCollection<>(this, documentUri, id, propertyDescriptor, null ,null)); + return Optional.of(new ModelCollectionV2<>(this, documentUri, id, propertyDescriptor, null ,null)); } else { throw new InvalidSPDXAnalysisException("Unimplemented version 3"); } diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index a7b1e10ed..721eb5761 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -25,7 +25,7 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactory; +import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java index a4bbc3286..76e88c471 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java @@ -23,7 +23,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.model.compat.v2.ExternalRef; import org.spdx.library.model.compat.v2.ReferenceType; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.enumerations.ReferenceCategory; /** * Contains information on differences between two different External Refs. diff --git a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java index 7cf8e12b3..dc1ae775f 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java @@ -28,8 +28,8 @@ import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.Relationship; import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.library.model.enumerations.FileType; /** * Contains the results of a comparison between two SPDX files with the same name diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/SpdxModelFactoryTest.java similarity index 81% rename from src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java rename to src/test/java/org/spdx/library/SpdxModelFactoryTest.java index 38342ab86..30eeb69b5 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/SpdxModelFactoryTest.java @@ -1,14 +1,15 @@ -package org.spdx.library.model.compat.v2; +package org.spdx.library; import java.util.Optional; import java.util.stream.Stream; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.compat.v2.Annotation; +import org.spdx.library.model.compat.v2.Checksum; +import org.spdx.library.model.compat.v2.ModelObject; +import org.spdx.library.model.compat.v2.SpdxDocument; +import org.spdx.library.model.compat.v2.SpdxElement; +import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -35,18 +36,46 @@ protected void tearDown() throws Exception { } public void testCreateSpdxDocument() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testCreateModelObject2() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoolean2() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testTypeToClass() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testGetElements() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testClassUriToClass() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testGetModelObjectIModelStoreStringStringModelCopyManager2() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } + + public void testCreateSpdxDocumentV2() throws InvalidSPDXAnalysisException { SpdxDocument result = SpdxModelFactory.createSpdxDocumentV2(modelStore, DOCUMENT_URI, copyManager); assertEquals(SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, result.getId()); } - public void testCreateModelObject() throws InvalidSPDXAnalysisException { + public void testCreateModelObjectV2() throws InvalidSPDXAnalysisException { ModelObject result = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); } - public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoolean() throws InvalidSPDXAnalysisException { + public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBooleanV2() throws InvalidSPDXAnalysisException { ModelObject result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); @@ -64,7 +93,7 @@ public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBoole } } - public void testTypeToClass() throws InvalidSPDXAnalysisException { + public void testTypeToClassV2() throws InvalidSPDXAnalysisException { assertEquals(Checksum.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, SpdxMajorVersion.VERSION_2)); assertEquals(SpdxFile.class, SpdxModelFactory.typeToClass(SpdxConstantsCompatV2.CLASS_SPDX_FILE, @@ -72,7 +101,7 @@ public void testTypeToClass() throws InvalidSPDXAnalysisException { } @SuppressWarnings("unchecked") - public void testGetElements() throws InvalidSPDXAnalysisException { + public void testGetElementsV2() throws InvalidSPDXAnalysisException { ModelObject file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); ModelObject file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, @@ -125,13 +154,13 @@ public void testGetElementsNamespace() throws InvalidSPDXAnalysisException { } } - public void testClassUriToClass() throws InvalidSPDXAnalysisException { + public void testClassUriToClassV2() throws InvalidSPDXAnalysisException { assertEquals(Annotation.class, SpdxModelFactory.classUriToClass(SpdxConstantsCompatV2.SPDX_NAMESPACE + SpdxConstantsCompatV2.CLASS_ANNOTATION, SpdxMajorVersion.VERSION_2)); } - public void testGetModelObjectIModelStoreStringStringModelCopyManager() throws InvalidSPDXAnalysisException { + public void testGetModelObjectIModelStoreStringStringModelCopyManagerV2() throws InvalidSPDXAnalysisException { ModelObject result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); diff --git a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java b/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java index ff101ff7b..805639e03 100644 --- a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java +++ b/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java @@ -22,7 +22,7 @@ import java.util.Date; import java.util.Objects; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/ModelCollectionTest.java new file mode 100644 index 000000000..6a9f10dcd --- /dev/null +++ b/src/test/java/org/spdx/library/model/ModelCollectionTest.java @@ -0,0 +1,155 @@ +package org.spdx.library.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.storage.PropertyDescriptor; + +import junit.framework.TestCase; + +public class ModelCollectionTest extends TestCase { + + static final PropertyDescriptor PROPERTY_NAME = new PropertyDescriptor("property", "namespace"); + static final String[] ELEMENTS = new String[] {"e1", "e2", "e3", "e4"}; + + //TODO: Change this to a version 3 GMO + GenericModelObject gmo; + + protected void setUp() throws Exception { + super.setUp(); + DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); + gmo = new GenericModelObject(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testSize() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), null); + for (String element:ELEMENTS) { + mc.add(element); + } + assertEquals(ELEMENTS.length, mc.size()); + } + + public void testIsEmpty() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + assertTrue(mc.isEmpty()); + for (String element:ELEMENTS) { + mc.add(element); + } + assertFalse(mc.isEmpty()); + } + + public void testContains() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + for (String element:ELEMENTS) { + mc.add(element); + } + for (String element:ELEMENTS) { + assertTrue(mc.contains(element)); + } + assertFalse(mc.contains("not there")); + } + + public void testToImmutableList() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + for (String element:ELEMENTS) { + mc.add(element); + } + List result = mc.toImmutableList(); + assertEquals(ELEMENTS.length, result.size()); + for (String element:ELEMENTS) { + assertTrue(result.contains(element)); + } + } + + public void testAdd() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + assertEquals(0, mc.size()); + mc.add(ELEMENTS[0]); + assertEquals(1, mc.size()); + assertTrue(mc.contains(ELEMENTS[0])); + mc.add(ELEMENTS[1]); + assertEquals(2, mc.size()); + assertTrue(mc.contains(ELEMENTS[0])); + assertTrue(mc.contains(ELEMENTS[1])); + } + + public void testRemove() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + for (String element:ELEMENTS) { + mc.add(element); + } + assertEquals(ELEMENTS.length, mc.size()); + assertTrue(mc.contains(ELEMENTS[0])); + mc.remove(ELEMENTS[0]); + assertEquals(ELEMENTS.length-1, mc.size()); + assertFalse(mc.contains(ELEMENTS[0])); + } + + public void testContainsAll() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + for (String element:ELEMENTS) { + mc.add(element); + } + List compare = new ArrayList(Arrays.asList(ELEMENTS)); + assertTrue(mc.containsAll(compare)); + compare.add("Another"); + assertFalse(mc.containsAll(compare)); + } + + public void testAddAll() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + List compare = new ArrayList(Arrays.asList(ELEMENTS)); + mc.addAll(compare); + + assertEquals(ELEMENTS.length, mc.size()); + for (String element:ELEMENTS) { + assertTrue(mc.contains(element)); + } + } + + public void testRemoveAll() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + List list1 = Arrays.asList(ELEMENTS); + List list2 = new ArrayList(list1); + String addedElement = "added"; + list2.add(addedElement); + mc.addAll(list2); + mc.removeAll(list1); + assertEquals(1, mc.size()); + assertTrue(mc.contains(addedElement)); + } + + public void testRetainAll() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + List list1 = Arrays.asList(ELEMENTS); + List list2 = new ArrayList(list1); + String addedElement = "added"; + list2.add(addedElement); + mc.addAll(list2); + assertEquals(list2.size(), mc.size()); + mc.retainAll(list1); + assertEquals(list1.size(), mc.size()); + for (String s:list1) { + assertTrue(mc.contains(s)); + } + } + + public void testClear() throws InvalidSPDXAnalysisException { + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + for (String element:ELEMENTS) { + mc.add(element); + } + assertEquals(ELEMENTS.length, mc.size()); + mc.clear(); + assertEquals(0, mc.size()); + } + +} diff --git a/src/test/java/org/spdx/library/model/ModelObjectHelperTest.java b/src/test/java/org/spdx/library/model/ModelObjectHelperTest.java new file mode 100644 index 000000000..05ccf38a7 --- /dev/null +++ b/src/test/java/org/spdx/library/model/ModelObjectHelperTest.java @@ -0,0 +1,133 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import junit.framework.TestCase; + +/** + * @author gary + * + */ +public class ModelObjectHelperTest extends TestCase { + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#getObjectPropertyValue(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, org.spdx.library.ModelCopyManager)}. + */ + public void testGetObjectPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#setPropertyValue(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object, org.spdx.library.ModelCopyManager)}. + */ + public void testSetPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#removeProperty(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor)}. + */ + public void testRemoveProperty() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#clearValueCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor)}. + */ + public void testClearValueCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#addValueToCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object, org.spdx.library.ModelCopyManager)}. + */ + public void testAddValueToCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#replacePropertyValueCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.util.Collection, org.spdx.library.ModelCopyManager)}. + */ + public void testReplacePropertyValueCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#removePropertyValueFromCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testRemovePropertyValueFromCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#optionalStoredObjectToModelObject(java.util.Optional, org.spdx.storage.IModelStore, org.spdx.library.ModelCopyManager)}. + */ + public void testOptionalStoredObjectToModelObject() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#modelObjectToStoredObject(java.lang.Object, org.spdx.storage.IModelStore, org.spdx.library.ModelCopyManager)}. + */ + public void testModelObjectToStoredObject() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#storedObjectToModelObject(java.lang.Object, org.spdx.storage.IModelStore, org.spdx.library.ModelCopyManager)}. + */ + public void testStoredObjectToModelObject() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#modelClassToStoredClass(java.lang.Class)}. + */ + public void testModelClassToStoredClass() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#implementsIndividualUriValue(java.lang.Class)}. + */ + public void testImplementsIndividualUriValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObjectHelper#verifyCollection(java.util.Collection, java.lang.String, java.util.Set, java.lang.String)}. + */ + public void testVerifyCollection() { + fail("Not yet implemented"); + } + +} diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/ModelObjectTest.java new file mode 100644 index 000000000..5b10ec439 --- /dev/null +++ b/src/test/java/org/spdx/library/model/ModelObjectTest.java @@ -0,0 +1,294 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import junit.framework.TestCase; + +/** + * @author gary + * + */ +public class ModelObjectTest extends TestCase { + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#hashCode()}. + */ + public void testHashCode() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#ModelObject(org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager, boolean)}. + */ + public void testModelObjectIModelStoreStringModelCopyManagerBoolean() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#verify(java.lang.String)}. + */ + public void testVerifyString() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getObjectUri()}. + */ + public void testGetObjectUri() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getModelStore()}. + */ + public void testGetModelStore() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#setStrict(boolean)}. + */ + public void testSetStrict() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getPropertyValueDescriptors()}. + */ + public void testGetPropertyValueDescriptors() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetObjectPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#setPropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testSetPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#updatePropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testUpdatePropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getStringPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetStringPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getIntegerPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetIntegerPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getEnumPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetEnumPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getBooleanPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetBooleanPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetAnyLicenseInfoPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getElementPropertyValue(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetElementPropertyValue() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#removeProperty(org.spdx.storage.PropertyDescriptor)}. + */ + public void testRemoveProperty() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#updateRemoveProperty(org.spdx.storage.PropertyDescriptor)}. + */ + public void testUpdateRemoveProperty() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#clearValueCollection(org.spdx.storage.PropertyDescriptor)}. + */ + public void testClearValueCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#updateClearValueCollection(org.spdx.storage.PropertyDescriptor)}. + */ + public void testUpdateClearValueCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#addPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testAddPropertyValueToCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#updateAddPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testUpdateAddPropertyValueToCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#removePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testRemovePropertyValueFromCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#updateRemovePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + */ + public void testUpdateRemovePropertyValueFromCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValueSet(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + public void testGetObjectPropertyValueSet() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValueCollection(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + public void testGetObjectPropertyValueCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getStringCollection(org.spdx.storage.PropertyDescriptor)}. + */ + public void testGetStringCollection() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + public void testIsCollectionMembersAssignableTo() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#equivalent(org.spdx.library.model.ModelObject)}. + */ + public void testEquivalentModelObject() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#equals(java.lang.Object)}. + */ + public void testEqualsObject() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#clone(org.spdx.storage.IModelStore)}. + */ + public void testCloneIModelStore() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#copyFrom(org.spdx.library.model.ModelObject)}. + */ + public void testCopyFrom() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#copyFromV2(org.spdx.library.model.compat.v2.ModelObject)}. + */ + public void testCopyFromV2() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#setCopyManager(org.spdx.library.ModelCopyManager)}. + */ + public void testSetCopyManager() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#getCopyManager()}. + */ + public void testGetCopyManager() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ModelObject#toTypedValue()}. + */ + public void testToTypedValue() { + fail("Not yet implemented"); + } + +} diff --git a/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java similarity index 78% rename from src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java rename to src/test/java/org/spdx/library/model/SimpleUriValueTest.java index 0f583ea38..1189502c2 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SimpleUriValueTest.java +++ b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java @@ -15,15 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.compat.v2; +package org.spdx.library.model; -import org.spdx.library.DefaultModelStore; import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -46,7 +48,6 @@ public class SimpleUriValueTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); } /* (non-Javadoc) @@ -79,12 +80,15 @@ public String getIndividualURI() { * Test method for {@link org.spdx.library.compat.v2.SimpleUriValue#toModelObject(org.spdx.storage.IModelStore, java.lang.String)}. * @throws InvalidSPDXAnalysisException */ - public void testToModelObject() throws InvalidSPDXAnalysisException { - GenericModelObject gmo = new GenericModelObject(); - new SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); + public void testToModelObjectV2() throws InvalidSPDXAnalysisException { + IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + ModelCopyManager copyManager = new ModelCopyManager(); + org.spdx.library.model.compat.v2.GenericModelObject gmo = + new org.spdx.library.model.compat.v2.GenericModelObject(store, "http://doc", "id", copyManager, true); + new org.spdx.library.model.compat.v2.SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); Object result = new SimpleUriValue(EXTERNAL_SPDX_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); - assertTrue(result instanceof ExternalSpdxElement); - ExternalSpdxElement externalElement = (ExternalSpdxElement)result; + assertTrue(result instanceof org.spdx.library.model.compat.v2.ExternalSpdxElement); + org.spdx.library.model.compat.v2.ExternalSpdxElement externalElement = (org.spdx.library.model.compat.v2.ExternalSpdxElement)result; assertEquals(EXTERNAL_SPDX_ELEMENT_ID, externalElement.getExternalElementId()); assertEquals(EXTERNAL_SPDX_URI, externalElement.getExternalSpdxElementURI()); @@ -95,5 +99,9 @@ public void testToModelObject() throws InvalidSPDXAnalysisException { assertTrue(result instanceof SimpleUriValue); assertEquals(NON_INTERESTING_URI, ((SimpleUriValue)result).getIndividualURI()); } + + public void testToModelObject() throws InvalidSPDXAnalysisException { + fail("Unimplemented"); + } } diff --git a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java index dfbbe67ff..00762edc0 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java @@ -24,8 +24,8 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.enumerations.AnnotationType; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java index b024c2f61..1a4f82439 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java @@ -23,8 +23,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java index b7e05be77..70bc42c88 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java @@ -25,7 +25,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java index dd6cdbc33..fad2727df 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java @@ -25,7 +25,7 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.enumerations.ReferenceCategory; import org.spdx.library.referencetype.compat.v2.ListedReferenceTypes; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java index 3c1589a53..ae79f49fd 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java @@ -6,8 +6,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java index 31ef00fc5..5c6b8ae1c 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java @@ -5,10 +5,10 @@ import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java index b465c9a5b..7fad4b12b 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelCollectionTest.java @@ -29,7 +29,7 @@ protected void tearDown() throws Exception { } public void testSize() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), null); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), null); for (String element:ELEMENTS) { mc.add(element); } @@ -37,7 +37,7 @@ public void testSize() throws InvalidSPDXAnalysisException { } public void testIsEmpty() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); assertTrue(mc.isEmpty()); for (String element:ELEMENTS) { mc.add(element); @@ -46,7 +46,7 @@ public void testIsEmpty() throws InvalidSPDXAnalysisException { } public void testContains() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); for (String element:ELEMENTS) { mc.add(element); } @@ -57,7 +57,7 @@ public void testContains() throws InvalidSPDXAnalysisException { } public void testToImmutableList() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); for (String element:ELEMENTS) { mc.add(element); } @@ -69,7 +69,7 @@ public void testToImmutableList() throws InvalidSPDXAnalysisException { } public void testAdd() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); assertEquals(0, mc.size()); mc.add(ELEMENTS[0]); assertEquals(1, mc.size()); @@ -81,7 +81,7 @@ public void testAdd() throws InvalidSPDXAnalysisException { } public void testRemove() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); for (String element:ELEMENTS) { mc.add(element); } @@ -93,7 +93,7 @@ public void testRemove() throws InvalidSPDXAnalysisException { } public void testContainsAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); for (String element:ELEMENTS) { mc.add(element); } @@ -104,7 +104,7 @@ public void testContainsAll() throws InvalidSPDXAnalysisException { } public void testAddAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); List compare = new ArrayList(Arrays.asList(ELEMENTS)); mc.addAll(compare); @@ -115,7 +115,7 @@ public void testAddAll() throws InvalidSPDXAnalysisException { } public void testRemoveAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); List list1 = Arrays.asList(ELEMENTS); List list2 = new ArrayList(list1); String addedElement = "added"; @@ -127,7 +127,7 @@ public void testRemoveAll() throws InvalidSPDXAnalysisException { } public void testRetainAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); List list1 = Arrays.asList(ELEMENTS); List list2 = new ArrayList(list1); String addedElement = "added"; @@ -142,7 +142,7 @@ public void testRetainAll() throws InvalidSPDXAnalysisException { } public void testClear() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollectionV2 mc = new ModelCollectionV2(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getId(), PROPERTY_NAME, gmo.getCopyManager(), String.class); for (String element:ELEMENTS) { mc.add(element); } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index 636d209c3..c12a93375 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -33,11 +33,10 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdInUseException; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.TypedValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; @@ -46,6 +45,8 @@ import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.ModelUpdate; @@ -118,7 +119,6 @@ public class ModelObjectTest extends TestCase { */ protected void setUp() throws Exception { DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); - ModelStorageClassConverter.reset(); store = DefaultModelStore.getDefaultModelStore(); docUri = DefaultModelStore.getDefaultDocumentUri(); copyManager = DefaultModelStore.getDefaultCopyManager(); @@ -318,8 +318,8 @@ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { assertTrue(compareLists(entry.getValue(), result.get())); } else if (result.get() instanceof ModelObject) { assertEquals(entry.getValue(), result.get()); - } else if (result.get() instanceof ModelCollection) { - assertTrue(compareLists(entry.getValue(), ((ModelCollection)result.get()).toImmutableList())); + } else if (result.get() instanceof ModelCollectionV2) { + assertTrue(compareLists(entry.getValue(), ((ModelCollectionV2)result.get()).toImmutableList())); } else { assertEquals(entry.getValue(), result.get()); } @@ -644,7 +644,7 @@ public void testEquivalentIgnoresEmptyModelCollections() throws InvalidSPDXAnaly // Given GenericModelObject firstObject = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); GenericModelObject secondObject = new GenericModelObject(store, docUri, "testId2", copyManager, true); - ModelCollection emptyModelCollection = new ModelCollection<>(store, + ModelCollectionV2 emptyModelCollection = new ModelCollectionV2<>(store, docUri, TEST_ID, TEST_PROPERTY1, copyManager, GenericModelObject.class); firstObject.setPropertyValue(TEST_PROPERTY1, emptyModelCollection); secondObject.setPropertyValue(TEST_PROPERTY2, emptyModelCollection); @@ -884,7 +884,7 @@ public void testAnyLicenseCollection() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); addTestValues(gmo); for (int i = 0; i < TEST_ANYLICENSEINFO_LIST_PROPERTIES.length; i++) { - ModelCollection result = (ModelCollection)(ModelCollection)gmo.getObjectPropertyValueSet(TEST_ANYLICENSEINFO_LIST_PROPERTIES[i], AnyLicenseInfo.class); + ModelCollectionV2 result = (ModelCollectionV2)(ModelCollectionV2)gmo.getObjectPropertyValueSet(TEST_ANYLICENSEINFO_LIST_PROPERTIES[i], AnyLicenseInfo.class); assertTrue(compareLists(TEST_ANYLICENSEINFO_LIST_PROP_VALUES[i], result.toImmutableList())); } } diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index 9c5c5bccb..1f7636d59 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -12,10 +12,10 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.TypedValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; diff --git a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java index 28bbf383e..61829bbbc 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java @@ -20,7 +20,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java index 063105a80..0f8bedfff 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java @@ -25,7 +25,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.RelationshipType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java index e9db5a4ba..12fb5b01c 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java @@ -31,13 +31,13 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index 70bbfc786..7ee1a2069 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -30,15 +30,15 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java index 25a65cfa3..54735c573 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java @@ -27,8 +27,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java index 7819deb80..64a0c0964 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java @@ -12,15 +12,15 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java index c290a31eb..2f07346f8 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java @@ -20,7 +20,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java index e84423050..de1805bc7 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java @@ -30,14 +30,14 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.Purpose; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; +import org.spdx.library.model.enumerations.Purpose; +import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java index ebb945dbc..b667e4162 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java @@ -28,8 +28,6 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -38,6 +36,8 @@ import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java index 14d4d180a..c7f3aea10 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java @@ -27,7 +27,7 @@ import org.spdx.library.model.compat.v2.ExternalDocumentRef; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java index 7247d6884..a0806ee0d 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java @@ -28,7 +28,7 @@ import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java index f4d8f48c9..0d12f82c0 100644 --- a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java +++ b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java @@ -19,8 +19,8 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdInUseException; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.SpdxIdInUseException; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index 906ed2ea6..e2d822b79 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -34,8 +34,8 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.SpdxIdInUseException; import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.SpdxIdInUseException; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index 941715b65..19be55e68 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -49,10 +49,6 @@ import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.library.model.compat.v2.SpdxSnippet; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -67,6 +63,10 @@ import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java index 5b52d7972..5e1436913 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java @@ -31,12 +31,12 @@ import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.InvalidLicenseStringException; import org.spdx.library.model.compat.v2.license.License; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java index cf3f6bd6a..585380818 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java @@ -32,10 +32,10 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxElement; import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java index 5cacdd423..6b58bd316 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java @@ -39,13 +39,13 @@ import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; +import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.enumerations.RelationshipType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java index f3865094f..f7b8ac716 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java @@ -31,14 +31,14 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxSnippet; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; +import org.spdx.library.model.enumerations.RelationshipType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java index 9e777e974..1f441ecdc 100644 --- a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java +++ b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java @@ -10,9 +10,9 @@ import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.enumerations.FileType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; From 3f8ec18ee9a7bd4980729e41cd3c541fc231a29f Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Tue, 11 Jul 2023 15:27:17 -0700 Subject: [PATCH 11/62] Update verify to use profiles Signed-off-by: Gary O'Neall --- .../org/spdx/library/model/ModelObject.java | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 381f9ed4e..103e54bd9 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -44,7 +44,9 @@ import org.spdx.library.NotEquivalentReason.NotEquivalent; import org.spdx.library.SpdxConstants; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.CreationInfo; import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.library.model.licensing.AnyLicenseInfo; import org.spdx.storage.IModelStore; @@ -177,9 +179,10 @@ public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopy * Implementation of the specific verifications for this model object * @param specVersion Version of the SPDX spec to verify against * @param verifiedElementIds list of all Element Id's which have already been verified - prevents infinite recursion + * @param profiles list of profile identifiers to validate against * @return Any verification errors or warnings associated with this object */ - protected abstract List _verify(Set verifiedElementIds, String specVersion); + protected abstract List _verify(Set verifiedElementIds, String specVersion, List profiles); /** * Enter a critical section. leaveCriticialSection must be called. @@ -200,15 +203,37 @@ public void leaveCriticalSection(IModelStoreLock lock) { /** * @param specVersion Version of the SPDX spec to verify against * @param verifiedElementUris list of all element object URIs which have already been verified - prevents infinite recursion + * @param profiles list of profile identifiers to validate against * @return Any verification errors or warnings associated with this object */ - public List verify(Set verifiedElementUris, String specVersion) { + public List verify(Set verifiedElementUris, String specVersion, List profiles) { if (verifiedElementUris.contains(this.objectUri)) { return new ArrayList<>(); } else { // The verifiedElementId is added in the SpdxElement._verify method - return _verify(verifiedElementUris, specVersion); + return _verify(verifiedElementUris, specVersion, profiles); + } + } + + /** + * @param specVersion Version of the SPDX spec to verify against + * @param verifiedElementUris list of all element object URIs which have already been verified - prevents infinite recursion + * @return Any verification errors or warnings associated with this object + */ + public List verify(Set verifiedElementUris, String specVersion) { + List profiles = new ArrayList<>(); + if (this instanceof Element) { + Optional creationInfo; + try { + creationInfo = ((Element)this).getCreationInfo(); + if (creationInfo.isPresent()) { + profiles = new ArrayList<>(creationInfo.get().getProfiles()); + } + } catch (InvalidSPDXAnalysisException e) { + logger.error("Error getting element profile for verification", e); + } } + return verify(verifiedElementUris, specVersion, profiles); } /** @@ -219,6 +244,15 @@ public List verify() { return verify(Version.CURRENT_SPDX_VERSION); } + /** + * @param specVersion Version of the SPDX spec to verify against + * @param profiles list of profile identifiers to validate against + * @return Any verification errors or warnings associated with this object + */ + public List verify(String specVersion, List profiles) { + return verify(new HashSet(), specVersion, profiles); + } + /** * @param specVersion Version of the SPDX spec to verify against * @return Any verification errors or warnings associated with this object @@ -649,7 +683,7 @@ private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor prop * @return true if the object is "to" part of a relationships */ private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { - return SpdxConstants.CORE_PROP_RELATED_SPDX_ELEMENT.equals(propertyDescriptor); + return SpdxConstants.CORE_PROP_TO.equals(propertyDescriptor); } /** From 38879abc55d1f69df6bd756035895995217222af Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Tue, 11 Jul 2023 19:57:54 -0700 Subject: [PATCH 12/62] Fix ModelCollectionTest for no GMO Signed-off-by: Gary O'Neall --- .../java/org/spdx/library/model/ModelCollectionTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/spdx/library/model/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/ModelCollectionTest.java index 6a9f10dcd..00e80bff7 100644 --- a/src/test/java/org/spdx/library/model/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/ModelCollectionTest.java @@ -7,6 +7,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Element; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; @@ -17,12 +18,12 @@ public class ModelCollectionTest extends TestCase { static final String[] ELEMENTS = new String[] {"e1", "e2", "e3", "e4"}; //TODO: Change this to a version 3 GMO - GenericModelObject gmo; + Element gmo; protected void setUp() throws Exception { super.setUp(); DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); - gmo = new GenericModelObject(); + gmo = new Element(); } protected void tearDown() throws Exception { From d51398378118be9edbe1a559866f33ce7ae80b4a Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Thu, 13 Jul 2023 22:25:59 -0700 Subject: [PATCH 13/62] add a base builder class to ModelObject Signed-off-by: Gary O'Neall --- .../org/spdx/library/model/ModelObject.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 103e54bd9..4a27ea4a3 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -45,7 +45,9 @@ import org.spdx.library.SpdxConstants; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.CreationInfo; +import org.spdx.library.model.core.CreationInfo.CreationInfoBuilder; import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.Payload.PayloadBuilder; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.library.model.licensing.AnyLicenseInfo; @@ -169,6 +171,14 @@ public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopy } } + /** + * @param builder base builder to create the ModelObject from + * @throws InvalidSPDXAnalysisException + */ + public ModelObject(ModelObjectBuilder builder) throws InvalidSPDXAnalysisException { + this(builder.modelStore, builder.objectUri, builder.copyManager, true); + } + // Abstract methods that must be implemented in the subclasses /** * @return The class name for this object. Class names are defined in the constants file @@ -947,4 +957,20 @@ public String toString() { return this.getType() + ":" + objectUri; } + /** + * Base builder class for all model objects + * + */ + public static class ModelObjectBuilder { + + public IModelStore modelStore; + public String objectUri; + public ModelCopyManager copyManager; + + public ModelObjectBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + this.modelStore = modelStore; + this.objectUri = objectUri; + this.copyManager = copyManager; + } + } } From 4b09e2da1ddb131a4a614c200f0fa3bbc24cadaf Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 14 Jul 2023 21:55:36 -0700 Subject: [PATCH 14/62] Fixes to pass unit tests Signed-off-by: Gary O'Neall --- src/main/java/org/spdx/library/TypedValue.java | 10 +++++++++- src/main/java/org/spdx/library/model/ModelObject.java | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/spdx/library/TypedValue.java b/src/main/java/org/spdx/library/TypedValue.java index 2f1a6e071..98769fa46 100644 --- a/src/main/java/org/spdx/library/TypedValue.java +++ b/src/main/java/org/spdx/library/TypedValue.java @@ -1,6 +1,7 @@ package org.spdx.library; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -14,7 +15,14 @@ */ public class TypedValue { - static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); + static Set SPDX_CLASSES; + + static { + Set spdxClasses = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); + spdxClasses.addAll(Arrays.asList(SpdxConstants.ALL_SPDX_CLASSES)); + SPDX_CLASSES = Collections.unmodifiableSet(spdxClasses); + } + String objectUri; String type; diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 4a27ea4a3..a81c81fe9 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -147,6 +147,7 @@ public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopy } this.modelStore = modelStore; this.copyManager = copyManager; + this.objectUri = objectUri; Optional existing = modelStore.getTypedValue(objectUri); if (existing.isPresent()) { if (create && !existing.get().getType().equals(getType())) { From a095390f0c9c3abd01adad3d99ff93efdfcebfab Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sat, 15 Jul 2023 16:22:56 -0700 Subject: [PATCH 15/62] Add generated model code Signed-off-by: Gary O'Neall --- .../java/org/spdx/library/SpdxConstants.java | 315 ++++++++ .../org/spdx/library/model/ai/AIPackage.java | 670 ++++++++++++++++++ .../spdx/library/model/ai/PresenceType.java | 54 ++ .../model/ai/SafetyRiskAssessmentType.java | 56 ++ .../org/spdx/library/model/build/Build.java | 458 ++++++++++++ .../org/spdx/library/model/core/Agent.java | 138 ++++ .../spdx/library/model/core/Annotation.java | 263 +++++++ .../library/model/core/AnnotationType.java | 53 ++ .../library/model/core/AnonymousPayload.java | 136 ++++ .../org/spdx/library/model/core/Artifact.java | 340 +++++++++ .../java/org/spdx/library/model/core/Bom.java | 139 ++++ .../org/spdx/library/model/core/Bundle.java | 169 +++++ .../spdx/library/model/core/CreationInfo.java | 377 ++++++++++ .../library/model/core/DictionaryEntry.java | 211 ++++++ .../org/spdx/library/model/core/Element.java | 278 ++++++++ .../library/model/core/ElementCollection.java | 214 ++++++ .../model/core/ExternalIdentifier.java | 324 +++++++++ .../model/core/ExternalIdentifierType.java | 62 ++ .../spdx/library/model/core/ExternalMap.java | 280 ++++++++ .../library/model/core/ExternalReference.java | 278 ++++++++ .../model/core/ExternalReferenceType.java | 89 +++ .../org/spdx/library/model/core/Hash.java | 227 ++++++ .../library/model/core/HashAlgorithm.java | 77 ++ .../library/model/core/IntegrityMethod.java | 172 +++++ .../model/core/LifecycleScopeType.java | 57 ++ .../core/LifecycleScopedRelationship.java | 178 +++++ .../spdx/library/model/core/NamespaceMap.java | 217 ++++++ .../spdx/library/model/core/Organization.java | 137 ++++ .../org/spdx/library/model/core/Payload.java | 254 +++++++ .../org/spdx/library/model/core/Person.java | 136 ++++ .../model/core/PositiveIntegerRange.java | 242 +++++++ .../model/core/ProfileIdentifierType.java | 62 ++ .../spdx/library/model/core/Relationship.java | 376 ++++++++++ .../model/core/RelationshipCompleteness.java | 55 ++ .../library/model/core/RelationshipType.java | 115 +++ .../library/model/core/SoftwareAgent.java | 137 ++++ .../spdx/library/model/core/SpdxDocument.java | 138 ++++ .../org/spdx/library/model/core/Tool.java | 137 ++++ .../dataset/ConfidentialityLevelType.java | 55 ++ .../spdx/library/model/dataset/Dataset.java | 621 ++++++++++++++++ .../dataset/DatasetAvailabilityType.java | 58 ++ .../library/model/dataset/DatasetType.java | 68 ++ .../ConjunctiveLicenseSet.java | 146 ++++ .../DisjunctiveLicenseSet.java | 144 ++++ .../expandedlicense/ExtendableLicense.java | 139 ++++ .../model/licensing/AnyLicenseInfo.java | 142 ++++ .../model/licensing/CustomLicense.java | 138 ++++ .../licensing/CustomLicenseAddition.java | 141 ++++ .../spdx/library/model/licensing/License.java | 347 +++++++++ .../model/licensing/LicenseAddition.java | 249 +++++++ .../model/licensing/LicenseExpression.java | 191 +++++ .../model/licensing/ListedLicense.java | 137 ++++ .../licensing/ListedLicenseException.java | 139 ++++ .../model/licensing/OrLaterOperator.java | 145 ++++ .../model/licensing/WithAdditionOperator.java | 140 ++++ .../CvssV2VulnAssessmentRelationship.java | 155 ++++ .../CvssV3VulnAssessmentRelationship.java | 156 ++++ .../EpssVulnAssessmentRelationship.java | 197 +++++ .../model/security/ExploitCatalogType.java | 54 ++ ...loitCatalogVulnAssessmentRelationship.java | 275 +++++++ .../model/security/SsvcDecisionType.java | 56 ++ .../SsvcVulnAssessmentRelationship.java | 193 +++++ ...VexAffectedVulnAssessmentRelationship.java | 215 ++++++ .../VexFixedVulnAssessmentRelationship.java | 148 ++++ .../model/security/VexJustificationType.java | 57 ++ ...NotAffectedVulnAssessmentRelationship.java | 260 +++++++ ...vestigationVulnAssessmentRelationship.java | 148 ++++ .../VexVulnAssessmentRelationship.java | 215 ++++++ .../security/VulnAssessmentRelationship.java | 218 ++++++ .../library/model/security/Vulnerability.java | 166 +++++ .../DependencyConditionalityType.java | 56 ++ .../spdx/library/model/software/SBOMType.java | 62 ++ .../org/spdx/library/model/software/Sbom.java | 174 +++++ .../spdx/library/model/software/Snippet.java | 235 ++++++ .../model/software/SoftwareArtifact.java | 390 ++++++++++ .../software/SoftwareDependencyLinkType.java | 55 ++ .../SoftwareDependencyRelationship.java | 222 ++++++ .../model/software/SoftwarePurpose.java | 80 +++ .../spdx/library/model/software/SpdxFile.java | 172 +++++ .../library/model/software/SpdxPackage.java | 311 ++++++++ .../spdx/library/model/ai/AIPackageTest.java | 295 ++++++++ .../spdx/library/model/build/BuildTest.java | 220 ++++++ .../spdx/library/model/core/AgentTest.java | 107 +++ .../library/model/core/AnnotationTest.java | 143 ++++ .../model/core/AnonymousPayloadTest.java | 107 +++ .../spdx/library/model/core/ArtifactTest.java | 182 +++++ .../org/spdx/library/model/core/BomTest.java | 107 +++ .../spdx/library/model/core/BundleTest.java | 119 ++++ .../library/model/core/CreationInfoTest.java | 197 +++++ .../model/core/DictionaryEntryTest.java | 131 ++++ .../model/core/ElementCollectionTest.java | 133 ++++ .../spdx/library/model/core/ElementTest.java | 157 ++++ .../model/core/ExternalIdentifierTest.java | 168 +++++ .../library/model/core/ExternalMapTest.java | 156 ++++ .../model/core/ExternalReferenceTest.java | 156 ++++ .../org/spdx/library/model/core/HashTest.java | 131 ++++ .../model/core/IntegrityMethodTest.java | 119 ++++ .../core/LifecycleScopedRelationshipTest.java | 119 ++++ .../library/model/core/NamespaceMapTest.java | 131 ++++ .../library/model/core/OrganizationTest.java | 107 +++ .../spdx/library/model/core/PayloadTest.java | 145 ++++ .../spdx/library/model/core/PersonTest.java | 107 +++ .../model/core/PositiveIntegerRangeTest.java | 131 ++++ .../library/model/core/RelationshipTest.java | 180 +++++ .../library/model/core/SoftwareAgentTest.java | 107 +++ .../library/model/core/SpdxDocumentTest.java | 107 +++ .../org/spdx/library/model/core/ToolTest.java | 107 +++ .../library/model/dataset/DatasetTest.java | 268 +++++++ .../ConjunctiveLicenseSetTest.java | 107 +++ .../DisjunctiveLicenseSetTest.java | 107 +++ .../ExtendableLicenseTest.java | 107 +++ .../model/licensing/AnyLicenseInfoTest.java | 107 +++ .../licensing/CustomLicenseAdditionTest.java | 107 +++ .../model/licensing/CustomLicenseTest.java | 107 +++ .../model/licensing/LicenseAdditionTest.java | 143 ++++ .../licensing/LicenseExpressionTest.java | 119 ++++ .../library/model/licensing/LicenseTest.java | 179 +++++ .../licensing/ListedLicenseExceptionTest.java | 107 +++ .../model/licensing/ListedLicenseTest.java | 107 +++ .../model/licensing/OrLaterOperatorTest.java | 107 +++ .../licensing/WithAdditionOperatorTest.java | 107 +++ .../CvssV2VulnAssessmentRelationshipTest.java | 107 +++ .../CvssV3VulnAssessmentRelationshipTest.java | 107 +++ .../EpssVulnAssessmentRelationshipTest.java | 119 ++++ ...CatalogVulnAssessmentRelationshipTest.java | 143 ++++ .../SsvcVulnAssessmentRelationshipTest.java | 119 ++++ ...ffectedVulnAssessmentRelationshipTest.java | 132 ++++ ...exFixedVulnAssessmentRelationshipTest.java | 107 +++ ...ffectedVulnAssessmentRelationshipTest.java | 143 ++++ ...igationVulnAssessmentRelationshipTest.java | 107 +++ .../VexVulnAssessmentRelationshipTest.java | 131 ++++ .../VulnAssessmentRelationshipTest.java | 131 ++++ .../model/security/VulnerabilityTest.java | 107 +++ .../spdx/library/model/software/SbomTest.java | 120 ++++ .../library/model/software/SnippetTest.java | 131 ++++ .../model/software/SoftwareArtifactTest.java | 192 +++++ .../SoftwareDependencyRelationshipTest.java | 131 ++++ .../library/model/software/SpdxFileTest.java | 119 ++++ .../model/software/SpdxPackageTest.java | 167 +++++ 139 files changed, 22852 insertions(+) create mode 100644 generated/src/main/java/org/spdx/library/SpdxConstants.java create mode 100644 generated/src/main/java/org/spdx/library/model/ai/AIPackage.java create mode 100644 generated/src/main/java/org/spdx/library/model/ai/PresenceType.java create mode 100644 generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java create mode 100644 generated/src/main/java/org/spdx/library/model/build/Build.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Agent.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Annotation.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/AnnotationType.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Artifact.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Bom.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Bundle.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/CreationInfo.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Element.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ElementCollection.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ExternalMap.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ExternalReference.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Hash.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Organization.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Payload.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Person.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Relationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/RelationshipType.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java create mode 100644 generated/src/main/java/org/spdx/library/model/core/Tool.java create mode 100644 generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java create mode 100644 generated/src/main/java/org/spdx/library/model/dataset/Dataset.java create mode 100644 generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java create mode 100644 generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java create mode 100644 generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java create mode 100644 generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java create mode 100644 generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/License.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java create mode 100644 generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/security/Vulnerability.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SBOMType.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/Sbom.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/Snippet.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SpdxFile.java create mode 100644 generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java create mode 100644 generated/src/test/java/org/spdx/library/model/ai/AIPackageTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/build/BuildTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/AgentTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/AnnotationTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ArtifactTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/BomTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/BundleTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/CreationInfoTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ElementTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ExternalMapTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/HashTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/OrganizationTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/PayloadTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/PersonTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/RelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/core/ToolTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/dataset/DatasetTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/LicenseTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/software/SbomTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/software/SnippetTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/software/SpdxFileTest.java create mode 100644 generated/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java diff --git a/generated/src/main/java/org/spdx/library/SpdxConstants.java b/generated/src/main/java/org/spdx/library/SpdxConstants.java new file mode 100644 index 000000000..6459129b7 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/SpdxConstants.java @@ -0,0 +1,315 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import org.spdx.storage.PropertyDescriptor; + +/** + * Constants which map to the SPDX specifications + * @author Gary O'Neall + * + */ +public class SpdxConstants { + + public enum SpdxMajorVersion { + VERSION_1, + VERSION_2, + VERSION_3; + + public static SpdxMajorVersion latestVersion() { + return VERSION_3; + } + } + + /** + * AI namespace + */ + public static final String A_I_NAMESPACE = "https://spdx.org/rdf/AI"; + public static final PropertyDescriptor A_I_PROP_AUTONOMY_TYPE = new PropertyDescriptor("autonomyType", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_DOMAIN = new PropertyDescriptor("domain", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_ENERGY_CONSUMPTION = new PropertyDescriptor("energyConsumption", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_HYPERPARAMETER = new PropertyDescriptor("hyperparameter", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_INFORMATION_ABOUT_APPLICATION = new PropertyDescriptor("informationAboutApplication", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_INFORMATION_ABOUT_TRAINING = new PropertyDescriptor("informationAboutTraining", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_LIMITATION = new PropertyDescriptor("limitation", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_METRIC = new PropertyDescriptor("metric", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_METRIC_DECISION_THRESHOLD = new PropertyDescriptor("metricDecisionThreshold", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_MODEL_DATA_PREPROCESSING = new PropertyDescriptor("modelDataPreprocessing", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_MODEL_EXPLAINABILITY = new PropertyDescriptor("modelExplainability", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_SAFETY_RISK_ASSESSMENT = new PropertyDescriptor("safetyRiskAssessment", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_SENSITIVE_PERSONAL_INFORMATION = new PropertyDescriptor("sensitivePersonalInformation", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_STANDARD_COMPLIANCE = new PropertyDescriptor("standardCompliance", A_I_NAMESPACE); + public static final PropertyDescriptor A_I_PROP_TYPE_OF_MODEL = new PropertyDescriptor("typeOfModel", A_I_NAMESPACE); + + /** + * Build namespace + */ + public static final String BUILD_NAMESPACE = "https://spdx.org/rdf/Build"; + public static final PropertyDescriptor BUILD_PROP_BUILD_END_TIME = new PropertyDescriptor("buildEndTime", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_BUILD_ID = new PropertyDescriptor("buildId", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_BUILD_START_TIME = new PropertyDescriptor("buildStartTime", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_BUILD_TYPE = new PropertyDescriptor("buildType", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_CONFIG_SOURCE_DIGEST = new PropertyDescriptor("configSourceDigest", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT = new PropertyDescriptor("configSourceEntrypoint", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_CONFIG_SOURCE_URI = new PropertyDescriptor("configSourceUri", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_ENVIRONMENT = new PropertyDescriptor("environment", BUILD_NAMESPACE); + public static final PropertyDescriptor BUILD_PROP_PARAMETERS = new PropertyDescriptor("parameters", BUILD_NAMESPACE); + + /** + * Core namespace + */ + public static final String CORE_NAMESPACE = "https://spdx.org/rdf/Core"; + public static final PropertyDescriptor CORE_PROP_ALGORITHM = new PropertyDescriptor("algorithm", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_ANNOTATION_TYPE = new PropertyDescriptor("annotationType", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_BEGIN = new PropertyDescriptor("begin", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_BUILT_TIME = new PropertyDescriptor("builtTime", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_COMMENT = new PropertyDescriptor("comment", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_COMPLETENESS = new PropertyDescriptor("completeness", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_CONTENT_TYPE = new PropertyDescriptor("contentType", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_CONTEXT = new PropertyDescriptor("context", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_CREATED = new PropertyDescriptor("created", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_CREATED_BY = new PropertyDescriptor("createdBy", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_CREATED_USING = new PropertyDescriptor("createdUsing", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_CREATION_INFO = new PropertyDescriptor("creationInfo", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_DATA_LICENSE = new PropertyDescriptor("dataLicense", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_DEFINING_DOCUMENT = new PropertyDescriptor("definingDocument", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_DESCRIPTION = new PropertyDescriptor("description", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_ELEMENT = new PropertyDescriptor("element", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_END = new PropertyDescriptor("end", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_END_TIME = new PropertyDescriptor("endTime", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_ID = new PropertyDescriptor("externalId", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_IDENTIFIER = new PropertyDescriptor("externalIdentifier", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_IDENTIFIER_TYPE = new PropertyDescriptor("externalIdentifierType", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_REFERENCE = new PropertyDescriptor("externalReference", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_REFERENCE_TYPE = new PropertyDescriptor("externalReferenceType", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_FROM = new PropertyDescriptor("from", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_HASH_VALUE = new PropertyDescriptor("hashValue", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_IDENTIFIER = new PropertyDescriptor("identifier", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_IDENTIFIER_LOCATOR = new PropertyDescriptor("identifierLocator", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_IMPORTS = new PropertyDescriptor("imports", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_ISSUING_AUTHORITY = new PropertyDescriptor("issuingAuthority", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_KEY = new PropertyDescriptor("key", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_LOCATION_HINT = new PropertyDescriptor("locationHint", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_LOCATOR = new PropertyDescriptor("locator", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_NAMESPACE = new PropertyDescriptor("namespace", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_NAMESPACES = new PropertyDescriptor("namespaces", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_ORIGINATED_BY = new PropertyDescriptor("originatedBy", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_PREFIX = new PropertyDescriptor("prefix", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_PROFILE = new PropertyDescriptor("profile", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_RELATIONSHIP_TYPE = new PropertyDescriptor("relationshipType", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_RELEASE_TIME = new PropertyDescriptor("releaseTime", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_ROOT_ELEMENT = new PropertyDescriptor("rootElement", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_SCOPE = new PropertyDescriptor("scope", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_SPEC_VERSION = new PropertyDescriptor("specVersion", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_STANDARD = new PropertyDescriptor("standard", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_START_TIME = new PropertyDescriptor("startTime", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_STATEMENT = new PropertyDescriptor("statement", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_SUBJECT = new PropertyDescriptor("subject", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_SUMMARY = new PropertyDescriptor("summary", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_SUPPLIED_BY = new PropertyDescriptor("suppliedBy", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_TO = new PropertyDescriptor("to", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_VALID_UNTIL_TIME = new PropertyDescriptor("validUntilTime", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_VALUE = new PropertyDescriptor("value", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_VERIFIED_USING = new PropertyDescriptor("verifiedUsing", CORE_NAMESPACE); + + /** + * Dataset namespace + */ + public static final String DATASET_NAMESPACE = "https://spdx.org/rdf/Dataset"; + public static final PropertyDescriptor DATASET_PROP_ANONYMIZATION_METHOD_USED = new PropertyDescriptor("anonymizationMethodUsed", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_CONFIDENTIALITY_LEVEL = new PropertyDescriptor("confidentialityLevel", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATA_COLLECTION_PROCESS = new PropertyDescriptor("dataCollectionProcess", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATA_PREPROCESSING = new PropertyDescriptor("dataPreprocessing", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATASET_AVAILABILITY = new PropertyDescriptor("datasetAvailability", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATASET_NOISE = new PropertyDescriptor("datasetNoise", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATASET_SIZE = new PropertyDescriptor("datasetSize", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATASET_TYPE = new PropertyDescriptor("datasetType", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_DATASET_UPDATE_MECHANISM = new PropertyDescriptor("datasetUpdateMechanism", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_INTENDED_USE = new PropertyDescriptor("intendedUse", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_KNOWN_BIAS = new PropertyDescriptor("knownBias", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION = new PropertyDescriptor("sensitivePersonalInformation", DATASET_NAMESPACE); + public static final PropertyDescriptor DATASET_PROP_SENSOR = new PropertyDescriptor("sensor", DATASET_NAMESPACE); + + /** + * Licensing namespace + */ + public static final String LICENSING_NAMESPACE = "https://spdx.org/rdf/Licensing"; + public static final PropertyDescriptor LICENSING_PROP_ADDITION_TEXT = new PropertyDescriptor("additionText", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_IS_DEPRECATED_ADDITION_ID = new PropertyDescriptor("isDeprecatedAdditionId", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_IS_DEPRECATED_LICENSE_ID = new PropertyDescriptor("isDeprecatedLicenseId", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_IS_FSF_LIBRE = new PropertyDescriptor("isFsfLibre", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_IS_OSI_APPROVED = new PropertyDescriptor("isOsiApproved", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_LICENSE_EXPRESSION = new PropertyDescriptor("licenseExpression", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_LICENSE_TEXT = new PropertyDescriptor("licenseText", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_STANDARD_ADDITION_TEMPLATE = new PropertyDescriptor("standardAdditionTemplate", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_STANDARD_LICENSE_HEADER = new PropertyDescriptor("standardLicenseHeader", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_STANDARD_LICENSE_TEMPLATE = new PropertyDescriptor("standardLicenseTemplate", LICENSING_NAMESPACE); + + /** + * Security namespace + */ + public static final String SECURITY_NAMESPACE = "https://spdx.org/rdf/Security"; + public static final PropertyDescriptor SECURITY_PROP_ACTION_STATEMENT = new PropertyDescriptor("actionStatement", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_ACTION_STATEMENT_TIME = new PropertyDescriptor("actionStatementTime", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_ASSESSED_ELEMENT = new PropertyDescriptor("assessedElement", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_CATALOG_TYPE = new PropertyDescriptor("catalogType", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_DECISION_TYPE = new PropertyDescriptor("decisionType", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_EXPLOITED = new PropertyDescriptor("exploited", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_IMPACT_STATEMENT = new PropertyDescriptor("impactStatement", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_IMPACT_STATEMENT_TIME = new PropertyDescriptor("impactStatementTime", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_JUSTIFICATION_TYPE = new PropertyDescriptor("justificationType", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_LOCATOR = new PropertyDescriptor("locator", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_PROBABILITY = new PropertyDescriptor("probability", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_STATUS_NOTES = new PropertyDescriptor("statusNotes", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_SUPPLIED_BY = new PropertyDescriptor("suppliedBy", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_VEX_VERSION = new PropertyDescriptor("vexVersion", SECURITY_NAMESPACE); + + /** + * Software namespace + */ + public static final String SOFTWARE_NAMESPACE = "https://spdx.org/rdf/Software"; + public static final PropertyDescriptor SOFTWARE_PROP_ADDITIONAL_PURPOSE = new PropertyDescriptor("additionalPurpose", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_ATTRIBUTION_TEXT = new PropertyDescriptor("attributionText", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_BYTE_RANGE = new PropertyDescriptor("byteRange", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_CONCLUDED_LICENSE = new PropertyDescriptor("concludedLicense", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_CONDITIONALITY = new PropertyDescriptor("conditionality", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_CONTENT_IDENTIFIER = new PropertyDescriptor("contentIdentifier", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_CONTENT_TYPE = new PropertyDescriptor("contentType", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_COPYRIGHT_TEXT = new PropertyDescriptor("copyrightText", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_DECLARED_LICENSE = new PropertyDescriptor("declaredLicense", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_DOWNLOAD_LOCATION = new PropertyDescriptor("downloadLocation", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_HOME_PAGE = new PropertyDescriptor("homePage", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_LINE_RANGE = new PropertyDescriptor("lineRange", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_PACKAGE_URL = new PropertyDescriptor("packageUrl", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_PACKAGE_VERSION = new PropertyDescriptor("packageVersion", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_PRIMARY_PURPOSE = new PropertyDescriptor("primaryPurpose", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_SBOM_TYPE = new PropertyDescriptor("sbomType", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_SOFTWARE_LINKAGE = new PropertyDescriptor("softwareLinkage", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_SOURCE_INFO = new PropertyDescriptor("sourceInfo", SOFTWARE_NAMESPACE); + + // class types + static final String SOFTWARE_SOFTWARE_PURPOSE = "Software.SoftwarePurpose"; + static final String DATASET_DATASET = "Dataset.Dataset"; + static final String CORE_SEM_VER = "Core.SemVer"; + static final String CORE_LIFECYCLE_SCOPE_TYPE = "Core.LifecycleScopeType"; + static final String LICENSING_WITH_ADDITION_OPERATOR = "Licensing.WithAdditionOperator"; + static final String SECURITY_VEX_JUSTIFICATION_TYPE = "Security.VexJustificationType"; + static final String SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE = "Software.SoftwareDependencyLinkType"; + static final String DATASET_CONFIDENTIALITY_LEVEL_TYPE = "Dataset.ConfidentialityLevelType"; + static final String SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP = "Software.SoftwareDependencyRelationship"; + static final String CORE_HASH_ALGORITHM = "Core.HashAlgorithm"; + static final String CORE_EXTERNAL_REFERENCE_TYPE = "Core.ExternalReferenceType"; + static final String SOFTWARE_SNIPPET = "Software.Snippet"; + static final String SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP = "Security.SsvcVulnAssessmentRelationship"; + static final String SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexUnderInvestigationVulnAssessmentRelationship"; + static final String CORE_ANONYMOUS_PAYLOAD = "Core.AnonymousPayload"; + static final String LICENSING_LICENSE_ADDITION = "Licensing.LicenseAddition"; + static final String DATASET_DATASET_TYPE = "Dataset.DatasetType"; + static final String LICENSING_OR_LATER_OPERATOR = "Licensing.OrLaterOperator"; + static final String CORE_POSITIVE_INTEGER_RANGE = "Core.PositiveIntegerRange"; + static final String DATASET_DATASET_AVAILABILITY_TYPE = "Dataset.DatasetAvailabilityType"; + static final String SOFTWARE_S_B_O_M_TYPE = "Software.SBOMType"; + static final String SECURITY_VULN_ASSESSMENT_RELATIONSHIP = "Security.VulnAssessmentRelationship"; + static final String SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP = "Security.EpssVulnAssessmentRelationship"; + static final String EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET = "ExpandedLicense.ConjunctiveLicenseSet"; + static final String SECURITY_CVSS_V_2_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV2VulnAssessmentRelationship"; + static final String CORE_RELATIONSHIP_COMPLETENESS = "Core.RelationshipCompleteness"; + static final String CORE_PROFILE_IDENTIFIER_TYPE = "Core.ProfileIdentifierType"; + static final String SOFTWARE_SOFTWARE_ARTIFACT = "Software.SoftwareArtifact"; + static final String LICENSING_LISTED_LICENSE = "Licensing.ListedLicense"; + static final String SECURITY_SSVC_DECISION_TYPE = "Security.SsvcDecisionType"; + static final String SOFTWARE_SPDX_FILE = "Software.SpdxFile"; + static final String CORE_ANNOTATION = "Core.Annotation"; + static final String CORE_MEDIA_TYPE = "Core.MediaType"; + static final String CORE_TOOL = "Core.Tool"; + static final String CORE_EXTERNAL_MAP = "Core.ExternalMap"; + static final String CORE_EXTERNAL_IDENTIFIER = "Core.ExternalIdentifier"; + static final String CORE_ANNOTATION_TYPE = "Core.AnnotationType"; + static final String LICENSING_ANY_LICENSE_INFO = "Licensing.AnyLicenseInfo"; + static final String CORE_ELEMENT_COLLECTION = "Core.ElementCollection"; + static final String CORE_HASH = "Core.Hash"; + static final String A_I_SAFETY_RISK_ASSESSMENT_TYPE = "AI.SafetyRiskAssessmentType"; + static final String SECURITY_CVSS_V_3_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV3VulnAssessmentRelationship"; + static final String LICENSING_LICENSE_EXPRESSION = "Licensing.LicenseExpression"; + static final String CORE_LIFECYCLE_SCOPED_RELATIONSHIP = "Core.LifecycleScopedRelationship"; + static final String LICENSING_LICENSE = "Licensing.License"; + static final String SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE = "Software.DependencyConditionalityType"; + static final String CORE_INTEGRITY_METHOD = "Core.IntegrityMethod"; + static final String CORE_BUNDLE = "Core.Bundle"; + static final String SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP = "Security.ExploitCatalogVulnAssessmentRelationship"; + static final String CORE_ARTIFACT = "Core.Artifact"; + static final String LICENSING_CUSTOM_LICENSE = "Licensing.CustomLicense"; + static final String CORE_EXTERNAL_REFERENCE = "Core.ExternalReference"; + static final String CORE_DICTIONARY_ENTRY = "Core.DictionaryEntry"; + static final String EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET = "ExpandedLicense.DisjunctiveLicenseSet"; + static final String LICENSING_LISTED_LICENSE_EXCEPTION = "Licensing.ListedLicenseException"; + static final String CORE_EXTERNAL_IDENTIFIER_TYPE = "Core.ExternalIdentifierType"; + static final String SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexNotAffectedVulnAssessmentRelationship"; + static final String CORE_ELEMENT = "Core.Element"; + static final String SECURITY_VULNERABILITY = "Security.Vulnerability"; + static final String CORE_NAMESPACE_MAP = "Core.NamespaceMap"; + static final String CORE_PERSON = "Core.Person"; + static final String SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexVulnAssessmentRelationship"; + static final String CORE_ORGANIZATION = "Core.Organization"; + static final String SECURITY_EXPLOIT_CATALOG_TYPE = "Security.ExploitCatalogType"; + static final String CORE_CREATION_INFO = "Core.CreationInfo"; + static final String CORE_RELATIONSHIP = "Core.Relationship"; + static final String SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexAffectedVulnAssessmentRelationship"; + static final String BUILD_BUILD = "Build.Build"; + static final String SOFTWARE_SPDX_PACKAGE = "Software.SpdxPackage"; + static final String SOFTWARE_SBOM = "Software.Sbom"; + static final String CORE_SPDX_DOCUMENT = "Core.SpdxDocument"; + static final String SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexFixedVulnAssessmentRelationship"; + static final String A_I_A_I_PACKAGE = "AI.AIPackage"; + static final String CORE_PAYLOAD = "Core.Payload"; + static final String A_I_PRESENCE_TYPE = "AI.PresenceType"; + static final String LICENSING_CUSTOM_LICENSE_ADDITION = "Licensing.CustomLicenseAddition"; + static final String CORE_BOM = "Core.Bom"; + static final String CORE_SOFTWARE_AGENT = "Core.SoftwareAgent"; + static final String EXPANDED_LICENSE_EXTENDABLE_LICENSE = "ExpandedLicense.ExtendableLicense"; + static final String CORE_AGENT = "Core.Agent"; + static final String CORE_DATE_TIME = "Core.DateTime"; + static final String CORE_RELATIONSHIP_TYPE = "Core.RelationshipType"; + + static final String[] ALL_SPDX_CLASSES = {SOFTWARE_SOFTWARE_PURPOSE, DATASET_DATASET, CORE_SEM_VER, + CORE_LIFECYCLE_SCOPE_TYPE, LICENSING_WITH_ADDITION_OPERATOR, SECURITY_VEX_JUSTIFICATION_TYPE, + SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE, DATASET_CONFIDENTIALITY_LEVEL_TYPE, + SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP, CORE_HASH_ALGORITHM, CORE_EXTERNAL_REFERENCE_TYPE, + SOFTWARE_SNIPPET, SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP, + CORE_ANONYMOUS_PAYLOAD, LICENSING_LICENSE_ADDITION, DATASET_DATASET_TYPE, + LICENSING_OR_LATER_OPERATOR, CORE_POSITIVE_INTEGER_RANGE, DATASET_DATASET_AVAILABILITY_TYPE, + SOFTWARE_S_B_O_M_TYPE, SECURITY_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP, + EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET, SECURITY_CVSS_V_2_VULN_ASSESSMENT_RELATIONSHIP, + CORE_RELATIONSHIP_COMPLETENESS, CORE_PROFILE_IDENTIFIER_TYPE, SOFTWARE_SOFTWARE_ARTIFACT, + LICENSING_LISTED_LICENSE, SECURITY_SSVC_DECISION_TYPE, SOFTWARE_SPDX_FILE, + CORE_ANNOTATION, CORE_MEDIA_TYPE, CORE_TOOL, CORE_EXTERNAL_MAP, CORE_EXTERNAL_IDENTIFIER, + CORE_ANNOTATION_TYPE, LICENSING_ANY_LICENSE_INFO, CORE_ELEMENT_COLLECTION, + CORE_HASH, A_I_SAFETY_RISK_ASSESSMENT_TYPE, SECURITY_CVSS_V_3_VULN_ASSESSMENT_RELATIONSHIP, + LICENSING_LICENSE_EXPRESSION, CORE_LIFECYCLE_SCOPED_RELATIONSHIP, LICENSING_LICENSE, + SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE, CORE_INTEGRITY_METHOD, CORE_BUNDLE, + SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP, CORE_ARTIFACT, LICENSING_CUSTOM_LICENSE, + CORE_EXTERNAL_REFERENCE, CORE_DICTIONARY_ENTRY, EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET, + LICENSING_LISTED_LICENSE_EXCEPTION, CORE_EXTERNAL_IDENTIFIER_TYPE, SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, + CORE_ELEMENT, SECURITY_VULNERABILITY, CORE_NAMESPACE_MAP, CORE_PERSON, + SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP, CORE_ORGANIZATION, SECURITY_EXPLOIT_CATALOG_TYPE, + CORE_CREATION_INFO, CORE_RELATIONSHIP, SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, + BUILD_BUILD, SOFTWARE_SPDX_PACKAGE, SOFTWARE_SBOM, CORE_SPDX_DOCUMENT, + SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP, A_I_A_I_PACKAGE, CORE_PAYLOAD, + A_I_PRESENCE_TYPE, LICENSING_CUSTOM_LICENSE_ADDITION, CORE_BOM, CORE_SOFTWARE_AGENT, + EXPANDED_LICENSE_EXTENDABLE_LICENSE, CORE_AGENT, CORE_DATE_TIME, CORE_RELATIONSHIP_TYPE}; +} diff --git a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java b/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java new file mode 100644 index 000000000..af30410f3 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java @@ -0,0 +1,670 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.ai; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; +import org.spdx.library.model.core.DictionaryEntry; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.software.SpdxPackage; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Metadata information that can be added to a package to describe an AI application + * or trained AI model. External property restriction on /Core/Artifact/suppliedBy: + * minCount: 1 External property restriction on /Software/Package/downloadLocation: + * minCount: 1 External property restriction on /Software/Package/packageVersion: + * minCount: 1 External property restriction on /Software/SoftwareArtifact/primaryPurpose: + * minCount: 1 External property restriction on /Core/Artifact/releaseTime: minCount: + * 1 + */ +public class AIPackage extends SpdxPackage { + + Collection metrics; + Collection hyperparameters; + Collection metricDecisionThresholds; + Collection domains; + Collection standardCompliances; + Collection modelDataPreprocessings; + Collection typeOfModels; + Collection modelExplainabilitys; + + /** + * Create the AIPackage with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the AIPackage + */ + public AIPackage() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the AIPackage + * @throws InvalidSPDXAnalysisException when unable to create the AIPackage + */ + public AIPackage(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the AIPackage is to be stored + * @param objectUri URI or anonymous ID for the AIPackage + * @param copyManager Copy manager for the AIPackage - can be null if copying is not required + * @param create true if AIPackage is to be created + * @throws InvalidSPDXAnalysisException when unable to create the AIPackage + */ + @SuppressWarnings("unchecked") + public AIPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); + hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); + metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); + domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); + standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); + modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); + modelExplainabilitys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_EXPLAINABILITY, String.class); + } + + /** + * Create the AIPackage from the builder - used in the builder class + * @param builder Builder to create the AIPackage from + * @throws InvalidSPDXAnalysisException when unable to create the AIPackage + */ + protected AIPackage(AIPackageBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); + hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); + metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); + domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); + standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); + modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); + modelExplainabilitys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_EXPLAINABILITY, String.class); + getMetrics().addAll(builder.metrics); + getHyperparameters().addAll(builder.hyperparameters); + getMetricDecisionThresholds().addAll(builder.metricDecisionThresholds); + getDomains().addAll(builder.domains); + getStandardCompliances().addAll(builder.standardCompliances); + getModelDataPreprocessings().addAll(builder.modelDataPreprocessings); + getTypeOfModels().addAll(builder.typeOfModels); + getModelExplainabilitys().addAll(builder.modelExplainabilitys); + setSensitivePersonalInformation(builder.sensitivePersonalInformation); + setSafetyRiskAssessment(builder.safetyRiskAssessment); + setAutonomyType(builder.autonomyType); + setInformationAboutTraining(builder.informationAboutTraining); + setLimitation(builder.limitation); + setEnergyConsumption(builder.energyConsumption); + setInformationAboutApplication(builder.informationAboutApplication); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "AI.AIPackage"; + } + + // Getters and Setters + public Collection getMetrics() { + return metrics; + } + public Collection getHyperparameters() { + return hyperparameters; + } + public Collection getMetricDecisionThresholds() { + return metricDecisionThresholds; + } + public Collection getDomains() { + return domains; + } + public Collection getStandardCompliances() { + return standardCompliances; + } + public Collection getModelDataPreprocessings() { + return modelDataPreprocessings; + } + public Collection getTypeOfModels() { + return typeOfModels; + } + public Collection getModelExplainabilitys() { + return modelExplainabilitys; + } + + + /** + * @return the sensitivePersonalInformation + */ + @SuppressWarnings("unchecked") + public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_SENSITIVE_PERSONAL_INFORMATION); + if (retval.isPresent()) { + if (!(retval.get() instanceof PresenceType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param sensitivePersonalInformation the sensitivePersonalInformation to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setSensitivePersonalInformation(@Nullable PresenceType sensitivePersonalInformation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_SENSITIVE_PERSONAL_INFORMATION, sensitivePersonalInformation); + return this; + } + + /** + * @return the safetyRiskAssessment + */ + @SuppressWarnings("unchecked") + public Optional getSafetyRiskAssessment() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_SAFETY_RISK_ASSESSMENT); + if (retval.isPresent()) { + if (!(retval.get() instanceof SafetyRiskAssessmentType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param safetyRiskAssessment the safetyRiskAssessment to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setSafetyRiskAssessment(@Nullable SafetyRiskAssessmentType safetyRiskAssessment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_SAFETY_RISK_ASSESSMENT, safetyRiskAssessment); + return this; + } + + /** + * @return the autonomyType + */ + @SuppressWarnings("unchecked") + public Optional getAutonomyType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_AUTONOMY_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof PresenceType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param autonomyType the autonomyType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setAutonomyType(@Nullable PresenceType autonomyType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_AUTONOMY_TYPE, autonomyType); + return this; + } + + /** + * @return the informationAboutTraining + */ + public Optional getInformationAboutTraining() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING); + } + /** + * @param informationAboutTraining the informationAboutTraining to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setInformationAboutTraining(@Nullable String informationAboutTraining) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING, informationAboutTraining); + return this; + } + + /** + * @return the limitation + */ + public Optional getLimitation() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.A_I_PROP_LIMITATION); + } + /** + * @param limitation the limitation to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setLimitation(@Nullable String limitation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_LIMITATION, limitation); + return this; + } + + /** + * @return the energyConsumption + */ + public Optional getEnergyConsumption() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.A_I_PROP_ENERGY_CONSUMPTION); + } + /** + * @param energyConsumption the energyConsumption to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setEnergyConsumption(@Nullable String energyConsumption) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_ENERGY_CONSUMPTION, energyConsumption); + return this; + } + + /** + * @return the informationAboutApplication + */ + public Optional getInformationAboutApplication() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_APPLICATION); + } + /** + * @param informationAboutApplication the informationAboutApplication to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setInformationAboutApplication(@Nullable String informationAboutApplication) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_APPLICATION, informationAboutApplication); + return this; + } + + + @Override + public String toString() { + return "AIPackage: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional sensitivePersonalInformation = getSensitivePersonalInformation(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting sensitivePersonalInformation for AIPackage: "+e.getMessage()); + } + try { + Optional safetyRiskAssessment = getSafetyRiskAssessment(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting safetyRiskAssessment for AIPackage: "+e.getMessage()); + } + try { + Optional autonomyType = getAutonomyType(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting autonomyType for AIPackage: "+e.getMessage()); + } + try { + Optional informationAboutTraining = getInformationAboutTraining(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting informationAboutTraining for AIPackage: "+e.getMessage()); + } + try { + Optional limitation = getLimitation(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting limitation for AIPackage: "+e.getMessage()); + } + try { + Optional energyConsumption = getEnergyConsumption(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting energyConsumption for AIPackage: "+e.getMessage()); + } + try { + Optional informationAboutApplication = getInformationAboutApplication(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting informationAboutApplication for AIPackage: "+e.getMessage()); + } + for (DictionaryEntry metric:metrics) { + retval.addAll(metric.verify(verifiedIds, specVersion, profiles)); + } + for (DictionaryEntry hyperparameter:hyperparameters) { + retval.addAll(hyperparameter.verify(verifiedIds, specVersion, profiles)); + } + for (DictionaryEntry metricDecisionThreshold:metricDecisionThresholds) { + retval.addAll(metricDecisionThreshold.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class AIPackageBuilder extends SpdxPackageBuilder { + + public AIPackageBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection metrics = new ArrayList<>(); + Collection hyperparameters = new ArrayList<>(); + Collection metricDecisionThresholds = new ArrayList<>(); + Collection domains = new ArrayList<>(); + Collection standardCompliances = new ArrayList<>(); + Collection modelDataPreprocessings = new ArrayList<>(); + Collection typeOfModels = new ArrayList<>(); + Collection modelExplainabilitys = new ArrayList<>(); + PresenceType sensitivePersonalInformation = null; + SafetyRiskAssessmentType safetyRiskAssessment = null; + PresenceType autonomyType = null; + String informationAboutTraining = null; + String limitation = null; + String energyConsumption = null; + String informationAboutApplication = null; + + + /** + * Adds a metric to the initial collection + * @parameter metric metric to add + * @return this for chaining + **/ + AIPackageBuilder addmetric(DictionaryEntry metric) { + if (Objects.nonNull(metric)) { + metrics.add(metric); + } + return this; + } + + /** + * Adds all elements from a collection to the initial metric collection + * @parameter metricCollection collection to initialize the metric + * @return this for chaining + **/ + AIPackageBuilder addAllmetric(Collection metricCollection) { + if (Objects.nonNull(metricCollection)) { + metrics.addAll(metricCollection); + } + return this; + } + + /** + * Adds a hyperparameter to the initial collection + * @parameter hyperparameter hyperparameter to add + * @return this for chaining + **/ + AIPackageBuilder addhyperparameter(DictionaryEntry hyperparameter) { + if (Objects.nonNull(hyperparameter)) { + hyperparameters.add(hyperparameter); + } + return this; + } + + /** + * Adds all elements from a collection to the initial hyperparameter collection + * @parameter hyperparameterCollection collection to initialize the hyperparameter + * @return this for chaining + **/ + AIPackageBuilder addAllhyperparameter(Collection hyperparameterCollection) { + if (Objects.nonNull(hyperparameterCollection)) { + hyperparameters.addAll(hyperparameterCollection); + } + return this; + } + + /** + * Adds a metricDecisionThreshold to the initial collection + * @parameter metricDecisionThreshold metricDecisionThreshold to add + * @return this for chaining + **/ + AIPackageBuilder addmetricDecisionThreshold(DictionaryEntry metricDecisionThreshold) { + if (Objects.nonNull(metricDecisionThreshold)) { + metricDecisionThresholds.add(metricDecisionThreshold); + } + return this; + } + + /** + * Adds all elements from a collection to the initial metricDecisionThreshold collection + * @parameter metricDecisionThresholdCollection collection to initialize the metricDecisionThreshold + * @return this for chaining + **/ + AIPackageBuilder addAllmetricDecisionThreshold(Collection metricDecisionThresholdCollection) { + if (Objects.nonNull(metricDecisionThresholdCollection)) { + metricDecisionThresholds.addAll(metricDecisionThresholdCollection); + } + return this; + } + + /** + * Adds a domain to the initial collection + * @parameter domain domain to add + * @return this for chaining + **/ + AIPackageBuilder adddomain(String domain) { + if (Objects.nonNull(domain)) { + domains.add(domain); + } + return this; + } + + /** + * Adds all elements from a collection to the initial domain collection + * @parameter domainCollection collection to initialize the domain + * @return this for chaining + **/ + AIPackageBuilder addAlldomain(Collection domainCollection) { + if (Objects.nonNull(domainCollection)) { + domains.addAll(domainCollection); + } + return this; + } + + /** + * Adds a standardCompliance to the initial collection + * @parameter standardCompliance standardCompliance to add + * @return this for chaining + **/ + AIPackageBuilder addstandardCompliance(String standardCompliance) { + if (Objects.nonNull(standardCompliance)) { + standardCompliances.add(standardCompliance); + } + return this; + } + + /** + * Adds all elements from a collection to the initial standardCompliance collection + * @parameter standardComplianceCollection collection to initialize the standardCompliance + * @return this for chaining + **/ + AIPackageBuilder addAllstandardCompliance(Collection standardComplianceCollection) { + if (Objects.nonNull(standardComplianceCollection)) { + standardCompliances.addAll(standardComplianceCollection); + } + return this; + } + + /** + * Adds a modelDataPreprocessing to the initial collection + * @parameter modelDataPreprocessing modelDataPreprocessing to add + * @return this for chaining + **/ + AIPackageBuilder addmodelDataPreprocessing(String modelDataPreprocessing) { + if (Objects.nonNull(modelDataPreprocessing)) { + modelDataPreprocessings.add(modelDataPreprocessing); + } + return this; + } + + /** + * Adds all elements from a collection to the initial modelDataPreprocessing collection + * @parameter modelDataPreprocessingCollection collection to initialize the modelDataPreprocessing + * @return this for chaining + **/ + AIPackageBuilder addAllmodelDataPreprocessing(Collection modelDataPreprocessingCollection) { + if (Objects.nonNull(modelDataPreprocessingCollection)) { + modelDataPreprocessings.addAll(modelDataPreprocessingCollection); + } + return this; + } + + /** + * Adds a typeOfModel to the initial collection + * @parameter typeOfModel typeOfModel to add + * @return this for chaining + **/ + AIPackageBuilder addtypeOfModel(String typeOfModel) { + if (Objects.nonNull(typeOfModel)) { + typeOfModels.add(typeOfModel); + } + return this; + } + + /** + * Adds all elements from a collection to the initial typeOfModel collection + * @parameter typeOfModelCollection collection to initialize the typeOfModel + * @return this for chaining + **/ + AIPackageBuilder addAlltypeOfModel(Collection typeOfModelCollection) { + if (Objects.nonNull(typeOfModelCollection)) { + typeOfModels.addAll(typeOfModelCollection); + } + return this; + } + + /** + * Adds a modelExplainability to the initial collection + * @parameter modelExplainability modelExplainability to add + * @return this for chaining + **/ + AIPackageBuilder addmodelExplainability(String modelExplainability) { + if (Objects.nonNull(modelExplainability)) { + modelExplainabilitys.add(modelExplainability); + } + return this; + } + + /** + * Adds all elements from a collection to the initial modelExplainability collection + * @parameter modelExplainabilityCollection collection to initialize the modelExplainability + * @return this for chaining + **/ + AIPackageBuilder addAllmodelExplainability(Collection modelExplainabilityCollection) { + if (Objects.nonNull(modelExplainabilityCollection)) { + modelExplainabilitys.addAll(modelExplainabilityCollection); + } + return this; + } + + /** + * Sets the initial value of sensitivePersonalInformation + * @parameter sensitivePersonalInformation value to set + * @return this for chaining + **/ + AIPackageBuilder setsensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + this.sensitivePersonalInformation = sensitivePersonalInformation; + return this; + } + + /** + * Sets the initial value of safetyRiskAssessment + * @parameter safetyRiskAssessment value to set + * @return this for chaining + **/ + AIPackageBuilder setsafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAssessment) { + this.safetyRiskAssessment = safetyRiskAssessment; + return this; + } + + /** + * Sets the initial value of autonomyType + * @parameter autonomyType value to set + * @return this for chaining + **/ + AIPackageBuilder setautonomyType(PresenceType autonomyType) { + this.autonomyType = autonomyType; + return this; + } + + /** + * Sets the initial value of informationAboutTraining + * @parameter informationAboutTraining value to set + * @return this for chaining + **/ + AIPackageBuilder setinformationAboutTraining(String informationAboutTraining) { + this.informationAboutTraining = informationAboutTraining; + return this; + } + + /** + * Sets the initial value of limitation + * @parameter limitation value to set + * @return this for chaining + **/ + AIPackageBuilder setlimitation(String limitation) { + this.limitation = limitation; + return this; + } + + /** + * Sets the initial value of energyConsumption + * @parameter energyConsumption value to set + * @return this for chaining + **/ + AIPackageBuilder setenergyConsumption(String energyConsumption) { + this.energyConsumption = energyConsumption; + return this; + } + + /** + * Sets the initial value of informationAboutApplication + * @parameter informationAboutApplication value to set + * @return this for chaining + **/ + AIPackageBuilder setinformationAboutApplication(String informationAboutApplication) { + this.informationAboutApplication = informationAboutApplication; + return this; + } + + + /** + * @return the AIPackage + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public AIPackage build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new AIPackage(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/ai/PresenceType.java b/generated/src/main/java/org/spdx/library/model/ai/PresenceType.java new file mode 100644 index 000000000..0def2e7f2 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/ai/PresenceType.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.ai; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * This type is used to indicate if a given field is present or absent or unknown. + */ +public enum PresenceType implements IndividualUriValue { + + NO_ASSERTION("noAssertion"), + YES("yes"), + NO("no"); + + private String longName; + + private PresenceType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/AI/PresenceType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java b/generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java new file mode 100644 index 000000000..f220e7fcb --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.ai; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Lists the different safety risk type values that can be used to describe the safety + * risk of AI software according to [Article 20 of Regulation 765/2008/EC](https://ec.europa.eu/docsroom/documents/17107/attachments/1/translations/en/renditions/pdf). + */ +public enum SafetyRiskAssessmentType implements IndividualUriValue { + + LOW("low"), + HIGH("high"), + MEDIUM("medium"), + SERIOUS("serious"); + + private String longName; + + private SafetyRiskAssessmentType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/AI/SafetyRiskAssessmentType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/build/Build.java b/generated/src/main/java/org/spdx/library/model/build/Build.java new file mode 100644 index 000000000..f8e0f9721 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/build/Build.java @@ -0,0 +1,458 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.build; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; +import org.spdx.library.model.core.DictionaryEntry; +import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.Hash; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A build is a representation of the process in which a piece of software or artifact + * is built. It encapsulates information related to a build process and provides an + * element from which relationships can be created to describe the build's inputs, + * outputs, and related entities (e.g. builders, identities, etc.). Definitions + * of "BuildType", "ConfigSource", "Parameters" and "Environment" follow those + * defined in [SLSA provenance](https://slsa.dev/provenance/v0.2). ExternalIdentifier + * of type "urlScheme" may be used to identify build logs. In this case, the comment of + * the ExternalIdentifier should be "LogReference". Note that buildStart and buildEnd + * are optional, and may be omitted to simplify creating reproducible builds. + */ +public class Build extends Element { + + Collection parameterss; + Collection configSourceDigests; + Collection environments; + Collection configSourceEntrypoints; + Collection configSourceUris; + + /** + * Create the Build with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Build + */ + public Build() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Build + * @throws InvalidSPDXAnalysisException when unable to create the Build + */ + public Build(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Build is to be stored + * @param objectUri URI or anonymous ID for the Build + * @param copyManager Copy manager for the Build - can be null if copying is not required + * @param create true if Build is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Build + */ + @SuppressWarnings("unchecked") + public Build(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); + configSourceDigests = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_DIGEST, Hash.class); + environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); + configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); + configSourceUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_URI, String.class); + } + + /** + * Create the Build from the builder - used in the builder class + * @param builder Builder to create the Build from + * @throws InvalidSPDXAnalysisException when unable to create the Build + */ + protected Build(BuildBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); + configSourceDigests = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_DIGEST, Hash.class); + environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); + configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); + configSourceUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_URI, String.class); + getParameterss().addAll(builder.parameterss); + getConfigSourceDigests().addAll(builder.configSourceDigests); + getEnvironments().addAll(builder.environments); + getConfigSourceEntrypoints().addAll(builder.configSourceEntrypoints); + getConfigSourceUris().addAll(builder.configSourceUris); + setBuildEndTime(builder.buildEndTime); + setBuildType(builder.buildType); + setBuildStartTime(builder.buildStartTime); + setBuildId(builder.buildId); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Build.Build"; + } + + // Getters and Setters + public Collection getParameterss() { + return parameterss; + } + public Collection getConfigSourceDigests() { + return configSourceDigests; + } + public Collection getEnvironments() { + return environments; + } + public Collection getConfigSourceEntrypoints() { + return configSourceEntrypoints; + } + public Collection getConfigSourceUris() { + return configSourceUris; + } + + + /** + * @return the buildEndTime + */ + public Optional getBuildEndTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME); + } + /** + * @param buildEndTime the buildEndTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Build setBuildEndTime(@Nullable String buildEndTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME, buildEndTime); + return this; + } + + /** + * @return the buildType + */ + public @Nullable String getBuildType() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_TYPE); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param buildType the buildType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Build setBuildType(@Nullable String buildType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(buildType)) { + throw new InvalidSPDXAnalysisException("buildType is a required property"); + } + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_TYPE, buildType); + return this; + } + + /** + * @return the buildStartTime + */ + public Optional getBuildStartTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME); + } + /** + * @param buildStartTime the buildStartTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Build setBuildStartTime(@Nullable String buildStartTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME, buildStartTime); + return this; + } + + /** + * @return the buildId + */ + public Optional getBuildId() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_ID); + } + /** + * @param buildId the buildId to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Build setBuildId(@Nullable String buildId) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_ID, buildId); + return this; + } + + + @Override + public String toString() { + return "Build: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional buildEndTime = getBuildEndTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting buildEndTime for Build: "+e.getMessage()); + } + try { + String buildType = getBuildType(); + if (Objects.isNull(buildType)) { + retval.add("Missing buildType in Build"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting buildType for Build: "+e.getMessage()); + } + try { + Optional buildStartTime = getBuildStartTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting buildStartTime for Build: "+e.getMessage()); + } + try { + Optional buildId = getBuildId(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting buildId for Build: "+e.getMessage()); + } + for (DictionaryEntry parameters:parameterss) { + retval.addAll(parameters.verify(verifiedIds, specVersion, profiles)); + } + for (Hash configSourceDigest:configSourceDigests) { + retval.addAll(configSourceDigest.verify(verifiedIds, specVersion, profiles)); + } + for (DictionaryEntry environment:environments) { + retval.addAll(environment.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class BuildBuilder extends ElementBuilder { + + public BuildBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection parameterss = new ArrayList<>(); + Collection configSourceDigests = new ArrayList<>(); + Collection environments = new ArrayList<>(); + Collection configSourceEntrypoints = new ArrayList<>(); + Collection configSourceUris = new ArrayList<>(); + String buildEndTime = null; + String buildType = null; + String buildStartTime = null; + String buildId = null; + + + /** + * Adds a parameters to the initial collection + * @parameter parameters parameters to add + * @return this for chaining + **/ + BuildBuilder addparameters(DictionaryEntry parameters) { + if (Objects.nonNull(parameters)) { + parameterss.add(parameters); + } + return this; + } + + /** + * Adds all elements from a collection to the initial parameters collection + * @parameter parametersCollection collection to initialize the parameters + * @return this for chaining + **/ + BuildBuilder addAllparameters(Collection parametersCollection) { + if (Objects.nonNull(parametersCollection)) { + parameterss.addAll(parametersCollection); + } + return this; + } + + /** + * Adds a configSourceDigest to the initial collection + * @parameter configSourceDigest configSourceDigest to add + * @return this for chaining + **/ + BuildBuilder addconfigSourceDigest(Hash configSourceDigest) { + if (Objects.nonNull(configSourceDigest)) { + configSourceDigests.add(configSourceDigest); + } + return this; + } + + /** + * Adds all elements from a collection to the initial configSourceDigest collection + * @parameter configSourceDigestCollection collection to initialize the configSourceDigest + * @return this for chaining + **/ + BuildBuilder addAllconfigSourceDigest(Collection configSourceDigestCollection) { + if (Objects.nonNull(configSourceDigestCollection)) { + configSourceDigests.addAll(configSourceDigestCollection); + } + return this; + } + + /** + * Adds a environment to the initial collection + * @parameter environment environment to add + * @return this for chaining + **/ + BuildBuilder addenvironment(DictionaryEntry environment) { + if (Objects.nonNull(environment)) { + environments.add(environment); + } + return this; + } + + /** + * Adds all elements from a collection to the initial environment collection + * @parameter environmentCollection collection to initialize the environment + * @return this for chaining + **/ + BuildBuilder addAllenvironment(Collection environmentCollection) { + if (Objects.nonNull(environmentCollection)) { + environments.addAll(environmentCollection); + } + return this; + } + + /** + * Adds a configSourceEntrypoint to the initial collection + * @parameter configSourceEntrypoint configSourceEntrypoint to add + * @return this for chaining + **/ + BuildBuilder addconfigSourceEntrypoint(String configSourceEntrypoint) { + if (Objects.nonNull(configSourceEntrypoint)) { + configSourceEntrypoints.add(configSourceEntrypoint); + } + return this; + } + + /** + * Adds all elements from a collection to the initial configSourceEntrypoint collection + * @parameter configSourceEntrypointCollection collection to initialize the configSourceEntrypoint + * @return this for chaining + **/ + BuildBuilder addAllconfigSourceEntrypoint(Collection configSourceEntrypointCollection) { + if (Objects.nonNull(configSourceEntrypointCollection)) { + configSourceEntrypoints.addAll(configSourceEntrypointCollection); + } + return this; + } + + /** + * Adds a configSourceUri to the initial collection + * @parameter configSourceUri configSourceUri to add + * @return this for chaining + **/ + BuildBuilder addconfigSourceUri(String configSourceUri) { + if (Objects.nonNull(configSourceUri)) { + configSourceUris.add(configSourceUri); + } + return this; + } + + /** + * Adds all elements from a collection to the initial configSourceUri collection + * @parameter configSourceUriCollection collection to initialize the configSourceUri + * @return this for chaining + **/ + BuildBuilder addAllconfigSourceUri(Collection configSourceUriCollection) { + if (Objects.nonNull(configSourceUriCollection)) { + configSourceUris.addAll(configSourceUriCollection); + } + return this; + } + + /** + * Sets the initial value of buildEndTime + * @parameter buildEndTime value to set + * @return this for chaining + **/ + BuildBuilder setbuildEndTime(String buildEndTime) { + this.buildEndTime = buildEndTime; + return this; + } + + /** + * Sets the initial value of buildType + * @parameter buildType value to set + * @return this for chaining + **/ + BuildBuilder setbuildType(String buildType) { + this.buildType = buildType; + return this; + } + + /** + * Sets the initial value of buildStartTime + * @parameter buildStartTime value to set + * @return this for chaining + **/ + BuildBuilder setbuildStartTime(String buildStartTime) { + this.buildStartTime = buildStartTime; + return this; + } + + /** + * Sets the initial value of buildId + * @parameter buildId value to set + * @return this for chaining + **/ + BuildBuilder setbuildId(String buildId) { + this.buildId = buildId; + return this; + } + + + /** + * @return the Build + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Build build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Build(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Agent.java b/generated/src/main/java/org/spdx/library/model/core/Agent.java new file mode 100644 index 000000000..3eb7da891 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Agent.java @@ -0,0 +1,138 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * The Agent class represents anything that has the potential to act on a system. This + * could be a person, organization, software agent, etc. This is not to be confused with + * tools that are used to perform tasks. + */ +public class Agent extends Element { + + + /** + * Create the Agent with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Agent + */ + public Agent() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Agent + * @throws InvalidSPDXAnalysisException when unable to create the Agent + */ + public Agent(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Agent is to be stored + * @param objectUri URI or anonymous ID for the Agent + * @param copyManager Copy manager for the Agent - can be null if copying is not required + * @param create true if Agent is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Agent + */ + public Agent(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Agent from the builder - used in the builder class + * @param builder Builder to create the Agent from + * @throws InvalidSPDXAnalysisException when unable to create the Agent + */ + protected Agent(AgentBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Agent"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Agent: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class AgentBuilder extends ElementBuilder { + + public AgentBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Agent + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Agent build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Agent(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Annotation.java b/generated/src/main/java/org/spdx/library/model/core/Annotation.java new file mode 100644 index 000000000..d4a60271c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Annotation.java @@ -0,0 +1,263 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An Annotation is an assertion made in relation to one or more elements. + */ +public class Annotation extends Element { + + + /** + * Create the Annotation with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Annotation + */ + public Annotation() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Annotation + * @throws InvalidSPDXAnalysisException when unable to create the Annotation + */ + public Annotation(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Annotation is to be stored + * @param objectUri URI or anonymous ID for the Annotation + * @param copyManager Copy manager for the Annotation - can be null if copying is not required + * @param create true if Annotation is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Annotation + */ + public Annotation(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Annotation from the builder - used in the builder class + * @param builder Builder to create the Annotation from + * @throws InvalidSPDXAnalysisException when unable to create the Annotation + */ + protected Annotation(AnnotationBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setSubject(builder.subject); + setAnnotationType(builder.annotationType); + setStatement(builder.statement); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Annotation"; + } + + // Getters and Setters + + /** + * @return the subject + */ + public @Nullable Element getSubject() throws InvalidSPDXAnalysisException { + Optional retval = getElementPropertyValue(SpdxConstants.CORE_PROP_SUBJECT); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param subject the subject to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Annotation setSubject(@Nullable Element subject) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(subject)) { + throw new InvalidSPDXAnalysisException("subject is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_SUBJECT, subject); + return this; + } + + + /** + * @return the annotationType + */ + @SuppressWarnings("unchecked") + public @Nullable AnnotationType getAnnotationType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_ANNOTATION_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof AnnotationType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (AnnotationType)(retval.get()); + } else { + return null; + } + } + /** + * @param annotationType the annotationType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Annotation setAnnotationType(@Nullable AnnotationType annotationType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(annotationType)) { + throw new InvalidSPDXAnalysisException("annotationType is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_ANNOTATION_TYPE, annotationType); + return this; + } + + /** + * @return the statement + */ + public Optional getStatement() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_STATEMENT); + } + /** + * @param statement the statement to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Annotation setStatement(@Nullable String statement) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_STATEMENT, statement); + return this; + } + + + @Override + public String toString() { + return "Annotation: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Element subject; + try { + subject = getSubject(); + if (Objects.nonNull(subject)) { + retval.addAll(subject.verify(verifiedIds, specVersion, profiles)); + } else { + if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing subject in subject"); + } + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting subject for Annotation: "+e.getMessage()); + } + try { + AnnotationType annotationType = getAnnotationType(); + if (Objects.isNull(annotationType)) { + retval.add("Missing annotationType in Annotation"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting annotationType for Annotation: "+e.getMessage()); + } + try { + Optional statement = getStatement(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting statement for Annotation: "+e.getMessage()); + } + return retval; + } + + public static class AnnotationBuilder extends ElementBuilder { + + public AnnotationBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Element subject = null; + AnnotationType annotationType = null; + String statement = null; + + + /** + * Sets the initial value of subject + * @parameter subject value to set + * @return this for chaining + **/ + AnnotationBuilder setsubject(Element subject) { + this.subject = subject; + return this; + } + + /** + * Sets the initial value of annotationType + * @parameter annotationType value to set + * @return this for chaining + **/ + AnnotationBuilder setannotationType(AnnotationType annotationType) { + this.annotationType = annotationType; + return this; + } + + /** + * Sets the initial value of statement + * @parameter statement value to set + * @return this for chaining + **/ + AnnotationBuilder setstatement(String statement) { + this.statement = statement; + return this; + } + + + /** + * @return the Annotation + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Annotation build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Annotation(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/AnnotationType.java b/generated/src/main/java/org/spdx/library/model/core/AnnotationType.java new file mode 100644 index 000000000..93c169f9d --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/AnnotationType.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * AnnotationType specifies the type of an annotation. + */ +public enum AnnotationType implements IndividualUriValue { + + REVIEW("review"), + OTHER("other"); + + private String longName; + + private AnnotationType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/AnnotationType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java new file mode 100644 index 000000000..c555e0c1d --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public class AnonymousPayload extends Payload { + + + /** + * Create the AnonymousPayload with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload + */ + public AnonymousPayload() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the AnonymousPayload + * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload + */ + public AnonymousPayload(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the AnonymousPayload is to be stored + * @param objectUri URI or anonymous ID for the AnonymousPayload + * @param copyManager Copy manager for the AnonymousPayload - can be null if copying is not required + * @param create true if AnonymousPayload is to be created + * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload + */ + public AnonymousPayload(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the AnonymousPayload from the builder - used in the builder class + * @param builder Builder to create the AnonymousPayload from + * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload + */ + protected AnonymousPayload(AnonymousPayloadBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.AnonymousPayload"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "AnonymousPayload: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class AnonymousPayloadBuilder extends PayloadBuilder { + + public AnonymousPayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the AnonymousPayload + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public AnonymousPayload build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new AnonymousPayload(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Artifact.java b/generated/src/main/java/org/spdx/library/model/core/Artifact.java new file mode 100644 index 000000000..d284b22d7 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Artifact.java @@ -0,0 +1,340 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An artifact is a distinct article or unit within the digital domain, such as an electronic + * file, a software package, a device or an element of data. + */ +public class Artifact extends Element { + + Collection originatedBys; + Collection suppliedBys; + Collection standards; + + /** + * Create the Artifact with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Artifact + */ + public Artifact() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Artifact + * @throws InvalidSPDXAnalysisException when unable to create the Artifact + */ + public Artifact(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Artifact is to be stored + * @param objectUri URI or anonymous ID for the Artifact + * @param copyManager Copy manager for the Artifact - can be null if copying is not required + * @param create true if Artifact is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Artifact + */ + @SuppressWarnings("unchecked") + public Artifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); + suppliedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SUPPLIED_BY, Agent.class); + standards = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_STANDARD, String.class); + } + + /** + * Create the Artifact from the builder - used in the builder class + * @param builder Builder to create the Artifact from + * @throws InvalidSPDXAnalysisException when unable to create the Artifact + */ + protected Artifact(ArtifactBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); + suppliedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SUPPLIED_BY, Agent.class); + standards = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_STANDARD, String.class); + getOriginatedBys().addAll(builder.originatedBys); + getSuppliedBys().addAll(builder.suppliedBys); + getStandards().addAll(builder.standards); + setReleaseTime(builder.releaseTime); + setValidUntilTime(builder.validUntilTime); + setBuiltTime(builder.builtTime); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Artifact"; + } + + // Getters and Setters + public Collection getOriginatedBys() { + return originatedBys; + } + public Collection getSuppliedBys() { + return suppliedBys; + } + public Collection getStandards() { + return standards; + } + + + /** + * @return the releaseTime + */ + public Optional getReleaseTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME); + } + /** + * @param releaseTime the releaseTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Artifact setReleaseTime(@Nullable String releaseTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME, releaseTime); + return this; + } + + /** + * @return the validUntilTime + */ + public Optional getValidUntilTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME); + } + /** + * @param validUntilTime the validUntilTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Artifact setValidUntilTime(@Nullable String validUntilTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME, validUntilTime); + return this; + } + + /** + * @return the builtTime + */ + public Optional getBuiltTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME); + } + /** + * @param builtTime the builtTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Artifact setBuiltTime(@Nullable String builtTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME, builtTime); + return this; + } + + + @Override + public String toString() { + return "Artifact: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional releaseTime = getReleaseTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting releaseTime for Artifact: "+e.getMessage()); + } + try { + Optional validUntilTime = getValidUntilTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting validUntilTime for Artifact: "+e.getMessage()); + } + try { + Optional builtTime = getBuiltTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting builtTime for Artifact: "+e.getMessage()); + } + for (Agent originatedBy:originatedBys) { + retval.addAll(originatedBy.verify(verifiedIds, specVersion, profiles)); + } + for (Agent suppliedBy:suppliedBys) { + retval.addAll(suppliedBy.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class ArtifactBuilder extends ElementBuilder { + + public ArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection originatedBys = new ArrayList<>(); + Collection suppliedBys = new ArrayList<>(); + Collection standards = new ArrayList<>(); + String releaseTime = null; + String validUntilTime = null; + String builtTime = null; + + + /** + * Adds a originatedBy to the initial collection + * @parameter originatedBy originatedBy to add + * @return this for chaining + **/ + ArtifactBuilder addoriginatedBy(Agent originatedBy) { + if (Objects.nonNull(originatedBy)) { + originatedBys.add(originatedBy); + } + return this; + } + + /** + * Adds all elements from a collection to the initial originatedBy collection + * @parameter originatedByCollection collection to initialize the originatedBy + * @return this for chaining + **/ + ArtifactBuilder addAlloriginatedBy(Collection originatedByCollection) { + if (Objects.nonNull(originatedByCollection)) { + originatedBys.addAll(originatedByCollection); + } + return this; + } + + /** + * Adds a suppliedBy to the initial collection + * @parameter suppliedBy suppliedBy to add + * @return this for chaining + **/ + ArtifactBuilder addsuppliedBy(Agent suppliedBy) { + if (Objects.nonNull(suppliedBy)) { + suppliedBys.add(suppliedBy); + } + return this; + } + + /** + * Adds all elements from a collection to the initial suppliedBy collection + * @parameter suppliedByCollection collection to initialize the suppliedBy + * @return this for chaining + **/ + ArtifactBuilder addAllsuppliedBy(Collection suppliedByCollection) { + if (Objects.nonNull(suppliedByCollection)) { + suppliedBys.addAll(suppliedByCollection); + } + return this; + } + + /** + * Adds a standard to the initial collection + * @parameter standard standard to add + * @return this for chaining + **/ + ArtifactBuilder addstandard(String standard) { + if (Objects.nonNull(standard)) { + standards.add(standard); + } + return this; + } + + /** + * Adds all elements from a collection to the initial standard collection + * @parameter standardCollection collection to initialize the standard + * @return this for chaining + **/ + ArtifactBuilder addAllstandard(Collection standardCollection) { + if (Objects.nonNull(standardCollection)) { + standards.addAll(standardCollection); + } + return this; + } + + /** + * Sets the initial value of releaseTime + * @parameter releaseTime value to set + * @return this for chaining + **/ + ArtifactBuilder setreleaseTime(String releaseTime) { + this.releaseTime = releaseTime; + return this; + } + + /** + * Sets the initial value of validUntilTime + * @parameter validUntilTime value to set + * @return this for chaining + **/ + ArtifactBuilder setvalidUntilTime(String validUntilTime) { + this.validUntilTime = validUntilTime; + return this; + } + + /** + * Sets the initial value of builtTime + * @parameter builtTime value to set + * @return this for chaining + **/ + ArtifactBuilder setbuiltTime(String builtTime) { + this.builtTime = builtTime; + return this; + } + + + /** + * @return the Artifact + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Artifact build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Artifact(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Bom.java b/generated/src/main/java/org/spdx/library/model/core/Bom.java new file mode 100644 index 000000000..57d1be700 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Bom.java @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A Bill Of Materials (BOM) is a container for a grouping of SPDX-3.0 content characterizing + * details about a product. This could include details of the content and composition + * of the product, provenence details of the product and/or its composition, licensing + * information, known quality or security issues, etc. + */ +public class Bom extends Bundle { + + + /** + * Create the Bom with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Bom + */ + public Bom() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Bom + * @throws InvalidSPDXAnalysisException when unable to create the Bom + */ + public Bom(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Bom is to be stored + * @param objectUri URI or anonymous ID for the Bom + * @param copyManager Copy manager for the Bom - can be null if copying is not required + * @param create true if Bom is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Bom + */ + public Bom(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Bom from the builder - used in the builder class + * @param builder Builder to create the Bom from + * @throws InvalidSPDXAnalysisException when unable to create the Bom + */ + protected Bom(BomBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Bom"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Bom: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class BomBuilder extends BundleBuilder { + + public BomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Bom + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Bom build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Bom(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Bundle.java b/generated/src/main/java/org/spdx/library/model/core/Bundle.java new file mode 100644 index 000000000..a75a35f21 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Bundle.java @@ -0,0 +1,169 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A bundle is a collection of Elements that have a shared context. + */ +public class Bundle extends ElementCollection { + + + /** + * Create the Bundle with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Bundle + */ + public Bundle() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Bundle + * @throws InvalidSPDXAnalysisException when unable to create the Bundle + */ + public Bundle(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Bundle is to be stored + * @param objectUri URI or anonymous ID for the Bundle + * @param copyManager Copy manager for the Bundle - can be null if copying is not required + * @param create true if Bundle is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Bundle + */ + public Bundle(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Bundle from the builder - used in the builder class + * @param builder Builder to create the Bundle from + * @throws InvalidSPDXAnalysisException when unable to create the Bundle + */ + protected Bundle(BundleBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setContext(builder.context); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Bundle"; + } + + // Getters and Setters + + + /** + * @return the context + */ + public Optional getContext() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_CONTEXT); + } + /** + * @param context the context to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Bundle setContext(@Nullable String context) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_CONTEXT, context); + return this; + } + + + @Override + public String toString() { + return "Bundle: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional context = getContext(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting context for Bundle: "+e.getMessage()); + } + return retval; + } + + public static class BundleBuilder extends ElementCollectionBuilder { + + public BundleBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String context = null; + + + /** + * Sets the initial value of context + * @parameter context value to set + * @return this for chaining + **/ + BundleBuilder setcontext(String context) { + this.context = context; + return this; + } + + + /** + * @return the Bundle + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Bundle build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Bundle(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java b/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java new file mode 100644 index 000000000..2a031fb1f --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java @@ -0,0 +1,377 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * The CreationInfo provides information about who created the Element, and when and + * how it was created. The dateTime created is often the date of last change (e.g., a git + * commit date), not the date when the SPDX data was created, as doing so supports reproducible + * builds. + */ +public class CreationInfo extends ModelObject { + + Collection createdUsings; + Collection createdBys; + Collection createds; + Collection dataLicenses; + Collection specVersions; + Collection profiles; + + /** + * Create the CreationInfo with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the CreationInfo + */ + public CreationInfo() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the CreationInfo + * @throws InvalidSPDXAnalysisException when unable to create the CreationInfo + */ + public CreationInfo(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the CreationInfo is to be stored + * @param objectUri URI or anonymous ID for the CreationInfo + * @param copyManager Copy manager for the CreationInfo - can be null if copying is not required + * @param create true if CreationInfo is to be created + * @throws InvalidSPDXAnalysisException when unable to create the CreationInfo + */ + @SuppressWarnings("unchecked") + public CreationInfo(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); + createdBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_BY, Agent.class); + profiles = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_PROFILE, ProfileIdentifierType.class); + createds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED, String.class); + dataLicenses = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_DATA_LICENSE, String.class); + specVersions = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SPEC_VERSION, String.class); + } + + /** + * Create the CreationInfo from the builder - used in the builder class + * @param builder Builder to create the CreationInfo from + * @throws InvalidSPDXAnalysisException when unable to create the CreationInfo + */ + protected CreationInfo(CreationInfoBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); + createdBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_BY, Agent.class); + profiles = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_PROFILE, ProfileIdentifierType.class); + createds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED, String.class); + dataLicenses = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_DATA_LICENSE, String.class); + specVersions = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SPEC_VERSION, String.class); + getCreatedUsings().addAll(builder.createdUsings); + getCreatedBys().addAll(builder.createdBys); + getProfiles().addAll(builder.profiles); + getCreateds().addAll(builder.createds); + getDataLicenses().addAll(builder.dataLicenses); + getSpecVersions().addAll(builder.specVersions); + setComment(builder.comment); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.CreationInfo"; + } + + // Getters and Setters + public Collection getCreatedUsings() { + return createdUsings; + } + public Collection getCreatedBys() { + return createdBys; + } + public Collection getProfiles() { + return profiles; + } + public Collection getCreateds() { + return createds; + } + public Collection getDataLicenses() { + return dataLicenses; + } + public Collection getSpecVersions() { + return specVersions; + } + + + /** + * @return the comment + */ + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + } + /** + * @param comment the comment to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CreationInfo setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + return this; + } + + + @Override + public String toString() { + return "CreationInfo: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + Optional comment = getComment(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting comment for CreationInfo: "+e.getMessage()); + } + for (Tool createdUsing:createdUsings) { + retval.addAll(createdUsing.verify(verifiedIds, specVersion, profiles)); + } + for (Agent createdBy:createdBys) { + retval.addAll(createdBy.verify(verifiedIds, specVersion, profiles)); + } + if (createdBys.size() < 1) { + retval.add("createdBys size " + createdBys.size() + " is less than 1 in CreationInfo"); + } + if (profiles.size() < 1) { + retval.add("profiles size " + profiles.size() + " is less than 1 in CreationInfo"); + } + return retval; + } + + public static class CreationInfoBuilder extends ModelObjectBuilder { + + public CreationInfoBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection createdUsings = new ArrayList<>(); + Collection createdBys = new ArrayList<>(); + Collection profiles = new ArrayList<>(); + Collection createds = new ArrayList<>(); + Collection dataLicenses = new ArrayList<>(); + Collection specVersions = new ArrayList<>(); + String comment = null; + + + /** + * Adds a createdUsing to the initial collection + * @parameter createdUsing createdUsing to add + * @return this for chaining + **/ + CreationInfoBuilder addcreatedUsing(Tool createdUsing) { + if (Objects.nonNull(createdUsing)) { + createdUsings.add(createdUsing); + } + return this; + } + + /** + * Adds all elements from a collection to the initial createdUsing collection + * @parameter createdUsingCollection collection to initialize the createdUsing + * @return this for chaining + **/ + CreationInfoBuilder addAllcreatedUsing(Collection createdUsingCollection) { + if (Objects.nonNull(createdUsingCollection)) { + createdUsings.addAll(createdUsingCollection); + } + return this; + } + + /** + * Adds a createdBy to the initial collection + * @parameter createdBy createdBy to add + * @return this for chaining + **/ + CreationInfoBuilder addcreatedBy(Agent createdBy) { + if (Objects.nonNull(createdBy)) { + createdBys.add(createdBy); + } + return this; + } + + /** + * Adds all elements from a collection to the initial createdBy collection + * @parameter createdByCollection collection to initialize the createdBy + * @return this for chaining + **/ + CreationInfoBuilder addAllcreatedBy(Collection createdByCollection) { + if (Objects.nonNull(createdByCollection)) { + createdBys.addAll(createdByCollection); + } + return this; + } + + /** + * Adds a profile to the initial collection + * @parameter profile profile to add + * @return this for chaining + **/ + CreationInfoBuilder addprofile(ProfileIdentifierType profile) { + if (Objects.nonNull(profile)) { + profiles.add(profile); + } + return this; + } + + /** + * Adds all elements from a collection to the initial profile collection + * @parameter profileCollection collection to initialize the profile + * @return this for chaining + **/ + CreationInfoBuilder addAllprofile(Collection profileCollection) { + if (Objects.nonNull(profileCollection)) { + profiles.addAll(profileCollection); + } + return this; + } + + /** + * Adds a created to the initial collection + * @parameter created created to add + * @return this for chaining + **/ + CreationInfoBuilder addcreated(String created) { + if (Objects.nonNull(created)) { + createds.add(created); + } + return this; + } + + /** + * Adds all elements from a collection to the initial created collection + * @parameter createdCollection collection to initialize the created + * @return this for chaining + **/ + CreationInfoBuilder addAllcreated(Collection createdCollection) { + if (Objects.nonNull(createdCollection)) { + createds.addAll(createdCollection); + } + return this; + } + + /** + * Adds a dataLicense to the initial collection + * @parameter dataLicense dataLicense to add + * @return this for chaining + **/ + CreationInfoBuilder adddataLicense(String dataLicense) { + if (Objects.nonNull(dataLicense)) { + dataLicenses.add(dataLicense); + } + return this; + } + + /** + * Adds all elements from a collection to the initial dataLicense collection + * @parameter dataLicenseCollection collection to initialize the dataLicense + * @return this for chaining + **/ + CreationInfoBuilder addAlldataLicense(Collection dataLicenseCollection) { + if (Objects.nonNull(dataLicenseCollection)) { + dataLicenses.addAll(dataLicenseCollection); + } + return this; + } + + /** + * Adds a specVersion to the initial collection + * @parameter specVersion specVersion to add + * @return this for chaining + **/ + CreationInfoBuilder addspecVersion(String specVersion) { + if (Objects.nonNull(specVersion)) { + specVersions.add(specVersion); + } + return this; + } + + /** + * Adds all elements from a collection to the initial specVersion collection + * @parameter specVersionCollection collection to initialize the specVersion + * @return this for chaining + **/ + CreationInfoBuilder addAllspecVersion(Collection specVersionCollection) { + if (Objects.nonNull(specVersionCollection)) { + specVersions.addAll(specVersionCollection); + } + return this; + } + + /** + * Sets the initial value of comment + * @parameter comment value to set + * @return this for chaining + **/ + CreationInfoBuilder setcomment(String comment) { + this.comment = comment; + return this; + } + + + /** + * @return the CreationInfo + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public CreationInfo build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new CreationInfo(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java new file mode 100644 index 000000000..7461f251d --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java @@ -0,0 +1,211 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * The class used for implementing a generic string mapping (also known as associative + * array, dictionary, or hash map) in SPDX. Each DictionaryEntry contains a key-value + * pair which maps the key to its associated value. To implement a dictionary, this class + * is to be used in a collection with unique keys. + */ +public class DictionaryEntry extends ModelObject { + + + /** + * Create the DictionaryEntry with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the DictionaryEntry + */ + public DictionaryEntry() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the DictionaryEntry + * @throws InvalidSPDXAnalysisException when unable to create the DictionaryEntry + */ + public DictionaryEntry(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the DictionaryEntry is to be stored + * @param objectUri URI or anonymous ID for the DictionaryEntry + * @param copyManager Copy manager for the DictionaryEntry - can be null if copying is not required + * @param create true if DictionaryEntry is to be created + * @throws InvalidSPDXAnalysisException when unable to create the DictionaryEntry + */ + public DictionaryEntry(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the DictionaryEntry from the builder - used in the builder class + * @param builder Builder to create the DictionaryEntry from + * @throws InvalidSPDXAnalysisException when unable to create the DictionaryEntry + */ + protected DictionaryEntry(DictionaryEntryBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setKey(builder.key); + setValue(builder.value); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.DictionaryEntry"; + } + + // Getters and Setters + + + /** + * @return the key + */ + public @Nullable String getKey() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_KEY); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param key the key to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public DictionaryEntry setKey(@Nullable String key) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(key)) { + throw new InvalidSPDXAnalysisException("key is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_KEY, key); + return this; + } + + /** + * @return the value + */ + public Optional getValue() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_VALUE); + } + /** + * @param value the value to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public DictionaryEntry setValue(@Nullable String value) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_VALUE, value); + return this; + } + + + @Override + public String toString() { + return "DictionaryEntry: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + String key = getKey(); + if (Objects.isNull(key)) { + retval.add("Missing key in DictionaryEntry"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting key for DictionaryEntry: "+e.getMessage()); + } + try { + Optional value = getValue(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting value for DictionaryEntry: "+e.getMessage()); + } + return retval; + } + + public static class DictionaryEntryBuilder extends ModelObjectBuilder { + + public DictionaryEntryBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String key = null; + String value = null; + + + /** + * Sets the initial value of key + * @parameter key value to set + * @return this for chaining + **/ + DictionaryEntryBuilder setkey(String key) { + this.key = key; + return this; + } + + /** + * Sets the initial value of value + * @parameter value value to set + * @return this for chaining + **/ + DictionaryEntryBuilder setvalue(String value) { + this.value = value; + return this; + } + + + /** + * @return the DictionaryEntry + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public DictionaryEntry build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new DictionaryEntry(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Element.java b/generated/src/main/java/org/spdx/library/model/core/Element.java new file mode 100644 index 000000000..84595ed81 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Element.java @@ -0,0 +1,278 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An Element is a representation of a fundamental concept either directly inherent + * to the Bill of Materials (BOM) domain or indirectly related to the BOM domain and necessary + * for contextually characterizing BOM concepts and relationships. Within SPDX-3.0 + * structure this is the base class acting as a consistent, unifying, and interoperable + * foundation for all explicit and inter-relatable content objects. + */ +public class Element extends Payload { + + Collection externalReferences; + Collection externalIdentifiers; + + /** + * Create the Element with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Element + */ + public Element() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Element + * @throws InvalidSPDXAnalysisException when unable to create the Element + */ + public Element(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Element is to be stored + * @param objectUri URI or anonymous ID for the Element + * @param copyManager Copy manager for the Element - can be null if copying is not required + * @param create true if Element is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Element + */ + @SuppressWarnings("unchecked") + public Element(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); + externalIdentifiers = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER, ExternalIdentifier.class); + } + + /** + * Create the Element from the builder - used in the builder class + * @param builder Builder to create the Element from + * @throws InvalidSPDXAnalysisException when unable to create the Element + */ + protected Element(ElementBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); + externalIdentifiers = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER, ExternalIdentifier.class); + getExternalReferences().addAll(builder.externalReferences); + getExternalIdentifiers().addAll(builder.externalIdentifiers); + setDescription(builder.description); + setSummary(builder.summary); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Element"; + } + + // Getters and Setters + public Collection getExternalReferences() { + return externalReferences; + } + public Collection getExternalIdentifiers() { + return externalIdentifiers; + } + + + /** + * @return the description + */ + public Optional getDescription() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_DESCRIPTION); + } + /** + * @param description the description to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Element setDescription(@Nullable String description) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_DESCRIPTION, description); + return this; + } + + /** + * @return the summary + */ + public Optional getSummary() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_SUMMARY); + } + /** + * @param summary the summary to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Element setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_SUMMARY, summary); + return this; + } + + + @Override + public String toString() { + return "Element: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional description = getDescription(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting description for Element: "+e.getMessage()); + } + try { + Optional summary = getSummary(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting summary for Element: "+e.getMessage()); + } + for (ExternalReference externalReference:externalReferences) { + retval.addAll(externalReference.verify(verifiedIds, specVersion, profiles)); + } + for (ExternalIdentifier externalIdentifier:externalIdentifiers) { + retval.addAll(externalIdentifier.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class ElementBuilder extends PayloadBuilder { + + public ElementBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection externalReferences = new ArrayList<>(); + Collection externalIdentifiers = new ArrayList<>(); + String description = null; + String summary = null; + + + /** + * Adds a externalReference to the initial collection + * @parameter externalReference externalReference to add + * @return this for chaining + **/ + ElementBuilder addexternalReference(ExternalReference externalReference) { + if (Objects.nonNull(externalReference)) { + externalReferences.add(externalReference); + } + return this; + } + + /** + * Adds all elements from a collection to the initial externalReference collection + * @parameter externalReferenceCollection collection to initialize the externalReference + * @return this for chaining + **/ + ElementBuilder addAllexternalReference(Collection externalReferenceCollection) { + if (Objects.nonNull(externalReferenceCollection)) { + externalReferences.addAll(externalReferenceCollection); + } + return this; + } + + /** + * Adds a externalIdentifier to the initial collection + * @parameter externalIdentifier externalIdentifier to add + * @return this for chaining + **/ + ElementBuilder addexternalIdentifier(ExternalIdentifier externalIdentifier) { + if (Objects.nonNull(externalIdentifier)) { + externalIdentifiers.add(externalIdentifier); + } + return this; + } + + /** + * Adds all elements from a collection to the initial externalIdentifier collection + * @parameter externalIdentifierCollection collection to initialize the externalIdentifier + * @return this for chaining + **/ + ElementBuilder addAllexternalIdentifier(Collection externalIdentifierCollection) { + if (Objects.nonNull(externalIdentifierCollection)) { + externalIdentifiers.addAll(externalIdentifierCollection); + } + return this; + } + + /** + * Sets the initial value of description + * @parameter description value to set + * @return this for chaining + **/ + ElementBuilder setdescription(String description) { + this.description = description; + return this; + } + + /** + * Sets the initial value of summary + * @parameter summary value to set + * @return this for chaining + **/ + ElementBuilder setsummary(String summary) { + this.summary = summary; + return this; + } + + + /** + * @return the Element + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Element build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Element(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java b/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java new file mode 100644 index 000000000..734703720 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java @@ -0,0 +1,214 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An SpdxCollection is a collection of Elements, not necessarily with unifying context. + */ +public class ElementCollection extends Element { + + Collection elements; + Collection rootElements; + + /** + * Create the ElementCollection with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ElementCollection + */ + public ElementCollection() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ElementCollection + * @throws InvalidSPDXAnalysisException when unable to create the ElementCollection + */ + public ElementCollection(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ElementCollection is to be stored + * @param objectUri URI or anonymous ID for the ElementCollection + * @param copyManager Copy manager for the ElementCollection - can be null if copying is not required + * @param create true if ElementCollection is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ElementCollection + */ + @SuppressWarnings("unchecked") + public ElementCollection(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); + } + + /** + * Create the ElementCollection from the builder - used in the builder class + * @param builder Builder to create the ElementCollection from + * @throws InvalidSPDXAnalysisException when unable to create the ElementCollection + */ + protected ElementCollection(ElementCollectionBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); + getElements().addAll(builder.elements); + getRootElements().addAll(builder.rootElements); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.ElementCollection"; + } + + // Getters and Setters + public Collection getElements() { + return elements; + } + public Collection getRootElements() { + return rootElements; + } + + + + @Override + public String toString() { + return "ElementCollection: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + for (Element element:elements) { + retval.addAll(element.verify(verifiedIds, specVersion, profiles)); + } + if (elements.size() < 1) { + retval.add("elements size " + elements.size() + " is less than 1 in ElementCollection"); + } + for (Element rootElement:rootElements) { + retval.addAll(rootElement.verify(verifiedIds, specVersion, profiles)); + } + if (rootElements.size() < 1) { + retval.add("rootElements size " + rootElements.size() + " is less than 1 in ElementCollection"); + } + return retval; + } + + public static class ElementCollectionBuilder extends ElementBuilder { + + public ElementCollectionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection elements = new ArrayList<>(); + Collection rootElements = new ArrayList<>(); + + + /** + * Adds a element to the initial collection + * @parameter element element to add + * @return this for chaining + **/ + ElementCollectionBuilder addelement(Element element) { + if (Objects.nonNull(element)) { + elements.add(element); + } + return this; + } + + /** + * Adds all elements from a collection to the initial element collection + * @parameter elementCollection collection to initialize the element + * @return this for chaining + **/ + ElementCollectionBuilder addAllelement(Collection elementCollection) { + if (Objects.nonNull(elementCollection)) { + elements.addAll(elementCollection); + } + return this; + } + + /** + * Adds a rootElement to the initial collection + * @parameter rootElement rootElement to add + * @return this for chaining + **/ + ElementCollectionBuilder addrootElement(Element rootElement) { + if (Objects.nonNull(rootElement)) { + rootElements.add(rootElement); + } + return this; + } + + /** + * Adds all elements from a collection to the initial rootElement collection + * @parameter rootElementCollection collection to initialize the rootElement + * @return this for chaining + **/ + ElementCollectionBuilder addAllrootElement(Collection rootElementCollection) { + if (Objects.nonNull(rootElementCollection)) { + rootElements.addAll(rootElementCollection); + } + return this; + } + + + /** + * @return the ElementCollection + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ElementCollection build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ElementCollection(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java new file mode 100644 index 000000000..287d3944c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java @@ -0,0 +1,324 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An ExternalIdentifier is a reference to a resource outside the scope of SPDX-3.0 + * content that uniquely identifies an Element. + */ +public class ExternalIdentifier extends ModelObject { + + Collection identifierLocators; + + /** + * Create the ExternalIdentifier with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ExternalIdentifier + */ + public ExternalIdentifier() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ExternalIdentifier + * @throws InvalidSPDXAnalysisException when unable to create the ExternalIdentifier + */ + public ExternalIdentifier(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ExternalIdentifier is to be stored + * @param objectUri URI or anonymous ID for the ExternalIdentifier + * @param copyManager Copy manager for the ExternalIdentifier - can be null if copying is not required + * @param create true if ExternalIdentifier is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ExternalIdentifier + */ + @SuppressWarnings("unchecked") + public ExternalIdentifier(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + identifierLocators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IDENTIFIER_LOCATOR, String.class); + } + + /** + * Create the ExternalIdentifier from the builder - used in the builder class + * @param builder Builder to create the ExternalIdentifier from + * @throws InvalidSPDXAnalysisException when unable to create the ExternalIdentifier + */ + protected ExternalIdentifier(ExternalIdentifierBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + identifierLocators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IDENTIFIER_LOCATOR, String.class); + getIdentifierLocators().addAll(builder.identifierLocators); + setExternalIdentifierType(builder.externalIdentifierType); + setIssuingAuthority(builder.issuingAuthority); + setIdentifier(builder.identifier); + setComment(builder.comment); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.ExternalIdentifier"; + } + + // Getters and Setters + public Collection getIdentifierLocators() { + return identifierLocators; + } + + + /** + * @return the externalIdentifierType + */ + @SuppressWarnings("unchecked") + public @Nullable ExternalIdentifierType getExternalIdentifierType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof ExternalIdentifierType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (ExternalIdentifierType)(retval.get()); + } else { + return null; + } + } + /** + * @param externalIdentifierType the externalIdentifierType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalIdentifier setExternalIdentifierType(@Nullable ExternalIdentifierType externalIdentifierType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(externalIdentifierType)) { + throw new InvalidSPDXAnalysisException("externalIdentifierType is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER_TYPE, externalIdentifierType); + return this; + } + + /** + * @return the issuingAuthority + */ + public Optional getIssuingAuthority() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY); + } + /** + * @param issuingAuthority the issuingAuthority to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalIdentifier setIssuingAuthority(@Nullable String issuingAuthority) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY, issuingAuthority); + return this; + } + + /** + * @return the identifier + */ + public @Nullable String getIdentifier() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_IDENTIFIER); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param identifier the identifier to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalIdentifier setIdentifier(@Nullable String identifier) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(identifier)) { + throw new InvalidSPDXAnalysisException("identifier is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_IDENTIFIER, identifier); + return this; + } + + /** + * @return the comment + */ + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + } + /** + * @param comment the comment to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalIdentifier setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + return this; + } + + + @Override + public String toString() { + return "ExternalIdentifier: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + ExternalIdentifierType externalIdentifierType = getExternalIdentifierType(); + if (Objects.isNull(externalIdentifierType)) { + retval.add("Missing externalIdentifierType in ExternalIdentifier"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting externalIdentifierType for ExternalIdentifier: "+e.getMessage()); + } + try { + Optional issuingAuthority = getIssuingAuthority(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting issuingAuthority for ExternalIdentifier: "+e.getMessage()); + } + try { + String identifier = getIdentifier(); + if (Objects.isNull(identifier)) { + retval.add("Missing identifier in ExternalIdentifier"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting identifier for ExternalIdentifier: "+e.getMessage()); + } + try { + Optional comment = getComment(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting comment for ExternalIdentifier: "+e.getMessage()); + } + return retval; + } + + public static class ExternalIdentifierBuilder extends ModelObjectBuilder { + + public ExternalIdentifierBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection identifierLocators = new ArrayList<>(); + ExternalIdentifierType externalIdentifierType = null; + String issuingAuthority = null; + String identifier = null; + String comment = null; + + + /** + * Adds a identifierLocator to the initial collection + * @parameter identifierLocator identifierLocator to add + * @return this for chaining + **/ + ExternalIdentifierBuilder addidentifierLocator(String identifierLocator) { + if (Objects.nonNull(identifierLocator)) { + identifierLocators.add(identifierLocator); + } + return this; + } + + /** + * Adds all elements from a collection to the initial identifierLocator collection + * @parameter identifierLocatorCollection collection to initialize the identifierLocator + * @return this for chaining + **/ + ExternalIdentifierBuilder addAllidentifierLocator(Collection identifierLocatorCollection) { + if (Objects.nonNull(identifierLocatorCollection)) { + identifierLocators.addAll(identifierLocatorCollection); + } + return this; + } + + /** + * Sets the initial value of externalIdentifierType + * @parameter externalIdentifierType value to set + * @return this for chaining + **/ + ExternalIdentifierBuilder setexternalIdentifierType(ExternalIdentifierType externalIdentifierType) { + this.externalIdentifierType = externalIdentifierType; + return this; + } + + /** + * Sets the initial value of issuingAuthority + * @parameter issuingAuthority value to set + * @return this for chaining + **/ + ExternalIdentifierBuilder setissuingAuthority(String issuingAuthority) { + this.issuingAuthority = issuingAuthority; + return this; + } + + /** + * Sets the initial value of identifier + * @parameter identifier value to set + * @return this for chaining + **/ + ExternalIdentifierBuilder setidentifier(String identifier) { + this.identifier = identifier; + return this; + } + + /** + * Sets the initial value of comment + * @parameter comment value to set + * @return this for chaining + **/ + ExternalIdentifierBuilder setcomment(String comment) { + this.comment = comment; + return this; + } + + + /** + * @return the ExternalIdentifier + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ExternalIdentifier build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ExternalIdentifier(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java new file mode 100644 index 000000000..aec6594b5 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * ExteralIdentifierType specifies the type of an external identifier. + */ +public enum ExternalIdentifierType implements IndividualUriValue { + + SWHID("swhid"), + SECURITY_OTHER("securityOther"), + URL_SCHEME("urlScheme"), + PKG_URL("pkgUrl"), + CPE_2_3("cpe23"), + GITOID("gitoid"), + SWID("swid"), + CPE_2_2("cpe22"), + EMAIL("email"), + CVE("cve"), + OTHER("other"); + + private String longName; + + private ExternalIdentifierType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/ExternalIdentifierType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java new file mode 100644 index 000000000..15ede6f7a --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java @@ -0,0 +1,280 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An External Map is a map of Element identifiers that are used within a Document but + * defined external to that Document. The external map provides details about the externally-defined + * Element such as its provenance, where to retrieve it, and how to verify its integrity. + */ +public class ExternalMap extends ModelObject { + + Collection verifiedUsings; + + /** + * Create the ExternalMap with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ExternalMap + */ + public ExternalMap() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ExternalMap + * @throws InvalidSPDXAnalysisException when unable to create the ExternalMap + */ + public ExternalMap(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ExternalMap is to be stored + * @param objectUri URI or anonymous ID for the ExternalMap + * @param copyManager Copy manager for the ExternalMap - can be null if copying is not required + * @param create true if ExternalMap is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ExternalMap + */ + @SuppressWarnings("unchecked") + public ExternalMap(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); + } + + /** + * Create the ExternalMap from the builder - used in the builder class + * @param builder Builder to create the ExternalMap from + * @throws InvalidSPDXAnalysisException when unable to create the ExternalMap + */ + protected ExternalMap(ExternalMapBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); + getVerifiedUsings().addAll(builder.verifiedUsings); + setDefiningDocument(builder.definingDocument); + setLocationHint(builder.locationHint); + setExternalId(builder.externalId); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.ExternalMap"; + } + + // Getters and Setters + public Collection getVerifiedUsings() { + return verifiedUsings; + } + + + /** + * @return the definingDocument + */ + public Optional getDefiningDocument() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_DEFINING_DOCUMENT); + } + /** + * @param definingDocument the definingDocument to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalMap setDefiningDocument(@Nullable String definingDocument) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_DEFINING_DOCUMENT, definingDocument); + return this; + } + + /** + * @return the locationHint + */ + public Optional getLocationHint() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_LOCATION_HINT); + } + /** + * @param locationHint the locationHint to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalMap setLocationHint(@Nullable String locationHint) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_LOCATION_HINT, locationHint); + return this; + } + + /** + * @return the externalId + */ + public @Nullable String getExternalId() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_ID); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param externalId the externalId to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalMap setExternalId(@Nullable String externalId) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(externalId)) { + throw new InvalidSPDXAnalysisException("externalId is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_ID, externalId); + return this; + } + + + @Override + public String toString() { + return "ExternalMap: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + Optional definingDocument = getDefiningDocument(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting definingDocument for ExternalMap: "+e.getMessage()); + } + try { + Optional locationHint = getLocationHint(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting locationHint for ExternalMap: "+e.getMessage()); + } + try { + String externalId = getExternalId(); + if (Objects.isNull(externalId)) { + retval.add("Missing externalId in ExternalMap"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting externalId for ExternalMap: "+e.getMessage()); + } + for (IntegrityMethod verifiedUsing:verifiedUsings) { + retval.addAll(verifiedUsing.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class ExternalMapBuilder extends ModelObjectBuilder { + + public ExternalMapBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection verifiedUsings = new ArrayList<>(); + String definingDocument = null; + String locationHint = null; + String externalId = null; + + + /** + * Adds a verifiedUsing to the initial collection + * @parameter verifiedUsing verifiedUsing to add + * @return this for chaining + **/ + ExternalMapBuilder addverifiedUsing(IntegrityMethod verifiedUsing) { + if (Objects.nonNull(verifiedUsing)) { + verifiedUsings.add(verifiedUsing); + } + return this; + } + + /** + * Adds all elements from a collection to the initial verifiedUsing collection + * @parameter verifiedUsingCollection collection to initialize the verifiedUsing + * @return this for chaining + **/ + ExternalMapBuilder addAllverifiedUsing(Collection verifiedUsingCollection) { + if (Objects.nonNull(verifiedUsingCollection)) { + verifiedUsings.addAll(verifiedUsingCollection); + } + return this; + } + + /** + * Sets the initial value of definingDocument + * @parameter definingDocument value to set + * @return this for chaining + **/ + ExternalMapBuilder setdefiningDocument(String definingDocument) { + this.definingDocument = definingDocument; + return this; + } + + /** + * Sets the initial value of locationHint + * @parameter locationHint value to set + * @return this for chaining + **/ + ExternalMapBuilder setlocationHint(String locationHint) { + this.locationHint = locationHint; + return this; + } + + /** + * Sets the initial value of externalId + * @parameter externalId value to set + * @return this for chaining + **/ + ExternalMapBuilder setexternalId(String externalId) { + this.externalId = externalId; + return this; + } + + + /** + * @return the ExternalMap + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ExternalMap build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ExternalMap(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java b/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java new file mode 100644 index 000000000..f07263886 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java @@ -0,0 +1,278 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An External Reference points to a resource outside the scope of the SPDX-3.0 content + * that provides additional characteristics of an Element. + */ +public class ExternalReference extends ModelObject { + + Collection locators; + + /** + * Create the ExternalReference with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + */ + public ExternalReference() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ExternalReference + * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + */ + public ExternalReference(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ExternalReference is to be stored + * @param objectUri URI or anonymous ID for the ExternalReference + * @param copyManager Copy manager for the ExternalReference - can be null if copying is not required + * @param create true if ExternalReference is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + */ + @SuppressWarnings("unchecked") + public ExternalReference(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + locators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_LOCATOR, String.class); + } + + /** + * Create the ExternalReference from the builder - used in the builder class + * @param builder Builder to create the ExternalReference from + * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + */ + protected ExternalReference(ExternalReferenceBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + locators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_LOCATOR, String.class); + getLocators().addAll(builder.locators); + setExternalReferenceType(builder.externalReferenceType); + setContentType(builder.contentType); + setComment(builder.comment); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.ExternalReference"; + } + + // Getters and Setters + public Collection getLocators() { + return locators; + } + + + /** + * @return the externalReferenceType + */ + @SuppressWarnings("unchecked") + public Optional getExternalReferenceType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof ExternalReferenceType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param externalReferenceType the externalReferenceType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalReference setExternalReferenceType(@Nullable ExternalReferenceType externalReferenceType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE_TYPE, externalReferenceType); + return this; + } + + /** + * @return the contentType + */ + public Optional getContentType() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE); + } + /** + * @param contentType the contentType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalReference setContentType(@Nullable String contentType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE, contentType); + return this; + } + + /** + * @return the comment + */ + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + } + /** + * @param comment the comment to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalReference setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + return this; + } + + + @Override + public String toString() { + return "ExternalReference: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + Optional externalReferenceType = getExternalReferenceType(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting externalReferenceType for ExternalReference: "+e.getMessage()); + } + try { + Optional contentType = getContentType(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting contentType for ExternalReference: "+e.getMessage()); + } + try { + Optional comment = getComment(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting comment for ExternalReference: "+e.getMessage()); + } + return retval; + } + + public static class ExternalReferenceBuilder extends ModelObjectBuilder { + + public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection locators = new ArrayList<>(); + ExternalReferenceType externalReferenceType = null; + String contentType = null; + String comment = null; + + + /** + * Adds a locator to the initial collection + * @parameter locator locator to add + * @return this for chaining + **/ + ExternalReferenceBuilder addlocator(String locator) { + if (Objects.nonNull(locator)) { + locators.add(locator); + } + return this; + } + + /** + * Adds all elements from a collection to the initial locator collection + * @parameter locatorCollection collection to initialize the locator + * @return this for chaining + **/ + ExternalReferenceBuilder addAlllocator(Collection locatorCollection) { + if (Objects.nonNull(locatorCollection)) { + locators.addAll(locatorCollection); + } + return this; + } + + /** + * Sets the initial value of externalReferenceType + * @parameter externalReferenceType value to set + * @return this for chaining + **/ + ExternalReferenceBuilder setexternalReferenceType(ExternalReferenceType externalReferenceType) { + this.externalReferenceType = externalReferenceType; + return this; + } + + /** + * Sets the initial value of contentType + * @parameter contentType value to set + * @return this for chaining + **/ + ExternalReferenceBuilder setcontentType(String contentType) { + this.contentType = contentType; + return this; + } + + /** + * Sets the initial value of comment + * @parameter comment value to set + * @return this for chaining + **/ + ExternalReferenceBuilder setcomment(String comment) { + this.comment = comment; + return this; + } + + + /** + * @return the ExternalReference + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ExternalReference build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ExternalReference(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java b/generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java new file mode 100644 index 000000000..9de382914 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * ExteralReferenceType specifies the type of an external reference. + */ +public enum ExternalReferenceType implements IndividualUriValue { + + VULNERABILITY_EXPLOITABILITY_ASSESSMENT("vulnerabilityExploitabilityAssessment"), + BINARY_ARTIFACT("binaryArtifact"), + RELEASE_HISTORY("releaseHistory"), + FUNDING("funding"), + BUILD_META("buildMeta"), + PRODUCT_METADATA("productMetadata"), + STATIC_ANALYSIS_REPORT("staticAnalysisReport"), + DYNAMIC_ANALYSIS_REPORT("dynamicAnalysisReport"), + MAILING_LIST("mailingList"), + ALT_DOWNLOAD_LOCATION("altDownloadLocation"), + CHAT("chat"), + LICENSE("license"), + VULNERABILITY_DISCLOSURE_REPORT("vulnerabilityDisclosureReport"), + QUALITY_ASSESSMENT_REPORT("qualityAssessmentReport"), + BUILD_SYSTEM("buildSystem"), + SECURITY_THREAT_MODEL("securityThreatModel"), + METRICS("metrics"), + EOL_NOTICE("eolNotice"), + SECURITY_PEN_TEST_REPORT("securityPenTestReport"), + SECURITY_ADVISORY("securityAdvisory"), + DOCUMENTATION("documentation"), + VCS("vcs"), + SUPPORT("support"), + SECURITY_FIX("securityFix"), + SECURE_SOFTWARE_ATTESTATION("secureSoftwareAttestation"), + SOURCE_ARTIFACT("sourceArtifact"), + SECURITY_ADVERSARY_MODEL("securityAdversaryModel"), + RELEASE_NOTES("releaseNotes"), + SECURITY_POLICY("securityPolicy"), + ALT_WEB_PAGE("altWebPage"), + RISK_ASSESSMENT("riskAssessment"), + SECURITY_OTHER("securityOther"), + CERTIFICATION_REPORT("certificationReport"), + RUNTIME_ANALYSIS_REPORT("runtimeAnalysisReport"), + OTHER("other"), + ISSUE_TRACKER("issueTracker"), + SOCIAL_MEDIA("socialMedia"), + COMPONENT_ANALYSIS_REPORT("componentAnalysisReport"); + + private String longName; + + private ExternalReferenceType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/ExternalReferenceType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/Hash.java b/generated/src/main/java/org/spdx/library/model/core/Hash.java new file mode 100644 index 000000000..c4a9b327a --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Hash.java @@ -0,0 +1,227 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A hash is a grouping of characteristics unique to the result of applying a mathematical + * algorithm that maps data of arbitrary size to a bit string (the hash) and is a one-way + * function, that is, a function which is practically infeasible to invert. This is + * commonly used for integrity checking of data. + */ +public class Hash extends IntegrityMethod { + + + /** + * Create the Hash with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Hash + */ + public Hash() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Hash + * @throws InvalidSPDXAnalysisException when unable to create the Hash + */ + public Hash(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Hash is to be stored + * @param objectUri URI or anonymous ID for the Hash + * @param copyManager Copy manager for the Hash - can be null if copying is not required + * @param create true if Hash is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Hash + */ + public Hash(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Hash from the builder - used in the builder class + * @param builder Builder to create the Hash from + * @throws InvalidSPDXAnalysisException when unable to create the Hash + */ + protected Hash(HashBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setAlgorithm(builder.algorithm); + setHashValue(builder.hashValue); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Hash"; + } + + // Getters and Setters + + + /** + * @return the algorithm + */ + @SuppressWarnings("unchecked") + public @Nullable HashAlgorithm getAlgorithm() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_ALGORITHM); + if (retval.isPresent()) { + if (!(retval.get() instanceof HashAlgorithm)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (HashAlgorithm)(retval.get()); + } else { + return null; + } + } + /** + * @param algorithm the algorithm to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Hash setAlgorithm(@Nullable HashAlgorithm algorithm) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(algorithm)) { + throw new InvalidSPDXAnalysisException("algorithm is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_ALGORITHM, algorithm); + return this; + } + + /** + * @return the hashValue + */ + public @Nullable String getHashValue() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_HASH_VALUE); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param hashValue the hashValue to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Hash setHashValue(@Nullable String hashValue) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(hashValue)) { + throw new InvalidSPDXAnalysisException("hashValue is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_HASH_VALUE, hashValue); + return this; + } + + + @Override + public String toString() { + return "Hash: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + HashAlgorithm algorithm = getAlgorithm(); + if (Objects.isNull(algorithm)) { + retval.add("Missing algorithm in Hash"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting algorithm for Hash: "+e.getMessage()); + } + try { + String hashValue = getHashValue(); + if (Objects.isNull(hashValue)) { + retval.add("Missing hashValue in Hash"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting hashValue for Hash: "+e.getMessage()); + } + return retval; + } + + public static class HashBuilder extends IntegrityMethodBuilder { + + public HashBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + HashAlgorithm algorithm = null; + String hashValue = null; + + + /** + * Sets the initial value of algorithm + * @parameter algorithm value to set + * @return this for chaining + **/ + HashBuilder setalgorithm(HashAlgorithm algorithm) { + this.algorithm = algorithm; + return this; + } + + /** + * Sets the initial value of hashValue + * @parameter hashValue value to set + * @return this for chaining + **/ + HashBuilder sethashValue(String hashValue) { + this.hashValue = hashValue; + return this; + } + + + /** + * @return the Hash + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Hash build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Hash(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java b/generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java new file mode 100644 index 000000000..fb897baac --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A HashAlgorithm is a mathematical algorithm that maps data of arbitrary size to a + * bit string (the hash) and is a one-way function, that is, a function which is practically + * infeasible to invert. + */ +public enum HashAlgorithm implements IndividualUriValue { + + SHA_3___5_1_2("sha3_512"), + SPDX_PVC_SHA_1("spdxPvcSha1"), + SHA_5_1_2("sha512"), + FALCON("falcon"), + SHA_2_5_6("sha256"), + SPDX_PVC_SHA_2_5_6("spdxPvcSha256"), + MD_2("md2"), + SHA_3___2_5_6("sha3_256"), + SHA_1("sha1"), + MD_4("md4"), + SHA_3___3_8_4("sha3_384"), + MD_6("md6"), + SPHINCS_PLUS("sphincsPlus"), + SHA_3_8_4("sha384"), + MD_5("md5"), + BLAKE_2B_2_5_6("blake2b256"), + BLAKE_3("blake3"), + OTHER("other"), + BLAKE_2B_5_1_2("blake2b512"), + CRYSTALS_DILITHIUM("crystalsDilithium"), + BLAKE_2B_3_8_4("blake2b384"), + SHA_2_2_4("sha224"), + CRYSTALS_KYBER("crystalsKyber"), + SHA_3___2_2_4("sha3_224"); + + private String longName; + + private HashAlgorithm(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/HashAlgorithm"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java b/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java new file mode 100644 index 000000000..3919397fa --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An IntegrityMethod provides an independently reproducible mechanism that permits + * verification of a specific Element that correlates to the data in this SPDX document. + * This identifier enables a recipient to determine if anything in the original Element + * has been changed and eliminates confusion over which version or modification of + * a specific Element is referenced. + */ +public class IntegrityMethod extends ModelObject { + + + /** + * Create the IntegrityMethod with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the IntegrityMethod + */ + public IntegrityMethod() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the IntegrityMethod + * @throws InvalidSPDXAnalysisException when unable to create the IntegrityMethod + */ + public IntegrityMethod(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the IntegrityMethod is to be stored + * @param objectUri URI or anonymous ID for the IntegrityMethod + * @param copyManager Copy manager for the IntegrityMethod - can be null if copying is not required + * @param create true if IntegrityMethod is to be created + * @throws InvalidSPDXAnalysisException when unable to create the IntegrityMethod + */ + public IntegrityMethod(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the IntegrityMethod from the builder - used in the builder class + * @param builder Builder to create the IntegrityMethod from + * @throws InvalidSPDXAnalysisException when unable to create the IntegrityMethod + */ + protected IntegrityMethod(IntegrityMethodBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setComment(builder.comment); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.IntegrityMethod"; + } + + // Getters and Setters + + + /** + * @return the comment + */ + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + } + /** + * @param comment the comment to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public IntegrityMethod setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + return this; + } + + + @Override + public String toString() { + return "IntegrityMethod: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + Optional comment = getComment(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting comment for IntegrityMethod: "+e.getMessage()); + } + return retval; + } + + public static class IntegrityMethodBuilder extends ModelObjectBuilder { + + public IntegrityMethodBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String comment = null; + + + /** + * Sets the initial value of comment + * @parameter comment value to set + * @return this for chaining + **/ + IntegrityMethodBuilder setcomment(String comment) { + this.comment = comment; + return this; + } + + + /** + * @return the IntegrityMethod + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public IntegrityMethod build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new IntegrityMethod(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java new file mode 100644 index 000000000..96a01825d --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public enum LifecycleScopeType implements IndividualUriValue { + + RUNTIME("runtime"), + DEVELOPMENT("development"), + DESIGN("design"), + BUILD("build"), + TEST("test"), + OTHER("other"); + + private String longName; + + private LifecycleScopeType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/LifecycleScopeType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java new file mode 100644 index 000000000..5ffb5517d --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java @@ -0,0 +1,178 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public class LifecycleScopedRelationship extends Relationship { + + + /** + * Create the LifecycleScopedRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the LifecycleScopedRelationship + */ + public LifecycleScopedRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the LifecycleScopedRelationship + * @throws InvalidSPDXAnalysisException when unable to create the LifecycleScopedRelationship + */ + public LifecycleScopedRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the LifecycleScopedRelationship is to be stored + * @param objectUri URI or anonymous ID for the LifecycleScopedRelationship + * @param copyManager Copy manager for the LifecycleScopedRelationship - can be null if copying is not required + * @param create true if LifecycleScopedRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the LifecycleScopedRelationship + */ + public LifecycleScopedRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the LifecycleScopedRelationship from the builder - used in the builder class + * @param builder Builder to create the LifecycleScopedRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the LifecycleScopedRelationship + */ + protected LifecycleScopedRelationship(LifecycleScopedRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setScope(builder.scope); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.LifecycleScopedRelationship"; + } + + // Getters and Setters + + + /** + * @return the scope + */ + @SuppressWarnings("unchecked") + public Optional getScope() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_SCOPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof LifecycleScopeType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param scope the scope to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LifecycleScopedRelationship setScope(@Nullable LifecycleScopeType scope) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_SCOPE, scope); + return this; + } + + + @Override + public String toString() { + return "LifecycleScopedRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional scope = getScope(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting scope for LifecycleScopedRelationship: "+e.getMessage()); + } + return retval; + } + + public static class LifecycleScopedRelationshipBuilder extends RelationshipBuilder { + + public LifecycleScopedRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + LifecycleScopeType scope = null; + + + /** + * Sets the initial value of scope + * @parameter scope value to set + * @return this for chaining + **/ + LifecycleScopedRelationshipBuilder setscope(LifecycleScopeType scope) { + this.scope = scope; + return this; + } + + + /** + * @return the LifecycleScopedRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public LifecycleScopedRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new LifecycleScopedRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java new file mode 100644 index 000000000..2e33b421c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A namespace map allows the creator of a collection of Elements to use shorter identifiers + * ("prefixes") instead of URIs to provide a more human-readable and smaller serialized + * representation of the Elements. + */ +public class NamespaceMap extends ModelObject { + + + /** + * Create the NamespaceMap with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap + */ + public NamespaceMap() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the NamespaceMap + * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap + */ + public NamespaceMap(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the NamespaceMap is to be stored + * @param objectUri URI or anonymous ID for the NamespaceMap + * @param copyManager Copy manager for the NamespaceMap - can be null if copying is not required + * @param create true if NamespaceMap is to be created + * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap + */ + public NamespaceMap(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the NamespaceMap from the builder - used in the builder class + * @param builder Builder to create the NamespaceMap from + * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap + */ + protected NamespaceMap(NamespaceMapBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setPrefix(builder.prefix); + setNamespace(builder.namespace); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.NamespaceMap"; + } + + // Getters and Setters + + + /** + * @return the prefix + */ + public @Nullable String getPrefix() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_PREFIX); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param prefix the prefix to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public NamespaceMap setPrefix(@Nullable String prefix) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(prefix)) { + throw new InvalidSPDXAnalysisException("prefix is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_PREFIX, prefix); + return this; + } + + /** + * @return the namespace + */ + public @Nullable String getNamespace() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_NAMESPACE); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param namespace the namespace to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public NamespaceMap setNamespace(@Nullable String namespace) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(namespace)) { + throw new InvalidSPDXAnalysisException("namespace is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_NAMESPACE, namespace); + return this; + } + + + @Override + public String toString() { + return "NamespaceMap: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + String prefix = getPrefix(); + if (Objects.isNull(prefix)) { + retval.add("Missing prefix in NamespaceMap"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting prefix for NamespaceMap: "+e.getMessage()); + } + try { + String namespace = getNamespace(); + if (Objects.isNull(namespace)) { + retval.add("Missing namespace in NamespaceMap"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting namespace for NamespaceMap: "+e.getMessage()); + } + return retval; + } + + public static class NamespaceMapBuilder extends ModelObjectBuilder { + + public NamespaceMapBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String prefix = null; + String namespace = null; + + + /** + * Sets the initial value of prefix + * @parameter prefix value to set + * @return this for chaining + **/ + NamespaceMapBuilder setprefix(String prefix) { + this.prefix = prefix; + return this; + } + + /** + * Sets the initial value of namespace + * @parameter namespace value to set + * @return this for chaining + **/ + NamespaceMapBuilder setnamespace(String namespace) { + this.namespace = namespace; + return this; + } + + + /** + * @return the NamespaceMap + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public NamespaceMap build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new NamespaceMap(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Organization.java b/generated/src/main/java/org/spdx/library/model/core/Organization.java new file mode 100644 index 000000000..ecea6214c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Organization.java @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An Organization is a group of people who work together in an organized way for a shared + * purpose. + */ +public class Organization extends Agent { + + + /** + * Create the Organization with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Organization + */ + public Organization() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Organization + * @throws InvalidSPDXAnalysisException when unable to create the Organization + */ + public Organization(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Organization is to be stored + * @param objectUri URI or anonymous ID for the Organization + * @param copyManager Copy manager for the Organization - can be null if copying is not required + * @param create true if Organization is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Organization + */ + public Organization(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Organization from the builder - used in the builder class + * @param builder Builder to create the Organization from + * @throws InvalidSPDXAnalysisException when unable to create the Organization + */ + protected Organization(OrganizationBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Organization"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Organization: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class OrganizationBuilder extends AgentBuilder { + + public OrganizationBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Organization + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Organization build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Organization(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Payload.java b/generated/src/main/java/org/spdx/library/model/core/Payload.java new file mode 100644 index 000000000..e96905533 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Payload.java @@ -0,0 +1,254 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public class Payload extends ModelObject { + + Collection namespacess; + Collection importss; + + /** + * Create the Payload with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Payload + */ + public Payload() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Payload + * @throws InvalidSPDXAnalysisException when unable to create the Payload + */ + public Payload(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Payload is to be stored + * @param objectUri URI or anonymous ID for the Payload + * @param copyManager Copy manager for the Payload - can be null if copying is not required + * @param create true if Payload is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Payload + */ + @SuppressWarnings("unchecked") + public Payload(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + namespacess = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_NAMESPACES, NamespaceMap.class); + importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); + } + + /** + * Create the Payload from the builder - used in the builder class + * @param builder Builder to create the Payload from + * @throws InvalidSPDXAnalysisException when unable to create the Payload + */ + protected Payload(PayloadBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + namespacess = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_NAMESPACES, NamespaceMap.class); + importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); + getNamespacess().addAll(builder.namespacess); + getImportss().addAll(builder.importss); + setCreationInfo(builder.creationInfo); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Payload"; + } + + // Getters and Setters + public Collection getNamespacess() { + return namespacess; + } + public Collection getImportss() { + return importss; + } + + + /** + * @return the creationInfo + */ + @SuppressWarnings("unchecked") + public Optional getCreationInfo() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO); + if (retval.isPresent()) { + if (!(retval.get() instanceof CreationInfo)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param creationInfo the creationInfo to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Payload setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO, creationInfo); + return this; + } + + + @Override + public String toString() { + return "Payload: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + Optional creationInfo; + try { + creationInfo = getCreationInfo(); + if (creationInfo.isPresent()) { + retval.addAll(creationInfo.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting creationInfo for Payload: "+e.getMessage()); + } + for (NamespaceMap namespaces:namespacess) { + retval.addAll(namespaces.verify(verifiedIds, specVersion, profiles)); + } + for (ExternalMap imports:importss) { + retval.addAll(imports.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class PayloadBuilder extends ModelObjectBuilder { + + public PayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection namespacess = new ArrayList<>(); + Collection importss = new ArrayList<>(); + CreationInfo creationInfo = null; + + + /** + * Adds a namespaces to the initial collection + * @parameter namespaces namespaces to add + * @return this for chaining + **/ + PayloadBuilder addnamespaces(NamespaceMap namespaces) { + if (Objects.nonNull(namespaces)) { + namespacess.add(namespaces); + } + return this; + } + + /** + * Adds all elements from a collection to the initial namespaces collection + * @parameter namespacesCollection collection to initialize the namespaces + * @return this for chaining + **/ + PayloadBuilder addAllnamespaces(Collection namespacesCollection) { + if (Objects.nonNull(namespacesCollection)) { + namespacess.addAll(namespacesCollection); + } + return this; + } + + /** + * Adds a imports to the initial collection + * @parameter imports imports to add + * @return this for chaining + **/ + PayloadBuilder addimports(ExternalMap imports) { + if (Objects.nonNull(imports)) { + importss.add(imports); + } + return this; + } + + /** + * Adds all elements from a collection to the initial imports collection + * @parameter importsCollection collection to initialize the imports + * @return this for chaining + **/ + PayloadBuilder addAllimports(Collection importsCollection) { + if (Objects.nonNull(importsCollection)) { + importss.addAll(importsCollection); + } + return this; + } + + /** + * Sets the initial value of creationInfo + * @parameter creationInfo value to set + * @return this for chaining + **/ + PayloadBuilder setcreationInfo(CreationInfo creationInfo) { + this.creationInfo = creationInfo; + return this; + } + + + /** + * @return the Payload + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Payload build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Payload(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Person.java b/generated/src/main/java/org/spdx/library/model/core/Person.java new file mode 100644 index 000000000..dd720f554 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Person.java @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A Person is an individual human being. + */ +public class Person extends Agent { + + + /** + * Create the Person with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Person + */ + public Person() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Person + * @throws InvalidSPDXAnalysisException when unable to create the Person + */ + public Person(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Person is to be stored + * @param objectUri URI or anonymous ID for the Person + * @param copyManager Copy manager for the Person - can be null if copying is not required + * @param create true if Person is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Person + */ + public Person(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Person from the builder - used in the builder class + * @param builder Builder to create the Person from + * @throws InvalidSPDXAnalysisException when unable to create the Person + */ + protected Person(PersonBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Person"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Person: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class PersonBuilder extends AgentBuilder { + + public PersonBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Person + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Person build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Person(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java new file mode 100644 index 000000000..c143c9ef8 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java @@ -0,0 +1,242 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * PositiveIntegerRange is a tuple of two positive integers that define a range. "begin" + * must be less than or equal to "end". + */ +public class PositiveIntegerRange extends ModelObject { + + + /** + * Create the PositiveIntegerRange with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the PositiveIntegerRange + */ + public PositiveIntegerRange() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the PositiveIntegerRange + * @throws InvalidSPDXAnalysisException when unable to create the PositiveIntegerRange + */ + public PositiveIntegerRange(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the PositiveIntegerRange is to be stored + * @param objectUri URI or anonymous ID for the PositiveIntegerRange + * @param copyManager Copy manager for the PositiveIntegerRange - can be null if copying is not required + * @param create true if PositiveIntegerRange is to be created + * @throws InvalidSPDXAnalysisException when unable to create the PositiveIntegerRange + */ + public PositiveIntegerRange(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the PositiveIntegerRange from the builder - used in the builder class + * @param builder Builder to create the PositiveIntegerRange from + * @throws InvalidSPDXAnalysisException when unable to create the PositiveIntegerRange + */ + protected PositiveIntegerRange(PositiveIntegerRangeBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setEnd(builder.end); + setBegin(builder.begin); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.PositiveIntegerRange"; + } + + // Getters and Setters + + + /** + * @return the end + */ + public @Nullable Integer getEnd() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_END); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param end the end to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public PositiveIntegerRange setEnd(@Nullable Integer end) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(end)) { + throw new InvalidSPDXAnalysisException("end is a required property"); + } + if (isStrict() && Objects.nonNull(end) && end < 1) { + throw new InvalidSPDXAnalysisException("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); + } + if (isStrict() && Objects.nonNull(end) && end > 1) { + throw new InvalidSPDXAnalysisException("end value " + end + " is greater than the maximum 1 in PositiveIntegerRange"); + } + setPropertyValue(SpdxConstants.CORE_PROP_END, end); + return this; + } + + /** + * @return the begin + */ + public @Nullable Integer getBegin() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_BEGIN); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param begin the begin to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public PositiveIntegerRange setBegin(@Nullable Integer begin) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(begin)) { + throw new InvalidSPDXAnalysisException("begin is a required property"); + } + if (isStrict() && Objects.nonNull(begin) && begin < 1) { + throw new InvalidSPDXAnalysisException("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); + } + if (isStrict() && Objects.nonNull(begin) && begin > 1) { + throw new InvalidSPDXAnalysisException("begin value " + begin + " is greater than the maximum 1 in PositiveIntegerRange"); + } + setPropertyValue(SpdxConstants.CORE_PROP_BEGIN, begin); + return this; + } + + + @Override + public String toString() { + return "PositiveIntegerRange: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + try { + Integer end = getEnd(); + if (Objects.isNull(end)) { + retval.add("Missing end in PositiveIntegerRange"); + } + if (Objects.nonNull(end) && end < 1) { + retval.add("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); + } + if (Objects.nonNull(end) && end > 1) { + retval.add("end value " + end + " is greater than the maximum 1 in PositiveIntegerRange"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting end for PositiveIntegerRange: "+e.getMessage()); + } + try { + Integer begin = getBegin(); + if (Objects.isNull(begin)) { + retval.add("Missing begin in PositiveIntegerRange"); + } + if (Objects.nonNull(begin) && begin < 1) { + retval.add("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); + } + if (Objects.nonNull(begin) && begin > 1) { + retval.add("begin value " + begin + " is greater than the maximum 1 in PositiveIntegerRange"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting begin for PositiveIntegerRange: "+e.getMessage()); + } + return retval; + } + + public static class PositiveIntegerRangeBuilder extends ModelObjectBuilder { + + public PositiveIntegerRangeBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Integer end = null; + Integer begin = null; + + + /** + * Sets the initial value of end + * @parameter end value to set + * @return this for chaining + **/ + PositiveIntegerRangeBuilder setend(Integer end) { + this.end = end; + return this; + } + + /** + * Sets the initial value of begin + * @parameter begin value to set + * @return this for chaining + **/ + PositiveIntegerRangeBuilder setbegin(Integer begin) { + this.begin = begin; + return this; + } + + + /** + * @return the PositiveIntegerRange + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public PositiveIntegerRange build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new PositiveIntegerRange(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java b/generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java new file mode 100644 index 000000000..61cc41ffd --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * There are a set of profiles that have been defined to be valid for a specific release + * This file enumerates the values that have been agreed on, and may be applied to the + * creation information for an an element. + */ +public enum ProfileIdentifierType implements IndividualUriValue { + + USAGE("usage"), + SECURITY("security"), + SOFTWARE("software"), + EXTENSION("extension"), + BUILD("build"), + AI("ai"), + CORE("core"), + LICENSING("licensing"), + DATASET("dataset"); + + private String longName; + + private ProfileIdentifierType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/ProfileIdentifierType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/Relationship.java b/generated/src/main/java/org/spdx/library/model/core/Relationship.java new file mode 100644 index 000000000..0527fceb0 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Relationship.java @@ -0,0 +1,376 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A Relationship is a grouping of characteristics unique to an assertion that one Element + * is related to one or more other Elements in some way. + */ +public class Relationship extends Element { + + Collection tos; + + /** + * Create the Relationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Relationship + */ + public Relationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Relationship + * @throws InvalidSPDXAnalysisException when unable to create the Relationship + */ + public Relationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Relationship is to be stored + * @param objectUri URI or anonymous ID for the Relationship + * @param copyManager Copy manager for the Relationship - can be null if copying is not required + * @param create true if Relationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Relationship + */ + @SuppressWarnings("unchecked") + public Relationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + tos = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_TO, Element.class); + } + + /** + * Create the Relationship from the builder - used in the builder class + * @param builder Builder to create the Relationship from + * @throws InvalidSPDXAnalysisException when unable to create the Relationship + */ + protected Relationship(RelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + tos = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_TO, Element.class); + getTos().addAll(builder.tos); + setFrom(builder.from); + setRelationshipType(builder.relationshipType); + setCompleteness(builder.completeness); + setStartTime(builder.startTime); + setEndTime(builder.endTime); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Relationship"; + } + + // Getters and Setters + public Collection getTos() { + return tos; + } + + /** + * @return the from + */ + public @Nullable Element getFrom() throws InvalidSPDXAnalysisException { + Optional retval = getElementPropertyValue(SpdxConstants.CORE_PROP_FROM); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param from the from to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setFrom(@Nullable Element from) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(from)) { + throw new InvalidSPDXAnalysisException("from is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_FROM, from); + return this; + } + + + /** + * @return the relationshipType + */ + @SuppressWarnings("unchecked") + public @Nullable RelationshipType getRelationshipType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_RELATIONSHIP_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof RelationshipType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (RelationshipType)(retval.get()); + } else { + return null; + } + } + /** + * @param relationshipType the relationshipType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setRelationshipType(@Nullable RelationshipType relationshipType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(relationshipType)) { + throw new InvalidSPDXAnalysisException("relationshipType is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_RELATIONSHIP_TYPE, relationshipType); + return this; + } + + /** + * @return the completeness + */ + @SuppressWarnings("unchecked") + public Optional getCompleteness() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS); + if (retval.isPresent()) { + if (!(retval.get() instanceof RelationshipCompleteness)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param completeness the completeness to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setCompleteness(@Nullable RelationshipCompleteness completeness) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS, completeness); + return this; + } + + /** + * @return the startTime + */ + public Optional getStartTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_START_TIME); + } + /** + * @param startTime the startTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setStartTime(@Nullable String startTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_START_TIME, startTime); + return this; + } + + /** + * @return the endTime + */ + public Optional getEndTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_END_TIME); + } + /** + * @param endTime the endTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setEndTime(@Nullable String endTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_END_TIME, endTime); + return this; + } + + + @Override + public String toString() { + return "Relationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Element from; + try { + from = getFrom(); + if (Objects.nonNull(from)) { + retval.addAll(from.verify(verifiedIds, specVersion, profiles)); + } else { + if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing from in from"); + } + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting from for Relationship: "+e.getMessage()); + } + try { + RelationshipType relationshipType = getRelationshipType(); + if (Objects.isNull(relationshipType)) { + retval.add("Missing relationshipType in Relationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting relationshipType for Relationship: "+e.getMessage()); + } + try { + Optional completeness = getCompleteness(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting completeness for Relationship: "+e.getMessage()); + } + try { + Optional startTime = getStartTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting startTime for Relationship: "+e.getMessage()); + } + try { + Optional endTime = getEndTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting endTime for Relationship: "+e.getMessage()); + } + for (Element to:tos) { + retval.addAll(to.verify(verifiedIds, specVersion, profiles)); + } + return retval; + } + + public static class RelationshipBuilder extends ElementBuilder { + + public RelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection tos = new ArrayList<>(); + Element from = null; + RelationshipType relationshipType = null; + RelationshipCompleteness completeness = null; + String startTime = null; + String endTime = null; + + + /** + * Adds a to to the initial collection + * @parameter to to to add + * @return this for chaining + **/ + RelationshipBuilder addto(Element to) { + if (Objects.nonNull(to)) { + tos.add(to); + } + return this; + } + + /** + * Adds all elements from a collection to the initial to collection + * @parameter toCollection collection to initialize the to + * @return this for chaining + **/ + RelationshipBuilder addAllto(Collection toCollection) { + if (Objects.nonNull(toCollection)) { + tos.addAll(toCollection); + } + return this; + } + + /** + * Sets the initial value of from + * @parameter from value to set + * @return this for chaining + **/ + RelationshipBuilder setfrom(Element from) { + this.from = from; + return this; + } + + /** + * Sets the initial value of relationshipType + * @parameter relationshipType value to set + * @return this for chaining + **/ + RelationshipBuilder setrelationshipType(RelationshipType relationshipType) { + this.relationshipType = relationshipType; + return this; + } + + /** + * Sets the initial value of completeness + * @parameter completeness value to set + * @return this for chaining + **/ + RelationshipBuilder setcompleteness(RelationshipCompleteness completeness) { + this.completeness = completeness; + return this; + } + + /** + * Sets the initial value of startTime + * @parameter startTime value to set + * @return this for chaining + **/ + RelationshipBuilder setstartTime(String startTime) { + this.startTime = startTime; + return this; + } + + /** + * Sets the initial value of endTime + * @parameter endTime value to set + * @return this for chaining + **/ + RelationshipBuilder setendTime(String endTime) { + this.endTime = endTime; + return this; + } + + + /** + * @return the Relationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Relationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Relationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java b/generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java new file mode 100644 index 000000000..553581601 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * RelationshipCompleteness indicates whether a relationship is complete or known + * to be incomplete or if there is made no assertion either way. + */ +public enum RelationshipCompleteness implements IndividualUriValue { + + COMPLETE("complete"), + NO_ASSERTION("noAssertion"), + INCOMPLETE("incomplete"); + + private String longName; + + private RelationshipCompleteness(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/RelationshipCompleteness"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/RelationshipType.java b/generated/src/main/java/org/spdx/library/model/core/RelationshipType.java new file mode 100644 index 000000000..517c7cc40 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/RelationshipType.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Provides information about the relationship between two Elements. For example, + * you can represent a relationship between two different Files, between a Package + * and a File, between two Packages, or between one SPDXDocument and another SPDXDocument. + */ +public enum RelationshipType implements IndividualUriValue { + + DOES_NOT_AFFECT("doesNotAffect"), + EXPANDED_FROM_ARCHIVE("expandedFromArchive"), + CONFIG_OF("configOf"), + FILE_DELETED("fileDeleted"), + HAS_ASSESSMENT_FOR("hasAssessmentFor"), + COPY("copy"), + ANCESTOR("ancestor"), + HAS_ASSOCIATED_VULNERABILITY("hasAssociatedVulnerability"), + HOST_OF("hostOf"), + PROVIDED_DEPENDENCY("providedDependency"), + COORDINATED_BY("coordinatedBy"), + REQUIREMENT_FOR("requirementFor"), + AFFECTS("affects"), + CONTAINS("contains"), + DOCUMENTATION("documentation"), + TEST_TOOL("testTool"), + ON_BEHALF_OF("onBehalfOf"), + TRAINED_ON("trainedOn"), + EXAMPLE("example"), + DEV_TOOL("devTool"), + INPUT_OF("inputOf"), + DEPENDENCY_MANIFEST("dependencyManifest"), + TEST("test"), + REPORTED_BY("reportedBy"), + FOUND_BY("foundBy"), + FIXED_BY("fixedBy"), + AMENDS("amends"), + EVIDENCE_FOR("evidenceFor"), + PACKAGES("packages"), + TEST_CASE("testCase"), + TEST_DEPENDENCY("testDependency"), + BUILD_TOOL("buildTool"), + FILE_MODIFIED("fileModified"), + DYNAMIC_LINK("dynamicLink"), + PREREQUISITE("prerequisite"), + AVAILABLE_FROM("availableFrom"), + UNDER_INVESTIGATION_FOR("underInvestigationFor"), + REPUBLISHED_BY("republishedBy"), + DESCENDANT("descendant"), + PUBLISHED_BY("publishedBy"), + GENERATES("generates"), + DISTRIBUTION_ARTIFACT("distributionArtifact"), + EXPLOIT_CREATED_BY("exploitCreatedBy"), + OPTIONAL_DEPENDENCY("optionalDependency"), + DATA_FILE("dataFile"), + OTHER("other"), + SPECIFICATION_FOR("specificationFor"), + INVOKED_BY("invokedBy"), + DEPENDS_ON("dependsOn"), + VARIANT("variant"), + DEV_DEPENDENCY("devDependency"), + STATIC_LINK("staticLink"), + TESTED_ON("testedOn"), + PATCH("patch"), + FILE_ADDED("fileAdded"), + OUTPUT_OF("outputOf"), + BUILD_DEPENDENCY("buildDependency"), + DESCRIBES("describes"), + METAFILE("metafile"), + OPTIONAL_COMPONENT("optionalComponent"), + FIXED_IN("fixedIn"), + RUNTIME_DEPENDENCY("runtimeDependency"); + + private String longName; + + private RelationshipType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Core/RelationshipType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java b/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java new file mode 100644 index 000000000..ef99f49d8 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A SoftwareAgent is a software program that is given the authority (similar to a user's + * authority) to act on a system. + */ +public class SoftwareAgent extends Agent { + + + /** + * Create the SoftwareAgent with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareAgent + */ + public SoftwareAgent() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SoftwareAgent + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareAgent + */ + public SoftwareAgent(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SoftwareAgent is to be stored + * @param objectUri URI or anonymous ID for the SoftwareAgent + * @param copyManager Copy manager for the SoftwareAgent - can be null if copying is not required + * @param create true if SoftwareAgent is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareAgent + */ + public SoftwareAgent(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SoftwareAgent from the builder - used in the builder class + * @param builder Builder to create the SoftwareAgent from + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareAgent + */ + protected SoftwareAgent(SoftwareAgentBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.SoftwareAgent"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "SoftwareAgent: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class SoftwareAgentBuilder extends AgentBuilder { + + public SoftwareAgentBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the SoftwareAgent + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SoftwareAgent build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SoftwareAgent(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java b/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java new file mode 100644 index 000000000..1977a6407 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java @@ -0,0 +1,138 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An SpdxDocument assembles a collection of Elements under a common string, the name + * of the document. Commonly used when representing a unit of transfer of SPDX Elements. + * External property restriction on /Core/Element/name: minCount: 1 + */ +public class SpdxDocument extends Bundle { + + + /** + * Create the SpdxDocument with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SpdxDocument + */ + public SpdxDocument() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SpdxDocument + * @throws InvalidSPDXAnalysisException when unable to create the SpdxDocument + */ + public SpdxDocument(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SpdxDocument is to be stored + * @param objectUri URI or anonymous ID for the SpdxDocument + * @param copyManager Copy manager for the SpdxDocument - can be null if copying is not required + * @param create true if SpdxDocument is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SpdxDocument + */ + public SpdxDocument(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SpdxDocument from the builder - used in the builder class + * @param builder Builder to create the SpdxDocument from + * @throws InvalidSPDXAnalysisException when unable to create the SpdxDocument + */ + protected SpdxDocument(SpdxDocumentBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.SpdxDocument"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "SpdxDocument: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class SpdxDocumentBuilder extends BundleBuilder { + + public SpdxDocumentBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the SpdxDocument + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SpdxDocument build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SpdxDocument(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/core/Tool.java b/generated/src/main/java/org/spdx/library/model/core/Tool.java new file mode 100644 index 000000000..542fae5ca --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/core/Tool.java @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A Tool is an element of hardware and/or software utilized to carry out a particular + * function. + */ +public class Tool extends Element { + + + /** + * Create the Tool with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Tool + */ + public Tool() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Tool + * @throws InvalidSPDXAnalysisException when unable to create the Tool + */ + public Tool(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Tool is to be stored + * @param objectUri URI or anonymous ID for the Tool + * @param copyManager Copy manager for the Tool - can be null if copying is not required + * @param create true if Tool is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Tool + */ + public Tool(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Tool from the builder - used in the builder class + * @param builder Builder to create the Tool from + * @throws InvalidSPDXAnalysisException when unable to create the Tool + */ + protected Tool(ToolBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Tool"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Tool: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class ToolBuilder extends ElementBuilder { + + public ToolBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Tool + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Tool build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Tool(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java b/generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java new file mode 100644 index 000000000..e3b86277e --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.dataset; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Describes the different confidentiality levels as given by the [Traffic Light Protocol](https://en.wikipedia.org/wiki/Traffic_Light_Protocol). + */ +public enum ConfidentialityLevelType implements IndividualUriValue { + + GREEN("Green"), + CLEAR("Clear"), + RED("Red"), + AMBER("Amber"); + + private String longName; + + private ConfidentialityLevelType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Dataset/ConfidentialityLevelType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java new file mode 100644 index 000000000..0401274ef --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java @@ -0,0 +1,621 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.dataset; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; +import org.spdx.library.model.core.DictionaryEntry; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.software.SpdxPackage; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Metadata information that can be added to a dataset that may be used in a software or + * to train/test an AI package. External property restriction on /Core/Artifact/originatedBy: + * minCount: 1 External property restriction on /Software/Package/downloadLocation: + * minCount: 1 External property restriction on /Software/SoftwareArtifact/primaryPurpose: + * minCount: 1 External property restriction on /Core/Artifact/releaseTime: minCount: + * 1 External property restriction on /Core/Artifact/builtTime: minCount: 1 + */ +public class Dataset extends SpdxPackage { + + Collection sensors; + Collection anonymizationMethodUseds; + Collection dataPreprocessings; + Collection knownBiass; + Collection datasetTypes; + + /** + * Create the Dataset with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Dataset + */ + public Dataset() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Dataset + * @throws InvalidSPDXAnalysisException when unable to create the Dataset + */ + public Dataset(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Dataset is to be stored + * @param objectUri URI or anonymous ID for the Dataset + * @param copyManager Copy manager for the Dataset - can be null if copying is not required + * @param create true if Dataset is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Dataset + */ + @SuppressWarnings("unchecked") + public Dataset(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + sensors = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_SENSOR, DictionaryEntry.class); + datasetTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATASET_TYPE, DatasetType.class); + anonymizationMethodUseds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_ANONYMIZATION_METHOD_USED, String.class); + dataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATA_PREPROCESSING, String.class); + knownBiass = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_KNOWN_BIAS, String.class); + } + + /** + * Create the Dataset from the builder - used in the builder class + * @param builder Builder to create the Dataset from + * @throws InvalidSPDXAnalysisException when unable to create the Dataset + */ + protected Dataset(DatasetBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + sensors = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_SENSOR, DictionaryEntry.class); + datasetTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATASET_TYPE, DatasetType.class); + anonymizationMethodUseds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_ANONYMIZATION_METHOD_USED, String.class); + dataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATA_PREPROCESSING, String.class); + knownBiass = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_KNOWN_BIAS, String.class); + getSensors().addAll(builder.sensors); + getDatasetTypes().addAll(builder.datasetTypes); + getAnonymizationMethodUseds().addAll(builder.anonymizationMethodUseds); + getDataPreprocessings().addAll(builder.dataPreprocessings); + getKnownBiass().addAll(builder.knownBiass); + setSensitivePersonalInformation(builder.sensitivePersonalInformation); + setConfidentialityLevel(builder.confidentialityLevel); + setDatasetAvailability(builder.datasetAvailability); + setDatasetSize(builder.datasetSize); + setIntendedUse(builder.intendedUse); + setDatasetNoise(builder.datasetNoise); + setDataCollectionProcess(builder.dataCollectionProcess); + setDatasetUpdateMechanism(builder.datasetUpdateMechanism); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Dataset.Dataset"; + } + + // Getters and Setters + public Collection getSensors() { + return sensors; + } + public Collection getDatasetTypes() { + return datasetTypes; + } + public Collection getAnonymizationMethodUseds() { + return anonymizationMethodUseds; + } + public Collection getDataPreprocessings() { + return dataPreprocessings; + } + public Collection getKnownBiass() { + return knownBiass; + } + + + /** + * @return the sensitivePersonalInformation + */ + @SuppressWarnings("unchecked") + public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION); + if (retval.isPresent()) { + if (!(retval.get() instanceof PresenceType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param sensitivePersonalInformation the sensitivePersonalInformation to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setSensitivePersonalInformation(@Nullable PresenceType sensitivePersonalInformation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION, sensitivePersonalInformation); + return this; + } + + /** + * @return the confidentialityLevel + */ + @SuppressWarnings("unchecked") + public Optional getConfidentialityLevel() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_CONFIDENTIALITY_LEVEL); + if (retval.isPresent()) { + if (!(retval.get() instanceof ConfidentialityLevelType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param confidentialityLevel the confidentialityLevel to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setConfidentialityLevel(@Nullable ConfidentialityLevelType confidentialityLevel) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_CONFIDENTIALITY_LEVEL, confidentialityLevel); + return this; + } + + /** + * @return the datasetAvailability + */ + @SuppressWarnings("unchecked") + public Optional getDatasetAvailability() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_DATASET_AVAILABILITY); + if (retval.isPresent()) { + if (!(retval.get() instanceof DatasetAvailabilityType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param datasetAvailability the datasetAvailability to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setDatasetAvailability(@Nullable DatasetAvailabilityType datasetAvailability) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_AVAILABILITY, datasetAvailability); + return this; + } + + /** + * @return the datasetSize + */ + public Optional getDatasetSize() throws InvalidSPDXAnalysisException { + return getIntegerPropertyValue(SpdxConstants.DATASET_PROP_DATASET_SIZE); + } + + /** + * @param datasetSize the datasetSize to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setDatasetSize(@Nullable Integer datasetSize) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.nonNull(datasetSize) && datasetSize < 0) { + throw new InvalidSPDXAnalysisException("datasetSize value " + datasetSize + " is less than the minimum 0 in Dataset"); + } + if (isStrict() && Objects.nonNull(datasetSize) && datasetSize > 1) { + throw new InvalidSPDXAnalysisException("datasetSize value " + datasetSize + " is greater than the maximum 1 in Dataset"); + } + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_SIZE, datasetSize); + return this; + } + + /** + * @return the intendedUse + */ + public Optional getIntendedUse() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_INTENDED_USE); + } + /** + * @param intendedUse the intendedUse to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setIntendedUse(@Nullable String intendedUse) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_INTENDED_USE, intendedUse); + return this; + } + + /** + * @return the datasetNoise + */ + public Optional getDatasetNoise() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATASET_NOISE); + } + /** + * @param datasetNoise the datasetNoise to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setDatasetNoise(@Nullable String datasetNoise) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_NOISE, datasetNoise); + return this; + } + + /** + * @return the dataCollectionProcess + */ + public Optional getDataCollectionProcess() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATA_COLLECTION_PROCESS); + } + /** + * @param dataCollectionProcess the dataCollectionProcess to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setDataCollectionProcess(@Nullable String dataCollectionProcess) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATA_COLLECTION_PROCESS, dataCollectionProcess); + return this; + } + + /** + * @return the datasetUpdateMechanism + */ + public Optional getDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATASET_UPDATE_MECHANISM); + } + /** + * @param datasetUpdateMechanism the datasetUpdateMechanism to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setDatasetUpdateMechanism(@Nullable String datasetUpdateMechanism) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_UPDATE_MECHANISM, datasetUpdateMechanism); + return this; + } + + + @Override + public String toString() { + return "Dataset: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional sensitivePersonalInformation; + try { + sensitivePersonalInformation = getSensitivePersonalInformation(); + if (sensitivePersonalInformation.isPresent()) { + retval.addAll(sensitivePersonalInformation.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting sensitivePersonalInformation for Dataset: "+e.getMessage()); + } + try { + Optional confidentialityLevel = getConfidentialityLevel(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting confidentialityLevel for Dataset: "+e.getMessage()); + } + try { + Optional datasetAvailability = getDatasetAvailability(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting datasetAvailability for Dataset: "+e.getMessage()); + } + try { + Optional datasetSize = getDatasetSize(); + if (datasetSize.isPresent() && datasetSize.get() < 0) { + retval.add("datasetSize value " + datasetSize.get() + " is less than the minimum 0 in Dataset"); + } + if (datasetSize.isPresent() && datasetSize.get() > 1) { + retval.add("datasetSize value " + datasetSize.get() + " is greater than the maximum 1 in Dataset"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting datasetSize for Dataset: "+e.getMessage()); + } + try { + Optional intendedUse = getIntendedUse(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting intendedUse for Dataset: "+e.getMessage()); + } + try { + Optional datasetNoise = getDatasetNoise(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting datasetNoise for Dataset: "+e.getMessage()); + } + try { + Optional dataCollectionProcess = getDataCollectionProcess(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting dataCollectionProcess for Dataset: "+e.getMessage()); + } + try { + Optional datasetUpdateMechanism = getDatasetUpdateMechanism(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting datasetUpdateMechanism for Dataset: "+e.getMessage()); + } + for (DictionaryEntry sensor:sensors) { + retval.addAll(sensor.verify(verifiedIds, specVersion, profiles)); + } + if (datasetTypes.size() < 1) { + retval.add("datasetTypes size " + datasetTypes.size() + " is less than 1 in Dataset"); + } + return retval; + } + + public static class DatasetBuilder extends SpdxPackageBuilder { + + public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection sensors = new ArrayList<>(); + Collection datasetTypes = new ArrayList<>(); + Collection anonymizationMethodUseds = new ArrayList<>(); + Collection dataPreprocessings = new ArrayList<>(); + Collection knownBiass = new ArrayList<>(); + PresenceType sensitivePersonalInformation = null; + ConfidentialityLevelType confidentialityLevel = null; + DatasetAvailabilityType datasetAvailability = null; + Integer datasetSize = null; + String intendedUse = null; + String datasetNoise = null; + String dataCollectionProcess = null; + String datasetUpdateMechanism = null; + + + /** + * Adds a sensor to the initial collection + * @parameter sensor sensor to add + * @return this for chaining + **/ + DatasetBuilder addsensor(DictionaryEntry sensor) { + if (Objects.nonNull(sensor)) { + sensors.add(sensor); + } + return this; + } + + /** + * Adds all elements from a collection to the initial sensor collection + * @parameter sensorCollection collection to initialize the sensor + * @return this for chaining + **/ + DatasetBuilder addAllsensor(Collection sensorCollection) { + if (Objects.nonNull(sensorCollection)) { + sensors.addAll(sensorCollection); + } + return this; + } + + /** + * Adds a datasetType to the initial collection + * @parameter datasetType datasetType to add + * @return this for chaining + **/ + DatasetBuilder adddatasetType(DatasetType datasetType) { + if (Objects.nonNull(datasetType)) { + datasetTypes.add(datasetType); + } + return this; + } + + /** + * Adds all elements from a collection to the initial datasetType collection + * @parameter datasetTypeCollection collection to initialize the datasetType + * @return this for chaining + **/ + DatasetBuilder addAlldatasetType(Collection datasetTypeCollection) { + if (Objects.nonNull(datasetTypeCollection)) { + datasetTypes.addAll(datasetTypeCollection); + } + return this; + } + + /** + * Adds a anonymizationMethodUsed to the initial collection + * @parameter anonymizationMethodUsed anonymizationMethodUsed to add + * @return this for chaining + **/ + DatasetBuilder addanonymizationMethodUsed(String anonymizationMethodUsed) { + if (Objects.nonNull(anonymizationMethodUsed)) { + anonymizationMethodUseds.add(anonymizationMethodUsed); + } + return this; + } + + /** + * Adds all elements from a collection to the initial anonymizationMethodUsed collection + * @parameter anonymizationMethodUsedCollection collection to initialize the anonymizationMethodUsed + * @return this for chaining + **/ + DatasetBuilder addAllanonymizationMethodUsed(Collection anonymizationMethodUsedCollection) { + if (Objects.nonNull(anonymizationMethodUsedCollection)) { + anonymizationMethodUseds.addAll(anonymizationMethodUsedCollection); + } + return this; + } + + /** + * Adds a dataPreprocessing to the initial collection + * @parameter dataPreprocessing dataPreprocessing to add + * @return this for chaining + **/ + DatasetBuilder adddataPreprocessing(String dataPreprocessing) { + if (Objects.nonNull(dataPreprocessing)) { + dataPreprocessings.add(dataPreprocessing); + } + return this; + } + + /** + * Adds all elements from a collection to the initial dataPreprocessing collection + * @parameter dataPreprocessingCollection collection to initialize the dataPreprocessing + * @return this for chaining + **/ + DatasetBuilder addAlldataPreprocessing(Collection dataPreprocessingCollection) { + if (Objects.nonNull(dataPreprocessingCollection)) { + dataPreprocessings.addAll(dataPreprocessingCollection); + } + return this; + } + + /** + * Adds a knownBias to the initial collection + * @parameter knownBias knownBias to add + * @return this for chaining + **/ + DatasetBuilder addknownBias(String knownBias) { + if (Objects.nonNull(knownBias)) { + knownBiass.add(knownBias); + } + return this; + } + + /** + * Adds all elements from a collection to the initial knownBias collection + * @parameter knownBiasCollection collection to initialize the knownBias + * @return this for chaining + **/ + DatasetBuilder addAllknownBias(Collection knownBiasCollection) { + if (Objects.nonNull(knownBiasCollection)) { + knownBiass.addAll(knownBiasCollection); + } + return this; + } + + /** + * Sets the initial value of sensitivePersonalInformation + * @parameter sensitivePersonalInformation value to set + * @return this for chaining + **/ + DatasetBuilder setsensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + this.sensitivePersonalInformation = sensitivePersonalInformation; + return this; + } + + /** + * Sets the initial value of confidentialityLevel + * @parameter confidentialityLevel value to set + * @return this for chaining + **/ + DatasetBuilder setconfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { + this.confidentialityLevel = confidentialityLevel; + return this; + } + + /** + * Sets the initial value of datasetAvailability + * @parameter datasetAvailability value to set + * @return this for chaining + **/ + DatasetBuilder setdatasetAvailability(DatasetAvailabilityType datasetAvailability) { + this.datasetAvailability = datasetAvailability; + return this; + } + + /** + * Sets the initial value of datasetSize + * @parameter datasetSize value to set + * @return this for chaining + **/ + DatasetBuilder setdatasetSize(Integer datasetSize) { + this.datasetSize = datasetSize; + return this; + } + + /** + * Sets the initial value of intendedUse + * @parameter intendedUse value to set + * @return this for chaining + **/ + DatasetBuilder setintendedUse(String intendedUse) { + this.intendedUse = intendedUse; + return this; + } + + /** + * Sets the initial value of datasetNoise + * @parameter datasetNoise value to set + * @return this for chaining + **/ + DatasetBuilder setdatasetNoise(String datasetNoise) { + this.datasetNoise = datasetNoise; + return this; + } + + /** + * Sets the initial value of dataCollectionProcess + * @parameter dataCollectionProcess value to set + * @return this for chaining + **/ + DatasetBuilder setdataCollectionProcess(String dataCollectionProcess) { + this.dataCollectionProcess = dataCollectionProcess; + return this; + } + + /** + * Sets the initial value of datasetUpdateMechanism + * @parameter datasetUpdateMechanism value to set + * @return this for chaining + **/ + DatasetBuilder setdatasetUpdateMechanism(String datasetUpdateMechanism) { + this.datasetUpdateMechanism = datasetUpdateMechanism; + return this; + } + + + /** + * @return the Dataset + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Dataset build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Dataset(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java b/generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java new file mode 100644 index 000000000..d11ea7533 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.dataset; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Describes the possible types of availability of a dataset, indicating whether the + * dataset can be directly downloaded, can be assembled using a script for scraping + * the data, is only available after a clickthrough or a registration form. + */ +public enum DatasetAvailabilityType implements IndividualUriValue { + + SCRAPING___SCRIPT("Scraping-Script"), + DIRECT___DOWNLOAD("Direct-Download"), + QUERY("Query"), + CLICKTHROUGH("Clickthrough"), + REGISTRATION("Registration"); + + private String longName; + + private DatasetAvailabilityType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Dataset/DatasetAvailabilityType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java b/generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java new file mode 100644 index 000000000..6cfbefbf8 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.dataset; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Describes the different structures of data within a given dataset. A dataset can + * have multiple types of data, or even a single type of data but still match multiple + * types, for example sensor data could also be timeseries or labeled image data could + * also be considered categorical. + */ +public enum DatasetType implements IndividualUriValue { + + SYNTACTIC("syntactic"), + GRAPH("graph"), + NUMERIC("numeric"), + TIMESERIES("timeseries"), + NO_ASSERTION("noAssertion"), + IMAGE("image"), + CATEGORICAL("categorical"), + AUDIO("audio"), + SENSOR("sensor"), + OTHER("other"), + TIMESTAMP("timestamp"), + VIDEO("video"), + STRUCTURED("structured"), + TEXT("text"); + + private String longName; + + private DatasetType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Dataset/DatasetType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java new file mode 100644 index 000000000..334686301 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java @@ -0,0 +1,146 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.expandedlicense; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.licensing.AnyLicenseInfo; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A ConjunctiveLicenseSet indicates that _each_ of its subsidiary AnyLicenseInfos + * apply. In other words, a ConjunctiveLicenseSet of two or more licenses represents + * a licensing situation where _all_ of the specified licenses are to be complied with. + * It is represented in the SPDX License Expression Syntax by the `AND` operator. It + * is syntactically correct to specify a ConjunctiveLicenseSet where the subsidiary + * AnyLicenseInfos may be "incompatible" according to a particular interpretation + * of the corresponding Licenses. The SPDX License Expression Syntax does not take + * into account interpretation of license texts, which is left to the consumer of SPDX + * data to determine for themselves. + */ +public class ConjunctiveLicenseSet extends AnyLicenseInfo { + + + /** + * Create the ConjunctiveLicenseSet with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ConjunctiveLicenseSet + */ + public ConjunctiveLicenseSet() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ConjunctiveLicenseSet + * @throws InvalidSPDXAnalysisException when unable to create the ConjunctiveLicenseSet + */ + public ConjunctiveLicenseSet(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ConjunctiveLicenseSet is to be stored + * @param objectUri URI or anonymous ID for the ConjunctiveLicenseSet + * @param copyManager Copy manager for the ConjunctiveLicenseSet - can be null if copying is not required + * @param create true if ConjunctiveLicenseSet is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ConjunctiveLicenseSet + */ + public ConjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the ConjunctiveLicenseSet from the builder - used in the builder class + * @param builder Builder to create the ConjunctiveLicenseSet from + * @throws InvalidSPDXAnalysisException when unable to create the ConjunctiveLicenseSet + */ + protected ConjunctiveLicenseSet(ConjunctiveLicenseSetBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "ExpandedLicense.ConjunctiveLicenseSet"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "ConjunctiveLicenseSet: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class ConjunctiveLicenseSetBuilder extends AnyLicenseInfoBuilder { + + public ConjunctiveLicenseSetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the ConjunctiveLicenseSet + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ConjunctiveLicenseSet build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ConjunctiveLicenseSet(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java new file mode 100644 index 000000000..4890c9328 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.expandedlicense; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.licensing.AnyLicenseInfo; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A DisjunctiveLicenseSet indicates that _only one_ of its subsidiary AnyLicenseInfos + * is required to apply. In other words, a DisjunctiveLicenseSet of two or more licenses + * represents a licensing situation where _only one_ of the specified licenses are + * to be complied with. A consumer of SPDX data would typically understand this to permit + * the recipient of the licensed content to choose which of the corresponding license + * they would prefer to use. It is represented in the SPDX License Expression Syntax + * by the `OR` operator. + */ +public class DisjunctiveLicenseSet extends AnyLicenseInfo { + + + /** + * Create the DisjunctiveLicenseSet with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the DisjunctiveLicenseSet + */ + public DisjunctiveLicenseSet() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the DisjunctiveLicenseSet + * @throws InvalidSPDXAnalysisException when unable to create the DisjunctiveLicenseSet + */ + public DisjunctiveLicenseSet(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the DisjunctiveLicenseSet is to be stored + * @param objectUri URI or anonymous ID for the DisjunctiveLicenseSet + * @param copyManager Copy manager for the DisjunctiveLicenseSet - can be null if copying is not required + * @param create true if DisjunctiveLicenseSet is to be created + * @throws InvalidSPDXAnalysisException when unable to create the DisjunctiveLicenseSet + */ + public DisjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the DisjunctiveLicenseSet from the builder - used in the builder class + * @param builder Builder to create the DisjunctiveLicenseSet from + * @throws InvalidSPDXAnalysisException when unable to create the DisjunctiveLicenseSet + */ + protected DisjunctiveLicenseSet(DisjunctiveLicenseSetBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "ExpandedLicense.DisjunctiveLicenseSet"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "DisjunctiveLicenseSet: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class DisjunctiveLicenseSetBuilder extends AnyLicenseInfoBuilder { + + public DisjunctiveLicenseSetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the DisjunctiveLicenseSet + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public DisjunctiveLicenseSet build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new DisjunctiveLicenseSet(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java new file mode 100644 index 000000000..21e23d005 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.expandedlicense; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.licensing.AnyLicenseInfo; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * The WithAdditionOperator can have a License or an OrLaterOperator as the license + * property value. This class is used for the value. + */ +public class ExtendableLicense extends AnyLicenseInfo { + + + /** + * Create the ExtendableLicense with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ExtendableLicense + */ + public ExtendableLicense() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ExtendableLicense + * @throws InvalidSPDXAnalysisException when unable to create the ExtendableLicense + */ + public ExtendableLicense(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ExtendableLicense is to be stored + * @param objectUri URI or anonymous ID for the ExtendableLicense + * @param copyManager Copy manager for the ExtendableLicense - can be null if copying is not required + * @param create true if ExtendableLicense is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ExtendableLicense + */ + public ExtendableLicense(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the ExtendableLicense from the builder - used in the builder class + * @param builder Builder to create the ExtendableLicense from + * @throws InvalidSPDXAnalysisException when unable to create the ExtendableLicense + */ + protected ExtendableLicense(ExtendableLicenseBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "ExpandedLicense.ExtendableLicense"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "ExtendableLicense: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class ExtendableLicenseBuilder extends AnyLicenseInfoBuilder { + + public ExtendableLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the ExtendableLicense + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ExtendableLicense build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ExtendableLicense(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java b/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java new file mode 100644 index 000000000..ddde9acf8 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java @@ -0,0 +1,142 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An AnyLicenseInfo is used by licensing properties of software artifacts. It can + * be a NoneLicense, a NoAssertionLicense, single license (either on the SPDX License + * List or a custom-defined license); a single license with an "or later" operator applied; + * the foregoing with additional text applied; or a set of licenses combined by applying + * "AND" and "OR" operators recursively. + */ +public class AnyLicenseInfo extends Element { + + + /** + * Create the AnyLicenseInfo with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the AnyLicenseInfo + */ + public AnyLicenseInfo() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the AnyLicenseInfo + * @throws InvalidSPDXAnalysisException when unable to create the AnyLicenseInfo + */ + public AnyLicenseInfo(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the AnyLicenseInfo is to be stored + * @param objectUri URI or anonymous ID for the AnyLicenseInfo + * @param copyManager Copy manager for the AnyLicenseInfo - can be null if copying is not required + * @param create true if AnyLicenseInfo is to be created + * @throws InvalidSPDXAnalysisException when unable to create the AnyLicenseInfo + */ + public AnyLicenseInfo(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the AnyLicenseInfo from the builder - used in the builder class + * @param builder Builder to create the AnyLicenseInfo from + * @throws InvalidSPDXAnalysisException when unable to create the AnyLicenseInfo + */ + protected AnyLicenseInfo(AnyLicenseInfoBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.AnyLicenseInfo"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "AnyLicenseInfo: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class AnyLicenseInfoBuilder extends ElementBuilder { + + public AnyLicenseInfoBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the AnyLicenseInfo + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public AnyLicenseInfo build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new AnyLicenseInfo(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java new file mode 100644 index 000000000..8dda87cc9 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java @@ -0,0 +1,138 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A CustomLicense represents a License that is not listed on the SPDX License List at + * https://spdx.org/licenses, and is therefore defined by an SPDX data creator. + */ +public class CustomLicense extends License { + + + /** + * Create the CustomLicense with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicense + */ + public CustomLicense() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the CustomLicense + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicense + */ + public CustomLicense(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the CustomLicense is to be stored + * @param objectUri URI or anonymous ID for the CustomLicense + * @param copyManager Copy manager for the CustomLicense - can be null if copying is not required + * @param create true if CustomLicense is to be created + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicense + */ + public CustomLicense(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the CustomLicense from the builder - used in the builder class + * @param builder Builder to create the CustomLicense from + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicense + */ + protected CustomLicense(CustomLicenseBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.CustomLicense"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "CustomLicense: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class CustomLicenseBuilder extends LicenseBuilder { + + public CustomLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the CustomLicense + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public CustomLicense build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new CustomLicense(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java new file mode 100644 index 000000000..1769ae018 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java @@ -0,0 +1,141 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A CustomLicenseAddition represents an addition to a License that is not listed on + * the SPDX Exceptions List at https://spdx.org/licenses/exceptions-index.html, + * and is therefore defined by an SPDX data creator. It is intended to represent additional + * language which is meant to be added to a License, but which is not itself a standalone + * License. + */ +public class CustomLicenseAddition extends LicenseAddition { + + + /** + * Create the CustomLicenseAddition with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicenseAddition + */ + public CustomLicenseAddition() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the CustomLicenseAddition + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicenseAddition + */ + public CustomLicenseAddition(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the CustomLicenseAddition is to be stored + * @param objectUri URI or anonymous ID for the CustomLicenseAddition + * @param copyManager Copy manager for the CustomLicenseAddition - can be null if copying is not required + * @param create true if CustomLicenseAddition is to be created + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicenseAddition + */ + public CustomLicenseAddition(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the CustomLicenseAddition from the builder - used in the builder class + * @param builder Builder to create the CustomLicenseAddition from + * @throws InvalidSPDXAnalysisException when unable to create the CustomLicenseAddition + */ + protected CustomLicenseAddition(CustomLicenseAdditionBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.CustomLicenseAddition"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "CustomLicenseAddition: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class CustomLicenseAdditionBuilder extends LicenseAdditionBuilder { + + public CustomLicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the CustomLicenseAddition + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public CustomLicenseAddition build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new CustomLicenseAddition(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/License.java b/generated/src/main/java/org/spdx/library/model/licensing/License.java new file mode 100644 index 000000000..1aba3fac9 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/License.java @@ -0,0 +1,347 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.expandedlicense.ExtendableLicense; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A License represents a license text, whether listed on the SPDX License List (ListedLicense) + * or defined by an SPDX data creator (CustomLicense). + */ +public class License extends ExtendableLicense { + + + /** + * Create the License with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the License + */ + public License() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the License + * @throws InvalidSPDXAnalysisException when unable to create the License + */ + public License(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the License is to be stored + * @param objectUri URI or anonymous ID for the License + * @param copyManager Copy manager for the License - can be null if copying is not required + * @param create true if License is to be created + * @throws InvalidSPDXAnalysisException when unable to create the License + */ + public License(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the License from the builder - used in the builder class + * @param builder Builder to create the License from + * @throws InvalidSPDXAnalysisException when unable to create the License + */ + protected License(LicenseBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setIsFsfLibre(builder.isFsfLibre); + setIsDeprecatedLicenseId(builder.isDeprecatedLicenseId); + setIsOsiApproved(builder.isOsiApproved); + setStandardLicenseTemplate(builder.standardLicenseTemplate); + setStandardLicenseHeader(builder.standardLicenseHeader); + setLicenseText(builder.licenseText); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.License"; + } + + // Getters and Setters + + + /** + * @return the isFsfLibre + */ + public Optional getIsFsfLibre() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_FSF_LIBRE); + } + + /** + * @param isFsfLibre the isFsfLibre to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setIsFsfLibre(@Nullable Boolean isFsfLibre) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_IS_FSF_LIBRE, isFsfLibre); + return this; + } + + /** + * @return the isDeprecatedLicenseId + */ + public Optional getIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID); + } + + /** + * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setIsDeprecatedLicenseId(@Nullable Boolean isDeprecatedLicenseId) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID, isDeprecatedLicenseId); + return this; + } + + /** + * @return the isOsiApproved + */ + public Optional getIsOsiApproved() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED); + } + + /** + * @param isOsiApproved the isOsiApproved to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setIsOsiApproved(@Nullable Boolean isOsiApproved) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED, isOsiApproved); + return this; + } + + /** + * @return the standardLicenseTemplate + */ + public Optional getStandardLicenseTemplate() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_TEMPLATE); + } + /** + * @param standardLicenseTemplate the standardLicenseTemplate to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setStandardLicenseTemplate(@Nullable String standardLicenseTemplate) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_TEMPLATE, standardLicenseTemplate); + return this; + } + + /** + * @return the standardLicenseHeader + */ + public Optional getStandardLicenseHeader() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_HEADER); + } + /** + * @param standardLicenseHeader the standardLicenseHeader to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setStandardLicenseHeader(@Nullable String standardLicenseHeader) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_HEADER, standardLicenseHeader); + return this; + } + + /** + * @return the licenseText + */ + public @Nullable String getLicenseText() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_TEXT); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param licenseText the licenseText to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setLicenseText(@Nullable String licenseText) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(licenseText)) { + throw new InvalidSPDXAnalysisException("licenseText is a required property"); + } + setPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_TEXT, licenseText); + return this; + } + + + @Override + public String toString() { + return "License: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional isFsfLibre = getIsFsfLibre(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting isFsfLibre for License: "+e.getMessage()); + } + try { + Optional isDeprecatedLicenseId = getIsDeprecatedLicenseId(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting isDeprecatedLicenseId for License: "+e.getMessage()); + } + try { + Optional isOsiApproved = getIsOsiApproved(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting isOsiApproved for License: "+e.getMessage()); + } + try { + Optional standardLicenseTemplate = getStandardLicenseTemplate(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting standardLicenseTemplate for License: "+e.getMessage()); + } + try { + Optional standardLicenseHeader = getStandardLicenseHeader(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting standardLicenseHeader for License: "+e.getMessage()); + } + try { + String licenseText = getLicenseText(); + if (Objects.isNull(licenseText)) { + retval.add("Missing licenseText in License"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting licenseText for License: "+e.getMessage()); + } + return retval; + } + + public static class LicenseBuilder extends ExtendableLicenseBuilder { + + public LicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Boolean isFsfLibre = null; + Boolean isDeprecatedLicenseId = null; + Boolean isOsiApproved = null; + String standardLicenseTemplate = null; + String standardLicenseHeader = null; + String licenseText = null; + + + /** + * Sets the initial value of isFsfLibre + * @parameter isFsfLibre value to set + * @return this for chaining + **/ + LicenseBuilder setisFsfLibre(Boolean isFsfLibre) { + this.isFsfLibre = isFsfLibre; + return this; + } + + /** + * Sets the initial value of isDeprecatedLicenseId + * @parameter isDeprecatedLicenseId value to set + * @return this for chaining + **/ + LicenseBuilder setisDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { + this.isDeprecatedLicenseId = isDeprecatedLicenseId; + return this; + } + + /** + * Sets the initial value of isOsiApproved + * @parameter isOsiApproved value to set + * @return this for chaining + **/ + LicenseBuilder setisOsiApproved(Boolean isOsiApproved) { + this.isOsiApproved = isOsiApproved; + return this; + } + + /** + * Sets the initial value of standardLicenseTemplate + * @parameter standardLicenseTemplate value to set + * @return this for chaining + **/ + LicenseBuilder setstandardLicenseTemplate(String standardLicenseTemplate) { + this.standardLicenseTemplate = standardLicenseTemplate; + return this; + } + + /** + * Sets the initial value of standardLicenseHeader + * @parameter standardLicenseHeader value to set + * @return this for chaining + **/ + LicenseBuilder setstandardLicenseHeader(String standardLicenseHeader) { + this.standardLicenseHeader = standardLicenseHeader; + return this; + } + + /** + * Sets the initial value of licenseText + * @parameter licenseText value to set + * @return this for chaining + **/ + LicenseBuilder setlicenseText(String licenseText) { + this.licenseText = licenseText; + return this; + } + + + /** + * @return the License + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public License build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new License(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java new file mode 100644 index 000000000..1f7a8f9a6 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A LicenseAddition represents text which is intended to be added to a License as additional + * text, but which is not itself intended to be a standalone License. It may be an exception + * which is listed on the SPDX Exceptions List (ListedLicenseException), or may be + * any other additional text (as an exception or otherwise) which is defined by an SPDX + * data creator (CustomLicenseAddition). + */ +public class LicenseAddition extends Element { + + + /** + * Create the LicenseAddition with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the LicenseAddition + */ + public LicenseAddition() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the LicenseAddition + * @throws InvalidSPDXAnalysisException when unable to create the LicenseAddition + */ + public LicenseAddition(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the LicenseAddition is to be stored + * @param objectUri URI or anonymous ID for the LicenseAddition + * @param copyManager Copy manager for the LicenseAddition - can be null if copying is not required + * @param create true if LicenseAddition is to be created + * @throws InvalidSPDXAnalysisException when unable to create the LicenseAddition + */ + public LicenseAddition(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the LicenseAddition from the builder - used in the builder class + * @param builder Builder to create the LicenseAddition from + * @throws InvalidSPDXAnalysisException when unable to create the LicenseAddition + */ + protected LicenseAddition(LicenseAdditionBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setIsDeprecatedAdditionId(builder.isDeprecatedAdditionId); + setStandardAdditionTemplate(builder.standardAdditionTemplate); + setAdditionText(builder.additionText); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.LicenseAddition"; + } + + // Getters and Setters + + + /** + * @return the isDeprecatedAdditionId + */ + public Optional getIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_ADDITION_ID); + } + + /** + * @param isDeprecatedAdditionId the isDeprecatedAdditionId to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseAddition setIsDeprecatedAdditionId(@Nullable Boolean isDeprecatedAdditionId) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_ADDITION_ID, isDeprecatedAdditionId); + return this; + } + + /** + * @return the standardAdditionTemplate + */ + public Optional getStandardAdditionTemplate() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_ADDITION_TEMPLATE); + } + /** + * @param standardAdditionTemplate the standardAdditionTemplate to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseAddition setStandardAdditionTemplate(@Nullable String standardAdditionTemplate) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_ADDITION_TEMPLATE, standardAdditionTemplate); + return this; + } + + /** + * @return the additionText + */ + public @Nullable String getAdditionText() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.LICENSING_PROP_ADDITION_TEXT); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param additionText the additionText to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseAddition setAdditionText(@Nullable String additionText) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(additionText)) { + throw new InvalidSPDXAnalysisException("additionText is a required property"); + } + setPropertyValue(SpdxConstants.LICENSING_PROP_ADDITION_TEXT, additionText); + return this; + } + + + @Override + public String toString() { + return "LicenseAddition: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional isDeprecatedAdditionId = getIsDeprecatedAdditionId(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting isDeprecatedAdditionId for LicenseAddition: "+e.getMessage()); + } + try { + Optional standardAdditionTemplate = getStandardAdditionTemplate(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting standardAdditionTemplate for LicenseAddition: "+e.getMessage()); + } + try { + String additionText = getAdditionText(); + if (Objects.isNull(additionText)) { + retval.add("Missing additionText in LicenseAddition"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting additionText for LicenseAddition: "+e.getMessage()); + } + return retval; + } + + public static class LicenseAdditionBuilder extends ElementBuilder { + + public LicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Boolean isDeprecatedAdditionId = null; + String standardAdditionTemplate = null; + String additionText = null; + + + /** + * Sets the initial value of isDeprecatedAdditionId + * @parameter isDeprecatedAdditionId value to set + * @return this for chaining + **/ + LicenseAdditionBuilder setisDeprecatedAdditionId(Boolean isDeprecatedAdditionId) { + this.isDeprecatedAdditionId = isDeprecatedAdditionId; + return this; + } + + /** + * Sets the initial value of standardAdditionTemplate + * @parameter standardAdditionTemplate value to set + * @return this for chaining + **/ + LicenseAdditionBuilder setstandardAdditionTemplate(String standardAdditionTemplate) { + this.standardAdditionTemplate = standardAdditionTemplate; + return this; + } + + /** + * Sets the initial value of additionText + * @parameter additionText value to set + * @return this for chaining + **/ + LicenseAdditionBuilder setadditionText(String additionText) { + this.additionText = additionText; + return this; + } + + + /** + * @return the LicenseAddition + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public LicenseAddition build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new LicenseAddition(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java new file mode 100644 index 000000000..831e37121 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java @@ -0,0 +1,191 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Often a single license can be used to represent the licensing terms of a source code + * or binary file, but there are situations where a single license identifier is not + * sufficient. A common example is when software is offered under a choice of one or more + * licenses (e.g., GPL-2.0-only OR BSD-3-Clause). Another example is when a set of + * licenses is needed to represent a binary program constructed by compiling and linking + * two (or more) different source files each governed by different licenses (e.g., + * LGPL-2.1-only AND BSD-3-Clause). SPDX License Expressions provide a way for one + * to construct expressions that more accurately represent the licensing terms typically + * found in open source software source code. A license expression could be a single + * license identifier found on the SPDX License List; a user defined license reference + * denoted by the LicenseRef-idString; a license identifier combined with an SPDX + * exception; or some combination of license identifiers, license references and + * exceptions constructed using a small set of defined operators (e.g., AND, OR, WITH + * and +). We provide the definition of what constitutes a valid an SPDX License Expression + * in this section. + */ +public class LicenseExpression extends AnyLicenseInfo { + + + /** + * Create the LicenseExpression with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression + */ + public LicenseExpression() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the LicenseExpression + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression + */ + public LicenseExpression(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the LicenseExpression is to be stored + * @param objectUri URI or anonymous ID for the LicenseExpression + * @param copyManager Copy manager for the LicenseExpression - can be null if copying is not required + * @param create true if LicenseExpression is to be created + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression + */ + public LicenseExpression(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the LicenseExpression from the builder - used in the builder class + * @param builder Builder to create the LicenseExpression from + * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression + */ + protected LicenseExpression(LicenseExpressionBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setLicenseExpression(builder.licenseExpression); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.LicenseExpression"; + } + + // Getters and Setters + + + /** + * @return the licenseExpression + */ + public @Nullable String getLicenseExpression() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_EXPRESSION); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param licenseExpression the licenseExpression to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseExpression setLicenseExpression(@Nullable String licenseExpression) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(licenseExpression)) { + throw new InvalidSPDXAnalysisException("licenseExpression is a required property"); + } + setPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_EXPRESSION, licenseExpression); + return this; + } + + + @Override + public String toString() { + return "LicenseExpression: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + String licenseExpression = getLicenseExpression(); + if (Objects.isNull(licenseExpression)) { + retval.add("Missing licenseExpression in LicenseExpression"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting licenseExpression for LicenseExpression: "+e.getMessage()); + } + return retval; + } + + public static class LicenseExpressionBuilder extends AnyLicenseInfoBuilder { + + public LicenseExpressionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String licenseExpression = null; + + + /** + * Sets the initial value of licenseExpression + * @parameter licenseExpression value to set + * @return this for chaining + **/ + LicenseExpressionBuilder setlicenseExpression(String licenseExpression) { + this.licenseExpression = licenseExpression; + return this; + } + + + /** + * @return the LicenseExpression + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public LicenseExpression build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new LicenseExpression(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java new file mode 100644 index 000000000..9d5fdf46b --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A ListedLicense represents a License that is listed on the SPDX License List at https://spdx.org/licenses. + */ +public class ListedLicense extends License { + + + /** + * Create the ListedLicense with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicense + */ + public ListedLicense() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ListedLicense + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicense + */ + public ListedLicense(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ListedLicense is to be stored + * @param objectUri URI or anonymous ID for the ListedLicense + * @param copyManager Copy manager for the ListedLicense - can be null if copying is not required + * @param create true if ListedLicense is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicense + */ + public ListedLicense(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the ListedLicense from the builder - used in the builder class + * @param builder Builder to create the ListedLicense from + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicense + */ + protected ListedLicense(ListedLicenseBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.ListedLicense"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "ListedLicense: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class ListedLicenseBuilder extends LicenseBuilder { + + public ListedLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the ListedLicense + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ListedLicense build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ListedLicense(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java new file mode 100644 index 000000000..9e17eab27 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A ListedLicenseException represents an exception to a License (in other words, + * an exception to a license condition or an additional permission beyond those granted + * in a License) which is listed on the SPDX Exceptions List at https://spdx.org/licenses/exceptions-index.html. + */ +public class ListedLicenseException extends LicenseAddition { + + + /** + * Create the ListedLicenseException with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicenseException + */ + public ListedLicenseException() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ListedLicenseException + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicenseException + */ + public ListedLicenseException(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ListedLicenseException is to be stored + * @param objectUri URI or anonymous ID for the ListedLicenseException + * @param copyManager Copy manager for the ListedLicenseException - can be null if copying is not required + * @param create true if ListedLicenseException is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicenseException + */ + public ListedLicenseException(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the ListedLicenseException from the builder - used in the builder class + * @param builder Builder to create the ListedLicenseException from + * @throws InvalidSPDXAnalysisException when unable to create the ListedLicenseException + */ + protected ListedLicenseException(ListedLicenseExceptionBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.ListedLicenseException"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "ListedLicenseException: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class ListedLicenseExceptionBuilder extends LicenseAdditionBuilder { + + public ListedLicenseExceptionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the ListedLicenseException + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ListedLicenseException build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ListedLicenseException(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java b/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java new file mode 100644 index 000000000..8345d074f --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.expandedlicense.ExtendableLicense; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An OrLaterOperator indicates that this portion of the AnyLicenseInfo represents + * either (1) the specified version of the corresponding License, or (2) any later version + * of that License. It is represented in the SPDX License Expression Syntax by the `+` + * operator. It is context-dependent, and unspecified by SPDX, as to what constitutes + * a "later version" of any particular License. Some Licenses may not be versioned, + * or may not have clearly-defined ordering for versions. The consumer of SPDX data + * will need to determine for themselves what meaning to attribute to a "later version" + * operator for a particular License. + */ +public class OrLaterOperator extends ExtendableLicense { + + + /** + * Create the OrLaterOperator with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the OrLaterOperator + */ + public OrLaterOperator() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the OrLaterOperator + * @throws InvalidSPDXAnalysisException when unable to create the OrLaterOperator + */ + public OrLaterOperator(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the OrLaterOperator is to be stored + * @param objectUri URI or anonymous ID for the OrLaterOperator + * @param copyManager Copy manager for the OrLaterOperator - can be null if copying is not required + * @param create true if OrLaterOperator is to be created + * @throws InvalidSPDXAnalysisException when unable to create the OrLaterOperator + */ + public OrLaterOperator(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the OrLaterOperator from the builder - used in the builder class + * @param builder Builder to create the OrLaterOperator from + * @throws InvalidSPDXAnalysisException when unable to create the OrLaterOperator + */ + protected OrLaterOperator(OrLaterOperatorBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.OrLaterOperator"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "OrLaterOperator: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class OrLaterOperatorBuilder extends ExtendableLicenseBuilder { + + public OrLaterOperatorBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the OrLaterOperator + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public OrLaterOperator build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new OrLaterOperator(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java b/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java new file mode 100644 index 000000000..09981e40c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java @@ -0,0 +1,140 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A WithAdditionOperator indicates that the designated License is subject to the + * designated LicenseAddition, which might be a license exception on the SPDX Exceptions + * List (ListedLicenseException) or may be other additional text (CustomLicenseAddition). + * It is represented in the SPDX License Expression Syntax by the `WITH` operator. + */ +public class WithAdditionOperator extends AnyLicenseInfo { + + + /** + * Create the WithAdditionOperator with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the WithAdditionOperator + */ + public WithAdditionOperator() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the WithAdditionOperator + * @throws InvalidSPDXAnalysisException when unable to create the WithAdditionOperator + */ + public WithAdditionOperator(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the WithAdditionOperator is to be stored + * @param objectUri URI or anonymous ID for the WithAdditionOperator + * @param copyManager Copy manager for the WithAdditionOperator - can be null if copying is not required + * @param create true if WithAdditionOperator is to be created + * @throws InvalidSPDXAnalysisException when unable to create the WithAdditionOperator + */ + public WithAdditionOperator(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the WithAdditionOperator from the builder - used in the builder class + * @param builder Builder to create the WithAdditionOperator from + * @throws InvalidSPDXAnalysisException when unable to create the WithAdditionOperator + */ + protected WithAdditionOperator(WithAdditionOperatorBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Licensing.WithAdditionOperator"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "WithAdditionOperator: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class WithAdditionOperatorBuilder extends AnyLicenseInfoBuilder { + + public WithAdditionOperatorBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the WithAdditionOperator + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public WithAdditionOperator build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new WithAdditionOperator(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java new file mode 100644 index 000000000..084807b5e --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java @@ -0,0 +1,155 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A CvssV2VulnAssessmentRelationship relationship describes the determined score + * and vector of a vulnerability using version 2.0 of the Common Vulnerability Scoring + * System (CVSS) as defined on [https://www.first.org/cvss/v2/guide](https://www.first.org/cvss/v2/guide). + * It is intented to communicate the results of using a CVSS calculator. **Constraints** + * - The value of severity must be one of 'low', 'medium' or 'high' - The relationship + * type must be set to hasAssessmentFor. **Syntax** ```json { "@type": "CvssV2VulnAssessmentRelationship", + * "@id": "urn:spdx.dev:cvssv2-cve-2020-28498", "relationshipType": "hasAssessmentFor", + * "score": 4.3, "vector": "(AV:N/AC:M/Au:N/C:P/I:N/A:N)", "severity": "low", + * "from": "urn:spdx.dev:vuln-cve-2020-28498", "to": ["urn:product-acme-application-1.3"], + * "assessedElement": "urn:npm-elliptic-6.5.2", "externalReferences": [ { "@type": + * "ExternalReference", "externalReferenceType": "securityAdvisory", "locator": + * "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" }, { "@type": "ExternalReference", + * "externalReferenceType": "securityAdvisory", "locator": "https://snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" + * }, { "@type": "ExternalReference", "externalReferenceType": "securityFix", + * "locator": "https://github.com/indutny/elliptic/commit/441b742" } ], "suppliedBy": + * ["urn:spdx.dev:agent-my-security-vendor"], "publishedTime": "2023-05-06T10:06:13Z" + * }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", "relationshipType": + * "publishedBy", "from": "urn:spdx.dev:cvssv2-cve-2020-28498", "to": ["urn:spdx.dev:agent-snyk"], + * "startTime": "2021-03-08T16:06:50Z" } ``` + */ +public class CvssV2VulnAssessmentRelationship extends VulnAssessmentRelationship { + + + /** + * Create the CvssV2VulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the CvssV2VulnAssessmentRelationship + */ + public CvssV2VulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the CvssV2VulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the CvssV2VulnAssessmentRelationship + */ + public CvssV2VulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the CvssV2VulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the CvssV2VulnAssessmentRelationship + * @param copyManager Copy manager for the CvssV2VulnAssessmentRelationship - can be null if copying is not required + * @param create true if CvssV2VulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the CvssV2VulnAssessmentRelationship + */ + public CvssV2VulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the CvssV2VulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the CvssV2VulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the CvssV2VulnAssessmentRelationship + */ + protected CvssV2VulnAssessmentRelationship(CvssV2VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.CvssV2VulnAssessmentRelationship"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "CvssV2VulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class CvssV2VulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + + public CvssV2VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the CvssV2VulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public CvssV2VulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new CvssV2VulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java new file mode 100644 index 000000000..e1a2d75f9 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A CvssV3VulnAssessmentRelationship relationship describes the determined score, + * severity, and vector of a vulnerability using version 3.1 of the Common Vulnerability + * Scoring System (CVSS) as defined on [https://www.first.org/cvss/v3.1/specification-document](https://www.first.org/cvss/v3.1/specification-document). + * It is intented to communicate the results of using a CVSS calculator. **Constraints** + * - The value of severity must be one of 'none', 'low', 'medium', 'high' or 'critical'. + * - Absence of the property shall be interpreted as 'none'. - The relationship type + * must be set to hasAssessmentFor. **Syntax** ```json { "@type": "CvssV3VulnAssessmentRelationship", + * "@id": "urn:spdx.dev:cvssv3-cve-2020-28498", "relationshipType": "hasAssessmentFor", + * "severity": "medium", "score": 6.8, "vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:N/A:N", + * "from": "urn:spdx.dev:vuln-cve-2020-28498", "to": ["urn:product-acme-application-1.3"], + * "assessedElement": "urn:npm-elliptic-6.5.2", "externalReferences": [ { "@type": + * "ExternalReference", "externalReferenceType": "securityAdvisory", "locator": + * "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" }, { "@type": "ExternalReference", + * "externalReferenceType": "securityAdvisory", "locator": "https://snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" + * }, { "@type": "ExternalReference", "externalReferenceType": "securityFix", + * "locator": "https://github.com/indutny/elliptic/commit/441b742" } ], "suppliedBy": + * ["urn:spdx.dev:agent-my-security-vendor"], "publishedTime": "2023-05-06T10:06:13Z" + * }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", "relationshipType": + * "publishedBy", "from": "urn:spdx.dev:cvssv3-cve-2020-28498", "to": "urn:spdx.dev:agent-snyk", + * "startTime": "2021-03-08T16:06:50Z" } ``` + */ +public class CvssV3VulnAssessmentRelationship extends VulnAssessmentRelationship { + + + /** + * Create the CvssV3VulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the CvssV3VulnAssessmentRelationship + */ + public CvssV3VulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the CvssV3VulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the CvssV3VulnAssessmentRelationship + */ + public CvssV3VulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the CvssV3VulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the CvssV3VulnAssessmentRelationship + * @param copyManager Copy manager for the CvssV3VulnAssessmentRelationship - can be null if copying is not required + * @param create true if CvssV3VulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the CvssV3VulnAssessmentRelationship + */ + public CvssV3VulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the CvssV3VulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the CvssV3VulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the CvssV3VulnAssessmentRelationship + */ + protected CvssV3VulnAssessmentRelationship(CvssV3VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.CvssV3VulnAssessmentRelationship"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "CvssV3VulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class CvssV3VulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + + public CvssV3VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the CvssV3VulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public CvssV3VulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new CvssV3VulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java new file mode 100644 index 000000000..1959b6538 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An EpssVulnAssessmentRelationship relationship describes the likelihood or + * probability that a vulnerability will be exploited in the wild using the Exploit + * Prediction Scoring System (EPSS) as defined on [https://www.first.org/epss/model](https://www.first.org/epss/model). + * **Constraints** - The relationship type must be set to hasAssessmentFor. **Syntax** + * ```json { "@type": "EpssVulnAssessmentRelationship", "@id": "urn:spdx.dev:epss-1", + * "relationshipType": "hasAssessmentFor", "probability": 80, "from": "urn:spdx.dev:vuln-cve-2020-28498", + * "to": ["urn:product-acme-application-1.3"], "suppliedBy": ["urn:spdx.dev:agent-jane-doe"], + * "publishedTime": "2021-03-09T11:04:53Z" } ``` + */ +public class EpssVulnAssessmentRelationship extends VulnAssessmentRelationship { + + + /** + * Create the EpssVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the EpssVulnAssessmentRelationship + */ + public EpssVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the EpssVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the EpssVulnAssessmentRelationship + */ + public EpssVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the EpssVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the EpssVulnAssessmentRelationship + * @param copyManager Copy manager for the EpssVulnAssessmentRelationship - can be null if copying is not required + * @param create true if EpssVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the EpssVulnAssessmentRelationship + */ + public EpssVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the EpssVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the EpssVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the EpssVulnAssessmentRelationship + */ + protected EpssVulnAssessmentRelationship(EpssVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setProbability(builder.probability); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.EpssVulnAssessmentRelationship"; + } + + // Getters and Setters + + + /** + * @return the probability + */ + public @Nullable Integer getProbability() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.SECURITY_PROP_PROBABILITY); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param probability the probability to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public EpssVulnAssessmentRelationship setProbability(@Nullable Integer probability) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(probability)) { + throw new InvalidSPDXAnalysisException("probability is a required property"); + } + if (isStrict() && Objects.nonNull(probability) && probability < 1) { + throw new InvalidSPDXAnalysisException("probability value " + probability + " is less than the minimum 1 in EpssVulnAssessmentRelationship"); + } + if (isStrict() && Objects.nonNull(probability) && probability > 1) { + throw new InvalidSPDXAnalysisException("probability value " + probability + " is greater than the maximum 1 in EpssVulnAssessmentRelationship"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_PROBABILITY, probability); + return this; + } + + + @Override + public String toString() { + return "EpssVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Integer probability = getProbability(); + if (Objects.isNull(probability)) { + retval.add("Missing probability in EpssVulnAssessmentRelationship"); + } + if (Objects.nonNull(probability) && probability < 1) { + retval.add("probability value " + probability + " is less than the minimum 1 in EpssVulnAssessmentRelationship"); + } + if (Objects.nonNull(probability) && probability > 1) { + retval.add("probability value " + probability + " is greater than the maximum 1 in EpssVulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting probability for EpssVulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class EpssVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + + public EpssVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Integer probability = null; + + + /** + * Sets the initial value of probability + * @parameter probability value to set + * @return this for chaining + **/ + EpssVulnAssessmentRelationshipBuilder setprobability(Integer probability) { + this.probability = probability; + return this; + } + + + /** + * @return the EpssVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public EpssVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new EpssVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java new file mode 100644 index 000000000..2d1b88f89 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * ExploitCatalogType specifies the type of exploit catalog that a vulnerability + * is listed in. + */ +public enum ExploitCatalogType implements IndividualUriValue { + + KEV("kev"), + OTHER("other"); + + private String longName; + + private ExploitCatalogType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Security/ExploitCatalogType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java new file mode 100644 index 000000000..1a921b7ce --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java @@ -0,0 +1,275 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An ExploitCatalogVulnAssessmentRelationship describes if a vulnerability is + * listed in any exploit catalog such as the CISA Known Exploited Vulnerabilities Catalog + * (KEV) [https://www.cisa.gov/known-exploited-vulnerabilities-catalog](https://www.cisa.gov/known-exploited-vulnerabilities-catalog). + * **Constraints** - The relationship type must be set to hasAssessmentFor. **Syntax** + * ```json { "@type": "ExploitCatalogVulnAssessmentRelationship", "@id": "urn:spdx.dev:exploit-catalog-1", + * "relationshipType": "hasAssessmentFor", "catalogType": "kev", "locator": + * "https://www.cisa.gov/known-exploited-vulnerabilities-catalog", "exploited": + * "true", "from": "urn:spdx.dev:vuln-cve-2023-2136", "to": ["urn:product-google-chrome-112.0.5615.136"], + * "suppliedBy": ["urn:spdx.dev:agent-jane-doe"], "publishedTime": "2021-03-09T11:04:53Z" + * } ``` + */ +public class ExploitCatalogVulnAssessmentRelationship extends VulnAssessmentRelationship { + + + /** + * Create the ExploitCatalogVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ExploitCatalogVulnAssessmentRelationship + */ + public ExploitCatalogVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the ExploitCatalogVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the ExploitCatalogVulnAssessmentRelationship + */ + public ExploitCatalogVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the ExploitCatalogVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the ExploitCatalogVulnAssessmentRelationship + * @param copyManager Copy manager for the ExploitCatalogVulnAssessmentRelationship - can be null if copying is not required + * @param create true if ExploitCatalogVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ExploitCatalogVulnAssessmentRelationship + */ + public ExploitCatalogVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the ExploitCatalogVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the ExploitCatalogVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the ExploitCatalogVulnAssessmentRelationship + */ + protected ExploitCatalogVulnAssessmentRelationship(ExploitCatalogVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setCatalogType(builder.catalogType); + setExploited(builder.exploited); + setLocator(builder.locator); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.ExploitCatalogVulnAssessmentRelationship"; + } + + // Getters and Setters + + + /** + * @return the catalogType + */ + @SuppressWarnings("unchecked") + public @Nullable ExploitCatalogType getCatalogType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.SECURITY_PROP_CATALOG_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof ExploitCatalogType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (ExploitCatalogType)(retval.get()); + } else { + return null; + } + } + /** + * @param catalogType the catalogType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExploitCatalogVulnAssessmentRelationship setCatalogType(@Nullable ExploitCatalogType catalogType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(catalogType)) { + throw new InvalidSPDXAnalysisException("catalogType is a required property"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_CATALOG_TYPE, catalogType); + return this; + } + + /** + * @return the exploited + */ + public @Nullable Boolean getExploited() throws InvalidSPDXAnalysisException { + Optional retval = getBooleanPropertyValue(SpdxConstants.SECURITY_PROP_EXPLOITED); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param exploited the exploited to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExploitCatalogVulnAssessmentRelationship setExploited(@Nullable Boolean exploited) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(exploited)) { + throw new InvalidSPDXAnalysisException("exploited is a required property"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_EXPLOITED, exploited); + return this; + } + + /** + * @return the locator + */ + public @Nullable String getLocator() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.SECURITY_PROP_LOCATOR); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param locator the locator to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExploitCatalogVulnAssessmentRelationship setLocator(@Nullable String locator) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(locator)) { + throw new InvalidSPDXAnalysisException("locator is a required property"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_LOCATOR, locator); + return this; + } + + + @Override + public String toString() { + return "ExploitCatalogVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + ExploitCatalogType catalogType = getCatalogType(); + if (Objects.isNull(catalogType)) { + retval.add("Missing catalogType in ExploitCatalogVulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting catalogType for ExploitCatalogVulnAssessmentRelationship: "+e.getMessage()); + } + try { + Boolean exploited = getExploited(); + if (Objects.isNull(exploited)) { + retval.add("Missing exploited in ExploitCatalogVulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting exploited for ExploitCatalogVulnAssessmentRelationship: "+e.getMessage()); + } + try { + String locator = getLocator(); + if (Objects.isNull(locator)) { + retval.add("Missing locator in ExploitCatalogVulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting locator for ExploitCatalogVulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class ExploitCatalogVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + + public ExploitCatalogVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + ExploitCatalogType catalogType = null; + Boolean exploited = null; + String locator = null; + + + /** + * Sets the initial value of catalogType + * @parameter catalogType value to set + * @return this for chaining + **/ + ExploitCatalogVulnAssessmentRelationshipBuilder setcatalogType(ExploitCatalogType catalogType) { + this.catalogType = catalogType; + return this; + } + + /** + * Sets the initial value of exploited + * @parameter exploited value to set + * @return this for chaining + **/ + ExploitCatalogVulnAssessmentRelationshipBuilder setexploited(Boolean exploited) { + this.exploited = exploited; + return this; + } + + /** + * Sets the initial value of locator + * @parameter locator value to set + * @return this for chaining + **/ + ExploitCatalogVulnAssessmentRelationshipBuilder setlocator(String locator) { + this.locator = locator; + return this; + } + + + /** + * @return the ExploitCatalogVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public ExploitCatalogVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new ExploitCatalogVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java b/generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java new file mode 100644 index 000000000..a36975c0c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * SsvcDecisionType specifies the type of decision that's been made according to the + * Stakeholder-Specific Vulnerability Categorization (SSVC) system [https://www.cisa.gov/stakeholder-specific-vulnerability-categorization-ssvc](https://www.cisa.gov/stakeholder-specific-vulnerability-categorization-ssvc) + */ +public enum SsvcDecisionType implements IndividualUriValue { + + ACT("act"), + TRACK_STAR("trackStar"), + ATTEND("attend"), + TRACK("track"); + + private String longName; + + private SsvcDecisionType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Security/SsvcDecisionType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java new file mode 100644 index 000000000..d06e99ee5 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java @@ -0,0 +1,193 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * An SsvcVulnAssessmentRelationship describes the decision made using the Stakeholder-Specific + * Vulnerability Categorization (SSVC) decision tree as defined on [https://www.cisa.gov/stakeholder-specific-vulnerability-categorization-ssvc](https://www.cisa.gov/stakeholder-specific-vulnerability-categorization-ssvc). + * It is intended to communicate the results of using the CISA SSVC Calculator. **Constraints** + * - The relationship type must be set to hasAssessmentFor. **Syntax** ```json { "@type": + * "SsvcVulnAssessmentRelationship", "@id": "urn:spdx.dev:ssvc-1", "relationshipType": + * "hasAssessmentFor", "decisionType": "act", "from": "urn:spdx.dev:vuln-cve-2020-28498", + * "to": ["urn:product-acme-application-1.3"], "assessedElement": "urn:npm-elliptic-6.5.2", + * "suppliedBy": ["urn:spdx.dev:agent-jane-doe"], "publishedTime": "2021-03-09T11:04:53Z" + * } ``` + */ +public class SsvcVulnAssessmentRelationship extends VulnAssessmentRelationship { + + + /** + * Create the SsvcVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SsvcVulnAssessmentRelationship + */ + public SsvcVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SsvcVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the SsvcVulnAssessmentRelationship + */ + public SsvcVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SsvcVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the SsvcVulnAssessmentRelationship + * @param copyManager Copy manager for the SsvcVulnAssessmentRelationship - can be null if copying is not required + * @param create true if SsvcVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SsvcVulnAssessmentRelationship + */ + public SsvcVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SsvcVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the SsvcVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the SsvcVulnAssessmentRelationship + */ + protected SsvcVulnAssessmentRelationship(SsvcVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setDecisionType(builder.decisionType); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.SsvcVulnAssessmentRelationship"; + } + + // Getters and Setters + + + /** + * @return the decisionType + */ + @SuppressWarnings("unchecked") + public @Nullable SsvcDecisionType getDecisionType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.SECURITY_PROP_DECISION_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof SsvcDecisionType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (SsvcDecisionType)(retval.get()); + } else { + return null; + } + } + /** + * @param decisionType the decisionType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SsvcVulnAssessmentRelationship setDecisionType(@Nullable SsvcDecisionType decisionType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(decisionType)) { + throw new InvalidSPDXAnalysisException("decisionType is a required property"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_DECISION_TYPE, decisionType); + return this; + } + + + @Override + public String toString() { + return "SsvcVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + SsvcDecisionType decisionType = getDecisionType(); + if (Objects.isNull(decisionType)) { + retval.add("Missing decisionType in SsvcVulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting decisionType for SsvcVulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class SsvcVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + + public SsvcVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + SsvcDecisionType decisionType = null; + + + /** + * Sets the initial value of decisionType + * @parameter decisionType value to set + * @return this for chaining + **/ + SsvcVulnAssessmentRelationshipBuilder setdecisionType(SsvcDecisionType decisionType) { + this.decisionType = decisionType; + return this; + } + + + /** + * @return the SsvcVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SsvcVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SsvcVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java new file mode 100644 index 000000000..c77e8770c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java @@ -0,0 +1,215 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VexAffectedVulnAssessmentRelationship connects a vulnerability and a number + * of elements. The relationship marks these elements as products affected by the vulnerability. + * This relationship corresponds to the VEX affected status. **Constraints** When + * linking elements using a VexAffectedVulnAssessmentRelationship, the following + * requirements must be observed: - Elements linked with a VulnVexAffectedAssessmentRelationship + * are constrained to the affects relationship type. **Syntax** ```json { "@type": + * "VexAffectedVulnAssessmentRelationship", "@id": "urn:spdx.dev:vex-affected-1", + * "relationshipType": "affects", "from": "urn:spdx.dev:vuln-cve-2020-28498", + * "to": ["urn:product-acme-application-1.3"], "assessedElement": "urn:npm-elliptic-6.5.2", + * "actionStatement": "Upgrade to version 1.4 of ACME application.", "suppliedBy": + * ["urn:spdx.dev:agent-jane-doe"], "publishedTime": "2021-03-09T11:04:53Z" + * } ``` + */ +public class VexAffectedVulnAssessmentRelationship extends VexVulnAssessmentRelationship { + + Collection actionStatementTimes; + + /** + * Create the VexAffectedVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the VexAffectedVulnAssessmentRelationship + */ + public VexAffectedVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the VexAffectedVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the VexAffectedVulnAssessmentRelationship + */ + public VexAffectedVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the VexAffectedVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the VexAffectedVulnAssessmentRelationship + * @param copyManager Copy manager for the VexAffectedVulnAssessmentRelationship - can be null if copying is not required + * @param create true if VexAffectedVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the VexAffectedVulnAssessmentRelationship + */ + @SuppressWarnings("unchecked") + public VexAffectedVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); + } + + /** + * Create the VexAffectedVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the VexAffectedVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the VexAffectedVulnAssessmentRelationship + */ + protected VexAffectedVulnAssessmentRelationship(VexAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); + getActionStatementTimes().addAll(builder.actionStatementTimes); + setActionStatement(builder.actionStatement); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.VexAffectedVulnAssessmentRelationship"; + } + + // Getters and Setters + public Collection getActionStatementTimes() { + return actionStatementTimes; + } + + + /** + * @return the actionStatement + */ + public Optional getActionStatement() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT); + } + /** + * @param actionStatement the actionStatement to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexAffectedVulnAssessmentRelationship setActionStatement(@Nullable String actionStatement) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT, actionStatement); + return this; + } + + + @Override + public String toString() { + return "VexAffectedVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional actionStatement = getActionStatement(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting actionStatement for VexAffectedVulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class VexAffectedVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + + public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection actionStatementTimes = new ArrayList<>(); + String actionStatement = null; + + + /** + * Adds a actionStatementTime to the initial collection + * @parameter actionStatementTime actionStatementTime to add + * @return this for chaining + **/ + VexAffectedVulnAssessmentRelationshipBuilder addactionStatementTime(String actionStatementTime) { + if (Objects.nonNull(actionStatementTime)) { + actionStatementTimes.add(actionStatementTime); + } + return this; + } + + /** + * Adds all elements from a collection to the initial actionStatementTime collection + * @parameter actionStatementTimeCollection collection to initialize the actionStatementTime + * @return this for chaining + **/ + VexAffectedVulnAssessmentRelationshipBuilder addAllactionStatementTime(Collection actionStatementTimeCollection) { + if (Objects.nonNull(actionStatementTimeCollection)) { + actionStatementTimes.addAll(actionStatementTimeCollection); + } + return this; + } + + /** + * Sets the initial value of actionStatement + * @parameter actionStatement value to set + * @return this for chaining + **/ + VexAffectedVulnAssessmentRelationshipBuilder setactionStatement(String actionStatement) { + this.actionStatement = actionStatement; + return this; + } + + + /** + * @return the VexAffectedVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public VexAffectedVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new VexAffectedVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java new file mode 100644 index 000000000..5179050de --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VexFixedVulnAssessmentRelationship links a vulnerability to a number of elements + * representing VEX products where a vulnerability has been fixed and are no longer + * affected. It represents the VEX fixed status. **Constraints** When linking elements + * using a VexFixedVulnAssessmentRelationship, the following requirements must + * be observed: - Elements linked with a VulnVexFixedAssessmentRelationship are + * constrained to using the fixedIn relationship type. - The from: end of the relationship + * must ve a /Security/Vulnerability classed element. **Syntax** ```json { "@type": + * "VexFixedVulnAssessmentRelationship", "@id": "urn:spdx.dev:vex-fixed-in-1", + * "relationshipType": "fixedIn", "from": "urn:spdx.dev:vuln-cve-2020-28498", + * "to": ["urn:product-acme-application-1.3"], "assessedElement": "urn:npm-elliptic-6.5.4", + * "suppliedBy": ["urn:spdx.dev:agent-jane-doe"], "publishedTime": "2021-03-09T11:04:53Z" + * } ``` + */ +public class VexFixedVulnAssessmentRelationship extends VexVulnAssessmentRelationship { + + + /** + * Create the VexFixedVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the VexFixedVulnAssessmentRelationship + */ + public VexFixedVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the VexFixedVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the VexFixedVulnAssessmentRelationship + */ + public VexFixedVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the VexFixedVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the VexFixedVulnAssessmentRelationship + * @param copyManager Copy manager for the VexFixedVulnAssessmentRelationship - can be null if copying is not required + * @param create true if VexFixedVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the VexFixedVulnAssessmentRelationship + */ + public VexFixedVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the VexFixedVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the VexFixedVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the VexFixedVulnAssessmentRelationship + */ + protected VexFixedVulnAssessmentRelationship(VexFixedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.VexFixedVulnAssessmentRelationship"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "VexFixedVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class VexFixedVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + + public VexFixedVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the VexFixedVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public VexFixedVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new VexFixedVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java b/generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java new file mode 100644 index 000000000..71402500c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VexJustificationType specifies the type of Vulnerability Exploitability eXchange + * (VEX) justification. + */ +public enum VexJustificationType implements IndividualUriValue { + + COMPONENT_NOT_PRESENT("componentNotPresent"), + INLINE_MITIGATIONS_ALREADY_EXIST("inlineMitigationsAlreadyExist"), + VULNERABLE_CODE_NOT_IN_EXECUTE_PATH("vulnerableCodeNotInExecutePath"), + VULNERABLE_CODE_CANNOT_BE_CONTROLLED_BY_ADVERSARY("vulnerableCodeCannotBeControlledByAdversary"), + VULNERABLE_CODE_NOT_PRESENT("vulnerableCodeNotPresent"); + + private String longName; + + private VexJustificationType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Security/VexJustificationType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java new file mode 100644 index 000000000..a37b3f204 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java @@ -0,0 +1,260 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VexNotAffectedVulnAssessmentRelationship connects a vulnerability and a number + * of elements designating them as products not affected by the vulnerability. This + * relationship corresponds to the VEX not_affected status. **Constraints** When + * linking elements using a VexNotVulnAffectedAssessmentRelationship, the following + * requirements must be observed: * Relating elements with a VexNotAffectedVulnAssessmentRelationship + * is restricted to the doesNotAffect relationship type. * The from: end of the relationship + * must be a /Security/Vulnerability classed element. * Both impactStatement and + * justificationType properties have a cardinality of 0..1 making them optional. + * Nevertheless, to produce a valid VEX not_affected statement, one of them MUST be + * defined. This is specified in the Minimum Elements for VEX. **Syntax** ```json { + * "@type": "VexNotAffectedVulnAssessmentRelationship", "@id": "urn:spdx.dev:vex-not-affected-1", + * "relationshipType": "doesNotAffect", "from": "urn:spdx.dev:vuln-cve-2020-28498", + * "to": ["urn:product-acme-application-1.3"], "assessedElement": "urn:npm-elliptic-6.5.2", + * "justificationType": "componentNotPresent", "impactStatement": "Not using + * this vulnerable part of this library.", "suppliedBy": ["urn:spdx.dev:agent-jane-doe"], + * "publishedTime": "2021-03-09T11:04:53Z" } ``` + */ +public class VexNotAffectedVulnAssessmentRelationship extends VexVulnAssessmentRelationship { + + + /** + * Create the VexNotAffectedVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the VexNotAffectedVulnAssessmentRelationship + */ + public VexNotAffectedVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the VexNotAffectedVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the VexNotAffectedVulnAssessmentRelationship + */ + public VexNotAffectedVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the VexNotAffectedVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the VexNotAffectedVulnAssessmentRelationship + * @param copyManager Copy manager for the VexNotAffectedVulnAssessmentRelationship - can be null if copying is not required + * @param create true if VexNotAffectedVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the VexNotAffectedVulnAssessmentRelationship + */ + public VexNotAffectedVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the VexNotAffectedVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the VexNotAffectedVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the VexNotAffectedVulnAssessmentRelationship + */ + protected VexNotAffectedVulnAssessmentRelationship(VexNotAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setJustificationType(builder.justificationType); + setImpactStatementTime(builder.impactStatementTime); + setImpactStatement(builder.impactStatement); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.VexNotAffectedVulnAssessmentRelationship"; + } + + // Getters and Setters + + + /** + * @return the justificationType + */ + @SuppressWarnings("unchecked") + public Optional getJustificationType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.SECURITY_PROP_JUSTIFICATION_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof VexJustificationType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param justificationType the justificationType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexNotAffectedVulnAssessmentRelationship setJustificationType(@Nullable VexJustificationType justificationType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_JUSTIFICATION_TYPE, justificationType); + return this; + } + + /** + * @return the impactStatementTime + */ + public Optional getImpactStatementTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME); + } + /** + * @param impactStatementTime the impactStatementTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexNotAffectedVulnAssessmentRelationship setImpactStatementTime(@Nullable String impactStatementTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME, impactStatementTime); + return this; + } + + /** + * @return the impactStatement + */ + public Optional getImpactStatement() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT); + } + /** + * @param impactStatement the impactStatement to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexNotAffectedVulnAssessmentRelationship setImpactStatement(@Nullable String impactStatement) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT, impactStatement); + return this; + } + + + @Override + public String toString() { + return "VexNotAffectedVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional justificationType = getJustificationType(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting justificationType for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + } + try { + Optional impactStatementTime = getImpactStatementTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting impactStatementTime for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + } + try { + Optional impactStatement = getImpactStatement(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting impactStatement for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class VexNotAffectedVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + + public VexNotAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + VexJustificationType justificationType = null; + String impactStatementTime = null; + String impactStatement = null; + + + /** + * Sets the initial value of justificationType + * @parameter justificationType value to set + * @return this for chaining + **/ + VexNotAffectedVulnAssessmentRelationshipBuilder setjustificationType(VexJustificationType justificationType) { + this.justificationType = justificationType; + return this; + } + + /** + * Sets the initial value of impactStatementTime + * @parameter impactStatementTime value to set + * @return this for chaining + **/ + VexNotAffectedVulnAssessmentRelationshipBuilder setimpactStatementTime(String impactStatementTime) { + this.impactStatementTime = impactStatementTime; + return this; + } + + /** + * Sets the initial value of impactStatement + * @parameter impactStatement value to set + * @return this for chaining + **/ + VexNotAffectedVulnAssessmentRelationshipBuilder setimpactStatement(String impactStatement) { + this.impactStatement = impactStatement; + return this; + } + + + /** + * @return the VexNotAffectedVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public VexNotAffectedVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new VexNotAffectedVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java new file mode 100644 index 000000000..800378f0d --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VexUnderInvestigationVulnAssessmentRelationship links a vulnerability to + * a number of products stating the vulnerability's impact on them is being investigated. + * It represents the VEX under_investigation status. **Constraints** When linking + * elements using a VexUnderInvestigationVulnAssessmentRelationship the following + * requirements must be observed: - Elements linked with a VexUnderInvestigationVulnAssessmentRelationship + * are constrained to using the underInvestigationFor relationship type. - The from: + * end of the relationship must ve a /Security/Vulnerability classed element. **Syntax** + * ```json { "@type": "VexUnderInvestigationVulnAssessmentRelationship", "@id": + * "urn:spdx.dev:vex-underInvestigation-1", "relationshipType": "underInvestigationFor", + * "from": "urn:spdx.dev:vuln-cve-2020-28498", "to": ["urn:product-acme-application-1.3"], + * "assessedElement": "urn:npm-elliptic-6.5.2", "suppliedBy": ["urn:spdx.dev:agent-jane-doe"], + * "publishedTime": "2021-03-09T11:04:53Z" } ``` + */ +public class VexUnderInvestigationVulnAssessmentRelationship extends VexVulnAssessmentRelationship { + + + /** + * Create the VexUnderInvestigationVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the VexUnderInvestigationVulnAssessmentRelationship + */ + public VexUnderInvestigationVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the VexUnderInvestigationVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the VexUnderInvestigationVulnAssessmentRelationship + */ + public VexUnderInvestigationVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the VexUnderInvestigationVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the VexUnderInvestigationVulnAssessmentRelationship + * @param copyManager Copy manager for the VexUnderInvestigationVulnAssessmentRelationship - can be null if copying is not required + * @param create true if VexUnderInvestigationVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the VexUnderInvestigationVulnAssessmentRelationship + */ + public VexUnderInvestigationVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the VexUnderInvestigationVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the VexUnderInvestigationVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the VexUnderInvestigationVulnAssessmentRelationship + */ + protected VexUnderInvestigationVulnAssessmentRelationship(VexUnderInvestigationVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.VexUnderInvestigationVulnAssessmentRelationship"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "VexUnderInvestigationVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class VexUnderInvestigationVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + + public VexUnderInvestigationVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the VexUnderInvestigationVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public VexUnderInvestigationVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new VexUnderInvestigationVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java new file mode 100644 index 000000000..227accccc --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java @@ -0,0 +1,215 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VexVulnAssessmentRelationship is an abstract subclass that defined the common + * properties shared by all the SPDX-VEX status relationships. **Constraints** When + * linking elements using a VexVulnAssessmentRelationship, the following requirements + * must be observed: - The from: end must be a /Security/Vulnerability classed element + * - The to: end must point to elements representing the VEX _products_. To specify a + * different element where the vulnerability was detected, the VEX relationship can + * optionally specify _subcomponents_ using the assessedElement property. VEX inherits + * information from the document level down to its statements. When a statement is missing + * information it can be completed by reading the equivalent field from the containing + * document. For example, if a VEX relationship is missing data in its createdBy property, + * tools must consider the entity listed in the CreationInfo section of the document + * as the VEX author. In the same way, when a VEX relationship does not have a created property, + * the document's date must be considered as authoritative. + */ +public class VexVulnAssessmentRelationship extends VulnAssessmentRelationship { + + + /** + * Create the VexVulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the VexVulnAssessmentRelationship + */ + public VexVulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the VexVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the VexVulnAssessmentRelationship + */ + public VexVulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the VexVulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the VexVulnAssessmentRelationship + * @param copyManager Copy manager for the VexVulnAssessmentRelationship - can be null if copying is not required + * @param create true if VexVulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the VexVulnAssessmentRelationship + */ + public VexVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the VexVulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the VexVulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the VexVulnAssessmentRelationship + */ + protected VexVulnAssessmentRelationship(VexVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setStatusNotes(builder.statusNotes); + setVexVersion(builder.vexVersion); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.VexVulnAssessmentRelationship"; + } + + // Getters and Setters + + + /** + * @return the statusNotes + */ + public Optional getStatusNotes() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_STATUS_NOTES); + } + /** + * @param statusNotes the statusNotes to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexVulnAssessmentRelationship setStatusNotes(@Nullable String statusNotes) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_STATUS_NOTES, statusNotes); + return this; + } + + /** + * @return the vexVersion + */ + public Optional getVexVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_VEX_VERSION); + } + /** + * @param vexVersion the vexVersion to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexVulnAssessmentRelationship setVexVersion(@Nullable String vexVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_VEX_VERSION, vexVersion); + return this; + } + + + @Override + public String toString() { + return "VexVulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional statusNotes = getStatusNotes(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting statusNotes for VexVulnAssessmentRelationship: "+e.getMessage()); + } + try { + Optional vexVersion = getVexVersion(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting vexVersion for VexVulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class VexVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + + public VexVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String statusNotes = null; + String vexVersion = null; + + + /** + * Sets the initial value of statusNotes + * @parameter statusNotes value to set + * @return this for chaining + **/ + VexVulnAssessmentRelationshipBuilder setstatusNotes(String statusNotes) { + this.statusNotes = statusNotes; + return this; + } + + /** + * Sets the initial value of vexVersion + * @parameter vexVersion value to set + * @return this for chaining + **/ + VexVulnAssessmentRelationshipBuilder setvexVersion(String vexVersion) { + this.vexVersion = vexVersion; + return this; + } + + + /** + * @return the VexVulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public VexVulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new VexVulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java new file mode 100644 index 000000000..b88237514 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java @@ -0,0 +1,218 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.Agent; +import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.core.Relationship; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * VulnAssessmentRelationship is the ancestor class common to all vulnerability + * assessment relationships. It factors out the common properties shared by them. + * External property restriction on /Core/Relationship/to: minCount: 1 + */ +public class VulnAssessmentRelationship extends Relationship { + + + /** + * Create the VulnAssessmentRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the VulnAssessmentRelationship + */ + public VulnAssessmentRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the VulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException when unable to create the VulnAssessmentRelationship + */ + public VulnAssessmentRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the VulnAssessmentRelationship is to be stored + * @param objectUri URI or anonymous ID for the VulnAssessmentRelationship + * @param copyManager Copy manager for the VulnAssessmentRelationship - can be null if copying is not required + * @param create true if VulnAssessmentRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the VulnAssessmentRelationship + */ + public VulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the VulnAssessmentRelationship from the builder - used in the builder class + * @param builder Builder to create the VulnAssessmentRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the VulnAssessmentRelationship + */ + protected VulnAssessmentRelationship(VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setAssessedElement(builder.assessedElement); + setSuppliedBy(builder.suppliedBy); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.VulnAssessmentRelationship"; + } + + // Getters and Setters + + /** + * @return the assessedElement + */ + public Optional getAssessedElement() throws InvalidSPDXAnalysisException { + return getElementPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT); + } + + /** + * @param assessedElement the assessedElement to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VulnAssessmentRelationship setAssessedElement(@Nullable Element assessedElement) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT, assessedElement); + return this; + } + + /** + * @return the suppliedBy + */ + public Optional getSuppliedBy() throws InvalidSPDXAnalysisException { + return getElementPropertyValue(SpdxConstants.SECURITY_PROP_SUPPLIED_BY); + } + + /** + * @param suppliedBy the suppliedBy to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VulnAssessmentRelationship setSuppliedBy(@Nullable Element suppliedBy) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_SUPPLIED_BY, suppliedBy); + return this; + } + + + + @Override + public String toString() { + return "VulnAssessmentRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional assessedElement; + try { + assessedElement = getAssessedElement(); + if (assessedElement.isPresent()) { + retval.addAll(assessedElement.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting assessedElement for VulnAssessmentRelationship: "+e.getMessage()); + } + Optional suppliedBy; + try { + suppliedBy = getSuppliedBy(); + if (suppliedBy.isPresent()) { + retval.addAll(suppliedBy.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting suppliedBy for VulnAssessmentRelationship: "+e.getMessage()); + } + return retval; + } + + public static class VulnAssessmentRelationshipBuilder extends RelationshipBuilder { + + public VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Element assessedElement = null; + Agent suppliedBy = null; + + + /** + * Sets the initial value of assessedElement + * @parameter assessedElement value to set + * @return this for chaining + **/ + VulnAssessmentRelationshipBuilder setassessedElement(Element assessedElement) { + this.assessedElement = assessedElement; + return this; + } + + /** + * Sets the initial value of suppliedBy + * @parameter suppliedBy value to set + * @return this for chaining + **/ + VulnAssessmentRelationshipBuilder setsuppliedBy(Agent suppliedBy) { + this.suppliedBy = suppliedBy; + return this; + } + + + /** + * @return the VulnAssessmentRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public VulnAssessmentRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new VulnAssessmentRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java b/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java new file mode 100644 index 000000000..ef897cd8b --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java @@ -0,0 +1,166 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Specifies a vulnerability and its associated information. **Syntax** ```json + * { "@type": "Vulnerability", "@id": "urn:spdx.dev:vuln-1", "summary": "Use of + * a Broken or Risky Cryptographic Algorithm", "description": "The npm package `elliptic` + * before version 6.5.4 are vulnerable to Cryptographic Issues via the secp256k1 implementation + * in elliptic/ec/key.js. There is no check to confirm that the public key point passed + * into the derive function actually exists on the secp256k1 curve. This results in + * the potential for the private key used in this implementation to be revealed after + * a number of ECDH operations are performed.", "modified": "2021-03-08T16:02:43Z", + * "published": "2021-03-08T16:06:50Z", "externalIdentifiers": [ { "@type": "ExternalIdentifier", + * "externalIdentifierType": "cve", "identifier": "CVE-2020-2849", "identifierLocator": + * [ "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28498", "https://www.cve.org/CVERecord?id=CVE-2020-28498" + * ], "issuingAuthority": "urn:spdx.dev:agent-cve.org" }, { "type": "ExternalIdentifier", + * "externalIdentifierType": "securityOther", "identifier": "GHSA-r9p9-mrjm-926w", + * "identifierLocator": "https://github.com/advisories/GHSA-r9p9-mrjm-926w" + * }, { "type": "ExternalIdentifier", "externalIdentifierType": "securityOther", + * "identifier": "SNYK-JS-ELLIPTIC-1064899", "identifierLocator": "https://security.snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" + * } ], "externalReferences": [ { "@type": "ExternalReference", "externalReferenceType": + * "securityAdvisory", "locator": "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" + * }, { "@type": "ExternalReference", "externalReferenceType": "securityAdvisory", + * "locator": "https://ubuntu.com/security/CVE-2020-28498" }, { "@type": "ExternalReference", + * "externalReferenceType": "securityOther", "locator": "https://github.com/indutny/elliptic/pull/244/commits" + * }, { "@type": "ExternalReference", "externalReferenceType": "securityOther", + * "locator": "https://github.com/christianlundkvist/blog/blob/master/2020_05_26_secp256k1_twist_attacks/secp256k1_twist_attacks.md" + * } ] }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnRelationship-1", + * "relationshipType": "hasAssociatedVulnerability", "from": "urn:npm-elliptic-6.5.2", + * "to": ["urn:spdx.dev:vuln-1"], "startTime": "2021-03-08T16:06:50Z" }, { "@type": + * "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", "relationshipType": + * "publishedBy", "from": "urn:spdx.dev:vuln-1", "to": ["urn:spdx.dev:agent-snyk"], + * "startTime": "2021-03-08T16:06:50Z" } ``` + */ +public class Vulnerability extends Element { + + + /** + * Create the Vulnerability with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Vulnerability + */ + public Vulnerability() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Vulnerability + * @throws InvalidSPDXAnalysisException when unable to create the Vulnerability + */ + public Vulnerability(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Vulnerability is to be stored + * @param objectUri URI or anonymous ID for the Vulnerability + * @param copyManager Copy manager for the Vulnerability - can be null if copying is not required + * @param create true if Vulnerability is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Vulnerability + */ + public Vulnerability(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Vulnerability from the builder - used in the builder class + * @param builder Builder to create the Vulnerability from + * @throws InvalidSPDXAnalysisException when unable to create the Vulnerability + */ + protected Vulnerability(VulnerabilityBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Security.Vulnerability"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Vulnerability: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class VulnerabilityBuilder extends ElementBuilder { + + public VulnerabilityBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Vulnerability + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Vulnerability build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Vulnerability(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java b/generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java new file mode 100644 index 000000000..16bec94be --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public enum DependencyConditionalityType implements IndividualUriValue { + + OTHER("other"), + REQUIRED("required"), + OPTIONAL("optional"), + PROVIDED("provided"), + PREREQUISITE("prerequisite"); + + private String longName; + + private DependencyConditionalityType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Software/DependencyConditionalityType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/software/SBOMType.java b/generated/src/main/java/org/spdx/library/model/software/SBOMType.java new file mode 100644 index 000000000..d6884f9a1 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SBOMType.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * The set of SBOM types with definitions as defined in [Types of Software Bill of Material + * (SBOM) Documents](https://www.cisa.gov/sites/default/files/2023-04/sbom-types-document-508c.pdf), + * published on April 21, 2023. An SBOM type describes the most likely type of an SBOM + * from the producer perspective, so that consumers can draw conclusions about the + * data inside an SBOM. A single SBOM can have multiple SBOM document types associated + * with it. + */ +public enum SBOMType implements IndividualUriValue { + + SOURCE("source"), + BUILD("build"), + DEPLOYED("deployed"), + ANALYZED("analyzed"), + RUNTIME("runtime"), + DESIGN("design"); + + private String longName; + + private SBOMType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Software/SBOMType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/software/Sbom.java b/generated/src/main/java/org/spdx/library/model/software/Sbom.java new file mode 100644 index 000000000..9a5cbfd76 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/Sbom.java @@ -0,0 +1,174 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; +import org.spdx.library.model.core.Bom; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A Software Bill of Materials (SBOM) is a collection of SPDX Elements describing a + * single package. This could include details of the content and composition of the + * product, provenance details of the product and/or its composition, licensing information, + * known quality or security issues, etc. + */ +public class Sbom extends Bom { + + Collection sbomTypes; + + /** + * Create the Sbom with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Sbom + */ + public Sbom() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Sbom + * @throws InvalidSPDXAnalysisException when unable to create the Sbom + */ + public Sbom(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Sbom is to be stored + * @param objectUri URI or anonymous ID for the Sbom + * @param copyManager Copy manager for the Sbom - can be null if copying is not required + * @param create true if Sbom is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Sbom + */ + public Sbom(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + sbomTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_SBOM_TYPE, SBOMType.class); + } + + /** + * Create the Sbom from the builder - used in the builder class + * @param builder Builder to create the Sbom from + * @throws InvalidSPDXAnalysisException when unable to create the Sbom + */ + protected Sbom(SbomBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + sbomTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_SBOM_TYPE, SBOMType.class); + getSbomTypes().addAll(builder.sbomTypes); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Software.Sbom"; + } + + // Getters and Setters + public Collection getSbomTypes() { + return sbomTypes; + } + + + + @Override + public String toString() { + return "Sbom: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + return retval; + } + + public static class SbomBuilder extends BomBuilder { + + public SbomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection sbomTypes = new ArrayList<>(); + + + /** + * Adds a sbomType to the initial collection + * @parameter sbomType sbomType to add + * @return this for chaining + **/ + SbomBuilder addsbomType(SBOMType sbomType) { + if (Objects.nonNull(sbomType)) { + sbomTypes.add(sbomType); + } + return this; + } + + /** + * Adds all elements from a collection to the initial sbomType collection + * @parameter sbomTypeCollection collection to initialize the sbomType + * @return this for chaining + **/ + SbomBuilder addAllsbomType(Collection sbomTypeCollection) { + if (Objects.nonNull(sbomTypeCollection)) { + sbomTypes.addAll(sbomTypeCollection); + } + return this; + } + + + /** + * @return the Sbom + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Sbom build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Sbom(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/software/Snippet.java b/generated/src/main/java/org/spdx/library/model/software/Snippet.java new file mode 100644 index 000000000..bd46bd7aa --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/Snippet.java @@ -0,0 +1,235 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.PositiveIntegerRange; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A Snippet describes a certain part of a file and can be used when the file is known to + * have some content that has been included from another original source. Snippets + * are useful for denoting when part of a file may have been originally created under + * another license or copied from a place with a known vulnerability. + */ +public class Snippet extends SoftwareArtifact { + + + /** + * Create the Snippet with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Snippet + */ + public Snippet() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Snippet + * @throws InvalidSPDXAnalysisException when unable to create the Snippet + */ + public Snippet(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Snippet is to be stored + * @param objectUri URI or anonymous ID for the Snippet + * @param copyManager Copy manager for the Snippet - can be null if copying is not required + * @param create true if Snippet is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Snippet + */ + public Snippet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Snippet from the builder - used in the builder class + * @param builder Builder to create the Snippet from + * @throws InvalidSPDXAnalysisException when unable to create the Snippet + */ + protected Snippet(SnippetBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setByteRange(builder.byteRange); + setLineRange(builder.lineRange); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Software.Snippet"; + } + + // Getters and Setters + + + /** + * @return the byteRange + */ + @SuppressWarnings("unchecked") + public Optional getByteRange() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_BYTE_RANGE); + if (retval.isPresent()) { + if (!(retval.get() instanceof PositiveIntegerRange)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param byteRange the byteRange to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Snippet setByteRange(@Nullable PositiveIntegerRange byteRange) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_BYTE_RANGE, byteRange); + return this; + } + + /** + * @return the lineRange + */ + @SuppressWarnings("unchecked") + public Optional getLineRange() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_LINE_RANGE); + if (retval.isPresent()) { + if (!(retval.get() instanceof PositiveIntegerRange)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param lineRange the lineRange to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Snippet setLineRange(@Nullable PositiveIntegerRange lineRange) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_LINE_RANGE, lineRange); + return this; + } + + + @Override + public String toString() { + return "Snippet: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional byteRange; + try { + byteRange = getByteRange(); + if (byteRange.isPresent()) { + retval.addAll(byteRange.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting byteRange for Snippet: "+e.getMessage()); + } + Optional lineRange; + try { + lineRange = getLineRange(); + if (lineRange.isPresent()) { + retval.addAll(lineRange.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting lineRange for Snippet: "+e.getMessage()); + } + return retval; + } + + public static class SnippetBuilder extends SoftwareArtifactBuilder { + + public SnippetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + PositiveIntegerRange byteRange = null; + PositiveIntegerRange lineRange = null; + + + /** + * Sets the initial value of byteRange + * @parameter byteRange value to set + * @return this for chaining + **/ + SnippetBuilder setbyteRange(PositiveIntegerRange byteRange) { + this.byteRange = byteRange; + return this; + } + + /** + * Sets the initial value of lineRange + * @parameter lineRange value to set + * @return this for chaining + **/ + SnippetBuilder setlineRange(PositiveIntegerRange lineRange) { + this.lineRange = lineRange; + return this; + } + + + /** + * @return the Snippet + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Snippet build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Snippet(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java new file mode 100644 index 000000000..e54661f63 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java @@ -0,0 +1,390 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Collection; +import org.spdx.library.model.core.Artifact; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.licensing.AnyLicenseInfo; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A software artifact is a distinct article or unit related to software such as a package, + * a file, or a snippet. + */ +public class SoftwareArtifact extends Artifact { + + Collection additionalPurposes; + + /** + * Create the SoftwareArtifact with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareArtifact + */ + public SoftwareArtifact() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SoftwareArtifact + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareArtifact + */ + public SoftwareArtifact(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SoftwareArtifact is to be stored + * @param objectUri URI or anonymous ID for the SoftwareArtifact + * @param copyManager Copy manager for the SoftwareArtifact - can be null if copying is not required + * @param create true if SoftwareArtifact is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareArtifact + */ + public SoftwareArtifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + additionalPurposes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ADDITIONAL_PURPOSE, SoftwarePurpose.class); + } + + /** + * Create the SoftwareArtifact from the builder - used in the builder class + * @param builder Builder to create the SoftwareArtifact from + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareArtifact + */ + protected SoftwareArtifact(SoftwareArtifactBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + additionalPurposes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ADDITIONAL_PURPOSE, SoftwarePurpose.class); + getAdditionalPurposes().addAll(builder.additionalPurposes); + setDeclaredLicense(builder.declaredLicense); + setConcludedLicense(builder.concludedLicense); + setPrimaryPurpose(builder.primaryPurpose); + setContentIdentifier(builder.contentIdentifier); + setAttributionText(builder.attributionText); + setCopyrightText(builder.copyrightText); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Software.SoftwareArtifact"; + } + + // Getters and Setters + public Collection getAdditionalPurposes() { + return additionalPurposes; + } + + + /** + * @return the declaredLicense + */ + public Optional getDeclaredLicense() throws InvalidSPDXAnalysisException { + return getAnyLicenseInfoPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE); + } + + /** + * @param declaredLicense the declaredLicense to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifact setDeclaredLicense(@Nullable AnyLicenseInfo declaredLicense) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE, declaredLicense); + return this; + } + + /** + * @return the concludedLicense + */ + public Optional getConcludedLicense() throws InvalidSPDXAnalysisException { + return getAnyLicenseInfoPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE); + } + + /** + * @param concludedLicense the concludedLicense to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifact setConcludedLicense(@Nullable AnyLicenseInfo concludedLicense) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE, concludedLicense); + return this; + } + + /** + * @return the primaryPurpose + */ + @SuppressWarnings("unchecked") + public Optional getPrimaryPurpose() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.SOFTWARE_PROP_PRIMARY_PURPOSE); + if (retval.isPresent()) { + if (!(retval.get() instanceof SoftwarePurpose)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param primaryPurpose the primaryPurpose to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifact setPrimaryPurpose(@Nullable SoftwarePurpose primaryPurpose) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_PRIMARY_PURPOSE, primaryPurpose); + return this; + } + + /** + * @return the contentIdentifier + */ + public Optional getContentIdentifier() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_IDENTIFIER); + } + /** + * @param contentIdentifier the contentIdentifier to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifact setContentIdentifier(@Nullable String contentIdentifier) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_IDENTIFIER, contentIdentifier); + return this; + } + + /** + * @return the attributionText + */ + public Optional getAttributionText() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT); + } + /** + * @param attributionText the attributionText to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifact setAttributionText(@Nullable String attributionText) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT, attributionText); + return this; + } + + /** + * @return the copyrightText + */ + public Optional getCopyrightText() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_COPYRIGHT_TEXT); + } + /** + * @param copyrightText the copyrightText to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifact setCopyrightText(@Nullable String copyrightText) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_COPYRIGHT_TEXT, copyrightText); + return this; + } + + + @Override + public String toString() { + return "SoftwareArtifact: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional declaredLicense; + try { + declaredLicense = getDeclaredLicense(); + if (declaredLicense.isPresent()) { + retval.addAll(declaredLicense.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting declaredLicense for SoftwareArtifact: "+e.getMessage()); + } + Optional concludedLicense; + try { + concludedLicense = getConcludedLicense(); + if (concludedLicense.isPresent()) { + retval.addAll(concludedLicense.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting concludedLicense for SoftwareArtifact: "+e.getMessage()); + } + try { + Optional primaryPurpose = getPrimaryPurpose(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting primaryPurpose for SoftwareArtifact: "+e.getMessage()); + } + try { + Optional contentIdentifier = getContentIdentifier(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting contentIdentifier for SoftwareArtifact: "+e.getMessage()); + } + try { + Optional attributionText = getAttributionText(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting attributionText for SoftwareArtifact: "+e.getMessage()); + } + try { + Optional copyrightText = getCopyrightText(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting copyrightText for SoftwareArtifact: "+e.getMessage()); + } + return retval; + } + + public static class SoftwareArtifactBuilder extends ArtifactBuilder { + + public SoftwareArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + Collection additionalPurposes = new ArrayList<>(); + AnyLicenseInfo declaredLicense = null; + AnyLicenseInfo concludedLicense = null; + SoftwarePurpose primaryPurpose = null; + String contentIdentifier = null; + String attributionText = null; + String copyrightText = null; + + + /** + * Adds a additionalPurpose to the initial collection + * @parameter additionalPurpose additionalPurpose to add + * @return this for chaining + **/ + SoftwareArtifactBuilder addadditionalPurpose(SoftwarePurpose additionalPurpose) { + if (Objects.nonNull(additionalPurpose)) { + additionalPurposes.add(additionalPurpose); + } + return this; + } + + /** + * Adds all elements from a collection to the initial additionalPurpose collection + * @parameter additionalPurposeCollection collection to initialize the additionalPurpose + * @return this for chaining + **/ + SoftwareArtifactBuilder addAlladditionalPurpose(Collection additionalPurposeCollection) { + if (Objects.nonNull(additionalPurposeCollection)) { + additionalPurposes.addAll(additionalPurposeCollection); + } + return this; + } + + /** + * Sets the initial value of declaredLicense + * @parameter declaredLicense value to set + * @return this for chaining + **/ + SoftwareArtifactBuilder setdeclaredLicense(AnyLicenseInfo declaredLicense) { + this.declaredLicense = declaredLicense; + return this; + } + + /** + * Sets the initial value of concludedLicense + * @parameter concludedLicense value to set + * @return this for chaining + **/ + SoftwareArtifactBuilder setconcludedLicense(AnyLicenseInfo concludedLicense) { + this.concludedLicense = concludedLicense; + return this; + } + + /** + * Sets the initial value of primaryPurpose + * @parameter primaryPurpose value to set + * @return this for chaining + **/ + SoftwareArtifactBuilder setprimaryPurpose(SoftwarePurpose primaryPurpose) { + this.primaryPurpose = primaryPurpose; + return this; + } + + /** + * Sets the initial value of contentIdentifier + * @parameter contentIdentifier value to set + * @return this for chaining + **/ + SoftwareArtifactBuilder setcontentIdentifier(String contentIdentifier) { + this.contentIdentifier = contentIdentifier; + return this; + } + + /** + * Sets the initial value of attributionText + * @parameter attributionText value to set + * @return this for chaining + **/ + SoftwareArtifactBuilder setattributionText(String attributionText) { + this.attributionText = attributionText; + return this; + } + + /** + * Sets the initial value of copyrightText + * @parameter copyrightText value to set + * @return this for chaining + **/ + SoftwareArtifactBuilder setcopyrightText(String copyrightText) { + this.copyrightText = copyrightText; + return this; + } + + + /** + * @return the SoftwareArtifact + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SoftwareArtifact build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SoftwareArtifact(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java new file mode 100644 index 000000000..6bd6a2b8a --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public enum SoftwareDependencyLinkType implements IndividualUriValue { + + STATIC("static"), + OTHER("other"), + DYNAMIC("dynamic"), + TOOL("tool"); + + private String longName; + + private SoftwareDependencyLinkType(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Software/SoftwareDependencyLinkType"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java new file mode 100644 index 000000000..4f24bd782 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java @@ -0,0 +1,222 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.LifecycleScopedRelationship; +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public class SoftwareDependencyRelationship extends LifecycleScopedRelationship { + + + /** + * Create the SoftwareDependencyRelationship with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareDependencyRelationship + */ + public SoftwareDependencyRelationship() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SoftwareDependencyRelationship + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareDependencyRelationship + */ + public SoftwareDependencyRelationship(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SoftwareDependencyRelationship is to be stored + * @param objectUri URI or anonymous ID for the SoftwareDependencyRelationship + * @param copyManager Copy manager for the SoftwareDependencyRelationship - can be null if copying is not required + * @param create true if SoftwareDependencyRelationship is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareDependencyRelationship + */ + public SoftwareDependencyRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SoftwareDependencyRelationship from the builder - used in the builder class + * @param builder Builder to create the SoftwareDependencyRelationship from + * @throws InvalidSPDXAnalysisException when unable to create the SoftwareDependencyRelationship + */ + protected SoftwareDependencyRelationship(SoftwareDependencyRelationshipBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setSoftwareLinkage(builder.softwareLinkage); + setConditionality(builder.conditionality); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Software.SoftwareDependencyRelationship"; + } + + // Getters and Setters + + + /** + * @return the softwareLinkage + */ + @SuppressWarnings("unchecked") + public Optional getSoftwareLinkage() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.SOFTWARE_PROP_SOFTWARE_LINKAGE); + if (retval.isPresent()) { + if (!(retval.get() instanceof SoftwareDependencyLinkType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param softwareLinkage the softwareLinkage to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareDependencyRelationship setSoftwareLinkage(@Nullable SoftwareDependencyLinkType softwareLinkage) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_SOFTWARE_LINKAGE, softwareLinkage); + return this; + } + + /** + * @return the conditionality + */ + @SuppressWarnings("unchecked") + public Optional getConditionality() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.SOFTWARE_PROP_CONDITIONALITY); + if (retval.isPresent()) { + if (!(retval.get() instanceof DependencyConditionalityType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param conditionality the conditionality to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SoftwareDependencyRelationship setConditionality(@Nullable DependencyConditionalityType conditionality) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONDITIONALITY, conditionality); + return this; + } + + + @Override + public String toString() { + return "SoftwareDependencyRelationship: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional softwareLinkage = getSoftwareLinkage(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting softwareLinkage for SoftwareDependencyRelationship: "+e.getMessage()); + } + try { + Optional conditionality = getConditionality(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting conditionality for SoftwareDependencyRelationship: "+e.getMessage()); + } + return retval; + } + + public static class SoftwareDependencyRelationshipBuilder extends LifecycleScopedRelationshipBuilder { + + public SoftwareDependencyRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + SoftwareDependencyLinkType softwareLinkage = null; + DependencyConditionalityType conditionality = null; + + + /** + * Sets the initial value of softwareLinkage + * @parameter softwareLinkage value to set + * @return this for chaining + **/ + SoftwareDependencyRelationshipBuilder setsoftwareLinkage(SoftwareDependencyLinkType softwareLinkage) { + this.softwareLinkage = softwareLinkage; + return this; + } + + /** + * Sets the initial value of conditionality + * @parameter conditionality value to set + * @return this for chaining + **/ + SoftwareDependencyRelationshipBuilder setconditionality(DependencyConditionalityType conditionality) { + this.conditionality = conditionality; + return this; + } + + + /** + * @return the SoftwareDependencyRelationship + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SoftwareDependencyRelationship build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SoftwareDependencyRelationship(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java b/generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java new file mode 100644 index 000000000..b88e751ab --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import org.spdx.library.IndividualUriValue; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * This field provides information about the primary purpose of an Element. Software + * Purpose is intrinsic to how the Element is being used rather than the content of the + * Element. This field is a reasonable estimate of the most likely usage of the Element + * from the producer and consumer perspective from which both parties can draw conclusions + * about the context in which the Element exists. + */ +public enum SoftwarePurpose implements IndividualUriValue { + + CONFIGURATION("configuration"), + FILE("file"), + FIRMWARE("firmware"), + EXECUTABLE("executable"), + ARCHIVE("archive"), + MODEL("model"), + REQUIREMENT("requirement"), + SPECIFICATION("specification"), + FRAMEWORK("framework"), + PATCH("patch"), + DATA("data"), + LIBRARY("library"), + EVIDENCE("evidence"), + TEST("test"), + INSTALL("install"), + CONTAINER("container"), + SOURCE("source"), + OPERATING_SYSTEM("operatingSystem"), + DOCUMENTATION("documentation"), + MODULE("module"), + DEVICE("device"), + APPLICATION("application"), + OTHER("other"), + BOM("bom"), + MANIFEST("manifest"); + + private String longName; + + private SoftwarePurpose(String longName) { + this.longName = longName; + } + + @Override + public String getIndividualURI() { + return getNameSpace() + "/" + getLongName(); + } + + public String getLongName() { + return longName; + } + + public String getNameSpace() { + return "https://spdx.org/rdf/Software/SoftwarePurpose"; + } +} + diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java b/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java new file mode 100644 index 000000000..8ab225752 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * Refers to any object that stores content on a computer. The type of content can optionally + * be provided in the contentType property. External property restriction on /Core/Element/name: + * minCount: 1 + */ +public class SpdxFile extends SoftwareArtifact { + + + /** + * Create the SpdxFile with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SpdxFile + */ + public SpdxFile() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SpdxFile + * @throws InvalidSPDXAnalysisException when unable to create the SpdxFile + */ + public SpdxFile(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SpdxFile is to be stored + * @param objectUri URI or anonymous ID for the SpdxFile + * @param copyManager Copy manager for the SpdxFile - can be null if copying is not required + * @param create true if SpdxFile is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SpdxFile + */ + public SpdxFile(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SpdxFile from the builder - used in the builder class + * @param builder Builder to create the SpdxFile from + * @throws InvalidSPDXAnalysisException when unable to create the SpdxFile + */ + protected SpdxFile(SpdxFileBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setContentType(builder.contentType); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Software.SpdxFile"; + } + + // Getters and Setters + + + /** + * @return the contentType + */ + public Optional getContentType() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE); + } + /** + * @param contentType the contentType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxFile setContentType(@Nullable String contentType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE, contentType); + return this; + } + + + @Override + public String toString() { + return "SpdxFile: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional contentType = getContentType(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting contentType for SpdxFile: "+e.getMessage()); + } + return retval; + } + + public static class SpdxFileBuilder extends SoftwareArtifactBuilder { + + public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String contentType = null; + + + /** + * Sets the initial value of contentType + * @parameter contentType value to set + * @return this for chaining + **/ + SpdxFileBuilder setcontentType(String contentType) { + this.contentType = contentType; + return this; + } + + + /** + * @return the SpdxFile + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SpdxFile build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SpdxFile(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java b/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java new file mode 100644 index 000000000..af0e686fa --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java @@ -0,0 +1,311 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import org.spdx.library.model.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A package refers to any unit of content that can be associated with a distribution + * of software. Typically, a package is composed of one or more files. Any of the following + * non-limiting examples may be (but are not required to be) represented in SPDX as a + * package: - a tarball, zip file or other archive - a directory or sub-directory - a separately + * distributed piece of software which another Package or File uses or depends upon + * (e.g., a Python package, a Go module, ...) - a container image, and/or each image layer + * within a container image - a collection of one or more sub-packages - a Git repository + * snapshot from a particular point in time Note that some of these could be represented + * in SPDX as a file as well. External property restriction on /Core/Element/name: + * minCount: 1 + */ +public class SpdxPackage extends SoftwareArtifact { + + + /** + * Create the SpdxPackage with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SpdxPackage + */ + public SpdxPackage() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SpdxPackage + * @throws InvalidSPDXAnalysisException when unable to create the SpdxPackage + */ + public SpdxPackage(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SpdxPackage is to be stored + * @param objectUri URI or anonymous ID for the SpdxPackage + * @param copyManager Copy manager for the SpdxPackage - can be null if copying is not required + * @param create true if SpdxPackage is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SpdxPackage + */ + public SpdxPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SpdxPackage from the builder - used in the builder class + * @param builder Builder to create the SpdxPackage from + * @throws InvalidSPDXAnalysisException when unable to create the SpdxPackage + */ + protected SpdxPackage(SpdxPackageBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setDownloadLocation(builder.downloadLocation); + setSourceInfo(builder.sourceInfo); + setPackageVersion(builder.packageVersion); + setHomePage(builder.homePage); + setPackageUrl(builder.packageUrl); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Software.SpdxPackage"; + } + + // Getters and Setters + + + /** + * @return the downloadLocation + */ + public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION); + } + /** + * @param downloadLocation the downloadLocation to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxPackage setDownloadLocation(@Nullable String downloadLocation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION, downloadLocation); + return this; + } + + /** + * @return the sourceInfo + */ + public Optional getSourceInfo() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO); + } + /** + * @param sourceInfo the sourceInfo to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxPackage setSourceInfo(@Nullable String sourceInfo) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO, sourceInfo); + return this; + } + + /** + * @return the packageVersion + */ + public Optional getPackageVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_VERSION); + } + /** + * @param packageVersion the packageVersion to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxPackage setPackageVersion(@Nullable String packageVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_VERSION, packageVersion); + return this; + } + + /** + * @return the homePage + */ + public Optional getHomePage() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_HOME_PAGE); + } + /** + * @param homePage the homePage to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxPackage setHomePage(@Nullable String homePage) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_HOME_PAGE, homePage); + return this; + } + + /** + * @return the packageUrl + */ + public Optional getPackageUrl() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL); + } + /** + * @param packageUrl the packageUrl to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxPackage setPackageUrl(@Nullable String packageUrl) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL, packageUrl); + return this; + } + + + @Override + public String toString() { + return "SpdxPackage: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional downloadLocation = getDownloadLocation(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting downloadLocation for SpdxPackage: "+e.getMessage()); + } + try { + Optional sourceInfo = getSourceInfo(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting sourceInfo for SpdxPackage: "+e.getMessage()); + } + try { + Optional packageVersion = getPackageVersion(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting packageVersion for SpdxPackage: "+e.getMessage()); + } + try { + Optional homePage = getHomePage(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting homePage for SpdxPackage: "+e.getMessage()); + } + try { + Optional packageUrl = getPackageUrl(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting packageUrl for SpdxPackage: "+e.getMessage()); + } + return retval; + } + + public static class SpdxPackageBuilder extends SoftwareArtifactBuilder { + + public SpdxPackageBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String downloadLocation = null; + String sourceInfo = null; + String packageVersion = null; + String homePage = null; + String packageUrl = null; + + + /** + * Sets the initial value of downloadLocation + * @parameter downloadLocation value to set + * @return this for chaining + **/ + SpdxPackageBuilder setdownloadLocation(String downloadLocation) { + this.downloadLocation = downloadLocation; + return this; + } + + /** + * Sets the initial value of sourceInfo + * @parameter sourceInfo value to set + * @return this for chaining + **/ + SpdxPackageBuilder setsourceInfo(String sourceInfo) { + this.sourceInfo = sourceInfo; + return this; + } + + /** + * Sets the initial value of packageVersion + * @parameter packageVersion value to set + * @return this for chaining + **/ + SpdxPackageBuilder setpackageVersion(String packageVersion) { + this.packageVersion = packageVersion; + return this; + } + + /** + * Sets the initial value of homePage + * @parameter homePage value to set + * @return this for chaining + **/ + SpdxPackageBuilder sethomePage(String homePage) { + this.homePage = homePage; + return this; + } + + /** + * Sets the initial value of packageUrl + * @parameter packageUrl value to set + * @return this for chaining + **/ + SpdxPackageBuilder setpackageUrl(String packageUrl) { + this.packageUrl = packageUrl; + return this; + } + + + /** + * @return the SpdxPackage + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SpdxPackage build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SpdxPackage(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/test/java/org/spdx/library/model/ai/AIPackageTest.java b/generated/src/test/java/org/spdx/library/model/ai/AIPackageTest.java new file mode 100644 index 000000000..3cc310698 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/ai/AIPackageTest.java @@ -0,0 +1,295 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.ai; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.ai.AIPackage.AIPackageBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class AIPackageTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static AIPackageBuilder builderForAIPackageTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setsensitivePersonalInformation(PresenceType.ENUM) + .setsafetyRiskAssessment(SafetyRiskAssessmentType.ENUM) + .setautonomyType(PresenceType.ENUM) + .setinformationAboutTraining("A string") + .setlimitation("A string") + .setenergyConsumption("A string") + .setinformationAboutApplication("A string") + .getmetric.add(DictionaryEntry) + .gethyperparameter.add(DictionaryEntry) + .getmetricDecisionThreshold.add(DictionaryEntry) + .getdomain.add("Test string") + .getstandardCompliance.add("Test string") + .getmodelDataPreprocessing.add("Test string") + .gettypeOfModel.add("Test string") + .getmodelExplainability.add("Test string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testAIPackage.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("AI.AIPackage", testAIPackage.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("AIPackage: "+TEST_OBJECT_URI, testAIPackage.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#Element(org.spdx.library.model.ai.AIPackage.AIPackageBuilder)}. + */ + public void testAIPackageAIPackageBuilder() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AIPackage test2AIPackage = builderForAIPackageTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testAIPackage.equivalent(test2AIPackage)); + assertTrue(test2AIPackage.equivalent(testAIPackage)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setSensitivePersonalInformation}. + */ + public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getSensitivePersonalInformation()); +// testAIPackage.setSensitivePersonalInformation(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getSensitivePersonalInformation()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setSafetyRiskAssessment}. + */ + public void testAIPackagesetSafetyRiskAssessment() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getSafetyRiskAssessment()); +// testAIPackage.setSafetyRiskAssessment(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getSafetyRiskAssessment()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setAutonomyType}. + */ + public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getAutonomyType()); +// testAIPackage.setAutonomyType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getAutonomyType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setInformationAboutTraining}. + */ + public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getInformationAboutTraining()); +// testAIPackage.setInformationAboutTraining(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getInformationAboutTraining()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setLimitation}. + */ + public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getLimitation()); +// testAIPackage.setLimitation(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getLimitation()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setEnergyConsumption}. + */ + public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getEnergyConsumption()); +// testAIPackage.setEnergyConsumption(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getEnergyConsumption()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#setInformationAboutApplication}. + */ + public void testAIPackagesetInformationAboutApplication() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAIPackage.getInformationAboutApplication()); +// testAIPackage.setInformationAboutApplication(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAIPackage.getInformationAboutApplication()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getMetric}. + */ + public void testAIPackagesetMetric() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetric())); +// testAIPackage.getMetric().clear(); +// testAIPackage.getMetric().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetric())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getHyperparameter}. + */ + public void testAIPackagesetHyperparameter() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameter())); +// testAIPackage.getHyperparameter().clear(); +// testAIPackage.getHyperparameter().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameter())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getMetricDecisionThreshold}. + */ + public void testAIPackagesetMetricDecisionThreshold() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThreshold())); +// testAIPackage.getMetricDecisionThreshold().clear(); +// testAIPackage.getMetricDecisionThreshold().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThreshold())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getDomain}. + */ + public void testAIPackagegetDomain() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getDomain())); +// testAIPackage.getDomain().clear(); +// testAIPackage.getDomain().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getDomain())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getStandardCompliance}. + */ + public void testAIPackagegetStandardCompliance() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getStandardCompliance())); +// testAIPackage.getStandardCompliance().clear(); +// testAIPackage.getStandardCompliance().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getStandardCompliance())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelDataPreprocessing}. + */ + public void testAIPackagegetModelDataPreprocessing() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getModelDataPreprocessing())); +// testAIPackage.getModelDataPreprocessing().clear(); +// testAIPackage.getModelDataPreprocessing().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getModelDataPreprocessing())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getTypeOfModel}. + */ + public void testAIPackagegetTypeOfModel() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getTypeOfModel())); +// testAIPackage.getTypeOfModel().clear(); +// testAIPackage.getTypeOfModel().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getTypeOfModel())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelExplainability}. + */ + public void testAIPackagegetModelExplainability() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getModelExplainability())); +// testAIPackage.getModelExplainability().clear(); +// testAIPackage.getModelExplainability().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getModelExplainability())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/build/BuildTest.java b/generated/src/test/java/org/spdx/library/model/build/BuildTest.java new file mode 100644 index 000000000..10f9f8e2f --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/build/BuildTest.java @@ -0,0 +1,220 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.build; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.build.Build.BuildBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class BuildTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static BuildBuilder builderForBuildTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + BuildBuilder retval = new BuildBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setbuildEndTime("A string") + .setbuildType("A string") + .setbuildStartTime("A string") + .setbuildId("A string") + .getparameters.add(DictionaryEntry) + .getconfigSourceDigest.add(Hash) + .getenvironment.add(DictionaryEntry) + .getconfigSourceEntrypoint.add("Test string") + .getconfigSourceUri.add("Test string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testBuild.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Build.Build", testBuild.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Build: "+TEST_OBJECT_URI, testBuild.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#Element(org.spdx.library.model.build.Build.BuildBuilder)}. + */ + public void testBuildBuildBuilder() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Build test2Build = builderForBuildTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testBuild.equivalent(test2Build)); + assertTrue(test2Build.equivalent(testBuild)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#setBuildEndTime}. + */ + public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testBuild.getBuildEndTime()); +// testBuild.setBuildEndTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testBuild.getBuildEndTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#setBuildType}. + */ + public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testBuild.getBuildType()); +// testBuild.setBuildType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testBuild.getBuildType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#setBuildStartTime}. + */ + public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testBuild.getBuildStartTime()); +// testBuild.setBuildStartTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testBuild.getBuildStartTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#setBuildId}. + */ + public void testBuildsetBuildId() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testBuild.getBuildId()); +// testBuild.setBuildId(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testBuild.getBuildId()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#getParameters}. + */ + public void testBuildsetParameters() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getParameters())); +// testBuild.getParameters().clear(); +// testBuild.getParameters().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getParameters())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceDigest}. + */ + public void testBuildsetConfigSourceDigest() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigest())); +// testBuild.getConfigSourceDigest().clear(); +// testBuild.getConfigSourceDigest().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigest())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#getEnvironment}. + */ + public void testBuildsetEnvironment() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getEnvironment())); +// testBuild.getEnvironment().clear(); +// testBuild.getEnvironment().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getEnvironment())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceEntrypoint}. + */ + public void testBuildgetConfigSourceEntrypoint() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceEntrypoint())); +// testBuild.getConfigSourceEntrypoint().clear(); +// testBuild.getConfigSourceEntrypoint().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceEntrypoint())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceUri}. + */ + public void testBuildgetConfigSourceUri() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceUri())); +// testBuild.getConfigSourceUri().clear(); +// testBuild.getConfigSourceUri().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceUri())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/AgentTest.java b/generated/src/test/java/org/spdx/library/model/core/AgentTest.java new file mode 100644 index 000000000..6c1f321ce --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/AgentTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Agent.AgentBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class AgentTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static AgentBuilder builderForAgentTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + AgentBuilder retval = new AgentBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Agent#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testAgent.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Agent#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Agent", testAgent.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Agent#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Agent: "+TEST_OBJECT_URI, testAgent.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Agent#Element(org.spdx.library.model.core.Agent.AgentBuilder)}. + */ + public void testAgentAgentBuilder() throws InvalidSPDXAnalysisException { + Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Agent test2Agent = builderForAgentTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testAgent.equivalent(test2Agent)); + assertTrue(test2Agent.equivalent(testAgent)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/AnnotationTest.java b/generated/src/test/java/org/spdx/library/model/core/AnnotationTest.java new file mode 100644 index 000000000..69c38c3ce --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/AnnotationTest.java @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Annotation.AnnotationBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class AnnotationTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static AnnotationBuilder builderForAnnotationTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + AnnotationBuilder retval = new AnnotationBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setsubject(Element testElement) + .setannotationType(AnnotationType.ENUM) + .setstatement("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testAnnotation.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Annotation", testAnnotation.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Annotation: "+TEST_OBJECT_URI, testAnnotation.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#Element(org.spdx.library.model.core.Annotation.AnnotationBuilder)}. + */ + public void testAnnotationAnnotationBuilder() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Annotation test2Annotation = builderForAnnotationTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testAnnotation.equivalent(test2Annotation)); + assertTrue(test2Annotation.equivalent(testAnnotation)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#setSubject}. + */ + public void testAnnotationsetSubject() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAnnotation.getSubject()); +// testAnnotation.setSubject(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAnnotation.getSubject()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#setAnnotationType}. + */ + public void testAnnotationsetAnnotationType() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAnnotation.getAnnotationType()); +// testAnnotation.setAnnotationType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAnnotation.getAnnotationType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Annotation#setStatement}. + */ + public void testAnnotationsetStatement() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testAnnotation.getStatement()); +// testAnnotation.setStatement(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testAnnotation.getStatement()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java b/generated/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java new file mode 100644 index 000000000..ef3310f2b --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.AnonymousPayload.AnonymousPayloadBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class AnonymousPayloadTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static AnonymousPayloadBuilder builderForAnonymousPayloadTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + AnonymousPayloadBuilder retval = new AnonymousPayloadBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.AnonymousPayload#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testAnonymousPayload.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.AnonymousPayload#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.AnonymousPayload", testAnonymousPayload.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.AnonymousPayload#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("AnonymousPayload: "+TEST_OBJECT_URI, testAnonymousPayload.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.AnonymousPayload#Element(org.spdx.library.model.core.AnonymousPayload.AnonymousPayloadBuilder)}. + */ + public void testAnonymousPayloadAnonymousPayloadBuilder() throws InvalidSPDXAnalysisException { + AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AnonymousPayload test2AnonymousPayload = builderForAnonymousPayloadTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testAnonymousPayload.equivalent(test2AnonymousPayload)); + assertTrue(test2AnonymousPayload.equivalent(testAnonymousPayload)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ArtifactTest.java b/generated/src/test/java/org/spdx/library/model/core/ArtifactTest.java new file mode 100644 index 000000000..9dc30ad2a --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ArtifactTest.java @@ -0,0 +1,182 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Artifact.ArtifactBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ArtifactTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ArtifactBuilder builderForArtifactTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ArtifactBuilder retval = new ArtifactBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setreleaseTime("A string") + .setvalidUntilTime("A string") + .setbuiltTime("A string") + .getoriginatedBy.add(Agent) + .getsuppliedBy.add(Agent) + .getstandard.add("Test string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testArtifact.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Artifact", testArtifact.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Artifact: "+TEST_OBJECT_URI, testArtifact.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#Element(org.spdx.library.model.core.Artifact.ArtifactBuilder)}. + */ + public void testArtifactArtifactBuilder() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Artifact test2Artifact = builderForArtifactTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testArtifact.equivalent(test2Artifact)); + assertTrue(test2Artifact.equivalent(testArtifact)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#setReleaseTime}. + */ + public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testArtifact.getReleaseTime()); +// testArtifact.setReleaseTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testArtifact.getReleaseTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#setValidUntilTime}. + */ + public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testArtifact.getValidUntilTime()); +// testArtifact.setValidUntilTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testArtifact.getValidUntilTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#setBuiltTime}. + */ + public void testArtifactsetBuiltTime() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testArtifact.getBuiltTime()); +// testArtifact.setBuiltTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testArtifact.getBuiltTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#getOriginatedBy}. + */ + public void testArtifactsetOriginatedBy() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBy())); +// testArtifact.getOriginatedBy().clear(); +// testArtifact.getOriginatedBy().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBy())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#getSuppliedBy}. + */ + public void testArtifactsetSuppliedBy() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBy())); +// testArtifact.getSuppliedBy().clear(); +// testArtifact.getSuppliedBy().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBy())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Artifact#getStandard}. + */ + public void testArtifactgetStandard() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testArtifact.getStandard())); +// testArtifact.getStandard().clear(); +// testArtifact.getStandard().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getStandard())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/BomTest.java b/generated/src/test/java/org/spdx/library/model/core/BomTest.java new file mode 100644 index 000000000..497ad14b3 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/BomTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Bom.BomBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class BomTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static BomBuilder builderForBomTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + BomBuilder retval = new BomBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Bom#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testBom.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Bom#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Bom", testBom.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Bom#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Bom: "+TEST_OBJECT_URI, testBom.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Bom#Element(org.spdx.library.model.core.Bom.BomBuilder)}. + */ + public void testBomBomBuilder() throws InvalidSPDXAnalysisException { + Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Bom test2Bom = builderForBomTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testBom.equivalent(test2Bom)); + assertTrue(test2Bom.equivalent(testBom)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/BundleTest.java b/generated/src/test/java/org/spdx/library/model/core/BundleTest.java new file mode 100644 index 000000000..2fc52e4eb --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/BundleTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Bundle.BundleBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class BundleTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static BundleBuilder builderForBundleTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + BundleBuilder retval = new BundleBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setcontext("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Bundle#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testBundle.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Bundle#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Bundle", testBundle.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Bundle#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Bundle: "+TEST_OBJECT_URI, testBundle.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Bundle#Element(org.spdx.library.model.core.Bundle.BundleBuilder)}. + */ + public void testBundleBundleBuilder() throws InvalidSPDXAnalysisException { + Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Bundle test2Bundle = builderForBundleTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testBundle.equivalent(test2Bundle)); + assertTrue(test2Bundle.equivalent(testBundle)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Bundle#setContext}. + */ + public void testBundlesetContext() throws InvalidSPDXAnalysisException { + Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testBundle.getContext()); +// testBundle.setContext(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testBundle.getContext()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/CreationInfoTest.java b/generated/src/test/java/org/spdx/library/model/core/CreationInfoTest.java new file mode 100644 index 000000000..af6d1b1ee --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/CreationInfoTest.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.CreationInfo.CreationInfoBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class CreationInfoTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static CreationInfoBuilder builderForCreationInfoTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + CreationInfoBuilder retval = new CreationInfoBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setcomment("A string") + .getcreatedUsing.add(Tool) + .getcreatedBy.add(Agent) + .getcreated.add("Test string") + .getdataLicense.add("Test string") + .getspecVersion.add("Test string") + .getprofile.add(ProfileIdentifierType.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testCreationInfo.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.CreationInfo", testCreationInfo.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("CreationInfo: "+TEST_OBJECT_URI, testCreationInfo.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#Element(org.spdx.library.model.core.CreationInfo.CreationInfoBuilder)}. + */ + public void testCreationInfoCreationInfoBuilder() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + CreationInfo test2CreationInfo = builderForCreationInfoTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testCreationInfo.equivalent(test2CreationInfo)); + assertTrue(test2CreationInfo.equivalent(testCreationInfo)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#setComment}. + */ + public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testCreationInfo.getComment()); +// testCreationInfo.setComment(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testCreationInfo.getComment()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreatedUsing}. + */ + public void testCreationInfosetCreatedUsing() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsing())); +// testCreationInfo.getCreatedUsing().clear(); +// testCreationInfo.getCreatedUsing().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsing())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreatedBy}. + */ + public void testCreationInfosetCreatedBy() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBy())); +// testCreationInfo.getCreatedBy().clear(); +// testCreationInfo.getCreatedBy().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBy())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreated}. + */ + public void testCreationInfogetCreated() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreated())); +// testCreationInfo.getCreated().clear(); +// testCreationInfo.getCreated().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreated())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getDataLicense}. + */ + public void testCreationInfogetDataLicense() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getDataLicense())); +// testCreationInfo.getDataLicense().clear(); +// testCreationInfo.getDataLicense().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getDataLicense())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getSpecVersion}. + */ + public void testCreationInfogetSpecVersion() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getSpecVersion())); +// testCreationInfo.getSpecVersion().clear(); +// testCreationInfo.getSpecVersion().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getSpecVersion())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.CreationInfo#getProfile}. + */ + public void testCreationInfogetProfile() throws InvalidSPDXAnalysisException { + CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getProfile())); +// testCreationInfo.getProfile().clear(); +// testCreationInfo.getProfile().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getProfile())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java b/generated/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java new file mode 100644 index 000000000..6a8f20e80 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.DictionaryEntry.DictionaryEntryBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class DictionaryEntryTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static DictionaryEntryBuilder builderForDictionaryEntryTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + DictionaryEntryBuilder retval = new DictionaryEntryBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setkey("A string") + .setvalue("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.DictionaryEntry#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testDictionaryEntry.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.DictionaryEntry#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.DictionaryEntry", testDictionaryEntry.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.DictionaryEntry#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("DictionaryEntry: "+TEST_OBJECT_URI, testDictionaryEntry.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.DictionaryEntry#Element(org.spdx.library.model.core.DictionaryEntry.DictionaryEntryBuilder)}. + */ + public void testDictionaryEntryDictionaryEntryBuilder() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + DictionaryEntry test2DictionaryEntry = builderForDictionaryEntryTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testDictionaryEntry.equivalent(test2DictionaryEntry)); + assertTrue(test2DictionaryEntry.equivalent(testDictionaryEntry)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.DictionaryEntry#setKey}. + */ + public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDictionaryEntry.getKey()); +// testDictionaryEntry.setKey(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDictionaryEntry.getKey()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.DictionaryEntry#setValue}. + */ + public void testDictionaryEntrysetValue() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDictionaryEntry.getValue()); +// testDictionaryEntry.setValue(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDictionaryEntry.getValue()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java b/generated/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java new file mode 100644 index 000000000..9a5805a93 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java @@ -0,0 +1,133 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.ElementCollection.ElementCollectionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ElementCollectionTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ElementCollectionBuilder builderForElementCollectionTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ElementCollectionBuilder retval = new ElementCollectionBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .getelement.add(Element) + .getrootElement.add(Element) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.ElementCollection#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testElementCollection.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ElementCollection#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.ElementCollection", testElementCollection.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ElementCollection#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ElementCollection: "+TEST_OBJECT_URI, testElementCollection.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ElementCollection#Element(org.spdx.library.model.core.ElementCollection.ElementCollectionBuilder)}. + */ + public void testElementCollectionElementCollectionBuilder() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ElementCollection test2ElementCollection = builderForElementCollectionTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testElementCollection.equivalent(test2ElementCollection)); + assertTrue(test2ElementCollection.equivalent(testElementCollection)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ElementCollection#getElement}. + */ + public void testElementCollectionsetElement() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getElement())); +// testElementCollection.getElement().clear(); +// testElementCollection.getElement().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getElement())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ElementCollection#getRootElement}. + */ + public void testElementCollectionsetRootElement() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getRootElement())); +// testElementCollection.getRootElement().clear(); +// testElementCollection.getRootElement().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getRootElement())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ElementTest.java b/generated/src/test/java/org/spdx/library/model/core/ElementTest.java new file mode 100644 index 000000000..18621c60d --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ElementTest.java @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Element.ElementBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ElementTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ElementBuilder builderForElementTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ElementBuilder retval = new ElementBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setdescription("A string") + .setsummary("A string") + .getexternalReference.add(ExternalReference) + .getexternalIdentifier.add(ExternalIdentifier) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testElement.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Element", testElement.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Element: "+TEST_OBJECT_URI, testElement.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#Element(org.spdx.library.model.core.Element.ElementBuilder)}. + */ + public void testElementElementBuilder() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Element test2Element = builderForElementTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testElement.equivalent(test2Element)); + assertTrue(test2Element.equivalent(testElement)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#setDescription}. + */ + public void testElementsetDescription() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testElement.getDescription()); +// testElement.setDescription(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testElement.getDescription()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#setSummary}. + */ + public void testElementsetSummary() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testElement.getSummary()); +// testElement.setSummary(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testElement.getSummary()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#getExternalReference}. + */ + public void testElementsetExternalReference() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalReference())); +// testElement.getExternalReference().clear(); +// testElement.getExternalReference().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalReference())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Element#getExternalIdentifier}. + */ + public void testElementsetExternalIdentifier() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifier())); +// testElement.getExternalIdentifier().clear(); +// testElement.getExternalIdentifier().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifier())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java b/generated/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java new file mode 100644 index 000000000..5c1682e21 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java @@ -0,0 +1,168 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.ExternalIdentifier.ExternalIdentifierBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExternalIdentifierTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExternalIdentifierBuilder builderForExternalIdentifierTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExternalIdentifierBuilder retval = new ExternalIdentifierBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setexternalIdentifierType(ExternalIdentifierType.ENUM) + .setissuingAuthority("A string") + .setidentifier("A string") + .setcomment("A string") + .getidentifierLocator.add("Test string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExternalIdentifier.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.ExternalIdentifier", testExternalIdentifier.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExternalIdentifier: "+TEST_OBJECT_URI, testExternalIdentifier.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#Element(org.spdx.library.model.core.ExternalIdentifier.ExternalIdentifierBuilder)}. + */ + public void testExternalIdentifierExternalIdentifierBuilder() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ExternalIdentifier test2ExternalIdentifier = builderForExternalIdentifierTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExternalIdentifier.equivalent(test2ExternalIdentifier)); + assertTrue(test2ExternalIdentifier.equivalent(testExternalIdentifier)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setExternalIdentifierType}. + */ + public void testExternalIdentifiersetExternalIdentifierType() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalIdentifier.getExternalIdentifierType()); +// testExternalIdentifier.setExternalIdentifierType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getExternalIdentifierType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setIssuingAuthority}. + */ + public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalIdentifier.getIssuingAuthority()); +// testExternalIdentifier.setIssuingAuthority(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getIssuingAuthority()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setIdentifier}. + */ + public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalIdentifier.getIdentifier()); +// testExternalIdentifier.setIdentifier(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getIdentifier()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setComment}. + */ + public void testExternalIdentifiersetComment() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalIdentifier.getComment()); +// testExternalIdentifier.setComment(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getComment()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#getIdentifierLocator}. + */ + public void testExternalIdentifiergetIdentifierLocator() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testExternalIdentifier.getIdentifierLocator())); +// testExternalIdentifier.getIdentifierLocator().clear(); +// testExternalIdentifier.getIdentifierLocator().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testExternalIdentifier.getIdentifierLocator())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ExternalMapTest.java b/generated/src/test/java/org/spdx/library/model/core/ExternalMapTest.java new file mode 100644 index 000000000..f234defe1 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ExternalMapTest.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.ExternalMap.ExternalMapBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExternalMapTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExternalMapBuilder builderForExternalMapTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExternalMapBuilder retval = new ExternalMapBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setdefiningDocument("A string") + .setlocationHint("A string") + .setexternalId("A string") + .getverifiedUsing.add(IntegrityMethod) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExternalMap.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.ExternalMap", testExternalMap.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExternalMap: "+TEST_OBJECT_URI, testExternalMap.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#Element(org.spdx.library.model.core.ExternalMap.ExternalMapBuilder)}. + */ + public void testExternalMapExternalMapBuilder() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ExternalMap test2ExternalMap = builderForExternalMapTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExternalMap.equivalent(test2ExternalMap)); + assertTrue(test2ExternalMap.equivalent(testExternalMap)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#setDefiningDocument}. + */ + public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalMap.getDefiningDocument()); +// testExternalMap.setDefiningDocument(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalMap.getDefiningDocument()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#setLocationHint}. + */ + public void testExternalMapsetLocationHint() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalMap.getLocationHint()); +// testExternalMap.setLocationHint(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalMap.getLocationHint()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#setExternalId}. + */ + public void testExternalMapsetExternalId() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalMap.getExternalId()); +// testExternalMap.setExternalId(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalMap.getExternalId()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalMap#getVerifiedUsing}. + */ + public void testExternalMapsetVerifiedUsing() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testExternalMap.getVerifiedUsing())); +// testExternalMap.getVerifiedUsing().clear(); +// testExternalMap.getVerifiedUsing().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testExternalMap.getVerifiedUsing())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java b/generated/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java new file mode 100644 index 000000000..7441feb90 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.ExternalReference.ExternalReferenceBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExternalReferenceTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExternalReferenceBuilder builderForExternalReferenceTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExternalReferenceBuilder retval = new ExternalReferenceBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setexternalReferenceType(ExternalReferenceType.ENUM) + .setcontentType("A string") + .setcomment("A string") + .getlocator.add("Test string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExternalReference.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.ExternalReference", testExternalReference.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExternalReference: "+TEST_OBJECT_URI, testExternalReference.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#Element(org.spdx.library.model.core.ExternalReference.ExternalReferenceBuilder)}. + */ + public void testExternalReferenceExternalReferenceBuilder() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ExternalReference test2ExternalReference = builderForExternalReferenceTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExternalReference.equivalent(test2ExternalReference)); + assertTrue(test2ExternalReference.equivalent(testExternalReference)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#setExternalReferenceType}. + */ + public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalReference.getExternalReferenceType()); +// testExternalReference.setExternalReferenceType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalReference.getExternalReferenceType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#setContentType}. + */ + public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalReference.getContentType()); +// testExternalReference.setContentType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalReference.getContentType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#setComment}. + */ + public void testExternalReferencesetComment() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExternalReference.getComment()); +// testExternalReference.setComment(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExternalReference.getComment()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.ExternalReference#getLocator}. + */ + public void testExternalReferencegetLocator() throws InvalidSPDXAnalysisException { + ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testExternalReference.getLocator())); +// testExternalReference.getLocator().clear(); +// testExternalReference.getLocator().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testExternalReference.getLocator())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/HashTest.java b/generated/src/test/java/org/spdx/library/model/core/HashTest.java new file mode 100644 index 000000000..307aec391 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/HashTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Hash.HashBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class HashTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static HashBuilder builderForHashTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + HashBuilder retval = new HashBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setalgorithm(HashAlgorithm.ENUM) + .sethashValue("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Hash#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testHash.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Hash#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Hash", testHash.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Hash#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Hash: "+TEST_OBJECT_URI, testHash.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Hash#Element(org.spdx.library.model.core.Hash.HashBuilder)}. + */ + public void testHashHashBuilder() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Hash test2Hash = builderForHashTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testHash.equivalent(test2Hash)); + assertTrue(test2Hash.equivalent(testHash)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Hash#setAlgorithm}. + */ + public void testHashsetAlgorithm() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testHash.getAlgorithm()); +// testHash.setAlgorithm(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testHash.getAlgorithm()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Hash#setHashValue}. + */ + public void testHashsetHashValue() throws InvalidSPDXAnalysisException { + Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testHash.getHashValue()); +// testHash.setHashValue(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testHash.getHashValue()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java b/generated/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java new file mode 100644 index 000000000..d1da4df55 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.IntegrityMethod.IntegrityMethodBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class IntegrityMethodTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static IntegrityMethodBuilder builderForIntegrityMethodTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + IntegrityMethodBuilder retval = new IntegrityMethodBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setcomment("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.IntegrityMethod#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testIntegrityMethod.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.IntegrityMethod#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.IntegrityMethod", testIntegrityMethod.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.IntegrityMethod#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("IntegrityMethod: "+TEST_OBJECT_URI, testIntegrityMethod.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.IntegrityMethod#Element(org.spdx.library.model.core.IntegrityMethod.IntegrityMethodBuilder)}. + */ + public void testIntegrityMethodIntegrityMethodBuilder() throws InvalidSPDXAnalysisException { + IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + IntegrityMethod test2IntegrityMethod = builderForIntegrityMethodTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testIntegrityMethod.equivalent(test2IntegrityMethod)); + assertTrue(test2IntegrityMethod.equivalent(testIntegrityMethod)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.IntegrityMethod#setComment}. + */ + public void testIntegrityMethodsetComment() throws InvalidSPDXAnalysisException { + IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testIntegrityMethod.getComment()); +// testIntegrityMethod.setComment(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testIntegrityMethod.getComment()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java new file mode 100644 index 000000000..b8ef37a11 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class LifecycleScopedRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static LifecycleScopedRelationshipBuilder builderForLifecycleScopedRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + LifecycleScopedRelationshipBuilder retval = new LifecycleScopedRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setscope(LifecycleScopeType.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testLifecycleScopedRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.LifecycleScopedRelationship", testLifecycleScopedRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("LifecycleScopedRelationship: "+TEST_OBJECT_URI, testLifecycleScopedRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#Element(org.spdx.library.model.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder)}. + */ + public void testLifecycleScopedRelationshipLifecycleScopedRelationshipBuilder() throws InvalidSPDXAnalysisException { + LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + LifecycleScopedRelationship test2LifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testLifecycleScopedRelationship.equivalent(test2LifecycleScopedRelationship)); + assertTrue(test2LifecycleScopedRelationship.equivalent(testLifecycleScopedRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#setScope}. + */ + public void testLifecycleScopedRelationshipsetScope() throws InvalidSPDXAnalysisException { + LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLifecycleScopedRelationship.getScope()); +// testLifecycleScopedRelationship.setScope(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLifecycleScopedRelationship.getScope()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java b/generated/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java new file mode 100644 index 000000000..c86fab22f --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.NamespaceMap.NamespaceMapBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class NamespaceMapTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static NamespaceMapBuilder builderForNamespaceMapTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + NamespaceMapBuilder retval = new NamespaceMapBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setprefix("A string") + .setnamespace("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.NamespaceMap#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testNamespaceMap.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.NamespaceMap#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.NamespaceMap", testNamespaceMap.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.NamespaceMap#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("NamespaceMap: "+TEST_OBJECT_URI, testNamespaceMap.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.NamespaceMap#Element(org.spdx.library.model.core.NamespaceMap.NamespaceMapBuilder)}. + */ + public void testNamespaceMapNamespaceMapBuilder() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + NamespaceMap test2NamespaceMap = builderForNamespaceMapTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testNamespaceMap.equivalent(test2NamespaceMap)); + assertTrue(test2NamespaceMap.equivalent(testNamespaceMap)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.NamespaceMap#setPrefix}. + */ + public void testNamespaceMapsetPrefix() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testNamespaceMap.getPrefix()); +// testNamespaceMap.setPrefix(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testNamespaceMap.getPrefix()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.NamespaceMap#setNamespace}. + */ + public void testNamespaceMapsetNamespace() throws InvalidSPDXAnalysisException { + NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testNamespaceMap.getNamespace()); +// testNamespaceMap.setNamespace(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testNamespaceMap.getNamespace()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/OrganizationTest.java b/generated/src/test/java/org/spdx/library/model/core/OrganizationTest.java new file mode 100644 index 000000000..6b89fcfa1 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/OrganizationTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Organization.OrganizationBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class OrganizationTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static OrganizationBuilder builderForOrganizationTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + OrganizationBuilder retval = new OrganizationBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Organization#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testOrganization.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Organization#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Organization", testOrganization.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Organization#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Organization: "+TEST_OBJECT_URI, testOrganization.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Organization#Element(org.spdx.library.model.core.Organization.OrganizationBuilder)}. + */ + public void testOrganizationOrganizationBuilder() throws InvalidSPDXAnalysisException { + Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Organization test2Organization = builderForOrganizationTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testOrganization.equivalent(test2Organization)); + assertTrue(test2Organization.equivalent(testOrganization)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/PayloadTest.java b/generated/src/test/java/org/spdx/library/model/core/PayloadTest.java new file mode 100644 index 000000000..ca8b90d85 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/PayloadTest.java @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Payload.PayloadBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class PayloadTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static PayloadBuilder builderForPayloadTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + PayloadBuilder retval = new PayloadBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setcreationInfo(new CreationInfo()) + .getnamespaces.add(NamespaceMap) + .getimports.add(ExternalMap) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testPayload.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Payload", testPayload.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Payload: "+TEST_OBJECT_URI, testPayload.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#Element(org.spdx.library.model.core.Payload.PayloadBuilder)}. + */ + public void testPayloadPayloadBuilder() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Payload test2Payload = builderForPayloadTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testPayload.equivalent(test2Payload)); + assertTrue(test2Payload.equivalent(testPayload)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#setCreationInfo}. + */ + public void testPayloadsetCreationInfo() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testPayload.getCreationInfo()); +// testPayload.setCreationInfo(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testPayload.getCreationInfo()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#getNamespaces}. + */ + public void testPayloadsetNamespaces() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getNamespaces())); +// testPayload.getNamespaces().clear(); +// testPayload.getNamespaces().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getNamespaces())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Payload#getImports}. + */ + public void testPayloadsetImports() throws InvalidSPDXAnalysisException { + Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getImports())); +// testPayload.getImports().clear(); +// testPayload.getImports().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getImports())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/PersonTest.java b/generated/src/test/java/org/spdx/library/model/core/PersonTest.java new file mode 100644 index 000000000..3df485d34 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/PersonTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Person.PersonBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class PersonTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static PersonBuilder builderForPersonTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + PersonBuilder retval = new PersonBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Person#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testPerson.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Person#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Person", testPerson.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Person#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Person: "+TEST_OBJECT_URI, testPerson.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Person#Element(org.spdx.library.model.core.Person.PersonBuilder)}. + */ + public void testPersonPersonBuilder() throws InvalidSPDXAnalysisException { + Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Person test2Person = builderForPersonTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testPerson.equivalent(test2Person)); + assertTrue(test2Person.equivalent(testPerson)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java b/generated/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java new file mode 100644 index 000000000..584660640 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.PositiveIntegerRange.PositiveIntegerRangeBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class PositiveIntegerRangeTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static PositiveIntegerRangeBuilder builderForPositiveIntegerRangeTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + PositiveIntegerRangeBuilder retval = new PositiveIntegerRangeBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setend(57) + .setbegin(57) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testPositiveIntegerRange.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.PositiveIntegerRange", testPositiveIntegerRange.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("PositiveIntegerRange: "+TEST_OBJECT_URI, testPositiveIntegerRange.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#Element(org.spdx.library.model.core.PositiveIntegerRange.PositiveIntegerRangeBuilder)}. + */ + public void testPositiveIntegerRangePositiveIntegerRangeBuilder() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + PositiveIntegerRange test2PositiveIntegerRange = builderForPositiveIntegerRangeTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testPositiveIntegerRange.equivalent(test2PositiveIntegerRange)); + assertTrue(test2PositiveIntegerRange.equivalent(testPositiveIntegerRange)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#setEnd}. + */ + public void testPositiveIntegerRangesetEnd() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testPositiveIntegerRange.getEnd()); +// testPositiveIntegerRange.setEnd(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testPositiveIntegerRange.getEnd()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#setBegin}. + */ + public void testPositiveIntegerRangesetBegin() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testPositiveIntegerRange.getBegin()); +// testPositiveIntegerRange.setBegin(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testPositiveIntegerRange.getBegin()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/RelationshipTest.java b/generated/src/test/java/org/spdx/library/model/core/RelationshipTest.java new file mode 100644 index 000000000..02b44a931 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/RelationshipTest.java @@ -0,0 +1,180 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Relationship.RelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class RelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static RelationshipBuilder builderForRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + RelationshipBuilder retval = new RelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setfrom(Element testElement) + .setrelationshipType(RelationshipType.ENUM) + .setcompleteness(RelationshipCompleteness.ENUM) + .setstartTime("A string") + .setendTime("A string") + .getto.add(Element) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Relationship", testRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Relationship: "+TEST_OBJECT_URI, testRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#Element(org.spdx.library.model.core.Relationship.RelationshipBuilder)}. + */ + public void testRelationshipRelationshipBuilder() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Relationship test2Relationship = builderForRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testRelationship.equivalent(test2Relationship)); + assertTrue(test2Relationship.equivalent(testRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#setFrom}. + */ + public void testRelationshipsetFrom() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testRelationship.getFrom()); +// testRelationship.setFrom(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testRelationship.getFrom()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#setRelationshipType}. + */ + public void testRelationshipsetRelationshipType() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testRelationship.getRelationshipType()); +// testRelationship.setRelationshipType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testRelationship.getRelationshipType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#setCompleteness}. + */ + public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testRelationship.getCompleteness()); +// testRelationship.setCompleteness(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testRelationship.getCompleteness()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#setStartTime}. + */ + public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testRelationship.getStartTime()); +// testRelationship.setStartTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testRelationship.getStartTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#setEndTime}. + */ + public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testRelationship.getEndTime()); +// testRelationship.setEndTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testRelationship.getEndTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.core.Relationship#getTo}. + */ + public void testRelationshipsetTo() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testRelationship.getTo())); +// testRelationship.getTo().clear(); +// testRelationship.getTo().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testRelationship.getTo())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java b/generated/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java new file mode 100644 index 000000000..332b4cd59 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.SoftwareAgent.SoftwareAgentBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SoftwareAgentTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SoftwareAgentBuilder builderForSoftwareAgentTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SoftwareAgentBuilder retval = new SoftwareAgentBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.SoftwareAgent#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSoftwareAgent.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.SoftwareAgent#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.SoftwareAgent", testSoftwareAgent.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.SoftwareAgent#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SoftwareAgent: "+TEST_OBJECT_URI, testSoftwareAgent.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.SoftwareAgent#Element(org.spdx.library.model.core.SoftwareAgent.SoftwareAgentBuilder)}. + */ + public void testSoftwareAgentSoftwareAgentBuilder() throws InvalidSPDXAnalysisException { + SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SoftwareAgent test2SoftwareAgent = builderForSoftwareAgentTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSoftwareAgent.equivalent(test2SoftwareAgent)); + assertTrue(test2SoftwareAgent.equivalent(testSoftwareAgent)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java b/generated/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java new file mode 100644 index 000000000..538d02a7e --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.SpdxDocument.SpdxDocumentBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SpdxDocumentTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SpdxDocumentBuilder builderForSpdxDocumentTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SpdxDocumentBuilder retval = new SpdxDocumentBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.SpdxDocument#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSpdxDocument.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.SpdxDocument#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.SpdxDocument", testSpdxDocument.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.SpdxDocument#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SpdxDocument: "+TEST_OBJECT_URI, testSpdxDocument.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.SpdxDocument#Element(org.spdx.library.model.core.SpdxDocument.SpdxDocumentBuilder)}. + */ + public void testSpdxDocumentSpdxDocumentBuilder() throws InvalidSPDXAnalysisException { + SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SpdxDocument test2SpdxDocument = builderForSpdxDocumentTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSpdxDocument.equivalent(test2SpdxDocument)); + assertTrue(test2SpdxDocument.equivalent(testSpdxDocument)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/core/ToolTest.java b/generated/src/test/java/org/spdx/library/model/core/ToolTest.java new file mode 100644 index 000000000..121b0dd31 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/core/ToolTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.core.Tool.ToolBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ToolTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ToolBuilder builderForToolTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ToolBuilder retval = new ToolBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.core.Tool#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testTool.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.core.Tool#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Tool", testTool.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Tool#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Tool: "+TEST_OBJECT_URI, testTool.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.core.Tool#Element(org.spdx.library.model.core.Tool.ToolBuilder)}. + */ + public void testToolToolBuilder() throws InvalidSPDXAnalysisException { + Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Tool test2Tool = builderForToolTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testTool.equivalent(test2Tool)); + assertTrue(test2Tool.equivalent(testTool)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/dataset/DatasetTest.java b/generated/src/test/java/org/spdx/library/model/dataset/DatasetTest.java new file mode 100644 index 000000000..b3fd4e453 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/dataset/DatasetTest.java @@ -0,0 +1,268 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.dataset; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.dataset.Dataset.DatasetBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class DatasetTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static DatasetBuilder builderForDatasetTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + DatasetBuilder retval = new DatasetBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setsensitivePersonalInformation(new PresenceType()) + .setconfidentialityLevel(ConfidentialityLevelType.ENUM) + .setdatasetAvailability(DatasetAvailabilityType.ENUM) + .setdatasetSize(57) + .setintendedUse("A string") + .setdatasetNoise("A string") + .setdataCollectionProcess("A string") + .setdatasetUpdateMechanism("A string") + .getsensor.add(DictionaryEntry) + .getanonymizationMethodUsed.add("Test string") + .getdataPreprocessing.add("Test string") + .getknownBias.add("Test string") + .getdatasetType.add(DatasetType.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testDataset.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Dataset.Dataset", testDataset.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Dataset: "+TEST_OBJECT_URI, testDataset.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#Element(org.spdx.library.model.dataset.Dataset.DatasetBuilder)}. + */ + public void testDatasetDatasetBuilder() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Dataset test2Dataset = builderForDatasetTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testDataset.equivalent(test2Dataset)); + assertTrue(test2Dataset.equivalent(testDataset)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setSensitivePersonalInformation}. + */ + public void testDatasetsetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getSensitivePersonalInformation()); +// testDataset.setSensitivePersonalInformation(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getSensitivePersonalInformation()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setConfidentialityLevel}. + */ + public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getConfidentialityLevel()); +// testDataset.setConfidentialityLevel(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getConfidentialityLevel()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetAvailability}. + */ + public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getDatasetAvailability()); +// testDataset.setDatasetAvailability(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetAvailability()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetSize}. + */ + public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getDatasetSize()); +// testDataset.setDatasetSize(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetSize()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setIntendedUse}. + */ + public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getIntendedUse()); +// testDataset.setIntendedUse(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getIntendedUse()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetNoise}. + */ + public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getDatasetNoise()); +// testDataset.setDatasetNoise(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetNoise()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setDataCollectionProcess}. + */ + public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getDataCollectionProcess()); +// testDataset.setDataCollectionProcess(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getDataCollectionProcess()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetUpdateMechanism}. + */ + public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testDataset.getDatasetUpdateMechanism()); +// testDataset.setDatasetUpdateMechanism(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetUpdateMechanism()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#getSensor}. + */ + public void testDatasetsetSensor() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testDataset.getSensor())); +// testDataset.getSensor().clear(); +// testDataset.getSensor().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testDataset.getSensor())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#getAnonymizationMethodUsed}. + */ + public void testDatasetgetAnonymizationMethodUsed() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getAnonymizationMethodUsed())); +// testDataset.getAnonymizationMethodUsed().clear(); +// testDataset.getAnonymizationMethodUsed().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getAnonymizationMethodUsed())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#getDataPreprocessing}. + */ + public void testDatasetgetDataPreprocessing() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getDataPreprocessing())); +// testDataset.getDataPreprocessing().clear(); +// testDataset.getDataPreprocessing().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getDataPreprocessing())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#getKnownBias}. + */ + public void testDatasetgetKnownBias() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getKnownBias())); +// testDataset.getKnownBias().clear(); +// testDataset.getKnownBias().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getKnownBias())); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.dataset.Dataset#getDatasetType}. + */ + public void testDatasetgetDatasetType() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getDatasetType())); +// testDataset.getDatasetType().clear(); +// testDataset.getDatasetType().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getDatasetType())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java b/generated/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java new file mode 100644 index 000000000..733208b10 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.expandedlicense; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ConjunctiveLicenseSetTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ConjunctiveLicenseSetBuilder builderForConjunctiveLicenseSetTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSetBuilder retval = new ConjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testConjunctiveLicenseSet.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExpandedLicense.ConjunctiveLicenseSet", testConjunctiveLicenseSet.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ConjunctiveLicenseSet: "+TEST_OBJECT_URI, testConjunctiveLicenseSet.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#Element(org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder)}. + */ + public void testConjunctiveLicenseSetConjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ConjunctiveLicenseSet test2ConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testConjunctiveLicenseSet.equivalent(test2ConjunctiveLicenseSet)); + assertTrue(test2ConjunctiveLicenseSet.equivalent(testConjunctiveLicenseSet)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java b/generated/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java new file mode 100644 index 000000000..f0bae2b8b --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.expandedlicense; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class DisjunctiveLicenseSetTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static DisjunctiveLicenseSetBuilder builderForDisjunctiveLicenseSetTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSetBuilder retval = new DisjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testDisjunctiveLicenseSet.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExpandedLicense.DisjunctiveLicenseSet", testDisjunctiveLicenseSet.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("DisjunctiveLicenseSet: "+TEST_OBJECT_URI, testDisjunctiveLicenseSet.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#Element(org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder)}. + */ + public void testDisjunctiveLicenseSetDisjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + DisjunctiveLicenseSet test2DisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testDisjunctiveLicenseSet.equivalent(test2DisjunctiveLicenseSet)); + assertTrue(test2DisjunctiveLicenseSet.equivalent(testDisjunctiveLicenseSet)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java b/generated/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java new file mode 100644 index 000000000..cb78dc3c6 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.expandedlicense; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.expandedlicense.ExtendableLicense.ExtendableLicenseBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExtendableLicenseTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExtendableLicenseBuilder builderForExtendableLicenseTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExtendableLicenseBuilder retval = new ExtendableLicenseBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExtendableLicense.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExpandedLicense.ExtendableLicense", testExtendableLicense.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExtendableLicense: "+TEST_OBJECT_URI, testExtendableLicense.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#Element(org.spdx.library.model.expandedlicense.ExtendableLicense.ExtendableLicenseBuilder)}. + */ + public void testExtendableLicenseExtendableLicenseBuilder() throws InvalidSPDXAnalysisException { + ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ExtendableLicense test2ExtendableLicense = builderForExtendableLicenseTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExtendableLicense.equivalent(test2ExtendableLicense)); + assertTrue(test2ExtendableLicense.equivalent(testExtendableLicense)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java b/generated/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java new file mode 100644 index 000000000..d732814f3 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class AnyLicenseInfoTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static AnyLicenseInfoBuilder builderForAnyLicenseInfoTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + AnyLicenseInfoBuilder retval = new AnyLicenseInfoBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testAnyLicenseInfo.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.AnyLicenseInfo", testAnyLicenseInfo.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("AnyLicenseInfo: "+TEST_OBJECT_URI, testAnyLicenseInfo.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#Element(org.spdx.library.model.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder)}. + */ + public void testAnyLicenseInfoAnyLicenseInfoBuilder() throws InvalidSPDXAnalysisException { + AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AnyLicenseInfo test2AnyLicenseInfo = builderForAnyLicenseInfoTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testAnyLicenseInfo.equivalent(test2AnyLicenseInfo)); + assertTrue(test2AnyLicenseInfo.equivalent(testAnyLicenseInfo)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java b/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java new file mode 100644 index 000000000..3cf93c6e4 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class CustomLicenseAdditionTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static CustomLicenseAdditionBuilder builderForCustomLicenseAdditionTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + CustomLicenseAdditionBuilder retval = new CustomLicenseAdditionBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testCustomLicenseAddition.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.CustomLicenseAddition", testCustomLicenseAddition.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("CustomLicenseAddition: "+TEST_OBJECT_URI, testCustomLicenseAddition.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#Element(org.spdx.library.model.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder)}. + */ + public void testCustomLicenseAdditionCustomLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { + CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + CustomLicenseAddition test2CustomLicenseAddition = builderForCustomLicenseAdditionTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testCustomLicenseAddition.equivalent(test2CustomLicenseAddition)); + assertTrue(test2CustomLicenseAddition.equivalent(testCustomLicenseAddition)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java b/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java new file mode 100644 index 000000000..74de52977 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.CustomLicense.CustomLicenseBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class CustomLicenseTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static CustomLicenseBuilder builderForCustomLicenseTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + CustomLicenseBuilder retval = new CustomLicenseBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicense#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testCustomLicense.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicense#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.CustomLicense", testCustomLicense.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicense#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("CustomLicense: "+TEST_OBJECT_URI, testCustomLicense.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.CustomLicense#Element(org.spdx.library.model.licensing.CustomLicense.CustomLicenseBuilder)}. + */ + public void testCustomLicenseCustomLicenseBuilder() throws InvalidSPDXAnalysisException { + CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + CustomLicense test2CustomLicense = builderForCustomLicenseTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testCustomLicense.equivalent(test2CustomLicense)); + assertTrue(test2CustomLicense.equivalent(testCustomLicense)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java b/generated/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java new file mode 100644 index 000000000..5f9ec9089 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.LicenseAddition.LicenseAdditionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class LicenseAdditionTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static LicenseAdditionBuilder builderForLicenseAdditionTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + LicenseAdditionBuilder retval = new LicenseAdditionBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setisDeprecatedAdditionId(true) + .setstandardAdditionTemplate("A string") + .setadditionText("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testLicenseAddition.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.LicenseAddition", testLicenseAddition.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("LicenseAddition: "+TEST_OBJECT_URI, testLicenseAddition.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#Element(org.spdx.library.model.licensing.LicenseAddition.LicenseAdditionBuilder)}. + */ + public void testLicenseAdditionLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + LicenseAddition test2LicenseAddition = builderForLicenseAdditionTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testLicenseAddition.equivalent(test2LicenseAddition)); + assertTrue(test2LicenseAddition.equivalent(testLicenseAddition)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#setIsDeprecatedAdditionId}. + */ + public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicenseAddition.getIsDeprecatedAdditionId()); +// testLicenseAddition.setIsDeprecatedAdditionId(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicenseAddition.getIsDeprecatedAdditionId()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#setStandardAdditionTemplate}. + */ + public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicenseAddition.getStandardAdditionTemplate()); +// testLicenseAddition.setStandardAdditionTemplate(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicenseAddition.getStandardAdditionTemplate()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#setAdditionText}. + */ + public void testLicenseAdditionsetAdditionText() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicenseAddition.getAdditionText()); +// testLicenseAddition.setAdditionText(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicenseAddition.getAdditionText()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java b/generated/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java new file mode 100644 index 000000000..d90c3e7d6 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.LicenseExpression.LicenseExpressionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class LicenseExpressionTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static LicenseExpressionBuilder builderForLicenseExpressionTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + LicenseExpressionBuilder retval = new LicenseExpressionBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setlicenseExpression("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testLicenseExpression.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.LicenseExpression", testLicenseExpression.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("LicenseExpression: "+TEST_OBJECT_URI, testLicenseExpression.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#Element(org.spdx.library.model.licensing.LicenseExpression.LicenseExpressionBuilder)}. + */ + public void testLicenseExpressionLicenseExpressionBuilder() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + LicenseExpression test2LicenseExpression = builderForLicenseExpressionTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testLicenseExpression.equivalent(test2LicenseExpression)); + assertTrue(test2LicenseExpression.equivalent(testLicenseExpression)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#setLicenseExpression}. + */ + public void testLicenseExpressionsetLicenseExpression() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicenseExpression.getLicenseExpression()); +// testLicenseExpression.setLicenseExpression(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicenseExpression.getLicenseExpression()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/LicenseTest.java b/generated/src/test/java/org/spdx/library/model/licensing/LicenseTest.java new file mode 100644 index 000000000..806285d4a --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/LicenseTest.java @@ -0,0 +1,179 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.License.LicenseBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class LicenseTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static LicenseBuilder builderForLicenseTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + LicenseBuilder retval = new LicenseBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setisFsfLibre(true) + .setisDeprecatedLicenseId(true) + .setisOsiApproved(true) + .setstandardLicenseTemplate("A string") + .setstandardLicenseHeader("A string") + .setlicenseText("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testLicense.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.License", testLicense.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("License: "+TEST_OBJECT_URI, testLicense.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#Element(org.spdx.library.model.licensing.License.LicenseBuilder)}. + */ + public void testLicenseLicenseBuilder() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + License test2License = builderForLicenseTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testLicense.equivalent(test2License)); + assertTrue(test2License.equivalent(testLicense)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#setIsFsfLibre}. + */ + public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicense.getIsFsfLibre()); +// testLicense.setIsFsfLibre(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicense.getIsFsfLibre()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#setIsDeprecatedLicenseId}. + */ + public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicense.getIsDeprecatedLicenseId()); +// testLicense.setIsDeprecatedLicenseId(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicense.getIsDeprecatedLicenseId()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#setIsOsiApproved}. + */ + public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicense.getIsOsiApproved()); +// testLicense.setIsOsiApproved(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicense.getIsOsiApproved()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#setStandardLicenseTemplate}. + */ + public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicense.getStandardLicenseTemplate()); +// testLicense.setStandardLicenseTemplate(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicense.getStandardLicenseTemplate()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#setStandardLicenseHeader}. + */ + public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicense.getStandardLicenseHeader()); +// testLicense.setStandardLicenseHeader(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicense.getStandardLicenseHeader()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.License#setLicenseText}. + */ + public void testLicensesetLicenseText() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testLicense.getLicenseText()); +// testLicense.setLicenseText(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testLicense.getLicenseText()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java b/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java new file mode 100644 index 000000000..f1c9f1e09 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ListedLicenseExceptionTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ListedLicenseExceptionBuilder builderForListedLicenseExceptionTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ListedLicenseExceptionBuilder retval = new ListedLicenseExceptionBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testListedLicenseException.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.ListedLicenseException", testListedLicenseException.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ListedLicenseException: "+TEST_OBJECT_URI, testListedLicenseException.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#Element(org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder)}. + */ + public void testListedLicenseExceptionListedLicenseExceptionBuilder() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ListedLicenseException test2ListedLicenseException = builderForListedLicenseExceptionTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testListedLicenseException.equivalent(test2ListedLicenseException)); + assertTrue(test2ListedLicenseException.equivalent(testListedLicenseException)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java b/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java new file mode 100644 index 000000000..ec72fd264 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.ListedLicense.ListedLicenseBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ListedLicenseTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ListedLicenseBuilder builderForListedLicenseTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ListedLicenseBuilder retval = new ListedLicenseBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicense#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testListedLicense.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicense#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.ListedLicense", testListedLicense.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicense#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ListedLicense: "+TEST_OBJECT_URI, testListedLicense.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.ListedLicense#Element(org.spdx.library.model.licensing.ListedLicense.ListedLicenseBuilder)}. + */ + public void testListedLicenseListedLicenseBuilder() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ListedLicense test2ListedLicense = builderForListedLicenseTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testListedLicense.equivalent(test2ListedLicense)); + assertTrue(test2ListedLicense.equivalent(testListedLicense)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java b/generated/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java new file mode 100644 index 000000000..1ec9fe0b7 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.OrLaterOperator.OrLaterOperatorBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class OrLaterOperatorTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static OrLaterOperatorBuilder builderForOrLaterOperatorTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + OrLaterOperatorBuilder retval = new OrLaterOperatorBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testOrLaterOperator.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.OrLaterOperator", testOrLaterOperator.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("OrLaterOperator: "+TEST_OBJECT_URI, testOrLaterOperator.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#Element(org.spdx.library.model.licensing.OrLaterOperator.OrLaterOperatorBuilder)}. + */ + public void testOrLaterOperatorOrLaterOperatorBuilder() throws InvalidSPDXAnalysisException { + OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + OrLaterOperator test2OrLaterOperator = builderForOrLaterOperatorTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testOrLaterOperator.equivalent(test2OrLaterOperator)); + assertTrue(test2OrLaterOperator.equivalent(testOrLaterOperator)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java b/generated/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java new file mode 100644 index 000000000..23395583f --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.licensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.licensing.WithAdditionOperator.WithAdditionOperatorBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class WithAdditionOperatorTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static WithAdditionOperatorBuilder builderForWithAdditionOperatorTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + WithAdditionOperatorBuilder retval = new WithAdditionOperatorBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testWithAdditionOperator.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Licensing.WithAdditionOperator", testWithAdditionOperator.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("WithAdditionOperator: "+TEST_OBJECT_URI, testWithAdditionOperator.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#Element(org.spdx.library.model.licensing.WithAdditionOperator.WithAdditionOperatorBuilder)}. + */ + public void testWithAdditionOperatorWithAdditionOperatorBuilder() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + WithAdditionOperator test2WithAdditionOperator = builderForWithAdditionOperatorTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testWithAdditionOperator.equivalent(test2WithAdditionOperator)); + assertTrue(test2WithAdditionOperator.equivalent(testWithAdditionOperator)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..cfaf3b002 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class CvssV2VulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static CvssV2VulnAssessmentRelationshipBuilder builderForCvssV2VulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationshipBuilder retval = new CvssV2VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testCvssV2VulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.CvssV2VulnAssessmentRelationship", testCvssV2VulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("CvssV2VulnAssessmentRelationship: "+TEST_OBJECT_URI, testCvssV2VulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#Element(org.spdx.library.model.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder)}. + */ + public void testCvssV2VulnAssessmentRelationshipCvssV2VulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + CvssV2VulnAssessmentRelationship test2CvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testCvssV2VulnAssessmentRelationship.equivalent(test2CvssV2VulnAssessmentRelationship)); + assertTrue(test2CvssV2VulnAssessmentRelationship.equivalent(testCvssV2VulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..4450a4c90 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class CvssV3VulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static CvssV3VulnAssessmentRelationshipBuilder builderForCvssV3VulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationshipBuilder retval = new CvssV3VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testCvssV3VulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.CvssV3VulnAssessmentRelationship", testCvssV3VulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("CvssV3VulnAssessmentRelationship: "+TEST_OBJECT_URI, testCvssV3VulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#Element(org.spdx.library.model.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder)}. + */ + public void testCvssV3VulnAssessmentRelationshipCvssV3VulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + CvssV3VulnAssessmentRelationship test2CvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testCvssV3VulnAssessmentRelationship.equivalent(test2CvssV3VulnAssessmentRelationship)); + assertTrue(test2CvssV3VulnAssessmentRelationship.equivalent(testCvssV3VulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..0eefc21b0 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class EpssVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static EpssVulnAssessmentRelationshipBuilder builderForEpssVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationshipBuilder retval = new EpssVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setprobability(57) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testEpssVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.EpssVulnAssessmentRelationship", testEpssVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("EpssVulnAssessmentRelationship: "+TEST_OBJECT_URI, testEpssVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#Element(org.spdx.library.model.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder)}. + */ + public void testEpssVulnAssessmentRelationshipEpssVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + EpssVulnAssessmentRelationship test2EpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testEpssVulnAssessmentRelationship.equivalent(test2EpssVulnAssessmentRelationship)); + assertTrue(test2EpssVulnAssessmentRelationship.equivalent(testEpssVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#setProbability}. + */ + public void testEpssVulnAssessmentRelationshipsetProbability() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testEpssVulnAssessmentRelationship.getProbability()); +// testEpssVulnAssessmentRelationship.setProbability(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testEpssVulnAssessmentRelationship.getProbability()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..16c0fd598 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExploitCatalogVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExploitCatalogVulnAssessmentRelationshipBuilder builderForExploitCatalogVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationshipBuilder retval = new ExploitCatalogVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setcatalogType(ExploitCatalogType.ENUM) + .setexploited(true) + .setlocator("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExploitCatalogVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.ExploitCatalogVulnAssessmentRelationship", testExploitCatalogVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExploitCatalogVulnAssessmentRelationship: "+TEST_OBJECT_URI, testExploitCatalogVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#Element(org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder)}. + */ + public void testExploitCatalogVulnAssessmentRelationshipExploitCatalogVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ExploitCatalogVulnAssessmentRelationship test2ExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExploitCatalogVulnAssessmentRelationship.equivalent(test2ExploitCatalogVulnAssessmentRelationship)); + assertTrue(test2ExploitCatalogVulnAssessmentRelationship.equivalent(testExploitCatalogVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#setCatalogType}. + */ + public void testExploitCatalogVulnAssessmentRelationshipsetCatalogType() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getCatalogType()); +// testExploitCatalogVulnAssessmentRelationship.setCatalogType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getCatalogType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#setExploited}. + */ + public void testExploitCatalogVulnAssessmentRelationshipsetExploited() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getExploited()); +// testExploitCatalogVulnAssessmentRelationship.setExploited(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getExploited()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#setLocator}. + */ + public void testExploitCatalogVulnAssessmentRelationshipsetLocator() throws InvalidSPDXAnalysisException { + ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getLocator()); +// testExploitCatalogVulnAssessmentRelationship.setLocator(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getLocator()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..aec7a6761 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SsvcVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SsvcVulnAssessmentRelationshipBuilder builderForSsvcVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationshipBuilder retval = new SsvcVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setdecisionType(SsvcDecisionType.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSsvcVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.SsvcVulnAssessmentRelationship", testSsvcVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SsvcVulnAssessmentRelationship: "+TEST_OBJECT_URI, testSsvcVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#Element(org.spdx.library.model.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder)}. + */ + public void testSsvcVulnAssessmentRelationshipSsvcVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SsvcVulnAssessmentRelationship test2SsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSsvcVulnAssessmentRelationship.equivalent(test2SsvcVulnAssessmentRelationship)); + assertTrue(test2SsvcVulnAssessmentRelationship.equivalent(testSsvcVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#setDecisionType}. + */ + public void testSsvcVulnAssessmentRelationshipsetDecisionType() throws InvalidSPDXAnalysisException { + SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSsvcVulnAssessmentRelationship.getDecisionType()); +// testSsvcVulnAssessmentRelationship.setDecisionType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSsvcVulnAssessmentRelationship.getDecisionType()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..e7348d64d --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VexAffectedVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VexAffectedVulnAssessmentRelationshipBuilder builderForVexAffectedVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationshipBuilder retval = new VexAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setactionStatement("A string") + .getactionStatementTime.add("Test string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVexAffectedVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.VexAffectedVulnAssessmentRelationship", testVexAffectedVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("VexAffectedVulnAssessmentRelationship: "+TEST_OBJECT_URI, testVexAffectedVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder)}. + */ + public void testVexAffectedVulnAssessmentRelationshipVexAffectedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + VexAffectedVulnAssessmentRelationship test2VexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVexAffectedVulnAssessmentRelationship.equivalent(test2VexAffectedVulnAssessmentRelationship)); + assertTrue(test2VexAffectedVulnAssessmentRelationship.equivalent(testVexAffectedVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#setActionStatement}. + */ + public void testVexAffectedVulnAssessmentRelationshipsetActionStatement() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVexAffectedVulnAssessmentRelationship.getActionStatement()); +// testVexAffectedVulnAssessmentRelationship.setActionStatement(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVexAffectedVulnAssessmentRelationship.getActionStatement()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#getActionStatementTime}. + */ + public void testVexAffectedVulnAssessmentRelationshipgetActionStatementTime() throws InvalidSPDXAnalysisException { + VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTime())); +// testVexAffectedVulnAssessmentRelationship.getActionStatementTime().clear(); +// testVexAffectedVulnAssessmentRelationship.getActionStatementTime().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTime())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..7399f455c --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VexFixedVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VexFixedVulnAssessmentRelationshipBuilder builderForVexFixedVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VexFixedVulnAssessmentRelationshipBuilder retval = new VexFixedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVexFixedVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.VexFixedVulnAssessmentRelationship", testVexFixedVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("VexFixedVulnAssessmentRelationship: "+TEST_OBJECT_URI, testVexFixedVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder)}. + */ + public void testVexFixedVulnAssessmentRelationshipVexFixedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + VexFixedVulnAssessmentRelationship test2VexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVexFixedVulnAssessmentRelationship.equivalent(test2VexFixedVulnAssessmentRelationship)); + assertTrue(test2VexFixedVulnAssessmentRelationship.equivalent(testVexFixedVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..33c8cddcd --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VexNotAffectedVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VexNotAffectedVulnAssessmentRelationshipBuilder builderForVexNotAffectedVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationshipBuilder retval = new VexNotAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setjustificationType(VexJustificationType.ENUM) + .setimpactStatementTime("A string") + .setimpactStatement("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVexNotAffectedVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.VexNotAffectedVulnAssessmentRelationship", testVexNotAffectedVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("VexNotAffectedVulnAssessmentRelationship: "+TEST_OBJECT_URI, testVexNotAffectedVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder)}. + */ + public void testVexNotAffectedVulnAssessmentRelationshipVexNotAffectedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + VexNotAffectedVulnAssessmentRelationship test2VexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVexNotAffectedVulnAssessmentRelationship.equivalent(test2VexNotAffectedVulnAssessmentRelationship)); + assertTrue(test2VexNotAffectedVulnAssessmentRelationship.equivalent(testVexNotAffectedVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#setJustificationType}. + */ + public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); +// testVexNotAffectedVulnAssessmentRelationship.setJustificationType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatementTime}. + */ + public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); +// testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatement}. + */ + public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatement() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); +// testVexNotAffectedVulnAssessmentRelationship.setImpactStatement(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..cc07fae64 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VexUnderInvestigationVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VexUnderInvestigationVulnAssessmentRelationshipBuilder builderForVexUnderInvestigationVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VexUnderInvestigationVulnAssessmentRelationshipBuilder retval = new VexUnderInvestigationVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVexUnderInvestigationVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.VexUnderInvestigationVulnAssessmentRelationship", testVexUnderInvestigationVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("VexUnderInvestigationVulnAssessmentRelationship: "+TEST_OBJECT_URI, testVexUnderInvestigationVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder)}. + */ + public void testVexUnderInvestigationVulnAssessmentRelationshipVexUnderInvestigationVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + VexUnderInvestigationVulnAssessmentRelationship test2VexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVexUnderInvestigationVulnAssessmentRelationship.equivalent(test2VexUnderInvestigationVulnAssessmentRelationship)); + assertTrue(test2VexUnderInvestigationVulnAssessmentRelationship.equivalent(testVexUnderInvestigationVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..1221be150 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VexVulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VexVulnAssessmentRelationshipBuilder builderForVexVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationshipBuilder retval = new VexVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setstatusNotes("A string") + .setvexVersion("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVexVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.VexVulnAssessmentRelationship", testVexVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("VexVulnAssessmentRelationship: "+TEST_OBJECT_URI, testVexVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder)}. + */ + public void testVexVulnAssessmentRelationshipVexVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + VexVulnAssessmentRelationship test2VexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVexVulnAssessmentRelationship.equivalent(test2VexVulnAssessmentRelationship)); + assertTrue(test2VexVulnAssessmentRelationship.equivalent(testVexVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#setStatusNotes}. + */ + public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVexVulnAssessmentRelationship.getStatusNotes()); +// testVexVulnAssessmentRelationship.setStatusNotes(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVexVulnAssessmentRelationship.getStatusNotes()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#setVexVersion}. + */ + public void testVexVulnAssessmentRelationshipsetVexVersion() throws InvalidSPDXAnalysisException { + VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVexVulnAssessmentRelationship.getVexVersion()); +// testVexVulnAssessmentRelationship.setVexVersion(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVexVulnAssessmentRelationship.getVexVersion()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java new file mode 100644 index 000000000..a71d8d826 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VulnAssessmentRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VulnAssessmentRelationshipBuilder builderForVulnAssessmentRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VulnAssessmentRelationshipBuilder retval = new VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setassessedElement(Element testElement) + .setsuppliedBy(Element testElement) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVulnAssessmentRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.VulnAssessmentRelationship", testVulnAssessmentRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("VulnAssessmentRelationship: "+TEST_OBJECT_URI, testVulnAssessmentRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#Element(org.spdx.library.model.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder)}. + */ + public void testVulnAssessmentRelationshipVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + VulnAssessmentRelationship test2VulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVulnAssessmentRelationship.equivalent(test2VulnAssessmentRelationship)); + assertTrue(test2VulnAssessmentRelationship.equivalent(testVulnAssessmentRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#setAssessedElement}. + */ + public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVulnAssessmentRelationship.getAssessedElement()); +// testVulnAssessmentRelationship.setAssessedElement(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVulnAssessmentRelationship.getAssessedElement()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#setSuppliedBy}. + */ + public void testVulnAssessmentRelationshipsetSuppliedBy() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testVulnAssessmentRelationship.getSuppliedBy()); +// testVulnAssessmentRelationship.setSuppliedBy(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testVulnAssessmentRelationship.getSuppliedBy()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java b/generated/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java new file mode 100644 index 000000000..fb96cfc87 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.security; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.security.Vulnerability.VulnerabilityBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class VulnerabilityTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static VulnerabilityBuilder builderForVulnerabilityTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + VulnerabilityBuilder retval = new VulnerabilityBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.security.Vulnerability#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testVulnerability.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.security.Vulnerability#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Security.Vulnerability", testVulnerability.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.security.Vulnerability#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Vulnerability: "+TEST_OBJECT_URI, testVulnerability.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.security.Vulnerability#Element(org.spdx.library.model.security.Vulnerability.VulnerabilityBuilder)}. + */ + public void testVulnerabilityVulnerabilityBuilder() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Vulnerability test2Vulnerability = builderForVulnerabilityTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testVulnerability.equivalent(test2Vulnerability)); + assertTrue(test2Vulnerability.equivalent(testVulnerability)); + // TODO change some parameters for negative tests + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/software/SbomTest.java b/generated/src/test/java/org/spdx/library/model/software/SbomTest.java new file mode 100644 index 000000000..8040a00ed --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/software/SbomTest.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.software.Sbom.SbomBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SbomTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SbomBuilder builderForSbomTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SbomBuilder retval = new SbomBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .getsbomType.add(SBOMType.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.software.Sbom#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSbom.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.Sbom#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Software.Sbom", testSbom.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.software.Sbom#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Sbom: "+TEST_OBJECT_URI, testSbom.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.software.Sbom#Element(org.spdx.library.model.software.Sbom.SbomBuilder)}. + */ + public void testSbomSbomBuilder() throws InvalidSPDXAnalysisException { + Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Sbom test2Sbom = builderForSbomTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSbom.equivalent(test2Sbom)); + assertTrue(test2Sbom.equivalent(testSbom)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.Sbom#getSbomType}. + */ + public void testSbomgetSbomType() throws InvalidSPDXAnalysisException { + Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSbom.getSbomType())); +// testSbom.getSbomType().clear(); +// testSbom.getSbomType().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSbom.getSbomType())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/software/SnippetTest.java b/generated/src/test/java/org/spdx/library/model/software/SnippetTest.java new file mode 100644 index 000000000..11cb06c37 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/software/SnippetTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.software.Snippet.SnippetBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SnippetTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SnippetBuilder builderForSnippetTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SnippetBuilder retval = new SnippetBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setbyteRange(new PositiveIntegerRange()) + .setlineRange(new PositiveIntegerRange()) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.software.Snippet#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSnippet.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.Snippet#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Software.Snippet", testSnippet.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.software.Snippet#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Snippet: "+TEST_OBJECT_URI, testSnippet.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.software.Snippet#Element(org.spdx.library.model.software.Snippet.SnippetBuilder)}. + */ + public void testSnippetSnippetBuilder() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Snippet test2Snippet = builderForSnippetTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSnippet.equivalent(test2Snippet)); + assertTrue(test2Snippet.equivalent(testSnippet)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.Snippet#setByteRange}. + */ + public void testSnippetsetByteRange() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSnippet.getByteRange()); +// testSnippet.setByteRange(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSnippet.getByteRange()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.Snippet#setLineRange}. + */ + public void testSnippetsetLineRange() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSnippet.getLineRange()); +// testSnippet.setLineRange(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSnippet.getLineRange()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java b/generated/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java new file mode 100644 index 000000000..8241e2032 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java @@ -0,0 +1,192 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.software.SoftwareArtifact.SoftwareArtifactBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SoftwareArtifactTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SoftwareArtifactBuilder builderForSoftwareArtifactTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SoftwareArtifactBuilder retval = new SoftwareArtifactBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setdeclaredLicense(TEST_ANYLICENSE_INFO) + .setconcludedLicense(TEST_ANYLICENSE_INFO) + .setprimaryPurpose(SoftwarePurpose.ENUM) + .setcontentIdentifier("A string") + .setattributionText("A string") + .setcopyrightText("A string") + .getadditionalPurpose.add(SoftwarePurpose.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSoftwareArtifact.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Software.SoftwareArtifact", testSoftwareArtifact.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SoftwareArtifact: "+TEST_OBJECT_URI, testSoftwareArtifact.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#Element(org.spdx.library.model.software.SoftwareArtifact.SoftwareArtifactBuilder)}. + */ + public void testSoftwareArtifactSoftwareArtifactBuilder() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SoftwareArtifact test2SoftwareArtifact = builderForSoftwareArtifactTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSoftwareArtifact.equivalent(test2SoftwareArtifact)); + assertTrue(test2SoftwareArtifact.equivalent(testSoftwareArtifact)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setDeclaredLicense}. + */ + public void testSoftwareArtifactsetDeclaredLicense() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareArtifact.getDeclaredLicense()); +// testSoftwareArtifact.setDeclaredLicense(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getDeclaredLicense()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setConcludedLicense}. + */ + public void testSoftwareArtifactsetConcludedLicense() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareArtifact.getConcludedLicense()); +// testSoftwareArtifact.setConcludedLicense(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getConcludedLicense()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setPrimaryPurpose}. + */ + public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareArtifact.getPrimaryPurpose()); +// testSoftwareArtifact.setPrimaryPurpose(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getPrimaryPurpose()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setContentIdentifier}. + */ + public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareArtifact.getContentIdentifier()); +// testSoftwareArtifact.setContentIdentifier(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getContentIdentifier()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setAttributionText}. + */ + public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareArtifact.getAttributionText()); +// testSoftwareArtifact.setAttributionText(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getAttributionText()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setCopyrightText}. + */ + public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareArtifact.getCopyrightText()); +// testSoftwareArtifact.setCopyrightText(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getCopyrightText()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#getAdditionalPurpose}. + */ + public void testSoftwareArtifactgetAdditionalPurpose() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurpose())); +// testSoftwareArtifact.getAdditionalPurpose().clear(); +// testSoftwareArtifact.getAdditionalPurpose().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurpose())); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java b/generated/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java new file mode 100644 index 000000000..211567825 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SoftwareDependencyRelationshipTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SoftwareDependencyRelationshipBuilder builderForSoftwareDependencyRelationshipTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationshipBuilder retval = new SoftwareDependencyRelationshipBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setsoftwareLinkage(SoftwareDependencyLinkType.ENUM) + .setconditionality(DependencyConditionalityType.ENUM) + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSoftwareDependencyRelationship.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Software.SoftwareDependencyRelationship", testSoftwareDependencyRelationship.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SoftwareDependencyRelationship: "+TEST_OBJECT_URI, testSoftwareDependencyRelationship.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#Element(org.spdx.library.model.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder)}. + */ + public void testSoftwareDependencyRelationshipSoftwareDependencyRelationshipBuilder() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SoftwareDependencyRelationship test2SoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSoftwareDependencyRelationship.equivalent(test2SoftwareDependencyRelationship)); + assertTrue(test2SoftwareDependencyRelationship.equivalent(testSoftwareDependencyRelationship)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#setSoftwareLinkage}. + */ + public void testSoftwareDependencyRelationshipsetSoftwareLinkage() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareDependencyRelationship.getSoftwareLinkage()); +// testSoftwareDependencyRelationship.setSoftwareLinkage(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareDependencyRelationship.getSoftwareLinkage()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#setConditionality}. + */ + public void testSoftwareDependencyRelationshipsetConditionality() throws InvalidSPDXAnalysisException { + SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSoftwareDependencyRelationship.getConditionality()); +// testSoftwareDependencyRelationship.setConditionality(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSoftwareDependencyRelationship.getConditionality()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/software/SpdxFileTest.java b/generated/src/test/java/org/spdx/library/model/software/SpdxFileTest.java new file mode 100644 index 000000000..a5822abaa --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/software/SpdxFileTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.software.SpdxFile.SpdxFileBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SpdxFileTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SpdxFileBuilder builderForSpdxFileTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SpdxFileBuilder retval = new SpdxFileBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setcontentType("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxFile#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSpdxFile.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxFile#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Software.SpdxFile", testSpdxFile.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxFile#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SpdxFile: "+TEST_OBJECT_URI, testSpdxFile.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxFile#Element(org.spdx.library.model.software.SpdxFile.SpdxFileBuilder)}. + */ + public void testSpdxFileSpdxFileBuilder() throws InvalidSPDXAnalysisException { + SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SpdxFile test2SpdxFile = builderForSpdxFileTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSpdxFile.equivalent(test2SpdxFile)); + assertTrue(test2SpdxFile.equivalent(testSpdxFile)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxFile#setContentType}. + */ + public void testSpdxFilesetContentType() throws InvalidSPDXAnalysisException { + SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSpdxFile.getContentType()); +// testSpdxFile.setContentType(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSpdxFile.getContentType()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java b/generated/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java new file mode 100644 index 000000000..552084136 --- /dev/null +++ b/generated/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java @@ -0,0 +1,167 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.software; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.software.SpdxPackage.SpdxPackageBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SpdxPackageTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + IModelStore modelStore; + ModelCopyManager copyManager; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SpdxPackageBuilder builderForSpdxPackageTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SpdxPackageBuilder retval = new SpdxPackageBuilder(modelStore, objectUri, copyManager); + //TODO: Add in test values + /******************** + .setdownloadLocation("A string") + .setsourceInfo("A string") + .setpackageVersion("A string") + .sethomePage("A string") + .setpackageUrl("A string") + ***************/ + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSpdxPackage.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Software.SpdxPackage", testSpdxPackage.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SpdxPackage: "+TEST_OBJECT_URI, testSpdxPackage.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#Element(org.spdx.library.model.software.SpdxPackage.SpdxPackageBuilder)}. + */ + public void testSpdxPackageSpdxPackageBuilder() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SpdxPackage test2SpdxPackage = builderForSpdxPackageTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSpdxPackage.equivalent(test2SpdxPackage)); + assertTrue(test2SpdxPackage.equivalent(testSpdxPackage)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#setDownloadLocation}. + */ + public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSpdxPackage.getDownloadLocation()); +// testSpdxPackage.setDownloadLocation(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getDownloadLocation()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#setSourceInfo}. + */ + public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSpdxPackage.getSourceInfo()); +// testSpdxPackage.setSourceInfo(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getSourceInfo()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#setPackageVersion}. + */ + public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSpdxPackage.getPackageVersion()); +// testSpdxPackage.setPackageVersion(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getPackageVersion()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#setHomePage}. + */ + public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSpdxPackage.getHomePage()); +// testSpdxPackage.setHomePage(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getHomePage()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.software.SpdxPackage#setPackageUrl}. + */ + public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { + SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSpdxPackage.getPackageUrl()); +// testSpdxPackage.setPackageUrl(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getPackageUrl()); + fail("Not yet implemented"); + } + +/* +*/ + +} \ No newline at end of file From fa8602e2960fcc37c85d75af6516f301b152cb6f Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sat, 15 Jul 2023 16:25:39 -0700 Subject: [PATCH 16/62] Remove Generic Model Object Signed-off-by: Gary O'Neall --- .../library/model/GenericModelObject.java | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 src/main/java/org/spdx/library/model/GenericModelObject.java diff --git a/src/main/java/org/spdx/library/model/GenericModelObject.java b/src/main/java/org/spdx/library/model/GenericModelObject.java deleted file mode 100644 index 1aea7af42..000000000 --- a/src/main/java/org/spdx/library/model/GenericModelObject.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; - -/** - * Primarily used for testing, this model object does not implement any unique getters and setters nor - * does it implement any verification. - * - * @author Gary O'Neall - * - */ -public class GenericModelObject extends ModelObject { - - public static final String GENERIC_MODEL_OBJECT_TYPE = "GenericModelObject"; - - /** - * @throws InvalidSPDXAnalysisException - */ - public GenericModelObject() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public GenericModelObject(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public GenericModelObject(IModelStore modelStore, String objectUri, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return GENERIC_MODEL_OBJECT_TYPE; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - return new ArrayList<>(); - } -} From 1d84bd740e0fad93e45f3bdd1f771e5dd236d261 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sat, 15 Jul 2023 17:01:27 -0700 Subject: [PATCH 17/62] Move unit tests and update POM file for additional source directory Signed-off-by: Gary O'Neall --- .../spdx/library/model/dataset/Dataset.java | 48 +----------- pom.xml | 19 +++++ .../java/org/spdx/library/SpdxConstants.java | 45 ----------- .../org/spdx/library/model/core/Element.java | 72 ------------------ .../org/spdx/library/model/core/Payload.java | 66 ---------------- .../spdx/library/model/core/package-info.java | 26 ------- .../model/licensing/AnyLicenseInfo.java | 75 ------------------- .../library/model/licensing/package-info.java | 27 ------- .../spdx/library/model/ai/AIPackageTest.java | 0 .../spdx/library/model/build/BuildTest.java | 0 .../spdx/library/model/core/AgentTest.java | 1 - .../library/model/core/AnnotationTest.java | 0 .../model/core/AnonymousPayloadTest.java | 0 .../spdx/library/model/core/ArtifactTest.java | 0 .../org/spdx/library/model/core/BomTest.java | 0 .../spdx/library/model/core/BundleTest.java | 0 .../library/model/core/CreationInfoTest.java | 0 .../model/core/DictionaryEntryTest.java | 0 .../model/core/ElementCollectionTest.java | 0 .../spdx/library/model/core/ElementTest.java | 0 .../model/core/ExternalIdentifierTest.java | 0 .../library/model/core/ExternalMapTest.java | 0 .../model/core/ExternalReferenceTest.java | 0 .../org/spdx/library/model/core/HashTest.java | 0 .../model/core/IntegrityMethodTest.java | 0 .../core/LifecycleScopedRelationshipTest.java | 0 .../library/model/core/NamespaceMapTest.java | 0 .../library/model/core/OrganizationTest.java | 0 .../spdx/library/model/core/PayloadTest.java | 0 .../spdx/library/model/core/PersonTest.java | 0 .../model/core/PositiveIntegerRangeTest.java | 0 .../library/model/core/RelationshipTest.java | 0 .../library/model/core/SoftwareAgentTest.java | 0 .../library/model/core/SpdxDocumentTest.java | 0 .../org/spdx/library/model/core/ToolTest.java | 0 .../library/model/dataset/DatasetTest.java | 0 .../ConjunctiveLicenseSetTest.java | 0 .../DisjunctiveLicenseSetTest.java | 0 .../ExtendableLicenseTest.java | 0 .../model/licensing/AnyLicenseInfoTest.java | 0 .../licensing/CustomLicenseAdditionTest.java | 0 .../model/licensing/CustomLicenseTest.java | 0 .../model/licensing/LicenseAdditionTest.java | 0 .../licensing/LicenseExpressionTest.java | 0 .../library/model/licensing/LicenseTest.java | 0 .../licensing/ListedLicenseExceptionTest.java | 0 .../model/licensing/ListedLicenseTest.java | 0 .../model/licensing/OrLaterOperatorTest.java | 0 .../licensing/WithAdditionOperatorTest.java | 0 .../CvssV2VulnAssessmentRelationshipTest.java | 0 .../CvssV3VulnAssessmentRelationshipTest.java | 0 .../EpssVulnAssessmentRelationshipTest.java | 0 ...CatalogVulnAssessmentRelationshipTest.java | 0 .../SsvcVulnAssessmentRelationshipTest.java | 0 ...ffectedVulnAssessmentRelationshipTest.java | 0 ...exFixedVulnAssessmentRelationshipTest.java | 0 ...ffectedVulnAssessmentRelationshipTest.java | 0 ...igationVulnAssessmentRelationshipTest.java | 0 .../VexVulnAssessmentRelationshipTest.java | 0 .../VulnAssessmentRelationshipTest.java | 0 .../model/security/VulnerabilityTest.java | 0 .../spdx/library/model/software/SbomTest.java | 0 .../library/model/software/SnippetTest.java | 0 .../model/software/SoftwareArtifactTest.java | 0 .../SoftwareDependencyRelationshipTest.java | 0 .../library/model/software/SpdxFileTest.java | 0 .../model/software/SpdxPackageTest.java | 0 67 files changed, 20 insertions(+), 359 deletions(-) delete mode 100644 src/main/java/org/spdx/library/SpdxConstants.java delete mode 100644 src/main/java/org/spdx/library/model/core/Element.java delete mode 100644 src/main/java/org/spdx/library/model/core/Payload.java delete mode 100644 src/main/java/org/spdx/library/model/core/package-info.java delete mode 100644 src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java delete mode 100644 src/main/java/org/spdx/library/model/licensing/package-info.java rename {generated/src => src}/test/java/org/spdx/library/model/ai/AIPackageTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/build/BuildTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/AgentTest.java (98%) rename {generated/src => src}/test/java/org/spdx/library/model/core/AnnotationTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ArtifactTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/BomTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/BundleTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/CreationInfoTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/DictionaryEntryTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ElementCollectionTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ElementTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ExternalMapTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ExternalReferenceTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/HashTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/IntegrityMethodTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/NamespaceMapTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/OrganizationTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/PayloadTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/PersonTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/RelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/SoftwareAgentTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/SpdxDocumentTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/core/ToolTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/dataset/DatasetTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/LicenseTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/security/VulnerabilityTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/software/SbomTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/software/SnippetTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/software/SpdxFileTest.java (100%) rename {generated/src => src}/test/java/org/spdx/library/model/software/SpdxPackageTest.java (100%) diff --git a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java index 0401274ef..04746f3cc 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java +++ b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java @@ -112,7 +112,6 @@ protected Dataset(DatasetBuilder builder) throws InvalidSPDXAnalysisException { getAnonymizationMethodUseds().addAll(builder.anonymizationMethodUseds); getDataPreprocessings().addAll(builder.dataPreprocessings); getKnownBiass().addAll(builder.knownBiass); - setSensitivePersonalInformation(builder.sensitivePersonalInformation); setConfidentialityLevel(builder.confidentialityLevel); setDatasetAvailability(builder.datasetAvailability); setDatasetSize(builder.datasetSize); @@ -147,32 +146,6 @@ public Collection getKnownBiass() { return knownBiass; } - - /** - * @return the sensitivePersonalInformation - */ - @SuppressWarnings("unchecked") - public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION); - if (retval.isPresent()) { - if (!(retval.get() instanceof PresenceType)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } - } - - /** - * @param sensitivePersonalInformation the sensitivePersonalInformation to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Dataset setSensitivePersonalInformation(@Nullable PresenceType sensitivePersonalInformation) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION, sensitivePersonalInformation); - return this; - } /** * @return the confidentialityLevel @@ -324,15 +297,7 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional sensitivePersonalInformation; - try { - sensitivePersonalInformation = getSensitivePersonalInformation(); - if (sensitivePersonalInformation.isPresent()) { - retval.addAll(sensitivePersonalInformation.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting sensitivePersonalInformation for Dataset: "+e.getMessage()); - } + try { Optional confidentialityLevel = getConfidentialityLevel(); } catch (InvalidSPDXAnalysisException e) { @@ -394,7 +359,6 @@ public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC Collection anonymizationMethodUseds = new ArrayList<>(); Collection dataPreprocessings = new ArrayList<>(); Collection knownBiass = new ArrayList<>(); - PresenceType sensitivePersonalInformation = null; ConfidentialityLevelType confidentialityLevel = null; DatasetAvailabilityType datasetAvailability = null; Integer datasetSize = null; @@ -524,16 +488,6 @@ DatasetBuilder addAllknownBias(Collection knownBiasCollection) { return this; } - /** - * Sets the initial value of sensitivePersonalInformation - * @parameter sensitivePersonalInformation value to set - * @return this for chaining - **/ - DatasetBuilder setsensitivePersonalInformation(PresenceType sensitivePersonalInformation) { - this.sensitivePersonalInformation = sensitivePersonalInformation; - return this; - } - /** * Sets the initial value of confidentialityLevel * @parameter confidentialityLevel value to set diff --git a/pom.xml b/pom.xml index 1f3acc4e1..c8f82cb82 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,25 @@ gpg-signing + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-source + generate-sources + + add-source + + + + generated/src/main/java + + + + + org.apache.maven.plugins maven-gpg-plugin diff --git a/src/main/java/org/spdx/library/SpdxConstants.java b/src/main/java/org/spdx/library/SpdxConstants.java deleted file mode 100644 index ba127e589..000000000 --- a/src/main/java/org/spdx/library/SpdxConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import org.spdx.storage.PropertyDescriptor; - -/** - * Constants which map to the SPDX specifications - * @author Gary O'Neall - * - */ -public class SpdxConstants { - - public enum SpdxMajorVersion { - VERSION_1, - VERSION_2, - VERSION_3; - - public static SpdxMajorVersion latestVersion() { - return VERSION_3; - } - } - - /** - * Core namespace - */ - public static final String CORE_NAMESPACE = "https://rdf.spdx.org/v3/Core"; - public static final PropertyDescriptor CORE_PROP_RELATED_SPDX_ELEMENT = new PropertyDescriptor("to", CORE_NAMESPACE); - -} diff --git a/src/main/java/org/spdx/library/model/core/Element.java b/src/main/java/org/spdx/library/model/core/Element.java deleted file mode 100644 index 503f54f1e..000000000 --- a/src/main/java/org/spdx/library/model/core/Element.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.core; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; - -/** - * - * Base domain class from which all other SPDX-3.0 domain classes derive. - * - * An Element is a representation of a fundamental concept either directly inherent - * to the Bill of Materials (BOM) domain or indirectly related to the BOM domain - * and necessary for contextually characterizing BOM concepts and relationships. - * Within SPDX-3.0 structure this is the base class acting as a consistent, - * unifying, and interoperable foundation for all explicit - * and inter-relatable content objects. - * - * @author Gary O'Neall - * - */ -public abstract class Element extends Payload { - - /** - * @throws InvalidSPDXAnalysisException - */ - public Element() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * Creates a new Element object - * @param modelStore Storage for the model objects - Must support model V3 classes - * @param objectUri Anonymous ID or URI for the model object - * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - public Element(IModelStore modelStore, String objectUri, - ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /** - * Open or create an Element object with the default store - * @param objectUri Anonymous ID or URI for the model object - * @throws InvalidSPDXAnalysisException - */ - public Element(String objectUri) throws InvalidSPDXAnalysisException { - super(objectUri); - } - - //TODO: Implement properties - -} diff --git a/src/main/java/org/spdx/library/model/core/Payload.java b/src/main/java/org/spdx/library/model/core/Payload.java deleted file mode 100644 index 4368866d0..000000000 --- a/src/main/java/org/spdx/library/model/core/Payload.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * TODO: Add description from model markdown once complete - * - * @author Gary O'Neall - * - */ -public abstract class Payload extends ModelObject { - - /** - * @throws InvalidSPDXAnalysisException - */ - public Payload() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * Creates a new Payload object - * @param modelStore Storage for the model objects - Must support model V3 classes - * @param objectUri Anonymous ID or URI for the model object - * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - public Payload(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /** - * Open or create a Payload object with the default store - * @param objectUri Anonymous ID or URI for the model object - * @throws InvalidSPDXAnalysisException - */ - public Payload(String objectUri) throws InvalidSPDXAnalysisException { - super(objectUri); - } - - //TODO: Add in creationInfo and nameSpace maps - -} diff --git a/src/main/java/org/spdx/library/model/core/package-info.java b/src/main/java/org/spdx/library/model/core/package-info.java deleted file mode 100644 index 68e847a8c..000000000 --- a/src/main/java/org/spdx/library/model/core/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Classes for the implementation of the SPDX Core Profile - * - * The Core namespace defines foundational concepts serving as the basis for all SPDX-3.0 profiles. - * - * @author Gary O'Neall - * - */ -package org.spdx.library.model.core; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java b/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java deleted file mode 100644 index 99983b54e..000000000 --- a/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.licensing; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Element; -import org.spdx.storage.IModelStore; - -/** - * - * Abstract class representing a license combination consisting of one or more - * licenses (optionally including additional text), which may be combined - * according to the SPDX license expression syntax. - * - * An AnyLicenseInfo is used by licensing properties of software artifacts. - * It can be a NoneLicense, a NoAssertionLicense, - * single license (either on the SPDX License List or a custom-defined license); - * a single license with an "or later" operator applied; the foregoing with - * additional text applied; or a set of licenses combined by applying "AND" and - * "OR" operators recursively. - * - * @author Gary O'Neall - * - */ -public abstract class AnyLicenseInfo extends Element { - - /** - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param modelStore Storage for the model objects - Must support model V3 classes - * @param objectUri Anonymous ID or URI for the model object - * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo(IModelStore modelStore, String objectUri, - ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /** - * Open or create an Element object with the default store - * @param objectUri Anonymous ID or URI for the model object - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo(String objectUri) - throws InvalidSPDXAnalysisException { - super(objectUri); - } - - //TODO: Implement properties - -} diff --git a/src/main/java/org/spdx/library/model/licensing/package-info.java b/src/main/java/org/spdx/library/model/licensing/package-info.java deleted file mode 100644 index aa60d409b..000000000 --- a/src/main/java/org/spdx/library/model/licensing/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * - * The Licensing namespace defines metadata fields applicable to software - * licensing. It also defines the classes and properties that comprise the - * SPDX License Expression syntax and that relate to the SPDX License List. - * - * @author Gary O'Neall - * - */ -package org.spdx.library.model.licensing; \ No newline at end of file diff --git a/generated/src/test/java/org/spdx/library/model/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/ai/AIPackageTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/ai/AIPackageTest.java rename to src/test/java/org/spdx/library/model/ai/AIPackageTest.java diff --git a/generated/src/test/java/org/spdx/library/model/build/BuildTest.java b/src/test/java/org/spdx/library/model/build/BuildTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/build/BuildTest.java rename to src/test/java/org/spdx/library/model/build/BuildTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/AgentTest.java b/src/test/java/org/spdx/library/model/core/AgentTest.java similarity index 98% rename from generated/src/test/java/org/spdx/library/model/core/AgentTest.java rename to src/test/java/org/spdx/library/model/core/AgentTest.java index 6c1f321ce..0cc4045f3 100644 --- a/generated/src/test/java/org/spdx/library/model/core/AgentTest.java +++ b/src/test/java/org/spdx/library/model/core/AgentTest.java @@ -29,7 +29,6 @@ import org.spdx.library.model.core.Agent.AgentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; -import org.spdx.utility.compare.UnitTestHelper; import junit.framework.TestCase; diff --git a/generated/src/test/java/org/spdx/library/model/core/AnnotationTest.java b/src/test/java/org/spdx/library/model/core/AnnotationTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/AnnotationTest.java rename to src/test/java/org/spdx/library/model/core/AnnotationTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java b/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java rename to src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ArtifactTest.java b/src/test/java/org/spdx/library/model/core/ArtifactTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ArtifactTest.java rename to src/test/java/org/spdx/library/model/core/ArtifactTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/BomTest.java b/src/test/java/org/spdx/library/model/core/BomTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/BomTest.java rename to src/test/java/org/spdx/library/model/core/BomTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/BundleTest.java b/src/test/java/org/spdx/library/model/core/BundleTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/BundleTest.java rename to src/test/java/org/spdx/library/model/core/BundleTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/CreationInfoTest.java b/src/test/java/org/spdx/library/model/core/CreationInfoTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/CreationInfoTest.java rename to src/test/java/org/spdx/library/model/core/CreationInfoTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java b/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java rename to src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java b/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java rename to src/test/java/org/spdx/library/model/core/ElementCollectionTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ElementTest.java b/src/test/java/org/spdx/library/model/core/ElementTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ElementTest.java rename to src/test/java/org/spdx/library/model/core/ElementTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java b/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java rename to src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ExternalMapTest.java b/src/test/java/org/spdx/library/model/core/ExternalMapTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ExternalMapTest.java rename to src/test/java/org/spdx/library/model/core/ExternalMapTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java b/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java rename to src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/HashTest.java b/src/test/java/org/spdx/library/model/core/HashTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/HashTest.java rename to src/test/java/org/spdx/library/model/core/HashTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java b/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java rename to src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java b/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java rename to src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java b/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java rename to src/test/java/org/spdx/library/model/core/NamespaceMapTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/OrganizationTest.java b/src/test/java/org/spdx/library/model/core/OrganizationTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/OrganizationTest.java rename to src/test/java/org/spdx/library/model/core/OrganizationTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/PayloadTest.java b/src/test/java/org/spdx/library/model/core/PayloadTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/PayloadTest.java rename to src/test/java/org/spdx/library/model/core/PayloadTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/PersonTest.java b/src/test/java/org/spdx/library/model/core/PersonTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/PersonTest.java rename to src/test/java/org/spdx/library/model/core/PersonTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java b/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java rename to src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/RelationshipTest.java b/src/test/java/org/spdx/library/model/core/RelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/RelationshipTest.java rename to src/test/java/org/spdx/library/model/core/RelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java b/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java rename to src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java rename to src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java diff --git a/generated/src/test/java/org/spdx/library/model/core/ToolTest.java b/src/test/java/org/spdx/library/model/core/ToolTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/core/ToolTest.java rename to src/test/java/org/spdx/library/model/core/ToolTest.java diff --git a/generated/src/test/java/org/spdx/library/model/dataset/DatasetTest.java b/src/test/java/org/spdx/library/model/dataset/DatasetTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/dataset/DatasetTest.java rename to src/test/java/org/spdx/library/model/dataset/DatasetTest.java diff --git a/generated/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java diff --git a/generated/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java diff --git a/generated/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java b/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java rename to src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java b/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java rename to src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java b/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java rename to src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java b/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java rename to src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java rename to src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java rename to src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/LicenseTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/LicenseTest.java rename to src/test/java/org/spdx/library/model/licensing/LicenseTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java b/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java rename to src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java b/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java rename to src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java rename to src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java diff --git a/generated/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java b/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java rename to src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java b/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java rename to src/test/java/org/spdx/library/model/security/VulnerabilityTest.java diff --git a/generated/src/test/java/org/spdx/library/model/software/SbomTest.java b/src/test/java/org/spdx/library/model/software/SbomTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/software/SbomTest.java rename to src/test/java/org/spdx/library/model/software/SbomTest.java diff --git a/generated/src/test/java/org/spdx/library/model/software/SnippetTest.java b/src/test/java/org/spdx/library/model/software/SnippetTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/software/SnippetTest.java rename to src/test/java/org/spdx/library/model/software/SnippetTest.java diff --git a/generated/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java b/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java rename to src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java diff --git a/generated/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java b/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java rename to src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java diff --git a/generated/src/test/java/org/spdx/library/model/software/SpdxFileTest.java b/src/test/java/org/spdx/library/model/software/SpdxFileTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/software/SpdxFileTest.java rename to src/test/java/org/spdx/library/model/software/SpdxFileTest.java diff --git a/generated/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java similarity index 100% rename from generated/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java rename to src/test/java/org/spdx/library/model/software/SpdxPackageTest.java From f60f8fa1115b6a73786d52c6bc095c99dc4a4602 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 19 Jul 2023 09:32:38 -0700 Subject: [PATCH 18/62] Update generated files Signed-off-by: Gary O'Neall --- .../org/spdx/library/model/ai/AIPackage.java | 46 ++-- .../org/spdx/library/model/build/Build.java | 28 +-- .../spdx/library/model/core/Annotation.java | 6 +- .../org/spdx/library/model/core/Artifact.java | 18 +- .../org/spdx/library/model/core/Bundle.java | 2 +- .../spdx/library/model/core/CreationInfo.java | 26 +-- .../library/model/core/DictionaryEntry.java | 4 +- .../org/spdx/library/model/core/Element.java | 12 +- .../library/model/core/ElementCollection.java | 8 +- .../model/core/ExternalIdentifier.java | 12 +- .../spdx/library/model/core/ExternalMap.java | 10 +- .../library/model/core/ExternalReference.java | 10 +- .../org/spdx/library/model/core/Hash.java | 4 +- .../library/model/core/IntegrityMethod.java | 2 +- .../core/LifecycleScopedRelationship.java | 2 +- .../spdx/library/model/core/NamespaceMap.java | 4 +- .../org/spdx/library/model/core/Payload.java | 10 +- .../model/core/PositiveIntegerRange.java | 4 +- .../spdx/library/model/core/Relationship.java | 14 +- .../spdx/library/model/dataset/Dataset.java | 37 ++-- .../spdx/library/model/licensing/License.java | 12 +- .../model/licensing/LicenseAddition.java | 6 +- .../model/licensing/LicenseExpression.java | 2 +- .../EpssVulnAssessmentRelationship.java | 2 +- ...loitCatalogVulnAssessmentRelationship.java | 6 +- .../SsvcVulnAssessmentRelationship.java | 2 +- ...VexAffectedVulnAssessmentRelationship.java | 6 +- ...NotAffectedVulnAssessmentRelationship.java | 6 +- .../VexVulnAssessmentRelationship.java | 4 +- .../security/VulnAssessmentRelationship.java | 4 +- .../org/spdx/library/model/software/Sbom.java | 4 +- .../spdx/library/model/software/Snippet.java | 4 +- .../model/software/SoftwareArtifact.java | 16 +- .../SoftwareDependencyRelationship.java | 4 +- .../spdx/library/model/software/SpdxFile.java | 2 +- .../library/model/software/SpdxPackage.java | 10 +- .../spdx/library/model/ai/AIPackageTest.java | 201 ++++++++++-------- .../spdx/library/model/build/BuildTest.java | 135 ++++++------ .../spdx/library/model/core/AgentTest.java | 20 +- .../library/model/core/AnnotationTest.java | 33 ++- .../model/core/AnonymousPayloadTest.java | 19 +- .../spdx/library/model/core/ArtifactTest.java | 93 ++++---- .../org/spdx/library/model/core/BomTest.java | 19 +- .../spdx/library/model/core/BundleTest.java | 29 ++- .../library/model/core/CreationInfoTest.java | 125 ++++++----- .../model/core/DictionaryEntryTest.java | 39 ++-- .../model/core/ElementCollectionTest.java | 43 ++-- .../spdx/library/model/core/ElementTest.java | 63 +++--- .../model/core/ExternalIdentifierTest.java | 71 ++++--- .../library/model/core/ExternalMapTest.java | 61 +++--- .../model/core/ExternalReferenceTest.java | 61 +++--- .../org/spdx/library/model/core/HashTest.java | 31 ++- .../model/core/IntegrityMethodTest.java | 29 ++- .../core/LifecycleScopedRelationshipTest.java | 21 +- .../library/model/core/NamespaceMapTest.java | 39 ++-- .../library/model/core/OrganizationTest.java | 19 +- .../spdx/library/model/core/PayloadTest.java | 45 ++-- .../spdx/library/model/core/PersonTest.java | 19 +- .../model/core/PositiveIntegerRangeTest.java | 39 ++-- .../library/model/core/RelationshipTest.java | 57 +++-- .../library/model/core/SoftwareAgentTest.java | 19 +- .../library/model/core/SpdxDocumentTest.java | 19 +- .../org/spdx/library/model/core/ToolTest.java | 19 +- .../library/model/dataset/DatasetTest.java | 159 +++++++------- .../ConjunctiveLicenseSetTest.java | 19 +- .../DisjunctiveLicenseSetTest.java | 19 +- .../ExtendableLicenseTest.java | 19 +- .../model/licensing/AnyLicenseInfoTest.java | 19 +- .../licensing/CustomLicenseAdditionTest.java | 19 +- .../model/licensing/CustomLicenseTest.java | 19 +- .../model/licensing/LicenseAdditionTest.java | 48 ++--- .../licensing/LicenseExpressionTest.java | 29 ++- .../library/model/licensing/LicenseTest.java | 76 ++++--- .../licensing/ListedLicenseExceptionTest.java | 19 +- .../model/licensing/ListedLicenseTest.java | 19 +- .../model/licensing/OrLaterOperatorTest.java | 19 +- .../licensing/WithAdditionOperatorTest.java | 19 +- .../CvssV2VulnAssessmentRelationshipTest.java | 19 +- .../CvssV3VulnAssessmentRelationshipTest.java | 19 +- .../EpssVulnAssessmentRelationshipTest.java | 29 ++- ...CatalogVulnAssessmentRelationshipTest.java | 40 ++-- .../SsvcVulnAssessmentRelationshipTest.java | 21 +- ...ffectedVulnAssessmentRelationshipTest.java | 49 +++-- ...exFixedVulnAssessmentRelationshipTest.java | 19 +- ...ffectedVulnAssessmentRelationshipTest.java | 41 ++-- ...igationVulnAssessmentRelationshipTest.java | 19 +- .../VexVulnAssessmentRelationshipTest.java | 39 ++-- .../VulnAssessmentRelationshipTest.java | 23 +- .../model/security/VulnerabilityTest.java | 19 +- .../spdx/library/model/software/SbomTest.java | 31 ++- .../library/model/software/SnippetTest.java | 23 +- .../model/software/SoftwareArtifactTest.java | 67 +++--- .../SoftwareDependencyRelationshipTest.java | 23 +- .../library/model/software/SpdxFileTest.java | 29 ++- .../model/software/SpdxPackageTest.java | 69 +++--- 95 files changed, 1419 insertions(+), 1379 deletions(-) diff --git a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java b/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java index af30410f3..e7e89d2bf 100644 --- a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java +++ b/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java @@ -396,7 +396,7 @@ public AIPackageBuilder(IModelStore modelStore, String objectUri, @Nullable Mode * @parameter metric metric to add * @return this for chaining **/ - AIPackageBuilder addmetric(DictionaryEntry metric) { + AIPackageBuilder addMetric(DictionaryEntry metric) { if (Objects.nonNull(metric)) { metrics.add(metric); } @@ -408,7 +408,7 @@ AIPackageBuilder addmetric(DictionaryEntry metric) { * @parameter metricCollection collection to initialize the metric * @return this for chaining **/ - AIPackageBuilder addAllmetric(Collection metricCollection) { + AIPackageBuilder addAllMetric(Collection metricCollection) { if (Objects.nonNull(metricCollection)) { metrics.addAll(metricCollection); } @@ -420,7 +420,7 @@ AIPackageBuilder addAllmetric(Collection metricCollection) { * @parameter hyperparameter hyperparameter to add * @return this for chaining **/ - AIPackageBuilder addhyperparameter(DictionaryEntry hyperparameter) { + AIPackageBuilder addHyperparameter(DictionaryEntry hyperparameter) { if (Objects.nonNull(hyperparameter)) { hyperparameters.add(hyperparameter); } @@ -432,7 +432,7 @@ AIPackageBuilder addhyperparameter(DictionaryEntry hyperparameter) { * @parameter hyperparameterCollection collection to initialize the hyperparameter * @return this for chaining **/ - AIPackageBuilder addAllhyperparameter(Collection hyperparameterCollection) { + AIPackageBuilder addAllHyperparameter(Collection hyperparameterCollection) { if (Objects.nonNull(hyperparameterCollection)) { hyperparameters.addAll(hyperparameterCollection); } @@ -444,7 +444,7 @@ AIPackageBuilder addAllhyperparameter(Collection hyperparameter * @parameter metricDecisionThreshold metricDecisionThreshold to add * @return this for chaining **/ - AIPackageBuilder addmetricDecisionThreshold(DictionaryEntry metricDecisionThreshold) { + AIPackageBuilder addMetricDecisionThreshold(DictionaryEntry metricDecisionThreshold) { if (Objects.nonNull(metricDecisionThreshold)) { metricDecisionThresholds.add(metricDecisionThreshold); } @@ -456,7 +456,7 @@ AIPackageBuilder addmetricDecisionThreshold(DictionaryEntry metricDecisionThresh * @parameter metricDecisionThresholdCollection collection to initialize the metricDecisionThreshold * @return this for chaining **/ - AIPackageBuilder addAllmetricDecisionThreshold(Collection metricDecisionThresholdCollection) { + AIPackageBuilder addAllMetricDecisionThreshold(Collection metricDecisionThresholdCollection) { if (Objects.nonNull(metricDecisionThresholdCollection)) { metricDecisionThresholds.addAll(metricDecisionThresholdCollection); } @@ -468,7 +468,7 @@ AIPackageBuilder addAllmetricDecisionThreshold(Collection metri * @parameter domain domain to add * @return this for chaining **/ - AIPackageBuilder adddomain(String domain) { + AIPackageBuilder addDomain(String domain) { if (Objects.nonNull(domain)) { domains.add(domain); } @@ -480,7 +480,7 @@ AIPackageBuilder adddomain(String domain) { * @parameter domainCollection collection to initialize the domain * @return this for chaining **/ - AIPackageBuilder addAlldomain(Collection domainCollection) { + AIPackageBuilder addAllDomain(Collection domainCollection) { if (Objects.nonNull(domainCollection)) { domains.addAll(domainCollection); } @@ -492,7 +492,7 @@ AIPackageBuilder addAlldomain(Collection domainCollection) { * @parameter standardCompliance standardCompliance to add * @return this for chaining **/ - AIPackageBuilder addstandardCompliance(String standardCompliance) { + AIPackageBuilder addStandardCompliance(String standardCompliance) { if (Objects.nonNull(standardCompliance)) { standardCompliances.add(standardCompliance); } @@ -504,7 +504,7 @@ AIPackageBuilder addstandardCompliance(String standardCompliance) { * @parameter standardComplianceCollection collection to initialize the standardCompliance * @return this for chaining **/ - AIPackageBuilder addAllstandardCompliance(Collection standardComplianceCollection) { + AIPackageBuilder addAllStandardCompliance(Collection standardComplianceCollection) { if (Objects.nonNull(standardComplianceCollection)) { standardCompliances.addAll(standardComplianceCollection); } @@ -516,7 +516,7 @@ AIPackageBuilder addAllstandardCompliance(Collection standardComplianceC * @parameter modelDataPreprocessing modelDataPreprocessing to add * @return this for chaining **/ - AIPackageBuilder addmodelDataPreprocessing(String modelDataPreprocessing) { + AIPackageBuilder addModelDataPreprocessing(String modelDataPreprocessing) { if (Objects.nonNull(modelDataPreprocessing)) { modelDataPreprocessings.add(modelDataPreprocessing); } @@ -528,7 +528,7 @@ AIPackageBuilder addmodelDataPreprocessing(String modelDataPreprocessing) { * @parameter modelDataPreprocessingCollection collection to initialize the modelDataPreprocessing * @return this for chaining **/ - AIPackageBuilder addAllmodelDataPreprocessing(Collection modelDataPreprocessingCollection) { + AIPackageBuilder addAllModelDataPreprocessing(Collection modelDataPreprocessingCollection) { if (Objects.nonNull(modelDataPreprocessingCollection)) { modelDataPreprocessings.addAll(modelDataPreprocessingCollection); } @@ -540,7 +540,7 @@ AIPackageBuilder addAllmodelDataPreprocessing(Collection modelDataPrepro * @parameter typeOfModel typeOfModel to add * @return this for chaining **/ - AIPackageBuilder addtypeOfModel(String typeOfModel) { + AIPackageBuilder addTypeOfModel(String typeOfModel) { if (Objects.nonNull(typeOfModel)) { typeOfModels.add(typeOfModel); } @@ -552,7 +552,7 @@ AIPackageBuilder addtypeOfModel(String typeOfModel) { * @parameter typeOfModelCollection collection to initialize the typeOfModel * @return this for chaining **/ - AIPackageBuilder addAlltypeOfModel(Collection typeOfModelCollection) { + AIPackageBuilder addAllTypeOfModel(Collection typeOfModelCollection) { if (Objects.nonNull(typeOfModelCollection)) { typeOfModels.addAll(typeOfModelCollection); } @@ -564,7 +564,7 @@ AIPackageBuilder addAlltypeOfModel(Collection typeOfModelCollection) { * @parameter modelExplainability modelExplainability to add * @return this for chaining **/ - AIPackageBuilder addmodelExplainability(String modelExplainability) { + AIPackageBuilder addModelExplainability(String modelExplainability) { if (Objects.nonNull(modelExplainability)) { modelExplainabilitys.add(modelExplainability); } @@ -576,7 +576,7 @@ AIPackageBuilder addmodelExplainability(String modelExplainability) { * @parameter modelExplainabilityCollection collection to initialize the modelExplainability * @return this for chaining **/ - AIPackageBuilder addAllmodelExplainability(Collection modelExplainabilityCollection) { + AIPackageBuilder addAllModelExplainability(Collection modelExplainabilityCollection) { if (Objects.nonNull(modelExplainabilityCollection)) { modelExplainabilitys.addAll(modelExplainabilityCollection); } @@ -588,7 +588,7 @@ AIPackageBuilder addAllmodelExplainability(Collection modelExplainabilit * @parameter sensitivePersonalInformation value to set * @return this for chaining **/ - AIPackageBuilder setsensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + AIPackageBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { this.sensitivePersonalInformation = sensitivePersonalInformation; return this; } @@ -598,7 +598,7 @@ AIPackageBuilder setsensitivePersonalInformation(PresenceType sensitivePersonalI * @parameter safetyRiskAssessment value to set * @return this for chaining **/ - AIPackageBuilder setsafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAssessment) { + AIPackageBuilder setSafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAssessment) { this.safetyRiskAssessment = safetyRiskAssessment; return this; } @@ -608,7 +608,7 @@ AIPackageBuilder setsafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAsse * @parameter autonomyType value to set * @return this for chaining **/ - AIPackageBuilder setautonomyType(PresenceType autonomyType) { + AIPackageBuilder setAutonomyType(PresenceType autonomyType) { this.autonomyType = autonomyType; return this; } @@ -618,7 +618,7 @@ AIPackageBuilder setautonomyType(PresenceType autonomyType) { * @parameter informationAboutTraining value to set * @return this for chaining **/ - AIPackageBuilder setinformationAboutTraining(String informationAboutTraining) { + AIPackageBuilder setInformationAboutTraining(String informationAboutTraining) { this.informationAboutTraining = informationAboutTraining; return this; } @@ -628,7 +628,7 @@ AIPackageBuilder setinformationAboutTraining(String informationAboutTraining) { * @parameter limitation value to set * @return this for chaining **/ - AIPackageBuilder setlimitation(String limitation) { + AIPackageBuilder setLimitation(String limitation) { this.limitation = limitation; return this; } @@ -638,7 +638,7 @@ AIPackageBuilder setlimitation(String limitation) { * @parameter energyConsumption value to set * @return this for chaining **/ - AIPackageBuilder setenergyConsumption(String energyConsumption) { + AIPackageBuilder setEnergyConsumption(String energyConsumption) { this.energyConsumption = energyConsumption; return this; } @@ -648,7 +648,7 @@ AIPackageBuilder setenergyConsumption(String energyConsumption) { * @parameter informationAboutApplication value to set * @return this for chaining **/ - AIPackageBuilder setinformationAboutApplication(String informationAboutApplication) { + AIPackageBuilder setInformationAboutApplication(String informationAboutApplication) { this.informationAboutApplication = informationAboutApplication; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/build/Build.java b/generated/src/main/java/org/spdx/library/model/build/Build.java index f8e0f9721..6a8765c78 100644 --- a/generated/src/main/java/org/spdx/library/model/build/Build.java +++ b/generated/src/main/java/org/spdx/library/model/build/Build.java @@ -286,7 +286,7 @@ public BuildBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCop * @parameter parameters parameters to add * @return this for chaining **/ - BuildBuilder addparameters(DictionaryEntry parameters) { + BuildBuilder addParameters(DictionaryEntry parameters) { if (Objects.nonNull(parameters)) { parameterss.add(parameters); } @@ -298,7 +298,7 @@ BuildBuilder addparameters(DictionaryEntry parameters) { * @parameter parametersCollection collection to initialize the parameters * @return this for chaining **/ - BuildBuilder addAllparameters(Collection parametersCollection) { + BuildBuilder addAllParameters(Collection parametersCollection) { if (Objects.nonNull(parametersCollection)) { parameterss.addAll(parametersCollection); } @@ -310,7 +310,7 @@ BuildBuilder addAllparameters(Collection parametersCollection) * @parameter configSourceDigest configSourceDigest to add * @return this for chaining **/ - BuildBuilder addconfigSourceDigest(Hash configSourceDigest) { + BuildBuilder addConfigSourceDigest(Hash configSourceDigest) { if (Objects.nonNull(configSourceDigest)) { configSourceDigests.add(configSourceDigest); } @@ -322,7 +322,7 @@ BuildBuilder addconfigSourceDigest(Hash configSourceDigest) { * @parameter configSourceDigestCollection collection to initialize the configSourceDigest * @return this for chaining **/ - BuildBuilder addAllconfigSourceDigest(Collection configSourceDigestCollection) { + BuildBuilder addAllConfigSourceDigest(Collection configSourceDigestCollection) { if (Objects.nonNull(configSourceDigestCollection)) { configSourceDigests.addAll(configSourceDigestCollection); } @@ -334,7 +334,7 @@ BuildBuilder addAllconfigSourceDigest(Collection configSourceDigestCollect * @parameter environment environment to add * @return this for chaining **/ - BuildBuilder addenvironment(DictionaryEntry environment) { + BuildBuilder addEnvironment(DictionaryEntry environment) { if (Objects.nonNull(environment)) { environments.add(environment); } @@ -346,7 +346,7 @@ BuildBuilder addenvironment(DictionaryEntry environment) { * @parameter environmentCollection collection to initialize the environment * @return this for chaining **/ - BuildBuilder addAllenvironment(Collection environmentCollection) { + BuildBuilder addAllEnvironment(Collection environmentCollection) { if (Objects.nonNull(environmentCollection)) { environments.addAll(environmentCollection); } @@ -358,7 +358,7 @@ BuildBuilder addAllenvironment(Collection environmentCollection * @parameter configSourceEntrypoint configSourceEntrypoint to add * @return this for chaining **/ - BuildBuilder addconfigSourceEntrypoint(String configSourceEntrypoint) { + BuildBuilder addConfigSourceEntrypoint(String configSourceEntrypoint) { if (Objects.nonNull(configSourceEntrypoint)) { configSourceEntrypoints.add(configSourceEntrypoint); } @@ -370,7 +370,7 @@ BuildBuilder addconfigSourceEntrypoint(String configSourceEntrypoint) { * @parameter configSourceEntrypointCollection collection to initialize the configSourceEntrypoint * @return this for chaining **/ - BuildBuilder addAllconfigSourceEntrypoint(Collection configSourceEntrypointCollection) { + BuildBuilder addAllConfigSourceEntrypoint(Collection configSourceEntrypointCollection) { if (Objects.nonNull(configSourceEntrypointCollection)) { configSourceEntrypoints.addAll(configSourceEntrypointCollection); } @@ -382,7 +382,7 @@ BuildBuilder addAllconfigSourceEntrypoint(Collection configSourceEntrypo * @parameter configSourceUri configSourceUri to add * @return this for chaining **/ - BuildBuilder addconfigSourceUri(String configSourceUri) { + BuildBuilder addConfigSourceUri(String configSourceUri) { if (Objects.nonNull(configSourceUri)) { configSourceUris.add(configSourceUri); } @@ -394,7 +394,7 @@ BuildBuilder addconfigSourceUri(String configSourceUri) { * @parameter configSourceUriCollection collection to initialize the configSourceUri * @return this for chaining **/ - BuildBuilder addAllconfigSourceUri(Collection configSourceUriCollection) { + BuildBuilder addAllConfigSourceUri(Collection configSourceUriCollection) { if (Objects.nonNull(configSourceUriCollection)) { configSourceUris.addAll(configSourceUriCollection); } @@ -406,7 +406,7 @@ BuildBuilder addAllconfigSourceUri(Collection configSourceUriCollection) * @parameter buildEndTime value to set * @return this for chaining **/ - BuildBuilder setbuildEndTime(String buildEndTime) { + BuildBuilder setBuildEndTime(String buildEndTime) { this.buildEndTime = buildEndTime; return this; } @@ -416,7 +416,7 @@ BuildBuilder setbuildEndTime(String buildEndTime) { * @parameter buildType value to set * @return this for chaining **/ - BuildBuilder setbuildType(String buildType) { + BuildBuilder setBuildType(String buildType) { this.buildType = buildType; return this; } @@ -426,7 +426,7 @@ BuildBuilder setbuildType(String buildType) { * @parameter buildStartTime value to set * @return this for chaining **/ - BuildBuilder setbuildStartTime(String buildStartTime) { + BuildBuilder setBuildStartTime(String buildStartTime) { this.buildStartTime = buildStartTime; return this; } @@ -436,7 +436,7 @@ BuildBuilder setbuildStartTime(String buildStartTime) { * @parameter buildId value to set * @return this for chaining **/ - BuildBuilder setbuildId(String buildId) { + BuildBuilder setBuildId(String buildId) { this.buildId = buildId; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Annotation.java b/generated/src/main/java/org/spdx/library/model/core/Annotation.java index d4a60271c..cbccbebb4 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Annotation.java +++ b/generated/src/main/java/org/spdx/library/model/core/Annotation.java @@ -221,7 +221,7 @@ public AnnotationBuilder(IModelStore modelStore, String objectUri, @Nullable Mod * @parameter subject value to set * @return this for chaining **/ - AnnotationBuilder setsubject(Element subject) { + AnnotationBuilder setSubject(Element subject) { this.subject = subject; return this; } @@ -231,7 +231,7 @@ AnnotationBuilder setsubject(Element subject) { * @parameter annotationType value to set * @return this for chaining **/ - AnnotationBuilder setannotationType(AnnotationType annotationType) { + AnnotationBuilder setAnnotationType(AnnotationType annotationType) { this.annotationType = annotationType; return this; } @@ -241,7 +241,7 @@ AnnotationBuilder setannotationType(AnnotationType annotationType) { * @parameter statement value to set * @return this for chaining **/ - AnnotationBuilder setstatement(String statement) { + AnnotationBuilder setStatement(String statement) { this.statement = statement; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Artifact.java b/generated/src/main/java/org/spdx/library/model/core/Artifact.java index d284b22d7..893a91c33 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Artifact.java +++ b/generated/src/main/java/org/spdx/library/model/core/Artifact.java @@ -226,7 +226,7 @@ public ArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable Model * @parameter originatedBy originatedBy to add * @return this for chaining **/ - ArtifactBuilder addoriginatedBy(Agent originatedBy) { + ArtifactBuilder addOriginatedBy(Agent originatedBy) { if (Objects.nonNull(originatedBy)) { originatedBys.add(originatedBy); } @@ -238,7 +238,7 @@ ArtifactBuilder addoriginatedBy(Agent originatedBy) { * @parameter originatedByCollection collection to initialize the originatedBy * @return this for chaining **/ - ArtifactBuilder addAlloriginatedBy(Collection originatedByCollection) { + ArtifactBuilder addAllOriginatedBy(Collection originatedByCollection) { if (Objects.nonNull(originatedByCollection)) { originatedBys.addAll(originatedByCollection); } @@ -250,7 +250,7 @@ ArtifactBuilder addAlloriginatedBy(Collection originatedByCollection) { * @parameter suppliedBy suppliedBy to add * @return this for chaining **/ - ArtifactBuilder addsuppliedBy(Agent suppliedBy) { + ArtifactBuilder addSuppliedBy(Agent suppliedBy) { if (Objects.nonNull(suppliedBy)) { suppliedBys.add(suppliedBy); } @@ -262,7 +262,7 @@ ArtifactBuilder addsuppliedBy(Agent suppliedBy) { * @parameter suppliedByCollection collection to initialize the suppliedBy * @return this for chaining **/ - ArtifactBuilder addAllsuppliedBy(Collection suppliedByCollection) { + ArtifactBuilder addAllSuppliedBy(Collection suppliedByCollection) { if (Objects.nonNull(suppliedByCollection)) { suppliedBys.addAll(suppliedByCollection); } @@ -274,7 +274,7 @@ ArtifactBuilder addAllsuppliedBy(Collection suppliedByCollection) { * @parameter standard standard to add * @return this for chaining **/ - ArtifactBuilder addstandard(String standard) { + ArtifactBuilder addStandard(String standard) { if (Objects.nonNull(standard)) { standards.add(standard); } @@ -286,7 +286,7 @@ ArtifactBuilder addstandard(String standard) { * @parameter standardCollection collection to initialize the standard * @return this for chaining **/ - ArtifactBuilder addAllstandard(Collection standardCollection) { + ArtifactBuilder addAllStandard(Collection standardCollection) { if (Objects.nonNull(standardCollection)) { standards.addAll(standardCollection); } @@ -298,7 +298,7 @@ ArtifactBuilder addAllstandard(Collection standardCollection) { * @parameter releaseTime value to set * @return this for chaining **/ - ArtifactBuilder setreleaseTime(String releaseTime) { + ArtifactBuilder setReleaseTime(String releaseTime) { this.releaseTime = releaseTime; return this; } @@ -308,7 +308,7 @@ ArtifactBuilder setreleaseTime(String releaseTime) { * @parameter validUntilTime value to set * @return this for chaining **/ - ArtifactBuilder setvalidUntilTime(String validUntilTime) { + ArtifactBuilder setValidUntilTime(String validUntilTime) { this.validUntilTime = validUntilTime; return this; } @@ -318,7 +318,7 @@ ArtifactBuilder setvalidUntilTime(String validUntilTime) { * @parameter builtTime value to set * @return this for chaining **/ - ArtifactBuilder setbuiltTime(String builtTime) { + ArtifactBuilder setBuiltTime(String builtTime) { this.builtTime = builtTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Bundle.java b/generated/src/main/java/org/spdx/library/model/core/Bundle.java index a75a35f21..d4589bb45 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Bundle.java +++ b/generated/src/main/java/org/spdx/library/model/core/Bundle.java @@ -147,7 +147,7 @@ public BundleBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCo * @parameter context value to set * @return this for chaining **/ - BundleBuilder setcontext(String context) { + BundleBuilder setContext(String context) { this.context = context; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java b/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java index 2a031fb1f..6811cb19b 100644 --- a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java +++ b/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java @@ -211,7 +211,7 @@ public CreationInfoBuilder(IModelStore modelStore, String objectUri, @Nullable M * @parameter createdUsing createdUsing to add * @return this for chaining **/ - CreationInfoBuilder addcreatedUsing(Tool createdUsing) { + CreationInfoBuilder addCreatedUsing(Tool createdUsing) { if (Objects.nonNull(createdUsing)) { createdUsings.add(createdUsing); } @@ -223,7 +223,7 @@ CreationInfoBuilder addcreatedUsing(Tool createdUsing) { * @parameter createdUsingCollection collection to initialize the createdUsing * @return this for chaining **/ - CreationInfoBuilder addAllcreatedUsing(Collection createdUsingCollection) { + CreationInfoBuilder addAllCreatedUsing(Collection createdUsingCollection) { if (Objects.nonNull(createdUsingCollection)) { createdUsings.addAll(createdUsingCollection); } @@ -235,7 +235,7 @@ CreationInfoBuilder addAllcreatedUsing(Collection createdUsingCollection) * @parameter createdBy createdBy to add * @return this for chaining **/ - CreationInfoBuilder addcreatedBy(Agent createdBy) { + CreationInfoBuilder addCreatedBy(Agent createdBy) { if (Objects.nonNull(createdBy)) { createdBys.add(createdBy); } @@ -247,7 +247,7 @@ CreationInfoBuilder addcreatedBy(Agent createdBy) { * @parameter createdByCollection collection to initialize the createdBy * @return this for chaining **/ - CreationInfoBuilder addAllcreatedBy(Collection createdByCollection) { + CreationInfoBuilder addAllCreatedBy(Collection createdByCollection) { if (Objects.nonNull(createdByCollection)) { createdBys.addAll(createdByCollection); } @@ -259,7 +259,7 @@ CreationInfoBuilder addAllcreatedBy(Collection createdByCollection) { * @parameter profile profile to add * @return this for chaining **/ - CreationInfoBuilder addprofile(ProfileIdentifierType profile) { + CreationInfoBuilder addProfile(ProfileIdentifierType profile) { if (Objects.nonNull(profile)) { profiles.add(profile); } @@ -271,7 +271,7 @@ CreationInfoBuilder addprofile(ProfileIdentifierType profile) { * @parameter profileCollection collection to initialize the profile * @return this for chaining **/ - CreationInfoBuilder addAllprofile(Collection profileCollection) { + CreationInfoBuilder addAllProfile(Collection profileCollection) { if (Objects.nonNull(profileCollection)) { profiles.addAll(profileCollection); } @@ -283,7 +283,7 @@ CreationInfoBuilder addAllprofile(Collection profileColle * @parameter created created to add * @return this for chaining **/ - CreationInfoBuilder addcreated(String created) { + CreationInfoBuilder addCreated(String created) { if (Objects.nonNull(created)) { createds.add(created); } @@ -295,7 +295,7 @@ CreationInfoBuilder addcreated(String created) { * @parameter createdCollection collection to initialize the created * @return this for chaining **/ - CreationInfoBuilder addAllcreated(Collection createdCollection) { + CreationInfoBuilder addAllCreated(Collection createdCollection) { if (Objects.nonNull(createdCollection)) { createds.addAll(createdCollection); } @@ -307,7 +307,7 @@ CreationInfoBuilder addAllcreated(Collection createdCollection) { * @parameter dataLicense dataLicense to add * @return this for chaining **/ - CreationInfoBuilder adddataLicense(String dataLicense) { + CreationInfoBuilder addDataLicense(String dataLicense) { if (Objects.nonNull(dataLicense)) { dataLicenses.add(dataLicense); } @@ -319,7 +319,7 @@ CreationInfoBuilder adddataLicense(String dataLicense) { * @parameter dataLicenseCollection collection to initialize the dataLicense * @return this for chaining **/ - CreationInfoBuilder addAlldataLicense(Collection dataLicenseCollection) { + CreationInfoBuilder addAllDataLicense(Collection dataLicenseCollection) { if (Objects.nonNull(dataLicenseCollection)) { dataLicenses.addAll(dataLicenseCollection); } @@ -331,7 +331,7 @@ CreationInfoBuilder addAlldataLicense(Collection dataLicenseCollection) * @parameter specVersion specVersion to add * @return this for chaining **/ - CreationInfoBuilder addspecVersion(String specVersion) { + CreationInfoBuilder addSpecVersion(String specVersion) { if (Objects.nonNull(specVersion)) { specVersions.add(specVersion); } @@ -343,7 +343,7 @@ CreationInfoBuilder addspecVersion(String specVersion) { * @parameter specVersionCollection collection to initialize the specVersion * @return this for chaining **/ - CreationInfoBuilder addAllspecVersion(Collection specVersionCollection) { + CreationInfoBuilder addAllSpecVersion(Collection specVersionCollection) { if (Objects.nonNull(specVersionCollection)) { specVersions.addAll(specVersionCollection); } @@ -355,7 +355,7 @@ CreationInfoBuilder addAllspecVersion(Collection specVersionCollection) * @parameter comment value to set * @return this for chaining **/ - CreationInfoBuilder setcomment(String comment) { + CreationInfoBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java index 7461f251d..6761a6a6d 100644 --- a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java +++ b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java @@ -179,7 +179,7 @@ public DictionaryEntryBuilder(IModelStore modelStore, String objectUri, @Nullabl * @parameter key value to set * @return this for chaining **/ - DictionaryEntryBuilder setkey(String key) { + DictionaryEntryBuilder setKey(String key) { this.key = key; return this; } @@ -189,7 +189,7 @@ DictionaryEntryBuilder setkey(String key) { * @parameter value value to set * @return this for chaining **/ - DictionaryEntryBuilder setvalue(String value) { + DictionaryEntryBuilder setValue(String value) { this.value = value; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Element.java b/generated/src/main/java/org/spdx/library/model/core/Element.java index 84595ed81..ca16738c2 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Element.java +++ b/generated/src/main/java/org/spdx/library/model/core/Element.java @@ -198,7 +198,7 @@ public ElementBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter externalReference externalReference to add * @return this for chaining **/ - ElementBuilder addexternalReference(ExternalReference externalReference) { + ElementBuilder addExternalReference(ExternalReference externalReference) { if (Objects.nonNull(externalReference)) { externalReferences.add(externalReference); } @@ -210,7 +210,7 @@ ElementBuilder addexternalReference(ExternalReference externalReference) { * @parameter externalReferenceCollection collection to initialize the externalReference * @return this for chaining **/ - ElementBuilder addAllexternalReference(Collection externalReferenceCollection) { + ElementBuilder addAllExternalReference(Collection externalReferenceCollection) { if (Objects.nonNull(externalReferenceCollection)) { externalReferences.addAll(externalReferenceCollection); } @@ -222,7 +222,7 @@ ElementBuilder addAllexternalReference(Collection externalRef * @parameter externalIdentifier externalIdentifier to add * @return this for chaining **/ - ElementBuilder addexternalIdentifier(ExternalIdentifier externalIdentifier) { + ElementBuilder addExternalIdentifier(ExternalIdentifier externalIdentifier) { if (Objects.nonNull(externalIdentifier)) { externalIdentifiers.add(externalIdentifier); } @@ -234,7 +234,7 @@ ElementBuilder addexternalIdentifier(ExternalIdentifier externalIdentifier) { * @parameter externalIdentifierCollection collection to initialize the externalIdentifier * @return this for chaining **/ - ElementBuilder addAllexternalIdentifier(Collection externalIdentifierCollection) { + ElementBuilder addAllExternalIdentifier(Collection externalIdentifierCollection) { if (Objects.nonNull(externalIdentifierCollection)) { externalIdentifiers.addAll(externalIdentifierCollection); } @@ -246,7 +246,7 @@ ElementBuilder addAllexternalIdentifier(Collection externalI * @parameter description value to set * @return this for chaining **/ - ElementBuilder setdescription(String description) { + ElementBuilder setDescription(String description) { this.description = description; return this; } @@ -256,7 +256,7 @@ ElementBuilder setdescription(String description) { * @parameter summary value to set * @return this for chaining **/ - ElementBuilder setsummary(String summary) { + ElementBuilder setSummary(String summary) { this.summary = summary; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java b/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java index 734703720..bf10cce1f 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java +++ b/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java @@ -154,7 +154,7 @@ public ElementCollectionBuilder(IModelStore modelStore, String objectUri, @Nulla * @parameter element element to add * @return this for chaining **/ - ElementCollectionBuilder addelement(Element element) { + ElementCollectionBuilder addElement(Element element) { if (Objects.nonNull(element)) { elements.add(element); } @@ -166,7 +166,7 @@ ElementCollectionBuilder addelement(Element element) { * @parameter elementCollection collection to initialize the element * @return this for chaining **/ - ElementCollectionBuilder addAllelement(Collection elementCollection) { + ElementCollectionBuilder addAllElement(Collection elementCollection) { if (Objects.nonNull(elementCollection)) { elements.addAll(elementCollection); } @@ -178,7 +178,7 @@ ElementCollectionBuilder addAllelement(Collection elementCollection) { * @parameter rootElement rootElement to add * @return this for chaining **/ - ElementCollectionBuilder addrootElement(Element rootElement) { + ElementCollectionBuilder addRootElement(Element rootElement) { if (Objects.nonNull(rootElement)) { rootElements.add(rootElement); } @@ -190,7 +190,7 @@ ElementCollectionBuilder addrootElement(Element rootElement) { * @parameter rootElementCollection collection to initialize the rootElement * @return this for chaining **/ - ElementCollectionBuilder addAllrootElement(Collection rootElementCollection) { + ElementCollectionBuilder addAllRootElement(Collection rootElementCollection) { if (Objects.nonNull(rootElementCollection)) { rootElements.addAll(rootElementCollection); } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java index 287d3944c..966d4dd50 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java @@ -248,7 +248,7 @@ public ExternalIdentifierBuilder(IModelStore modelStore, String objectUri, @Null * @parameter identifierLocator identifierLocator to add * @return this for chaining **/ - ExternalIdentifierBuilder addidentifierLocator(String identifierLocator) { + ExternalIdentifierBuilder addIdentifierLocator(String identifierLocator) { if (Objects.nonNull(identifierLocator)) { identifierLocators.add(identifierLocator); } @@ -260,7 +260,7 @@ ExternalIdentifierBuilder addidentifierLocator(String identifierLocator) { * @parameter identifierLocatorCollection collection to initialize the identifierLocator * @return this for chaining **/ - ExternalIdentifierBuilder addAllidentifierLocator(Collection identifierLocatorCollection) { + ExternalIdentifierBuilder addAllIdentifierLocator(Collection identifierLocatorCollection) { if (Objects.nonNull(identifierLocatorCollection)) { identifierLocators.addAll(identifierLocatorCollection); } @@ -272,7 +272,7 @@ ExternalIdentifierBuilder addAllidentifierLocator(Collection identifierL * @parameter externalIdentifierType value to set * @return this for chaining **/ - ExternalIdentifierBuilder setexternalIdentifierType(ExternalIdentifierType externalIdentifierType) { + ExternalIdentifierBuilder setExternalIdentifierType(ExternalIdentifierType externalIdentifierType) { this.externalIdentifierType = externalIdentifierType; return this; } @@ -282,7 +282,7 @@ ExternalIdentifierBuilder setexternalIdentifierType(ExternalIdentifierType exter * @parameter issuingAuthority value to set * @return this for chaining **/ - ExternalIdentifierBuilder setissuingAuthority(String issuingAuthority) { + ExternalIdentifierBuilder setIssuingAuthority(String issuingAuthority) { this.issuingAuthority = issuingAuthority; return this; } @@ -292,7 +292,7 @@ ExternalIdentifierBuilder setissuingAuthority(String issuingAuthority) { * @parameter identifier value to set * @return this for chaining **/ - ExternalIdentifierBuilder setidentifier(String identifier) { + ExternalIdentifierBuilder setIdentifier(String identifier) { this.identifier = identifier; return this; } @@ -302,7 +302,7 @@ ExternalIdentifierBuilder setidentifier(String identifier) { * @parameter comment value to set * @return this for chaining **/ - ExternalIdentifierBuilder setcomment(String comment) { + ExternalIdentifierBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java index 15ede6f7a..9b7483adc 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java @@ -214,7 +214,7 @@ public ExternalMapBuilder(IModelStore modelStore, String objectUri, @Nullable Mo * @parameter verifiedUsing verifiedUsing to add * @return this for chaining **/ - ExternalMapBuilder addverifiedUsing(IntegrityMethod verifiedUsing) { + ExternalMapBuilder addVerifiedUsing(IntegrityMethod verifiedUsing) { if (Objects.nonNull(verifiedUsing)) { verifiedUsings.add(verifiedUsing); } @@ -226,7 +226,7 @@ ExternalMapBuilder addverifiedUsing(IntegrityMethod verifiedUsing) { * @parameter verifiedUsingCollection collection to initialize the verifiedUsing * @return this for chaining **/ - ExternalMapBuilder addAllverifiedUsing(Collection verifiedUsingCollection) { + ExternalMapBuilder addAllVerifiedUsing(Collection verifiedUsingCollection) { if (Objects.nonNull(verifiedUsingCollection)) { verifiedUsings.addAll(verifiedUsingCollection); } @@ -238,7 +238,7 @@ ExternalMapBuilder addAllverifiedUsing(Collection verifiedUsing * @parameter definingDocument value to set * @return this for chaining **/ - ExternalMapBuilder setdefiningDocument(String definingDocument) { + ExternalMapBuilder setDefiningDocument(String definingDocument) { this.definingDocument = definingDocument; return this; } @@ -248,7 +248,7 @@ ExternalMapBuilder setdefiningDocument(String definingDocument) { * @parameter locationHint value to set * @return this for chaining **/ - ExternalMapBuilder setlocationHint(String locationHint) { + ExternalMapBuilder setLocationHint(String locationHint) { this.locationHint = locationHint; return this; } @@ -258,7 +258,7 @@ ExternalMapBuilder setlocationHint(String locationHint) { * @parameter externalId value to set * @return this for chaining **/ - ExternalMapBuilder setexternalId(String externalId) { + ExternalMapBuilder setExternalId(String externalId) { this.externalId = externalId; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java b/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java index f07263886..6d062f5dc 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java @@ -212,7 +212,7 @@ public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nulla * @parameter locator locator to add * @return this for chaining **/ - ExternalReferenceBuilder addlocator(String locator) { + ExternalReferenceBuilder addLocator(String locator) { if (Objects.nonNull(locator)) { locators.add(locator); } @@ -224,7 +224,7 @@ ExternalReferenceBuilder addlocator(String locator) { * @parameter locatorCollection collection to initialize the locator * @return this for chaining **/ - ExternalReferenceBuilder addAlllocator(Collection locatorCollection) { + ExternalReferenceBuilder addAllLocator(Collection locatorCollection) { if (Objects.nonNull(locatorCollection)) { locators.addAll(locatorCollection); } @@ -236,7 +236,7 @@ ExternalReferenceBuilder addAlllocator(Collection locatorCollection) { * @parameter externalReferenceType value to set * @return this for chaining **/ - ExternalReferenceBuilder setexternalReferenceType(ExternalReferenceType externalReferenceType) { + ExternalReferenceBuilder setExternalReferenceType(ExternalReferenceType externalReferenceType) { this.externalReferenceType = externalReferenceType; return this; } @@ -246,7 +246,7 @@ ExternalReferenceBuilder setexternalReferenceType(ExternalReferenceType external * @parameter contentType value to set * @return this for chaining **/ - ExternalReferenceBuilder setcontentType(String contentType) { + ExternalReferenceBuilder setContentType(String contentType) { this.contentType = contentType; return this; } @@ -256,7 +256,7 @@ ExternalReferenceBuilder setcontentType(String contentType) { * @parameter comment value to set * @return this for chaining **/ - ExternalReferenceBuilder setcomment(String comment) { + ExternalReferenceBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Hash.java b/generated/src/main/java/org/spdx/library/model/core/Hash.java index c4a9b327a..084d0599b 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Hash.java +++ b/generated/src/main/java/org/spdx/library/model/core/Hash.java @@ -195,7 +195,7 @@ public HashBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopy * @parameter algorithm value to set * @return this for chaining **/ - HashBuilder setalgorithm(HashAlgorithm algorithm) { + HashBuilder setAlgorithm(HashAlgorithm algorithm) { this.algorithm = algorithm; return this; } @@ -205,7 +205,7 @@ HashBuilder setalgorithm(HashAlgorithm algorithm) { * @parameter hashValue value to set * @return this for chaining **/ - HashBuilder sethashValue(String hashValue) { + HashBuilder setHashValue(String hashValue) { this.hashValue = hashValue; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java b/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java index 3919397fa..f73fdf4ed 100644 --- a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java +++ b/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java @@ -150,7 +150,7 @@ public IntegrityMethodBuilder(IModelStore modelStore, String objectUri, @Nullabl * @parameter comment value to set * @return this for chaining **/ - IntegrityMethodBuilder setcomment(String comment) { + IntegrityMethodBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java index 5ffb5517d..e6cdaf3ee 100644 --- a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java @@ -156,7 +156,7 @@ public LifecycleScopedRelationshipBuilder(IModelStore modelStore, String objectU * @parameter scope value to set * @return this for chaining **/ - LifecycleScopedRelationshipBuilder setscope(LifecycleScopeType scope) { + LifecycleScopedRelationshipBuilder setScope(LifecycleScopeType scope) { this.scope = scope; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java index 2e33b421c..5c5064dc8 100644 --- a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java +++ b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java @@ -185,7 +185,7 @@ public NamespaceMapBuilder(IModelStore modelStore, String objectUri, @Nullable M * @parameter prefix value to set * @return this for chaining **/ - NamespaceMapBuilder setprefix(String prefix) { + NamespaceMapBuilder setPrefix(String prefix) { this.prefix = prefix; return this; } @@ -195,7 +195,7 @@ NamespaceMapBuilder setprefix(String prefix) { * @parameter namespace value to set * @return this for chaining **/ - NamespaceMapBuilder setnamespace(String namespace) { + NamespaceMapBuilder setNamespace(String namespace) { this.namespace = namespace; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Payload.java b/generated/src/main/java/org/spdx/library/model/core/Payload.java index e96905533..67bc30bd5 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Payload.java +++ b/generated/src/main/java/org/spdx/library/model/core/Payload.java @@ -184,7 +184,7 @@ public PayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter namespaces namespaces to add * @return this for chaining **/ - PayloadBuilder addnamespaces(NamespaceMap namespaces) { + PayloadBuilder addNamespaces(NamespaceMap namespaces) { if (Objects.nonNull(namespaces)) { namespacess.add(namespaces); } @@ -196,7 +196,7 @@ PayloadBuilder addnamespaces(NamespaceMap namespaces) { * @parameter namespacesCollection collection to initialize the namespaces * @return this for chaining **/ - PayloadBuilder addAllnamespaces(Collection namespacesCollection) { + PayloadBuilder addAllNamespaces(Collection namespacesCollection) { if (Objects.nonNull(namespacesCollection)) { namespacess.addAll(namespacesCollection); } @@ -208,7 +208,7 @@ PayloadBuilder addAllnamespaces(Collection namespacesCollection) { * @parameter imports imports to add * @return this for chaining **/ - PayloadBuilder addimports(ExternalMap imports) { + PayloadBuilder addImports(ExternalMap imports) { if (Objects.nonNull(imports)) { importss.add(imports); } @@ -220,7 +220,7 @@ PayloadBuilder addimports(ExternalMap imports) { * @parameter importsCollection collection to initialize the imports * @return this for chaining **/ - PayloadBuilder addAllimports(Collection importsCollection) { + PayloadBuilder addAllImports(Collection importsCollection) { if (Objects.nonNull(importsCollection)) { importss.addAll(importsCollection); } @@ -232,7 +232,7 @@ PayloadBuilder addAllimports(Collection importsCollection) { * @parameter creationInfo value to set * @return this for chaining **/ - PayloadBuilder setcreationInfo(CreationInfo creationInfo) { + PayloadBuilder setCreationInfo(CreationInfo creationInfo) { this.creationInfo = creationInfo; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java index c143c9ef8..27b21dcff 100644 --- a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java +++ b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java @@ -210,7 +210,7 @@ public PositiveIntegerRangeBuilder(IModelStore modelStore, String objectUri, @Nu * @parameter end value to set * @return this for chaining **/ - PositiveIntegerRangeBuilder setend(Integer end) { + PositiveIntegerRangeBuilder setEnd(Integer end) { this.end = end; return this; } @@ -220,7 +220,7 @@ PositiveIntegerRangeBuilder setend(Integer end) { * @parameter begin value to set * @return this for chaining **/ - PositiveIntegerRangeBuilder setbegin(Integer begin) { + PositiveIntegerRangeBuilder setBegin(Integer begin) { this.begin = begin; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Relationship.java b/generated/src/main/java/org/spdx/library/model/core/Relationship.java index 0527fceb0..d4e0545fd 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Relationship.java +++ b/generated/src/main/java/org/spdx/library/model/core/Relationship.java @@ -290,7 +290,7 @@ public RelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable M * @parameter to to to add * @return this for chaining **/ - RelationshipBuilder addto(Element to) { + RelationshipBuilder addTo(Element to) { if (Objects.nonNull(to)) { tos.add(to); } @@ -302,7 +302,7 @@ RelationshipBuilder addto(Element to) { * @parameter toCollection collection to initialize the to * @return this for chaining **/ - RelationshipBuilder addAllto(Collection toCollection) { + RelationshipBuilder addAllTo(Collection toCollection) { if (Objects.nonNull(toCollection)) { tos.addAll(toCollection); } @@ -314,7 +314,7 @@ RelationshipBuilder addAllto(Collection toCollection) { * @parameter from value to set * @return this for chaining **/ - RelationshipBuilder setfrom(Element from) { + RelationshipBuilder setFrom(Element from) { this.from = from; return this; } @@ -324,7 +324,7 @@ RelationshipBuilder setfrom(Element from) { * @parameter relationshipType value to set * @return this for chaining **/ - RelationshipBuilder setrelationshipType(RelationshipType relationshipType) { + RelationshipBuilder setRelationshipType(RelationshipType relationshipType) { this.relationshipType = relationshipType; return this; } @@ -334,7 +334,7 @@ RelationshipBuilder setrelationshipType(RelationshipType relationshipType) { * @parameter completeness value to set * @return this for chaining **/ - RelationshipBuilder setcompleteness(RelationshipCompleteness completeness) { + RelationshipBuilder setCompleteness(RelationshipCompleteness completeness) { this.completeness = completeness; return this; } @@ -344,7 +344,7 @@ RelationshipBuilder setcompleteness(RelationshipCompleteness completeness) { * @parameter startTime value to set * @return this for chaining **/ - RelationshipBuilder setstartTime(String startTime) { + RelationshipBuilder setStartTime(String startTime) { this.startTime = startTime; return this; } @@ -354,7 +354,7 @@ RelationshipBuilder setstartTime(String startTime) { * @parameter endTime value to set * @return this for chaining **/ - RelationshipBuilder setendTime(String endTime) { + RelationshipBuilder setEndTime(String endTime) { this.endTime = endTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java index 04746f3cc..f6af48b80 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java +++ b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java @@ -146,6 +146,7 @@ public Collection getKnownBiass() { return knownBiass; } + /** * @return the confidentialityLevel @@ -373,7 +374,7 @@ public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter sensor sensor to add * @return this for chaining **/ - DatasetBuilder addsensor(DictionaryEntry sensor) { + DatasetBuilder addSensor(DictionaryEntry sensor) { if (Objects.nonNull(sensor)) { sensors.add(sensor); } @@ -385,7 +386,7 @@ DatasetBuilder addsensor(DictionaryEntry sensor) { * @parameter sensorCollection collection to initialize the sensor * @return this for chaining **/ - DatasetBuilder addAllsensor(Collection sensorCollection) { + DatasetBuilder addAllSensor(Collection sensorCollection) { if (Objects.nonNull(sensorCollection)) { sensors.addAll(sensorCollection); } @@ -397,7 +398,7 @@ DatasetBuilder addAllsensor(Collection sensorCollection) { * @parameter datasetType datasetType to add * @return this for chaining **/ - DatasetBuilder adddatasetType(DatasetType datasetType) { + DatasetBuilder addDatasetType(DatasetType datasetType) { if (Objects.nonNull(datasetType)) { datasetTypes.add(datasetType); } @@ -409,7 +410,7 @@ DatasetBuilder adddatasetType(DatasetType datasetType) { * @parameter datasetTypeCollection collection to initialize the datasetType * @return this for chaining **/ - DatasetBuilder addAlldatasetType(Collection datasetTypeCollection) { + DatasetBuilder addAllDatasetType(Collection datasetTypeCollection) { if (Objects.nonNull(datasetTypeCollection)) { datasetTypes.addAll(datasetTypeCollection); } @@ -421,7 +422,7 @@ DatasetBuilder addAlldatasetType(Collection datasetTypeCollection) * @parameter anonymizationMethodUsed anonymizationMethodUsed to add * @return this for chaining **/ - DatasetBuilder addanonymizationMethodUsed(String anonymizationMethodUsed) { + DatasetBuilder addAnonymizationMethodUsed(String anonymizationMethodUsed) { if (Objects.nonNull(anonymizationMethodUsed)) { anonymizationMethodUseds.add(anonymizationMethodUsed); } @@ -433,7 +434,7 @@ DatasetBuilder addanonymizationMethodUsed(String anonymizationMethodUsed) { * @parameter anonymizationMethodUsedCollection collection to initialize the anonymizationMethodUsed * @return this for chaining **/ - DatasetBuilder addAllanonymizationMethodUsed(Collection anonymizationMethodUsedCollection) { + DatasetBuilder addAllAnonymizationMethodUsed(Collection anonymizationMethodUsedCollection) { if (Objects.nonNull(anonymizationMethodUsedCollection)) { anonymizationMethodUseds.addAll(anonymizationMethodUsedCollection); } @@ -445,7 +446,7 @@ DatasetBuilder addAllanonymizationMethodUsed(Collection anonymizationMet * @parameter dataPreprocessing dataPreprocessing to add * @return this for chaining **/ - DatasetBuilder adddataPreprocessing(String dataPreprocessing) { + DatasetBuilder addDataPreprocessing(String dataPreprocessing) { if (Objects.nonNull(dataPreprocessing)) { dataPreprocessings.add(dataPreprocessing); } @@ -457,7 +458,7 @@ DatasetBuilder adddataPreprocessing(String dataPreprocessing) { * @parameter dataPreprocessingCollection collection to initialize the dataPreprocessing * @return this for chaining **/ - DatasetBuilder addAlldataPreprocessing(Collection dataPreprocessingCollection) { + DatasetBuilder addAllDataPreprocessing(Collection dataPreprocessingCollection) { if (Objects.nonNull(dataPreprocessingCollection)) { dataPreprocessings.addAll(dataPreprocessingCollection); } @@ -469,7 +470,7 @@ DatasetBuilder addAlldataPreprocessing(Collection dataPreprocessingColle * @parameter knownBias knownBias to add * @return this for chaining **/ - DatasetBuilder addknownBias(String knownBias) { + DatasetBuilder addKnownBias(String knownBias) { if (Objects.nonNull(knownBias)) { knownBiass.add(knownBias); } @@ -481,19 +482,19 @@ DatasetBuilder addknownBias(String knownBias) { * @parameter knownBiasCollection collection to initialize the knownBias * @return this for chaining **/ - DatasetBuilder addAllknownBias(Collection knownBiasCollection) { + DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { if (Objects.nonNull(knownBiasCollection)) { knownBiass.addAll(knownBiasCollection); } return this; } - + /** * Sets the initial value of confidentialityLevel * @parameter confidentialityLevel value to set * @return this for chaining **/ - DatasetBuilder setconfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { + DatasetBuilder setConfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { this.confidentialityLevel = confidentialityLevel; return this; } @@ -503,7 +504,7 @@ DatasetBuilder setconfidentialityLevel(ConfidentialityLevelType confidentialityL * @parameter datasetAvailability value to set * @return this for chaining **/ - DatasetBuilder setdatasetAvailability(DatasetAvailabilityType datasetAvailability) { + DatasetBuilder setDatasetAvailability(DatasetAvailabilityType datasetAvailability) { this.datasetAvailability = datasetAvailability; return this; } @@ -513,7 +514,7 @@ DatasetBuilder setdatasetAvailability(DatasetAvailabilityType datasetAvailabilit * @parameter datasetSize value to set * @return this for chaining **/ - DatasetBuilder setdatasetSize(Integer datasetSize) { + DatasetBuilder setDatasetSize(Integer datasetSize) { this.datasetSize = datasetSize; return this; } @@ -523,7 +524,7 @@ DatasetBuilder setdatasetSize(Integer datasetSize) { * @parameter intendedUse value to set * @return this for chaining **/ - DatasetBuilder setintendedUse(String intendedUse) { + DatasetBuilder setIntendedUse(String intendedUse) { this.intendedUse = intendedUse; return this; } @@ -533,7 +534,7 @@ DatasetBuilder setintendedUse(String intendedUse) { * @parameter datasetNoise value to set * @return this for chaining **/ - DatasetBuilder setdatasetNoise(String datasetNoise) { + DatasetBuilder setDatasetNoise(String datasetNoise) { this.datasetNoise = datasetNoise; return this; } @@ -543,7 +544,7 @@ DatasetBuilder setdatasetNoise(String datasetNoise) { * @parameter dataCollectionProcess value to set * @return this for chaining **/ - DatasetBuilder setdataCollectionProcess(String dataCollectionProcess) { + DatasetBuilder setDataCollectionProcess(String dataCollectionProcess) { this.dataCollectionProcess = dataCollectionProcess; return this; } @@ -553,7 +554,7 @@ DatasetBuilder setdataCollectionProcess(String dataCollectionProcess) { * @parameter datasetUpdateMechanism value to set * @return this for chaining **/ - DatasetBuilder setdatasetUpdateMechanism(String datasetUpdateMechanism) { + DatasetBuilder setDatasetUpdateMechanism(String datasetUpdateMechanism) { this.datasetUpdateMechanism = datasetUpdateMechanism; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/License.java b/generated/src/main/java/org/spdx/library/model/licensing/License.java index 1aba3fac9..b6b9b0223 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/License.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/License.java @@ -275,7 +275,7 @@ public LicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter isFsfLibre value to set * @return this for chaining **/ - LicenseBuilder setisFsfLibre(Boolean isFsfLibre) { + LicenseBuilder setIsFsfLibre(Boolean isFsfLibre) { this.isFsfLibre = isFsfLibre; return this; } @@ -285,7 +285,7 @@ LicenseBuilder setisFsfLibre(Boolean isFsfLibre) { * @parameter isDeprecatedLicenseId value to set * @return this for chaining **/ - LicenseBuilder setisDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { + LicenseBuilder setIsDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { this.isDeprecatedLicenseId = isDeprecatedLicenseId; return this; } @@ -295,7 +295,7 @@ LicenseBuilder setisDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { * @parameter isOsiApproved value to set * @return this for chaining **/ - LicenseBuilder setisOsiApproved(Boolean isOsiApproved) { + LicenseBuilder setIsOsiApproved(Boolean isOsiApproved) { this.isOsiApproved = isOsiApproved; return this; } @@ -305,7 +305,7 @@ LicenseBuilder setisOsiApproved(Boolean isOsiApproved) { * @parameter standardLicenseTemplate value to set * @return this for chaining **/ - LicenseBuilder setstandardLicenseTemplate(String standardLicenseTemplate) { + LicenseBuilder setStandardLicenseTemplate(String standardLicenseTemplate) { this.standardLicenseTemplate = standardLicenseTemplate; return this; } @@ -315,7 +315,7 @@ LicenseBuilder setstandardLicenseTemplate(String standardLicenseTemplate) { * @parameter standardLicenseHeader value to set * @return this for chaining **/ - LicenseBuilder setstandardLicenseHeader(String standardLicenseHeader) { + LicenseBuilder setStandardLicenseHeader(String standardLicenseHeader) { this.standardLicenseHeader = standardLicenseHeader; return this; } @@ -325,7 +325,7 @@ LicenseBuilder setstandardLicenseHeader(String standardLicenseHeader) { * @parameter licenseText value to set * @return this for chaining **/ - LicenseBuilder setlicenseText(String licenseText) { + LicenseBuilder setLicenseText(String licenseText) { this.licenseText = licenseText; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java index 1f7a8f9a6..558f51009 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java @@ -207,7 +207,7 @@ public LicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullabl * @parameter isDeprecatedAdditionId value to set * @return this for chaining **/ - LicenseAdditionBuilder setisDeprecatedAdditionId(Boolean isDeprecatedAdditionId) { + LicenseAdditionBuilder setIsDeprecatedAdditionId(Boolean isDeprecatedAdditionId) { this.isDeprecatedAdditionId = isDeprecatedAdditionId; return this; } @@ -217,7 +217,7 @@ LicenseAdditionBuilder setisDeprecatedAdditionId(Boolean isDeprecatedAdditionId) * @parameter standardAdditionTemplate value to set * @return this for chaining **/ - LicenseAdditionBuilder setstandardAdditionTemplate(String standardAdditionTemplate) { + LicenseAdditionBuilder setStandardAdditionTemplate(String standardAdditionTemplate) { this.standardAdditionTemplate = standardAdditionTemplate; return this; } @@ -227,7 +227,7 @@ LicenseAdditionBuilder setstandardAdditionTemplate(String standardAdditionTempla * @parameter additionText value to set * @return this for chaining **/ - LicenseAdditionBuilder setadditionText(String additionText) { + LicenseAdditionBuilder setAdditionText(String additionText) { this.additionText = additionText; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java index 831e37121..c759ae4e1 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java @@ -169,7 +169,7 @@ public LicenseExpressionBuilder(IModelStore modelStore, String objectUri, @Nulla * @parameter licenseExpression value to set * @return this for chaining **/ - LicenseExpressionBuilder setlicenseExpression(String licenseExpression) { + LicenseExpressionBuilder setLicenseExpression(String licenseExpression) { this.licenseExpression = licenseExpression; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java index 1959b6538..dd2e99760 100644 --- a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java @@ -175,7 +175,7 @@ public EpssVulnAssessmentRelationshipBuilder(IModelStore modelStore, String obje * @parameter probability value to set * @return this for chaining **/ - EpssVulnAssessmentRelationshipBuilder setprobability(Integer probability) { + EpssVulnAssessmentRelationshipBuilder setProbability(Integer probability) { this.probability = probability; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java index 1a921b7ce..fc3d4aad2 100644 --- a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java @@ -233,7 +233,7 @@ public ExploitCatalogVulnAssessmentRelationshipBuilder(IModelStore modelStore, S * @parameter catalogType value to set * @return this for chaining **/ - ExploitCatalogVulnAssessmentRelationshipBuilder setcatalogType(ExploitCatalogType catalogType) { + ExploitCatalogVulnAssessmentRelationshipBuilder setCatalogType(ExploitCatalogType catalogType) { this.catalogType = catalogType; return this; } @@ -243,7 +243,7 @@ ExploitCatalogVulnAssessmentRelationshipBuilder setcatalogType(ExploitCatalogTyp * @parameter exploited value to set * @return this for chaining **/ - ExploitCatalogVulnAssessmentRelationshipBuilder setexploited(Boolean exploited) { + ExploitCatalogVulnAssessmentRelationshipBuilder setExploited(Boolean exploited) { this.exploited = exploited; return this; } @@ -253,7 +253,7 @@ ExploitCatalogVulnAssessmentRelationshipBuilder setexploited(Boolean exploited) * @parameter locator value to set * @return this for chaining **/ - ExploitCatalogVulnAssessmentRelationshipBuilder setlocator(String locator) { + ExploitCatalogVulnAssessmentRelationshipBuilder setLocator(String locator) { this.locator = locator; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java index d06e99ee5..ab7d3cc5e 100644 --- a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java @@ -171,7 +171,7 @@ public SsvcVulnAssessmentRelationshipBuilder(IModelStore modelStore, String obje * @parameter decisionType value to set * @return this for chaining **/ - SsvcVulnAssessmentRelationshipBuilder setdecisionType(SsvcDecisionType decisionType) { + SsvcVulnAssessmentRelationshipBuilder setDecisionType(SsvcDecisionType decisionType) { this.decisionType = decisionType; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java index c77e8770c..237edacf1 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java @@ -169,7 +169,7 @@ public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, Stri * @parameter actionStatementTime actionStatementTime to add * @return this for chaining **/ - VexAffectedVulnAssessmentRelationshipBuilder addactionStatementTime(String actionStatementTime) { + VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(String actionStatementTime) { if (Objects.nonNull(actionStatementTime)) { actionStatementTimes.add(actionStatementTime); } @@ -181,7 +181,7 @@ VexAffectedVulnAssessmentRelationshipBuilder addactionStatementTime(String actio * @parameter actionStatementTimeCollection collection to initialize the actionStatementTime * @return this for chaining **/ - VexAffectedVulnAssessmentRelationshipBuilder addAllactionStatementTime(Collection actionStatementTimeCollection) { + VexAffectedVulnAssessmentRelationshipBuilder addAllActionStatementTime(Collection actionStatementTimeCollection) { if (Objects.nonNull(actionStatementTimeCollection)) { actionStatementTimes.addAll(actionStatementTimeCollection); } @@ -193,7 +193,7 @@ VexAffectedVulnAssessmentRelationshipBuilder addAllactionStatementTime(Collectio * @parameter actionStatement value to set * @return this for chaining **/ - VexAffectedVulnAssessmentRelationshipBuilder setactionStatement(String actionStatement) { + VexAffectedVulnAssessmentRelationshipBuilder setActionStatement(String actionStatement) { this.actionStatement = actionStatement; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java index a37b3f204..0b67435ae 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java @@ -218,7 +218,7 @@ public VexNotAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, S * @parameter justificationType value to set * @return this for chaining **/ - VexNotAffectedVulnAssessmentRelationshipBuilder setjustificationType(VexJustificationType justificationType) { + VexNotAffectedVulnAssessmentRelationshipBuilder setJustificationType(VexJustificationType justificationType) { this.justificationType = justificationType; return this; } @@ -228,7 +228,7 @@ VexNotAffectedVulnAssessmentRelationshipBuilder setjustificationType(VexJustific * @parameter impactStatementTime value to set * @return this for chaining **/ - VexNotAffectedVulnAssessmentRelationshipBuilder setimpactStatementTime(String impactStatementTime) { + VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatementTime(String impactStatementTime) { this.impactStatementTime = impactStatementTime; return this; } @@ -238,7 +238,7 @@ VexNotAffectedVulnAssessmentRelationshipBuilder setimpactStatementTime(String im * @parameter impactStatement value to set * @return this for chaining **/ - VexNotAffectedVulnAssessmentRelationshipBuilder setimpactStatement(String impactStatement) { + VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatement(String impactStatement) { this.impactStatement = impactStatement; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java index 227accccc..64d4a65a1 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java @@ -183,7 +183,7 @@ public VexVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objec * @parameter statusNotes value to set * @return this for chaining **/ - VexVulnAssessmentRelationshipBuilder setstatusNotes(String statusNotes) { + VexVulnAssessmentRelationshipBuilder setStatusNotes(String statusNotes) { this.statusNotes = statusNotes; return this; } @@ -193,7 +193,7 @@ VexVulnAssessmentRelationshipBuilder setstatusNotes(String statusNotes) { * @parameter vexVersion value to set * @return this for chaining **/ - VexVulnAssessmentRelationshipBuilder setvexVersion(String vexVersion) { + VexVulnAssessmentRelationshipBuilder setVexVersion(String vexVersion) { this.vexVersion = vexVersion; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java index b88237514..afcfe2f30 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java @@ -186,7 +186,7 @@ public VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUr * @parameter assessedElement value to set * @return this for chaining **/ - VulnAssessmentRelationshipBuilder setassessedElement(Element assessedElement) { + VulnAssessmentRelationshipBuilder setAssessedElement(Element assessedElement) { this.assessedElement = assessedElement; return this; } @@ -196,7 +196,7 @@ VulnAssessmentRelationshipBuilder setassessedElement(Element assessedElement) { * @parameter suppliedBy value to set * @return this for chaining **/ - VulnAssessmentRelationshipBuilder setsuppliedBy(Agent suppliedBy) { + VulnAssessmentRelationshipBuilder setSuppliedBy(Agent suppliedBy) { this.suppliedBy = suppliedBy; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/Sbom.java b/generated/src/main/java/org/spdx/library/model/software/Sbom.java index 9a5cbfd76..9c6535ddc 100644 --- a/generated/src/main/java/org/spdx/library/model/software/Sbom.java +++ b/generated/src/main/java/org/spdx/library/model/software/Sbom.java @@ -138,7 +138,7 @@ public SbomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopy * @parameter sbomType sbomType to add * @return this for chaining **/ - SbomBuilder addsbomType(SBOMType sbomType) { + SbomBuilder addSbomType(SBOMType sbomType) { if (Objects.nonNull(sbomType)) { sbomTypes.add(sbomType); } @@ -150,7 +150,7 @@ SbomBuilder addsbomType(SBOMType sbomType) { * @parameter sbomTypeCollection collection to initialize the sbomType * @return this for chaining **/ - SbomBuilder addAllsbomType(Collection sbomTypeCollection) { + SbomBuilder addAllSbomType(Collection sbomTypeCollection) { if (Objects.nonNull(sbomTypeCollection)) { sbomTypes.addAll(sbomTypeCollection); } diff --git a/generated/src/main/java/org/spdx/library/model/software/Snippet.java b/generated/src/main/java/org/spdx/library/model/software/Snippet.java index bd46bd7aa..1790ef56e 100644 --- a/generated/src/main/java/org/spdx/library/model/software/Snippet.java +++ b/generated/src/main/java/org/spdx/library/model/software/Snippet.java @@ -203,7 +203,7 @@ public SnippetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter byteRange value to set * @return this for chaining **/ - SnippetBuilder setbyteRange(PositiveIntegerRange byteRange) { + SnippetBuilder setByteRange(PositiveIntegerRange byteRange) { this.byteRange = byteRange; return this; } @@ -213,7 +213,7 @@ SnippetBuilder setbyteRange(PositiveIntegerRange byteRange) { * @parameter lineRange value to set * @return this for chaining **/ - SnippetBuilder setlineRange(PositiveIntegerRange lineRange) { + SnippetBuilder setLineRange(PositiveIntegerRange lineRange) { this.lineRange = lineRange; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java index e54661f63..41ca3cd16 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java @@ -294,7 +294,7 @@ public SoftwareArtifactBuilder(IModelStore modelStore, String objectUri, @Nullab * @parameter additionalPurpose additionalPurpose to add * @return this for chaining **/ - SoftwareArtifactBuilder addadditionalPurpose(SoftwarePurpose additionalPurpose) { + SoftwareArtifactBuilder addAdditionalPurpose(SoftwarePurpose additionalPurpose) { if (Objects.nonNull(additionalPurpose)) { additionalPurposes.add(additionalPurpose); } @@ -306,7 +306,7 @@ SoftwareArtifactBuilder addadditionalPurpose(SoftwarePurpose additionalPurpose) * @parameter additionalPurposeCollection collection to initialize the additionalPurpose * @return this for chaining **/ - SoftwareArtifactBuilder addAlladditionalPurpose(Collection additionalPurposeCollection) { + SoftwareArtifactBuilder addAllAdditionalPurpose(Collection additionalPurposeCollection) { if (Objects.nonNull(additionalPurposeCollection)) { additionalPurposes.addAll(additionalPurposeCollection); } @@ -318,7 +318,7 @@ SoftwareArtifactBuilder addAlladditionalPurpose(Collection addi * @parameter declaredLicense value to set * @return this for chaining **/ - SoftwareArtifactBuilder setdeclaredLicense(AnyLicenseInfo declaredLicense) { + SoftwareArtifactBuilder setDeclaredLicense(AnyLicenseInfo declaredLicense) { this.declaredLicense = declaredLicense; return this; } @@ -328,7 +328,7 @@ SoftwareArtifactBuilder setdeclaredLicense(AnyLicenseInfo declaredLicense) { * @parameter concludedLicense value to set * @return this for chaining **/ - SoftwareArtifactBuilder setconcludedLicense(AnyLicenseInfo concludedLicense) { + SoftwareArtifactBuilder setConcludedLicense(AnyLicenseInfo concludedLicense) { this.concludedLicense = concludedLicense; return this; } @@ -338,7 +338,7 @@ SoftwareArtifactBuilder setconcludedLicense(AnyLicenseInfo concludedLicense) { * @parameter primaryPurpose value to set * @return this for chaining **/ - SoftwareArtifactBuilder setprimaryPurpose(SoftwarePurpose primaryPurpose) { + SoftwareArtifactBuilder setPrimaryPurpose(SoftwarePurpose primaryPurpose) { this.primaryPurpose = primaryPurpose; return this; } @@ -348,7 +348,7 @@ SoftwareArtifactBuilder setprimaryPurpose(SoftwarePurpose primaryPurpose) { * @parameter contentIdentifier value to set * @return this for chaining **/ - SoftwareArtifactBuilder setcontentIdentifier(String contentIdentifier) { + SoftwareArtifactBuilder setContentIdentifier(String contentIdentifier) { this.contentIdentifier = contentIdentifier; return this; } @@ -358,7 +358,7 @@ SoftwareArtifactBuilder setcontentIdentifier(String contentIdentifier) { * @parameter attributionText value to set * @return this for chaining **/ - SoftwareArtifactBuilder setattributionText(String attributionText) { + SoftwareArtifactBuilder setAttributionText(String attributionText) { this.attributionText = attributionText; return this; } @@ -368,7 +368,7 @@ SoftwareArtifactBuilder setattributionText(String attributionText) { * @parameter copyrightText value to set * @return this for chaining **/ - SoftwareArtifactBuilder setcopyrightText(String copyrightText) { + SoftwareArtifactBuilder setCopyrightText(String copyrightText) { this.copyrightText = copyrightText; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java index 4f24bd782..d7df81d4b 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java @@ -190,7 +190,7 @@ public SoftwareDependencyRelationshipBuilder(IModelStore modelStore, String obje * @parameter softwareLinkage value to set * @return this for chaining **/ - SoftwareDependencyRelationshipBuilder setsoftwareLinkage(SoftwareDependencyLinkType softwareLinkage) { + SoftwareDependencyRelationshipBuilder setSoftwareLinkage(SoftwareDependencyLinkType softwareLinkage) { this.softwareLinkage = softwareLinkage; return this; } @@ -200,7 +200,7 @@ SoftwareDependencyRelationshipBuilder setsoftwareLinkage(SoftwareDependencyLinkT * @parameter conditionality value to set * @return this for chaining **/ - SoftwareDependencyRelationshipBuilder setconditionality(DependencyConditionalityType conditionality) { + SoftwareDependencyRelationshipBuilder setConditionality(DependencyConditionalityType conditionality) { this.conditionality = conditionality; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java b/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java index 8ab225752..f7565bf14 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java +++ b/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java @@ -150,7 +150,7 @@ public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable Model * @parameter contentType value to set * @return this for chaining **/ - SpdxFileBuilder setcontentType(String contentType) { + SpdxFileBuilder setContentType(String contentType) { this.contentType = contentType; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java b/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java index af0e686fa..c0303fb69 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java +++ b/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java @@ -249,7 +249,7 @@ public SpdxPackageBuilder(IModelStore modelStore, String objectUri, @Nullable Mo * @parameter downloadLocation value to set * @return this for chaining **/ - SpdxPackageBuilder setdownloadLocation(String downloadLocation) { + SpdxPackageBuilder setDownloadLocation(String downloadLocation) { this.downloadLocation = downloadLocation; return this; } @@ -259,7 +259,7 @@ SpdxPackageBuilder setdownloadLocation(String downloadLocation) { * @parameter sourceInfo value to set * @return this for chaining **/ - SpdxPackageBuilder setsourceInfo(String sourceInfo) { + SpdxPackageBuilder setSourceInfo(String sourceInfo) { this.sourceInfo = sourceInfo; return this; } @@ -269,7 +269,7 @@ SpdxPackageBuilder setsourceInfo(String sourceInfo) { * @parameter packageVersion value to set * @return this for chaining **/ - SpdxPackageBuilder setpackageVersion(String packageVersion) { + SpdxPackageBuilder setPackageVersion(String packageVersion) { this.packageVersion = packageVersion; return this; } @@ -279,7 +279,7 @@ SpdxPackageBuilder setpackageVersion(String packageVersion) { * @parameter homePage value to set * @return this for chaining **/ - SpdxPackageBuilder sethomePage(String homePage) { + SpdxPackageBuilder setHomePage(String homePage) { this.homePage = homePage; return this; } @@ -289,7 +289,7 @@ SpdxPackageBuilder sethomePage(String homePage) { * @parameter packageUrl value to set * @return this for chaining **/ - SpdxPackageBuilder setpackageUrl(String packageUrl) { + SpdxPackageBuilder setPackageUrl(String packageUrl) { this.packageUrl = packageUrl; return this; } diff --git a/src/test/java/org/spdx/library/model/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/ai/AIPackageTest.java index 3cc310698..29fc79bf3 100644 --- a/src/test/java/org/spdx/library/model/ai/AIPackageTest.java +++ b/src/test/java/org/spdx/library/model/ai/AIPackageTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.ai.AIPackage.AIPackageBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,41 @@ public class AIPackageTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String INFORMATION_ABOUT_TRAINING_TEST_VALUE = "test informationAboutTraining"; + static final String LIMITATION_TEST_VALUE = "test limitation"; + static final String ENERGY_CONSUMPTION_TEST_VALUE = "test energyConsumption"; + static final String INFORMATION_ABOUT_APPLICATION_TEST_VALUE = "test informationAboutApplication"; + static final String DOMAIN_TEST_VALUE1 = "test 1 domain"; + static final String DOMAIN_TEST_VALUE2 = "test 2 domain"; + static final String DOMAIN_TEST_VALUE3 = "test 3 domain"; + static final List DOMAIN_TEST_LIST1 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE1, DOMAIN_TEST_VALUE2 }); + static final List DOMAIN_TEST_LIST2 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE3 }); + static final String STANDARD_COMPLIANCE_TEST_VALUE1 = "test 1 standardCompliance"; + static final String STANDARD_COMPLIANCE_TEST_VALUE2 = "test 2 standardCompliance"; + static final String STANDARD_COMPLIANCE_TEST_VALUE3 = "test 3 standardCompliance"; + static final List STANDARD_COMPLIANCE_TEST_LIST1 = Arrays.asList(new String[] { STANDARD_COMPLIANCE_TEST_VALUE1, STANDARD_COMPLIANCE_TEST_VALUE2 }); + static final List STANDARD_COMPLIANCE_TEST_LIST2 = Arrays.asList(new String[] { STANDARD_COMPLIANCE_TEST_VALUE3 }); + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE1 = "test 1 modelDataPreprocessing"; + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE2 = "test 2 modelDataPreprocessing"; + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE3 = "test 3 modelDataPreprocessing"; + static final List MODEL_DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE1, MODEL_DATA_PREPROCESSING_TEST_VALUE2 }); + static final List MODEL_DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE3 }); + static final String TYPE_OF_MODEL_TEST_VALUE1 = "test 1 typeOfModel"; + static final String TYPE_OF_MODEL_TEST_VALUE2 = "test 2 typeOfModel"; + static final String TYPE_OF_MODEL_TEST_VALUE3 = "test 3 typeOfModel"; + static final List TYPE_OF_MODEL_TEST_LIST1 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE1, TYPE_OF_MODEL_TEST_VALUE2 }); + static final List TYPE_OF_MODEL_TEST_LIST2 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE3 }); + static final String MODEL_EXPLAINABILITY_TEST_VALUE1 = "test 1 modelExplainability"; + static final String MODEL_EXPLAINABILITY_TEST_VALUE2 = "test 2 modelExplainability"; + static final String MODEL_EXPLAINABILITY_TEST_VALUE3 = "test 3 modelExplainability"; + static final List MODEL_EXPLAINABILITY_TEST_LIST1 = Arrays.asList(new String[] { MODEL_EXPLAINABILITY_TEST_VALUE1, MODEL_EXPLAINABILITY_TEST_VALUE2 }); + static final List MODEL_EXPLAINABILITY_TEST_LIST2 = Arrays.asList(new String[] { MODEL_EXPLAINABILITY_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,25 +83,31 @@ protected void tearDown() throws Exception { public static AIPackageBuilder builderForAIPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setsensitivePersonalInformation(PresenceType.ENUM) - .setsafetyRiskAssessment(SafetyRiskAssessmentType.ENUM) - .setautonomyType(PresenceType.ENUM) - .setinformationAboutTraining("A string") - .setlimitation("A string") - .setenergyConsumption("A string") - .setinformationAboutApplication("A string") - .getmetric.add(DictionaryEntry) - .gethyperparameter.add(DictionaryEntry) - .getmetricDecisionThreshold.add(DictionaryEntry) - .getdomain.add("Test string") - .getstandardCompliance.add("Test string") - .getmodelDataPreprocessing.add("Test string") - .gettypeOfModel.add("Test string") - .getmodelExplainability.add("Test string") - ***************/ + AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager) + .setInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) + .setLimitation(LIMITATION_TEST_VALUE) + .setEnergyConsumption(ENERGY_CONSUMPTION_TEST_VALUE) + .setInformationAboutApplication(INFORMATION_ABOUT_APPLICATION_TEST_VALUE) + .addDomain(DOMAIN_TEST_VALUE1) + .addDomain(DOMAIN_TEST_VALUE2) + .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) + .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE2) + .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) + .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) + .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE1) + .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) + .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE1) + .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE2) + //TODO: Add in test values + /******************** + .setSensitivePersonalInformation(PresenceType.ENUM) + .setSafetyRiskAssessment(SafetyRiskAssessmentType.ENUM) + .setAutonomyType(PresenceType.ENUM) + .addMetric(DictionaryEntry) + .addHyperparameter(DictionaryEntry) + .addMetricDecisionThreshold(DictionaryEntry) + ***************/ + ; return retval; } @@ -105,7 +142,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.ai.AIPackage#Element(org.spdx.library.model.ai.AIPackage.AIPackageBuilder)}. */ public void testAIPackageAIPackageBuilder() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -154,10 +191,9 @@ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { */ public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getInformationAboutTraining()); -// testAIPackage.setInformationAboutTraining(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getInformationAboutTraining()); - fail("Not yet implemented"); + assertEquals(INFORMATION_ABOUT_TRAINING_TEST_VALUE, testAIPackage.getInformationAboutTraining()); + testAIPackage.setInformationAboutTraining("new informationAboutTraining value"); + assertEquals("new informationAboutTraining value", testAIPackage.getInformationAboutTraining()); } /** @@ -165,10 +201,9 @@ public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysi */ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getLimitation()); -// testAIPackage.setLimitation(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getLimitation()); - fail("Not yet implemented"); + assertEquals(LIMITATION_TEST_VALUE, testAIPackage.getLimitation()); + testAIPackage.setLimitation("new limitation value"); + assertEquals("new limitation value", testAIPackage.getLimitation()); } /** @@ -176,10 +211,9 @@ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { */ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getEnergyConsumption()); -// testAIPackage.setEnergyConsumption(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getEnergyConsumption()); - fail("Not yet implemented"); + assertEquals(ENERGY_CONSUMPTION_TEST_VALUE, testAIPackage.getEnergyConsumption()); + testAIPackage.setEnergyConsumption("new energyConsumption value"); + assertEquals("new energyConsumption value", testAIPackage.getEnergyConsumption()); } /** @@ -187,109 +221,104 @@ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisExcept */ public void testAIPackagesetInformationAboutApplication() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getInformationAboutApplication()); -// testAIPackage.setInformationAboutApplication(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getInformationAboutApplication()); - fail("Not yet implemented"); + assertEquals(INFORMATION_ABOUT_APPLICATION_TEST_VALUE, testAIPackage.getInformationAboutApplication()); + testAIPackage.setInformationAboutApplication("new informationAboutApplication value"); + assertEquals("new informationAboutApplication value", testAIPackage.getInformationAboutApplication()); } /** * Test method for {@link org.spdx.library.model.ai.AIPackage#getMetric}. */ - public void testAIPackagesetMetric() throws InvalidSPDXAnalysisException { + public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetric())); -// testAIPackage.getMetric().clear(); -// testAIPackage.getMetric().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetric())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); +// testAIPackage.getMetrics().clear(); +// testAIPackage.getMetrics().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ai.AIPackage#getHyperparameter}. */ - public void testAIPackagesetHyperparameter() throws InvalidSPDXAnalysisException { + public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameter())); -// testAIPackage.getHyperparameter().clear(); -// testAIPackage.getHyperparameter().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameter())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); +// testAIPackage.getHyperparameters().clear(); +// testAIPackage.getHyperparameters().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ai.AIPackage#getMetricDecisionThreshold}. */ - public void testAIPackagesetMetricDecisionThreshold() throws InvalidSPDXAnalysisException { + public void testAIPackagegetMetricDecisionThresholds() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThreshold())); -// testAIPackage.getMetricDecisionThreshold().clear(); -// testAIPackage.getMetricDecisionThreshold().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThreshold())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThresholds()))); +// testAIPackage.getMetricDecisionThresholds().clear(); +// testAIPackage.getMetricDecisionThresholds().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThresholds()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getDomain}. + * Test method for {@link org.spdx.library.model.ai.AIPackage#getDomains}. */ - public void testAIPackagegetDomain() throws InvalidSPDXAnalysisException { + public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getDomain())); -// testAIPackage.getDomain().clear(); -// testAIPackage.getDomain().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getDomain())); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getDomains()))); + testAIPackage.getDomains().clear(); + testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getStandardCompliance}. + * Test method for {@link org.spdx.library.model.ai.AIPackage#getStandardCompliances}. */ - public void testAIPackagegetStandardCompliance() throws InvalidSPDXAnalysisException { + public void testAIPackagegetStandardCompliances() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getStandardCompliance())); -// testAIPackage.getStandardCompliance().clear(); -// testAIPackage.getStandardCompliance().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getStandardCompliance())); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST1, new ArrayList<>(testAIPackage.getStandardCompliances()))); + testAIPackage.getStandardCompliances().clear(); + testAIPackage.getStandardCompliances().addAll(STANDARD_COMPLIANCE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST2, new ArrayList<>(testAIPackage.getStandardCompliances()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelDataPreprocessing}. + * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelDataPreprocessings}. */ - public void testAIPackagegetModelDataPreprocessing() throws InvalidSPDXAnalysisException { + public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getModelDataPreprocessing())); -// testAIPackage.getModelDataPreprocessing().clear(); -// testAIPackage.getModelDataPreprocessing().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getModelDataPreprocessing())); + assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); + testAIPackage.getModelDataPreprocessings().clear(); + testAIPackage.getModelDataPreprocessings().addAll(MODEL_DATA_PREPROCESSING_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getTypeOfModel}. + * Test method for {@link org.spdx.library.model.ai.AIPackage#getTypeOfModels}. */ - public void testAIPackagegetTypeOfModel() throws InvalidSPDXAnalysisException { + public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getTypeOfModel())); -// testAIPackage.getTypeOfModel().clear(); -// testAIPackage.getTypeOfModel().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getTypeOfModel())); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getTypeOfModels()))); + testAIPackage.getTypeOfModels().clear(); + testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelExplainability}. + * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelExplainabilitys}. */ - public void testAIPackagegetModelExplainability() throws InvalidSPDXAnalysisException { + public void testAIPackagegetModelExplainabilitys() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testAIPackage.getModelExplainability())); -// testAIPackage.getModelExplainability().clear(); -// testAIPackage.getModelExplainability().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getModelExplainability())); + assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST1, new ArrayList<>(testAIPackage.getModelExplainabilitys()))); + testAIPackage.getModelExplainabilitys().clear(); + testAIPackage.getModelExplainabilitys().addAll(MODEL_EXPLAINABILITY_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST2, new ArrayList<>(testAIPackage.getModelExplainabilitys()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/build/BuildTest.java b/src/test/java/org/spdx/library/model/build/BuildTest.java index 10f9f8e2f..77d3d6bac 100644 --- a/src/test/java/org/spdx/library/model/build/BuildTest.java +++ b/src/test/java/org/spdx/library/model/build/BuildTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.build.Build.BuildBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,26 @@ public class BuildTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String BUILD_END_TIME_TEST_VALUE = "test buildEndTime"; + static final String BUILD_TYPE_TEST_VALUE = "test buildType"; + static final String BUILD_START_TIME_TEST_VALUE = "test buildStartTime"; + static final String BUILD_ID_TEST_VALUE = "test buildId"; + static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1 = "test 1 configSourceEntrypoint"; + static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2 = "test 2 configSourceEntrypoint"; + static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE3 = "test 3 configSourceEntrypoint"; + static final List CONFIG_SOURCE_ENTRYPOINT_TEST_LIST1 = Arrays.asList(new String[] { CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1, CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2 }); + static final List CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2 = Arrays.asList(new String[] { CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE3 }); + static final String CONFIG_SOURCE_URI_TEST_VALUE1 = "test 1 configSourceUri"; + static final String CONFIG_SOURCE_URI_TEST_VALUE2 = "test 2 configSourceUri"; + static final String CONFIG_SOURCE_URI_TEST_VALUE3 = "test 3 configSourceUri"; + static final List CONFIG_SOURCE_URI_TEST_LIST1 = Arrays.asList(new String[] { CONFIG_SOURCE_URI_TEST_VALUE1, CONFIG_SOURCE_URI_TEST_VALUE2 }); + static final List CONFIG_SOURCE_URI_TEST_LIST2 = Arrays.asList(new String[] { CONFIG_SOURCE_URI_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,19 +68,22 @@ protected void tearDown() throws Exception { public static BuildBuilder builderForBuildTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - BuildBuilder retval = new BuildBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setbuildEndTime("A string") - .setbuildType("A string") - .setbuildStartTime("A string") - .setbuildId("A string") - .getparameters.add(DictionaryEntry) - .getconfigSourceDigest.add(Hash) - .getenvironment.add(DictionaryEntry) - .getconfigSourceEntrypoint.add("Test string") - .getconfigSourceUri.add("Test string") - ***************/ + BuildBuilder retval = new BuildBuilder(modelStore, objectUri, copyManager) + .setBuildEndTime(BUILD_END_TIME_TEST_VALUE) + .setBuildType(BUILD_TYPE_TEST_VALUE) + .setBuildStartTime(BUILD_START_TIME_TEST_VALUE) + .setBuildId(BUILD_ID_TEST_VALUE) + .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1) + .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2) + .addConfigSourceUri(CONFIG_SOURCE_URI_TEST_VALUE1) + .addConfigSourceUri(CONFIG_SOURCE_URI_TEST_VALUE2) + //TODO: Add in test values + /******************** + .addParameters(DictionaryEntry) + .addConfigSourceDigest(Hash) + .addEnvironment(DictionaryEntry) + ***************/ + ; return retval; } @@ -99,7 +118,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.build.Build#Element(org.spdx.library.model.build.Build.BuildBuilder)}. */ public void testBuildBuildBuilder() throws InvalidSPDXAnalysisException { - Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -115,10 +134,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testBuild.getBuildEndTime()); -// testBuild.setBuildEndTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testBuild.getBuildEndTime()); - fail("Not yet implemented"); + assertEquals(BUILD_END_TIME_TEST_VALUE, testBuild.getBuildEndTime()); + testBuild.setBuildEndTime("new buildEndTime value"); + assertEquals("new buildEndTime value", testBuild.getBuildEndTime()); } /** @@ -126,10 +144,9 @@ public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testBuild.getBuildType()); -// testBuild.setBuildType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testBuild.getBuildType()); - fail("Not yet implemented"); + assertEquals(BUILD_TYPE_TEST_VALUE, testBuild.getBuildType()); + testBuild.setBuildType("new buildType value"); + assertEquals("new buildType value", testBuild.getBuildType()); } /** @@ -137,10 +154,9 @@ public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testBuild.getBuildStartTime()); -// testBuild.setBuildStartTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testBuild.getBuildStartTime()); - fail("Not yet implemented"); + assertEquals(BUILD_START_TIME_TEST_VALUE, testBuild.getBuildStartTime()); + testBuild.setBuildStartTime("new buildStartTime value"); + assertEquals("new buildStartTime value", testBuild.getBuildStartTime()); } /** @@ -148,73 +164,68 @@ public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildId() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testBuild.getBuildId()); -// testBuild.setBuildId(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testBuild.getBuildId()); - fail("Not yet implemented"); + assertEquals(BUILD_ID_TEST_VALUE, testBuild.getBuildId()); + testBuild.setBuildId("new buildId value"); + assertEquals("new buildId value", testBuild.getBuildId()); } /** * Test method for {@link org.spdx.library.model.build.Build#getParameters}. */ - public void testBuildsetParameters() throws InvalidSPDXAnalysisException { + public void testBuildgetParameterss() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getParameters())); -// testBuild.getParameters().clear(); -// testBuild.getParameters().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getParameters())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getParameterss()))); +// testBuild.getParameterss().clear(); +// testBuild.getParameterss().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getParameterss()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceDigest}. */ - public void testBuildsetConfigSourceDigest() throws InvalidSPDXAnalysisException { + public void testBuildgetConfigSourceDigests() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigest())); -// testBuild.getConfigSourceDigest().clear(); -// testBuild.getConfigSourceDigest().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigest())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigests()))); +// testBuild.getConfigSourceDigests().clear(); +// testBuild.getConfigSourceDigests().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigests()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.build.Build#getEnvironment}. */ - public void testBuildsetEnvironment() throws InvalidSPDXAnalysisException { + public void testBuildgetEnvironments() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getEnvironment())); -// testBuild.getEnvironment().clear(); -// testBuild.getEnvironment().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getEnvironment())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getEnvironments()))); +// testBuild.getEnvironments().clear(); +// testBuild.getEnvironments().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getEnvironments()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceEntrypoint}. + * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceEntrypoints}. */ - public void testBuildgetConfigSourceEntrypoint() throws InvalidSPDXAnalysisException { + public void testBuildgetConfigSourceEntrypoints() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceEntrypoint())); -// testBuild.getConfigSourceEntrypoint().clear(); -// testBuild.getConfigSourceEntrypoint().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceEntrypoint())); + assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST1, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); + testBuild.getConfigSourceEntrypoints().clear(); + testBuild.getConfigSourceEntrypoints().addAll(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceUri}. + * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceUris}. */ - public void testBuildgetConfigSourceUri() throws InvalidSPDXAnalysisException { + public void testBuildgetConfigSourceUris() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceUri())); -// testBuild.getConfigSourceUri().clear(); -// testBuild.getConfigSourceUri().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceUri())); + assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_URI_TEST_LIST1, new ArrayList<>(testBuild.getConfigSourceUris()))); + testBuild.getConfigSourceUris().clear(); + testBuild.getConfigSourceUris().addAll(CONFIG_SOURCE_URI_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_URI_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceUris()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/AgentTest.java b/src/test/java/org/spdx/library/model/core/AgentTest.java index 0cc4045f3..769791d81 100644 --- a/src/test/java/org/spdx/library/model/core/AgentTest.java +++ b/src/test/java/org/spdx/library/model/core/AgentTest.java @@ -21,24 +21,27 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Agent.AgentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; import junit.framework.TestCase; public class AgentTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -51,10 +54,11 @@ protected void tearDown() throws Exception { public static AgentBuilder builderForAgentTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AgentBuilder retval = new AgentBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + AgentBuilder retval = new AgentBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -89,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Agent#Element(org.spdx.library.model.core.Agent.AgentBuilder)}. */ public void testAgentAgentBuilder() throws InvalidSPDXAnalysisException { - Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -99,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Agent.equivalent(testAgent)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/AnnotationTest.java b/src/test/java/org/spdx/library/model/core/AnnotationTest.java index 69c38c3ce..505974577 100644 --- a/src/test/java/org/spdx/library/model/core/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/core/AnnotationTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Annotation.AnnotationBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class AnnotationTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String STATEMENT_TEST_VALUE = "test statement"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,13 +55,14 @@ protected void tearDown() throws Exception { public static AnnotationBuilder builderForAnnotationTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AnnotationBuilder retval = new AnnotationBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setsubject(Element testElement) - .setannotationType(AnnotationType.ENUM) - .setstatement("A string") - ***************/ + AnnotationBuilder retval = new AnnotationBuilder(modelStore, objectUri, copyManager) + .setStatement(STATEMENT_TEST_VALUE) + //TODO: Add in test values + /******************** + .setSubject(Element testElement) + .setAnnotationType(AnnotationType.ENUM) + ***************/ + ; return retval; } @@ -93,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Annotation#Element(org.spdx.library.model.core.Annotation.AnnotationBuilder)}. */ public void testAnnotationAnnotationBuilder() throws InvalidSPDXAnalysisException { - Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -131,13 +135,8 @@ public void testAnnotationsetAnnotationType() throws InvalidSPDXAnalysisExceptio */ public void testAnnotationsetStatement() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAnnotation.getStatement()); -// testAnnotation.setStatement(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAnnotation.getStatement()); - fail("Not yet implemented"); + assertEquals(STATEMENT_TEST_VALUE, testAnnotation.getStatement()); + testAnnotation.setStatement("new statement value"); + assertEquals("new statement value", testAnnotation.getStatement()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java b/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java index ef3310f2b..7d6777854 100644 --- a/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java +++ b/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.AnonymousPayload.AnonymousPayloadBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class AnonymousPayloadTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static AnonymousPayloadBuilder builderForAnonymousPayloadTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AnonymousPayloadBuilder retval = new AnonymousPayloadBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + AnonymousPayloadBuilder retval = new AnonymousPayloadBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.AnonymousPayload#Element(org.spdx.library.model.core.AnonymousPayload.AnonymousPayloadBuilder)}. */ public void testAnonymousPayloadAnonymousPayloadBuilder() throws InvalidSPDXAnalysisException { - AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2AnonymousPayload.equivalent(testAnonymousPayload)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ArtifactTest.java b/src/test/java/org/spdx/library/model/core/ArtifactTest.java index 9dc30ad2a..d907defe5 100644 --- a/src/test/java/org/spdx/library/model/core/ArtifactTest.java +++ b/src/test/java/org/spdx/library/model/core/ArtifactTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Artifact.ArtifactBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,20 @@ public class ArtifactTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String RELEASE_TIME_TEST_VALUE = "test releaseTime"; + static final String VALID_UNTIL_TIME_TEST_VALUE = "test validUntilTime"; + static final String BUILT_TIME_TEST_VALUE = "test builtTime"; + static final String STANDARD_TEST_VALUE1 = "test 1 standard"; + static final String STANDARD_TEST_VALUE2 = "test 2 standard"; + static final String STANDARD_TEST_VALUE3 = "test 3 standard"; + static final List STANDARD_TEST_LIST1 = Arrays.asList(new String[] { STANDARD_TEST_VALUE1, STANDARD_TEST_VALUE2 }); + static final List STANDARD_TEST_LIST2 = Arrays.asList(new String[] { STANDARD_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,16 +62,18 @@ protected void tearDown() throws Exception { public static ArtifactBuilder builderForArtifactTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ArtifactBuilder retval = new ArtifactBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setreleaseTime("A string") - .setvalidUntilTime("A string") - .setbuiltTime("A string") - .getoriginatedBy.add(Agent) - .getsuppliedBy.add(Agent) - .getstandard.add("Test string") - ***************/ + ArtifactBuilder retval = new ArtifactBuilder(modelStore, objectUri, copyManager) + .setReleaseTime(RELEASE_TIME_TEST_VALUE) + .setValidUntilTime(VALID_UNTIL_TIME_TEST_VALUE) + .setBuiltTime(BUILT_TIME_TEST_VALUE) + .addStandard(STANDARD_TEST_VALUE1) + .addStandard(STANDARD_TEST_VALUE2) + //TODO: Add in test values + /******************** + .addOriginatedBy(Agent) + .addSuppliedBy(Agent) + ***************/ + ; return retval; } @@ -96,7 +108,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Artifact#Element(org.spdx.library.model.core.Artifact.ArtifactBuilder)}. */ public void testArtifactArtifactBuilder() throws InvalidSPDXAnalysisException { - Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -112,10 +124,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testArtifact.getReleaseTime()); -// testArtifact.setReleaseTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testArtifact.getReleaseTime()); - fail("Not yet implemented"); + assertEquals(RELEASE_TIME_TEST_VALUE, testArtifact.getReleaseTime()); + testArtifact.setReleaseTime("new releaseTime value"); + assertEquals("new releaseTime value", testArtifact.getReleaseTime()); } /** @@ -123,10 +134,9 @@ public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { */ public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testArtifact.getValidUntilTime()); -// testArtifact.setValidUntilTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testArtifact.getValidUntilTime()); - fail("Not yet implemented"); + assertEquals(VALID_UNTIL_TIME_TEST_VALUE, testArtifact.getValidUntilTime()); + testArtifact.setValidUntilTime("new validUntilTime value"); + assertEquals("new validUntilTime value", testArtifact.getValidUntilTime()); } /** @@ -134,49 +144,44 @@ public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException */ public void testArtifactsetBuiltTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testArtifact.getBuiltTime()); -// testArtifact.setBuiltTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testArtifact.getBuiltTime()); - fail("Not yet implemented"); + assertEquals(BUILT_TIME_TEST_VALUE, testArtifact.getBuiltTime()); + testArtifact.setBuiltTime("new builtTime value"); + assertEquals("new builtTime value", testArtifact.getBuiltTime()); } /** * Test method for {@link org.spdx.library.model.core.Artifact#getOriginatedBy}. */ - public void testArtifactsetOriginatedBy() throws InvalidSPDXAnalysisException { + public void testArtifactgetOriginatedBys() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBy())); -// testArtifact.getOriginatedBy().clear(); -// testArtifact.getOriginatedBy().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBy())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBys()))); +// testArtifact.getOriginatedBys().clear(); +// testArtifact.getOriginatedBys().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBys()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.core.Artifact#getSuppliedBy}. */ - public void testArtifactsetSuppliedBy() throws InvalidSPDXAnalysisException { + public void testArtifactgetSuppliedBys() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBy())); -// testArtifact.getSuppliedBy().clear(); -// testArtifact.getSuppliedBy().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBy())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBys()))); +// testArtifact.getSuppliedBys().clear(); +// testArtifact.getSuppliedBys().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBys()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.Artifact#getStandard}. + * Test method for {@link org.spdx.library.model.core.Artifact#getStandards}. */ - public void testArtifactgetStandard() throws InvalidSPDXAnalysisException { + public void testArtifactgetStandards() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testArtifact.getStandard())); -// testArtifact.getStandard().clear(); -// testArtifact.getStandard().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getStandard())); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_TEST_LIST1, new ArrayList<>(testArtifact.getStandards()))); + testArtifact.getStandards().clear(); + testArtifact.getStandards().addAll(STANDARD_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_TEST_LIST2, new ArrayList<>(testArtifact.getStandards()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/BomTest.java b/src/test/java/org/spdx/library/model/core/BomTest.java index 497ad14b3..bff2ed487 100644 --- a/src/test/java/org/spdx/library/model/core/BomTest.java +++ b/src/test/java/org/spdx/library/model/core/BomTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Bom.BomBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class BomTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static BomBuilder builderForBomTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - BomBuilder retval = new BomBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + BomBuilder retval = new BomBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Bom#Element(org.spdx.library.model.core.Bom.BomBuilder)}. */ public void testBomBomBuilder() throws InvalidSPDXAnalysisException { - Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Bom.equivalent(testBom)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/BundleTest.java b/src/test/java/org/spdx/library/model/core/BundleTest.java index 2fc52e4eb..39de9f0b8 100644 --- a/src/test/java/org/spdx/library/model/core/BundleTest.java +++ b/src/test/java/org/spdx/library/model/core/BundleTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Bundle.BundleBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class BundleTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String CONTEXT_TEST_VALUE = "test context"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +55,12 @@ protected void tearDown() throws Exception { public static BundleBuilder builderForBundleTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - BundleBuilder retval = new BundleBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setcontext("A string") - ***************/ + BundleBuilder retval = new BundleBuilder(modelStore, objectUri, copyManager) + .setContext(CONTEXT_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Bundle#Element(org.spdx.library.model.core.Bundle.BundleBuilder)}. */ public void testBundleBundleBuilder() throws InvalidSPDXAnalysisException { - Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -107,13 +111,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testBundlesetContext() throws InvalidSPDXAnalysisException { Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testBundle.getContext()); -// testBundle.setContext(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testBundle.getContext()); - fail("Not yet implemented"); + assertEquals(CONTEXT_TEST_VALUE, testBundle.getContext()); + testBundle.setContext("new context value"); + assertEquals("new context value", testBundle.getContext()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/CreationInfoTest.java b/src/test/java/org/spdx/library/model/core/CreationInfoTest.java index af6d1b1ee..2d1153274 100644 --- a/src/test/java/org/spdx/library/model/core/CreationInfoTest.java +++ b/src/test/java/org/spdx/library/model/core/CreationInfoTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.CreationInfo.CreationInfoBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,28 @@ public class CreationInfoTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String COMMENT_TEST_VALUE = "test comment"; + static final String CREATED_TEST_VALUE1 = "test 1 created"; + static final String CREATED_TEST_VALUE2 = "test 2 created"; + static final String CREATED_TEST_VALUE3 = "test 3 created"; + static final List CREATED_TEST_LIST1 = Arrays.asList(new String[] { CREATED_TEST_VALUE1, CREATED_TEST_VALUE2 }); + static final List CREATED_TEST_LIST2 = Arrays.asList(new String[] { CREATED_TEST_VALUE3 }); + static final String DATA_LICENSE_TEST_VALUE1 = "test 1 dataLicense"; + static final String DATA_LICENSE_TEST_VALUE2 = "test 2 dataLicense"; + static final String DATA_LICENSE_TEST_VALUE3 = "test 3 dataLicense"; + static final List DATA_LICENSE_TEST_LIST1 = Arrays.asList(new String[] { DATA_LICENSE_TEST_VALUE1, DATA_LICENSE_TEST_VALUE2 }); + static final List DATA_LICENSE_TEST_LIST2 = Arrays.asList(new String[] { DATA_LICENSE_TEST_VALUE3 }); + static final String SPEC_VERSION_TEST_VALUE1 = "test 1 specVersion"; + static final String SPEC_VERSION_TEST_VALUE2 = "test 2 specVersion"; + static final String SPEC_VERSION_TEST_VALUE3 = "test 3 specVersion"; + static final List SPEC_VERSION_TEST_LIST1 = Arrays.asList(new String[] { SPEC_VERSION_TEST_VALUE1, SPEC_VERSION_TEST_VALUE2 }); + static final List SPEC_VERSION_TEST_LIST2 = Arrays.asList(new String[] { SPEC_VERSION_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,17 +70,21 @@ protected void tearDown() throws Exception { public static CreationInfoBuilder builderForCreationInfoTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - CreationInfoBuilder retval = new CreationInfoBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setcomment("A string") - .getcreatedUsing.add(Tool) - .getcreatedBy.add(Agent) - .getcreated.add("Test string") - .getdataLicense.add("Test string") - .getspecVersion.add("Test string") - .getprofile.add(ProfileIdentifierType.ENUM) - ***************/ + CreationInfoBuilder retval = new CreationInfoBuilder(modelStore, objectUri, copyManager) + .setComment(COMMENT_TEST_VALUE) + .addCreated(CREATED_TEST_VALUE1) + .addCreated(CREATED_TEST_VALUE2) + .addDataLicense(DATA_LICENSE_TEST_VALUE1) + .addDataLicense(DATA_LICENSE_TEST_VALUE2) + .addSpecVersion(SPEC_VERSION_TEST_VALUE1) + .addSpecVersion(SPEC_VERSION_TEST_VALUE2) + //TODO: Add in test values + /******************** + .addCreatedUsing(Tool) + .addCreatedBy(Agent) + .addProfile(ProfileIdentifierType.ENUM) + ***************/ + ; return retval; } @@ -97,7 +119,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.CreationInfo#Element(org.spdx.library.model.core.CreationInfo.CreationInfoBuilder)}. */ public void testCreationInfoCreationInfoBuilder() throws InvalidSPDXAnalysisException { - CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -113,85 +135,80 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testCreationInfo.getComment()); -// testCreationInfo.setComment(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testCreationInfo.getComment()); - fail("Not yet implemented"); + assertEquals(COMMENT_TEST_VALUE, testCreationInfo.getComment()); + testCreationInfo.setComment("new comment value"); + assertEquals("new comment value", testCreationInfo.getComment()); } /** * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreatedUsing}. */ - public void testCreationInfosetCreatedUsing() throws InvalidSPDXAnalysisException { + public void testCreationInfogetCreatedUsings() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsing())); -// testCreationInfo.getCreatedUsing().clear(); -// testCreationInfo.getCreatedUsing().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsing())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsings()))); +// testCreationInfo.getCreatedUsings().clear(); +// testCreationInfo.getCreatedUsings().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsings()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreatedBy}. */ - public void testCreationInfosetCreatedBy() throws InvalidSPDXAnalysisException { + public void testCreationInfogetCreatedBys() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBy())); -// testCreationInfo.getCreatedBy().clear(); -// testCreationInfo.getCreatedBy().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBy())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBys()))); +// testCreationInfo.getCreatedBys().clear(); +// testCreationInfo.getCreatedBys().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBys()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreated}. + * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreateds}. */ - public void testCreationInfogetCreated() throws InvalidSPDXAnalysisException { + public void testCreationInfogetCreateds() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreated())); -// testCreationInfo.getCreated().clear(); -// testCreationInfo.getCreated().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreated())); + assertTrue(UnitTestHelper.isListsEqual(CREATED_TEST_LIST1, new ArrayList<>(testCreationInfo.getCreateds()))); + testCreationInfo.getCreateds().clear(); + testCreationInfo.getCreateds().addAll(CREATED_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(CREATED_TEST_LIST2, new ArrayList<>(testCreationInfo.getCreateds()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getDataLicense}. + * Test method for {@link org.spdx.library.model.core.CreationInfo#getDataLicenses}. */ - public void testCreationInfogetDataLicense() throws InvalidSPDXAnalysisException { + public void testCreationInfogetDataLicenses() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getDataLicense())); -// testCreationInfo.getDataLicense().clear(); -// testCreationInfo.getDataLicense().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getDataLicense())); + assertTrue(UnitTestHelper.isListsEqual(DATA_LICENSE_TEST_LIST1, new ArrayList<>(testCreationInfo.getDataLicenses()))); + testCreationInfo.getDataLicenses().clear(); + testCreationInfo.getDataLicenses().addAll(DATA_LICENSE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DATA_LICENSE_TEST_LIST2, new ArrayList<>(testCreationInfo.getDataLicenses()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getSpecVersion}. + * Test method for {@link org.spdx.library.model.core.CreationInfo#getSpecVersions}. */ - public void testCreationInfogetSpecVersion() throws InvalidSPDXAnalysisException { + public void testCreationInfogetSpecVersions() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getSpecVersion())); -// testCreationInfo.getSpecVersion().clear(); -// testCreationInfo.getSpecVersion().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getSpecVersion())); + assertTrue(UnitTestHelper.isListsEqual(SPEC_VERSION_TEST_LIST1, new ArrayList<>(testCreationInfo.getSpecVersions()))); + testCreationInfo.getSpecVersions().clear(); + testCreationInfo.getSpecVersions().addAll(SPEC_VERSION_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(SPEC_VERSION_TEST_LIST2, new ArrayList<>(testCreationInfo.getSpecVersions()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.core.CreationInfo#getProfile}. */ - public void testCreationInfogetProfile() throws InvalidSPDXAnalysisException { + public void testCreationInfogetProfiles() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getProfile())); -// testCreationInfo.getProfile().clear(); -// testCreationInfo.getProfile().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getProfile())); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getProfiles()))); +// testCreationInfo.getProfiles().clear(); +// testCreationInfo.getProfiles().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getProfiles()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java b/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java index 6a8f20e80..358eaef6d 100644 --- a/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java +++ b/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.DictionaryEntry.DictionaryEntryBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class DictionaryEntryTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String KEY_TEST_VALUE = "test key"; + static final String VALUE_TEST_VALUE = "test value"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +56,13 @@ protected void tearDown() throws Exception { public static DictionaryEntryBuilder builderForDictionaryEntryTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - DictionaryEntryBuilder retval = new DictionaryEntryBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setkey("A string") - .setvalue("A string") - ***************/ + DictionaryEntryBuilder retval = new DictionaryEntryBuilder(modelStore, objectUri, copyManager) + .setKey(KEY_TEST_VALUE) + .setValue(VALUE_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -92,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.DictionaryEntry#Element(org.spdx.library.model.core.DictionaryEntry.DictionaryEntryBuilder)}. */ public void testDictionaryEntryDictionaryEntryBuilder() throws InvalidSPDXAnalysisException { - DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -108,10 +113,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDictionaryEntry.getKey()); -// testDictionaryEntry.setKey(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDictionaryEntry.getKey()); - fail("Not yet implemented"); + assertEquals(KEY_TEST_VALUE, testDictionaryEntry.getKey()); + testDictionaryEntry.setKey("new key value"); + assertEquals("new key value", testDictionaryEntry.getKey()); } /** @@ -119,13 +123,8 @@ public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { */ public void testDictionaryEntrysetValue() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDictionaryEntry.getValue()); -// testDictionaryEntry.setValue(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDictionaryEntry.getValue()); - fail("Not yet implemented"); + assertEquals(VALUE_TEST_VALUE, testDictionaryEntry.getValue()); + testDictionaryEntry.setValue("new value value"); + assertEquals("new value value", testDictionaryEntry.getValue()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java b/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java index 9a5805a93..3805c2f06 100644 --- a/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.ElementCollection.ElementCollectionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class ElementCollectionTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +54,13 @@ protected void tearDown() throws Exception { public static ElementCollectionBuilder builderForElementCollectionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ElementCollectionBuilder retval = new ElementCollectionBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .getelement.add(Element) - .getrootElement.add(Element) - ***************/ + ElementCollectionBuilder retval = new ElementCollectionBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .addElement(Element) + .addRootElement(Element) + ***************/ + ; return retval; } @@ -92,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.ElementCollection#Element(org.spdx.library.model.core.ElementCollection.ElementCollectionBuilder)}. */ public void testElementCollectionElementCollectionBuilder() throws InvalidSPDXAnalysisException { - ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -106,28 +109,24 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { /** * Test method for {@link org.spdx.library.model.core.ElementCollection#getElement}. */ - public void testElementCollectionsetElement() throws InvalidSPDXAnalysisException { + public void testElementCollectiongetElements() throws InvalidSPDXAnalysisException { ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getElement())); -// testElementCollection.getElement().clear(); -// testElementCollection.getElement().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getElement())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); +// testElementCollection.getElements().clear(); +// testElementCollection.getElements().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.core.ElementCollection#getRootElement}. */ - public void testElementCollectionsetRootElement() throws InvalidSPDXAnalysisException { + public void testElementCollectiongetRootElements() throws InvalidSPDXAnalysisException { ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getRootElement())); -// testElementCollection.getRootElement().clear(); -// testElementCollection.getRootElement().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getRootElement())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); +// testElementCollection.getRootElements().clear(); +// testElementCollection.getRootElements().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ElementTest.java b/src/test/java/org/spdx/library/model/core/ElementTest.java index 18621c60d..5eac1ad8c 100644 --- a/src/test/java/org/spdx/library/model/core/ElementTest.java +++ b/src/test/java/org/spdx/library/model/core/ElementTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Element.ElementBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class ElementTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String DESCRIPTION_TEST_VALUE = "test description"; + static final String SUMMARY_TEST_VALUE = "test summary"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,14 +56,15 @@ protected void tearDown() throws Exception { public static ElementBuilder builderForElementTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ElementBuilder retval = new ElementBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setdescription("A string") - .setsummary("A string") - .getexternalReference.add(ExternalReference) - .getexternalIdentifier.add(ExternalIdentifier) - ***************/ + ElementBuilder retval = new ElementBuilder(modelStore, objectUri, copyManager) + .setDescription(DESCRIPTION_TEST_VALUE) + .setSummary(SUMMARY_TEST_VALUE) + //TODO: Add in test values + /******************** + .addExternalReference(ExternalReference) + .addExternalIdentifier(ExternalIdentifier) + ***************/ + ; return retval; } @@ -94,7 +99,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Element#Element(org.spdx.library.model.core.Element.ElementBuilder)}. */ public void testElementElementBuilder() throws InvalidSPDXAnalysisException { - Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -110,10 +115,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testElementsetDescription() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testElement.getDescription()); -// testElement.setDescription(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testElement.getDescription()); - fail("Not yet implemented"); + assertEquals(DESCRIPTION_TEST_VALUE, testElement.getDescription()); + testElement.setDescription("new description value"); + assertEquals("new description value", testElement.getDescription()); } /** @@ -121,37 +125,32 @@ public void testElementsetDescription() throws InvalidSPDXAnalysisException { */ public void testElementsetSummary() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testElement.getSummary()); -// testElement.setSummary(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testElement.getSummary()); - fail("Not yet implemented"); + assertEquals(SUMMARY_TEST_VALUE, testElement.getSummary()); + testElement.setSummary("new summary value"); + assertEquals("new summary value", testElement.getSummary()); } /** * Test method for {@link org.spdx.library.model.core.Element#getExternalReference}. */ - public void testElementsetExternalReference() throws InvalidSPDXAnalysisException { + public void testElementgetExternalReferences() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalReference())); -// testElement.getExternalReference().clear(); -// testElement.getExternalReference().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalReference())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); +// testElement.getExternalReferences().clear(); +// testElement.getExternalReferences().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.core.Element#getExternalIdentifier}. */ - public void testElementsetExternalIdentifier() throws InvalidSPDXAnalysisException { + public void testElementgetExternalIdentifiers() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifier())); -// testElement.getExternalIdentifier().clear(); -// testElement.getExternalIdentifier().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifier())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifiers()))); +// testElement.getExternalIdentifiers().clear(); +// testElement.getExternalIdentifiers().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifiers()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java b/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java index 5c1682e21..cb0101cdf 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java +++ b/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.ExternalIdentifier.ExternalIdentifierBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,20 @@ public class ExternalIdentifierTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String ISSUING_AUTHORITY_TEST_VALUE = "test issuingAuthority"; + static final String IDENTIFIER_TEST_VALUE = "test identifier"; + static final String COMMENT_TEST_VALUE = "test comment"; + static final String IDENTIFIER_LOCATOR_TEST_VALUE1 = "test 1 identifierLocator"; + static final String IDENTIFIER_LOCATOR_TEST_VALUE2 = "test 2 identifierLocator"; + static final String IDENTIFIER_LOCATOR_TEST_VALUE3 = "test 3 identifierLocator"; + static final List IDENTIFIER_LOCATOR_TEST_LIST1 = Arrays.asList(new String[] { IDENTIFIER_LOCATOR_TEST_VALUE1, IDENTIFIER_LOCATOR_TEST_VALUE2 }); + static final List IDENTIFIER_LOCATOR_TEST_LIST2 = Arrays.asList(new String[] { IDENTIFIER_LOCATOR_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,15 +62,17 @@ protected void tearDown() throws Exception { public static ExternalIdentifierBuilder builderForExternalIdentifierTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ExternalIdentifierBuilder retval = new ExternalIdentifierBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setexternalIdentifierType(ExternalIdentifierType.ENUM) - .setissuingAuthority("A string") - .setidentifier("A string") - .setcomment("A string") - .getidentifierLocator.add("Test string") - ***************/ + ExternalIdentifierBuilder retval = new ExternalIdentifierBuilder(modelStore, objectUri, copyManager) + .setIssuingAuthority(ISSUING_AUTHORITY_TEST_VALUE) + .setIdentifier(IDENTIFIER_TEST_VALUE) + .setComment(COMMENT_TEST_VALUE) + .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE1) + .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE2) + //TODO: Add in test values + /******************** + .setExternalIdentifierType(ExternalIdentifierType.ENUM) + ***************/ + ; return retval; } @@ -95,7 +107,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#Element(org.spdx.library.model.core.ExternalIdentifier.ExternalIdentifierBuilder)}. */ public void testExternalIdentifierExternalIdentifierBuilder() throws InvalidSPDXAnalysisException { - ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -122,10 +134,9 @@ public void testExternalIdentifiersetExternalIdentifierType() throws InvalidSPDX */ public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalIdentifier.getIssuingAuthority()); -// testExternalIdentifier.setIssuingAuthority(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getIssuingAuthority()); - fail("Not yet implemented"); + assertEquals(ISSUING_AUTHORITY_TEST_VALUE, testExternalIdentifier.getIssuingAuthority()); + testExternalIdentifier.setIssuingAuthority("new issuingAuthority value"); + assertEquals("new issuingAuthority value", testExternalIdentifier.getIssuingAuthority()); } /** @@ -133,10 +144,9 @@ public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalys */ public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalIdentifier.getIdentifier()); -// testExternalIdentifier.setIdentifier(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getIdentifier()); - fail("Not yet implemented"); + assertEquals(IDENTIFIER_TEST_VALUE, testExternalIdentifier.getIdentifier()); + testExternalIdentifier.setIdentifier("new identifier value"); + assertEquals("new identifier value", testExternalIdentifier.getIdentifier()); } /** @@ -144,25 +154,20 @@ public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisExce */ public void testExternalIdentifiersetComment() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalIdentifier.getComment()); -// testExternalIdentifier.setComment(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getComment()); - fail("Not yet implemented"); + assertEquals(COMMENT_TEST_VALUE, testExternalIdentifier.getComment()); + testExternalIdentifier.setComment("new comment value"); + assertEquals("new comment value", testExternalIdentifier.getComment()); } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#getIdentifierLocator}. + * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#getIdentifierLocators}. */ - public void testExternalIdentifiergetIdentifierLocator() throws InvalidSPDXAnalysisException { + public void testExternalIdentifiergetIdentifierLocators() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testExternalIdentifier.getIdentifierLocator())); -// testExternalIdentifier.getIdentifierLocator().clear(); -// testExternalIdentifier.getIdentifierLocator().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testExternalIdentifier.getIdentifierLocator())); + assertTrue(UnitTestHelper.isListsEqual(IDENTIFIER_LOCATOR_TEST_LIST1, new ArrayList<>(testExternalIdentifier.getIdentifierLocators()))); + testExternalIdentifier.getIdentifierLocators().clear(); + testExternalIdentifier.getIdentifierLocators().addAll(IDENTIFIER_LOCATOR_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(IDENTIFIER_LOCATOR_TEST_LIST2, new ArrayList<>(testExternalIdentifier.getIdentifierLocators()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ExternalMapTest.java b/src/test/java/org/spdx/library/model/core/ExternalMapTest.java index f234defe1..76a01c982 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalMapTest.java +++ b/src/test/java/org/spdx/library/model/core/ExternalMapTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.ExternalMap.ExternalMapBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,15 @@ public class ExternalMapTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String DEFINING_DOCUMENT_TEST_VALUE = "test definingDocument"; + static final String LOCATION_HINT_TEST_VALUE = "test locationHint"; + static final String EXTERNAL_ID_TEST_VALUE = "test externalId"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,14 +57,15 @@ protected void tearDown() throws Exception { public static ExternalMapBuilder builderForExternalMapTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ExternalMapBuilder retval = new ExternalMapBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setdefiningDocument("A string") - .setlocationHint("A string") - .setexternalId("A string") - .getverifiedUsing.add(IntegrityMethod) - ***************/ + ExternalMapBuilder retval = new ExternalMapBuilder(modelStore, objectUri, copyManager) + .setDefiningDocument(DEFINING_DOCUMENT_TEST_VALUE) + .setLocationHint(LOCATION_HINT_TEST_VALUE) + .setExternalId(EXTERNAL_ID_TEST_VALUE) + //TODO: Add in test values + /******************** + .addVerifiedUsing(IntegrityMethod) + ***************/ + ; return retval; } @@ -94,7 +100,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.ExternalMap#Element(org.spdx.library.model.core.ExternalMap.ExternalMapBuilder)}. */ public void testExternalMapExternalMapBuilder() throws InvalidSPDXAnalysisException { - ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -110,10 +116,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalMap.getDefiningDocument()); -// testExternalMap.setDefiningDocument(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalMap.getDefiningDocument()); - fail("Not yet implemented"); + assertEquals(DEFINING_DOCUMENT_TEST_VALUE, testExternalMap.getDefiningDocument()); + testExternalMap.setDefiningDocument("new definingDocument value"); + assertEquals("new definingDocument value", testExternalMap.getDefiningDocument()); } /** @@ -121,10 +126,9 @@ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisExcep */ public void testExternalMapsetLocationHint() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalMap.getLocationHint()); -// testExternalMap.setLocationHint(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalMap.getLocationHint()); - fail("Not yet implemented"); + assertEquals(LOCATION_HINT_TEST_VALUE, testExternalMap.getLocationHint()); + testExternalMap.setLocationHint("new locationHint value"); + assertEquals("new locationHint value", testExternalMap.getLocationHint()); } /** @@ -132,25 +136,20 @@ public void testExternalMapsetLocationHint() throws InvalidSPDXAnalysisException */ public void testExternalMapsetExternalId() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalMap.getExternalId()); -// testExternalMap.setExternalId(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalMap.getExternalId()); - fail("Not yet implemented"); + assertEquals(EXTERNAL_ID_TEST_VALUE, testExternalMap.getExternalId()); + testExternalMap.setExternalId("new externalId value"); + assertEquals("new externalId value", testExternalMap.getExternalId()); } /** * Test method for {@link org.spdx.library.model.core.ExternalMap#getVerifiedUsing}. */ - public void testExternalMapsetVerifiedUsing() throws InvalidSPDXAnalysisException { + public void testExternalMapgetVerifiedUsings() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testExternalMap.getVerifiedUsing())); -// testExternalMap.getVerifiedUsing().clear(); -// testExternalMap.getVerifiedUsing().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testExternalMap.getVerifiedUsing())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testExternalMap.getVerifiedUsings()))); +// testExternalMap.getVerifiedUsings().clear(); +// testExternalMap.getVerifiedUsings().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testExternalMap.getVerifiedUsings()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java b/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java index 7441feb90..faaf618c7 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java +++ b/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.ExternalReference.ExternalReferenceBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,19 @@ public class ExternalReferenceTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; + static final String COMMENT_TEST_VALUE = "test comment"; + static final String LOCATOR_TEST_VALUE1 = "test 1 locator"; + static final String LOCATOR_TEST_VALUE2 = "test 2 locator"; + static final String LOCATOR_TEST_VALUE3 = "test 3 locator"; + static final List LOCATOR_TEST_LIST1 = Arrays.asList(new String[] { LOCATOR_TEST_VALUE1, LOCATOR_TEST_VALUE2 }); + static final List LOCATOR_TEST_LIST2 = Arrays.asList(new String[] { LOCATOR_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,14 +61,16 @@ protected void tearDown() throws Exception { public static ExternalReferenceBuilder builderForExternalReferenceTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ExternalReferenceBuilder retval = new ExternalReferenceBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setexternalReferenceType(ExternalReferenceType.ENUM) - .setcontentType("A string") - .setcomment("A string") - .getlocator.add("Test string") - ***************/ + ExternalReferenceBuilder retval = new ExternalReferenceBuilder(modelStore, objectUri, copyManager) + .setContentType(CONTENT_TYPE_TEST_VALUE) + .setComment(COMMENT_TEST_VALUE) + .addLocator(LOCATOR_TEST_VALUE1) + .addLocator(LOCATOR_TEST_VALUE2) + //TODO: Add in test values + /******************** + .setExternalReferenceType(ExternalReferenceType.ENUM) + ***************/ + ; return retval; } @@ -94,7 +105,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.ExternalReference#Element(org.spdx.library.model.core.ExternalReference.ExternalReferenceBuilder)}. */ public void testExternalReferenceExternalReferenceBuilder() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -121,10 +132,9 @@ public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAn */ public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalReference.getContentType()); -// testExternalReference.setContentType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalReference.getContentType()); - fail("Not yet implemented"); + assertEquals(CONTENT_TYPE_TEST_VALUE, testExternalReference.getContentType()); + testExternalReference.setContentType("new contentType value"); + assertEquals("new contentType value", testExternalReference.getContentType()); } /** @@ -132,25 +142,20 @@ public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisExce */ public void testExternalReferencesetComment() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalReference.getComment()); -// testExternalReference.setComment(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalReference.getComment()); - fail("Not yet implemented"); + assertEquals(COMMENT_TEST_VALUE, testExternalReference.getComment()); + testExternalReference.setComment("new comment value"); + assertEquals("new comment value", testExternalReference.getComment()); } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#getLocator}. + * Test method for {@link org.spdx.library.model.core.ExternalReference#getLocators}. */ - public void testExternalReferencegetLocator() throws InvalidSPDXAnalysisException { + public void testExternalReferencegetLocators() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testExternalReference.getLocator())); -// testExternalReference.getLocator().clear(); -// testExternalReference.getLocator().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testExternalReference.getLocator())); + assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST1, new ArrayList<>(testExternalReference.getLocators()))); + testExternalReference.getLocators().clear(); + testExternalReference.getLocators().addAll(LOCATOR_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST2, new ArrayList<>(testExternalReference.getLocators()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/HashTest.java b/src/test/java/org/spdx/library/model/core/HashTest.java index 307aec391..856e65bb3 100644 --- a/src/test/java/org/spdx/library/model/core/HashTest.java +++ b/src/test/java/org/spdx/library/model/core/HashTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Hash.HashBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class HashTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String HASH_VALUE_TEST_VALUE = "test hashValue"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +55,13 @@ protected void tearDown() throws Exception { public static HashBuilder builderForHashTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - HashBuilder retval = new HashBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setalgorithm(HashAlgorithm.ENUM) - .sethashValue("A string") - ***************/ + HashBuilder retval = new HashBuilder(modelStore, objectUri, copyManager) + .setHashValue(HASH_VALUE_TEST_VALUE) + //TODO: Add in test values + /******************** + .setAlgorithm(HashAlgorithm.ENUM) + ***************/ + ; return retval; } @@ -92,7 +96,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Hash#Element(org.spdx.library.model.core.Hash.HashBuilder)}. */ public void testHashHashBuilder() throws InvalidSPDXAnalysisException { - Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -119,13 +123,8 @@ public void testHashsetAlgorithm() throws InvalidSPDXAnalysisException { */ public void testHashsetHashValue() throws InvalidSPDXAnalysisException { Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testHash.getHashValue()); -// testHash.setHashValue(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testHash.getHashValue()); - fail("Not yet implemented"); + assertEquals(HASH_VALUE_TEST_VALUE, testHash.getHashValue()); + testHash.setHashValue("new hashValue value"); + assertEquals("new hashValue value", testHash.getHashValue()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java b/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java index d1da4df55..34382a92f 100644 --- a/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java +++ b/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.IntegrityMethod.IntegrityMethodBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class IntegrityMethodTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String COMMENT_TEST_VALUE = "test comment"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +55,12 @@ protected void tearDown() throws Exception { public static IntegrityMethodBuilder builderForIntegrityMethodTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - IntegrityMethodBuilder retval = new IntegrityMethodBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setcomment("A string") - ***************/ + IntegrityMethodBuilder retval = new IntegrityMethodBuilder(modelStore, objectUri, copyManager) + .setComment(COMMENT_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.IntegrityMethod#Element(org.spdx.library.model.core.IntegrityMethod.IntegrityMethodBuilder)}. */ public void testIntegrityMethodIntegrityMethodBuilder() throws InvalidSPDXAnalysisException { - IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -107,13 +111,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testIntegrityMethodsetComment() throws InvalidSPDXAnalysisException { IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testIntegrityMethod.getComment()); -// testIntegrityMethod.setComment(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testIntegrityMethod.getComment()); - fail("Not yet implemented"); + assertEquals(COMMENT_TEST_VALUE, testIntegrityMethod.getComment()); + testIntegrityMethod.setComment("new comment value"); + assertEquals("new comment value", testIntegrityMethod.getComment()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java b/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java index b8ef37a11..4ffad298b 100644 --- a/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class LifecycleScopedRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +54,12 @@ protected void tearDown() throws Exception { public static LifecycleScopedRelationshipBuilder builderForLifecycleScopedRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - LifecycleScopedRelationshipBuilder retval = new LifecycleScopedRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setscope(LifecycleScopeType.ENUM) - ***************/ + LifecycleScopedRelationshipBuilder retval = new LifecycleScopedRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .setScope(LifecycleScopeType.ENUM) + ***************/ + ; return retval; } @@ -91,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#Element(org.spdx.library.model.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder)}. */ public void testLifecycleScopedRelationshipLifecycleScopedRelationshipBuilder() throws InvalidSPDXAnalysisException { - LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -112,8 +115,4 @@ public void testLifecycleScopedRelationshipsetScope() throws InvalidSPDXAnalysis // assertEquals(NEW_TEST_VALUE, testLifecycleScopedRelationship.getScope()); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java b/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java index c86fab22f..4e6aa31e8 100644 --- a/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java +++ b/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.NamespaceMap.NamespaceMapBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class NamespaceMapTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String PREFIX_TEST_VALUE = "test prefix"; + static final String NAMESPACE_TEST_VALUE = "test namespace"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +56,13 @@ protected void tearDown() throws Exception { public static NamespaceMapBuilder builderForNamespaceMapTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - NamespaceMapBuilder retval = new NamespaceMapBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setprefix("A string") - .setnamespace("A string") - ***************/ + NamespaceMapBuilder retval = new NamespaceMapBuilder(modelStore, objectUri, copyManager) + .setPrefix(PREFIX_TEST_VALUE) + .setNamespace(NAMESPACE_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -92,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.NamespaceMap#Element(org.spdx.library.model.core.NamespaceMap.NamespaceMapBuilder)}. */ public void testNamespaceMapNamespaceMapBuilder() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -108,10 +113,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testNamespaceMapsetPrefix() throws InvalidSPDXAnalysisException { NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testNamespaceMap.getPrefix()); -// testNamespaceMap.setPrefix(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testNamespaceMap.getPrefix()); - fail("Not yet implemented"); + assertEquals(PREFIX_TEST_VALUE, testNamespaceMap.getPrefix()); + testNamespaceMap.setPrefix("new prefix value"); + assertEquals("new prefix value", testNamespaceMap.getPrefix()); } /** @@ -119,13 +123,8 @@ public void testNamespaceMapsetPrefix() throws InvalidSPDXAnalysisException { */ public void testNamespaceMapsetNamespace() throws InvalidSPDXAnalysisException { NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testNamespaceMap.getNamespace()); -// testNamespaceMap.setNamespace(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testNamespaceMap.getNamespace()); - fail("Not yet implemented"); + assertEquals(NAMESPACE_TEST_VALUE, testNamespaceMap.getNamespace()); + testNamespaceMap.setNamespace("new namespace value"); + assertEquals("new namespace value", testNamespaceMap.getNamespace()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/OrganizationTest.java b/src/test/java/org/spdx/library/model/core/OrganizationTest.java index 6b89fcfa1..98c3610a2 100644 --- a/src/test/java/org/spdx/library/model/core/OrganizationTest.java +++ b/src/test/java/org/spdx/library/model/core/OrganizationTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Organization.OrganizationBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class OrganizationTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static OrganizationBuilder builderForOrganizationTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - OrganizationBuilder retval = new OrganizationBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + OrganizationBuilder retval = new OrganizationBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Organization#Element(org.spdx.library.model.core.Organization.OrganizationBuilder)}. */ public void testOrganizationOrganizationBuilder() throws InvalidSPDXAnalysisException { - Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Organization.equivalent(testOrganization)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/PayloadTest.java b/src/test/java/org/spdx/library/model/core/PayloadTest.java index ca8b90d85..7e8e3a289 100644 --- a/src/test/java/org/spdx/library/model/core/PayloadTest.java +++ b/src/test/java/org/spdx/library/model/core/PayloadTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Payload.PayloadBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class PayloadTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,13 +54,14 @@ protected void tearDown() throws Exception { public static PayloadBuilder builderForPayloadTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - PayloadBuilder retval = new PayloadBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setcreationInfo(new CreationInfo()) - .getnamespaces.add(NamespaceMap) - .getimports.add(ExternalMap) - ***************/ + PayloadBuilder retval = new PayloadBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .setCreationInfo(new CreationInfo()) + .addNamespaces(NamespaceMap) + .addImports(ExternalMap) + ***************/ + ; return retval; } @@ -93,7 +96,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Payload#Element(org.spdx.library.model.core.Payload.PayloadBuilder)}. */ public void testPayloadPayloadBuilder() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -118,28 +121,24 @@ public void testPayloadsetCreationInfo() throws InvalidSPDXAnalysisException { /** * Test method for {@link org.spdx.library.model.core.Payload#getNamespaces}. */ - public void testPayloadsetNamespaces() throws InvalidSPDXAnalysisException { + public void testPayloadgetNamespacess() throws InvalidSPDXAnalysisException { Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getNamespaces())); -// testPayload.getNamespaces().clear(); -// testPayload.getNamespaces().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getNamespaces())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getNamespacess()))); +// testPayload.getNamespacess().clear(); +// testPayload.getNamespacess().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getNamespacess()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.core.Payload#getImports}. */ - public void testPayloadsetImports() throws InvalidSPDXAnalysisException { + public void testPayloadgetImportss() throws InvalidSPDXAnalysisException { Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getImports())); -// testPayload.getImports().clear(); -// testPayload.getImports().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getImports())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getImportss()))); +// testPayload.getImportss().clear(); +// testPayload.getImportss().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getImportss()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/PersonTest.java b/src/test/java/org/spdx/library/model/core/PersonTest.java index 3df485d34..3d2517ea6 100644 --- a/src/test/java/org/spdx/library/model/core/PersonTest.java +++ b/src/test/java/org/spdx/library/model/core/PersonTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Person.PersonBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class PersonTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static PersonBuilder builderForPersonTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - PersonBuilder retval = new PersonBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + PersonBuilder retval = new PersonBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Person#Element(org.spdx.library.model.core.Person.PersonBuilder)}. */ public void testPersonPersonBuilder() throws InvalidSPDXAnalysisException { - Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Person.equivalent(testPerson)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java b/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java index 584660640..1b3cf2831 100644 --- a/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java +++ b/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.PositiveIntegerRange.PositiveIntegerRangeBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class PositiveIntegerRangeTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final Integer END_TEST_VALUE = 55; + static final Integer BEGIN_TEST_VALUE = 55; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +56,13 @@ protected void tearDown() throws Exception { public static PositiveIntegerRangeBuilder builderForPositiveIntegerRangeTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - PositiveIntegerRangeBuilder retval = new PositiveIntegerRangeBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setend(57) - .setbegin(57) - ***************/ + PositiveIntegerRangeBuilder retval = new PositiveIntegerRangeBuilder(modelStore, objectUri, copyManager) + .setEnd(END_TEST_VALUE) + .setBegin(BEGIN_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -92,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#Element(org.spdx.library.model.core.PositiveIntegerRange.PositiveIntegerRangeBuilder)}. */ public void testPositiveIntegerRangePositiveIntegerRangeBuilder() throws InvalidSPDXAnalysisException { - PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -108,10 +113,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testPositiveIntegerRangesetEnd() throws InvalidSPDXAnalysisException { PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testPositiveIntegerRange.getEnd()); -// testPositiveIntegerRange.setEnd(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testPositiveIntegerRange.getEnd()); - fail("Not yet implemented"); + assertEquals(END_TEST_VALUE, testPositiveIntegerRange.getEnd()); + testPositiveIntegerRange.setEnd(new Integer(653)); + assertEquals(new Integer(653), testPositiveIntegerRange.getEnd()); } /** @@ -119,13 +123,8 @@ public void testPositiveIntegerRangesetEnd() throws InvalidSPDXAnalysisException */ public void testPositiveIntegerRangesetBegin() throws InvalidSPDXAnalysisException { PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testPositiveIntegerRange.getBegin()); -// testPositiveIntegerRange.setBegin(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testPositiveIntegerRange.getBegin()); - fail("Not yet implemented"); + assertEquals(BEGIN_TEST_VALUE, testPositiveIntegerRange.getBegin()); + testPositiveIntegerRange.setBegin(new Integer(653)); + assertEquals(new Integer(653), testPositiveIntegerRange.getBegin()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/RelationshipTest.java b/src/test/java/org/spdx/library/model/core/RelationshipTest.java index 02b44a931..64bde293c 100644 --- a/src/test/java/org/spdx/library/model/core/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/core/RelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Relationship.RelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class RelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String START_TIME_TEST_VALUE = "test startTime"; + static final String END_TIME_TEST_VALUE = "test endTime"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,16 +56,17 @@ protected void tearDown() throws Exception { public static RelationshipBuilder builderForRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - RelationshipBuilder retval = new RelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setfrom(Element testElement) - .setrelationshipType(RelationshipType.ENUM) - .setcompleteness(RelationshipCompleteness.ENUM) - .setstartTime("A string") - .setendTime("A string") - .getto.add(Element) - ***************/ + RelationshipBuilder retval = new RelationshipBuilder(modelStore, objectUri, copyManager) + .setStartTime(START_TIME_TEST_VALUE) + .setEndTime(END_TIME_TEST_VALUE) + //TODO: Add in test values + /******************** + .setFrom(Element testElement) + .setRelationshipType(RelationshipType.ENUM) + .setCompleteness(RelationshipCompleteness.ENUM) + .addTo(Element) + ***************/ + ; return retval; } @@ -96,7 +101,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Relationship#Element(org.spdx.library.model.core.Relationship.RelationshipBuilder)}. */ public void testRelationshipRelationshipBuilder() throws InvalidSPDXAnalysisException { - Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -145,10 +150,9 @@ public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisExceptio */ public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testRelationship.getStartTime()); -// testRelationship.setStartTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testRelationship.getStartTime()); - fail("Not yet implemented"); + assertEquals(START_TIME_TEST_VALUE, testRelationship.getStartTime()); + testRelationship.setStartTime("new startTime value"); + assertEquals("new startTime value", testRelationship.getStartTime()); } /** @@ -156,25 +160,20 @@ public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { */ public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testRelationship.getEndTime()); -// testRelationship.setEndTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testRelationship.getEndTime()); - fail("Not yet implemented"); + assertEquals(END_TIME_TEST_VALUE, testRelationship.getEndTime()); + testRelationship.setEndTime("new endTime value"); + assertEquals("new endTime value", testRelationship.getEndTime()); } /** * Test method for {@link org.spdx.library.model.core.Relationship#getTo}. */ - public void testRelationshipsetTo() throws InvalidSPDXAnalysisException { + public void testRelationshipgetTos() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testRelationship.getTo())); -// testRelationship.getTo().clear(); -// testRelationship.getTo().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testRelationship.getTo())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testRelationship.getTos()))); +// testRelationship.getTos().clear(); +// testRelationship.getTos().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testRelationship.getTos()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java b/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java index 332b4cd59..900a39411 100644 --- a/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java +++ b/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.SoftwareAgent.SoftwareAgentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class SoftwareAgentTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static SoftwareAgentBuilder builderForSoftwareAgentTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SoftwareAgentBuilder retval = new SoftwareAgentBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + SoftwareAgentBuilder retval = new SoftwareAgentBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.SoftwareAgent#Element(org.spdx.library.model.core.SoftwareAgent.SoftwareAgentBuilder)}. */ public void testSoftwareAgentSoftwareAgentBuilder() throws InvalidSPDXAnalysisException { - SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2SoftwareAgent.equivalent(testSoftwareAgent)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java index 538d02a7e..16c771630 100644 --- a/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.SpdxDocument.SpdxDocumentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class SpdxDocumentTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static SpdxDocumentBuilder builderForSpdxDocumentTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SpdxDocumentBuilder retval = new SpdxDocumentBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + SpdxDocumentBuilder retval = new SpdxDocumentBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.SpdxDocument#Element(org.spdx.library.model.core.SpdxDocument.SpdxDocumentBuilder)}. */ public void testSpdxDocumentSpdxDocumentBuilder() throws InvalidSPDXAnalysisException { - SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2SpdxDocument.equivalent(testSpdxDocument)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ToolTest.java b/src/test/java/org/spdx/library/model/core/ToolTest.java index 121b0dd31..1b69b51e8 100644 --- a/src/test/java/org/spdx/library/model/core/ToolTest.java +++ b/src/test/java/org/spdx/library/model/core/ToolTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Tool.ToolBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class ToolTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static ToolBuilder builderForToolTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ToolBuilder retval = new ToolBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + ToolBuilder retval = new ToolBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.core.Tool#Element(org.spdx.library.model.core.Tool.ToolBuilder)}. */ public void testToolToolBuilder() throws InvalidSPDXAnalysisException { - Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Tool.equivalent(testTool)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/dataset/DatasetTest.java b/src/test/java/org/spdx/library/model/dataset/DatasetTest.java index b3fd4e453..6ccb439c5 100644 --- a/src/test/java/org/spdx/library/model/dataset/DatasetTest.java +++ b/src/test/java/org/spdx/library/model/dataset/DatasetTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.dataset.Dataset.DatasetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,32 @@ public class DatasetTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final Integer DATASET_SIZE_TEST_VALUE = 55; + static final String INTENDED_USE_TEST_VALUE = "test intendedUse"; + static final String DATASET_NOISE_TEST_VALUE = "test datasetNoise"; + static final String DATA_COLLECTION_PROCESS_TEST_VALUE = "test dataCollectionProcess"; + static final String DATASET_UPDATE_MECHANISM_TEST_VALUE = "test datasetUpdateMechanism"; + static final String ANONYMIZATION_METHOD_USED_TEST_VALUE1 = "test 1 anonymizationMethodUsed"; + static final String ANONYMIZATION_METHOD_USED_TEST_VALUE2 = "test 2 anonymizationMethodUsed"; + static final String ANONYMIZATION_METHOD_USED_TEST_VALUE3 = "test 3 anonymizationMethodUsed"; + static final List ANONYMIZATION_METHOD_USED_TEST_LIST1 = Arrays.asList(new String[] { ANONYMIZATION_METHOD_USED_TEST_VALUE1, ANONYMIZATION_METHOD_USED_TEST_VALUE2 }); + static final List ANONYMIZATION_METHOD_USED_TEST_LIST2 = Arrays.asList(new String[] { ANONYMIZATION_METHOD_USED_TEST_VALUE3 }); + static final String DATA_PREPROCESSING_TEST_VALUE1 = "test 1 dataPreprocessing"; + static final String DATA_PREPROCESSING_TEST_VALUE2 = "test 2 dataPreprocessing"; + static final String DATA_PREPROCESSING_TEST_VALUE3 = "test 3 dataPreprocessing"; + static final List DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { DATA_PREPROCESSING_TEST_VALUE1, DATA_PREPROCESSING_TEST_VALUE2 }); + static final List DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { DATA_PREPROCESSING_TEST_VALUE3 }); + static final String KNOWN_BIAS_TEST_VALUE1 = "test 1 knownBias"; + static final String KNOWN_BIAS_TEST_VALUE2 = "test 2 knownBias"; + static final String KNOWN_BIAS_TEST_VALUE3 = "test 3 knownBias"; + static final List KNOWN_BIAS_TEST_LIST1 = Arrays.asList(new String[] { KNOWN_BIAS_TEST_VALUE1, KNOWN_BIAS_TEST_VALUE2 }); + static final List KNOWN_BIAS_TEST_LIST2 = Arrays.asList(new String[] { KNOWN_BIAS_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,23 +74,27 @@ protected void tearDown() throws Exception { public static DatasetBuilder builderForDatasetTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - DatasetBuilder retval = new DatasetBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setsensitivePersonalInformation(new PresenceType()) - .setconfidentialityLevel(ConfidentialityLevelType.ENUM) - .setdatasetAvailability(DatasetAvailabilityType.ENUM) - .setdatasetSize(57) - .setintendedUse("A string") - .setdatasetNoise("A string") - .setdataCollectionProcess("A string") - .setdatasetUpdateMechanism("A string") - .getsensor.add(DictionaryEntry) - .getanonymizationMethodUsed.add("Test string") - .getdataPreprocessing.add("Test string") - .getknownBias.add("Test string") - .getdatasetType.add(DatasetType.ENUM) - ***************/ + DatasetBuilder retval = new DatasetBuilder(modelStore, objectUri, copyManager) + .setDatasetSize(DATASET_SIZE_TEST_VALUE) + .setIntendedUse(INTENDED_USE_TEST_VALUE) + .setDatasetNoise(DATASET_NOISE_TEST_VALUE) + .setDataCollectionProcess(DATA_COLLECTION_PROCESS_TEST_VALUE) + .setDatasetUpdateMechanism(DATASET_UPDATE_MECHANISM_TEST_VALUE) + .addAnonymizationMethodUsed(ANONYMIZATION_METHOD_USED_TEST_VALUE1) + .addAnonymizationMethodUsed(ANONYMIZATION_METHOD_USED_TEST_VALUE2) + .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE1) + .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE2) + .addKnownBias(KNOWN_BIAS_TEST_VALUE1) + .addKnownBias(KNOWN_BIAS_TEST_VALUE2) + //TODO: Add in test values + /******************** + .setSensitivePersonalInformation(new PresenceType()) + .setConfidentialityLevel(ConfidentialityLevelType.ENUM) + .setDatasetAvailability(DatasetAvailabilityType.ENUM) + .addSensor(DictionaryEntry) + .addDatasetType(DatasetType.ENUM) + ***************/ + ; return retval; } @@ -103,7 +129,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.dataset.Dataset#Element(org.spdx.library.model.dataset.Dataset.DatasetBuilder)}. */ public void testDatasetDatasetBuilder() throws InvalidSPDXAnalysisException { - Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -152,10 +178,9 @@ public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisExcept */ public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getDatasetSize()); -// testDataset.setDatasetSize(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetSize()); - fail("Not yet implemented"); + assertEquals(DATASET_SIZE_TEST_VALUE, testDataset.getDatasetSize()); + testDataset.setDatasetSize(new Integer(653)); + assertEquals(new Integer(653), testDataset.getDatasetSize()); } /** @@ -163,10 +188,9 @@ public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { */ public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getIntendedUse()); -// testDataset.setIntendedUse(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getIntendedUse()); - fail("Not yet implemented"); + assertEquals(INTENDED_USE_TEST_VALUE, testDataset.getIntendedUse()); + testDataset.setIntendedUse("new intendedUse value"); + assertEquals("new intendedUse value", testDataset.getIntendedUse()); } /** @@ -174,10 +198,9 @@ public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { */ public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getDatasetNoise()); -// testDataset.setDatasetNoise(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetNoise()); - fail("Not yet implemented"); + assertEquals(DATASET_NOISE_TEST_VALUE, testDataset.getDatasetNoise()); + testDataset.setDatasetNoise("new datasetNoise value"); + assertEquals("new datasetNoise value", testDataset.getDatasetNoise()); } /** @@ -185,10 +208,9 @@ public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { */ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getDataCollectionProcess()); -// testDataset.setDataCollectionProcess(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getDataCollectionProcess()); - fail("Not yet implemented"); + assertEquals(DATA_COLLECTION_PROCESS_TEST_VALUE, testDataset.getDataCollectionProcess()); + testDataset.setDataCollectionProcess("new dataCollectionProcess value"); + assertEquals("new dataCollectionProcess value", testDataset.getDataCollectionProcess()); } /** @@ -196,73 +218,68 @@ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisExce */ public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getDatasetUpdateMechanism()); -// testDataset.setDatasetUpdateMechanism(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetUpdateMechanism()); - fail("Not yet implemented"); + assertEquals(DATASET_UPDATE_MECHANISM_TEST_VALUE, testDataset.getDatasetUpdateMechanism()); + testDataset.setDatasetUpdateMechanism("new datasetUpdateMechanism value"); + assertEquals("new datasetUpdateMechanism value", testDataset.getDatasetUpdateMechanism()); } /** * Test method for {@link org.spdx.library.model.dataset.Dataset#getSensor}. */ - public void testDatasetsetSensor() throws InvalidSPDXAnalysisException { + public void testDatasetgetSensors() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testDataset.getSensor())); -// testDataset.getSensor().clear(); -// testDataset.getSensor().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testDataset.getSensor())); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testDataset.getSensors()))); +// testDataset.getSensors().clear(); +// testDataset.getSensors().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testDataset.getSensors()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getAnonymizationMethodUsed}. + * Test method for {@link org.spdx.library.model.dataset.Dataset#getAnonymizationMethodUseds}. */ - public void testDatasetgetAnonymizationMethodUsed() throws InvalidSPDXAnalysisException { + public void testDatasetgetAnonymizationMethodUseds() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getAnonymizationMethodUsed())); -// testDataset.getAnonymizationMethodUsed().clear(); -// testDataset.getAnonymizationMethodUsed().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getAnonymizationMethodUsed())); + assertTrue(UnitTestHelper.isListsEqual(ANONYMIZATION_METHOD_USED_TEST_LIST1, new ArrayList<>(testDataset.getAnonymizationMethodUseds()))); + testDataset.getAnonymizationMethodUseds().clear(); + testDataset.getAnonymizationMethodUseds().addAll(ANONYMIZATION_METHOD_USED_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(ANONYMIZATION_METHOD_USED_TEST_LIST2, new ArrayList<>(testDataset.getAnonymizationMethodUseds()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getDataPreprocessing}. + * Test method for {@link org.spdx.library.model.dataset.Dataset#getDataPreprocessings}. */ - public void testDatasetgetDataPreprocessing() throws InvalidSPDXAnalysisException { + public void testDatasetgetDataPreprocessings() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getDataPreprocessing())); -// testDataset.getDataPreprocessing().clear(); -// testDataset.getDataPreprocessing().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getDataPreprocessing())); + assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testDataset.getDataPreprocessings()))); + testDataset.getDataPreprocessings().clear(); + testDataset.getDataPreprocessings().addAll(DATA_PREPROCESSING_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testDataset.getDataPreprocessings()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getKnownBias}. + * Test method for {@link org.spdx.library.model.dataset.Dataset#getKnownBiass}. */ - public void testDatasetgetKnownBias() throws InvalidSPDXAnalysisException { + public void testDatasetgetKnownBiass() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getKnownBias())); -// testDataset.getKnownBias().clear(); -// testDataset.getKnownBias().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getKnownBias())); + assertTrue(UnitTestHelper.isListsEqual(KNOWN_BIAS_TEST_LIST1, new ArrayList<>(testDataset.getKnownBiass()))); + testDataset.getKnownBiass().clear(); + testDataset.getKnownBiass().addAll(KNOWN_BIAS_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(KNOWN_BIAS_TEST_LIST2, new ArrayList<>(testDataset.getKnownBiass()))); fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.dataset.Dataset#getDatasetType}. */ - public void testDatasetgetDatasetType() throws InvalidSPDXAnalysisException { + public void testDatasetgetDatasetTypes() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getDatasetType())); -// testDataset.getDatasetType().clear(); -// testDataset.getDatasetType().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getDatasetType())); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getDatasetTypes()))); +// testDataset.getDatasetTypes().clear(); +// testDataset.getDatasetTypes().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getDatasetTypes()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java index 733208b10..1840365a7 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class ConjunctiveLicenseSetTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static ConjunctiveLicenseSetBuilder builderForConjunctiveLicenseSetTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ConjunctiveLicenseSetBuilder retval = new ConjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + ConjunctiveLicenseSetBuilder retval = new ConjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#Element(org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder)}. */ public void testConjunctiveLicenseSetConjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { - ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ConjunctiveLicenseSet.equivalent(testConjunctiveLicenseSet)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java index f0bae2b8b..9d6f39910 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class DisjunctiveLicenseSetTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static DisjunctiveLicenseSetBuilder builderForDisjunctiveLicenseSetTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - DisjunctiveLicenseSetBuilder retval = new DisjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + DisjunctiveLicenseSetBuilder retval = new DisjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#Element(org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder)}. */ public void testDisjunctiveLicenseSetDisjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { - DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2DisjunctiveLicenseSet.equivalent(testDisjunctiveLicenseSet)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java b/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java index cb78dc3c6..27b72726b 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java +++ b/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.expandedlicense.ExtendableLicense.ExtendableLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class ExtendableLicenseTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static ExtendableLicenseBuilder builderForExtendableLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ExtendableLicenseBuilder retval = new ExtendableLicenseBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + ExtendableLicenseBuilder retval = new ExtendableLicenseBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#Element(org.spdx.library.model.expandedlicense.ExtendableLicense.ExtendableLicenseBuilder)}. */ public void testExtendableLicenseExtendableLicenseBuilder() throws InvalidSPDXAnalysisException { - ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ExtendableLicense.equivalent(testExtendableLicense)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java b/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java index d732814f3..f60fd6bad 100644 --- a/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java +++ b/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class AnyLicenseInfoTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static AnyLicenseInfoBuilder builderForAnyLicenseInfoTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AnyLicenseInfoBuilder retval = new AnyLicenseInfoBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + AnyLicenseInfoBuilder retval = new AnyLicenseInfoBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#Element(org.spdx.library.model.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder)}. */ public void testAnyLicenseInfoAnyLicenseInfoBuilder() throws InvalidSPDXAnalysisException { - AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2AnyLicenseInfo.equivalent(testAnyLicenseInfo)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java b/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java index 3cf93c6e4..8784bd1c3 100644 --- a/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class CustomLicenseAdditionTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static CustomLicenseAdditionBuilder builderForCustomLicenseAdditionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - CustomLicenseAdditionBuilder retval = new CustomLicenseAdditionBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + CustomLicenseAdditionBuilder retval = new CustomLicenseAdditionBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#Element(org.spdx.library.model.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder)}. */ public void testCustomLicenseAdditionCustomLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { - CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2CustomLicenseAddition.equivalent(testCustomLicenseAddition)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java b/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java index 74de52977..1bbff7089 100644 --- a/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java +++ b/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.CustomLicense.CustomLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class CustomLicenseTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static CustomLicenseBuilder builderForCustomLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - CustomLicenseBuilder retval = new CustomLicenseBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + CustomLicenseBuilder retval = new CustomLicenseBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.CustomLicense#Element(org.spdx.library.model.licensing.CustomLicense.CustomLicenseBuilder)}. */ public void testCustomLicenseCustomLicenseBuilder() throws InvalidSPDXAnalysisException { - CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2CustomLicense.equivalent(testCustomLicense)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java index 5f9ec9089..b4874bed1 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.LicenseAddition.LicenseAdditionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class LicenseAdditionTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String STANDARD_ADDITION_TEMPLATE_TEST_VALUE = "test standardAdditionTemplate"; + static final String ADDITION_TEXT_TEST_VALUE = "test additionText"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,13 +56,14 @@ protected void tearDown() throws Exception { public static LicenseAdditionBuilder builderForLicenseAdditionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - LicenseAdditionBuilder retval = new LicenseAdditionBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setisDeprecatedAdditionId(true) - .setstandardAdditionTemplate("A string") - .setadditionText("A string") - ***************/ + LicenseAdditionBuilder retval = new LicenseAdditionBuilder(modelStore, objectUri, copyManager) + .setIsDeprecatedAdditionId(true) + .setStandardAdditionTemplate(STANDARD_ADDITION_TEMPLATE_TEST_VALUE) + .setAdditionText(ADDITION_TEXT_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -93,7 +98,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#Element(org.spdx.library.model.licensing.LicenseAddition.LicenseAdditionBuilder)}. */ public void testLicenseAdditionLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { - LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -109,10 +114,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicenseAddition.getIsDeprecatedAdditionId()); -// testLicenseAddition.setIsDeprecatedAdditionId(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicenseAddition.getIsDeprecatedAdditionId()); - fail("Not yet implemented"); + assertEquals(new Boolean(true), testLicenseAddition.getIsDeprecatedAdditionId()); + testLicenseAddition.setIsDeprecatedAdditionId(false); + assertEquals(new Boolean(false), testLicenseAddition.getIsDeprecatedAdditionId()); } /** @@ -120,10 +124,9 @@ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAna */ public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicenseAddition.getStandardAdditionTemplate()); -// testLicenseAddition.setStandardAdditionTemplate(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicenseAddition.getStandardAdditionTemplate()); - fail("Not yet implemented"); + assertEquals(STANDARD_ADDITION_TEMPLATE_TEST_VALUE, testLicenseAddition.getStandardAdditionTemplate()); + testLicenseAddition.setStandardAdditionTemplate("new standardAdditionTemplate value"); + assertEquals("new standardAdditionTemplate value", testLicenseAddition.getStandardAdditionTemplate()); } /** @@ -131,13 +134,8 @@ public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXA */ public void testLicenseAdditionsetAdditionText() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicenseAddition.getAdditionText()); -// testLicenseAddition.setAdditionText(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicenseAddition.getAdditionText()); - fail("Not yet implemented"); + assertEquals(ADDITION_TEXT_TEST_VALUE, testLicenseAddition.getAdditionText()); + testLicenseAddition.setAdditionText("new additionText value"); + assertEquals("new additionText value", testLicenseAddition.getAdditionText()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java index d90c3e7d6..4d5dc6213 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.LicenseExpression.LicenseExpressionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class LicenseExpressionTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String LICENSE_EXPRESSION_TEST_VALUE = "test licenseExpression"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +55,12 @@ protected void tearDown() throws Exception { public static LicenseExpressionBuilder builderForLicenseExpressionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - LicenseExpressionBuilder retval = new LicenseExpressionBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setlicenseExpression("A string") - ***************/ + LicenseExpressionBuilder retval = new LicenseExpressionBuilder(modelStore, objectUri, copyManager) + .setLicenseExpression(LICENSE_EXPRESSION_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#Element(org.spdx.library.model.licensing.LicenseExpression.LicenseExpressionBuilder)}. */ public void testLicenseExpressionLicenseExpressionBuilder() throws InvalidSPDXAnalysisException { - LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -107,13 +111,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testLicenseExpressionsetLicenseExpression() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicenseExpression.getLicenseExpression()); -// testLicenseExpression.setLicenseExpression(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicenseExpression.getLicenseExpression()); - fail("Not yet implemented"); + assertEquals(LICENSE_EXPRESSION_TEST_VALUE, testLicenseExpression.getLicenseExpression()); + testLicenseExpression.setLicenseExpression("new licenseExpression value"); + assertEquals("new licenseExpression value", testLicenseExpression.getLicenseExpression()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseTest.java index 806285d4a..9ff738145 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseTest.java +++ b/src/test/java/org/spdx/library/model/licensing/LicenseTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.License.LicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,15 @@ public class LicenseTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String STANDARD_LICENSE_TEMPLATE_TEST_VALUE = "test standardLicenseTemplate"; + static final String STANDARD_LICENSE_HEADER_TEST_VALUE = "test standardLicenseHeader"; + static final String LICENSE_TEXT_TEST_VALUE = "test licenseText"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,16 +57,17 @@ protected void tearDown() throws Exception { public static LicenseBuilder builderForLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - LicenseBuilder retval = new LicenseBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setisFsfLibre(true) - .setisDeprecatedLicenseId(true) - .setisOsiApproved(true) - .setstandardLicenseTemplate("A string") - .setstandardLicenseHeader("A string") - .setlicenseText("A string") - ***************/ + LicenseBuilder retval = new LicenseBuilder(modelStore, objectUri, copyManager) + .setIsFsfLibre(true) + .setIsDeprecatedLicenseId(true) + .setIsOsiApproved(true) + .setStandardLicenseTemplate(STANDARD_LICENSE_TEMPLATE_TEST_VALUE) + .setStandardLicenseHeader(STANDARD_LICENSE_HEADER_TEST_VALUE) + .setLicenseText(LICENSE_TEXT_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -96,7 +102,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.License#Element(org.spdx.library.model.licensing.License.LicenseBuilder)}. */ public void testLicenseLicenseBuilder() throws InvalidSPDXAnalysisException { - License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -112,10 +118,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicense.getIsFsfLibre()); -// testLicense.setIsFsfLibre(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicense.getIsFsfLibre()); - fail("Not yet implemented"); + assertEquals(new Boolean(true), testLicense.getIsFsfLibre()); + testLicense.setIsFsfLibre(false); + assertEquals(new Boolean(false), testLicense.getIsFsfLibre()); } /** @@ -123,10 +128,9 @@ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { */ public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicense.getIsDeprecatedLicenseId()); -// testLicense.setIsDeprecatedLicenseId(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicense.getIsDeprecatedLicenseId()); - fail("Not yet implemented"); + assertEquals(new Boolean(true), testLicense.getIsDeprecatedLicenseId()); + testLicense.setIsDeprecatedLicenseId(false); + assertEquals(new Boolean(false), testLicense.getIsDeprecatedLicenseId()); } /** @@ -134,10 +138,9 @@ public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisExce */ public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicense.getIsOsiApproved()); -// testLicense.setIsOsiApproved(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicense.getIsOsiApproved()); - fail("Not yet implemented"); + assertEquals(new Boolean(true), testLicense.getIsOsiApproved()); + testLicense.setIsOsiApproved(false); + assertEquals(new Boolean(false), testLicense.getIsOsiApproved()); } /** @@ -145,10 +148,9 @@ public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { */ public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicense.getStandardLicenseTemplate()); -// testLicense.setStandardLicenseTemplate(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicense.getStandardLicenseTemplate()); - fail("Not yet implemented"); + assertEquals(STANDARD_LICENSE_TEMPLATE_TEST_VALUE, testLicense.getStandardLicenseTemplate()); + testLicense.setStandardLicenseTemplate("new standardLicenseTemplate value"); + assertEquals("new standardLicenseTemplate value", testLicense.getStandardLicenseTemplate()); } /** @@ -156,10 +158,9 @@ public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisEx */ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicense.getStandardLicenseHeader()); -// testLicense.setStandardLicenseHeader(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicense.getStandardLicenseHeader()); - fail("Not yet implemented"); + assertEquals(STANDARD_LICENSE_HEADER_TEST_VALUE, testLicense.getStandardLicenseHeader()); + testLicense.setStandardLicenseHeader("new standardLicenseHeader value"); + assertEquals("new standardLicenseHeader value", testLicense.getStandardLicenseHeader()); } /** @@ -167,13 +168,8 @@ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisExce */ public void testLicensesetLicenseText() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLicense.getLicenseText()); -// testLicense.setLicenseText(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLicense.getLicenseText()); - fail("Not yet implemented"); + assertEquals(LICENSE_TEXT_TEST_VALUE, testLicense.getLicenseText()); + testLicense.setLicenseText("new licenseText value"); + assertEquals("new licenseText value", testLicense.getLicenseText()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java b/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java index f1c9f1e09..b403e86c3 100644 --- a/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class ListedLicenseExceptionTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static ListedLicenseExceptionBuilder builderForListedLicenseExceptionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ListedLicenseExceptionBuilder retval = new ListedLicenseExceptionBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + ListedLicenseExceptionBuilder retval = new ListedLicenseExceptionBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#Element(org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder)}. */ public void testListedLicenseExceptionListedLicenseExceptionBuilder() throws InvalidSPDXAnalysisException { - ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ListedLicenseException.equivalent(testListedLicenseException)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java b/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java index ec72fd264..75a3ecb74 100644 --- a/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.ListedLicense.ListedLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class ListedLicenseTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static ListedLicenseBuilder builderForListedLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ListedLicenseBuilder retval = new ListedLicenseBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + ListedLicenseBuilder retval = new ListedLicenseBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.ListedLicense#Element(org.spdx.library.model.licensing.ListedLicense.ListedLicenseBuilder)}. */ public void testListedLicenseListedLicenseBuilder() throws InvalidSPDXAnalysisException { - ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ListedLicense.equivalent(testListedLicense)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java index 1ec9fe0b7..4c2191d2f 100644 --- a/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.OrLaterOperator.OrLaterOperatorBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class OrLaterOperatorTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static OrLaterOperatorBuilder builderForOrLaterOperatorTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - OrLaterOperatorBuilder retval = new OrLaterOperatorBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + OrLaterOperatorBuilder retval = new OrLaterOperatorBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#Element(org.spdx.library.model.licensing.OrLaterOperator.OrLaterOperatorBuilder)}. */ public void testOrLaterOperatorOrLaterOperatorBuilder() throws InvalidSPDXAnalysisException { - OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2OrLaterOperator.equivalent(testOrLaterOperator)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java b/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java index 23395583f..51faa2443 100644 --- a/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.licensing.WithAdditionOperator.WithAdditionOperatorBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class WithAdditionOperatorTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static WithAdditionOperatorBuilder builderForWithAdditionOperatorTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - WithAdditionOperatorBuilder retval = new WithAdditionOperatorBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + WithAdditionOperatorBuilder retval = new WithAdditionOperatorBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#Element(org.spdx.library.model.licensing.WithAdditionOperator.WithAdditionOperatorBuilder)}. */ public void testWithAdditionOperatorWithAdditionOperatorBuilder() throws InvalidSPDXAnalysisException { - WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2WithAdditionOperator.equivalent(testWithAdditionOperator)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java index cfaf3b002..ce1d8c9fd 100644 --- a/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class CvssV2VulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static CvssV2VulnAssessmentRelationshipBuilder builderForCvssV2VulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - CvssV2VulnAssessmentRelationshipBuilder retval = new CvssV2VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + CvssV2VulnAssessmentRelationshipBuilder retval = new CvssV2VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#Element(org.spdx.library.model.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder)}. */ public void testCvssV2VulnAssessmentRelationshipCvssV2VulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2CvssV2VulnAssessmentRelationship.equivalent(testCvssV2VulnAssessmentRelationship)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java index 4450a4c90..f33b83a20 100644 --- a/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class CvssV3VulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static CvssV3VulnAssessmentRelationshipBuilder builderForCvssV3VulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - CvssV3VulnAssessmentRelationshipBuilder retval = new CvssV3VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + CvssV3VulnAssessmentRelationshipBuilder retval = new CvssV3VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#Element(org.spdx.library.model.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder)}. */ public void testCvssV3VulnAssessmentRelationshipCvssV3VulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2CvssV3VulnAssessmentRelationship.equivalent(testCvssV3VulnAssessmentRelationship)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java index 0eefc21b0..0a2b33b21 100644 --- a/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class EpssVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final Integer PROBABILITY_TEST_VALUE = 55; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +55,12 @@ protected void tearDown() throws Exception { public static EpssVulnAssessmentRelationshipBuilder builderForEpssVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - EpssVulnAssessmentRelationshipBuilder retval = new EpssVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setprobability(57) - ***************/ + EpssVulnAssessmentRelationshipBuilder retval = new EpssVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setProbability(PROBABILITY_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#Element(org.spdx.library.model.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder)}. */ public void testEpssVulnAssessmentRelationshipEpssVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -107,13 +111,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testEpssVulnAssessmentRelationshipsetProbability() throws InvalidSPDXAnalysisException { EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testEpssVulnAssessmentRelationship.getProbability()); -// testEpssVulnAssessmentRelationship.setProbability(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testEpssVulnAssessmentRelationship.getProbability()); - fail("Not yet implemented"); + assertEquals(PROBABILITY_TEST_VALUE, testEpssVulnAssessmentRelationship.getProbability()); + testEpssVulnAssessmentRelationship.setProbability(new Integer(653)); + assertEquals(new Integer(653), testEpssVulnAssessmentRelationship.getProbability()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java index 16c0fd598..1ae7b8552 100644 --- a/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class ExploitCatalogVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String LOCATOR_TEST_VALUE = "test locator"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,13 +55,14 @@ protected void tearDown() throws Exception { public static ExploitCatalogVulnAssessmentRelationshipBuilder builderForExploitCatalogVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ExploitCatalogVulnAssessmentRelationshipBuilder retval = new ExploitCatalogVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setcatalogType(ExploitCatalogType.ENUM) - .setexploited(true) - .setlocator("A string") - ***************/ + ExploitCatalogVulnAssessmentRelationshipBuilder retval = new ExploitCatalogVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setExploited(true) + .setLocator(LOCATOR_TEST_VALUE) + //TODO: Add in test values + /******************** + .setCatalogType(ExploitCatalogType.ENUM) + ***************/ + ; return retval; } @@ -93,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#Element(org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder)}. */ public void testExploitCatalogVulnAssessmentRelationshipExploitCatalogVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -120,10 +124,9 @@ public void testExploitCatalogVulnAssessmentRelationshipsetCatalogType() throws */ public void testExploitCatalogVulnAssessmentRelationshipsetExploited() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getExploited()); -// testExploitCatalogVulnAssessmentRelationship.setExploited(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getExploited()); - fail("Not yet implemented"); + assertEquals(new Boolean(true), testExploitCatalogVulnAssessmentRelationship.getExploited()); + testExploitCatalogVulnAssessmentRelationship.setExploited(false); + assertEquals(new Boolean(false), testExploitCatalogVulnAssessmentRelationship.getExploited()); } /** @@ -131,13 +134,8 @@ public void testExploitCatalogVulnAssessmentRelationshipsetExploited() throws In */ public void testExploitCatalogVulnAssessmentRelationshipsetLocator() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getLocator()); -// testExploitCatalogVulnAssessmentRelationship.setLocator(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getLocator()); - fail("Not yet implemented"); + assertEquals(LOCATOR_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getLocator()); + testExploitCatalogVulnAssessmentRelationship.setLocator("new locator value"); + assertEquals("new locator value", testExploitCatalogVulnAssessmentRelationship.getLocator()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java index aec7a6761..8e33afbe9 100644 --- a/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class SsvcVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +54,12 @@ protected void tearDown() throws Exception { public static SsvcVulnAssessmentRelationshipBuilder builderForSsvcVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SsvcVulnAssessmentRelationshipBuilder retval = new SsvcVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setdecisionType(SsvcDecisionType.ENUM) - ***************/ + SsvcVulnAssessmentRelationshipBuilder retval = new SsvcVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .setDecisionType(SsvcDecisionType.ENUM) + ***************/ + ; return retval; } @@ -91,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#Element(org.spdx.library.model.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder)}. */ public void testSsvcVulnAssessmentRelationshipSsvcVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -112,8 +115,4 @@ public void testSsvcVulnAssessmentRelationshipsetDecisionType() throws InvalidSP // assertEquals(NEW_TEST_VALUE, testSsvcVulnAssessmentRelationship.getDecisionType()); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java index e7348d64d..5438d2de6 100644 --- a/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,18 @@ public class VexAffectedVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String ACTION_STATEMENT_TEST_VALUE = "test actionStatement"; + static final String ACTION_STATEMENT_TIME_TEST_VALUE1 = "test 1 actionStatementTime"; + static final String ACTION_STATEMENT_TIME_TEST_VALUE2 = "test 2 actionStatementTime"; + static final String ACTION_STATEMENT_TIME_TEST_VALUE3 = "test 3 actionStatementTime"; + static final List ACTION_STATEMENT_TIME_TEST_LIST1 = Arrays.asList(new String[] { ACTION_STATEMENT_TIME_TEST_VALUE1, ACTION_STATEMENT_TIME_TEST_VALUE2 }); + static final List ACTION_STATEMENT_TIME_TEST_LIST2 = Arrays.asList(new String[] { ACTION_STATEMENT_TIME_TEST_VALUE3 }); + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +60,14 @@ protected void tearDown() throws Exception { public static VexAffectedVulnAssessmentRelationshipBuilder builderForVexAffectedVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VexAffectedVulnAssessmentRelationshipBuilder retval = new VexAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setactionStatement("A string") - .getactionStatementTime.add("Test string") - ***************/ + VexAffectedVulnAssessmentRelationshipBuilder retval = new VexAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setActionStatement(ACTION_STATEMENT_TEST_VALUE) + .addActionStatementTime(ACTION_STATEMENT_TIME_TEST_VALUE1) + .addActionStatementTime(ACTION_STATEMENT_TIME_TEST_VALUE2) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -92,7 +102,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder)}. */ public void testVexAffectedVulnAssessmentRelationshipVexAffectedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -108,25 +118,20 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testVexAffectedVulnAssessmentRelationshipsetActionStatement() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVexAffectedVulnAssessmentRelationship.getActionStatement()); -// testVexAffectedVulnAssessmentRelationship.setActionStatement(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVexAffectedVulnAssessmentRelationship.getActionStatement()); - fail("Not yet implemented"); + assertEquals(ACTION_STATEMENT_TEST_VALUE, testVexAffectedVulnAssessmentRelationship.getActionStatement()); + testVexAffectedVulnAssessmentRelationship.setActionStatement("new actionStatement value"); + assertEquals("new actionStatement value", testVexAffectedVulnAssessmentRelationship.getActionStatement()); } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#getActionStatementTime}. + * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#getActionStatementTimes}. */ - public void testVexAffectedVulnAssessmentRelationshipgetActionStatementTime() throws InvalidSPDXAnalysisException { + public void testVexAffectedVulnAssessmentRelationshipgetActionStatementTimes() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTime())); -// testVexAffectedVulnAssessmentRelationship.getActionStatementTime().clear(); -// testVexAffectedVulnAssessmentRelationship.getActionStatementTime().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTime())); + assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST1, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); + testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().clear(); + testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().addAll(ACTION_STATEMENT_TIME_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST2, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java index 7399f455c..669bbe7d0 100644 --- a/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class VexFixedVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static VexFixedVulnAssessmentRelationshipBuilder builderForVexFixedVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VexFixedVulnAssessmentRelationshipBuilder retval = new VexFixedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + VexFixedVulnAssessmentRelationshipBuilder retval = new VexFixedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder)}. */ public void testVexFixedVulnAssessmentRelationshipVexFixedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2VexFixedVulnAssessmentRelationship.equivalent(testVexFixedVulnAssessmentRelationship)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java index 33c8cddcd..63a3c6931 100644 --- a/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class VexNotAffectedVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String IMPACT_STATEMENT_TIME_TEST_VALUE = "test impactStatementTime"; + static final String IMPACT_STATEMENT_TEST_VALUE = "test impactStatement"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,13 +56,14 @@ protected void tearDown() throws Exception { public static VexNotAffectedVulnAssessmentRelationshipBuilder builderForVexNotAffectedVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VexNotAffectedVulnAssessmentRelationshipBuilder retval = new VexNotAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setjustificationType(VexJustificationType.ENUM) - .setimpactStatementTime("A string") - .setimpactStatement("A string") - ***************/ + VexNotAffectedVulnAssessmentRelationshipBuilder retval = new VexNotAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setImpactStatementTime(IMPACT_STATEMENT_TIME_TEST_VALUE) + .setImpactStatement(IMPACT_STATEMENT_TEST_VALUE) + //TODO: Add in test values + /******************** + .setJustificationType(VexJustificationType.ENUM) + ***************/ + ; return retval; } @@ -93,7 +98,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder)}. */ public void testVexNotAffectedVulnAssessmentRelationshipVexNotAffectedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -120,10 +125,9 @@ public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() t */ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); -// testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); - fail("Not yet implemented"); + assertEquals(IMPACT_STATEMENT_TIME_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime("new impactStatementTime value"); + assertEquals("new impactStatementTime value", testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); } /** @@ -131,13 +135,8 @@ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() */ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatement() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); -// testVexNotAffectedVulnAssessmentRelationship.setImpactStatement(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); - fail("Not yet implemented"); + assertEquals(IMPACT_STATEMENT_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); + testVexNotAffectedVulnAssessmentRelationship.setImpactStatement("new impactStatement value"); + assertEquals("new impactStatement value", testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java index cc07fae64..94727920a 100644 --- a/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class VexUnderInvestigationVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static VexUnderInvestigationVulnAssessmentRelationshipBuilder builderForVexUnderInvestigationVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VexUnderInvestigationVulnAssessmentRelationshipBuilder retval = new VexUnderInvestigationVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + VexUnderInvestigationVulnAssessmentRelationshipBuilder retval = new VexUnderInvestigationVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder)}. */ public void testVexUnderInvestigationVulnAssessmentRelationshipVexUnderInvestigationVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2VexUnderInvestigationVulnAssessmentRelationship.equivalent(testVexUnderInvestigationVulnAssessmentRelationship)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java index 1221be150..6a51fcf93 100644 --- a/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,14 @@ public class VexVulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String STATUS_NOTES_TEST_VALUE = "test statusNotes"; + static final String VEX_VERSION_TEST_VALUE = "test vexVersion"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +56,13 @@ protected void tearDown() throws Exception { public static VexVulnAssessmentRelationshipBuilder builderForVexVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VexVulnAssessmentRelationshipBuilder retval = new VexVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setstatusNotes("A string") - .setvexVersion("A string") - ***************/ + VexVulnAssessmentRelationshipBuilder retval = new VexVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setStatusNotes(STATUS_NOTES_TEST_VALUE) + .setVexVersion(VEX_VERSION_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -92,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder)}. */ public void testVexVulnAssessmentRelationshipVexVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -108,10 +113,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVexVulnAssessmentRelationship.getStatusNotes()); -// testVexVulnAssessmentRelationship.setStatusNotes(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVexVulnAssessmentRelationship.getStatusNotes()); - fail("Not yet implemented"); + assertEquals(STATUS_NOTES_TEST_VALUE, testVexVulnAssessmentRelationship.getStatusNotes()); + testVexVulnAssessmentRelationship.setStatusNotes("new statusNotes value"); + assertEquals("new statusNotes value", testVexVulnAssessmentRelationship.getStatusNotes()); } /** @@ -119,13 +123,8 @@ public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDX */ public void testVexVulnAssessmentRelationshipsetVexVersion() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVexVulnAssessmentRelationship.getVexVersion()); -// testVexVulnAssessmentRelationship.setVexVersion(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVexVulnAssessmentRelationship.getVexVersion()); - fail("Not yet implemented"); + assertEquals(VEX_VERSION_TEST_VALUE, testVexVulnAssessmentRelationship.getVexVersion()); + testVexVulnAssessmentRelationship.setVexVersion("new vexVersion value"); + assertEquals("new vexVersion value", testVexVulnAssessmentRelationship.getVexVersion()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java index a71d8d826..fbd253314 100644 --- a/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class VulnAssessmentRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +54,13 @@ protected void tearDown() throws Exception { public static VulnAssessmentRelationshipBuilder builderForVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VulnAssessmentRelationshipBuilder retval = new VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setassessedElement(Element testElement) - .setsuppliedBy(Element testElement) - ***************/ + VulnAssessmentRelationshipBuilder retval = new VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .setAssessedElement(Element testElement) + .setSuppliedBy(Element testElement) + ***************/ + ; return retval; } @@ -92,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#Element(org.spdx.library.model.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder)}. */ public void testVulnAssessmentRelationshipVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { - VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -124,8 +127,4 @@ public void testVulnAssessmentRelationshipsetSuppliedBy() throws InvalidSPDXAnal // assertEquals(NEW_TEST_VALUE, testVulnAssessmentRelationship.getSuppliedBy()); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java b/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java index fb96cfc87..dc1ec9733 100644 --- a/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java +++ b/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.security.Vulnerability.VulnerabilityBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class VulnerabilityTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,10 +54,11 @@ protected void tearDown() throws Exception { public static VulnerabilityBuilder builderForVulnerabilityTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - VulnerabilityBuilder retval = new VulnerabilityBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - ***************/ + VulnerabilityBuilder retval = new VulnerabilityBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -90,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.security.Vulnerability#Element(org.spdx.library.model.security.Vulnerability.VulnerabilityBuilder)}. */ public void testVulnerabilityVulnerabilityBuilder() throws InvalidSPDXAnalysisException { - Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -100,8 +103,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Vulnerability.equivalent(testVulnerability)); // TODO change some parameters for negative tests } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SbomTest.java b/src/test/java/org/spdx/library/model/software/SbomTest.java index 8040a00ed..5b8524f2a 100644 --- a/src/test/java/org/spdx/library/model/software/SbomTest.java +++ b/src/test/java/org/spdx/library/model/software/SbomTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.software.Sbom.SbomBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class SbomTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +54,12 @@ protected void tearDown() throws Exception { public static SbomBuilder builderForSbomTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SbomBuilder retval = new SbomBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .getsbomType.add(SBOMType.ENUM) - ***************/ + SbomBuilder retval = new SbomBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .addSbomType(SBOMType.ENUM) + ***************/ + ; return retval; } @@ -91,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.software.Sbom#Element(org.spdx.library.model.software.Sbom.SbomBuilder)}. */ public void testSbomSbomBuilder() throws InvalidSPDXAnalysisException { - Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -105,16 +108,12 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { /** * Test method for {@link org.spdx.library.model.software.Sbom#getSbomType}. */ - public void testSbomgetSbomType() throws InvalidSPDXAnalysisException { + public void testSbomgetSbomTypes() throws InvalidSPDXAnalysisException { Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSbom.getSbomType())); -// testSbom.getSbomType().clear(); -// testSbom.getSbomType().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSbom.getSbomType())); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSbom.getSbomTypes()))); +// testSbom.getSbomTypes().clear(); +// testSbom.getSbomTypes().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSbom.getSbomTypes()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SnippetTest.java b/src/test/java/org/spdx/library/model/software/SnippetTest.java index 11cb06c37..80aa7c4e5 100644 --- a/src/test/java/org/spdx/library/model/software/SnippetTest.java +++ b/src/test/java/org/spdx/library/model/software/SnippetTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.software.Snippet.SnippetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class SnippetTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +54,13 @@ protected void tearDown() throws Exception { public static SnippetBuilder builderForSnippetTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SnippetBuilder retval = new SnippetBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setbyteRange(new PositiveIntegerRange()) - .setlineRange(new PositiveIntegerRange()) - ***************/ + SnippetBuilder retval = new SnippetBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .setByteRange(new PositiveIntegerRange()) + .setLineRange(new PositiveIntegerRange()) + ***************/ + ; return retval; } @@ -92,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.software.Snippet#Element(org.spdx.library.model.software.Snippet.SnippetBuilder)}. */ public void testSnippetSnippetBuilder() throws InvalidSPDXAnalysisException { - Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -124,8 +127,4 @@ public void testSnippetsetLineRange() throws InvalidSPDXAnalysisException { // assertEquals(NEW_TEST_VALUE, testSnippet.getLineRange()); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java b/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java index 8241e2032..33313cded 100644 --- a/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java +++ b/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.software.SoftwareArtifact.SoftwareArtifactBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,15 @@ public class SoftwareArtifactTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String CONTENT_IDENTIFIER_TEST_VALUE = "test contentIdentifier"; + static final String ATTRIBUTION_TEXT_TEST_VALUE = "test attributionText"; + static final String COPYRIGHT_TEXT_TEST_VALUE = "test copyrightText"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,17 +57,18 @@ protected void tearDown() throws Exception { public static SoftwareArtifactBuilder builderForSoftwareArtifactTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SoftwareArtifactBuilder retval = new SoftwareArtifactBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setdeclaredLicense(TEST_ANYLICENSE_INFO) - .setconcludedLicense(TEST_ANYLICENSE_INFO) - .setprimaryPurpose(SoftwarePurpose.ENUM) - .setcontentIdentifier("A string") - .setattributionText("A string") - .setcopyrightText("A string") - .getadditionalPurpose.add(SoftwarePurpose.ENUM) - ***************/ + SoftwareArtifactBuilder retval = new SoftwareArtifactBuilder(modelStore, objectUri, copyManager) + .setContentIdentifier(CONTENT_IDENTIFIER_TEST_VALUE) + .setAttributionText(ATTRIBUTION_TEXT_TEST_VALUE) + .setCopyrightText(COPYRIGHT_TEXT_TEST_VALUE) + //TODO: Add in test values + /******************** + .setDeclaredLicense(TEST_ANYLICENSE_INFO) + .setConcludedLicense(TEST_ANYLICENSE_INFO) + .setPrimaryPurpose(SoftwarePurpose.ENUM) + .addAdditionalPurpose(SoftwarePurpose.ENUM) + ***************/ + ; return retval; } @@ -97,7 +103,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#Element(org.spdx.library.model.software.SoftwareArtifact.SoftwareArtifactBuilder)}. */ public void testSoftwareArtifactSoftwareArtifactBuilder() throws InvalidSPDXAnalysisException { - SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -146,10 +152,9 @@ public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisEx */ public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareArtifact.getContentIdentifier()); -// testSoftwareArtifact.setContentIdentifier(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getContentIdentifier()); - fail("Not yet implemented"); + assertEquals(CONTENT_IDENTIFIER_TEST_VALUE, testSoftwareArtifact.getContentIdentifier()); + testSoftwareArtifact.setContentIdentifier("new contentIdentifier value"); + assertEquals("new contentIdentifier value", testSoftwareArtifact.getContentIdentifier()); } /** @@ -157,10 +162,9 @@ public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysi */ public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareArtifact.getAttributionText()); -// testSoftwareArtifact.setAttributionText(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getAttributionText()); - fail("Not yet implemented"); + assertEquals(ATTRIBUTION_TEXT_TEST_VALUE, testSoftwareArtifact.getAttributionText()); + testSoftwareArtifact.setAttributionText("new attributionText value"); + assertEquals("new attributionText value", testSoftwareArtifact.getAttributionText()); } /** @@ -168,25 +172,20 @@ public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisE */ public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareArtifact.getCopyrightText()); -// testSoftwareArtifact.setCopyrightText(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getCopyrightText()); - fail("Not yet implemented"); + assertEquals(COPYRIGHT_TEXT_TEST_VALUE, testSoftwareArtifact.getCopyrightText()); + testSoftwareArtifact.setCopyrightText("new copyrightText value"); + assertEquals("new copyrightText value", testSoftwareArtifact.getCopyrightText()); } /** * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#getAdditionalPurpose}. */ - public void testSoftwareArtifactgetAdditionalPurpose() throws InvalidSPDXAnalysisException { + public void testSoftwareArtifactgetAdditionalPurposes() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurpose())); -// testSoftwareArtifact.getAdditionalPurpose().clear(); -// testSoftwareArtifact.getAdditionalPurpose().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurpose())); +// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurposes()))); +// testSoftwareArtifact.getAdditionalPurposes().clear(); +// testSoftwareArtifact.getAdditionalPurposes().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurposes()))); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java b/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java index 211567825..03fe8dc09 100644 --- a/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,12 @@ public class SoftwareDependencyRelationshipTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,12 +54,13 @@ protected void tearDown() throws Exception { public static SoftwareDependencyRelationshipBuilder builderForSoftwareDependencyRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SoftwareDependencyRelationshipBuilder retval = new SoftwareDependencyRelationshipBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setsoftwareLinkage(SoftwareDependencyLinkType.ENUM) - .setconditionality(DependencyConditionalityType.ENUM) - ***************/ + SoftwareDependencyRelationshipBuilder retval = new SoftwareDependencyRelationshipBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + .setSoftwareLinkage(SoftwareDependencyLinkType.ENUM) + .setConditionality(DependencyConditionalityType.ENUM) + ***************/ + ; return retval; } @@ -92,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#Element(org.spdx.library.model.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder)}. */ public void testSoftwareDependencyRelationshipSoftwareDependencyRelationshipBuilder() throws InvalidSPDXAnalysisException { - SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -124,8 +127,4 @@ public void testSoftwareDependencyRelationshipsetConditionality() throws Invalid // assertEquals(NEW_TEST_VALUE, testSoftwareDependencyRelationship.getConditionality()); fail("Not yet implemented"); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SpdxFileTest.java b/src/test/java/org/spdx/library/model/software/SpdxFileTest.java index a5822abaa..31641b4ce 100644 --- a/src/test/java/org/spdx/library/model/software/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/software/SpdxFileTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.software.SpdxFile.SpdxFileBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,13 @@ public class SpdxFileTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,11 +55,12 @@ protected void tearDown() throws Exception { public static SpdxFileBuilder builderForSpdxFileTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SpdxFileBuilder retval = new SpdxFileBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setcontentType("A string") - ***************/ + SpdxFileBuilder retval = new SpdxFileBuilder(modelStore, objectUri, copyManager) + .setContentType(CONTENT_TYPE_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.software.SpdxFile#Element(org.spdx.library.model.software.SpdxFile.SpdxFileBuilder)}. */ public void testSpdxFileSpdxFileBuilder() throws InvalidSPDXAnalysisException { - SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -107,13 +111,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSpdxFilesetContentType() throws InvalidSPDXAnalysisException { SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSpdxFile.getContentType()); -// testSpdxFile.setContentType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSpdxFile.getContentType()); - fail("Not yet implemented"); + assertEquals(CONTENT_TYPE_TEST_VALUE, testSpdxFile.getContentType()); + testSpdxFile.setContentType("new contentType value"); + assertEquals("new contentType value", testSpdxFile.getContentType()); } - -/* -*/ - } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java index 552084136..5cc267b17 100644 --- a/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java @@ -21,11 +21,11 @@ import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.software.SpdxPackage.SpdxPackageBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -36,10 +36,17 @@ public class SpdxPackageTest extends TestCase { static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + IModelStore modelStore; ModelCopyManager copyManager; + static final String DOWNLOAD_LOCATION_TEST_VALUE = "test downloadLocation"; + static final String SOURCE_INFO_TEST_VALUE = "test sourceInfo"; + static final String PACKAGE_VERSION_TEST_VALUE = "test packageVersion"; + static final String HOME_PAGE_TEST_VALUE = "test homePage"; + static final String PACKAGE_URL_TEST_VALUE = "test packageUrl"; + protected void setUp() throws Exception { super.setUp(); modelStore = new InMemSpdxStore(); @@ -52,15 +59,16 @@ protected void tearDown() throws Exception { public static SpdxPackageBuilder builderForSpdxPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - SpdxPackageBuilder retval = new SpdxPackageBuilder(modelStore, objectUri, copyManager); - //TODO: Add in test values - /******************** - .setdownloadLocation("A string") - .setsourceInfo("A string") - .setpackageVersion("A string") - .sethomePage("A string") - .setpackageUrl("A string") - ***************/ + SpdxPackageBuilder retval = new SpdxPackageBuilder(modelStore, objectUri, copyManager) + .setDownloadLocation(DOWNLOAD_LOCATION_TEST_VALUE) + .setSourceInfo(SOURCE_INFO_TEST_VALUE) + .setPackageVersion(PACKAGE_VERSION_TEST_VALUE) + .setHomePage(HOME_PAGE_TEST_VALUE) + .setPackageUrl(PACKAGE_URL_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; return retval; } @@ -95,7 +103,7 @@ public void testToString() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.software.SpdxPackage#Element(org.spdx.library.model.software.SpdxPackage.SpdxPackageBuilder)}. */ public void testSpdxPackageSpdxPackageBuilder() throws InvalidSPDXAnalysisException { - SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { @@ -111,10 +119,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSpdxPackage.getDownloadLocation()); -// testSpdxPackage.setDownloadLocation(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getDownloadLocation()); - fail("Not yet implemented"); + assertEquals(DOWNLOAD_LOCATION_TEST_VALUE, testSpdxPackage.getDownloadLocation()); + testSpdxPackage.setDownloadLocation("new downloadLocation value"); + assertEquals("new downloadLocation value", testSpdxPackage.getDownloadLocation()); } /** @@ -122,10 +129,9 @@ public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisExcep */ public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSpdxPackage.getSourceInfo()); -// testSpdxPackage.setSourceInfo(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getSourceInfo()); - fail("Not yet implemented"); + assertEquals(SOURCE_INFO_TEST_VALUE, testSpdxPackage.getSourceInfo()); + testSpdxPackage.setSourceInfo("new sourceInfo value"); + assertEquals("new sourceInfo value", testSpdxPackage.getSourceInfo()); } /** @@ -133,10 +139,9 @@ public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { */ public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSpdxPackage.getPackageVersion()); -// testSpdxPackage.setPackageVersion(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getPackageVersion()); - fail("Not yet implemented"); + assertEquals(PACKAGE_VERSION_TEST_VALUE, testSpdxPackage.getPackageVersion()); + testSpdxPackage.setPackageVersion("new packageVersion value"); + assertEquals("new packageVersion value", testSpdxPackage.getPackageVersion()); } /** @@ -144,10 +149,9 @@ public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisExcepti */ public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSpdxPackage.getHomePage()); -// testSpdxPackage.setHomePage(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getHomePage()); - fail("Not yet implemented"); + assertEquals(HOME_PAGE_TEST_VALUE, testSpdxPackage.getHomePage()); + testSpdxPackage.setHomePage("new homePage value"); + assertEquals("new homePage value", testSpdxPackage.getHomePage()); } /** @@ -155,13 +159,8 @@ public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { */ public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSpdxPackage.getPackageUrl()); -// testSpdxPackage.setPackageUrl(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSpdxPackage.getPackageUrl()); - fail("Not yet implemented"); + assertEquals(PACKAGE_URL_TEST_VALUE, testSpdxPackage.getPackageUrl()); + testSpdxPackage.setPackageUrl("new packageUrl value"); + assertEquals("new packageUrl value", testSpdxPackage.getPackageUrl()); } - -/* -*/ - } \ No newline at end of file From 971c361c0348494e57ee894caa9314eaf55efd04 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 19 Jul 2023 13:07:26 -0700 Subject: [PATCH 19/62] Remove unused imports Signed-off-by: Gary O'Neall --- src/main/java/org/spdx/library/model/ModelObject.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index a81c81fe9..50d70a73d 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -45,9 +45,7 @@ import org.spdx.library.SpdxConstants; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.CreationInfo; -import org.spdx.library.model.core.CreationInfo.CreationInfoBuilder; import org.spdx.library.model.core.Element; -import org.spdx.library.model.core.Payload.PayloadBuilder; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.library.model.licensing.AnyLicenseInfo; From 703bce346f2c45db66cc7d2f85cc407ff3e6fe21 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 19 Jul 2023 16:44:27 -0700 Subject: [PATCH 20/62] Udpate generated and resolve some unused imports Signed-off-by: Gary O'Neall --- .../org/spdx/library/model/ai/AIPackage.java | 42 +++++++- .../org/spdx/library/model/build/Build.java | 40 ++++++- .../org/spdx/library/model/core/Agent.java | 33 +++++- .../spdx/library/model/core/Annotation.java | 38 +++++-- .../library/model/core/AnonymousPayload.java | 33 +++++- .../org/spdx/library/model/core/Artifact.java | 38 ++++++- .../java/org/spdx/library/model/core/Bom.java | 33 +++++- .../org/spdx/library/model/core/Bundle.java | 34 +++++- .../spdx/library/model/core/CreationInfo.java | 44 ++++++-- .../library/model/core/DictionaryEntry.java | 37 ++++++- .../org/spdx/library/model/core/Element.java | 37 ++++++- .../library/model/core/ElementCollection.java | 43 ++++++-- .../model/core/ExternalIdentifier.java | 40 +++++-- .../spdx/library/model/core/ExternalMap.java | 39 ++++++- .../library/model/core/ExternalReference.java | 38 ++++++- .../org/spdx/library/model/core/Hash.java | 37 +++++-- .../library/model/core/IntegrityMethod.java | 34 +++++- .../core/LifecycleScopedRelationship.java | 34 +++++- .../spdx/library/model/core/NamespaceMap.java | 36 ++++++- .../spdx/library/model/core/Organization.java | 33 +++++- .../org/spdx/library/model/core/Payload.java | 35 +++++- .../org/spdx/library/model/core/Person.java | 33 +++++- .../model/core/PositiveIntegerRange.java | 48 ++++++--- .../spdx/library/model/core/Relationship.java | 41 +++++-- .../library/model/core/SoftwareAgent.java | 33 +++++- .../spdx/library/model/core/SpdxDocument.java | 33 +++++- .../org/spdx/library/model/core/Tool.java | 33 +++++- .../spdx/library/model/dataset/Dataset.java | 101 +++++++++++++++--- .../ConjunctiveLicenseSet.java | 33 +++++- .../DisjunctiveLicenseSet.java | 33 +++++- .../expandedlicense/ExtendableLicense.java | 33 +++++- .../model/licensing/AnyLicenseInfo.java | 33 +++++- .../model/licensing/CustomLicense.java | 33 +++++- .../licensing/CustomLicenseAddition.java | 33 +++++- .../spdx/library/model/licensing/License.java | 41 ++++++- .../model/licensing/LicenseAddition.java | 38 ++++++- .../model/licensing/LicenseExpression.java | 36 ++++++- .../model/licensing/ListedLicense.java | 33 +++++- .../licensing/ListedLicenseException.java | 33 +++++- .../model/licensing/OrLaterOperator.java | 33 +++++- .../model/licensing/WithAdditionOperator.java | 33 +++++- .../CvssV2VulnAssessmentRelationship.java | 33 +++++- .../CvssV3VulnAssessmentRelationship.java | 33 +++++- .../EpssVulnAssessmentRelationship.java | 48 ++++++--- ...loitCatalogVulnAssessmentRelationship.java | 37 +++++-- .../SsvcVulnAssessmentRelationship.java | 37 +++++-- ...VexAffectedVulnAssessmentRelationship.java | 36 ++++++- .../VexFixedVulnAssessmentRelationship.java | 33 +++++- ...NotAffectedVulnAssessmentRelationship.java | 36 ++++++- ...vestigationVulnAssessmentRelationship.java | 33 +++++- .../VexVulnAssessmentRelationship.java | 35 +++++- .../security/VulnAssessmentRelationship.java | 33 +++++- .../library/model/security/Vulnerability.java | 33 +++++- .../org/spdx/library/model/software/Sbom.java | 34 +++++- .../spdx/library/model/software/Snippet.java | 33 +++++- .../model/software/SoftwareArtifact.java | 38 ++++++- .../SoftwareDependencyRelationship.java | 35 +++++- .../spdx/library/model/software/SpdxFile.java | 34 +++++- .../library/model/software/SpdxPackage.java | 38 ++++++- .../org/spdx/library/model/ModelObject.java | 6 ++ 60 files changed, 1842 insertions(+), 348 deletions(-) diff --git a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java b/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java index e7e89d2bf..45937eec6 100644 --- a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java +++ b/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.DictionaryEntry; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.software.SpdxPackage; @@ -107,6 +105,7 @@ public AIPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyMa * @param builder Builder to create the AIPackage from * @throws InvalidSPDXAnalysisException when unable to create the AIPackage */ + @SuppressWarnings("unchecked") protected AIPackage(AIPackageBuilder builder) throws InvalidSPDXAnalysisException { super(builder); metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); @@ -322,36 +321,43 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional sensitivePersonalInformation = getSensitivePersonalInformation(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting sensitivePersonalInformation for AIPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional safetyRiskAssessment = getSafetyRiskAssessment(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting safetyRiskAssessment for AIPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional autonomyType = getAutonomyType(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting autonomyType for AIPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional informationAboutTraining = getInformationAboutTraining(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting informationAboutTraining for AIPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional limitation = getLimitation(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting limitation for AIPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional energyConsumption = getEnergyConsumption(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting energyConsumption for AIPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional informationAboutApplication = getInformationAboutApplication(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting informationAboutApplication for AIPackage: "+e.getMessage()); @@ -370,6 +376,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class AIPackageBuilder extends SpdxPackageBuilder { + /** + * Create an AIPackageBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public AIPackageBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an AIPackageBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public AIPackageBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a AIPackageBuilder + * @param modelStore model store for the built AIPackage + * @param objectUri objectUri for the built AIPackage + * @param copyManager optional copyManager for the built AIPackage + */ public AIPackageBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/build/Build.java b/generated/src/main/java/org/spdx/library/model/build/Build.java index 6a8765c78..5509bc21a 100644 --- a/generated/src/main/java/org/spdx/library/model/build/Build.java +++ b/generated/src/main/java/org/spdx/library/model/build/Build.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.DictionaryEntry; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.Hash; @@ -104,6 +104,7 @@ public Build(IModelStore modelStore, String objectUri, @Nullable ModelCopyManage * @param builder Builder to create the Build from * @throws InvalidSPDXAnalysisException when unable to create the Build */ + @SuppressWarnings("unchecked") protected Build(BuildBuilder builder) throws InvalidSPDXAnalysisException { super(builder); parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); @@ -230,6 +231,7 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional buildEndTime = getBuildEndTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildEndTime for Build: "+e.getMessage()); @@ -243,11 +245,13 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting buildType for Build: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional buildStartTime = getBuildStartTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildStartTime for Build: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional buildId = getBuildId(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildId for Build: "+e.getMessage()); @@ -266,6 +270,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class BuildBuilder extends ElementBuilder { + /** + * Create an BuildBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public BuildBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an BuildBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public BuildBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a BuildBuilder + * @param modelStore model store for the built Build + * @param objectUri objectUri for the built Build + * @param copyManager optional copyManager for the built Build + */ public BuildBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Agent.java b/generated/src/main/java/org/spdx/library/model/core/Agent.java index 3eb7da891..21f442f90 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Agent.java +++ b/generated/src/main/java/org/spdx/library/model/core/Agent.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -115,6 +112,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class AgentBuilder extends ElementBuilder { + /** + * Create an AgentBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public AgentBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an AgentBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public AgentBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a AgentBuilder + * @param modelStore model store for the built Agent + * @param objectUri objectUri for the built Agent + * @param copyManager optional copyManager for the built Agent + */ public AgentBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Annotation.java b/generated/src/main/java/org/spdx/library/model/core/Annotation.java index cbccbebb4..cb9102487 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Annotation.java +++ b/generated/src/main/java/org/spdx/library/model/core/Annotation.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -122,7 +122,6 @@ public Annotation setSubject(@Nullable Element subject) throws InvalidSPDXAnalys /** * @return the annotationType */ - @SuppressWarnings("unchecked") public @Nullable AnnotationType getAnnotationType() throws InvalidSPDXAnalysisException { Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_ANNOTATION_TYPE); if (retval.isPresent()) { @@ -198,6 +197,7 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting annotationType for Annotation: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional statement = getStatement(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting statement for Annotation: "+e.getMessage()); @@ -207,6 +207,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class AnnotationBuilder extends ElementBuilder { + /** + * Create an AnnotationBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public AnnotationBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an AnnotationBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public AnnotationBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a AnnotationBuilder + * @param modelStore model store for the built Annotation + * @param objectUri objectUri for the built Annotation + * @param copyManager optional copyManager for the built Annotation + */ public AnnotationBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java index c555e0c1d..4e6fb932f 100644 --- a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java +++ b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -113,6 +110,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class AnonymousPayloadBuilder extends PayloadBuilder { + /** + * Create an AnonymousPayloadBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public AnonymousPayloadBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an AnonymousPayloadBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public AnonymousPayloadBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a AnonymousPayloadBuilder + * @param modelStore model store for the built AnonymousPayload + * @param objectUri objectUri for the built AnonymousPayload + * @param copyManager optional copyManager for the built AnonymousPayload + */ public AnonymousPayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Artifact.java b/generated/src/main/java/org/spdx/library/model/core/Artifact.java index 893a91c33..cb17f9eb3 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Artifact.java +++ b/generated/src/main/java/org/spdx/library/model/core/Artifact.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -89,6 +87,7 @@ public Artifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyMan * @param builder Builder to create the Artifact from * @throws InvalidSPDXAnalysisException when unable to create the Artifact */ + @SuppressWarnings("unchecked") protected Artifact(ArtifactBuilder builder) throws InvalidSPDXAnalysisException { super(builder); originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); @@ -184,16 +183,19 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional releaseTime = getReleaseTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting releaseTime for Artifact: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional validUntilTime = getValidUntilTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting validUntilTime for Artifact: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional builtTime = getBuiltTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting builtTime for Artifact: "+e.getMessage()); @@ -209,6 +211,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ArtifactBuilder extends ElementBuilder { + /** + * Create an ArtifactBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ArtifactBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ArtifactBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ArtifactBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ArtifactBuilder + * @param modelStore model store for the built Artifact + * @param objectUri objectUri for the built Artifact + * @param copyManager optional copyManager for the built Artifact + */ public ArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Bom.java b/generated/src/main/java/org/spdx/library/model/core/Bom.java index 57d1be700..c9a0a0dad 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Bom.java +++ b/generated/src/main/java/org/spdx/library/model/core/Bom.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -116,6 +113,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class BomBuilder extends BundleBuilder { + /** + * Create an BomBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public BomBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an BomBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public BomBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a BomBuilder + * @param modelStore model store for the built Bom + * @param objectUri objectUri for the built Bom + * @param copyManager optional copyManager for the built Bom + */ public BomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Bundle.java b/generated/src/main/java/org/spdx/library/model/core/Bundle.java index d4589bb45..fdb5ee912 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Bundle.java +++ b/generated/src/main/java/org/spdx/library/model/core/Bundle.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -126,6 +123,7 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional context = getContext(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting context for Bundle: "+e.getMessage()); @@ -135,6 +133,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class BundleBuilder extends ElementCollectionBuilder { + /** + * Create an BundleBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public BundleBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an BundleBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public BundleBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a BundleBuilder + * @param modelStore model store for the built Bundle + * @param objectUri objectUri for the built Bundle + * @param copyManager optional copyManager for the built Bundle + */ public BundleBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java b/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java index 6811cb19b..ba3a8188e 100644 --- a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java +++ b/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -97,6 +97,7 @@ public CreationInfo(IModelStore modelStore, String objectUri, @Nullable ModelCop * @param builder Builder to create the CreationInfo from * @throws InvalidSPDXAnalysisException when unable to create the CreationInfo */ + @SuppressWarnings("unchecked") protected CreationInfo(CreationInfoBuilder builder) throws InvalidSPDXAnalysisException { super(builder); createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); @@ -172,6 +173,7 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); try { + @SuppressWarnings("unused") Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting comment for CreationInfo: "+e.getMessage()); @@ -182,17 +184,37 @@ protected List _verify(Set verifiedIds, String specVersion, List for (Agent createdBy:createdBys) { retval.addAll(createdBy.verify(verifiedIds, specVersion, profiles)); } - if (createdBys.size() < 1) { - retval.add("createdBys size " + createdBys.size() + " is less than 1 in CreationInfo"); - } - if (profiles.size() < 1) { - retval.add("profiles size " + profiles.size() + " is less than 1 in CreationInfo"); - } return retval; } public static class CreationInfoBuilder extends ModelObjectBuilder { + /** + * Create an CreationInfoBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public CreationInfoBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an CreationInfoBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public CreationInfoBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a CreationInfoBuilder + * @param modelStore model store for the built CreationInfo + * @param objectUri objectUri for the built CreationInfo + * @param copyManager optional copyManager for the built CreationInfo + */ public CreationInfoBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java index 6761a6a6d..344d16143 100644 --- a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java +++ b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -157,6 +157,7 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting key for DictionaryEntry: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional value = getValue(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting value for DictionaryEntry: "+e.getMessage()); @@ -166,6 +167,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class DictionaryEntryBuilder extends ModelObjectBuilder { + /** + * Create an DictionaryEntryBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public DictionaryEntryBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an DictionaryEntryBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public DictionaryEntryBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a DictionaryEntryBuilder + * @param modelStore model store for the built DictionaryEntry + * @param objectUri objectUri for the built DictionaryEntry + * @param copyManager optional copyManager for the built DictionaryEntry + */ public DictionaryEntryBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Element.java b/generated/src/main/java/org/spdx/library/model/core/Element.java index ca16738c2..b8c75175f 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Element.java +++ b/generated/src/main/java/org/spdx/library/model/core/Element.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -90,6 +88,7 @@ public Element(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana * @param builder Builder to create the Element from * @throws InvalidSPDXAnalysisException when unable to create the Element */ + @SuppressWarnings("unchecked") protected Element(ElementBuilder builder) throws InvalidSPDXAnalysisException { super(builder); externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); @@ -163,11 +162,13 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional description = getDescription(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting description for Element: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional summary = getSummary(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting summary for Element: "+e.getMessage()); @@ -183,6 +184,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ElementBuilder extends PayloadBuilder { + /** + * Create an ElementBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ElementBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ElementBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ElementBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ElementBuilder + * @param modelStore model store for the built Element + * @param objectUri objectUri for the built Element + * @param copyManager optional copyManager for the built Element + */ public ElementBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java b/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java index bf10cce1f..2f1eeefa9 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java +++ b/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,6 +86,7 @@ public ElementCollection(IModelStore modelStore, String objectUri, @Nullable Mod * @param builder Builder to create the ElementCollection from * @throws InvalidSPDXAnalysisException when unable to create the ElementCollection */ + @SuppressWarnings("unchecked") protected ElementCollection(ElementCollectionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); @@ -127,20 +128,40 @@ protected List _verify(Set verifiedIds, String specVersion, List for (Element element:elements) { retval.addAll(element.verify(verifiedIds, specVersion, profiles)); } - if (elements.size() < 1) { - retval.add("elements size " + elements.size() + " is less than 1 in ElementCollection"); - } for (Element rootElement:rootElements) { retval.addAll(rootElement.verify(verifiedIds, specVersion, profiles)); } - if (rootElements.size() < 1) { - retval.add("rootElements size " + rootElements.size() + " is less than 1 in ElementCollection"); - } return retval; } public static class ElementCollectionBuilder extends ElementBuilder { + /** + * Create an ElementCollectionBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ElementCollectionBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ElementCollectionBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ElementCollectionBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ElementCollectionBuilder + * @param modelStore model store for the built ElementCollection + * @param objectUri objectUri for the built ElementCollection + * @param copyManager optional copyManager for the built ElementCollection + */ public ElementCollectionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java index 966d4dd50..7b28b9b5a 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -85,6 +85,7 @@ public ExternalIdentifier(IModelStore modelStore, String objectUri, @Nullable Mo * @param builder Builder to create the ExternalIdentifier from * @throws InvalidSPDXAnalysisException when unable to create the ExternalIdentifier */ + @SuppressWarnings("unchecked") protected ExternalIdentifier(ExternalIdentifierBuilder builder) throws InvalidSPDXAnalysisException { super(builder); identifierLocators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IDENTIFIER_LOCATOR, String.class); @@ -112,7 +113,6 @@ public Collection getIdentifierLocators() { /** * @return the externalIdentifierType */ - @SuppressWarnings("unchecked") public @Nullable ExternalIdentifierType getExternalIdentifierType() throws InvalidSPDXAnalysisException { Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER_TYPE); if (retval.isPresent()) { @@ -210,6 +210,7 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting externalIdentifierType for ExternalIdentifier: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional issuingAuthority = getIssuingAuthority(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting issuingAuthority for ExternalIdentifier: "+e.getMessage()); @@ -223,6 +224,7 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting identifier for ExternalIdentifier: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting comment for ExternalIdentifier: "+e.getMessage()); @@ -232,6 +234,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ExternalIdentifierBuilder extends ModelObjectBuilder { + /** + * Create an ExternalIdentifierBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ExternalIdentifierBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ExternalIdentifierBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ExternalIdentifierBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ExternalIdentifierBuilder + * @param modelStore model store for the built ExternalIdentifier + * @param objectUri objectUri for the built ExternalIdentifier + * @param copyManager optional copyManager for the built ExternalIdentifier + */ public ExternalIdentifierBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java index 9b7483adc..9344396aa 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,6 +86,7 @@ public ExternalMap(IModelStore modelStore, String objectUri, @Nullable ModelCopy * @param builder Builder to create the ExternalMap from * @throws InvalidSPDXAnalysisException when unable to create the ExternalMap */ + @SuppressWarnings("unchecked") protected ExternalMap(ExternalMapBuilder builder) throws InvalidSPDXAnalysisException { super(builder); verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); @@ -174,11 +175,13 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); try { + @SuppressWarnings("unused") Optional definingDocument = getDefiningDocument(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting definingDocument for ExternalMap: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional locationHint = getLocationHint(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting locationHint for ExternalMap: "+e.getMessage()); @@ -199,6 +202,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ExternalMapBuilder extends ModelObjectBuilder { + /** + * Create an ExternalMapBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ExternalMapBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ExternalMapBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ExternalMapBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ExternalMapBuilder + * @param modelStore model store for the built ExternalMap + * @param objectUri objectUri for the built ExternalMap + * @param copyManager optional copyManager for the built ExternalMap + */ public ExternalMapBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java b/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java index 6d062f5dc..66dfdbdbc 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -85,6 +83,7 @@ public ExternalReference(IModelStore modelStore, String objectUri, @Nullable Mod * @param builder Builder to create the ExternalReference from * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference */ + @SuppressWarnings("unchecked") protected ExternalReference(ExternalReferenceBuilder builder) throws InvalidSPDXAnalysisException { super(builder); locators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_LOCATOR, String.class); @@ -178,16 +177,19 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); try { + @SuppressWarnings("unused") Optional externalReferenceType = getExternalReferenceType(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting externalReferenceType for ExternalReference: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional contentType = getContentType(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting contentType for ExternalReference: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting comment for ExternalReference: "+e.getMessage()); @@ -197,6 +199,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ExternalReferenceBuilder extends ModelObjectBuilder { + /** + * Create an ExternalReferenceBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ExternalReferenceBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ExternalReferenceBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ExternalReferenceBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ExternalReferenceBuilder + * @param modelStore model store for the built ExternalReference + * @param objectUri objectUri for the built ExternalReference + * @param copyManager optional copyManager for the built ExternalReference + */ public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Hash.java b/generated/src/main/java/org/spdx/library/model/core/Hash.java index 084d0599b..5d0aaced7 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Hash.java +++ b/generated/src/main/java/org/spdx/library/model/core/Hash.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -103,7 +103,6 @@ public String getType() { /** * @return the algorithm */ - @SuppressWarnings("unchecked") public @Nullable HashAlgorithm getAlgorithm() throws InvalidSPDXAnalysisException { Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_ALGORITHM); if (retval.isPresent()) { @@ -182,6 +181,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class HashBuilder extends IntegrityMethodBuilder { + /** + * Create an HashBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public HashBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an HashBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public HashBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a HashBuilder + * @param modelStore model store for the built Hash + * @param objectUri objectUri for the built Hash + * @param copyManager optional copyManager for the built Hash + */ public HashBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java b/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java index f73fdf4ed..d20f1da06 100644 --- a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java +++ b/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -129,6 +126,7 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); try { + @SuppressWarnings("unused") Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting comment for IntegrityMethod: "+e.getMessage()); @@ -138,6 +136,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class IntegrityMethodBuilder extends ModelObjectBuilder { + /** + * Create an IntegrityMethodBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public IntegrityMethodBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an IntegrityMethodBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public IntegrityMethodBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a IntegrityMethodBuilder + * @param modelStore model store for the built IntegrityMethod + * @param objectUri objectUri for the built IntegrityMethod + * @param copyManager optional copyManager for the built IntegrityMethod + */ public IntegrityMethodBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java index e6cdaf3ee..486fe8de1 100644 --- a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -135,6 +132,7 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional scope = getScope(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting scope for LifecycleScopedRelationship: "+e.getMessage()); @@ -144,6 +142,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class LifecycleScopedRelationshipBuilder extends RelationshipBuilder { + /** + * Create an LifecycleScopedRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public LifecycleScopedRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an LifecycleScopedRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public LifecycleScopedRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a LifecycleScopedRelationshipBuilder + * @param modelStore model store for the built LifecycleScopedRelationship + * @param objectUri objectUri for the built LifecycleScopedRelationship + * @param copyManager optional copyManager for the built LifecycleScopedRelationship + */ public LifecycleScopedRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java index 5c5064dc8..18eb0a064 100644 --- a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java +++ b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -172,6 +172,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class NamespaceMapBuilder extends ModelObjectBuilder { + /** + * Create an NamespaceMapBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public NamespaceMapBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an NamespaceMapBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public NamespaceMapBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a NamespaceMapBuilder + * @param modelStore model store for the built NamespaceMap + * @param objectUri objectUri for the built NamespaceMap + * @param copyManager optional copyManager for the built NamespaceMap + */ public NamespaceMapBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Organization.java b/generated/src/main/java/org/spdx/library/model/core/Organization.java index ecea6214c..1c70a7146 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Organization.java +++ b/generated/src/main/java/org/spdx/library/model/core/Organization.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -114,6 +111,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class OrganizationBuilder extends AgentBuilder { + /** + * Create an OrganizationBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public OrganizationBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an OrganizationBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public OrganizationBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a OrganizationBuilder + * @param modelStore model store for the built Organization + * @param objectUri objectUri for the built Organization + * @param copyManager optional copyManager for the built Organization + */ public OrganizationBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Payload.java b/generated/src/main/java/org/spdx/library/model/core/Payload.java index 67bc30bd5..d084827ca 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Payload.java +++ b/generated/src/main/java/org/spdx/library/model/core/Payload.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,6 +84,7 @@ public Payload(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana * @param builder Builder to create the Payload from * @throws InvalidSPDXAnalysisException when unable to create the Payload */ + @SuppressWarnings("unchecked") protected Payload(PayloadBuilder builder) throws InvalidSPDXAnalysisException { super(builder); namespacess = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_NAMESPACES, NamespaceMap.class); @@ -170,6 +169,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class PayloadBuilder extends ModelObjectBuilder { + /** + * Create an PayloadBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public PayloadBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an PayloadBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public PayloadBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a PayloadBuilder + * @param modelStore model store for the built Payload + * @param objectUri objectUri for the built Payload + * @param copyManager optional copyManager for the built Payload + */ public PayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Person.java b/generated/src/main/java/org/spdx/library/model/core/Person.java index dd720f554..c9981b423 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Person.java +++ b/generated/src/main/java/org/spdx/library/model/core/Person.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -113,6 +110,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class PersonBuilder extends AgentBuilder { + /** + * Create an PersonBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public PersonBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an PersonBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public PersonBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a PersonBuilder + * @param modelStore model store for the built Person + * @param objectUri objectUri for the built Person + * @param copyManager optional copyManager for the built Person + */ public PersonBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java index 27b21dcff..c90c3ce97 100644 --- a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java +++ b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -118,9 +118,6 @@ public PositiveIntegerRange setEnd(@Nullable Integer end) throws InvalidSPDXAnal if (isStrict() && Objects.nonNull(end) && end < 1) { throw new InvalidSPDXAnalysisException("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); } - if (isStrict() && Objects.nonNull(end) && end > 1) { - throw new InvalidSPDXAnalysisException("end value " + end + " is greater than the maximum 1 in PositiveIntegerRange"); - } setPropertyValue(SpdxConstants.CORE_PROP_END, end); return this; } @@ -145,9 +142,6 @@ public PositiveIntegerRange setBegin(@Nullable Integer begin) throws InvalidSPDX if (isStrict() && Objects.nonNull(begin) && begin < 1) { throw new InvalidSPDXAnalysisException("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); } - if (isStrict() && Objects.nonNull(begin) && begin > 1) { - throw new InvalidSPDXAnalysisException("begin value " + begin + " is greater than the maximum 1 in PositiveIntegerRange"); - } setPropertyValue(SpdxConstants.CORE_PROP_BEGIN, begin); return this; } @@ -172,9 +166,6 @@ protected List _verify(Set verifiedIds, String specVersion, List if (Objects.nonNull(end) && end < 1) { retval.add("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); } - if (Objects.nonNull(end) && end > 1) { - retval.add("end value " + end + " is greater than the maximum 1 in PositiveIntegerRange"); - } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting end for PositiveIntegerRange: "+e.getMessage()); } @@ -186,9 +177,6 @@ protected List _verify(Set verifiedIds, String specVersion, List if (Objects.nonNull(begin) && begin < 1) { retval.add("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); } - if (Objects.nonNull(begin) && begin > 1) { - retval.add("begin value " + begin + " is greater than the maximum 1 in PositiveIntegerRange"); - } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting begin for PositiveIntegerRange: "+e.getMessage()); } @@ -197,6 +185,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class PositiveIntegerRangeBuilder extends ModelObjectBuilder { + /** + * Create an PositiveIntegerRangeBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public PositiveIntegerRangeBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an PositiveIntegerRangeBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public PositiveIntegerRangeBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a PositiveIntegerRangeBuilder + * @param modelStore model store for the built PositiveIntegerRange + * @param objectUri objectUri for the built PositiveIntegerRange + * @param copyManager optional copyManager for the built PositiveIntegerRange + */ public PositiveIntegerRangeBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Relationship.java b/generated/src/main/java/org/spdx/library/model/core/Relationship.java index d4e0545fd..0074092dc 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Relationship.java +++ b/generated/src/main/java/org/spdx/library/model/core/Relationship.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -85,6 +85,7 @@ public Relationship(IModelStore modelStore, String objectUri, @Nullable ModelCop * @param builder Builder to create the Relationship from * @throws InvalidSPDXAnalysisException when unable to create the Relationship */ + @SuppressWarnings("unchecked") protected Relationship(RelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); tos = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_TO, Element.class); @@ -134,7 +135,6 @@ public Relationship setFrom(@Nullable Element from) throws InvalidSPDXAnalysisEx /** * @return the relationshipType */ - @SuppressWarnings("unchecked") public @Nullable RelationshipType getRelationshipType() throws InvalidSPDXAnalysisException { Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_RELATIONSHIP_TYPE); if (retval.isPresent()) { @@ -251,16 +251,19 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting relationshipType for Relationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional completeness = getCompleteness(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting completeness for Relationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional startTime = getStartTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting startTime for Relationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional endTime = getEndTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting endTime for Relationship: "+e.getMessage()); @@ -273,6 +276,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class RelationshipBuilder extends ElementBuilder { + /** + * Create an RelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public RelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an RelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public RelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a RelationshipBuilder + * @param modelStore model store for the built Relationship + * @param objectUri objectUri for the built Relationship + * @param copyManager optional copyManager for the built Relationship + */ public RelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java b/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java index ef99f49d8..eb06e86ac 100644 --- a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java +++ b/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -114,6 +111,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SoftwareAgentBuilder extends AgentBuilder { + /** + * Create an SoftwareAgentBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SoftwareAgentBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SoftwareAgentBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SoftwareAgentBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SoftwareAgentBuilder + * @param modelStore model store for the built SoftwareAgent + * @param objectUri objectUri for the built SoftwareAgent + * @param copyManager optional copyManager for the built SoftwareAgent + */ public SoftwareAgentBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java b/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java index 1977a6407..907fe7e67 100644 --- a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java +++ b/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -115,6 +112,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SpdxDocumentBuilder extends BundleBuilder { + /** + * Create an SpdxDocumentBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SpdxDocumentBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SpdxDocumentBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SpdxDocumentBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SpdxDocumentBuilder + * @param modelStore model store for the built SpdxDocument + * @param objectUri objectUri for the built SpdxDocument + * @param copyManager optional copyManager for the built SpdxDocument + */ public SpdxDocumentBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/core/Tool.java b/generated/src/main/java/org/spdx/library/model/core/Tool.java index 542fae5ca..71167271e 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Tool.java +++ b/generated/src/main/java/org/spdx/library/model/core/Tool.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -114,6 +111,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ToolBuilder extends ElementBuilder { + /** + * Create an ToolBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ToolBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ToolBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ToolBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ToolBuilder + * @param modelStore model store for the built Tool + * @param objectUri objectUri for the built Tool + * @param copyManager optional copyManager for the built Tool + */ public ToolBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java index f6af48b80..dfa0628a5 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java +++ b/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java @@ -21,23 +21,23 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.DictionaryEntry; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.software.SpdxPackage; @@ -100,6 +100,7 @@ public Dataset(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana * @param builder Builder to create the Dataset from * @throws InvalidSPDXAnalysisException when unable to create the Dataset */ + @SuppressWarnings("unchecked") protected Dataset(DatasetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); sensors = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_SENSOR, DictionaryEntry.class); @@ -112,6 +113,7 @@ protected Dataset(DatasetBuilder builder) throws InvalidSPDXAnalysisException { getAnonymizationMethodUseds().addAll(builder.anonymizationMethodUseds); getDataPreprocessings().addAll(builder.dataPreprocessings); getKnownBiass().addAll(builder.knownBiass); + setSensitivePersonalInformation(builder.sensitivePersonalInformation); setConfidentialityLevel(builder.confidentialityLevel); setDatasetAvailability(builder.datasetAvailability); setDatasetSize(builder.datasetSize); @@ -147,6 +149,31 @@ public Collection getKnownBiass() { } + /** + * @return the sensitivePersonalInformation + */ + @SuppressWarnings("unchecked") + public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION); + if (retval.isPresent()) { + if (!(retval.get() instanceof PresenceType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param sensitivePersonalInformation the sensitivePersonalInformation to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Dataset setSensitivePersonalInformation(@Nullable PresenceType sensitivePersonalInformation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION, sensitivePersonalInformation); + return this; + } /** * @return the confidentialityLevel @@ -214,9 +241,6 @@ public Dataset setDatasetSize(@Nullable Integer datasetSize) throws InvalidSPDXA if (isStrict() && Objects.nonNull(datasetSize) && datasetSize < 0) { throw new InvalidSPDXAnalysisException("datasetSize value " + datasetSize + " is less than the minimum 0 in Dataset"); } - if (isStrict() && Objects.nonNull(datasetSize) && datasetSize > 1) { - throw new InvalidSPDXAnalysisException("datasetSize value " + datasetSize + " is greater than the maximum 1 in Dataset"); - } setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_SIZE, datasetSize); return this; } @@ -298,13 +322,23 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - + Optional sensitivePersonalInformation; + try { + sensitivePersonalInformation = getSensitivePersonalInformation(); + if (sensitivePersonalInformation.isPresent()) { + retval.addAll(sensitivePersonalInformation.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting sensitivePersonalInformation for Dataset: "+e.getMessage()); + } try { + @SuppressWarnings("unused") Optional confidentialityLevel = getConfidentialityLevel(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting confidentialityLevel for Dataset: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional datasetAvailability = getDatasetAvailability(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting datasetAvailability for Dataset: "+e.getMessage()); @@ -314,28 +348,29 @@ protected List _verify(Set verifiedIds, String specVersion, List if (datasetSize.isPresent() && datasetSize.get() < 0) { retval.add("datasetSize value " + datasetSize.get() + " is less than the minimum 0 in Dataset"); } - if (datasetSize.isPresent() && datasetSize.get() > 1) { - retval.add("datasetSize value " + datasetSize.get() + " is greater than the maximum 1 in Dataset"); - } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting datasetSize for Dataset: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional intendedUse = getIntendedUse(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting intendedUse for Dataset: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional datasetNoise = getDatasetNoise(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting datasetNoise for Dataset: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional dataCollectionProcess = getDataCollectionProcess(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting dataCollectionProcess for Dataset: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional datasetUpdateMechanism = getDatasetUpdateMechanism(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting datasetUpdateMechanism for Dataset: "+e.getMessage()); @@ -343,14 +378,37 @@ protected List _verify(Set verifiedIds, String specVersion, List for (DictionaryEntry sensor:sensors) { retval.addAll(sensor.verify(verifiedIds, specVersion, profiles)); } - if (datasetTypes.size() < 1) { - retval.add("datasetTypes size " + datasetTypes.size() + " is less than 1 in Dataset"); - } return retval; } public static class DatasetBuilder extends SpdxPackageBuilder { + /** + * Create an DatasetBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public DatasetBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an DatasetBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public DatasetBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a DatasetBuilder + * @param modelStore model store for the built Dataset + * @param objectUri objectUri for the built Dataset + * @param copyManager optional copyManager for the built Dataset + */ public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } @@ -360,6 +418,7 @@ public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC Collection anonymizationMethodUseds = new ArrayList<>(); Collection dataPreprocessings = new ArrayList<>(); Collection knownBiass = new ArrayList<>(); + PresenceType sensitivePersonalInformation = null; ConfidentialityLevelType confidentialityLevel = null; DatasetAvailabilityType datasetAvailability = null; Integer datasetSize = null; @@ -488,7 +547,17 @@ DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { } return this; } - + + /** + * Sets the initial value of sensitivePersonalInformation + * @parameter sensitivePersonalInformation value to set + * @return this for chaining + **/ + DatasetBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + this.sensitivePersonalInformation = sensitivePersonalInformation; + return this; + } + /** * Sets the initial value of confidentialityLevel * @parameter confidentialityLevel value to set diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java index 334686301..227616656 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; @@ -123,6 +120,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ConjunctiveLicenseSetBuilder extends AnyLicenseInfoBuilder { + /** + * Create an ConjunctiveLicenseSetBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ConjunctiveLicenseSetBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ConjunctiveLicenseSetBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ConjunctiveLicenseSetBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ConjunctiveLicenseSetBuilder + * @param modelStore model store for the built ConjunctiveLicenseSet + * @param objectUri objectUri for the built ConjunctiveLicenseSet + * @param copyManager optional copyManager for the built ConjunctiveLicenseSet + */ public ConjunctiveLicenseSetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java index 4890c9328..b677ec9fc 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; @@ -121,6 +118,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class DisjunctiveLicenseSetBuilder extends AnyLicenseInfoBuilder { + /** + * Create an DisjunctiveLicenseSetBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public DisjunctiveLicenseSetBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an DisjunctiveLicenseSetBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public DisjunctiveLicenseSetBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a DisjunctiveLicenseSetBuilder + * @param modelStore model store for the built DisjunctiveLicenseSet + * @param objectUri objectUri for the built DisjunctiveLicenseSet + * @param copyManager optional copyManager for the built DisjunctiveLicenseSet + */ public DisjunctiveLicenseSetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java index 21e23d005..cb7b1691b 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; @@ -116,6 +113,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ExtendableLicenseBuilder extends AnyLicenseInfoBuilder { + /** + * Create an ExtendableLicenseBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ExtendableLicenseBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ExtendableLicenseBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ExtendableLicenseBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ExtendableLicenseBuilder + * @param modelStore model store for the built ExtendableLicense + * @param objectUri objectUri for the built ExtendableLicense + * @param copyManager optional copyManager for the built ExtendableLicense + */ public ExtendableLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java b/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java index ddde9acf8..ef39f21c1 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; @@ -119,6 +116,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class AnyLicenseInfoBuilder extends ElementBuilder { + /** + * Create an AnyLicenseInfoBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public AnyLicenseInfoBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an AnyLicenseInfoBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public AnyLicenseInfoBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a AnyLicenseInfoBuilder + * @param modelStore model store for the built AnyLicenseInfo + * @param objectUri objectUri for the built AnyLicenseInfo + * @param copyManager optional copyManager for the built AnyLicenseInfo + */ public AnyLicenseInfoBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java index 8dda87cc9..d81bfb02b 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -115,6 +112,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class CustomLicenseBuilder extends LicenseBuilder { + /** + * Create an CustomLicenseBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public CustomLicenseBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an CustomLicenseBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public CustomLicenseBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a CustomLicenseBuilder + * @param modelStore model store for the built CustomLicense + * @param objectUri objectUri for the built CustomLicense + * @param copyManager optional copyManager for the built CustomLicense + */ public CustomLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java index 1769ae018..649db1728 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -118,6 +115,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class CustomLicenseAdditionBuilder extends LicenseAdditionBuilder { + /** + * Create an CustomLicenseAdditionBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public CustomLicenseAdditionBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an CustomLicenseAdditionBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public CustomLicenseAdditionBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a CustomLicenseAdditionBuilder + * @param modelStore model store for the built CustomLicenseAddition + * @param objectUri objectUri for the built CustomLicenseAddition + * @param copyManager optional copyManager for the built CustomLicenseAddition + */ public CustomLicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/License.java b/generated/src/main/java/org/spdx/library/model/licensing/License.java index b6b9b0223..49aa16ff7 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/License.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/License.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.expandedlicense.ExtendableLicense; @@ -221,26 +221,31 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional isFsfLibre = getIsFsfLibre(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isFsfLibre for License: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional isDeprecatedLicenseId = getIsDeprecatedLicenseId(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isDeprecatedLicenseId for License: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional isOsiApproved = getIsOsiApproved(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isOsiApproved for License: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional standardLicenseTemplate = getStandardLicenseTemplate(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting standardLicenseTemplate for License: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional standardLicenseHeader = getStandardLicenseHeader(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting standardLicenseHeader for License: "+e.getMessage()); @@ -258,6 +263,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class LicenseBuilder extends ExtendableLicenseBuilder { + /** + * Create an LicenseBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public LicenseBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an LicenseBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public LicenseBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a LicenseBuilder + * @param modelStore model store for the built License + * @param objectUri objectUri for the built License + * @param copyManager optional copyManager for the built License + */ public LicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java index 558f51009..900da360b 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; @@ -171,11 +171,13 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional isDeprecatedAdditionId = getIsDeprecatedAdditionId(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isDeprecatedAdditionId for LicenseAddition: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional standardAdditionTemplate = getStandardAdditionTemplate(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting standardAdditionTemplate for LicenseAddition: "+e.getMessage()); @@ -193,6 +195,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class LicenseAdditionBuilder extends ElementBuilder { + /** + * Create an LicenseAdditionBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public LicenseAdditionBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an LicenseAdditionBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public LicenseAdditionBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a LicenseAdditionBuilder + * @param modelStore model store for the built LicenseAddition + * @param objectUri objectUri for the built LicenseAddition + * @param copyManager optional copyManager for the built LicenseAddition + */ public LicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java index c759ae4e1..1b493454b 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -157,6 +157,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class LicenseExpressionBuilder extends AnyLicenseInfoBuilder { + /** + * Create an LicenseExpressionBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public LicenseExpressionBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an LicenseExpressionBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public LicenseExpressionBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a LicenseExpressionBuilder + * @param modelStore model store for the built LicenseExpression + * @param objectUri objectUri for the built LicenseExpression + * @param copyManager optional copyManager for the built LicenseExpression + */ public LicenseExpressionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java index 9d5fdf46b..cd4c85022 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -114,6 +111,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ListedLicenseBuilder extends LicenseBuilder { + /** + * Create an ListedLicenseBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ListedLicenseBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ListedLicenseBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ListedLicenseBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ListedLicenseBuilder + * @param modelStore model store for the built ListedLicense + * @param objectUri objectUri for the built ListedLicense + * @param copyManager optional copyManager for the built ListedLicense + */ public ListedLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java index 9e17eab27..6712a4876 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -116,6 +113,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ListedLicenseExceptionBuilder extends LicenseAdditionBuilder { + /** + * Create an ListedLicenseExceptionBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ListedLicenseExceptionBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ListedLicenseExceptionBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ListedLicenseExceptionBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ListedLicenseExceptionBuilder + * @param modelStore model store for the built ListedLicenseException + * @param objectUri objectUri for the built ListedLicenseException + * @param copyManager optional copyManager for the built ListedLicenseException + */ public ListedLicenseExceptionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java b/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java index 8345d074f..dd4c3608e 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.expandedlicense.ExtendableLicense; @@ -122,6 +119,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class OrLaterOperatorBuilder extends ExtendableLicenseBuilder { + /** + * Create an OrLaterOperatorBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public OrLaterOperatorBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an OrLaterOperatorBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public OrLaterOperatorBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a OrLaterOperatorBuilder + * @param modelStore model store for the built OrLaterOperator + * @param objectUri objectUri for the built OrLaterOperator + * @param copyManager optional copyManager for the built OrLaterOperator + */ public OrLaterOperatorBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java b/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java index 09981e40c..319afb92b 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -117,6 +114,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class WithAdditionOperatorBuilder extends AnyLicenseInfoBuilder { + /** + * Create an WithAdditionOperatorBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public WithAdditionOperatorBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an WithAdditionOperatorBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public WithAdditionOperatorBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a WithAdditionOperatorBuilder + * @param modelStore model store for the built WithAdditionOperator + * @param objectUri objectUri for the built WithAdditionOperator + * @param copyManager optional copyManager for the built WithAdditionOperator + */ public WithAdditionOperatorBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java index 084807b5e..175d74e08 100644 --- a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -132,6 +129,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class CvssV2VulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + /** + * Create an CvssV2VulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public CvssV2VulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an CvssV2VulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public CvssV2VulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a CvssV2VulnAssessmentRelationshipBuilder + * @param modelStore model store for the built CvssV2VulnAssessmentRelationship + * @param objectUri objectUri for the built CvssV2VulnAssessmentRelationship + * @param copyManager optional copyManager for the built CvssV2VulnAssessmentRelationship + */ public CvssV2VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java index e1a2d75f9..5b7093acb 100644 --- a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -133,6 +130,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class CvssV3VulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + /** + * Create an CvssV3VulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public CvssV3VulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an CvssV3VulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public CvssV3VulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a CvssV3VulnAssessmentRelationshipBuilder + * @param modelStore model store for the built CvssV3VulnAssessmentRelationship + * @param objectUri objectUri for the built CvssV3VulnAssessmentRelationship + * @param copyManager optional copyManager for the built CvssV3VulnAssessmentRelationship + */ public CvssV3VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java index dd2e99760..e470aac13 100644 --- a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -121,12 +121,6 @@ public EpssVulnAssessmentRelationship setProbability(@Nullable Integer probabili if (isStrict() && Objects.isNull(probability)) { throw new InvalidSPDXAnalysisException("probability is a required property"); } - if (isStrict() && Objects.nonNull(probability) && probability < 1) { - throw new InvalidSPDXAnalysisException("probability value " + probability + " is less than the minimum 1 in EpssVulnAssessmentRelationship"); - } - if (isStrict() && Objects.nonNull(probability) && probability > 1) { - throw new InvalidSPDXAnalysisException("probability value " + probability + " is greater than the maximum 1 in EpssVulnAssessmentRelationship"); - } setPropertyValue(SpdxConstants.SECURITY_PROP_PROBABILITY, probability); return this; } @@ -149,12 +143,6 @@ protected List _verify(Set verifiedIds, String specVersion, List if (Objects.isNull(probability)) { retval.add("Missing probability in EpssVulnAssessmentRelationship"); } - if (Objects.nonNull(probability) && probability < 1) { - retval.add("probability value " + probability + " is less than the minimum 1 in EpssVulnAssessmentRelationship"); - } - if (Objects.nonNull(probability) && probability > 1) { - retval.add("probability value " + probability + " is greater than the maximum 1 in EpssVulnAssessmentRelationship"); - } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting probability for EpssVulnAssessmentRelationship: "+e.getMessage()); } @@ -163,6 +151,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class EpssVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + /** + * Create an EpssVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public EpssVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an EpssVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public EpssVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a EpssVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built EpssVulnAssessmentRelationship + * @param objectUri objectUri for the built EpssVulnAssessmentRelationship + * @param copyManager optional copyManager for the built EpssVulnAssessmentRelationship + */ public EpssVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java index fc3d4aad2..30ab3ba45 100644 --- a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -111,7 +111,6 @@ public String getType() { /** * @return the catalogType */ - @SuppressWarnings("unchecked") public @Nullable ExploitCatalogType getCatalogType() throws InvalidSPDXAnalysisException { Optional> retval = getEnumPropertyValue(SpdxConstants.SECURITY_PROP_CATALOG_TYPE); if (retval.isPresent()) { @@ -219,6 +218,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class ExploitCatalogVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + /** + * Create an ExploitCatalogVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ExploitCatalogVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ExploitCatalogVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ExploitCatalogVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ExploitCatalogVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built ExploitCatalogVulnAssessmentRelationship + * @param objectUri objectUri for the built ExploitCatalogVulnAssessmentRelationship + * @param copyManager optional copyManager for the built ExploitCatalogVulnAssessmentRelationship + */ public ExploitCatalogVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java index ab7d3cc5e..9c14d00ec 100644 --- a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java @@ -21,22 +21,22 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -108,7 +108,6 @@ public String getType() { /** * @return the decisionType */ - @SuppressWarnings("unchecked") public @Nullable SsvcDecisionType getDecisionType() throws InvalidSPDXAnalysisException { Optional> retval = getEnumPropertyValue(SpdxConstants.SECURITY_PROP_DECISION_TYPE); if (retval.isPresent()) { @@ -159,6 +158,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SsvcVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + /** + * Create an SsvcVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SsvcVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SsvcVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SsvcVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SsvcVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built SsvcVulnAssessmentRelationship + * @param objectUri objectUri for the built SsvcVulnAssessmentRelationship + * @param copyManager optional copyManager for the built SsvcVulnAssessmentRelationship + */ public SsvcVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java index 237edacf1..ffdb0ec30 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -96,6 +94,7 @@ public VexAffectedVulnAssessmentRelationship(IModelStore modelStore, String obje * @param builder Builder to create the VexAffectedVulnAssessmentRelationship from * @throws InvalidSPDXAnalysisException when unable to create the VexAffectedVulnAssessmentRelationship */ + @SuppressWarnings("unchecked") protected VexAffectedVulnAssessmentRelationship(VexAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); @@ -147,6 +146,7 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional actionStatement = getActionStatement(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting actionStatement for VexAffectedVulnAssessmentRelationship: "+e.getMessage()); @@ -156,6 +156,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VexAffectedVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + /** + * Create an VexAffectedVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VexAffectedVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VexAffectedVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VexAffectedVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VexAffectedVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built VexAffectedVulnAssessmentRelationship + * @param objectUri objectUri for the built VexAffectedVulnAssessmentRelationship + * @param copyManager optional copyManager for the built VexAffectedVulnAssessmentRelationship + */ public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java index 5179050de..f2d807848 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -125,6 +122,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VexFixedVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + /** + * Create an VexFixedVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VexFixedVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VexFixedVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VexFixedVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VexFixedVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built VexFixedVulnAssessmentRelationship + * @param objectUri objectUri for the built VexFixedVulnAssessmentRelationship + * @param copyManager optional copyManager for the built VexFixedVulnAssessmentRelationship + */ public VexFixedVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java index 0b67435ae..db63752f8 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -185,16 +182,19 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional justificationType = getJustificationType(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting justificationType for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional impactStatementTime = getImpactStatementTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting impactStatementTime for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional impactStatement = getImpactStatement(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting impactStatement for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); @@ -204,6 +204,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VexNotAffectedVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + /** + * Create an VexNotAffectedVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VexNotAffectedVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VexNotAffectedVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VexNotAffectedVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VexNotAffectedVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built VexNotAffectedVulnAssessmentRelationship + * @param objectUri objectUri for the built VexNotAffectedVulnAssessmentRelationship + * @param copyManager optional copyManager for the built VexNotAffectedVulnAssessmentRelationship + */ public VexNotAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java index 800378f0d..1c6a24360 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -125,6 +122,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VexUnderInvestigationVulnAssessmentRelationshipBuilder extends VexVulnAssessmentRelationshipBuilder { + /** + * Create an VexUnderInvestigationVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VexUnderInvestigationVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VexUnderInvestigationVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VexUnderInvestigationVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VexUnderInvestigationVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built VexUnderInvestigationVulnAssessmentRelationship + * @param objectUri objectUri for the built VexUnderInvestigationVulnAssessmentRelationship + * @param copyManager optional copyManager for the built VexUnderInvestigationVulnAssessmentRelationship + */ public VexUnderInvestigationVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java index 64d4a65a1..7bd12225d 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -156,11 +153,13 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional statusNotes = getStatusNotes(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting statusNotes for VexVulnAssessmentRelationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional vexVersion = getVexVersion(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting vexVersion for VexVulnAssessmentRelationship: "+e.getMessage()); @@ -170,6 +169,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VexVulnAssessmentRelationshipBuilder extends VulnAssessmentRelationshipBuilder { + /** + * Create an VexVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VexVulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VexVulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VexVulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VexVulnAssessmentRelationshipBuilder + * @param modelStore model store for the built VexVulnAssessmentRelationship + * @param objectUri objectUri for the built VexVulnAssessmentRelationship + * @param copyManager optional copyManager for the built VexVulnAssessmentRelationship + */ public VexVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java index afcfe2f30..8f74a67be 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Agent; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; @@ -173,6 +170,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VulnAssessmentRelationshipBuilder extends RelationshipBuilder { + /** + * Create an VulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VulnAssessmentRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VulnAssessmentRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VulnAssessmentRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VulnAssessmentRelationshipBuilder + * @param modelStore model store for the built VulnAssessmentRelationship + * @param objectUri objectUri for the built VulnAssessmentRelationship + * @param copyManager optional copyManager for the built VulnAssessmentRelationship + */ public VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java b/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java index ef897cd8b..8ee3c8fe4 100644 --- a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java +++ b/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; @@ -143,6 +140,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class VulnerabilityBuilder extends ElementBuilder { + /** + * Create an VulnerabilityBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public VulnerabilityBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an VulnerabilityBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public VulnerabilityBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a VulnerabilityBuilder + * @param modelStore model store for the built Vulnerability + * @param objectUri objectUri for the built Vulnerability + * @param copyManager optional copyManager for the built Vulnerability + */ public VulnerabilityBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/software/Sbom.java b/generated/src/main/java/org/spdx/library/model/software/Sbom.java index 9c6535ddc..aa80b32d4 100644 --- a/generated/src/main/java/org/spdx/library/model/software/Sbom.java +++ b/generated/src/main/java/org/spdx/library/model/software/Sbom.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Bom; import org.spdx.library.model.core.ProfileIdentifierType; @@ -126,6 +124,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SbomBuilder extends BomBuilder { + /** + * Create an SbomBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SbomBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SbomBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SbomBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SbomBuilder + * @param modelStore model store for the built Sbom + * @param objectUri objectUri for the built Sbom + * @param copyManager optional copyManager for the built Sbom + */ public SbomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/software/Snippet.java b/generated/src/main/java/org/spdx/library/model/software/Snippet.java index 1790ef56e..491c22634 100644 --- a/generated/src/main/java/org/spdx/library/model/software/Snippet.java +++ b/generated/src/main/java/org/spdx/library/model/software/Snippet.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.PositiveIntegerRange; import org.spdx.library.model.core.ProfileIdentifierType; @@ -190,6 +187,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SnippetBuilder extends SoftwareArtifactBuilder { + /** + * Create an SnippetBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SnippetBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SnippetBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SnippetBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SnippetBuilder + * @param modelStore model store for the built Snippet + * @param objectUri objectUri for the built Snippet + * @param copyManager optional copyManager for the built Snippet + */ public SnippetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java index 41ca3cd16..dd4158077 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java @@ -21,23 +21,21 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Artifact; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; @@ -252,21 +250,25 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting concludedLicense for SoftwareArtifact: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional primaryPurpose = getPrimaryPurpose(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting primaryPurpose for SoftwareArtifact: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional contentIdentifier = getContentIdentifier(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting contentIdentifier for SoftwareArtifact: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional attributionText = getAttributionText(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting attributionText for SoftwareArtifact: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional copyrightText = getCopyrightText(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting copyrightText for SoftwareArtifact: "+e.getMessage()); @@ -276,6 +278,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SoftwareArtifactBuilder extends ArtifactBuilder { + /** + * Create an SoftwareArtifactBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SoftwareArtifactBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SoftwareArtifactBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SoftwareArtifactBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SoftwareArtifactBuilder + * @param modelStore model store for the built SoftwareArtifact + * @param objectUri objectUri for the built SoftwareArtifact + * @param copyManager optional copyManager for the built SoftwareArtifact + */ public SoftwareArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java index d7df81d4b..78437fe9a 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.LifecycleScopedRelationship; import org.spdx.library.model.core.ProfileIdentifierType; @@ -163,11 +160,13 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional softwareLinkage = getSoftwareLinkage(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting softwareLinkage for SoftwareDependencyRelationship: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional conditionality = getConditionality(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting conditionality for SoftwareDependencyRelationship: "+e.getMessage()); @@ -177,6 +176,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SoftwareDependencyRelationshipBuilder extends LifecycleScopedRelationshipBuilder { + /** + * Create an SoftwareDependencyRelationshipBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SoftwareDependencyRelationshipBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SoftwareDependencyRelationshipBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SoftwareDependencyRelationshipBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SoftwareDependencyRelationshipBuilder + * @param modelStore model store for the built SoftwareDependencyRelationship + * @param objectUri objectUri for the built SoftwareDependencyRelationship + * @param copyManager optional copyManager for the built SoftwareDependencyRelationship + */ public SoftwareDependencyRelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java b/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java index f7565bf14..a6deea6c3 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java +++ b/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -129,6 +126,7 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional contentType = getContentType(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting contentType for SpdxFile: "+e.getMessage()); @@ -138,6 +136,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SpdxFileBuilder extends SoftwareArtifactBuilder { + /** + * Create an SpdxFileBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SpdxFileBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SpdxFileBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SpdxFileBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SpdxFileBuilder + * @param modelStore model store for the built SpdxFile + * @param objectUri objectUri for the built SpdxFile + * @param copyManager optional copyManager for the built SpdxFile + */ public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java b/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java index c0303fb69..afc7c4b5c 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java +++ b/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java @@ -21,22 +21,19 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Optional; import java.util.Set; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObject; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -204,26 +201,31 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { + @SuppressWarnings("unused") Optional downloadLocation = getDownloadLocation(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting downloadLocation for SpdxPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional sourceInfo = getSourceInfo(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting sourceInfo for SpdxPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional packageVersion = getPackageVersion(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting packageVersion for SpdxPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional homePage = getHomePage(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting homePage for SpdxPackage: "+e.getMessage()); } try { + @SuppressWarnings("unused") Optional packageUrl = getPackageUrl(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting packageUrl for SpdxPackage: "+e.getMessage()); @@ -233,6 +235,32 @@ protected List _verify(Set verifiedIds, String specVersion, List public static class SpdxPackageBuilder extends SoftwareArtifactBuilder { + /** + * Create an SpdxPackageBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SpdxPackageBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SpdxPackageBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SpdxPackageBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SpdxPackageBuilder + * @param modelStore model store for the built SpdxPackage + * @param objectUri objectUri for the built SpdxPackage + * @param copyManager optional copyManager for the built SpdxPackage + */ public SpdxPackageBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 50d70a73d..66d943e79 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -176,6 +176,7 @@ public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopy */ public ModelObject(ModelObjectBuilder builder) throws InvalidSPDXAnalysisException { this(builder.modelStore, builder.objectUri, builder.copyManager, true); + this.strict = builder.strict; } // Abstract methods that must be implemented in the subclasses @@ -965,11 +966,16 @@ public static class ModelObjectBuilder { public IModelStore modelStore; public String objectUri; public ModelCopyManager copyManager; + public boolean strict = true; public ModelObjectBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { this.modelStore = modelStore; this.objectUri = objectUri; this.copyManager = copyManager; } + + public void setStrict(boolean strict) { + this.strict = strict; + } } } From 6183ae0807f0b25849e60f30f41b5e010852a0a6 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sat, 22 Jul 2023 17:10:36 -0700 Subject: [PATCH 21/62] Add support for external maps and individuals Signed-off-by: Gary O'Neall --- .../org/spdx/library/SpdxEnumFactory.java | 147 +++++++++++++++ .../spdx/library/SpdxIndividualFactory.java | 49 +++++ .../org/spdx/library/model/build/Build.java | 3 +- .../org/spdx/library/model/core/Agent.java | 2 - .../spdx/library/model/core/Annotation.java | 7 +- .../library/model/core/AnonymousPayload.java | 2 - .../java/org/spdx/library/model/core/Bom.java | 2 - .../library/model/core/DictionaryEntry.java | 3 +- .../model/core/ExternalIdentifier.java | 6 +- .../spdx/library/model/core/ExternalMap.java | 3 +- .../org/spdx/library/model/core/Hash.java | 6 +- .../spdx/library/model/core/NamespaceMap.java | 6 +- .../spdx/library/model/core/Organization.java | 2 - .../org/spdx/library/model/core/Person.java | 2 - .../model/core/PositiveIntegerRange.java | 6 +- .../spdx/library/model/core/Relationship.java | 7 +- .../library/model/core/SoftwareAgent.java | 2 - .../spdx/library/model/core/SpdxDocument.java | 2 - .../org/spdx/library/model/core/Tool.java | 2 - .../ConjunctiveLicenseSet.java | 2 - .../DisjunctiveLicenseSet.java | 2 - .../expandedlicense/ExtendableLicense.java | 2 - .../model/licensing/AnyLicenseInfo.java | 2 - .../model/licensing/CustomLicense.java | 2 - .../licensing/CustomLicenseAddition.java | 2 - .../spdx/library/model/licensing/License.java | 3 +- .../model/licensing/LicenseAddition.java | 3 +- .../model/licensing/LicenseExpression.java | 3 +- .../model/licensing/ListedLicense.java | 2 - .../licensing/ListedLicenseException.java | 2 - .../model/licensing/OrLaterOperator.java | 2 - .../model/licensing/WithAdditionOperator.java | 2 - .../CvssV2VulnAssessmentRelationship.java | 2 - .../CvssV3VulnAssessmentRelationship.java | 2 - .../EpssVulnAssessmentRelationship.java | 3 +- ...loitCatalogVulnAssessmentRelationship.java | 9 +- .../SsvcVulnAssessmentRelationship.java | 3 +- .../VexFixedVulnAssessmentRelationship.java | 2 - ...vestigationVulnAssessmentRelationship.java | 2 - .../library/model/security/Vulnerability.java | 2 - .../java/org/spdx/library/SimpleUriValue.java | 54 +++++- .../org/spdx/library/SpdxModelFactory.java | 12 +- .../spdx/library/SpdxVerificationHelper.java | 2 +- .../spdx/library/model/ExternalElement.java | 176 ++++++++++++++++++ .../spdx/library/model/ModelCollection.java | 13 +- .../org/spdx/library/model/ModelObject.java | 42 ++++- .../spdx/library/model/ModelObjectHelper.java | 21 ++- .../java/org/spdx/library/model/ModelSet.java | 20 +- .../library/model/compat/v2/Annotation.java | 2 +- .../library/model/compat/v2/Checksum.java | 2 +- .../model/compat/v2/ExternalDocumentRef.java | 2 +- .../library/model/compat/v2/ExternalRef.java | 2 +- .../library/model/compat/v2/ModelObject.java | 12 +- .../compat/v2/ModelStorageClassConverter.java | 5 +- .../compat/v2/RelatedElementCollection.java | 2 +- .../library/model/compat/v2/Relationship.java | 2 +- .../library/model/compat/v2/SpdxDocument.java | 2 +- .../library/model/compat/v2/SpdxFile.java | 4 +- .../library/model/compat/v2/SpdxPackage.java | 6 +- .../v2/SpdxPackageVerificationCode.java | 2 +- .../v2}/enumerations/AnnotationType.java | 2 +- .../v2}/enumerations/ChecksumAlgorithm.java | 2 +- .../v2}/enumerations/FileType.java | 2 +- .../{ => compat/v2}/enumerations/Purpose.java | 2 +- .../v2}/enumerations/ReferenceCategory.java | 2 +- .../v2}/enumerations/RelationshipType.java | 2 +- .../SpdxEnumFactoryCompatV2.java} | 6 +- .../v2}/enumerations/package-info.java | 4 +- .../spdx/storage/simple/StoredTypedItem.java | 6 +- .../compare/SpdxExternalRefDifference.java | 2 +- .../utility/compare/SpdxFileDifference.java | 2 +- .../library/SpdxVerificationHelperTest.java | 2 +- .../library/model/ModelCollectionTest.java | 26 +-- .../library/model/SimpleUriValueTest.java | 16 +- .../spdx/library/model/ai/AIPackageTest.java | 55 +++--- .../spdx/library/model/build/BuildTest.java | 15 +- .../model/compat/v2/AnnotationTest.java | 2 +- .../library/model/compat/v2/ChecksumTest.java | 2 +- .../compat/v2/ExternalDocumentRefTest.java | 2 +- .../model/compat/v2/ExternalRefTest.java | 2 +- .../compat/v2/ExternalSpdxElementTest.java | 4 +- .../compat/v2/IndividualUriValueTest.java | 2 +- .../model/compat/v2/ModelObjectTest.java | 4 +- .../v2/ModelStorageClassConverterTest.java | 6 +- .../compat/v2/NoAssertionElementTest.java | 2 +- .../v2/RelatedElementCollectionTest.java | 2 +- .../model/compat/v2/RelationshipTest.java | 6 +- .../model/compat/v2/SpdxDocumentTest.java | 8 +- .../model/compat/v2/SpdxElementTest.java | 4 +- .../library/model/compat/v2/SpdxFileTest.java | 8 +- .../model/compat/v2/SpdxNoneElementTest.java | 2 +- .../model/compat/v2/SpdxPackageTest.java | 12 +- .../model/compat/v2/SpdxSnippetTest.java | 4 +- .../v2/license/ExternalLicenseRefTest.java | 2 +- .../license/LicenseExpressionParserTest.java | 2 +- .../spdx/library/model/core/AgentTest.java | 1 + .../library/model/core/AnnotationTest.java | 16 +- .../model/core/AnonymousPayloadTest.java | 1 + .../spdx/library/model/core/ArtifactTest.java | 14 +- .../org/spdx/library/model/core/BomTest.java | 1 + .../spdx/library/model/core/BundleTest.java | 5 +- .../library/model/core/CreationInfoTest.java | 24 +-- .../model/core/DictionaryEntryTest.java | 5 +- .../model/core/ElementCollectionTest.java | 1 + .../spdx/library/model/core/ElementTest.java | 9 +- .../model/core/ExternalIdentifierTest.java | 21 ++- .../library/model/core/ExternalMapTest.java | 9 +- .../model/core/ExternalReferenceTest.java | 21 ++- .../org/spdx/library/model/core/HashTest.java | 12 +- .../model/core/IntegrityMethodTest.java | 5 +- .../core/LifecycleScopedRelationshipTest.java | 12 +- .../library/model/core/NamespaceMapTest.java | 1 + .../library/model/core/OrganizationTest.java | 1 + .../spdx/library/model/core/PayloadTest.java | 5 +- .../spdx/library/model/core/PersonTest.java | 1 + .../model/core/PositiveIntegerRangeTest.java | 1 + .../library/model/core/RelationshipTest.java | 31 +-- .../library/model/core/SoftwareAgentTest.java | 1 + .../library/model/core/SpdxDocumentTest.java | 1 + .../org/spdx/library/model/core/ToolTest.java | 1 + .../library/model/dataset/DatasetTest.java | 66 ++++--- .../ConjunctiveLicenseSetTest.java | 1 + .../DisjunctiveLicenseSetTest.java | 1 + .../ExtendableLicenseTest.java | 1 + .../model/licensing/AnyLicenseInfoTest.java | 1 + .../licensing/CustomLicenseAdditionTest.java | 1 + .../model/licensing/CustomLicenseTest.java | 1 + .../model/licensing/LicenseAdditionTest.java | 9 +- .../licensing/LicenseExpressionTest.java | 1 + .../library/model/licensing/LicenseTest.java | 21 ++- .../licensing/ListedLicenseExceptionTest.java | 1 + .../model/licensing/ListedLicenseTest.java | 1 + .../model/licensing/OrLaterOperatorTest.java | 1 + .../licensing/WithAdditionOperatorTest.java | 1 + .../CvssV2VulnAssessmentRelationshipTest.java | 1 + .../CvssV3VulnAssessmentRelationshipTest.java | 1 + .../EpssVulnAssessmentRelationshipTest.java | 1 + ...CatalogVulnAssessmentRelationshipTest.java | 12 +- .../SsvcVulnAssessmentRelationshipTest.java | 12 +- ...ffectedVulnAssessmentRelationshipTest.java | 6 +- ...exFixedVulnAssessmentRelationshipTest.java | 1 + ...ffectedVulnAssessmentRelationshipTest.java | 20 +- ...igationVulnAssessmentRelationshipTest.java | 1 + .../VexVulnAssessmentRelationshipTest.java | 9 +- .../VulnAssessmentRelationshipTest.java | 9 +- .../model/security/VulnerabilityTest.java | 1 + .../spdx/library/model/software/SbomTest.java | 17 +- .../library/model/software/SnippetTest.java | 9 +- .../model/software/SoftwareArtifactTest.java | 48 ++--- .../SoftwareDependencyRelationshipTest.java | 23 ++- .../library/model/software/SpdxFileTest.java | 5 +- .../model/software/SpdxPackageTest.java | 21 ++- .../utility/compare/SpdxComparerTest.java | 8 +- .../utility/compare/SpdxFileComparerTest.java | 4 +- .../utility/compare/SpdxItemComparerTest.java | 4 +- .../compare/SpdxPackageComparerTest.java | 10 +- .../compare/SpdxSnippetComparerTest.java | 6 +- .../VerificationCodeGeneratorTest.java | 4 +- 158 files changed, 988 insertions(+), 470 deletions(-) create mode 100644 generated/src/main/java/org/spdx/library/SpdxEnumFactory.java create mode 100644 generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java create mode 100644 src/main/java/org/spdx/library/model/ExternalElement.java rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/AnnotationType.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/ChecksumAlgorithm.java (97%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/FileType.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/Purpose.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/ReferenceCategory.java (96%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/RelationshipType.java (98%) rename src/main/java/org/spdx/library/model/{enumerations/SpdxEnumFactory.java => compat/v2/enumerations/SpdxEnumFactoryCompatV2.java} (93%) rename src/main/java/org/spdx/library/model/{ => compat/v2}/enumerations/package-info.java (90%) diff --git a/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java b/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java new file mode 100644 index 000000000..7a8f0bbed --- /dev/null +++ b/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.spdx.library.model.ai.PresenceType; +import org.spdx.library.model.ai.SafetyRiskAssessmentType; +import org.spdx.library.model.core.AnnotationType; +import org.spdx.library.model.core.ExternalIdentifierType; +import org.spdx.library.model.core.ExternalReferenceType; +import org.spdx.library.model.core.HashAlgorithm; +import org.spdx.library.model.core.LifecycleScopeType; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.core.RelationshipCompleteness; +import org.spdx.library.model.core.RelationshipType; +import org.spdx.library.model.dataset.ConfidentialityLevelType; +import org.spdx.library.model.dataset.DatasetAvailabilityType; +import org.spdx.library.model.dataset.DatasetType; +import org.spdx.library.model.security.ExploitCatalogType; +import org.spdx.library.model.security.SsvcDecisionType; +import org.spdx.library.model.security.VexJustificationType; +import org.spdx.library.model.software.DependencyConditionalityType; +import org.spdx.library.model.software.SBOMType; +import org.spdx.library.model.software.SoftwareDependencyLinkType; +import org.spdx.library.model.software.SoftwarePurpose; + +/** + * *** DO NOT EDIT *** + * This class is generated by the Model to Java utility + * + * This is a static class used to translate a URI into a Java enum class + * It is a static class with a single public static field uriToEnum which maps the URI to the enum class + */ +public class SpdxEnumFactory { + /** + * Map of enum URI's to their Enum values + */ + public static Map> uriToEnum; + + static { + Map> map = new HashMap<>(); + + for (SoftwarePurpose enumVal:SoftwarePurpose.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (LifecycleScopeType enumVal:LifecycleScopeType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (VexJustificationType enumVal:VexJustificationType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (SoftwareDependencyLinkType enumVal:SoftwareDependencyLinkType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (ConfidentialityLevelType enumVal:ConfidentialityLevelType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (HashAlgorithm enumVal:HashAlgorithm.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (ExternalReferenceType enumVal:ExternalReferenceType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (DatasetType enumVal:DatasetType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (DatasetAvailabilityType enumVal:DatasetAvailabilityType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (SBOMType enumVal:SBOMType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (RelationshipCompleteness enumVal:RelationshipCompleteness.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (ProfileIdentifierType enumVal:ProfileIdentifierType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (SsvcDecisionType enumVal:SsvcDecisionType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (AnnotationType enumVal:AnnotationType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (SafetyRiskAssessmentType enumVal:SafetyRiskAssessmentType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (DependencyConditionalityType enumVal:DependencyConditionalityType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (ExternalIdentifierType enumVal:ExternalIdentifierType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (ExploitCatalogType enumVal:ExploitCatalogType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (PresenceType enumVal:PresenceType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + + for (RelationshipType enumVal:RelationshipType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + uriToEnum = Collections.unmodifiableMap(map); + } + + private SpdxEnumFactory() { + // this is only a static class + } +} diff --git a/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java b/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java new file mode 100644 index 000000000..af57c946c --- /dev/null +++ b/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.spdx.library.model.core.Element; + + +/** + * *** DO NOT EDIT *** + * This class is generated by the Model to Java utility + * + * This is a static class used to translate a URI into a Java individual class + * It is a static class with a single public static field uriToIndividual which maps the URI to the individual class + */ +public class SpdxIndividualFactory { + /** + * Map of individual URI's to their individual values + */ + public static Map uriToIndividual; + + static { + Map map = new HashMap<>(); + uriToIndividual = Collections.unmodifiableMap(map); + } + + private SpdxIndividualFactory() { + // this is only a static class + } +} diff --git a/generated/src/main/java/org/spdx/library/model/build/Build.java b/generated/src/main/java/org/spdx/library/model/build/Build.java index 5509bc21a..da6cbeac5 100644 --- a/generated/src/main/java/org/spdx/library/model/build/Build.java +++ b/generated/src/main/java/org/spdx/library/model/build/Build.java @@ -238,7 +238,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String buildType = getBuildType(); - if (Objects.isNull(buildType)) { + if (Objects.isNull(buildType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.BUILD }))) { retval.add("Missing buildType in Build"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/Agent.java b/generated/src/main/java/org/spdx/library/model/core/Agent.java index 21f442f90..c56abcb74 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Agent.java +++ b/generated/src/main/java/org/spdx/library/model/core/Agent.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/Annotation.java b/generated/src/main/java/org/spdx/library/model/core/Annotation.java index cb9102487..9b5c2f62d 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Annotation.java +++ b/generated/src/main/java/org/spdx/library/model/core/Annotation.java @@ -180,17 +180,16 @@ protected List _verify(Set verifiedIds, String specVersion, List subject = getSubject(); if (Objects.nonNull(subject)) { retval.addAll(subject.verify(verifiedIds, specVersion, profiles)); - } else { - if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing subject in subject"); - } } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting subject for Annotation: "+e.getMessage()); } try { AnnotationType annotationType = getAnnotationType(); - if (Objects.isNull(annotationType)) { + if (Objects.isNull(annotationType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing annotationType in Annotation"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java index 4e6fb932f..6e580846c 100644 --- a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java +++ b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/Bom.java b/generated/src/main/java/org/spdx/library/model/core/Bom.java index c9a0a0dad..52ffdf895 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Bom.java +++ b/generated/src/main/java/org/spdx/library/model/core/Bom.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java index 344d16143..6f5722e06 100644 --- a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java +++ b/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java @@ -150,7 +150,8 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); try { String key = getKey(); - if (Objects.isNull(key)) { + if (Objects.isNull(key) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing key in DictionaryEntry"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java index 7b28b9b5a..f3b6db022 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java @@ -203,7 +203,8 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); try { ExternalIdentifierType externalIdentifierType = getExternalIdentifierType(); - if (Objects.isNull(externalIdentifierType)) { + if (Objects.isNull(externalIdentifierType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing externalIdentifierType in ExternalIdentifier"); } } catch (InvalidSPDXAnalysisException e) { @@ -217,7 +218,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String identifier = getIdentifier(); - if (Objects.isNull(identifier)) { + if (Objects.isNull(identifier) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing identifier in ExternalIdentifier"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java index 9344396aa..6c687e16d 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java +++ b/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java @@ -188,7 +188,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String externalId = getExternalId(); - if (Objects.isNull(externalId)) { + if (Objects.isNull(externalId) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing externalId in ExternalMap"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/Hash.java b/generated/src/main/java/org/spdx/library/model/core/Hash.java index 5d0aaced7..cdca98f22 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Hash.java +++ b/generated/src/main/java/org/spdx/library/model/core/Hash.java @@ -162,7 +162,8 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { HashAlgorithm algorithm = getAlgorithm(); - if (Objects.isNull(algorithm)) { + if (Objects.isNull(algorithm) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing algorithm in Hash"); } } catch (InvalidSPDXAnalysisException e) { @@ -170,7 +171,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String hashValue = getHashValue(); - if (Objects.isNull(hashValue)) { + if (Objects.isNull(hashValue) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing hashValue in Hash"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java index 18eb0a064..049c48c2a 100644 --- a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java +++ b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java @@ -153,7 +153,8 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); try { String prefix = getPrefix(); - if (Objects.isNull(prefix)) { + if (Objects.isNull(prefix) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing prefix in NamespaceMap"); } } catch (InvalidSPDXAnalysisException e) { @@ -161,7 +162,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String namespace = getNamespace(); - if (Objects.isNull(namespace)) { + if (Objects.isNull(namespace) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing namespace in NamespaceMap"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/Organization.java b/generated/src/main/java/org/spdx/library/model/core/Organization.java index 1c70a7146..bd80bd456 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Organization.java +++ b/generated/src/main/java/org/spdx/library/model/core/Organization.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/Person.java b/generated/src/main/java/org/spdx/library/model/core/Person.java index c9981b423..888a08ec1 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Person.java +++ b/generated/src/main/java/org/spdx/library/model/core/Person.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java index c90c3ce97..fb201c64b 100644 --- a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java +++ b/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java @@ -160,7 +160,8 @@ protected List _verify(Set verifiedIds, String specVersion, List List retval = new ArrayList<>(); try { Integer end = getEnd(); - if (Objects.isNull(end)) { + if (Objects.isNull(end) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing end in PositiveIntegerRange"); } if (Objects.nonNull(end) && end < 1) { @@ -171,7 +172,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { Integer begin = getBegin(); - if (Objects.isNull(begin)) { + if (Objects.isNull(begin) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing begin in PositiveIntegerRange"); } if (Objects.nonNull(begin) && begin < 1) { diff --git a/generated/src/main/java/org/spdx/library/model/core/Relationship.java b/generated/src/main/java/org/spdx/library/model/core/Relationship.java index 0074092dc..78873e66d 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Relationship.java +++ b/generated/src/main/java/org/spdx/library/model/core/Relationship.java @@ -234,17 +234,16 @@ protected List _verify(Set verifiedIds, String specVersion, List from = getFrom(); if (Objects.nonNull(from)) { retval.addAll(from.verify(verifiedIds, specVersion, profiles)); - } else { - if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing from in from"); - } } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting from for Relationship: "+e.getMessage()); } try { RelationshipType relationshipType = getRelationshipType(); - if (Objects.isNull(relationshipType)) { + if (Objects.isNull(relationshipType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing relationshipType in Relationship"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java b/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java index eb06e86ac..ca5f6bb00 100644 --- a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java +++ b/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java b/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java index 907fe7e67..0b7fb421a 100644 --- a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java +++ b/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/core/Tool.java b/generated/src/main/java/org/spdx/library/model/core/Tool.java index 71167271e..77a09229d 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Tool.java +++ b/generated/src/main/java/org/spdx/library/model/core/Tool.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java index 227616656..5b029bb5f 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java index b677ec9fc..5d4083dcd 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java b/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java index cb7b1691b..b5166515a 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java +++ b/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.licensing.AnyLicenseInfo; diff --git a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java b/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java index ef39f21c1..9d8cb7451 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java index d81bfb02b..1ff015f47 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java index 649db1728..69081fd0b 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/License.java b/generated/src/main/java/org/spdx/library/model/licensing/License.java index 49aa16ff7..685e07645 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/License.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/License.java @@ -252,7 +252,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String licenseText = getLicenseText(); - if (Objects.isNull(licenseText)) { + if (Objects.isNull(licenseText) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { retval.add("Missing licenseText in License"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java index 900da360b..26c11d5c1 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java @@ -184,7 +184,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String additionText = getAdditionText(); - if (Objects.isNull(additionText)) { + if (Objects.isNull(additionText) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { retval.add("Missing additionText in LicenseAddition"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java index 1b493454b..83966cd6f 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java @@ -146,7 +146,8 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { String licenseExpression = getLicenseExpression(); - if (Objects.isNull(licenseExpression)) { + if (Objects.isNull(licenseExpression) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { retval.add("Missing licenseExpression in LicenseExpression"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java index cd4c85022..45165e5e1 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java index 6712a4876..2aed94300 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java b/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java index dd4c3608e..5384e2350 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.expandedlicense.ExtendableLicense; diff --git a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java b/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java index 319afb92b..95ba3ff09 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java +++ b/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java index 175d74e08..2fb4bb9d4 100644 --- a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java index 5b7093acb..ccae6a41d 100644 --- a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java index e470aac13..a1b2baa56 100644 --- a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java @@ -140,7 +140,8 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { Integer probability = getProbability(); - if (Objects.isNull(probability)) { + if (Objects.isNull(probability) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { retval.add("Missing probability in EpssVulnAssessmentRelationship"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java index 30ab3ba45..787be6687 100644 --- a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java @@ -191,7 +191,8 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { ExploitCatalogType catalogType = getCatalogType(); - if (Objects.isNull(catalogType)) { + if (Objects.isNull(catalogType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { retval.add("Missing catalogType in ExploitCatalogVulnAssessmentRelationship"); } } catch (InvalidSPDXAnalysisException e) { @@ -199,7 +200,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { Boolean exploited = getExploited(); - if (Objects.isNull(exploited)) { + if (Objects.isNull(exploited) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { retval.add("Missing exploited in ExploitCatalogVulnAssessmentRelationship"); } } catch (InvalidSPDXAnalysisException e) { @@ -207,7 +209,8 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { String locator = getLocator(); - if (Objects.isNull(locator)) { + if (Objects.isNull(locator) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { retval.add("Missing locator in ExploitCatalogVulnAssessmentRelationship"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java index 9c14d00ec..54aedeb7d 100644 --- a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java @@ -147,7 +147,8 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { SsvcDecisionType decisionType = getDecisionType(); - if (Objects.isNull(decisionType)) { + if (Objects.isNull(decisionType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { retval.add("Missing decisionType in SsvcVulnAssessmentRelationship"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java index f2d807848..bd36318e4 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java index 1c6a24360..f7dd84e98 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** diff --git a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java b/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java index 8ee3c8fe4..2993c9d46 100644 --- a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java +++ b/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java @@ -32,8 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Optional; -import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; diff --git a/src/main/java/org/spdx/library/SimpleUriValue.java b/src/main/java/org/spdx/library/SimpleUriValue.java index cb4a97654..d168db003 100644 --- a/src/main/java/org/spdx/library/SimpleUriValue.java +++ b/src/main/java/org/spdx/library/SimpleUriValue.java @@ -17,6 +17,8 @@ */ package org.spdx.library; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import javax.annotation.Nullable; @@ -24,6 +26,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.ExternalElement; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; +import org.spdx.library.model.core.ExternalMap; import org.spdx.storage.IModelStore; /** @@ -80,14 +85,17 @@ public String getIndividualURI() { } /** - * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if it matches the pattern of an external SPDX element - * or returns itself otherwise - * @param store + * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if the uri is found in the + * externalMap or if it matches the pattern of a V2 compatible external SPDX element, an Individual object, or returns itself otherwise + * @param store store to use for the inflated object * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param defaultNamespace optional document namespace when creating V2 compatible external document references + * @param externalMap map of URI's to ExternalMaps for any external elements * @return Enum, ExternalSpdxElement or itself depending on the pattern - * @throws InvalidSPDXAnalysisException + * @throws InvalidSPDXAnalysisException on any store or parsing error */ - public Object toModelObject(IModelStore store, ModelCopyManager copyManager, @Nullable String defaultNamespace) throws InvalidSPDXAnalysisException { + public Object toModelObject(IModelStore store, ModelCopyManager copyManager, @Nullable String defaultNamespace, + @Nullable Map externalMap) throws InvalidSPDXAnalysisException { if (store.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) < 0) { if (Objects.isNull(defaultNamespace)) { logger.error("Default namespace can not be null for SPDX 2 model stores"); @@ -95,12 +103,44 @@ public Object toModelObject(IModelStore store, ModelCopyManager copyManager, @Nu } return toModelObjectV2Compat(store, defaultNamespace, copyManager); } else { - throw new InvalidSPDXAnalysisException("Not implemented"); + return toModelObject(store, copyManager, Objects.isNull(externalMap) ? new HashMap<>() : externalMap); } } + /** + * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if the uri is found in the + * externalMap, an Individual object, or returns itself otherwise + * @param store store to use for the inflated object + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param externalMap map of URI's to ExternalMaps for any external elements + * @return Enum, ExternalSpdxElement, individual or itself depending on the pattern + * @throws InvalidSPDXAnalysisException on any store or parsing error + */ + private Object toModelObject(IModelStore store, ModelCopyManager copyManager, Map externalMap) throws InvalidSPDXAnalysisException { + Object retval = SpdxEnumFactory.uriToEnum.get(uri); + if (Objects.nonNull(retval)) { + return retval; + } else if (externalMap.containsKey(uri)) { + return new ExternalElement(store, uri, copyManager, externalMap.get(uri)); + } else if (SpdxIndividualFactory.uriToIndividual.containsKey(uri)) { + return SpdxIndividualFactory.uriToIndividual.get(uri); + } else { + logger.warn("URI "+uri+" does not match any model object or enumeration"); + return this; + } + } + + /** + * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if it matches the pattern of an external SPDX element + * or returns itself otherwise + * @param store store to store the inflated object + * @param documentUri document URI to use if creating an external document reference + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @return Enum, ExternalSpdxElement or itself depending on the pattern + * @throws InvalidSPDXAnalysisException on any store or parsing error + */ private Object toModelObjectV2Compat(IModelStore store, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Object retval = org.spdx.library.model.enumerations.SpdxEnumFactory.uriToEnum.get(uri); + Object retval = SpdxEnumFactoryCompatV2.uriToEnum.get(uri); if (Objects.nonNull(retval)) { return retval; } else if (SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri).matches()) { diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index 5526a14d2..b2045d187 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -96,13 +96,13 @@ public class SpdxModelFactory { typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, org.spdx.library.model.compat.v2.pointer.CompoundPointer.class); typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, org.spdx.library.model.compat.v2.pointer.SinglePointer.class); typeToClassV2.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, org.spdx.library.model.compat.v2.license.CrossRef.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.enumerations.FileType.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.enumerations.AnnotationType.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.enumerations.ChecksumAlgorithm.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.enumerations.ReferenceCategory.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.enumerations.RelationshipType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.compat.v2.enumerations.FileType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.compat.v2.enumerations.AnnotationType.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.compat.v2.enumerations.ReferenceCategory.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.compat.v2.enumerations.RelationshipType.class); typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.enumerations.Purpose.class); + typeToClassV2.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.compat.v2.enumerations.Purpose.class); SPDX_TYPE_TO_CLASS_V2 = Collections.unmodifiableMap(typeToClassV2); Map> typeToClassV3 = new HashMap<>(); //TODO Add V3 class strings diff --git a/src/main/java/org/spdx/library/SpdxVerificationHelper.java b/src/main/java/org/spdx/library/SpdxVerificationHelper.java index fd763b9f2..1e68206a7 100644 --- a/src/main/java/org/spdx/library/SpdxVerificationHelper.java +++ b/src/main/java/org/spdx/library/SpdxVerificationHelper.java @@ -27,7 +27,7 @@ import java.util.Set; import java.util.regex.Pattern; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; /** * Holds static methods used for verify various property values diff --git a/src/main/java/org/spdx/library/model/ExternalElement.java b/src/main/java/org/spdx/library/model/ExternalElement.java new file mode 100644 index 000000000..7a8c7eb98 --- /dev/null +++ b/src/main/java/org/spdx/library/model/ExternalElement.java @@ -0,0 +1,176 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.spdx.library.IndividualUriValue; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.core.CreationInfo; +import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ExternalIdentifier; +import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.core.ExternalReference; +import org.spdx.library.model.core.NamespaceMap; +import org.spdx.library.model.core.Payload; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.storage.IModelStore; + +/** + * This class represents an SPDX element which is not present in the model store + * + * The external property provides optional information on where the external element may be located and verified + * + * @author Gary O'Neall + * + */ +public class ExternalElement extends Element implements IndividualUriValue { + + ExternalMap external; + + /** + * @param store store to use for the inflated object + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param objectUri URI or anonymous ID for the Element + * @param external Information about the external map + * @throws InvalidSPDXAnalysisException + */ + public ExternalElement(IModelStore store, String objectUri, ModelCopyManager copyManager, + ExternalMap external) throws InvalidSPDXAnalysisException { + super(store, objectUri, copyManager, true); + this.external = external; + } + + /* (non-Javadoc) + * @see org.spdx.library.IndividualUriValue#getIndividualURI() + */ + @Override + public String getIndividualURI() { + return getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.ExternalElement"; + } + + // Getters and Setters + + @Override + public Collection getNamespacess() { + throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); + } + /** + * @return the externalMap + */ + public ExternalMap getExternal() { + return this.external; + } + + @Override + public Collection getImportss() { + throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); + } + + + /** + * @return the creationInfo + */ + @Override + public Optional getCreationInfo() throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); + } + + /** + * @param creationInfo the creationInfo to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + @Override + public Payload setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); + } + + @Override + public Collection getExternalReferences() { + throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); + } + @Override + public Collection getExternalIdentifiers() { + throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); + } + + + /** + * @return the description + */ + public Optional getDescription() throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); + } + /** + * @param description the description to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + @Override + public Element setDescription(@Nullable String description) throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); + } + + /** + * @return the summary + */ + @Override + public Optional getSummary() throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); + } + /** + * @param summary the summary to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + @Override + public Element setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException { + throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); + } + + + @Override + public String toString() { + return "External Element: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + protected List _verify(Set verifiedIds, String specVersion, List profiles) { + return new ArrayList<>(); + } + +} diff --git a/src/main/java/org/spdx/library/model/ModelCollection.java b/src/main/java/org/spdx/library/model/ModelCollection.java index dce5cdc02..440acfc69 100644 --- a/src/main/java/org/spdx/library/model/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/ModelCollection.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Spliterator; import java.util.Spliterators; @@ -36,6 +37,7 @@ import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxObjectNotInStoreException; +import org.spdx.library.model.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -51,6 +53,10 @@ public class ModelCollection implements Collection { private String objectUri; private PropertyDescriptor propertyDescriptor; private ModelCopyManager copyManager; + /** + * Map of URI's of elements referenced but not present in the store + */ + protected Map externalMap; private Class type; // private boolean licensePrimitiveAssignable; // If true, NONE and NOASSERTION should be converted to NoneLicense and NoAssertionLicense @@ -80,11 +86,12 @@ public Object next() { * @param propertyDescriptor descriptor for the property use for the model collections * @param copyManager if non-null, use this to copy properties when referenced outside this model store * @param type The class of the elements to be stored in the collection if none, null if not known - * @throws InvalidSPDXAnalysisException + * @param externalMap Map of URI's of elements referenced but not present in the store + * @throws InvalidSPDXAnalysisException on parsing or store errors */ public ModelCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, @Nullable ModelCopyManager copyManager, - @Nullable Class type) throws InvalidSPDXAnalysisException { + @Nullable Class type, Map externalMap) throws InvalidSPDXAnalysisException { Objects.requireNonNull(modelStore, "Model store can not be null"); this.modelStore = modelStore; Objects.requireNonNull(objectUri, "Object URI or anonymous ID can not be null"); @@ -142,7 +149,7 @@ public boolean contains(Object o) { private Object checkConvertTypedValue(Object value) { try { - Object retval = ModelObjectHelper.storedObjectToModelObject(value, modelStore, copyManager); + Object retval = ModelObjectHelper.storedObjectToModelObject(value, modelStore, copyManager, externalMap); // if (licensePrimitiveAssignable && retval instanceof IndividualUriValue) { // String uri = ((IndividualUriValue)retval).getIndividualURI(); // if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 66d943e79..251b8c9a2 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -19,8 +19,10 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -44,10 +46,11 @@ import org.spdx.library.NotEquivalentReason.NotEquivalent; import org.spdx.library.SpdxConstants; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; import org.spdx.library.model.core.CreationInfo; import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ExternalMap; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.library.model.licensing.AnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -108,6 +111,11 @@ public abstract class ModelObject { NotEquivalentReason lastNotEquivalentReason = null; + /** + * Map of URI's of elements referenced but not present in the store + */ + protected Map externalMap = new HashMap<>(); + /** * Create a new Model Object using an Anonymous ID with the defualt store and default document URI * @throws InvalidSPDXAnalysisException @@ -177,6 +185,7 @@ public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopy public ModelObject(ModelObjectBuilder builder) throws InvalidSPDXAnalysisException { this(builder.modelStore, builder.objectUri, builder.copyManager, true); this.strict = builder.strict; + this.externalMap = builder.externalMap; } // Abstract methods that must be implemented in the subclasses @@ -299,6 +308,20 @@ public void setStrict(boolean strict) { this.strict = strict; } + /** + * @return the externalMap + */ + public Map getExternalMap() { + return externalMap; + } + + /** + * @param externalMap the externalMap to set + */ + public void setExternalMap(Map externalMap) { + this.externalMap = externalMap; + } + //The following methods are to manage the properties associated with the model object /** * @return all names of property descriptors currently associated with this object @@ -314,7 +337,7 @@ public List getPropertyValueDescriptors() throws InvalidSPDX * @return value associated with a property */ protected Optional getObjectPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional retval = ModelObjectHelper.getObjectPropertyValue(modelStore, objectUri, propertyDescriptor, copyManager); + Optional retval = ModelObjectHelper.getObjectPropertyValue(modelStore, objectUri, propertyDescriptor, copyManager, externalMap); if (retval.isPresent() && retval.get() instanceof ModelObject && !strict) { ((ModelObject)retval.get()).setStrict(strict); } @@ -401,7 +424,7 @@ protected Optional> getEnumPropertyValue(PropertyDescriptor propertyDesc if (!(result.get() instanceof IndividualUriValue)) { throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Individual Value or enum"); } - Enum retval = SpdxEnumFactory.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); + Enum retval = SpdxEnumFactoryCompatV2.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); if (Objects.isNull(retval)) { logger.error("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); throw new InvalidSPDXAnalysisException("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); @@ -452,7 +475,7 @@ protected Optional getAnyLicenseInfoPropertyValue(PropertyDescri } else if (result.get() instanceof AnyLicenseInfo) { return (Optional)(Optional)result; } else if (result.get() instanceof SimpleUriValue) { - Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null); + Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null, externalMap); if (val instanceof AnyLicenseInfo) { return Optional.of((AnyLicenseInfo)val); } else { @@ -479,7 +502,7 @@ protected Optional getElementPropertyValue(PropertyDescriptor propertyD } else if (result.get() instanceof Element) { return (Optional)(Optional)result; } else if (result.get() instanceof SimpleUriValue) { - Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null); + Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null, externalMap); if (val instanceof Element) { return Optional.of((Element)val); } else { @@ -582,7 +605,7 @@ protected ModelUpdate updateRemovePropertyValueFromCollection(PropertyDescriptor * @return Set of values associated with a property */ protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelSet(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type); + return new ModelSet(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type, externalMap); } /** @@ -590,7 +613,7 @@ protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescr * @return Collection of values associated with a property */ protected ModelCollection getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelCollection(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type); + return new ModelCollection(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type, externalMap); } /** @@ -967,6 +990,7 @@ public static class ModelObjectBuilder { public String objectUri; public ModelCopyManager copyManager; public boolean strict = true; + public Map externalMap = new HashMap<>(); public ModelObjectBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { this.modelStore = modelStore; @@ -977,5 +1001,9 @@ public ModelObjectBuilder(IModelStore modelStore, String objectUri, @Nullable Mo public void setStrict(boolean strict) { this.strict = strict; } + + public void setExternalMap(Map externalMap) { + this.externalMap = externalMap; + } } } diff --git a/src/main/java/org/spdx/library/model/ModelObjectHelper.java b/src/main/java/org/spdx/library/model/ModelObjectHelper.java index 2f647efb5..491e95ec1 100644 --- a/src/main/java/org/spdx/library/model/ModelObjectHelper.java +++ b/src/main/java/org/spdx/library/model/ModelObjectHelper.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -34,6 +35,7 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxObjectNotInStoreException; import org.spdx.library.TypedValue; +import org.spdx.library.model.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; @@ -56,21 +58,23 @@ private ModelObjectHelper() { * @param objectUri the Object URI or anonymous ID * @param propertyDescriptor property descriptor for the property * @param copyManager if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available + * @param externalMap map of URI's to ExternalMaps for any external elements * @return value associated with a property * @throws InvalidSPDXAnalysisException */ public static Optional getObjectPropertyValue(IModelStore modelStore, String objectUri, - PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager, + @Nullable Map externalMap) throws InvalidSPDXAnalysisException { IModelStoreLock lock = modelStore.enterCriticalSection(false); // NOTE: we use a write lock since the ModelStorageClassConverter may end up creating objects in the store try { if (!modelStore.exists(objectUri)) { return Optional.empty(); } else if (modelStore.isCollectionProperty(objectUri, propertyDescriptor)) { - return Optional.of(new ModelCollection<>(modelStore, objectUri, propertyDescriptor, copyManager, null)); + return Optional.of(new ModelCollection<>(modelStore, objectUri, propertyDescriptor, copyManager, null, externalMap)); } else { return optionalStoredObjectToModelObject(modelStore.getValue(objectUri, - propertyDescriptor), modelStore, copyManager); + propertyDescriptor), modelStore, copyManager, externalMap); } } finally { lock.unlock(); @@ -181,14 +185,16 @@ protected static void removePropertyValueFromCollection(IModelStore modelStore, * @param modelStore ModelStore to use in fetching or creating * @param copyManager if not null, copy any referenced ID's outside of this * document/model store + * @param externalMap map of URI's to ExternalMaps for any external elements * @return the object itself unless it is a TypedValue, in which case a * ModelObject is returned * @throws InvalidSPDXAnalysisException */ public static Optional optionalStoredObjectToModelObject(Optional value, - IModelStore modelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + IModelStore modelStore, ModelCopyManager copyManager, @Nullable Map externalMap) throws InvalidSPDXAnalysisException { if (value.isPresent() && value.get() instanceof IndividualUriValue) { - return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(modelStore, copyManager, null)); + return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(modelStore, copyManager, + null, externalMap)); } else if (value.isPresent() && value.get() instanceof TypedValue) { TypedValue tv = (TypedValue)value.get(); return Optional.of(SpdxModelFactory.createModelObject(modelStore, @@ -238,15 +244,16 @@ public static Object modelObjectToStoredObject(Object value, IModelStore modelSt * @param modelStore ModelStore to use in fetching or creating * @param copyManager if not null, copy any referenced ID's outside of this * document/model store + * @param externalMap map of URI's to ExternalMaps for any external elements * @return the object itself unless it is a TypedValue, in which case a * ModelObject is returned * @throws InvalidSPDXAnalysisException */ public static Object storedObjectToModelObject(Object value, IModelStore modelStore, - ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ModelCopyManager copyManager, @Nullable Map externalMap) throws InvalidSPDXAnalysisException { if (value instanceof IndividualUriValue) { // Note: this must be before the check for TypedValue SimpleUriValue suv = new SimpleUriValue((IndividualUriValue)value); - return suv.toModelObject(modelStore, copyManager, null); + return suv.toModelObject(modelStore, copyManager, null, externalMap); } else if (value instanceof TypedValue) { TypedValue tv = (TypedValue)value; return SpdxModelFactory.getModelObject(modelStore, tv.getObjectUri(), tv.getType(), copyManager, true); diff --git a/src/main/java/org/spdx/library/model/ModelSet.java b/src/main/java/org/spdx/library/model/ModelSet.java index 05438cd18..75f16d733 100644 --- a/src/main/java/org/spdx/library/model/ModelSet.java +++ b/src/main/java/org/spdx/library/model/ModelSet.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.Iterator; +import java.util.Map; import javax.annotation.Nullable; @@ -26,6 +27,7 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.PropertyDescriptor; @@ -42,16 +44,18 @@ public class ModelSet extends ModelCollection { static final Logger logger = LoggerFactory.getLogger(ModelSet.class); /** - * @param modelStore - * @param objectUri - * @param propertyDescriptor - * @param copyManager - * @param type - * @throws InvalidSPDXAnalysisException + * @param modelStore Storage for the model collection + * @param objectUri Object URI or anonymous ID + * @param propertyDescriptor descriptor for the property use for the model collections + * @param copyManager if non-null, use this to copy properties when referenced outside this model store + * @param type The class of the elements to be stored in the collection if none, null if not known + * @param externalMap Map of URI's of elements referenced but not present in the store + * @throws InvalidSPDXAnalysisException on parsing or store errors */ public ModelSet(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, - @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, propertyDescriptor, copyManager, type); + @Nullable ModelCopyManager copyManager, @Nullable Class type, + Map externalMap) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, propertyDescriptor, copyManager, type, externalMap); } @Override diff --git a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java index 0fe5419c9..2b0aa737f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java @@ -29,7 +29,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java index 7b1006fc0..e033bc270 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java @@ -31,7 +31,7 @@ import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java index f4ea0fa98..25dd03cc1 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java @@ -36,7 +36,7 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java index b6fb7a117..354dcccc9 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java @@ -30,7 +30,7 @@ import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java index 879cdfbdb..74c2f6d2c 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java @@ -45,6 +45,11 @@ import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.TypedValue; import org.spdx.library.Version; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -57,11 +62,6 @@ import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.SinglePointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.model.enumerations.RelationshipType; -import org.spdx.library.model.enumerations.SpdxEnumFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -474,7 +474,7 @@ protected Optional> getEnumPropertyValue(PropertyDescriptor propertyDesc if (!(result.get() instanceof IndividualUriValue)) { throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Individual Value or enum"); } - Enum retval = SpdxEnumFactory.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); + Enum retval = SpdxEnumFactoryCompatV2.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); if (Objects.isNull(retval)) { logger.error("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); throw new InvalidSPDXAnalysisException("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java index e22cd88d6..a1b13e5c7 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java @@ -71,7 +71,7 @@ public static Object storedObjectToModelObject(Object value, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (value instanceof IndividualUriValue) { // Note: this must be before the check for TypedValue SimpleUriValue suv = new SimpleUriValue((IndividualUriValue)value); - return suv.toModelObject(modelStore, null, documentUri); + return suv.toModelObject(modelStore, null, documentUri, null); } else if (value instanceof TypedValue) { TypedValue tv = (TypedValue)value; String id = tv.getObjectUri().startsWith(documentUri) ? tv.getObjectUri().substring(documentUri.length() + 1) : @@ -103,7 +103,8 @@ public static Object storedObjectToModelObject(Object value, String documentUri, public static Optional optionalStoredObjectToModelObject(Optional value, String stDocumentUri, IModelStore stModelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (value.isPresent() && value.get() instanceof IndividualUriValue) { - return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(stModelStore, copyManager, stDocumentUri)); + return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()) + .toModelObject(stModelStore, copyManager, stDocumentUri, null)); } else if (value.isPresent() && value.get() instanceof TypedValue) { TypedValue tv = (TypedValue)value.get(); return Optional.of(SpdxModelFactory.createModelObjectV2(stModelStore, stDocumentUri, diff --git a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java index 0c43f4f17..dd4419b1b 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java +++ b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java @@ -34,7 +34,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; diff --git a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java index bfc9bb05a..9e40dfaf4 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java +++ b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java @@ -27,7 +27,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.Version; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java index 9bf27bc9d..b6522c897 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java @@ -32,11 +32,11 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.Version; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java index 2a1c447d9..fdda006aa 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java @@ -32,9 +32,9 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java index 6372b2538..1e73523fa 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java @@ -32,15 +32,15 @@ import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxVerificationHelper; import org.spdx.library.Version; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.Purpose; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.OrLaterOperator; import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; import org.spdx.library.model.compat.v2.license.WithExceptionOperator; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.Purpose; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java index 066f70665..b7afc3f0f 100644 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java +++ b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java @@ -30,7 +30,7 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/model/enumerations/AnnotationType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java similarity index 96% rename from src/main/java/org/spdx/library/model/enumerations/AnnotationType.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java index 10815a26d..8786b163f 100644 --- a/src/main/java/org/spdx/library/model/enumerations/AnnotationType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java similarity index 97% rename from src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java index c444a7792..1d2482e0e 100644 --- a/src/main/java/org/spdx/library/model/enumerations/ChecksumAlgorithm.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/enumerations/FileType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java similarity index 96% rename from src/main/java/org/spdx/library/model/enumerations/FileType.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java index 772dbaeb3..e95f0406f 100644 --- a/src/main/java/org/spdx/library/model/enumerations/FileType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/enumerations/Purpose.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java similarity index 96% rename from src/main/java/org/spdx/library/model/enumerations/Purpose.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java index ca530a9f5..c193c1604 100644 --- a/src/main/java/org/spdx/library/model/enumerations/Purpose.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java similarity index 96% rename from src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java index a74c0d4c9..f787f53ba 100644 --- a/src/main/java/org/spdx/library/model/enumerations/ReferenceCategory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/enumerations/RelationshipType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java similarity index 98% rename from src/main/java/org/spdx/library/model/enumerations/RelationshipType.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java index 6a9cf4185..762f32fd8 100644 --- a/src/main/java/org/spdx/library/model/enumerations/RelationshipType.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import org.spdx.library.IndividualUriValue; import org.spdx.library.SpdxConstantsCompatV2; diff --git a/src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java similarity index 93% rename from src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java index 31b654f90..0880efec2 100644 --- a/src/main/java/org/spdx/library/model/enumerations/SpdxEnumFactory.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library.model.enumerations; +package org.spdx.library.model.compat.v2.enumerations; import java.util.Collections; import java.util.HashMap; @@ -25,7 +25,7 @@ * @author gary * */ -public class SpdxEnumFactory { +public class SpdxEnumFactoryCompatV2 { /** * Map of enum URI's to their Enum values @@ -55,7 +55,7 @@ public class SpdxEnumFactory { uriToEnum = Collections.unmodifiableMap(map); } - private SpdxEnumFactory() { + private SpdxEnumFactoryCompatV2() { // this is only a static class } diff --git a/src/main/java/org/spdx/library/model/enumerations/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java similarity index 90% rename from src/main/java/org/spdx/library/model/enumerations/package-info.java rename to src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java index e0270e935..ab50116e2 100644 --- a/src/main/java/org/spdx/library/model/enumerations/package-info.java +++ b/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java @@ -20,8 +20,8 @@ * * For the enumerations to be stored properly, they must implement the IndividualUriValue interface. * - * The enumerations also must be added to the static map uriToEnum in the SpdxEnumFactory classes. + * The enumerations also must be added to the static map uriToEnum in the SpdxEnumFactoryCompatV2 classes. * * @author Gary O'Neall */ -package org.spdx.library.model.enumerations; \ No newline at end of file +package org.spdx.library.model.compat.v2.enumerations; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index 721eb5761..21345af7f 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -25,7 +25,7 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.TypedValue; import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.enumerations.SpdxEnumFactory; +import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -431,7 +431,7 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri if (!clazz.isAssignableFrom(value.getClass())) { if (value instanceof IndividualUriValue) { String uri = ((IndividualUriValue)value).getIndividualURI(); - Enum spdxEnum = SpdxEnumFactory.uriToEnum.get(uri); + Enum spdxEnum = SpdxEnumFactoryCompatV2.uriToEnum.get(uri); if (Objects.nonNull(spdxEnum)) { if (!clazz.isAssignableFrom(spdxEnum.getClass())) { return false; @@ -499,7 +499,7 @@ public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { return true; } - Enum spdxEnum = SpdxEnumFactory.uriToEnum.get(uri); + Enum spdxEnum = SpdxEnumFactoryCompatV2.uriToEnum.get(uri); if (Objects.nonNull(spdxEnum)) { return clazz.isAssignableFrom(spdxEnum.getClass()); } else { diff --git a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java index 76e88c471..a4bbc3286 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java @@ -23,7 +23,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.model.compat.v2.ExternalRef; import org.spdx.library.model.compat.v2.ReferenceType; -import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; /** * Contains information on differences between two different External Refs. diff --git a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java index dc1ae775f..7cf8e12b3 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java @@ -28,8 +28,8 @@ import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.Relationship; import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.enumerations.FileType; /** * Contains the results of a comparison between two SPDX files with the same name diff --git a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java b/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java index 805639e03..ff101ff7b 100644 --- a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java +++ b/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java @@ -22,7 +22,7 @@ import java.util.Date; import java.util.Objects; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/ModelCollectionTest.java index 00e80bff7..a7e171142 100644 --- a/src/test/java/org/spdx/library/model/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/ModelCollectionTest.java @@ -2,12 +2,15 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.core.Element; +import org.spdx.library.model.core.ExternalMap; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; @@ -16,6 +19,7 @@ public class ModelCollectionTest extends TestCase { static final PropertyDescriptor PROPERTY_NAME = new PropertyDescriptor("property", "namespace"); static final String[] ELEMENTS = new String[] {"e1", "e2", "e3", "e4"}; + static final Map EXTERNAL_MAP = new HashMap<>(); //TODO: Change this to a version 3 GMO Element gmo; @@ -31,7 +35,7 @@ protected void tearDown() throws Exception { } public void testSize() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), null); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), null, EXTERNAL_MAP); for (String element:ELEMENTS) { mc.add(element); } @@ -39,7 +43,7 @@ public void testSize() throws InvalidSPDXAnalysisException { } public void testIsEmpty() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); assertTrue(mc.isEmpty()); for (String element:ELEMENTS) { mc.add(element); @@ -48,7 +52,7 @@ public void testIsEmpty() throws InvalidSPDXAnalysisException { } public void testContains() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); for (String element:ELEMENTS) { mc.add(element); } @@ -59,7 +63,7 @@ public void testContains() throws InvalidSPDXAnalysisException { } public void testToImmutableList() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); for (String element:ELEMENTS) { mc.add(element); } @@ -71,7 +75,7 @@ public void testToImmutableList() throws InvalidSPDXAnalysisException { } public void testAdd() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); assertEquals(0, mc.size()); mc.add(ELEMENTS[0]); assertEquals(1, mc.size()); @@ -83,7 +87,7 @@ public void testAdd() throws InvalidSPDXAnalysisException { } public void testRemove() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); for (String element:ELEMENTS) { mc.add(element); } @@ -95,7 +99,7 @@ public void testRemove() throws InvalidSPDXAnalysisException { } public void testContainsAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); for (String element:ELEMENTS) { mc.add(element); } @@ -106,7 +110,7 @@ public void testContainsAll() throws InvalidSPDXAnalysisException { } public void testAddAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); List compare = new ArrayList(Arrays.asList(ELEMENTS)); mc.addAll(compare); @@ -117,7 +121,7 @@ public void testAddAll() throws InvalidSPDXAnalysisException { } public void testRemoveAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); List list1 = Arrays.asList(ELEMENTS); List list2 = new ArrayList(list1); String addedElement = "added"; @@ -129,7 +133,7 @@ public void testRemoveAll() throws InvalidSPDXAnalysisException { } public void testRetainAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); List list1 = Arrays.asList(ELEMENTS); List list2 = new ArrayList(list1); String addedElement = "added"; @@ -144,7 +148,7 @@ public void testRetainAll() throws InvalidSPDXAnalysisException { } public void testClear() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class); + ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); for (String element:ELEMENTS) { mc.add(element); } diff --git a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java index 1189502c2..388137ed4 100644 --- a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java +++ b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java @@ -17,13 +17,17 @@ */ package org.spdx.library.model; +import java.util.HashMap; +import java.util.Map; + import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.library.model.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -42,6 +46,7 @@ public class SimpleUriValueTest extends TestCase { static final String EXTERNAL_SPDX_ELEMENT_ID = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "TEST"; static final String EXTERNAL_SPDX_URI = EXTERNAL_DOC_NAMSPACE + "#" + EXTERNAL_SPDX_ELEMENT_ID; static final String NON_INTERESTING_URI = "https://nothing/to/see/here"; + static final Map EXTERNAL_MAP = new HashMap<>(); /* (non-Javadoc) * @see junit.framework.TestCase#setUp() @@ -86,16 +91,19 @@ public void testToModelObjectV2() throws InvalidSPDXAnalysisException { org.spdx.library.model.compat.v2.GenericModelObject gmo = new org.spdx.library.model.compat.v2.GenericModelObject(store, "http://doc", "id", copyManager, true); new org.spdx.library.model.compat.v2.SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); - Object result = new SimpleUriValue(EXTERNAL_SPDX_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); + Object result = new SimpleUriValue(EXTERNAL_SPDX_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), + gmo.getDocumentUri(), EXTERNAL_MAP); assertTrue(result instanceof org.spdx.library.model.compat.v2.ExternalSpdxElement); org.spdx.library.model.compat.v2.ExternalSpdxElement externalElement = (org.spdx.library.model.compat.v2.ExternalSpdxElement)result; assertEquals(EXTERNAL_SPDX_ELEMENT_ID, externalElement.getExternalElementId()); assertEquals(EXTERNAL_SPDX_URI, externalElement.getExternalSpdxElementURI()); - result = new SimpleUriValue(ENUM_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); + result = new SimpleUriValue(ENUM_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), + gmo.getDocumentUri(), EXTERNAL_MAP); assertEquals(TEST_ENUM, result); - result = new SimpleUriValue(NON_INTERESTING_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), gmo.getDocumentUri()); + result = new SimpleUriValue(NON_INTERESTING_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), + gmo.getDocumentUri(), EXTERNAL_MAP); assertTrue(result instanceof SimpleUriValue); assertEquals(NON_INTERESTING_URI, ((SimpleUriValue)result).getIndividualURI()); } diff --git a/src/test/java/org/spdx/library/model/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/ai/AIPackageTest.java index 29fc79bf3..7b0e1d9f6 100644 --- a/src/test/java/org/spdx/library/model/ai/AIPackageTest.java +++ b/src/test/java/org/spdx/library/model/ai/AIPackageTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -45,6 +46,12 @@ public class AIPackageTest extends TestCase { static final String LIMITATION_TEST_VALUE = "test limitation"; static final String ENERGY_CONSUMPTION_TEST_VALUE = "test energyConsumption"; static final String INFORMATION_ABOUT_APPLICATION_TEST_VALUE = "test informationAboutApplication"; + static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1 = PresenceType.values()[0]; + static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2 = PresenceType.values()[1]; + static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE1 = SafetyRiskAssessmentType.values()[0]; + static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE2 = SafetyRiskAssessmentType.values()[1]; + static final PresenceType AUTONOMY_TYPE_TEST_VALUE1 = PresenceType.values()[0]; + static final PresenceType AUTONOMY_TYPE_TEST_VALUE2 = PresenceType.values()[1]; static final String DOMAIN_TEST_VALUE1 = "test 1 domain"; static final String DOMAIN_TEST_VALUE2 = "test 2 domain"; static final String DOMAIN_TEST_VALUE3 = "test 3 domain"; @@ -98,11 +105,11 @@ public static AIPackageBuilder builderForAIPackageTests( .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE1) .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE2) + .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) + .setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE1) + .setAutonomyType(AUTONOMY_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setSensitivePersonalInformation(PresenceType.ENUM) - .setSafetyRiskAssessment(SafetyRiskAssessmentType.ENUM) - .setAutonomyType(PresenceType.ENUM) .addMetric(DictionaryEntry) .addHyperparameter(DictionaryEntry) .addMetricDecisionThreshold(DictionaryEntry) @@ -158,10 +165,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getSensitivePersonalInformation()); -// testAIPackage.setSensitivePersonalInformation(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getSensitivePersonalInformation()); - fail("Not yet implemented"); + assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1), testAIPackage.getSensitivePersonalInformation()); + testAIPackage.setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2); + assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2), testAIPackage.getSensitivePersonalInformation()); } /** @@ -169,10 +175,9 @@ public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAna */ public void testAIPackagesetSafetyRiskAssessment() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getSafetyRiskAssessment()); -// testAIPackage.setSafetyRiskAssessment(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getSafetyRiskAssessment()); - fail("Not yet implemented"); + assertEquals(Optional.of(SAFETY_RISK_ASSESSMENT_TEST_VALUE1), testAIPackage.getSafetyRiskAssessment()); + testAIPackage.setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE2); + assertEquals(Optional.of(SAFETY_RISK_ASSESSMENT_TEST_VALUE2), testAIPackage.getSafetyRiskAssessment()); } /** @@ -180,10 +185,9 @@ public void testAIPackagesetSafetyRiskAssessment() throws InvalidSPDXAnalysisExc */ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAIPackage.getAutonomyType()); -// testAIPackage.setAutonomyType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAIPackage.getAutonomyType()); - fail("Not yet implemented"); + assertEquals(Optional.of(AUTONOMY_TYPE_TEST_VALUE1), testAIPackage.getAutonomyType()); + testAIPackage.setAutonomyType(AUTONOMY_TYPE_TEST_VALUE2); + assertEquals(Optional.of(AUTONOMY_TYPE_TEST_VALUE2), testAIPackage.getAutonomyType()); } /** @@ -191,9 +195,9 @@ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { */ public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(INFORMATION_ABOUT_TRAINING_TEST_VALUE, testAIPackage.getInformationAboutTraining()); + assertEquals(Optional.of(INFORMATION_ABOUT_TRAINING_TEST_VALUE), testAIPackage.getInformationAboutTraining()); testAIPackage.setInformationAboutTraining("new informationAboutTraining value"); - assertEquals("new informationAboutTraining value", testAIPackage.getInformationAboutTraining()); + assertEquals(Optional.of("new informationAboutTraining value"), testAIPackage.getInformationAboutTraining()); } /** @@ -201,9 +205,9 @@ public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysi */ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(LIMITATION_TEST_VALUE, testAIPackage.getLimitation()); + assertEquals(Optional.of(LIMITATION_TEST_VALUE), testAIPackage.getLimitation()); testAIPackage.setLimitation("new limitation value"); - assertEquals("new limitation value", testAIPackage.getLimitation()); + assertEquals(Optional.of("new limitation value"), testAIPackage.getLimitation()); } /** @@ -211,9 +215,9 @@ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { */ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(ENERGY_CONSUMPTION_TEST_VALUE, testAIPackage.getEnergyConsumption()); + assertEquals(Optional.of(ENERGY_CONSUMPTION_TEST_VALUE), testAIPackage.getEnergyConsumption()); testAIPackage.setEnergyConsumption("new energyConsumption value"); - assertEquals("new energyConsumption value", testAIPackage.getEnergyConsumption()); + assertEquals(Optional.of("new energyConsumption value"), testAIPackage.getEnergyConsumption()); } /** @@ -221,9 +225,9 @@ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisExcept */ public void testAIPackagesetInformationAboutApplication() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(INFORMATION_ABOUT_APPLICATION_TEST_VALUE, testAIPackage.getInformationAboutApplication()); + assertEquals(Optional.of(INFORMATION_ABOUT_APPLICATION_TEST_VALUE), testAIPackage.getInformationAboutApplication()); testAIPackage.setInformationAboutApplication("new informationAboutApplication value"); - assertEquals("new informationAboutApplication value", testAIPackage.getInformationAboutApplication()); + assertEquals(Optional.of("new informationAboutApplication value"), testAIPackage.getInformationAboutApplication()); } /** @@ -271,7 +275,6 @@ public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { testAIPackage.getDomains().clear(); testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); - fail("Not yet implemented"); } /** @@ -283,7 +286,6 @@ public void testAIPackagegetStandardCompliances() throws InvalidSPDXAnalysisExce testAIPackage.getStandardCompliances().clear(); testAIPackage.getStandardCompliances().addAll(STANDARD_COMPLIANCE_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST2, new ArrayList<>(testAIPackage.getStandardCompliances()))); - fail("Not yet implemented"); } /** @@ -295,7 +297,6 @@ public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysis testAIPackage.getModelDataPreprocessings().clear(); testAIPackage.getModelDataPreprocessings().addAll(MODEL_DATA_PREPROCESSING_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); - fail("Not yet implemented"); } /** @@ -307,7 +308,6 @@ public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { testAIPackage.getTypeOfModels().clear(); testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); - fail("Not yet implemented"); } /** @@ -319,6 +319,5 @@ public void testAIPackagegetModelExplainabilitys() throws InvalidSPDXAnalysisExc testAIPackage.getModelExplainabilitys().clear(); testAIPackage.getModelExplainabilitys().addAll(MODEL_EXPLAINABILITY_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST2, new ArrayList<>(testAIPackage.getModelExplainabilitys()))); - fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/build/BuildTest.java b/src/test/java/org/spdx/library/model/build/BuildTest.java index 77d3d6bac..4a57ee5c5 100644 --- a/src/test/java/org/spdx/library/model/build/BuildTest.java +++ b/src/test/java/org/spdx/library/model/build/BuildTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -134,9 +135,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BUILD_END_TIME_TEST_VALUE, testBuild.getBuildEndTime()); + assertEquals(Optional.of(BUILD_END_TIME_TEST_VALUE), testBuild.getBuildEndTime()); testBuild.setBuildEndTime("new buildEndTime value"); - assertEquals("new buildEndTime value", testBuild.getBuildEndTime()); + assertEquals(Optional.of("new buildEndTime value"), testBuild.getBuildEndTime()); } /** @@ -154,9 +155,9 @@ public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BUILD_START_TIME_TEST_VALUE, testBuild.getBuildStartTime()); + assertEquals(Optional.of(BUILD_START_TIME_TEST_VALUE), testBuild.getBuildStartTime()); testBuild.setBuildStartTime("new buildStartTime value"); - assertEquals("new buildStartTime value", testBuild.getBuildStartTime()); + assertEquals(Optional.of("new buildStartTime value"), testBuild.getBuildStartTime()); } /** @@ -164,9 +165,9 @@ public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { */ public void testBuildsetBuildId() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BUILD_ID_TEST_VALUE, testBuild.getBuildId()); + assertEquals(Optional.of(BUILD_ID_TEST_VALUE), testBuild.getBuildId()); testBuild.setBuildId("new buildId value"); - assertEquals("new buildId value", testBuild.getBuildId()); + assertEquals(Optional.of("new buildId value"), testBuild.getBuildId()); } /** @@ -214,7 +215,6 @@ public void testBuildgetConfigSourceEntrypoints() throws InvalidSPDXAnalysisExce testBuild.getConfigSourceEntrypoints().clear(); testBuild.getConfigSourceEntrypoints().addAll(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); - fail("Not yet implemented"); } /** @@ -226,6 +226,5 @@ public void testBuildgetConfigSourceUris() throws InvalidSPDXAnalysisException { testBuild.getConfigSourceUris().clear(); testBuild.getConfigSourceUris().addAll(CONFIG_SOURCE_URI_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_URI_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceUris()))); - fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java index 00762edc0..d166b25bc 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java @@ -24,7 +24,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; import org.spdx.library.SpdxConstantsCompatV2; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java index 1a4f82439..74697c1f0 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ChecksumTest.java @@ -24,7 +24,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java index 70bc42c88..b7e05be77 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalDocumentRefTest.java @@ -25,7 +25,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java index fad2727df..dd6cdbc33 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalRefTest.java @@ -25,7 +25,7 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; import org.spdx.library.referencetype.compat.v2.ListedReferenceTypes; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java index ae79f49fd..3c1589a53 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ExternalSpdxElementTest.java @@ -6,8 +6,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java index 5c6b8ae1c..31ef00fc5 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/IndividualUriValueTest.java @@ -5,10 +5,10 @@ import org.spdx.library.SimpleUriValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index c12a93375..ce7e5752b 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -37,6 +37,8 @@ import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.TypedValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; @@ -45,8 +47,6 @@ import org.spdx.library.model.compat.v2.license.SpdxListedLicense; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.ModelUpdate; diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index 1f7636d59..9c5c5bccb 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -12,10 +12,10 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.TypedValue; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; diff --git a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java index 61829bbbc..28bbf383e 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/NoAssertionElementTest.java @@ -20,7 +20,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java index 0f8bedfff..063105a80 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelatedElementCollectionTest.java @@ -25,7 +25,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java index 12fb5b01c..e9db5a4ba 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/RelationshipTest.java @@ -31,13 +31,13 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index 7ee1a2069..70bbfc786 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -30,15 +30,15 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java index 54735c573..25a65cfa3 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java @@ -27,8 +27,8 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java index 64a0c0964..7819deb80 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxFileTest.java @@ -12,15 +12,15 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; import org.spdx.library.model.compat.v2.license.SpdxListedLicense; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java index 2f07346f8..c290a31eb 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxNoneElementTest.java @@ -20,7 +20,7 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.enumerations.RelationshipType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java index de1805bc7..e84423050 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxPackageTest.java @@ -30,14 +30,14 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.Purpose; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.Purpose; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java index b667e4162..ebb945dbc 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxSnippetTest.java @@ -28,6 +28,8 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.Version; import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -36,8 +38,6 @@ import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java index c7f3aea10..14d4d180a 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/ExternalLicenseRefTest.java @@ -27,7 +27,7 @@ import org.spdx.library.model.compat.v2.ExternalDocumentRef; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java index a0806ee0d..7247d6884 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java @@ -28,7 +28,7 @@ import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.GenericModelObject; import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/core/AgentTest.java b/src/test/java/org/spdx/library/model/core/AgentTest.java index 769791d81..90aed3af1 100644 --- a/src/test/java/org/spdx/library/model/core/AgentTest.java +++ b/src/test/java/org/spdx/library/model/core/AgentTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/AnnotationTest.java b/src/test/java/org/spdx/library/model/core/AnnotationTest.java index 505974577..c54550e02 100644 --- a/src/test/java/org/spdx/library/model/core/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/core/AnnotationTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -42,6 +43,8 @@ public class AnnotationTest extends TestCase { ModelCopyManager copyManager; static final String STATEMENT_TEST_VALUE = "test statement"; + static final AnnotationType ANNOTATION_TYPE_TEST_VALUE1 = AnnotationType.values()[0]; + static final AnnotationType ANNOTATION_TYPE_TEST_VALUE2 = AnnotationType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -57,10 +60,10 @@ public static AnnotationBuilder builderForAnnotationTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { AnnotationBuilder retval = new AnnotationBuilder(modelStore, objectUri, copyManager) .setStatement(STATEMENT_TEST_VALUE) + .setAnnotationType(ANNOTATION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** .setSubject(Element testElement) - .setAnnotationType(AnnotationType.ENUM) ***************/ ; return retval; @@ -124,10 +127,9 @@ public void testAnnotationsetSubject() throws InvalidSPDXAnalysisException { */ public void testAnnotationsetAnnotationType() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testAnnotation.getAnnotationType()); -// testAnnotation.setAnnotationType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testAnnotation.getAnnotationType()); - fail("Not yet implemented"); + assertEquals(ANNOTATION_TYPE_TEST_VALUE1, testAnnotation.getAnnotationType()); + testAnnotation.setAnnotationType(ANNOTATION_TYPE_TEST_VALUE2); + assertEquals(ANNOTATION_TYPE_TEST_VALUE2, testAnnotation.getAnnotationType()); } /** @@ -135,8 +137,8 @@ public void testAnnotationsetAnnotationType() throws InvalidSPDXAnalysisExceptio */ public void testAnnotationsetStatement() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(STATEMENT_TEST_VALUE, testAnnotation.getStatement()); + assertEquals(Optional.of(STATEMENT_TEST_VALUE), testAnnotation.getStatement()); testAnnotation.setStatement("new statement value"); - assertEquals("new statement value", testAnnotation.getStatement()); + assertEquals(Optional.of("new statement value"), testAnnotation.getStatement()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java b/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java index 7d6777854..5582ee346 100644 --- a/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java +++ b/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/ArtifactTest.java b/src/test/java/org/spdx/library/model/core/ArtifactTest.java index d907defe5..86267a02f 100644 --- a/src/test/java/org/spdx/library/model/core/ArtifactTest.java +++ b/src/test/java/org/spdx/library/model/core/ArtifactTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -124,9 +125,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(RELEASE_TIME_TEST_VALUE, testArtifact.getReleaseTime()); + assertEquals(Optional.of(RELEASE_TIME_TEST_VALUE), testArtifact.getReleaseTime()); testArtifact.setReleaseTime("new releaseTime value"); - assertEquals("new releaseTime value", testArtifact.getReleaseTime()); + assertEquals(Optional.of("new releaseTime value"), testArtifact.getReleaseTime()); } /** @@ -134,9 +135,9 @@ public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { */ public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(VALID_UNTIL_TIME_TEST_VALUE, testArtifact.getValidUntilTime()); + assertEquals(Optional.of(VALID_UNTIL_TIME_TEST_VALUE), testArtifact.getValidUntilTime()); testArtifact.setValidUntilTime("new validUntilTime value"); - assertEquals("new validUntilTime value", testArtifact.getValidUntilTime()); + assertEquals(Optional.of("new validUntilTime value"), testArtifact.getValidUntilTime()); } /** @@ -144,9 +145,9 @@ public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException */ public void testArtifactsetBuiltTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BUILT_TIME_TEST_VALUE, testArtifact.getBuiltTime()); + assertEquals(Optional.of(BUILT_TIME_TEST_VALUE), testArtifact.getBuiltTime()); testArtifact.setBuiltTime("new builtTime value"); - assertEquals("new builtTime value", testArtifact.getBuiltTime()); + assertEquals(Optional.of("new builtTime value"), testArtifact.getBuiltTime()); } /** @@ -182,6 +183,5 @@ public void testArtifactgetStandards() throws InvalidSPDXAnalysisException { testArtifact.getStandards().clear(); testArtifact.getStandards().addAll(STANDARD_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(STANDARD_TEST_LIST2, new ArrayList<>(testArtifact.getStandards()))); - fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/BomTest.java b/src/test/java/org/spdx/library/model/core/BomTest.java index bff2ed487..3456d7208 100644 --- a/src/test/java/org/spdx/library/model/core/BomTest.java +++ b/src/test/java/org/spdx/library/model/core/BomTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/BundleTest.java b/src/test/java/org/spdx/library/model/core/BundleTest.java index 39de9f0b8..d7c825055 100644 --- a/src/test/java/org/spdx/library/model/core/BundleTest.java +++ b/src/test/java/org/spdx/library/model/core/BundleTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -111,8 +112,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testBundlesetContext() throws InvalidSPDXAnalysisException { Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(CONTEXT_TEST_VALUE, testBundle.getContext()); + assertEquals(Optional.of(CONTEXT_TEST_VALUE), testBundle.getContext()); testBundle.setContext("new context value"); - assertEquals("new context value", testBundle.getContext()); + assertEquals(Optional.of("new context value"), testBundle.getContext()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/CreationInfoTest.java b/src/test/java/org/spdx/library/model/core/CreationInfoTest.java index 2d1153274..cb35f3f04 100644 --- a/src/test/java/org/spdx/library/model/core/CreationInfoTest.java +++ b/src/test/java/org/spdx/library/model/core/CreationInfoTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -57,6 +58,10 @@ public class CreationInfoTest extends TestCase { static final String SPEC_VERSION_TEST_VALUE3 = "test 3 specVersion"; static final List SPEC_VERSION_TEST_LIST1 = Arrays.asList(new String[] { SPEC_VERSION_TEST_VALUE1, SPEC_VERSION_TEST_VALUE2 }); static final List SPEC_VERSION_TEST_LIST2 = Arrays.asList(new String[] { SPEC_VERSION_TEST_VALUE3 }); + static final ProfileIdentifierType PROFILE_TEST_VALUE1 = ProfileIdentifierType.values()[0]; + static final ProfileIdentifierType PROFILE_TEST_VALUE2 = ProfileIdentifierType.values()[1]; + static final List PROFILE_TEST_LIST1 = Arrays.asList(new ProfileIdentifierType[] { PROFILE_TEST_VALUE1, PROFILE_TEST_VALUE2 }); + static final List PROFILE_TEST_LIST2 = Arrays.asList(new ProfileIdentifierType[] { PROFILE_TEST_VALUE1 }); protected void setUp() throws Exception { super.setUp(); @@ -78,11 +83,12 @@ public static CreationInfoBuilder builderForCreationInfoTests( .addDataLicense(DATA_LICENSE_TEST_VALUE2) .addSpecVersion(SPEC_VERSION_TEST_VALUE1) .addSpecVersion(SPEC_VERSION_TEST_VALUE2) + .addProfile(PROFILE_TEST_VALUE1) + .addProfile(PROFILE_TEST_VALUE2) //TODO: Add in test values /******************** .addCreatedUsing(Tool) .addCreatedBy(Agent) - .addProfile(ProfileIdentifierType.ENUM) ***************/ ; return retval; @@ -135,9 +141,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(COMMENT_TEST_VALUE, testCreationInfo.getComment()); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testCreationInfo.getComment()); testCreationInfo.setComment("new comment value"); - assertEquals("new comment value", testCreationInfo.getComment()); + assertEquals(Optional.of("new comment value"), testCreationInfo.getComment()); } /** @@ -173,7 +179,6 @@ public void testCreationInfogetCreateds() throws InvalidSPDXAnalysisException { testCreationInfo.getCreateds().clear(); testCreationInfo.getCreateds().addAll(CREATED_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(CREATED_TEST_LIST2, new ArrayList<>(testCreationInfo.getCreateds()))); - fail("Not yet implemented"); } /** @@ -185,7 +190,6 @@ public void testCreationInfogetDataLicenses() throws InvalidSPDXAnalysisExceptio testCreationInfo.getDataLicenses().clear(); testCreationInfo.getDataLicenses().addAll(DATA_LICENSE_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(DATA_LICENSE_TEST_LIST2, new ArrayList<>(testCreationInfo.getDataLicenses()))); - fail("Not yet implemented"); } /** @@ -197,7 +201,6 @@ public void testCreationInfogetSpecVersions() throws InvalidSPDXAnalysisExceptio testCreationInfo.getSpecVersions().clear(); testCreationInfo.getSpecVersions().addAll(SPEC_VERSION_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(SPEC_VERSION_TEST_LIST2, new ArrayList<>(testCreationInfo.getSpecVersions()))); - fail("Not yet implemented"); } /** @@ -205,10 +208,9 @@ public void testCreationInfogetSpecVersions() throws InvalidSPDXAnalysisExceptio */ public void testCreationInfogetProfiles() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testCreationInfo.getProfiles()))); -// testCreationInfo.getProfiles().clear(); -// testCreationInfo.getProfiles().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getProfiles()))); - fail("Not yet implemented"); + assertTrue(UnitTestHelper.isListsEqual(PROFILE_TEST_LIST1, new ArrayList<>(testCreationInfo.getProfiles()))); + testCreationInfo.getProfiles().clear(); + testCreationInfo.getProfiles().addAll(PROFILE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(PROFILE_TEST_LIST2, new ArrayList<>(testCreationInfo.getProfiles()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java b/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java index 358eaef6d..3f78c32fa 100644 --- a/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java +++ b/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -123,8 +124,8 @@ public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { */ public void testDictionaryEntrysetValue() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(VALUE_TEST_VALUE, testDictionaryEntry.getValue()); + assertEquals(Optional.of(VALUE_TEST_VALUE), testDictionaryEntry.getValue()); testDictionaryEntry.setValue("new value value"); - assertEquals("new value value", testDictionaryEntry.getValue()); + assertEquals(Optional.of("new value value"), testDictionaryEntry.getValue()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java b/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java index 3805c2f06..c52744cf6 100644 --- a/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/ElementTest.java b/src/test/java/org/spdx/library/model/core/ElementTest.java index 5eac1ad8c..baeda7623 100644 --- a/src/test/java/org/spdx/library/model/core/ElementTest.java +++ b/src/test/java/org/spdx/library/model/core/ElementTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -115,9 +116,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testElementsetDescription() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DESCRIPTION_TEST_VALUE, testElement.getDescription()); + assertEquals(Optional.of(DESCRIPTION_TEST_VALUE), testElement.getDescription()); testElement.setDescription("new description value"); - assertEquals("new description value", testElement.getDescription()); + assertEquals(Optional.of("new description value"), testElement.getDescription()); } /** @@ -125,9 +126,9 @@ public void testElementsetDescription() throws InvalidSPDXAnalysisException { */ public void testElementsetSummary() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(SUMMARY_TEST_VALUE, testElement.getSummary()); + assertEquals(Optional.of(SUMMARY_TEST_VALUE), testElement.getSummary()); testElement.setSummary("new summary value"); - assertEquals("new summary value", testElement.getSummary()); + assertEquals(Optional.of("new summary value"), testElement.getSummary()); } /** diff --git a/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java b/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java index cb0101cdf..711d48430 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java +++ b/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -44,6 +45,8 @@ public class ExternalIdentifierTest extends TestCase { static final String ISSUING_AUTHORITY_TEST_VALUE = "test issuingAuthority"; static final String IDENTIFIER_TEST_VALUE = "test identifier"; static final String COMMENT_TEST_VALUE = "test comment"; + static final ExternalIdentifierType EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1 = ExternalIdentifierType.values()[0]; + static final ExternalIdentifierType EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE2 = ExternalIdentifierType.values()[1]; static final String IDENTIFIER_LOCATOR_TEST_VALUE1 = "test 1 identifierLocator"; static final String IDENTIFIER_LOCATOR_TEST_VALUE2 = "test 2 identifierLocator"; static final String IDENTIFIER_LOCATOR_TEST_VALUE3 = "test 3 identifierLocator"; @@ -68,9 +71,9 @@ public static ExternalIdentifierBuilder builderForExternalIdentifierTests( .setComment(COMMENT_TEST_VALUE) .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE1) .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE2) + .setExternalIdentifierType(EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setExternalIdentifierType(ExternalIdentifierType.ENUM) ***************/ ; return retval; @@ -123,10 +126,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testExternalIdentifiersetExternalIdentifierType() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalIdentifier.getExternalIdentifierType()); -// testExternalIdentifier.setExternalIdentifierType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalIdentifier.getExternalIdentifierType()); - fail("Not yet implemented"); + assertEquals(EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1, testExternalIdentifier.getExternalIdentifierType()); + testExternalIdentifier.setExternalIdentifierType(EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE2); + assertEquals(EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE2, testExternalIdentifier.getExternalIdentifierType()); } /** @@ -134,9 +136,9 @@ public void testExternalIdentifiersetExternalIdentifierType() throws InvalidSPDX */ public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(ISSUING_AUTHORITY_TEST_VALUE, testExternalIdentifier.getIssuingAuthority()); + assertEquals(Optional.of(ISSUING_AUTHORITY_TEST_VALUE), testExternalIdentifier.getIssuingAuthority()); testExternalIdentifier.setIssuingAuthority("new issuingAuthority value"); - assertEquals("new issuingAuthority value", testExternalIdentifier.getIssuingAuthority()); + assertEquals(Optional.of("new issuingAuthority value"), testExternalIdentifier.getIssuingAuthority()); } /** @@ -154,9 +156,9 @@ public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisExce */ public void testExternalIdentifiersetComment() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(COMMENT_TEST_VALUE, testExternalIdentifier.getComment()); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testExternalIdentifier.getComment()); testExternalIdentifier.setComment("new comment value"); - assertEquals("new comment value", testExternalIdentifier.getComment()); + assertEquals(Optional.of("new comment value"), testExternalIdentifier.getComment()); } /** @@ -168,6 +170,5 @@ public void testExternalIdentifiergetIdentifierLocators() throws InvalidSPDXAnal testExternalIdentifier.getIdentifierLocators().clear(); testExternalIdentifier.getIdentifierLocators().addAll(IDENTIFIER_LOCATOR_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(IDENTIFIER_LOCATOR_TEST_LIST2, new ArrayList<>(testExternalIdentifier.getIdentifierLocators()))); - fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ExternalMapTest.java b/src/test/java/org/spdx/library/model/core/ExternalMapTest.java index 76a01c982..96b0f5bef 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalMapTest.java +++ b/src/test/java/org/spdx/library/model/core/ExternalMapTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -116,9 +117,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DEFINING_DOCUMENT_TEST_VALUE, testExternalMap.getDefiningDocument()); + assertEquals(Optional.of(DEFINING_DOCUMENT_TEST_VALUE), testExternalMap.getDefiningDocument()); testExternalMap.setDefiningDocument("new definingDocument value"); - assertEquals("new definingDocument value", testExternalMap.getDefiningDocument()); + assertEquals(Optional.of("new definingDocument value"), testExternalMap.getDefiningDocument()); } /** @@ -126,9 +127,9 @@ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisExcep */ public void testExternalMapsetLocationHint() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(LOCATION_HINT_TEST_VALUE, testExternalMap.getLocationHint()); + assertEquals(Optional.of(LOCATION_HINT_TEST_VALUE), testExternalMap.getLocationHint()); testExternalMap.setLocationHint("new locationHint value"); - assertEquals("new locationHint value", testExternalMap.getLocationHint()); + assertEquals(Optional.of("new locationHint value"), testExternalMap.getLocationHint()); } /** diff --git a/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java b/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java index faaf618c7..75b483b30 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java +++ b/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -43,6 +44,8 @@ public class ExternalReferenceTest extends TestCase { static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; static final String COMMENT_TEST_VALUE = "test comment"; + static final ExternalReferenceType EXTERNAL_REFERENCE_TYPE_TEST_VALUE1 = ExternalReferenceType.values()[0]; + static final ExternalReferenceType EXTERNAL_REFERENCE_TYPE_TEST_VALUE2 = ExternalReferenceType.values()[1]; static final String LOCATOR_TEST_VALUE1 = "test 1 locator"; static final String LOCATOR_TEST_VALUE2 = "test 2 locator"; static final String LOCATOR_TEST_VALUE3 = "test 3 locator"; @@ -66,9 +69,9 @@ public static ExternalReferenceBuilder builderForExternalReferenceTests( .setComment(COMMENT_TEST_VALUE) .addLocator(LOCATOR_TEST_VALUE1) .addLocator(LOCATOR_TEST_VALUE2) + .setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setExternalReferenceType(ExternalReferenceType.ENUM) ***************/ ; return retval; @@ -121,10 +124,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExternalReference.getExternalReferenceType()); -// testExternalReference.setExternalReferenceType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExternalReference.getExternalReferenceType()); - fail("Not yet implemented"); + assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1), testExternalReference.getExternalReferenceType()); + testExternalReference.setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2); + assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2), testExternalReference.getExternalReferenceType()); } /** @@ -132,9 +134,9 @@ public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAn */ public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(CONTENT_TYPE_TEST_VALUE, testExternalReference.getContentType()); + assertEquals(Optional.of(CONTENT_TYPE_TEST_VALUE), testExternalReference.getContentType()); testExternalReference.setContentType("new contentType value"); - assertEquals("new contentType value", testExternalReference.getContentType()); + assertEquals(Optional.of("new contentType value"), testExternalReference.getContentType()); } /** @@ -142,9 +144,9 @@ public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisExce */ public void testExternalReferencesetComment() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(COMMENT_TEST_VALUE, testExternalReference.getComment()); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testExternalReference.getComment()); testExternalReference.setComment("new comment value"); - assertEquals("new comment value", testExternalReference.getComment()); + assertEquals(Optional.of("new comment value"), testExternalReference.getComment()); } /** @@ -156,6 +158,5 @@ public void testExternalReferencegetLocators() throws InvalidSPDXAnalysisExcepti testExternalReference.getLocators().clear(); testExternalReference.getLocators().addAll(LOCATOR_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST2, new ArrayList<>(testExternalReference.getLocators()))); - fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/HashTest.java b/src/test/java/org/spdx/library/model/core/HashTest.java index 856e65bb3..baa57276f 100644 --- a/src/test/java/org/spdx/library/model/core/HashTest.java +++ b/src/test/java/org/spdx/library/model/core/HashTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -42,6 +43,8 @@ public class HashTest extends TestCase { ModelCopyManager copyManager; static final String HASH_VALUE_TEST_VALUE = "test hashValue"; + static final HashAlgorithm ALGORITHM_TEST_VALUE1 = HashAlgorithm.values()[0]; + static final HashAlgorithm ALGORITHM_TEST_VALUE2 = HashAlgorithm.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -57,9 +60,9 @@ public static HashBuilder builderForHashTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { HashBuilder retval = new HashBuilder(modelStore, objectUri, copyManager) .setHashValue(HASH_VALUE_TEST_VALUE) + .setAlgorithm(ALGORITHM_TEST_VALUE1) //TODO: Add in test values /******************** - .setAlgorithm(HashAlgorithm.ENUM) ***************/ ; return retval; @@ -112,10 +115,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testHashsetAlgorithm() throws InvalidSPDXAnalysisException { Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testHash.getAlgorithm()); -// testHash.setAlgorithm(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testHash.getAlgorithm()); - fail("Not yet implemented"); + assertEquals(ALGORITHM_TEST_VALUE1, testHash.getAlgorithm()); + testHash.setAlgorithm(ALGORITHM_TEST_VALUE2); + assertEquals(ALGORITHM_TEST_VALUE2, testHash.getAlgorithm()); } /** diff --git a/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java b/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java index 34382a92f..892a229f5 100644 --- a/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java +++ b/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -111,8 +112,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testIntegrityMethodsetComment() throws InvalidSPDXAnalysisException { IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(COMMENT_TEST_VALUE, testIntegrityMethod.getComment()); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testIntegrityMethod.getComment()); testIntegrityMethod.setComment("new comment value"); - assertEquals("new comment value", testIntegrityMethod.getComment()); + assertEquals(Optional.of("new comment value"), testIntegrityMethod.getComment()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java b/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java index 4ffad298b..7285ae8d4 100644 --- a/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -41,6 +42,8 @@ public class LifecycleScopedRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final LifecycleScopeType SCOPE_TEST_VALUE1 = LifecycleScopeType.values()[0]; + static final LifecycleScopeType SCOPE_TEST_VALUE2 = LifecycleScopeType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -55,9 +58,9 @@ protected void tearDown() throws Exception { public static LifecycleScopedRelationshipBuilder builderForLifecycleScopedRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { LifecycleScopedRelationshipBuilder retval = new LifecycleScopedRelationshipBuilder(modelStore, objectUri, copyManager) + .setScope(SCOPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setScope(LifecycleScopeType.ENUM) ***************/ ; return retval; @@ -110,9 +113,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testLifecycleScopedRelationshipsetScope() throws InvalidSPDXAnalysisException { LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testLifecycleScopedRelationship.getScope()); -// testLifecycleScopedRelationship.setScope(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testLifecycleScopedRelationship.getScope()); - fail("Not yet implemented"); + assertEquals(Optional.of(SCOPE_TEST_VALUE1), testLifecycleScopedRelationship.getScope()); + testLifecycleScopedRelationship.setScope(SCOPE_TEST_VALUE2); + assertEquals(Optional.of(SCOPE_TEST_VALUE2), testLifecycleScopedRelationship.getScope()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java b/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java index 4e6aa31e8..ce0d4f681 100644 --- a/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java +++ b/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/OrganizationTest.java b/src/test/java/org/spdx/library/model/core/OrganizationTest.java index 98c3610a2..a487c3fee 100644 --- a/src/test/java/org/spdx/library/model/core/OrganizationTest.java +++ b/src/test/java/org/spdx/library/model/core/OrganizationTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/PayloadTest.java b/src/test/java/org/spdx/library/model/core/PayloadTest.java index 7e8e3a289..b04cf3290 100644 --- a/src/test/java/org/spdx/library/model/core/PayloadTest.java +++ b/src/test/java/org/spdx/library/model/core/PayloadTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -112,9 +113,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testPayloadsetCreationInfo() throws InvalidSPDXAnalysisException { Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testPayload.getCreationInfo()); +// assertEquals(Optional.of(TEST_VALUE), testPayload.getCreationInfo()); // testPayload.setCreationInfo(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testPayload.getCreationInfo()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testPayload.getCreationInfo()); fail("Not yet implemented"); } diff --git a/src/test/java/org/spdx/library/model/core/PersonTest.java b/src/test/java/org/spdx/library/model/core/PersonTest.java index 3d2517ea6..77ee1d63e 100644 --- a/src/test/java/org/spdx/library/model/core/PersonTest.java +++ b/src/test/java/org/spdx/library/model/core/PersonTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java b/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java index 1b3cf2831..9ac1f3022 100644 --- a/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java +++ b/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/RelationshipTest.java b/src/test/java/org/spdx/library/model/core/RelationshipTest.java index 64bde293c..56d68abe8 100644 --- a/src/test/java/org/spdx/library/model/core/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/core/RelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -43,6 +44,10 @@ public class RelationshipTest extends TestCase { static final String START_TIME_TEST_VALUE = "test startTime"; static final String END_TIME_TEST_VALUE = "test endTime"; + static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE1 = RelationshipType.values()[0]; + static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE2 = RelationshipType.values()[1]; + static final RelationshipCompleteness COMPLETENESS_TEST_VALUE1 = RelationshipCompleteness.values()[0]; + static final RelationshipCompleteness COMPLETENESS_TEST_VALUE2 = RelationshipCompleteness.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -59,11 +64,11 @@ public static RelationshipBuilder builderForRelationshipTests( RelationshipBuilder retval = new RelationshipBuilder(modelStore, objectUri, copyManager) .setStartTime(START_TIME_TEST_VALUE) .setEndTime(END_TIME_TEST_VALUE) + .setRelationshipType(RELATIONSHIP_TYPE_TEST_VALUE1) + .setCompleteness(COMPLETENESS_TEST_VALUE1) //TODO: Add in test values /******************** .setFrom(Element testElement) - .setRelationshipType(RelationshipType.ENUM) - .setCompleteness(RelationshipCompleteness.ENUM) .addTo(Element) ***************/ ; @@ -128,10 +133,9 @@ public void testRelationshipsetFrom() throws InvalidSPDXAnalysisException { */ public void testRelationshipsetRelationshipType() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testRelationship.getRelationshipType()); -// testRelationship.setRelationshipType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testRelationship.getRelationshipType()); - fail("Not yet implemented"); + assertEquals(RELATIONSHIP_TYPE_TEST_VALUE1, testRelationship.getRelationshipType()); + testRelationship.setRelationshipType(RELATIONSHIP_TYPE_TEST_VALUE2); + assertEquals(RELATIONSHIP_TYPE_TEST_VALUE2, testRelationship.getRelationshipType()); } /** @@ -139,10 +143,9 @@ public void testRelationshipsetRelationshipType() throws InvalidSPDXAnalysisExce */ public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testRelationship.getCompleteness()); -// testRelationship.setCompleteness(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testRelationship.getCompleteness()); - fail("Not yet implemented"); + assertEquals(Optional.of(COMPLETENESS_TEST_VALUE1), testRelationship.getCompleteness()); + testRelationship.setCompleteness(COMPLETENESS_TEST_VALUE2); + assertEquals(Optional.of(COMPLETENESS_TEST_VALUE2), testRelationship.getCompleteness()); } /** @@ -150,9 +153,9 @@ public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisExceptio */ public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(START_TIME_TEST_VALUE, testRelationship.getStartTime()); + assertEquals(Optional.of(START_TIME_TEST_VALUE), testRelationship.getStartTime()); testRelationship.setStartTime("new startTime value"); - assertEquals("new startTime value", testRelationship.getStartTime()); + assertEquals(Optional.of("new startTime value"), testRelationship.getStartTime()); } /** @@ -160,9 +163,9 @@ public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { */ public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(END_TIME_TEST_VALUE, testRelationship.getEndTime()); + assertEquals(Optional.of(END_TIME_TEST_VALUE), testRelationship.getEndTime()); testRelationship.setEndTime("new endTime value"); - assertEquals("new endTime value", testRelationship.getEndTime()); + assertEquals(Optional.of("new endTime value"), testRelationship.getEndTime()); } /** diff --git a/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java b/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java index 900a39411..8332d662e 100644 --- a/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java +++ b/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java index 16c771630..d6d6fc3b6 100644 --- a/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/core/ToolTest.java b/src/test/java/org/spdx/library/model/core/ToolTest.java index 1b69b51e8..38c2c192c 100644 --- a/src/test/java/org/spdx/library/model/core/ToolTest.java +++ b/src/test/java/org/spdx/library/model/core/ToolTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/dataset/DatasetTest.java b/src/test/java/org/spdx/library/model/dataset/DatasetTest.java index 6ccb439c5..f42327fe5 100644 --- a/src/test/java/org/spdx/library/model/dataset/DatasetTest.java +++ b/src/test/java/org/spdx/library/model/dataset/DatasetTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -46,6 +47,10 @@ public class DatasetTest extends TestCase { static final String DATASET_NOISE_TEST_VALUE = "test datasetNoise"; static final String DATA_COLLECTION_PROCESS_TEST_VALUE = "test dataCollectionProcess"; static final String DATASET_UPDATE_MECHANISM_TEST_VALUE = "test datasetUpdateMechanism"; + static final ConfidentialityLevelType CONFIDENTIALITY_LEVEL_TEST_VALUE1 = ConfidentialityLevelType.values()[0]; + static final ConfidentialityLevelType CONFIDENTIALITY_LEVEL_TEST_VALUE2 = ConfidentialityLevelType.values()[1]; + static final DatasetAvailabilityType DATASET_AVAILABILITY_TEST_VALUE1 = DatasetAvailabilityType.values()[0]; + static final DatasetAvailabilityType DATASET_AVAILABILITY_TEST_VALUE2 = DatasetAvailabilityType.values()[1]; static final String ANONYMIZATION_METHOD_USED_TEST_VALUE1 = "test 1 anonymizationMethodUsed"; static final String ANONYMIZATION_METHOD_USED_TEST_VALUE2 = "test 2 anonymizationMethodUsed"; static final String ANONYMIZATION_METHOD_USED_TEST_VALUE3 = "test 3 anonymizationMethodUsed"; @@ -61,6 +66,10 @@ public class DatasetTest extends TestCase { static final String KNOWN_BIAS_TEST_VALUE3 = "test 3 knownBias"; static final List KNOWN_BIAS_TEST_LIST1 = Arrays.asList(new String[] { KNOWN_BIAS_TEST_VALUE1, KNOWN_BIAS_TEST_VALUE2 }); static final List KNOWN_BIAS_TEST_LIST2 = Arrays.asList(new String[] { KNOWN_BIAS_TEST_VALUE3 }); + static final DatasetType DATASET_TYPE_TEST_VALUE1 = DatasetType.values()[0]; + static final DatasetType DATASET_TYPE_TEST_VALUE2 = DatasetType.values()[1]; + static final List DATASET_TYPE_TEST_LIST1 = Arrays.asList(new DatasetType[] { DATASET_TYPE_TEST_VALUE1, DATASET_TYPE_TEST_VALUE2 }); + static final List DATASET_TYPE_TEST_LIST2 = Arrays.asList(new DatasetType[] { DATASET_TYPE_TEST_VALUE1 }); protected void setUp() throws Exception { super.setUp(); @@ -86,13 +95,14 @@ public static DatasetBuilder builderForDatasetTests( .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE2) .addKnownBias(KNOWN_BIAS_TEST_VALUE1) .addKnownBias(KNOWN_BIAS_TEST_VALUE2) + .setConfidentialityLevel(CONFIDENTIALITY_LEVEL_TEST_VALUE1) + .setDatasetAvailability(DATASET_AVAILABILITY_TEST_VALUE1) + .addDatasetType(DATASET_TYPE_TEST_VALUE1) + .addDatasetType(DATASET_TYPE_TEST_VALUE2) //TODO: Add in test values /******************** .setSensitivePersonalInformation(new PresenceType()) - .setConfidentialityLevel(ConfidentialityLevelType.ENUM) - .setDatasetAvailability(DatasetAvailabilityType.ENUM) .addSensor(DictionaryEntry) - .addDatasetType(DatasetType.ENUM) ***************/ ; return retval; @@ -145,9 +155,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testDatasetsetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getSensitivePersonalInformation()); +// assertEquals(Optional.of(TEST_VALUE), testDataset.getSensitivePersonalInformation()); // testDataset.setSensitivePersonalInformation(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getSensitivePersonalInformation()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testDataset.getSensitivePersonalInformation()); fail("Not yet implemented"); } @@ -156,10 +166,9 @@ public void testDatasetsetSensitivePersonalInformation() throws InvalidSPDXAnaly */ public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getConfidentialityLevel()); -// testDataset.setConfidentialityLevel(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getConfidentialityLevel()); - fail("Not yet implemented"); + assertEquals(Optional.of(CONFIDENTIALITY_LEVEL_TEST_VALUE1), testDataset.getConfidentialityLevel()); + testDataset.setConfidentialityLevel(CONFIDENTIALITY_LEVEL_TEST_VALUE2); + assertEquals(Optional.of(CONFIDENTIALITY_LEVEL_TEST_VALUE2), testDataset.getConfidentialityLevel()); } /** @@ -167,10 +176,9 @@ public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisExcep */ public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testDataset.getDatasetAvailability()); -// testDataset.setDatasetAvailability(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testDataset.getDatasetAvailability()); - fail("Not yet implemented"); + assertEquals(Optional.of(DATASET_AVAILABILITY_TEST_VALUE1), testDataset.getDatasetAvailability()); + testDataset.setDatasetAvailability(DATASET_AVAILABILITY_TEST_VALUE2); + assertEquals(Optional.of(DATASET_AVAILABILITY_TEST_VALUE2), testDataset.getDatasetAvailability()); } /** @@ -178,9 +186,9 @@ public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisExcept */ public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DATASET_SIZE_TEST_VALUE, testDataset.getDatasetSize()); + assertEquals(Optional.of(DATASET_SIZE_TEST_VALUE), testDataset.getDatasetSize()); testDataset.setDatasetSize(new Integer(653)); - assertEquals(new Integer(653), testDataset.getDatasetSize()); + assertEquals(Optional.of(new Integer(653)), testDataset.getDatasetSize()); } /** @@ -188,9 +196,9 @@ public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { */ public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(INTENDED_USE_TEST_VALUE, testDataset.getIntendedUse()); + assertEquals(Optional.of(INTENDED_USE_TEST_VALUE), testDataset.getIntendedUse()); testDataset.setIntendedUse("new intendedUse value"); - assertEquals("new intendedUse value", testDataset.getIntendedUse()); + assertEquals(Optional.of("new intendedUse value"), testDataset.getIntendedUse()); } /** @@ -198,9 +206,9 @@ public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { */ public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DATASET_NOISE_TEST_VALUE, testDataset.getDatasetNoise()); + assertEquals(Optional.of(DATASET_NOISE_TEST_VALUE), testDataset.getDatasetNoise()); testDataset.setDatasetNoise("new datasetNoise value"); - assertEquals("new datasetNoise value", testDataset.getDatasetNoise()); + assertEquals(Optional.of("new datasetNoise value"), testDataset.getDatasetNoise()); } /** @@ -208,9 +216,9 @@ public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { */ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DATA_COLLECTION_PROCESS_TEST_VALUE, testDataset.getDataCollectionProcess()); + assertEquals(Optional.of(DATA_COLLECTION_PROCESS_TEST_VALUE), testDataset.getDataCollectionProcess()); testDataset.setDataCollectionProcess("new dataCollectionProcess value"); - assertEquals("new dataCollectionProcess value", testDataset.getDataCollectionProcess()); + assertEquals(Optional.of("new dataCollectionProcess value"), testDataset.getDataCollectionProcess()); } /** @@ -218,9 +226,9 @@ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisExce */ public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DATASET_UPDATE_MECHANISM_TEST_VALUE, testDataset.getDatasetUpdateMechanism()); + assertEquals(Optional.of(DATASET_UPDATE_MECHANISM_TEST_VALUE), testDataset.getDatasetUpdateMechanism()); testDataset.setDatasetUpdateMechanism("new datasetUpdateMechanism value"); - assertEquals("new datasetUpdateMechanism value", testDataset.getDatasetUpdateMechanism()); + assertEquals(Optional.of("new datasetUpdateMechanism value"), testDataset.getDatasetUpdateMechanism()); } /** @@ -244,7 +252,6 @@ public void testDatasetgetAnonymizationMethodUseds() throws InvalidSPDXAnalysisE testDataset.getAnonymizationMethodUseds().clear(); testDataset.getAnonymizationMethodUseds().addAll(ANONYMIZATION_METHOD_USED_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(ANONYMIZATION_METHOD_USED_TEST_LIST2, new ArrayList<>(testDataset.getAnonymizationMethodUseds()))); - fail("Not yet implemented"); } /** @@ -256,7 +263,6 @@ public void testDatasetgetDataPreprocessings() throws InvalidSPDXAnalysisExcepti testDataset.getDataPreprocessings().clear(); testDataset.getDataPreprocessings().addAll(DATA_PREPROCESSING_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testDataset.getDataPreprocessings()))); - fail("Not yet implemented"); } /** @@ -268,7 +274,6 @@ public void testDatasetgetKnownBiass() throws InvalidSPDXAnalysisException { testDataset.getKnownBiass().clear(); testDataset.getKnownBiass().addAll(KNOWN_BIAS_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(KNOWN_BIAS_TEST_LIST2, new ArrayList<>(testDataset.getKnownBiass()))); - fail("Not yet implemented"); } /** @@ -276,10 +281,9 @@ public void testDatasetgetKnownBiass() throws InvalidSPDXAnalysisException { */ public void testDatasetgetDatasetTypes() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testDataset.getDatasetTypes()))); -// testDataset.getDatasetTypes().clear(); -// testDataset.getDatasetTypes().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testDataset.getDatasetTypes()))); - fail("Not yet implemented"); + assertTrue(UnitTestHelper.isListsEqual(DATASET_TYPE_TEST_LIST1, new ArrayList<>(testDataset.getDatasetTypes()))); + testDataset.getDatasetTypes().clear(); + testDataset.getDatasetTypes().addAll(DATASET_TYPE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DATASET_TYPE_TEST_LIST2, new ArrayList<>(testDataset.getDatasetTypes()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java index 1840365a7..c99a13ea6 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java index 9d6f39910..b1eeea727 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java b/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java index 27b72726b..fb59258f7 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java +++ b/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java b/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java index f60fd6bad..f8910fa3c 100644 --- a/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java +++ b/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java b/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java index 8784bd1c3..7c448b6ca 100644 --- a/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java b/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java index 1bbff7089..7170de5ad 100644 --- a/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java +++ b/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java index b4874bed1..b228ed7b5 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -114,9 +115,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(new Boolean(true), testLicenseAddition.getIsDeprecatedAdditionId()); + assertEquals(Optional.of(new Boolean(true)), testLicenseAddition.getIsDeprecatedAdditionId()); testLicenseAddition.setIsDeprecatedAdditionId(false); - assertEquals(new Boolean(false), testLicenseAddition.getIsDeprecatedAdditionId()); + assertEquals(Optional.of(new Boolean(false)), testLicenseAddition.getIsDeprecatedAdditionId()); } /** @@ -124,9 +125,9 @@ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAna */ public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(STANDARD_ADDITION_TEMPLATE_TEST_VALUE, testLicenseAddition.getStandardAdditionTemplate()); + assertEquals(Optional.of(STANDARD_ADDITION_TEMPLATE_TEST_VALUE), testLicenseAddition.getStandardAdditionTemplate()); testLicenseAddition.setStandardAdditionTemplate("new standardAdditionTemplate value"); - assertEquals("new standardAdditionTemplate value", testLicenseAddition.getStandardAdditionTemplate()); + assertEquals(Optional.of("new standardAdditionTemplate value"), testLicenseAddition.getStandardAdditionTemplate()); } /** diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java index 4d5dc6213..2d39bdb45 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseTest.java b/src/test/java/org/spdx/library/model/licensing/LicenseTest.java index 9ff738145..cb1bf6db3 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseTest.java +++ b/src/test/java/org/spdx/library/model/licensing/LicenseTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -118,9 +119,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(new Boolean(true), testLicense.getIsFsfLibre()); + assertEquals(Optional.of(new Boolean(true)), testLicense.getIsFsfLibre()); testLicense.setIsFsfLibre(false); - assertEquals(new Boolean(false), testLicense.getIsFsfLibre()); + assertEquals(Optional.of(new Boolean(false)), testLicense.getIsFsfLibre()); } /** @@ -128,9 +129,9 @@ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { */ public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(new Boolean(true), testLicense.getIsDeprecatedLicenseId()); + assertEquals(Optional.of(new Boolean(true)), testLicense.getIsDeprecatedLicenseId()); testLicense.setIsDeprecatedLicenseId(false); - assertEquals(new Boolean(false), testLicense.getIsDeprecatedLicenseId()); + assertEquals(Optional.of(new Boolean(false)), testLicense.getIsDeprecatedLicenseId()); } /** @@ -138,9 +139,9 @@ public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisExce */ public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(new Boolean(true), testLicense.getIsOsiApproved()); + assertEquals(Optional.of(new Boolean(true)), testLicense.getIsOsiApproved()); testLicense.setIsOsiApproved(false); - assertEquals(new Boolean(false), testLicense.getIsOsiApproved()); + assertEquals(Optional.of(new Boolean(false)), testLicense.getIsOsiApproved()); } /** @@ -148,9 +149,9 @@ public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { */ public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(STANDARD_LICENSE_TEMPLATE_TEST_VALUE, testLicense.getStandardLicenseTemplate()); + assertEquals(Optional.of(STANDARD_LICENSE_TEMPLATE_TEST_VALUE), testLicense.getStandardLicenseTemplate()); testLicense.setStandardLicenseTemplate("new standardLicenseTemplate value"); - assertEquals("new standardLicenseTemplate value", testLicense.getStandardLicenseTemplate()); + assertEquals(Optional.of("new standardLicenseTemplate value"), testLicense.getStandardLicenseTemplate()); } /** @@ -158,9 +159,9 @@ public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisEx */ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(STANDARD_LICENSE_HEADER_TEST_VALUE, testLicense.getStandardLicenseHeader()); + assertEquals(Optional.of(STANDARD_LICENSE_HEADER_TEST_VALUE), testLicense.getStandardLicenseHeader()); testLicense.setStandardLicenseHeader("new standardLicenseHeader value"); - assertEquals("new standardLicenseHeader value", testLicense.getStandardLicenseHeader()); + assertEquals(Optional.of("new standardLicenseHeader value"), testLicense.getStandardLicenseHeader()); } /** diff --git a/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java b/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java index b403e86c3..4d11b3245 100644 --- a/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java b/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java index 75a3ecb74..6954dc45e 100644 --- a/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java index 4c2191d2f..6c1b2c521 100644 --- a/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java b/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java index 51faa2443..ffa322e47 100644 --- a/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java index ce1d8c9fd..03cf794d4 100644 --- a/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java index f33b83a20..87762c85f 100644 --- a/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java index 0a2b33b21..318d456b8 100644 --- a/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java index 1ae7b8552..1b011a702 100644 --- a/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -42,6 +43,8 @@ public class ExploitCatalogVulnAssessmentRelationshipTest extends TestCase { ModelCopyManager copyManager; static final String LOCATOR_TEST_VALUE = "test locator"; + static final ExploitCatalogType CATALOG_TYPE_TEST_VALUE1 = ExploitCatalogType.values()[0]; + static final ExploitCatalogType CATALOG_TYPE_TEST_VALUE2 = ExploitCatalogType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -58,9 +61,9 @@ public static ExploitCatalogVulnAssessmentRelationshipBuilder builderForExploitC ExploitCatalogVulnAssessmentRelationshipBuilder retval = new ExploitCatalogVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) .setExploited(true) .setLocator(LOCATOR_TEST_VALUE) + .setCatalogType(CATALOG_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setCatalogType(ExploitCatalogType.ENUM) ***************/ ; return retval; @@ -113,10 +116,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testExploitCatalogVulnAssessmentRelationshipsetCatalogType() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getCatalogType()); -// testExploitCatalogVulnAssessmentRelationship.setCatalogType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testExploitCatalogVulnAssessmentRelationship.getCatalogType()); - fail("Not yet implemented"); + assertEquals(CATALOG_TYPE_TEST_VALUE1, testExploitCatalogVulnAssessmentRelationship.getCatalogType()); + testExploitCatalogVulnAssessmentRelationship.setCatalogType(CATALOG_TYPE_TEST_VALUE2); + assertEquals(CATALOG_TYPE_TEST_VALUE2, testExploitCatalogVulnAssessmentRelationship.getCatalogType()); } /** diff --git a/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java index 8e33afbe9..a30c0277c 100644 --- a/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -41,6 +42,8 @@ public class SsvcVulnAssessmentRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final SsvcDecisionType DECISION_TYPE_TEST_VALUE1 = SsvcDecisionType.values()[0]; + static final SsvcDecisionType DECISION_TYPE_TEST_VALUE2 = SsvcDecisionType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -55,9 +58,9 @@ protected void tearDown() throws Exception { public static SsvcVulnAssessmentRelationshipBuilder builderForSsvcVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SsvcVulnAssessmentRelationshipBuilder retval = new SsvcVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setDecisionType(DECISION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setDecisionType(SsvcDecisionType.ENUM) ***************/ ; return retval; @@ -110,9 +113,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSsvcVulnAssessmentRelationshipsetDecisionType() throws InvalidSPDXAnalysisException { SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSsvcVulnAssessmentRelationship.getDecisionType()); -// testSsvcVulnAssessmentRelationship.setDecisionType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSsvcVulnAssessmentRelationship.getDecisionType()); - fail("Not yet implemented"); + assertEquals(DECISION_TYPE_TEST_VALUE1, testSsvcVulnAssessmentRelationship.getDecisionType()); + testSsvcVulnAssessmentRelationship.setDecisionType(DECISION_TYPE_TEST_VALUE2); + assertEquals(DECISION_TYPE_TEST_VALUE2, testSsvcVulnAssessmentRelationship.getDecisionType()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java index 5438d2de6..d0c51be10 100644 --- a/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -118,9 +119,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testVexAffectedVulnAssessmentRelationshipsetActionStatement() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(ACTION_STATEMENT_TEST_VALUE, testVexAffectedVulnAssessmentRelationship.getActionStatement()); + assertEquals(Optional.of(ACTION_STATEMENT_TEST_VALUE), testVexAffectedVulnAssessmentRelationship.getActionStatement()); testVexAffectedVulnAssessmentRelationship.setActionStatement("new actionStatement value"); - assertEquals("new actionStatement value", testVexAffectedVulnAssessmentRelationship.getActionStatement()); + assertEquals(Optional.of("new actionStatement value"), testVexAffectedVulnAssessmentRelationship.getActionStatement()); } /** @@ -132,6 +133,5 @@ public void testVexAffectedVulnAssessmentRelationshipgetActionStatementTimes() t testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().clear(); testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().addAll(ACTION_STATEMENT_TIME_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST2, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); - fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java index 669bbe7d0..dd9be2e56 100644 --- a/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java index 63a3c6931..847f2f3ed 100644 --- a/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -43,6 +44,8 @@ public class VexNotAffectedVulnAssessmentRelationshipTest extends TestCase { static final String IMPACT_STATEMENT_TIME_TEST_VALUE = "test impactStatementTime"; static final String IMPACT_STATEMENT_TEST_VALUE = "test impactStatement"; + static final VexJustificationType JUSTIFICATION_TYPE_TEST_VALUE1 = VexJustificationType.values()[0]; + static final VexJustificationType JUSTIFICATION_TYPE_TEST_VALUE2 = VexJustificationType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -59,9 +62,9 @@ public static VexNotAffectedVulnAssessmentRelationshipBuilder builderForVexNotAf VexNotAffectedVulnAssessmentRelationshipBuilder retval = new VexNotAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) .setImpactStatementTime(IMPACT_STATEMENT_TIME_TEST_VALUE) .setImpactStatement(IMPACT_STATEMENT_TEST_VALUE) + .setJustificationType(JUSTIFICATION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setJustificationType(VexJustificationType.ENUM) ***************/ ; return retval; @@ -114,10 +117,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); -// testVexNotAffectedVulnAssessmentRelationship.setJustificationType(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); - fail("Not yet implemented"); + assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE1), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); + testVexNotAffectedVulnAssessmentRelationship.setJustificationType(JUSTIFICATION_TYPE_TEST_VALUE2); + assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE2), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); } /** @@ -125,9 +127,9 @@ public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() t */ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(IMPACT_STATEMENT_TIME_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + assertEquals(Optional.of(IMPACT_STATEMENT_TIME_TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime("new impactStatementTime value"); - assertEquals("new impactStatementTime value", testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + assertEquals(Optional.of("new impactStatementTime value"), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); } /** @@ -135,8 +137,8 @@ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() */ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatement() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(IMPACT_STATEMENT_TEST_VALUE, testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); + assertEquals(Optional.of(IMPACT_STATEMENT_TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); testVexNotAffectedVulnAssessmentRelationship.setImpactStatement("new impactStatement value"); - assertEquals("new impactStatement value", testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); + assertEquals(Optional.of("new impactStatement value"), testVexNotAffectedVulnAssessmentRelationship.getImpactStatement()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java index 94727920a..770a4f146 100644 --- a/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java index 6a51fcf93..cbb9fa7ad 100644 --- a/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -113,9 +114,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(STATUS_NOTES_TEST_VALUE, testVexVulnAssessmentRelationship.getStatusNotes()); + assertEquals(Optional.of(STATUS_NOTES_TEST_VALUE), testVexVulnAssessmentRelationship.getStatusNotes()); testVexVulnAssessmentRelationship.setStatusNotes("new statusNotes value"); - assertEquals("new statusNotes value", testVexVulnAssessmentRelationship.getStatusNotes()); + assertEquals(Optional.of("new statusNotes value"), testVexVulnAssessmentRelationship.getStatusNotes()); } /** @@ -123,8 +124,8 @@ public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDX */ public void testVexVulnAssessmentRelationshipsetVexVersion() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(VEX_VERSION_TEST_VALUE, testVexVulnAssessmentRelationship.getVexVersion()); + assertEquals(Optional.of(VEX_VERSION_TEST_VALUE), testVexVulnAssessmentRelationship.getVexVersion()); testVexVulnAssessmentRelationship.setVexVersion("new vexVersion value"); - assertEquals("new vexVersion value", testVexVulnAssessmentRelationship.getVexVersion()); + assertEquals(Optional.of("new vexVersion value"), testVexVulnAssessmentRelationship.getVexVersion()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java index fbd253314..13d7ebc9a 100644 --- a/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -111,9 +112,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVulnAssessmentRelationship.getAssessedElement()); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getAssessedElement()); // testVulnAssessmentRelationship.setAssessedElement(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVulnAssessmentRelationship.getAssessedElement()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getAssessedElement()); fail("Not yet implemented"); } @@ -122,9 +123,9 @@ public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPD */ public void testVulnAssessmentRelationshipsetSuppliedBy() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testVulnAssessmentRelationship.getSuppliedBy()); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getSuppliedBy()); // testVulnAssessmentRelationship.setSuppliedBy(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testVulnAssessmentRelationship.getSuppliedBy()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getSuppliedBy()); fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java b/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java index dc1ec9733..463525f9b 100644 --- a/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java +++ b/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; diff --git a/src/test/java/org/spdx/library/model/software/SbomTest.java b/src/test/java/org/spdx/library/model/software/SbomTest.java index 5b8524f2a..036154a09 100644 --- a/src/test/java/org/spdx/library/model/software/SbomTest.java +++ b/src/test/java/org/spdx/library/model/software/SbomTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -41,6 +42,10 @@ public class SbomTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final SBOMType SBOM_TYPE_TEST_VALUE1 = SBOMType.values()[0]; + static final SBOMType SBOM_TYPE_TEST_VALUE2 = SBOMType.values()[1]; + static final List SBOM_TYPE_TEST_LIST1 = Arrays.asList(new SBOMType[] { SBOM_TYPE_TEST_VALUE1, SBOM_TYPE_TEST_VALUE2 }); + static final List SBOM_TYPE_TEST_LIST2 = Arrays.asList(new SBOMType[] { SBOM_TYPE_TEST_VALUE1 }); protected void setUp() throws Exception { super.setUp(); @@ -55,9 +60,10 @@ protected void tearDown() throws Exception { public static SbomBuilder builderForSbomTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SbomBuilder retval = new SbomBuilder(modelStore, objectUri, copyManager) + .addSbomType(SBOM_TYPE_TEST_VALUE1) + .addSbomType(SBOM_TYPE_TEST_VALUE2) //TODO: Add in test values /******************** - .addSbomType(SBOMType.ENUM) ***************/ ; return retval; @@ -110,10 +116,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSbomgetSbomTypes() throws InvalidSPDXAnalysisException { Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSbom.getSbomTypes()))); -// testSbom.getSbomTypes().clear(); -// testSbom.getSbomTypes().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSbom.getSbomTypes()))); - fail("Not yet implemented"); + assertTrue(UnitTestHelper.isListsEqual(SBOM_TYPE_TEST_LIST1, new ArrayList<>(testSbom.getSbomTypes()))); + testSbom.getSbomTypes().clear(); + testSbom.getSbomTypes().addAll(SBOM_TYPE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(SBOM_TYPE_TEST_LIST2, new ArrayList<>(testSbom.getSbomTypes()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SnippetTest.java b/src/test/java/org/spdx/library/model/software/SnippetTest.java index 80aa7c4e5..e5e1623e6 100644 --- a/src/test/java/org/spdx/library/model/software/SnippetTest.java +++ b/src/test/java/org/spdx/library/model/software/SnippetTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -111,9 +112,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSnippetsetByteRange() throws InvalidSPDXAnalysisException { Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSnippet.getByteRange()); +// assertEquals(Optional.of(TEST_VALUE), testSnippet.getByteRange()); // testSnippet.setByteRange(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSnippet.getByteRange()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSnippet.getByteRange()); fail("Not yet implemented"); } @@ -122,9 +123,9 @@ public void testSnippetsetByteRange() throws InvalidSPDXAnalysisException { */ public void testSnippetsetLineRange() throws InvalidSPDXAnalysisException { Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSnippet.getLineRange()); +// assertEquals(Optional.of(TEST_VALUE), testSnippet.getLineRange()); // testSnippet.setLineRange(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSnippet.getLineRange()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSnippet.getLineRange()); fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java b/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java index 33313cded..00c54bd05 100644 --- a/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java +++ b/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -44,6 +45,12 @@ public class SoftwareArtifactTest extends TestCase { static final String CONTENT_IDENTIFIER_TEST_VALUE = "test contentIdentifier"; static final String ATTRIBUTION_TEXT_TEST_VALUE = "test attributionText"; static final String COPYRIGHT_TEXT_TEST_VALUE = "test copyrightText"; + static final SoftwarePurpose PRIMARY_PURPOSE_TEST_VALUE1 = SoftwarePurpose.values()[0]; + static final SoftwarePurpose PRIMARY_PURPOSE_TEST_VALUE2 = SoftwarePurpose.values()[1]; + static final SoftwarePurpose ADDITIONAL_PURPOSE_TEST_VALUE1 = SoftwarePurpose.values()[0]; + static final SoftwarePurpose ADDITIONAL_PURPOSE_TEST_VALUE2 = SoftwarePurpose.values()[1]; + static final List ADDITIONAL_PURPOSE_TEST_LIST1 = Arrays.asList(new SoftwarePurpose[] { ADDITIONAL_PURPOSE_TEST_VALUE1, ADDITIONAL_PURPOSE_TEST_VALUE2 }); + static final List ADDITIONAL_PURPOSE_TEST_LIST2 = Arrays.asList(new SoftwarePurpose[] { ADDITIONAL_PURPOSE_TEST_VALUE1 }); protected void setUp() throws Exception { super.setUp(); @@ -61,12 +68,13 @@ public static SoftwareArtifactBuilder builderForSoftwareArtifactTests( .setContentIdentifier(CONTENT_IDENTIFIER_TEST_VALUE) .setAttributionText(ATTRIBUTION_TEXT_TEST_VALUE) .setCopyrightText(COPYRIGHT_TEXT_TEST_VALUE) + .setPrimaryPurpose(PRIMARY_PURPOSE_TEST_VALUE1) + .addAdditionalPurpose(ADDITIONAL_PURPOSE_TEST_VALUE1) + .addAdditionalPurpose(ADDITIONAL_PURPOSE_TEST_VALUE2) //TODO: Add in test values /******************** .setDeclaredLicense(TEST_ANYLICENSE_INFO) .setConcludedLicense(TEST_ANYLICENSE_INFO) - .setPrimaryPurpose(SoftwarePurpose.ENUM) - .addAdditionalPurpose(SoftwarePurpose.ENUM) ***************/ ; return retval; @@ -119,9 +127,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSoftwareArtifactsetDeclaredLicense() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareArtifact.getDeclaredLicense()); +// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); // testSoftwareArtifact.setDeclaredLicense(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getDeclaredLicense()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); fail("Not yet implemented"); } @@ -130,9 +138,9 @@ public void testSoftwareArtifactsetDeclaredLicense() throws InvalidSPDXAnalysisE */ public void testSoftwareArtifactsetConcludedLicense() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareArtifact.getConcludedLicense()); +// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); // testSoftwareArtifact.setConcludedLicense(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getConcludedLicense()); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); fail("Not yet implemented"); } @@ -141,10 +149,9 @@ public void testSoftwareArtifactsetConcludedLicense() throws InvalidSPDXAnalysis */ public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareArtifact.getPrimaryPurpose()); -// testSoftwareArtifact.setPrimaryPurpose(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareArtifact.getPrimaryPurpose()); - fail("Not yet implemented"); + assertEquals(Optional.of(PRIMARY_PURPOSE_TEST_VALUE1), testSoftwareArtifact.getPrimaryPurpose()); + testSoftwareArtifact.setPrimaryPurpose(PRIMARY_PURPOSE_TEST_VALUE2); + assertEquals(Optional.of(PRIMARY_PURPOSE_TEST_VALUE2), testSoftwareArtifact.getPrimaryPurpose()); } /** @@ -152,9 +159,9 @@ public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisEx */ public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(CONTENT_IDENTIFIER_TEST_VALUE, testSoftwareArtifact.getContentIdentifier()); + assertEquals(Optional.of(CONTENT_IDENTIFIER_TEST_VALUE), testSoftwareArtifact.getContentIdentifier()); testSoftwareArtifact.setContentIdentifier("new contentIdentifier value"); - assertEquals("new contentIdentifier value", testSoftwareArtifact.getContentIdentifier()); + assertEquals(Optional.of("new contentIdentifier value"), testSoftwareArtifact.getContentIdentifier()); } /** @@ -162,9 +169,9 @@ public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysi */ public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(ATTRIBUTION_TEXT_TEST_VALUE, testSoftwareArtifact.getAttributionText()); + assertEquals(Optional.of(ATTRIBUTION_TEXT_TEST_VALUE), testSoftwareArtifact.getAttributionText()); testSoftwareArtifact.setAttributionText("new attributionText value"); - assertEquals("new attributionText value", testSoftwareArtifact.getAttributionText()); + assertEquals(Optional.of("new attributionText value"), testSoftwareArtifact.getAttributionText()); } /** @@ -172,9 +179,9 @@ public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisE */ public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(COPYRIGHT_TEXT_TEST_VALUE, testSoftwareArtifact.getCopyrightText()); + assertEquals(Optional.of(COPYRIGHT_TEXT_TEST_VALUE), testSoftwareArtifact.getCopyrightText()); testSoftwareArtifact.setCopyrightText("new copyrightText value"); - assertEquals("new copyrightText value", testSoftwareArtifact.getCopyrightText()); + assertEquals(Optional.of("new copyrightText value"), testSoftwareArtifact.getCopyrightText()); } /** @@ -182,10 +189,9 @@ public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisExc */ public void testSoftwareArtifactgetAdditionalPurposes() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEqual(TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurposes()))); -// testSoftwareArtifact.getAdditionalPurposes().clear(); -// testSoftwareArtifact.getAdditionalPurposes().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEqual(NEW_TEST_VALUE, new ArrayList<>(testSoftwareArtifact.getAdditionalPurposes()))); - fail("Not yet implemented"); + assertTrue(UnitTestHelper.isListsEqual(ADDITIONAL_PURPOSE_TEST_LIST1, new ArrayList<>(testSoftwareArtifact.getAdditionalPurposes()))); + testSoftwareArtifact.getAdditionalPurposes().clear(); + testSoftwareArtifact.getAdditionalPurposes().addAll(ADDITIONAL_PURPOSE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(ADDITIONAL_PURPOSE_TEST_LIST2, new ArrayList<>(testSoftwareArtifact.getAdditionalPurposes()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java b/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java index 03fe8dc09..62de02a8d 100644 --- a/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -41,6 +42,10 @@ public class SoftwareDependencyRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final SoftwareDependencyLinkType SOFTWARE_LINKAGE_TEST_VALUE1 = SoftwareDependencyLinkType.values()[0]; + static final SoftwareDependencyLinkType SOFTWARE_LINKAGE_TEST_VALUE2 = SoftwareDependencyLinkType.values()[1]; + static final DependencyConditionalityType CONDITIONALITY_TEST_VALUE1 = DependencyConditionalityType.values()[0]; + static final DependencyConditionalityType CONDITIONALITY_TEST_VALUE2 = DependencyConditionalityType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -55,10 +60,10 @@ protected void tearDown() throws Exception { public static SoftwareDependencyRelationshipBuilder builderForSoftwareDependencyRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SoftwareDependencyRelationshipBuilder retval = new SoftwareDependencyRelationshipBuilder(modelStore, objectUri, copyManager) + .setSoftwareLinkage(SOFTWARE_LINKAGE_TEST_VALUE1) + .setConditionality(CONDITIONALITY_TEST_VALUE1) //TODO: Add in test values /******************** - .setSoftwareLinkage(SoftwareDependencyLinkType.ENUM) - .setConditionality(DependencyConditionalityType.ENUM) ***************/ ; return retval; @@ -111,10 +116,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSoftwareDependencyRelationshipsetSoftwareLinkage() throws InvalidSPDXAnalysisException { SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareDependencyRelationship.getSoftwareLinkage()); -// testSoftwareDependencyRelationship.setSoftwareLinkage(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareDependencyRelationship.getSoftwareLinkage()); - fail("Not yet implemented"); + assertEquals(Optional.of(SOFTWARE_LINKAGE_TEST_VALUE1), testSoftwareDependencyRelationship.getSoftwareLinkage()); + testSoftwareDependencyRelationship.setSoftwareLinkage(SOFTWARE_LINKAGE_TEST_VALUE2); + assertEquals(Optional.of(SOFTWARE_LINKAGE_TEST_VALUE2), testSoftwareDependencyRelationship.getSoftwareLinkage()); } /** @@ -122,9 +126,8 @@ public void testSoftwareDependencyRelationshipsetSoftwareLinkage() throws Invali */ public void testSoftwareDependencyRelationshipsetConditionality() throws InvalidSPDXAnalysisException { SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testSoftwareDependencyRelationship.getConditionality()); -// testSoftwareDependencyRelationship.setConditionality(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testSoftwareDependencyRelationship.getConditionality()); - fail("Not yet implemented"); + assertEquals(Optional.of(CONDITIONALITY_TEST_VALUE1), testSoftwareDependencyRelationship.getConditionality()); + testSoftwareDependencyRelationship.setConditionality(CONDITIONALITY_TEST_VALUE2); + assertEquals(Optional.of(CONDITIONALITY_TEST_VALUE2), testSoftwareDependencyRelationship.getConditionality()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SpdxFileTest.java b/src/test/java/org/spdx/library/model/software/SpdxFileTest.java index 31641b4ce..259f59f7f 100644 --- a/src/test/java/org/spdx/library/model/software/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/software/SpdxFileTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -111,8 +112,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSpdxFilesetContentType() throws InvalidSPDXAnalysisException { SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(CONTENT_TYPE_TEST_VALUE, testSpdxFile.getContentType()); + assertEquals(Optional.of(CONTENT_TYPE_TEST_VALUE), testSpdxFile.getContentType()); testSpdxFile.setContentType("new contentType value"); - assertEquals("new contentType value", testSpdxFile.getContentType()); + assertEquals(Optional.of("new contentType value"), testSpdxFile.getContentType()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java index 5cc267b17..75f1d828a 100644 --- a/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; @@ -119,9 +120,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(DOWNLOAD_LOCATION_TEST_VALUE, testSpdxPackage.getDownloadLocation()); + assertEquals(Optional.of(DOWNLOAD_LOCATION_TEST_VALUE), testSpdxPackage.getDownloadLocation()); testSpdxPackage.setDownloadLocation("new downloadLocation value"); - assertEquals("new downloadLocation value", testSpdxPackage.getDownloadLocation()); + assertEquals(Optional.of("new downloadLocation value"), testSpdxPackage.getDownloadLocation()); } /** @@ -129,9 +130,9 @@ public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisExcep */ public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(SOURCE_INFO_TEST_VALUE, testSpdxPackage.getSourceInfo()); + assertEquals(Optional.of(SOURCE_INFO_TEST_VALUE), testSpdxPackage.getSourceInfo()); testSpdxPackage.setSourceInfo("new sourceInfo value"); - assertEquals("new sourceInfo value", testSpdxPackage.getSourceInfo()); + assertEquals(Optional.of("new sourceInfo value"), testSpdxPackage.getSourceInfo()); } /** @@ -139,9 +140,9 @@ public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { */ public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(PACKAGE_VERSION_TEST_VALUE, testSpdxPackage.getPackageVersion()); + assertEquals(Optional.of(PACKAGE_VERSION_TEST_VALUE), testSpdxPackage.getPackageVersion()); testSpdxPackage.setPackageVersion("new packageVersion value"); - assertEquals("new packageVersion value", testSpdxPackage.getPackageVersion()); + assertEquals(Optional.of("new packageVersion value"), testSpdxPackage.getPackageVersion()); } /** @@ -149,9 +150,9 @@ public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisExcepti */ public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(HOME_PAGE_TEST_VALUE, testSpdxPackage.getHomePage()); + assertEquals(Optional.of(HOME_PAGE_TEST_VALUE), testSpdxPackage.getHomePage()); testSpdxPackage.setHomePage("new homePage value"); - assertEquals("new homePage value", testSpdxPackage.getHomePage()); + assertEquals(Optional.of("new homePage value"), testSpdxPackage.getHomePage()); } /** @@ -159,8 +160,8 @@ public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { */ public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(PACKAGE_URL_TEST_VALUE, testSpdxPackage.getPackageUrl()); + assertEquals(Optional.of(PACKAGE_URL_TEST_VALUE), testSpdxPackage.getPackageUrl()); testSpdxPackage.setPackageUrl("new packageUrl value"); - assertEquals("new packageUrl value", testSpdxPackage.getPackageUrl()); + assertEquals(Optional.of("new packageUrl value"), testSpdxPackage.getPackageUrl()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java index 19be55e68..941715b65 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxComparerTest.java @@ -49,6 +49,10 @@ import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; @@ -63,10 +67,6 @@ import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java index 5e1436913..5b52d7972 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxFileComparerTest.java @@ -31,12 +31,12 @@ import org.spdx.library.model.compat.v2.Checksum; import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxFile; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.InvalidLicenseStringException; import org.spdx.library.model.compat.v2.license.License; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java index 585380818..cf3f6bd6a 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxItemComparerTest.java @@ -32,10 +32,10 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxElement; import org.spdx.library.model.compat.v2.SpdxItem; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.RelationshipType; import org.spdx.storage.IModelStore.IdType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java index 6b58bd316..5cacdd423 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxPackageComparerTest.java @@ -39,13 +39,13 @@ import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxPackage; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.enumerations.AnnotationType; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.enumerations.AnnotationType; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.ReferenceCategory; -import org.spdx.library.model.enumerations.RelationshipType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java index f7b8ac716..f3865094f 100644 --- a/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java +++ b/src/test/java/org/spdx/utility/compare/SpdxSnippetComparerTest.java @@ -31,14 +31,14 @@ import org.spdx.library.model.compat.v2.SpdxDocument; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxSnippet; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; +import org.spdx.library.model.compat.v2.enumerations.RelationshipType; import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; import org.spdx.library.model.compat.v2.pointer.LineCharPointer; import org.spdx.library.model.compat.v2.pointer.StartEndPointer; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; -import org.spdx.library.model.enumerations.RelationshipType; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java index 1f441ecdc..9e777e974 100644 --- a/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java +++ b/src/test/java/org/spdx/utility/verificationcode/VerificationCodeGeneratorTest.java @@ -10,9 +10,9 @@ import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.SpdxFile; import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.compat.v2.enumerations.FileType; import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.enumerations.FileType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; From 23f13f3f2d3b0267ccd1e46b74a66f33d0d6d9fa Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Mon, 24 Jul 2023 15:50:07 -0700 Subject: [PATCH 22/62] Update to newly generated files Signed-off-by: Gary O'Neall --- .../java/org/spdx/library/SpdxConstants.java | 244 ++++++++------- .../org/spdx/library/SpdxEnumFactory.java | 80 ++--- .../spdx/library/SpdxIndividualFactory.java | 2 +- .../library/model/core/AnonymousPayload.java | 157 ---------- .../spdx/library/model/core/NamespaceMap.java | 245 --------------- .../org/spdx/library/model/core/Payload.java | 279 ----------------- .../library/model/{ => v3}/ai/AIPackage.java | 272 ++++++++--------- .../model/{ => v3}/ai/PresenceType.java | 8 +- .../{ => v3}/ai/SafetyRiskAssessmentType.java | 10 +- .../library/model/{ => v3}/build/Build.java | 237 +++++++------- .../library/model/{ => v3}/core/Agent.java | 2 +- .../model/{ => v3}/core/Annotation.java | 64 +++- .../model/{ => v3}/core/AnnotationType.java | 8 +- .../library/model/{ => v3}/core/Artifact.java | 179 ++++++----- .../spdx/library/model/{ => v3}/core/Bom.java | 2 +- .../library/model/{ => v3}/core/Bundle.java | 4 +- .../model/{ => v3}/core/CreationInfo.java | 259 +++++++++------- .../model/{ => v3}/core/DictionaryEntry.java | 6 +- .../library/model/{ => v3}/core/Element.java | 217 +++++++++++-- .../{ => v3}/core/ElementCollection.java | 79 +++-- .../{ => v3}/core/ExternalIdentifier.java | 66 ++-- .../{ => v3}/core/ExternalIdentifierType.java | 20 +- .../model/{ => v3}/core/ExternalMap.java | 92 +++--- .../{ => v3}/core/ExternalReference.java | 83 ++--- .../{ => v3}/core/ExternalReferenceType.java | 65 ++-- .../library/model/{ => v3}/core/Hash.java | 6 +- .../model/{ => v3}/core/HashAlgorithm.java | 48 +-- .../model/{ => v3}/core/IntegrityMethod.java | 4 +- .../{ => v3}/core/LifecycleScopeType.java | 14 +- .../core/LifecycleScopedRelationship.java | 4 +- .../model/{ => v3}/core/Organization.java | 2 +- .../library/model/{ => v3}/core/Person.java | 2 +- .../{ => v3}/core/PositiveIntegerRange.java | 86 +++--- .../{ => v3}/core/ProfileIdentifierType.java | 14 +- .../model/{ => v3}/core/Relationship.java | 184 ++++++----- .../core/RelationshipCompleteness.java | 8 +- .../model/{ => v3}/core/RelationshipType.java | 102 +++---- .../model/{ => v3}/core/SoftwareAgent.java | 2 +- .../model/{ => v3}/core/SpdxDocument.java | 47 ++- .../library/model/{ => v3}/core/Tool.java | 2 +- .../dataset/ConfidentialityLevelType.java | 8 +- .../model/{ => v3}/dataset/Dataset.java | 42 +-- .../dataset/DatasetAvailabilityType.java | 8 +- .../model/{ => v3}/dataset/DatasetType.java | 24 +- .../ConjunctiveLicenseSet.java | 47 ++- .../DisjunctiveLicenseSet.java | 47 ++- .../{ => v3}/licensing/AnyLicenseInfo.java | 4 +- .../{ => v3}/licensing/CustomLicense.java | 2 +- .../licensing/CustomLicenseAddition.java | 2 +- .../licensing}/ExtendableLicense.java | 5 +- .../model/{ => v3}/licensing/License.java | 97 ++++-- .../{ => v3}/licensing/LicenseAddition.java | 44 ++- .../{ => v3}/licensing/LicenseExpression.java | 4 +- .../{ => v3}/licensing/ListedLicense.java | 72 ++++- .../licensing/ListedLicenseException.java | 72 ++++- .../{ => v3}/licensing/OrLaterOperator.java | 60 +++- .../licensing/WithAdditionOperator.java | 111 ++++++- .../CvssV2VulnAssessmentRelationship.java | 117 ++++++- .../CvssV3VulnAssessmentRelationship.java | 117 ++++++- .../EpssVulnAssessmentRelationship.java | 44 ++- .../{ => v3}/security/ExploitCatalogType.java | 4 +- ...loitCatalogVulnAssessmentRelationship.java | 8 +- .../{ => v3}/security/SsvcDecisionType.java | 8 +- .../SsvcVulnAssessmentRelationship.java | 4 +- ...VexAffectedVulnAssessmentRelationship.java | 22 +- .../VexFixedVulnAssessmentRelationship.java | 2 +- .../security/VexJustificationType.java | 10 +- ...NotAffectedVulnAssessmentRelationship.java | 80 +++-- ...vestigationVulnAssessmentRelationship.java | 2 +- .../VexVulnAssessmentRelationship.java | 6 +- .../security/VulnAssessmentRelationship.java | 212 +++++++++++-- .../{ => v3}/security/Vulnerability.java | 148 ++++++++- .../DependencyConditionalityType.java | 8 +- .../library/model/{ => v3}/software/Sbom.java | 18 +- .../software/SbomType.java} | 16 +- .../model/{ => v3}/software/Snippet.java | 66 ++-- .../{ => v3}/software/SoftwareArtifact.java | 158 +++++----- .../software/SoftwareDependencyLinkType.java | 6 +- .../SoftwareDependencyRelationship.java | 8 +- .../{ => v3}/software/SoftwarePurpose.java | 42 +-- .../model/{ => v3}/software/SpdxFile.java | 30 +- .../model/{ => v3}/software/SpdxPackage.java | 108 +++---- .../java/org/spdx/library/SimpleUriValue.java | 2 +- .../java/org/spdx/library/TypedValue.java | 2 + .../spdx/library/model/ExternalElement.java | 36 +-- .../spdx/library/model/ModelCollection.java | 2 +- .../org/spdx/library/model/ModelObject.java | 16 +- .../spdx/library/model/ModelObjectHelper.java | 2 +- .../java/org/spdx/library/model/ModelSet.java | 2 +- .../library/model/ModelObjectForTesting.java | 131 ++++++++ .../spdx/library/model/ModelObjectTest.java | 289 +++++++++++++++--- .../library/model/SimpleUriValueTest.java | 1 - .../model/core/AnonymousPayloadTest.java | 107 ------- .../library/model/core/NamespaceMapTest.java | 131 -------- .../spdx/library/model/core/PayloadTest.java | 145 --------- .../model/{ => v3}/ai/AIPackageTest.java | 150 ++++----- .../model/{ => v3}/build/BuildTest.java | 116 +++---- .../model/{ => v3}/core/AgentTest.java | 12 +- .../model/{ => v3}/core/AnnotationTest.java | 33 +- .../model/{ => v3}/core/ArtifactTest.java | 80 ++--- .../library/model/{ => v3}/core/BomTest.java | 12 +- .../model/{ => v3}/core/BundleTest.java | 14 +- .../model/{ => v3}/core/CreationInfoTest.java | 112 +++---- .../{ => v3}/core/DictionaryEntryTest.java | 16 +- .../{ => v3}/core/ElementCollectionTest.java | 41 ++- .../model/{ => v3}/core/ElementTest.java | 91 ++++-- .../{ => v3}/core/ExternalIdentifierTest.java | 46 +-- .../model/{ => v3}/core/ExternalMapTest.java | 42 +-- .../{ => v3}/core/ExternalReferenceTest.java | 40 +-- .../library/model/{ => v3}/core/HashTest.java | 16 +- .../{ => v3}/core/IntegrityMethodTest.java | 14 +- .../core/LifecycleScopedRelationshipTest.java | 14 +- .../model/{ => v3}/core/OrganizationTest.java | 12 +- .../model/{ => v3}/core/PersonTest.java | 12 +- .../core/PositiveIntegerRangeTest.java | 36 +-- .../model/{ => v3}/core/RelationshipTest.java | 70 ++--- .../{ => v3}/core/SoftwareAgentTest.java | 12 +- .../model/{ => v3}/core/SpdxDocumentTest.java | 24 +- .../library/model/{ => v3}/core/ToolTest.java | 12 +- .../model/{ => v3}/dataset/DatasetTest.java | 38 +-- .../ConjunctiveLicenseSetTest.java | 25 +- .../DisjunctiveLicenseSetTest.java | 25 +- .../licensing/AnyLicenseInfoTest.java | 12 +- .../licensing/CustomLicenseAdditionTest.java | 12 +- .../{ => v3}/licensing/CustomLicenseTest.java | 12 +- .../licensing}/ExtendableLicenseTest.java | 14 +- .../licensing/LicenseAdditionTest.java | 30 +- .../licensing/LicenseExpressionTest.java | 14 +- .../model/{ => v3}/licensing/LicenseTest.java | 54 ++-- .../licensing/ListedLicenseExceptionTest.java | 36 ++- .../{ => v3}/licensing/ListedLicenseTest.java | 36 ++- .../licensing/OrLaterOperatorTest.java | 24 +- .../licensing/WithAdditionOperatorTest.java | 36 ++- .../CvssV2VulnAssessmentRelationshipTest.java | 48 ++- .../CvssV3VulnAssessmentRelationshipTest.java | 48 ++- .../EpssVulnAssessmentRelationshipTest.java | 26 +- ...CatalogVulnAssessmentRelationshipTest.java | 18 +- .../SsvcVulnAssessmentRelationshipTest.java | 14 +- ...ffectedVulnAssessmentRelationshipTest.java | 33 +- ...exFixedVulnAssessmentRelationshipTest.java | 12 +- ...ffectedVulnAssessmentRelationshipTest.java | 38 +-- ...igationVulnAssessmentRelationshipTest.java | 12 +- .../VexVulnAssessmentRelationshipTest.java | 16 +- .../VulnAssessmentRelationshipTest.java | 64 +++- .../{ => v3}/security/VulnerabilityTest.java | 48 ++- .../model/{ => v3}/software/SbomTest.java | 22 +- .../model/{ => v3}/software/SnippetTest.java | 34 +-- .../software/SoftwareArtifactTest.java | 66 ++-- .../SoftwareDependencyRelationshipTest.java | 16 +- .../model/{ => v3}/software/SpdxFileTest.java | 24 +- .../{ => v3}/software/SpdxPackageTest.java | 62 ++-- 151 files changed, 4542 insertions(+), 3418 deletions(-) delete mode 100644 generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java delete mode 100644 generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java delete mode 100644 generated/src/main/java/org/spdx/library/model/core/Payload.java rename generated/src/main/java/org/spdx/library/model/{ => v3}/ai/AIPackage.java (92%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/ai/PresenceType.java (91%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/ai/SafetyRiskAssessmentType.java (91%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/build/Build.java (84%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Agent.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Annotation.java (81%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/AnnotationType.java (90%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Artifact.java (77%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Bom.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Bundle.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/CreationInfo.java (69%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/DictionaryEntry.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Element.java (63%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ElementCollection.java (82%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ExternalIdentifier.java (95%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ExternalIdentifierType.java (88%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ExternalMap.java (96%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ExternalReference.java (88%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ExternalReferenceType.java (89%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Hash.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/HashAlgorithm.java (73%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/IntegrityMethod.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/LifecycleScopeType.java (90%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/LifecycleScopedRelationship.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Organization.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Person.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/PositiveIntegerRange.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/ProfileIdentifierType.java (92%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Relationship.java (83%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/RelationshipCompleteness.java (89%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/RelationshipType.java (95%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/SoftwareAgent.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/SpdxDocument.java (79%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/core/Tool.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/dataset/ConfidentialityLevelType.java (90%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/dataset/Dataset.java (93%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/dataset/DatasetAvailabilityType.java (89%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/dataset/DatasetType.java (92%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/expandedlicense/ConjunctiveLicenseSet.java (78%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/expandedlicense/DisjunctiveLicenseSet.java (78%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/AnyLicenseInfo.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/CustomLicense.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/CustomLicenseAddition.java (99%) rename generated/src/main/java/org/spdx/library/model/{expandedlicense => v3/licensing}/ExtendableLicense.java (97%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/License.java (88%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/LicenseAddition.java (87%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/LicenseExpression.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/ListedLicense.java (68%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/ListedLicenseException.java (69%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/OrLaterOperator.java (74%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/licensing/WithAdditionOperator.java (58%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/CvssV2VulnAssessmentRelationship.java (67%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/CvssV3VulnAssessmentRelationship.java (67%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/EpssVulnAssessmentRelationship.java (83%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/ExploitCatalogType.java (92%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/ExploitCatalogVulnAssessmentRelationship.java (97%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/SsvcDecisionType.java (91%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/SsvcVulnAssessmentRelationship.java (98%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VexAffectedVulnAssessmentRelationship.java (89%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VexFixedVulnAssessmentRelationship.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VexJustificationType.java (90%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VexNotAffectedVulnAssessmentRelationship.java (89%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VexUnderInvestigationVulnAssessmentRelationship.java (99%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VexVulnAssessmentRelationship.java (97%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/VulnAssessmentRelationship.java (56%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/security/Vulnerability.java (62%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/DependencyConditionalityType.java (91%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/Sbom.java (92%) rename generated/src/main/java/org/spdx/library/model/{software/SBOMType.java => v3/software/SbomType.java} (87%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/Snippet.java (97%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/SoftwareArtifact.java (89%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/SoftwareDependencyLinkType.java (91%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/SoftwareDependencyRelationship.java (96%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/SoftwarePurpose.java (93%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/SpdxFile.java (86%) rename generated/src/main/java/org/spdx/library/model/{ => v3}/software/SpdxPackage.java (96%) create mode 100644 src/test/java/org/spdx/library/model/ModelObjectForTesting.java delete mode 100644 src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java delete mode 100644 src/test/java/org/spdx/library/model/core/NamespaceMapTest.java delete mode 100644 src/test/java/org/spdx/library/model/core/PayloadTest.java rename src/test/java/org/spdx/library/model/{ => v3}/ai/AIPackageTest.java (89%) rename src/test/java/org/spdx/library/model/{ => v3}/build/BuildTest.java (82%) rename src/test/java/org/spdx/library/model/{ => v3}/core/AgentTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/AnnotationTest.java (77%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ArtifactTest.java (75%) rename src/test/java/org/spdx/library/model/{ => v3}/core/BomTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/BundleTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/CreationInfoTest.java (62%) rename src/test/java/org/spdx/library/model/{ => v3}/core/DictionaryEntryTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ElementCollectionTest.java (76%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ElementTest.java (64%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ExternalIdentifierTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ExternalMapTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ExternalReferenceTest.java (83%) rename src/test/java/org/spdx/library/model/{ => v3}/core/HashTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/IntegrityMethodTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/core/LifecycleScopedRelationshipTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/core/OrganizationTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/PersonTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/core/PositiveIntegerRangeTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/core/RelationshipTest.java (78%) rename src/test/java/org/spdx/library/model/{ => v3}/core/SoftwareAgentTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/core/SpdxDocumentTest.java (76%) rename src/test/java/org/spdx/library/model/{ => v3}/core/ToolTest.java (87%) rename src/test/java/org/spdx/library/model/{ => v3}/dataset/DatasetTest.java (88%) rename src/test/java/org/spdx/library/model/{ => v3}/expandedlicense/ConjunctiveLicenseSetTest.java (72%) rename src/test/java/org/spdx/library/model/{ => v3}/expandedlicense/DisjunctiveLicenseSetTest.java (72%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/AnyLicenseInfoTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/CustomLicenseAdditionTest.java (85%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/CustomLicenseTest.java (86%) rename src/test/java/org/spdx/library/model/{expandedlicense => v3/licensing}/ExtendableLicenseTest.java (83%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/LicenseAdditionTest.java (77%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/LicenseExpressionTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/LicenseTest.java (79%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/ListedLicenseExceptionTest.java (62%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/ListedLicenseTest.java (63%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/OrLaterOperatorTest.java (75%) rename src/test/java/org/spdx/library/model/{ => v3}/licensing/WithAdditionOperatorTest.java (65%) rename src/test/java/org/spdx/library/model/{ => v3}/security/CvssV2VulnAssessmentRelationshipTest.java (58%) rename src/test/java/org/spdx/library/model/{ => v3}/security/CvssV3VulnAssessmentRelationshipTest.java (58%) rename src/test/java/org/spdx/library/model/{ => v3}/security/EpssVulnAssessmentRelationshipTest.java (74%) rename src/test/java/org/spdx/library/model/{ => v3}/security/ExploitCatalogVulnAssessmentRelationshipTest.java (85%) rename src/test/java/org/spdx/library/model/{ => v3}/security/SsvcVulnAssessmentRelationshipTest.java (85%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VexAffectedVulnAssessmentRelationshipTest.java (71%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VexFixedVulnAssessmentRelationshipTest.java (85%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VexNotAffectedVulnAssessmentRelationshipTest.java (79%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java (84%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VexVulnAssessmentRelationshipTest.java (85%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VulnAssessmentRelationshipTest.java (62%) rename src/test/java/org/spdx/library/model/{ => v3}/security/VulnerabilityTest.java (59%) rename src/test/java/org/spdx/library/model/{ => v3}/software/SbomTest.java (80%) rename src/test/java/org/spdx/library/model/{ => v3}/software/SnippetTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/software/SoftwareArtifactTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/software/SoftwareDependencyRelationshipTest.java (86%) rename src/test/java/org/spdx/library/model/{ => v3}/software/SpdxFileTest.java (79%) rename src/test/java/org/spdx/library/model/{ => v3}/software/SpdxPackageTest.java (86%) diff --git a/generated/src/main/java/org/spdx/library/SpdxConstants.java b/generated/src/main/java/org/spdx/library/SpdxConstants.java index 6459129b7..8a2b61931 100644 --- a/generated/src/main/java/org/spdx/library/SpdxConstants.java +++ b/generated/src/main/java/org/spdx/library/SpdxConstants.java @@ -39,7 +39,7 @@ public static SpdxMajorVersion latestVersion() { /** * AI namespace */ - public static final String A_I_NAMESPACE = "https://spdx.org/rdf/AI"; + public static final String A_I_NAMESPACE = "https://spdx.org/rdf/v3/AI"; public static final PropertyDescriptor A_I_PROP_AUTONOMY_TYPE = new PropertyDescriptor("autonomyType", A_I_NAMESPACE); public static final PropertyDescriptor A_I_PROP_DOMAIN = new PropertyDescriptor("domain", A_I_NAMESPACE); public static final PropertyDescriptor A_I_PROP_ENERGY_CONSUMPTION = new PropertyDescriptor("energyConsumption", A_I_NAMESPACE); @@ -59,7 +59,7 @@ public static SpdxMajorVersion latestVersion() { /** * Build namespace */ - public static final String BUILD_NAMESPACE = "https://spdx.org/rdf/Build"; + public static final String BUILD_NAMESPACE = "https://spdx.org/rdf/v3/Build"; public static final PropertyDescriptor BUILD_PROP_BUILD_END_TIME = new PropertyDescriptor("buildEndTime", BUILD_NAMESPACE); public static final PropertyDescriptor BUILD_PROP_BUILD_ID = new PropertyDescriptor("buildId", BUILD_NAMESPACE); public static final PropertyDescriptor BUILD_PROP_BUILD_START_TIME = new PropertyDescriptor("buildStartTime", BUILD_NAMESPACE); @@ -73,7 +73,7 @@ public static SpdxMajorVersion latestVersion() { /** * Core namespace */ - public static final String CORE_NAMESPACE = "https://spdx.org/rdf/Core"; + public static final String CORE_NAMESPACE = "https://spdx.org/rdf/v3/Core"; public static final PropertyDescriptor CORE_PROP_ALGORITHM = new PropertyDescriptor("algorithm", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_ANNOTATION_TYPE = new PropertyDescriptor("annotationType", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_BEGIN = new PropertyDescriptor("begin", CORE_NAMESPACE); @@ -106,10 +106,8 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor CORE_PROP_KEY = new PropertyDescriptor("key", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_LOCATION_HINT = new PropertyDescriptor("locationHint", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_LOCATOR = new PropertyDescriptor("locator", CORE_NAMESPACE); - public static final PropertyDescriptor CORE_PROP_NAMESPACE = new PropertyDescriptor("namespace", CORE_NAMESPACE); - public static final PropertyDescriptor CORE_PROP_NAMESPACES = new PropertyDescriptor("namespaces", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_NAME = new PropertyDescriptor("name", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_ORIGINATED_BY = new PropertyDescriptor("originatedBy", CORE_NAMESPACE); - public static final PropertyDescriptor CORE_PROP_PREFIX = new PropertyDescriptor("prefix", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_PROFILE = new PropertyDescriptor("profile", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_RELATIONSHIP_TYPE = new PropertyDescriptor("relationshipType", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_RELEASE_TIME = new PropertyDescriptor("releaseTime", CORE_NAMESPACE); @@ -130,7 +128,7 @@ public static SpdxMajorVersion latestVersion() { /** * Dataset namespace */ - public static final String DATASET_NAMESPACE = "https://spdx.org/rdf/Dataset"; + public static final String DATASET_NAMESPACE = "https://spdx.org/rdf/v3/Dataset"; public static final PropertyDescriptor DATASET_PROP_ANONYMIZATION_METHOD_USED = new PropertyDescriptor("anonymizationMethodUsed", DATASET_NAMESPACE); public static final PropertyDescriptor DATASET_PROP_CONFIDENTIALITY_LEVEL = new PropertyDescriptor("confidentialityLevel", DATASET_NAMESPACE); public static final PropertyDescriptor DATASET_PROP_DATA_COLLECTION_PROCESS = new PropertyDescriptor("dataCollectionProcess", DATASET_NAMESPACE); @@ -145,25 +143,36 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION = new PropertyDescriptor("sensitivePersonalInformation", DATASET_NAMESPACE); public static final PropertyDescriptor DATASET_PROP_SENSOR = new PropertyDescriptor("sensor", DATASET_NAMESPACE); + /** + * ExpandedLicense namespace + */ + public static final String EXPANDED_LICENSE_NAMESPACE = "https://spdx.org/rdf/v3/ExpandedLicense"; + public static final PropertyDescriptor EXPANDED_LICENSE_PROP_MEMBER = new PropertyDescriptor("member", EXPANDED_LICENSE_NAMESPACE); + /** * Licensing namespace */ - public static final String LICENSING_NAMESPACE = "https://spdx.org/rdf/Licensing"; + public static final String LICENSING_NAMESPACE = "https://spdx.org/rdf/v3/Licensing"; public static final PropertyDescriptor LICENSING_PROP_ADDITION_TEXT = new PropertyDescriptor("additionText", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_DEPRECATED_VERSION = new PropertyDescriptor("deprecatedVersion", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_IS_DEPRECATED_ADDITION_ID = new PropertyDescriptor("isDeprecatedAdditionId", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_IS_DEPRECATED_LICENSE_ID = new PropertyDescriptor("isDeprecatedLicenseId", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_IS_FSF_LIBRE = new PropertyDescriptor("isFsfLibre", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_IS_OSI_APPROVED = new PropertyDescriptor("isOsiApproved", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_LICENSE_EXPRESSION = new PropertyDescriptor("licenseExpression", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_LICENSE_TEXT = new PropertyDescriptor("licenseText", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_LIST_VERSION_ADDED = new PropertyDescriptor("listVersionAdded", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_OBSOLETED_BY = new PropertyDescriptor("obsoletedBy", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_STANDARD_ADDITION_TEMPLATE = new PropertyDescriptor("standardAdditionTemplate", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_STANDARD_LICENSE_HEADER = new PropertyDescriptor("standardLicenseHeader", LICENSING_NAMESPACE); public static final PropertyDescriptor LICENSING_PROP_STANDARD_LICENSE_TEMPLATE = new PropertyDescriptor("standardLicenseTemplate", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_SUBJECT_ADDITION = new PropertyDescriptor("subjectAddition", LICENSING_NAMESPACE); + public static final PropertyDescriptor LICENSING_PROP_SUBJECT_LICENSE = new PropertyDescriptor("subjectLicense", LICENSING_NAMESPACE); /** * Security namespace */ - public static final String SECURITY_NAMESPACE = "https://spdx.org/rdf/Security"; + public static final String SECURITY_NAMESPACE = "https://spdx.org/rdf/v3/Security"; public static final PropertyDescriptor SECURITY_PROP_ACTION_STATEMENT = new PropertyDescriptor("actionStatement", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_ACTION_STATEMENT_TIME = new PropertyDescriptor("actionStatementTime", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_ASSESSED_ELEMENT = new PropertyDescriptor("assessedElement", SECURITY_NAMESPACE); @@ -174,15 +183,21 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor SECURITY_PROP_IMPACT_STATEMENT_TIME = new PropertyDescriptor("impactStatementTime", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_JUSTIFICATION_TYPE = new PropertyDescriptor("justificationType", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_LOCATOR = new PropertyDescriptor("locator", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_MODIFIED_TIME = new PropertyDescriptor("modifiedTime", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_PROBABILITY = new PropertyDescriptor("probability", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_PUBLISHED_TIME = new PropertyDescriptor("publishedTime", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_SCORE = new PropertyDescriptor("score", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_SEVERITY = new PropertyDescriptor("severity", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_STATUS_NOTES = new PropertyDescriptor("statusNotes", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_SUPPLIED_BY = new PropertyDescriptor("suppliedBy", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_VECTOR = new PropertyDescriptor("vector", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_VEX_VERSION = new PropertyDescriptor("vexVersion", SECURITY_NAMESPACE); + public static final PropertyDescriptor SECURITY_PROP_WITHDRAWN_TIME = new PropertyDescriptor("withdrawnTime", SECURITY_NAMESPACE); /** * Software namespace */ - public static final String SOFTWARE_NAMESPACE = "https://spdx.org/rdf/Software"; + public static final String SOFTWARE_NAMESPACE = "https://spdx.org/rdf/v3/Software"; public static final PropertyDescriptor SOFTWARE_PROP_ADDITIONAL_PURPOSE = new PropertyDescriptor("additionalPurpose", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_ATTRIBUTION_TEXT = new PropertyDescriptor("attributionText", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_BYTE_RANGE = new PropertyDescriptor("byteRange", SOFTWARE_NAMESPACE); @@ -203,113 +218,106 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor SOFTWARE_PROP_SOURCE_INFO = new PropertyDescriptor("sourceInfo", SOFTWARE_NAMESPACE); // class types - static final String SOFTWARE_SOFTWARE_PURPOSE = "Software.SoftwarePurpose"; - static final String DATASET_DATASET = "Dataset.Dataset"; - static final String CORE_SEM_VER = "Core.SemVer"; - static final String CORE_LIFECYCLE_SCOPE_TYPE = "Core.LifecycleScopeType"; - static final String LICENSING_WITH_ADDITION_OPERATOR = "Licensing.WithAdditionOperator"; - static final String SECURITY_VEX_JUSTIFICATION_TYPE = "Security.VexJustificationType"; - static final String SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE = "Software.SoftwareDependencyLinkType"; - static final String DATASET_CONFIDENTIALITY_LEVEL_TYPE = "Dataset.ConfidentialityLevelType"; - static final String SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP = "Software.SoftwareDependencyRelationship"; - static final String CORE_HASH_ALGORITHM = "Core.HashAlgorithm"; - static final String CORE_EXTERNAL_REFERENCE_TYPE = "Core.ExternalReferenceType"; - static final String SOFTWARE_SNIPPET = "Software.Snippet"; - static final String SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP = "Security.SsvcVulnAssessmentRelationship"; - static final String SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexUnderInvestigationVulnAssessmentRelationship"; - static final String CORE_ANONYMOUS_PAYLOAD = "Core.AnonymousPayload"; - static final String LICENSING_LICENSE_ADDITION = "Licensing.LicenseAddition"; - static final String DATASET_DATASET_TYPE = "Dataset.DatasetType"; - static final String LICENSING_OR_LATER_OPERATOR = "Licensing.OrLaterOperator"; - static final String CORE_POSITIVE_INTEGER_RANGE = "Core.PositiveIntegerRange"; - static final String DATASET_DATASET_AVAILABILITY_TYPE = "Dataset.DatasetAvailabilityType"; - static final String SOFTWARE_S_B_O_M_TYPE = "Software.SBOMType"; - static final String SECURITY_VULN_ASSESSMENT_RELATIONSHIP = "Security.VulnAssessmentRelationship"; - static final String SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP = "Security.EpssVulnAssessmentRelationship"; - static final String EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET = "ExpandedLicense.ConjunctiveLicenseSet"; - static final String SECURITY_CVSS_V_2_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV2VulnAssessmentRelationship"; - static final String CORE_RELATIONSHIP_COMPLETENESS = "Core.RelationshipCompleteness"; - static final String CORE_PROFILE_IDENTIFIER_TYPE = "Core.ProfileIdentifierType"; - static final String SOFTWARE_SOFTWARE_ARTIFACT = "Software.SoftwareArtifact"; - static final String LICENSING_LISTED_LICENSE = "Licensing.ListedLicense"; - static final String SECURITY_SSVC_DECISION_TYPE = "Security.SsvcDecisionType"; - static final String SOFTWARE_SPDX_FILE = "Software.SpdxFile"; - static final String CORE_ANNOTATION = "Core.Annotation"; - static final String CORE_MEDIA_TYPE = "Core.MediaType"; - static final String CORE_TOOL = "Core.Tool"; - static final String CORE_EXTERNAL_MAP = "Core.ExternalMap"; - static final String CORE_EXTERNAL_IDENTIFIER = "Core.ExternalIdentifier"; - static final String CORE_ANNOTATION_TYPE = "Core.AnnotationType"; - static final String LICENSING_ANY_LICENSE_INFO = "Licensing.AnyLicenseInfo"; - static final String CORE_ELEMENT_COLLECTION = "Core.ElementCollection"; - static final String CORE_HASH = "Core.Hash"; - static final String A_I_SAFETY_RISK_ASSESSMENT_TYPE = "AI.SafetyRiskAssessmentType"; - static final String SECURITY_CVSS_V_3_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV3VulnAssessmentRelationship"; - static final String LICENSING_LICENSE_EXPRESSION = "Licensing.LicenseExpression"; - static final String CORE_LIFECYCLE_SCOPED_RELATIONSHIP = "Core.LifecycleScopedRelationship"; - static final String LICENSING_LICENSE = "Licensing.License"; - static final String SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE = "Software.DependencyConditionalityType"; - static final String CORE_INTEGRITY_METHOD = "Core.IntegrityMethod"; - static final String CORE_BUNDLE = "Core.Bundle"; - static final String SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP = "Security.ExploitCatalogVulnAssessmentRelationship"; - static final String CORE_ARTIFACT = "Core.Artifact"; - static final String LICENSING_CUSTOM_LICENSE = "Licensing.CustomLicense"; - static final String CORE_EXTERNAL_REFERENCE = "Core.ExternalReference"; - static final String CORE_DICTIONARY_ENTRY = "Core.DictionaryEntry"; - static final String EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET = "ExpandedLicense.DisjunctiveLicenseSet"; - static final String LICENSING_LISTED_LICENSE_EXCEPTION = "Licensing.ListedLicenseException"; - static final String CORE_EXTERNAL_IDENTIFIER_TYPE = "Core.ExternalIdentifierType"; - static final String SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexNotAffectedVulnAssessmentRelationship"; - static final String CORE_ELEMENT = "Core.Element"; - static final String SECURITY_VULNERABILITY = "Security.Vulnerability"; - static final String CORE_NAMESPACE_MAP = "Core.NamespaceMap"; - static final String CORE_PERSON = "Core.Person"; - static final String SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexVulnAssessmentRelationship"; - static final String CORE_ORGANIZATION = "Core.Organization"; - static final String SECURITY_EXPLOIT_CATALOG_TYPE = "Security.ExploitCatalogType"; - static final String CORE_CREATION_INFO = "Core.CreationInfo"; - static final String CORE_RELATIONSHIP = "Core.Relationship"; - static final String SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexAffectedVulnAssessmentRelationship"; - static final String BUILD_BUILD = "Build.Build"; - static final String SOFTWARE_SPDX_PACKAGE = "Software.SpdxPackage"; - static final String SOFTWARE_SBOM = "Software.Sbom"; - static final String CORE_SPDX_DOCUMENT = "Core.SpdxDocument"; - static final String SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexFixedVulnAssessmentRelationship"; - static final String A_I_A_I_PACKAGE = "AI.AIPackage"; - static final String CORE_PAYLOAD = "Core.Payload"; - static final String A_I_PRESENCE_TYPE = "AI.PresenceType"; - static final String LICENSING_CUSTOM_LICENSE_ADDITION = "Licensing.CustomLicenseAddition"; - static final String CORE_BOM = "Core.Bom"; - static final String CORE_SOFTWARE_AGENT = "Core.SoftwareAgent"; - static final String EXPANDED_LICENSE_EXTENDABLE_LICENSE = "ExpandedLicense.ExtendableLicense"; - static final String CORE_AGENT = "Core.Agent"; - static final String CORE_DATE_TIME = "Core.DateTime"; - static final String CORE_RELATIONSHIP_TYPE = "Core.RelationshipType"; + public static final String CORE_DICTIONARY_ENTRY = "Core.DictionaryEntry"; + public static final String DATASET_CONFIDENTIALITY_LEVEL_TYPE = "Dataset.ConfidentialityLevelType"; + public static final String CORE_BOM = "Core.Bom"; + public static final String A_I_SAFETY_RISK_ASSESSMENT_TYPE = "AI.SafetyRiskAssessmentType"; + public static final String LICENSING_LICENSE_EXPRESSION = "Licensing.LicenseExpression"; + public static final String LICENSING_CUSTOM_LICENSE_ADDITION = "Licensing.CustomLicenseAddition"; + public static final String CORE_ANNOTATION = "Core.Annotation"; + public static final String SOFTWARE_SPDX_FILE = "Software.SpdxFile"; + public static final String SOFTWARE_SOFTWARE_ARTIFACT = "Software.SoftwareArtifact"; + public static final String SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexAffectedVulnAssessmentRelationship"; + public static final String DATASET_DATASET = "Dataset.Dataset"; + public static final String SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP = "Security.SsvcVulnAssessmentRelationship"; + public static final String LICENSING_LISTED_LICENSE = "Licensing.ListedLicense"; + public static final String CORE_INTEGRITY_METHOD = "Core.IntegrityMethod"; + public static final String SOFTWARE_SNIPPET = "Software.Snippet"; + public static final String LICENSING_LICENSE_ADDITION = "Licensing.LicenseAddition"; + public static final String SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP = "Security.EpssVulnAssessmentRelationship"; + public static final String LICENSING_EXTENDABLE_LICENSE = "Licensing.ExtendableLicense"; + public static final String EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET = "ExpandedLicense.ConjunctiveLicenseSet"; + public static final String LICENSING_WITH_ADDITION_OPERATOR = "Licensing.WithAdditionOperator"; + public static final String SOFTWARE_SBOM_TYPE = "Software.SbomType"; + public static final String CORE_TOOL = "Core.Tool"; + public static final String CORE_EXTERNAL_IDENTIFIER = "Core.ExternalIdentifier"; + public static final String CORE_ELEMENT_COLLECTION = "Core.ElementCollection"; + public static final String CORE_ANNOTATION_TYPE = "Core.AnnotationType"; + public static final String SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP = "Software.SoftwareDependencyRelationship"; + public static final String SECURITY_VEX_JUSTIFICATION_TYPE = "Security.VexJustificationType"; + public static final String A_I_A_I_PACKAGE = "AI.AIPackage"; + public static final String LICENSING_ANY_LICENSE_INFO = "Licensing.AnyLicenseInfo"; + public static final String SECURITY_EXPLOIT_CATALOG_TYPE = "Security.ExploitCatalogType"; + public static final String LICENSING_LISTED_LICENSE_EXCEPTION = "Licensing.ListedLicenseException"; + public static final String A_I_PRESENCE_TYPE = "AI.PresenceType"; + public static final String SOFTWARE_SOFTWARE_PURPOSE = "Software.SoftwarePurpose"; + public static final String CORE_ELEMENT = "Core.Element"; + public static final String CORE_PERSON = "Core.Person"; + public static final String SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE = "Software.DependencyConditionalityType"; + public static final String DATASET_DATASET_AVAILABILITY_TYPE = "Dataset.DatasetAvailabilityType"; + public static final String LICENSING_OR_LATER_OPERATOR = "Licensing.OrLaterOperator"; + public static final String CORE_EXTERNAL_MAP = "Core.ExternalMap"; + public static final String LICENSING_LICENSE = "Licensing.License"; + public static final String SECURITY_VULN_ASSESSMENT_RELATIONSHIP = "Security.VulnAssessmentRelationship"; + public static final String CORE_AGENT = "Core.Agent"; + public static final String SOFTWARE_SPDX_PACKAGE = "Software.SpdxPackage"; + public static final String CORE_EXTERNAL_IDENTIFIER_TYPE = "Core.ExternalIdentifierType"; + public static final String SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE = "Software.SoftwareDependencyLinkType"; + public static final String CORE_POSITIVE_INTEGER_RANGE = "Core.PositiveIntegerRange"; + public static final String CORE_HASH = "Core.Hash"; + public static final String DATASET_DATASET_TYPE = "Dataset.DatasetType"; + public static final String CORE_EXTERNAL_REFERENCE = "Core.ExternalReference"; + public static final String CORE_SPDX_DOCUMENT = "Core.SpdxDocument"; + public static final String SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexVulnAssessmentRelationship"; + public static final String SECURITY_CVSS_V2_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV2VulnAssessmentRelationship"; + public static final String EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET = "ExpandedLicense.DisjunctiveLicenseSet"; + public static final String CORE_BUNDLE = "Core.Bundle"; + public static final String SOFTWARE_SBOM = "Software.Sbom"; + public static final String CORE_LIFECYCLE_SCOPE_TYPE = "Core.LifecycleScopeType"; + public static final String SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexUnderInvestigationVulnAssessmentRelationship"; + public static final String SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexFixedVulnAssessmentRelationship"; + public static final String CORE_HASH_ALGORITHM = "Core.HashAlgorithm"; + public static final String SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP = "Security.ExploitCatalogVulnAssessmentRelationship"; + public static final String CORE_SOFTWARE_AGENT = "Core.SoftwareAgent"; + public static final String CORE_CREATION_INFO = "Core.CreationInfo"; + public static final String SECURITY_CVSS_V3_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV3VulnAssessmentRelationship"; + public static final String CORE_ORGANIZATION = "Core.Organization"; + public static final String CORE_RELATIONSHIP = "Core.Relationship"; + public static final String LICENSING_CUSTOM_LICENSE = "Licensing.CustomLicense"; + public static final String CORE_RELATIONSHIP_TYPE = "Core.RelationshipType"; + public static final String CORE_RELATIONSHIP_COMPLETENESS = "Core.RelationshipCompleteness"; + public static final String CORE_ARTIFACT = "Core.Artifact"; + public static final String CORE_LIFECYCLE_SCOPED_RELATIONSHIP = "Core.LifecycleScopedRelationship"; + public static final String SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexNotAffectedVulnAssessmentRelationship"; + public static final String CORE_PROFILE_IDENTIFIER_TYPE = "Core.ProfileIdentifierType"; + public static final String BUILD_BUILD = "Build.Build"; + public static final String SECURITY_SSVC_DECISION_TYPE = "Security.SsvcDecisionType"; + public static final String SECURITY_VULNERABILITY = "Security.Vulnerability"; + public static final String CORE_EXTERNAL_REFERENCE_TYPE = "Core.ExternalReferenceType"; - static final String[] ALL_SPDX_CLASSES = {SOFTWARE_SOFTWARE_PURPOSE, DATASET_DATASET, CORE_SEM_VER, - CORE_LIFECYCLE_SCOPE_TYPE, LICENSING_WITH_ADDITION_OPERATOR, SECURITY_VEX_JUSTIFICATION_TYPE, - SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE, DATASET_CONFIDENTIALITY_LEVEL_TYPE, - SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP, CORE_HASH_ALGORITHM, CORE_EXTERNAL_REFERENCE_TYPE, - SOFTWARE_SNIPPET, SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP, - CORE_ANONYMOUS_PAYLOAD, LICENSING_LICENSE_ADDITION, DATASET_DATASET_TYPE, - LICENSING_OR_LATER_OPERATOR, CORE_POSITIVE_INTEGER_RANGE, DATASET_DATASET_AVAILABILITY_TYPE, - SOFTWARE_S_B_O_M_TYPE, SECURITY_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP, - EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET, SECURITY_CVSS_V_2_VULN_ASSESSMENT_RELATIONSHIP, - CORE_RELATIONSHIP_COMPLETENESS, CORE_PROFILE_IDENTIFIER_TYPE, SOFTWARE_SOFTWARE_ARTIFACT, - LICENSING_LISTED_LICENSE, SECURITY_SSVC_DECISION_TYPE, SOFTWARE_SPDX_FILE, - CORE_ANNOTATION, CORE_MEDIA_TYPE, CORE_TOOL, CORE_EXTERNAL_MAP, CORE_EXTERNAL_IDENTIFIER, - CORE_ANNOTATION_TYPE, LICENSING_ANY_LICENSE_INFO, CORE_ELEMENT_COLLECTION, - CORE_HASH, A_I_SAFETY_RISK_ASSESSMENT_TYPE, SECURITY_CVSS_V_3_VULN_ASSESSMENT_RELATIONSHIP, - LICENSING_LICENSE_EXPRESSION, CORE_LIFECYCLE_SCOPED_RELATIONSHIP, LICENSING_LICENSE, - SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE, CORE_INTEGRITY_METHOD, CORE_BUNDLE, - SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP, CORE_ARTIFACT, LICENSING_CUSTOM_LICENSE, - CORE_EXTERNAL_REFERENCE, CORE_DICTIONARY_ENTRY, EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET, - LICENSING_LISTED_LICENSE_EXCEPTION, CORE_EXTERNAL_IDENTIFIER_TYPE, SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, - CORE_ELEMENT, SECURITY_VULNERABILITY, CORE_NAMESPACE_MAP, CORE_PERSON, - SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP, CORE_ORGANIZATION, SECURITY_EXPLOIT_CATALOG_TYPE, - CORE_CREATION_INFO, CORE_RELATIONSHIP, SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, - BUILD_BUILD, SOFTWARE_SPDX_PACKAGE, SOFTWARE_SBOM, CORE_SPDX_DOCUMENT, - SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP, A_I_A_I_PACKAGE, CORE_PAYLOAD, - A_I_PRESENCE_TYPE, LICENSING_CUSTOM_LICENSE_ADDITION, CORE_BOM, CORE_SOFTWARE_AGENT, - EXPANDED_LICENSE_EXTENDABLE_LICENSE, CORE_AGENT, CORE_DATE_TIME, CORE_RELATIONSHIP_TYPE}; + public static final String[] ALL_SPDX_CLASSES = {CORE_DICTIONARY_ENTRY, DATASET_CONFIDENTIALITY_LEVEL_TYPE, + CORE_BOM, A_I_SAFETY_RISK_ASSESSMENT_TYPE, LICENSING_LICENSE_EXPRESSION, + LICENSING_CUSTOM_LICENSE_ADDITION, CORE_ANNOTATION, SOFTWARE_SPDX_FILE, + SOFTWARE_SOFTWARE_ARTIFACT, SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, + DATASET_DATASET, SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP, LICENSING_LISTED_LICENSE, + CORE_INTEGRITY_METHOD, SOFTWARE_SNIPPET, LICENSING_LICENSE_ADDITION, SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP, + LICENSING_EXTENDABLE_LICENSE, EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET, + LICENSING_WITH_ADDITION_OPERATOR, SOFTWARE_SBOM_TYPE, CORE_TOOL, CORE_EXTERNAL_IDENTIFIER, + CORE_ELEMENT_COLLECTION, CORE_ANNOTATION_TYPE, SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP, + SECURITY_VEX_JUSTIFICATION_TYPE, A_I_A_I_PACKAGE, LICENSING_ANY_LICENSE_INFO, + SECURITY_EXPLOIT_CATALOG_TYPE, LICENSING_LISTED_LICENSE_EXCEPTION, A_I_PRESENCE_TYPE, + SOFTWARE_SOFTWARE_PURPOSE, CORE_ELEMENT, CORE_PERSON, SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE, + DATASET_DATASET_AVAILABILITY_TYPE, LICENSING_OR_LATER_OPERATOR, CORE_EXTERNAL_MAP, + LICENSING_LICENSE, SECURITY_VULN_ASSESSMENT_RELATIONSHIP, CORE_AGENT, SOFTWARE_SPDX_PACKAGE, + CORE_EXTERNAL_IDENTIFIER_TYPE, SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE, + CORE_POSITIVE_INTEGER_RANGE, CORE_HASH, DATASET_DATASET_TYPE, CORE_EXTERNAL_REFERENCE, + CORE_SPDX_DOCUMENT, SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_CVSS_V2_VULN_ASSESSMENT_RELATIONSHIP, + EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET, CORE_BUNDLE, SOFTWARE_SBOM, CORE_LIFECYCLE_SCOPE_TYPE, + SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP, + CORE_HASH_ALGORITHM, SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP, + CORE_SOFTWARE_AGENT, CORE_CREATION_INFO, SECURITY_CVSS_V3_VULN_ASSESSMENT_RELATIONSHIP, + CORE_ORGANIZATION, CORE_RELATIONSHIP, LICENSING_CUSTOM_LICENSE, CORE_RELATIONSHIP_TYPE, + CORE_RELATIONSHIP_COMPLETENESS, CORE_ARTIFACT, CORE_LIFECYCLE_SCOPED_RELATIONSHIP, + SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, CORE_PROFILE_IDENTIFIER_TYPE, + BUILD_BUILD, SECURITY_SSVC_DECISION_TYPE, SECURITY_VULNERABILITY, CORE_EXTERNAL_REFERENCE_TYPE}; } diff --git a/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java b/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java index 7a8f0bbed..94ce6192e 100644 --- a/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java +++ b/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java @@ -22,26 +22,26 @@ import java.util.HashMap; import java.util.Map; -import org.spdx.library.model.ai.PresenceType; -import org.spdx.library.model.ai.SafetyRiskAssessmentType; -import org.spdx.library.model.core.AnnotationType; -import org.spdx.library.model.core.ExternalIdentifierType; -import org.spdx.library.model.core.ExternalReferenceType; -import org.spdx.library.model.core.HashAlgorithm; -import org.spdx.library.model.core.LifecycleScopeType; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.core.RelationshipCompleteness; -import org.spdx.library.model.core.RelationshipType; -import org.spdx.library.model.dataset.ConfidentialityLevelType; -import org.spdx.library.model.dataset.DatasetAvailabilityType; -import org.spdx.library.model.dataset.DatasetType; -import org.spdx.library.model.security.ExploitCatalogType; -import org.spdx.library.model.security.SsvcDecisionType; -import org.spdx.library.model.security.VexJustificationType; -import org.spdx.library.model.software.DependencyConditionalityType; -import org.spdx.library.model.software.SBOMType; -import org.spdx.library.model.software.SoftwareDependencyLinkType; -import org.spdx.library.model.software.SoftwarePurpose; +import org.spdx.library.model.v3.ai.PresenceType; +import org.spdx.library.model.v3.ai.SafetyRiskAssessmentType; +import org.spdx.library.model.v3.core.AnnotationType; +import org.spdx.library.model.v3.core.ExternalIdentifierType; +import org.spdx.library.model.v3.core.ExternalReferenceType; +import org.spdx.library.model.v3.core.HashAlgorithm; +import org.spdx.library.model.v3.core.LifecycleScopeType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.RelationshipCompleteness; +import org.spdx.library.model.v3.core.RelationshipType; +import org.spdx.library.model.v3.dataset.ConfidentialityLevelType; +import org.spdx.library.model.v3.dataset.DatasetAvailabilityType; +import org.spdx.library.model.v3.dataset.DatasetType; +import org.spdx.library.model.v3.security.ExploitCatalogType; +import org.spdx.library.model.v3.security.SsvcDecisionType; +import org.spdx.library.model.v3.security.VexJustificationType; +import org.spdx.library.model.v3.software.DependencyConditionalityType; +import org.spdx.library.model.v3.software.SbomType; +import org.spdx.library.model.v3.software.SoftwareDependencyLinkType; +import org.spdx.library.model.v3.software.SoftwarePurpose; /** * *** DO NOT EDIT *** @@ -59,83 +59,83 @@ public class SpdxEnumFactory { static { Map> map = new HashMap<>(); - for (SoftwarePurpose enumVal:SoftwarePurpose.values()) { + for (ConfidentialityLevelType enumVal:ConfidentialityLevelType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (LifecycleScopeType enumVal:LifecycleScopeType.values()) { + for (SafetyRiskAssessmentType enumVal:SafetyRiskAssessmentType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (VexJustificationType enumVal:VexJustificationType.values()) { + for (SbomType enumVal:SbomType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (SoftwareDependencyLinkType enumVal:SoftwareDependencyLinkType.values()) { + for (AnnotationType enumVal:AnnotationType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (ConfidentialityLevelType enumVal:ConfidentialityLevelType.values()) { + for (VexJustificationType enumVal:VexJustificationType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (HashAlgorithm enumVal:HashAlgorithm.values()) { + for (ExploitCatalogType enumVal:ExploitCatalogType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (ExternalReferenceType enumVal:ExternalReferenceType.values()) { + for (PresenceType enumVal:PresenceType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (DatasetType enumVal:DatasetType.values()) { + for (SoftwarePurpose enumVal:SoftwarePurpose.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (DatasetAvailabilityType enumVal:DatasetAvailabilityType.values()) { + for (DependencyConditionalityType enumVal:DependencyConditionalityType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (SBOMType enumVal:SBOMType.values()) { + for (DatasetAvailabilityType enumVal:DatasetAvailabilityType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (RelationshipCompleteness enumVal:RelationshipCompleteness.values()) { + for (ExternalIdentifierType enumVal:ExternalIdentifierType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (ProfileIdentifierType enumVal:ProfileIdentifierType.values()) { + for (SoftwareDependencyLinkType enumVal:SoftwareDependencyLinkType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (SsvcDecisionType enumVal:SsvcDecisionType.values()) { + for (DatasetType enumVal:DatasetType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (AnnotationType enumVal:AnnotationType.values()) { + for (LifecycleScopeType enumVal:LifecycleScopeType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (SafetyRiskAssessmentType enumVal:SafetyRiskAssessmentType.values()) { + for (HashAlgorithm enumVal:HashAlgorithm.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (DependencyConditionalityType enumVal:DependencyConditionalityType.values()) { + for (RelationshipType enumVal:RelationshipType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (ExternalIdentifierType enumVal:ExternalIdentifierType.values()) { + for (RelationshipCompleteness enumVal:RelationshipCompleteness.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (ExploitCatalogType enumVal:ExploitCatalogType.values()) { + for (ProfileIdentifierType enumVal:ProfileIdentifierType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (PresenceType enumVal:PresenceType.values()) { + for (SsvcDecisionType enumVal:SsvcDecisionType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (RelationshipType enumVal:RelationshipType.values()) { + for (ExternalReferenceType enumVal:ExternalReferenceType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } uriToEnum = Collections.unmodifiableMap(map); diff --git a/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java b/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java index af57c946c..6d18107e0 100644 --- a/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java +++ b/generated/src/main/java/org/spdx/library/SpdxIndividualFactory.java @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.Map; -import org.spdx.library.model.core.Element; +import org.spdx.library.model.v3.core.Element; /** diff --git a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java b/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java deleted file mode 100644 index 6e580846c..000000000 --- a/generated/src/main/java/org/spdx/library/model/core/AnonymousPayload.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.ModelObject; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.IModelStore.IModelStoreLock; - - -/** - * DO NOT EDIT - this file is generated by the Owl to Java Utility - * See: https://github.com/spdx/tools-java - * - * TODO - */ -public class AnonymousPayload extends Payload { - - - /** - * Create the AnonymousPayload with default model store and generated anonymous ID - * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload - */ - public AnonymousPayload() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * @param objectUri URI or anonymous ID for the AnonymousPayload - * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload - */ - public AnonymousPayload(String objectUri) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore Model store where the AnonymousPayload is to be stored - * @param objectUri URI or anonymous ID for the AnonymousPayload - * @param copyManager Copy manager for the AnonymousPayload - can be null if copying is not required - * @param create true if AnonymousPayload is to be created - * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload - */ - public AnonymousPayload(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /** - * Create the AnonymousPayload from the builder - used in the builder class - * @param builder Builder to create the AnonymousPayload from - * @throws InvalidSPDXAnalysisException when unable to create the AnonymousPayload - */ - protected AnonymousPayload(AnonymousPayloadBuilder builder) throws InvalidSPDXAnalysisException { - super(builder); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() - */ - @Override - public String getType() { - return "Core.AnonymousPayload"; - } - - // Getters and Setters - - - - @Override - public String toString() { - return "AnonymousPayload: "+getObjectUri(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { - List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - return retval; - } - - public static class AnonymousPayloadBuilder extends PayloadBuilder { - - /** - * Create an AnonymousPayloadBuilder from another model object copying the modelStore and copyManager and using an anonymous ID - * @param from model object to copy the model store and copyManager from - * @throws InvalidSPDXAnalysisException - */ - public AnonymousPayloadBuilder(ModelObject from) throws InvalidSPDXAnalysisException { - this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * Create an AnonymousPayloadBuilder from another model object copying the modelStore and copyManager - * @param from model object to copy the model store and copyManager from - * @param objectUri URI for the object - * @param objectUri - */ - public AnonymousPayloadBuilder(ModelObject from, String objectUri) { - this(from.getModelStore(), objectUri, from.getCopyManager()); - setStrict(from.isStrict()); - } - - /** - * Creates a AnonymousPayloadBuilder - * @param modelStore model store for the built AnonymousPayload - * @param objectUri objectUri for the built AnonymousPayload - * @param copyManager optional copyManager for the built AnonymousPayload - */ - public AnonymousPayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { - super(modelStore, objectUri, copyManager); - } - - - - - /** - * @return the AnonymousPayload - * @throws InvalidSPDXAnalysisException on any errors during build - */ - public AnonymousPayload build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new AnonymousPayload(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } -} diff --git a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java b/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java deleted file mode 100644 index 049c48c2a..000000000 --- a/generated/src/main/java/org/spdx/library/model/core/NamespaceMap.java +++ /dev/null @@ -1,245 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.ModelObject; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.IModelStore.IModelStoreLock; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Objects; -import java.util.Optional; -import org.spdx.library.SpdxConstants; - -/** - * DO NOT EDIT - this file is generated by the Owl to Java Utility - * See: https://github.com/spdx/tools-java - * - * A namespace map allows the creator of a collection of Elements to use shorter identifiers - * ("prefixes") instead of URIs to provide a more human-readable and smaller serialized - * representation of the Elements. - */ -public class NamespaceMap extends ModelObject { - - - /** - * Create the NamespaceMap with default model store and generated anonymous ID - * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap - */ - public NamespaceMap() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * @param objectUri URI or anonymous ID for the NamespaceMap - * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap - */ - public NamespaceMap(String objectUri) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore Model store where the NamespaceMap is to be stored - * @param objectUri URI or anonymous ID for the NamespaceMap - * @param copyManager Copy manager for the NamespaceMap - can be null if copying is not required - * @param create true if NamespaceMap is to be created - * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap - */ - public NamespaceMap(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /** - * Create the NamespaceMap from the builder - used in the builder class - * @param builder Builder to create the NamespaceMap from - * @throws InvalidSPDXAnalysisException when unable to create the NamespaceMap - */ - protected NamespaceMap(NamespaceMapBuilder builder) throws InvalidSPDXAnalysisException { - super(builder); - setPrefix(builder.prefix); - setNamespace(builder.namespace); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() - */ - @Override - public String getType() { - return "Core.NamespaceMap"; - } - - // Getters and Setters - - - /** - * @return the prefix - */ - public @Nullable String getPrefix() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_PREFIX); - return retval.isPresent() ? retval.get() : null; - } - /** - * @param prefix the prefix to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public NamespaceMap setPrefix(@Nullable String prefix) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(prefix)) { - throw new InvalidSPDXAnalysisException("prefix is a required property"); - } - setPropertyValue(SpdxConstants.CORE_PROP_PREFIX, prefix); - return this; - } - - /** - * @return the namespace - */ - public @Nullable String getNamespace() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_NAMESPACE); - return retval.isPresent() ? retval.get() : null; - } - /** - * @param namespace the namespace to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public NamespaceMap setNamespace(@Nullable String namespace) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(namespace)) { - throw new InvalidSPDXAnalysisException("namespace is a required property"); - } - setPropertyValue(SpdxConstants.CORE_PROP_NAMESPACE, namespace); - return this; - } - - - @Override - public String toString() { - return "NamespaceMap: "+getObjectUri(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { - List retval = new ArrayList<>(); - try { - String prefix = getPrefix(); - if (Objects.isNull(prefix) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing prefix in NamespaceMap"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting prefix for NamespaceMap: "+e.getMessage()); - } - try { - String namespace = getNamespace(); - if (Objects.isNull(namespace) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing namespace in NamespaceMap"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting namespace for NamespaceMap: "+e.getMessage()); - } - return retval; - } - - public static class NamespaceMapBuilder extends ModelObjectBuilder { - - /** - * Create an NamespaceMapBuilder from another model object copying the modelStore and copyManager and using an anonymous ID - * @param from model object to copy the model store and copyManager from - * @throws InvalidSPDXAnalysisException - */ - public NamespaceMapBuilder(ModelObject from) throws InvalidSPDXAnalysisException { - this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * Create an NamespaceMapBuilder from another model object copying the modelStore and copyManager - * @param from model object to copy the model store and copyManager from - * @param objectUri URI for the object - * @param objectUri - */ - public NamespaceMapBuilder(ModelObject from, String objectUri) { - this(from.getModelStore(), objectUri, from.getCopyManager()); - setStrict(from.isStrict()); - } - - /** - * Creates a NamespaceMapBuilder - * @param modelStore model store for the built NamespaceMap - * @param objectUri objectUri for the built NamespaceMap - * @param copyManager optional copyManager for the built NamespaceMap - */ - public NamespaceMapBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { - super(modelStore, objectUri, copyManager); - } - - String prefix = null; - String namespace = null; - - - /** - * Sets the initial value of prefix - * @parameter prefix value to set - * @return this for chaining - **/ - NamespaceMapBuilder setPrefix(String prefix) { - this.prefix = prefix; - return this; - } - - /** - * Sets the initial value of namespace - * @parameter namespace value to set - * @return this for chaining - **/ - NamespaceMapBuilder setNamespace(String namespace) { - this.namespace = namespace; - return this; - } - - - /** - * @return the NamespaceMap - * @throws InvalidSPDXAnalysisException on any errors during build - */ - public NamespaceMap build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new NamespaceMap(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } -} diff --git a/generated/src/main/java/org/spdx/library/model/core/Payload.java b/generated/src/main/java/org/spdx/library/model/core/Payload.java deleted file mode 100644 index d084827ca..000000000 --- a/generated/src/main/java/org/spdx/library/model/core/Payload.java +++ /dev/null @@ -1,279 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.ModelObject; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.IModelStore.IModelStoreLock; - -import java.util.Collection; -import java.util.Objects; -import java.util.Optional; -import org.spdx.library.SpdxConstants; - -/** - * DO NOT EDIT - this file is generated by the Owl to Java Utility - * See: https://github.com/spdx/tools-java - * - * TODO - */ -public class Payload extends ModelObject { - - Collection namespacess; - Collection importss; - - /** - * Create the Payload with default model store and generated anonymous ID - * @throws InvalidSPDXAnalysisException when unable to create the Payload - */ - public Payload() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * @param objectUri URI or anonymous ID for the Payload - * @throws InvalidSPDXAnalysisException when unable to create the Payload - */ - public Payload(String objectUri) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore Model store where the Payload is to be stored - * @param objectUri URI or anonymous ID for the Payload - * @param copyManager Copy manager for the Payload - can be null if copying is not required - * @param create true if Payload is to be created - * @throws InvalidSPDXAnalysisException when unable to create the Payload - */ - @SuppressWarnings("unchecked") - public Payload(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - namespacess = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_NAMESPACES, NamespaceMap.class); - importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); - } - - /** - * Create the Payload from the builder - used in the builder class - * @param builder Builder to create the Payload from - * @throws InvalidSPDXAnalysisException when unable to create the Payload - */ - @SuppressWarnings("unchecked") - protected Payload(PayloadBuilder builder) throws InvalidSPDXAnalysisException { - super(builder); - namespacess = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_NAMESPACES, NamespaceMap.class); - importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); - getNamespacess().addAll(builder.namespacess); - getImportss().addAll(builder.importss); - setCreationInfo(builder.creationInfo); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() - */ - @Override - public String getType() { - return "Core.Payload"; - } - - // Getters and Setters - public Collection getNamespacess() { - return namespacess; - } - public Collection getImportss() { - return importss; - } - - - /** - * @return the creationInfo - */ - @SuppressWarnings("unchecked") - public Optional getCreationInfo() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO); - if (retval.isPresent()) { - if (!(retval.get() instanceof CreationInfo)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } - } - - /** - * @param creationInfo the creationInfo to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Payload setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO, creationInfo); - return this; - } - - - @Override - public String toString() { - return "Payload: "+getObjectUri(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { - List retval = new ArrayList<>(); - Optional creationInfo; - try { - creationInfo = getCreationInfo(); - if (creationInfo.isPresent()) { - retval.addAll(creationInfo.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting creationInfo for Payload: "+e.getMessage()); - } - for (NamespaceMap namespaces:namespacess) { - retval.addAll(namespaces.verify(verifiedIds, specVersion, profiles)); - } - for (ExternalMap imports:importss) { - retval.addAll(imports.verify(verifiedIds, specVersion, profiles)); - } - return retval; - } - - public static class PayloadBuilder extends ModelObjectBuilder { - - /** - * Create an PayloadBuilder from another model object copying the modelStore and copyManager and using an anonymous ID - * @param from model object to copy the model store and copyManager from - * @throws InvalidSPDXAnalysisException - */ - public PayloadBuilder(ModelObject from) throws InvalidSPDXAnalysisException { - this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * Create an PayloadBuilder from another model object copying the modelStore and copyManager - * @param from model object to copy the model store and copyManager from - * @param objectUri URI for the object - * @param objectUri - */ - public PayloadBuilder(ModelObject from, String objectUri) { - this(from.getModelStore(), objectUri, from.getCopyManager()); - setStrict(from.isStrict()); - } - - /** - * Creates a PayloadBuilder - * @param modelStore model store for the built Payload - * @param objectUri objectUri for the built Payload - * @param copyManager optional copyManager for the built Payload - */ - public PayloadBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { - super(modelStore, objectUri, copyManager); - } - - Collection namespacess = new ArrayList<>(); - Collection importss = new ArrayList<>(); - CreationInfo creationInfo = null; - - - /** - * Adds a namespaces to the initial collection - * @parameter namespaces namespaces to add - * @return this for chaining - **/ - PayloadBuilder addNamespaces(NamespaceMap namespaces) { - if (Objects.nonNull(namespaces)) { - namespacess.add(namespaces); - } - return this; - } - - /** - * Adds all elements from a collection to the initial namespaces collection - * @parameter namespacesCollection collection to initialize the namespaces - * @return this for chaining - **/ - PayloadBuilder addAllNamespaces(Collection namespacesCollection) { - if (Objects.nonNull(namespacesCollection)) { - namespacess.addAll(namespacesCollection); - } - return this; - } - - /** - * Adds a imports to the initial collection - * @parameter imports imports to add - * @return this for chaining - **/ - PayloadBuilder addImports(ExternalMap imports) { - if (Objects.nonNull(imports)) { - importss.add(imports); - } - return this; - } - - /** - * Adds all elements from a collection to the initial imports collection - * @parameter importsCollection collection to initialize the imports - * @return this for chaining - **/ - PayloadBuilder addAllImports(Collection importsCollection) { - if (Objects.nonNull(importsCollection)) { - importss.addAll(importsCollection); - } - return this; - } - - /** - * Sets the initial value of creationInfo - * @parameter creationInfo value to set - * @return this for chaining - **/ - PayloadBuilder setCreationInfo(CreationInfo creationInfo) { - this.creationInfo = creationInfo; - return this; - } - - - /** - * @return the Payload - * @throws InvalidSPDXAnalysisException on any errors during build - */ - public Payload build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new Payload(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } -} diff --git a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java b/generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/ai/AIPackage.java rename to generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java index 45937eec6..a84598e2c 100644 --- a/generated/src/main/java/org/spdx/library/model/ai/AIPackage.java +++ b/generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.ai; +package org.spdx.library.model.v3.ai; import javax.annotation.Nullable; @@ -36,9 +36,9 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.DictionaryEntry; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.software.SpdxPackage; +import org.spdx.library.model.v3.core.DictionaryEntry; +import org.spdx.library.model.v3.software.SpdxPackage; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -54,14 +54,14 @@ */ public class AIPackage extends SpdxPackage { - Collection metrics; Collection hyperparameters; Collection metricDecisionThresholds; - Collection domains; - Collection standardCompliances; - Collection modelDataPreprocessings; + Collection metrics; Collection typeOfModels; + Collection modelDataPreprocessings; + Collection standardCompliances; Collection modelExplainabilitys; + Collection domains; /** * Create the AIPackage with default model store and generated anonymous ID @@ -90,14 +90,14 @@ public AIPackage(String objectUri) throws InvalidSPDXAnalysisException { public AIPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); - domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); - standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); - modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); + modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); modelExplainabilitys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_EXPLAINABILITY, String.class); + domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); } /** @@ -108,29 +108,29 @@ public AIPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyMa @SuppressWarnings("unchecked") protected AIPackage(AIPackageBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); - domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); - standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); - modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); + modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); modelExplainabilitys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_EXPLAINABILITY, String.class); - getMetrics().addAll(builder.metrics); + domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); getHyperparameters().addAll(builder.hyperparameters); getMetricDecisionThresholds().addAll(builder.metricDecisionThresholds); - getDomains().addAll(builder.domains); - getStandardCompliances().addAll(builder.standardCompliances); - getModelDataPreprocessings().addAll(builder.modelDataPreprocessings); + getMetrics().addAll(builder.metrics); getTypeOfModels().addAll(builder.typeOfModels); + getModelDataPreprocessings().addAll(builder.modelDataPreprocessings); + getStandardCompliances().addAll(builder.standardCompliances); getModelExplainabilitys().addAll(builder.modelExplainabilitys); + getDomains().addAll(builder.domains); setSensitivePersonalInformation(builder.sensitivePersonalInformation); setSafetyRiskAssessment(builder.safetyRiskAssessment); setAutonomyType(builder.autonomyType); - setInformationAboutTraining(builder.informationAboutTraining); setLimitation(builder.limitation); setEnergyConsumption(builder.energyConsumption); setInformationAboutApplication(builder.informationAboutApplication); + setInformationAboutTraining(builder.informationAboutTraining); } /* (non-Javadoc) @@ -142,30 +142,30 @@ public String getType() { } // Getters and Setters - public Collection getMetrics() { - return metrics; - } public Collection getHyperparameters() { return hyperparameters; } public Collection getMetricDecisionThresholds() { return metricDecisionThresholds; } - public Collection getDomains() { - return domains; + public Collection getMetrics() { + return metrics; } - public Collection getStandardCompliances() { - return standardCompliances; + public Collection getTypeOfModels() { + return typeOfModels; } public Collection getModelDataPreprocessings() { return modelDataPreprocessings; } - public Collection getTypeOfModels() { - return typeOfModels; + public Collection getStandardCompliances() { + return standardCompliances; } public Collection getModelExplainabilitys() { return modelExplainabilitys; } + public Collection getDomains() { + return domains; + } /** @@ -243,22 +243,6 @@ public AIPackage setAutonomyType(@Nullable PresenceType autonomyType) throws Inv return this; } - /** - * @return the informationAboutTraining - */ - public Optional getInformationAboutTraining() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING); - } - /** - * @param informationAboutTraining the informationAboutTraining to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public AIPackage setInformationAboutTraining(@Nullable String informationAboutTraining) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING, informationAboutTraining); - return this; - } - /** * @return the limitation */ @@ -306,6 +290,22 @@ public AIPackage setInformationAboutApplication(@Nullable String informationAbou setPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_APPLICATION, informationAboutApplication); return this; } + + /** + * @return the informationAboutTraining + */ + public Optional getInformationAboutTraining() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING); + } + /** + * @param informationAboutTraining the informationAboutTraining to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setInformationAboutTraining(@Nullable String informationAboutTraining) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING, informationAboutTraining); + return this; + } @Override @@ -338,12 +338,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting autonomyType for AIPackage: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional informationAboutTraining = getInformationAboutTraining(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting informationAboutTraining for AIPackage: "+e.getMessage()); - } try { @SuppressWarnings("unused") Optional limitation = getLimitation(); @@ -362,8 +356,11 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting informationAboutApplication for AIPackage: "+e.getMessage()); } - for (DictionaryEntry metric:metrics) { - retval.addAll(metric.verify(verifiedIds, specVersion, profiles)); + try { + @SuppressWarnings("unused") + Optional informationAboutTraining = getInformationAboutTraining(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting informationAboutTraining for AIPackage: "+e.getMessage()); } for (DictionaryEntry hyperparameter:hyperparameters) { retval.addAll(hyperparameter.verify(verifiedIds, specVersion, profiles)); @@ -371,6 +368,9 @@ protected List _verify(Set verifiedIds, String specVersion, List for (DictionaryEntry metricDecisionThreshold:metricDecisionThresholds) { retval.addAll(metricDecisionThreshold.verify(verifiedIds, specVersion, profiles)); } + for (DictionaryEntry metric:metrics) { + retval.addAll(metric.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -406,53 +406,29 @@ public AIPackageBuilder(IModelStore modelStore, String objectUri, @Nullable Mode super(modelStore, objectUri, copyManager); } - Collection metrics = new ArrayList<>(); Collection hyperparameters = new ArrayList<>(); Collection metricDecisionThresholds = new ArrayList<>(); - Collection domains = new ArrayList<>(); - Collection standardCompliances = new ArrayList<>(); - Collection modelDataPreprocessings = new ArrayList<>(); + Collection metrics = new ArrayList<>(); Collection typeOfModels = new ArrayList<>(); + Collection modelDataPreprocessings = new ArrayList<>(); + Collection standardCompliances = new ArrayList<>(); Collection modelExplainabilitys = new ArrayList<>(); + Collection domains = new ArrayList<>(); PresenceType sensitivePersonalInformation = null; SafetyRiskAssessmentType safetyRiskAssessment = null; PresenceType autonomyType = null; - String informationAboutTraining = null; String limitation = null; String energyConsumption = null; String informationAboutApplication = null; + String informationAboutTraining = null; - /** - * Adds a metric to the initial collection - * @parameter metric metric to add - * @return this for chaining - **/ - AIPackageBuilder addMetric(DictionaryEntry metric) { - if (Objects.nonNull(metric)) { - metrics.add(metric); - } - return this; - } - - /** - * Adds all elements from a collection to the initial metric collection - * @parameter metricCollection collection to initialize the metric - * @return this for chaining - **/ - AIPackageBuilder addAllMetric(Collection metricCollection) { - if (Objects.nonNull(metricCollection)) { - metrics.addAll(metricCollection); - } - return this; - } - /** * Adds a hyperparameter to the initial collection * @parameter hyperparameter hyperparameter to add * @return this for chaining **/ - AIPackageBuilder addHyperparameter(DictionaryEntry hyperparameter) { + public AIPackageBuilder addHyperparameter(DictionaryEntry hyperparameter) { if (Objects.nonNull(hyperparameter)) { hyperparameters.add(hyperparameter); } @@ -464,7 +440,7 @@ AIPackageBuilder addHyperparameter(DictionaryEntry hyperparameter) { * @parameter hyperparameterCollection collection to initialize the hyperparameter * @return this for chaining **/ - AIPackageBuilder addAllHyperparameter(Collection hyperparameterCollection) { + public AIPackageBuilder addAllHyperparameter(Collection hyperparameterCollection) { if (Objects.nonNull(hyperparameterCollection)) { hyperparameters.addAll(hyperparameterCollection); } @@ -476,7 +452,7 @@ AIPackageBuilder addAllHyperparameter(Collection hyperparameter * @parameter metricDecisionThreshold metricDecisionThreshold to add * @return this for chaining **/ - AIPackageBuilder addMetricDecisionThreshold(DictionaryEntry metricDecisionThreshold) { + public AIPackageBuilder addMetricDecisionThreshold(DictionaryEntry metricDecisionThreshold) { if (Objects.nonNull(metricDecisionThreshold)) { metricDecisionThresholds.add(metricDecisionThreshold); } @@ -488,7 +464,7 @@ AIPackageBuilder addMetricDecisionThreshold(DictionaryEntry metricDecisionThresh * @parameter metricDecisionThresholdCollection collection to initialize the metricDecisionThreshold * @return this for chaining **/ - AIPackageBuilder addAllMetricDecisionThreshold(Collection metricDecisionThresholdCollection) { + public AIPackageBuilder addAllMetricDecisionThreshold(Collection metricDecisionThresholdCollection) { if (Objects.nonNull(metricDecisionThresholdCollection)) { metricDecisionThresholds.addAll(metricDecisionThresholdCollection); } @@ -496,49 +472,49 @@ AIPackageBuilder addAllMetricDecisionThreshold(Collection metri } /** - * Adds a domain to the initial collection - * @parameter domain domain to add + * Adds a metric to the initial collection + * @parameter metric metric to add * @return this for chaining **/ - AIPackageBuilder addDomain(String domain) { - if (Objects.nonNull(domain)) { - domains.add(domain); + public AIPackageBuilder addMetric(DictionaryEntry metric) { + if (Objects.nonNull(metric)) { + metrics.add(metric); } return this; } /** - * Adds all elements from a collection to the initial domain collection - * @parameter domainCollection collection to initialize the domain + * Adds all elements from a collection to the initial metric collection + * @parameter metricCollection collection to initialize the metric * @return this for chaining **/ - AIPackageBuilder addAllDomain(Collection domainCollection) { - if (Objects.nonNull(domainCollection)) { - domains.addAll(domainCollection); + public AIPackageBuilder addAllMetric(Collection metricCollection) { + if (Objects.nonNull(metricCollection)) { + metrics.addAll(metricCollection); } return this; } /** - * Adds a standardCompliance to the initial collection - * @parameter standardCompliance standardCompliance to add + * Adds a typeOfModel to the initial collection + * @parameter typeOfModel typeOfModel to add * @return this for chaining **/ - AIPackageBuilder addStandardCompliance(String standardCompliance) { - if (Objects.nonNull(standardCompliance)) { - standardCompliances.add(standardCompliance); + public AIPackageBuilder addTypeOfModel(String typeOfModel) { + if (Objects.nonNull(typeOfModel)) { + typeOfModels.add(typeOfModel); } return this; } /** - * Adds all elements from a collection to the initial standardCompliance collection - * @parameter standardComplianceCollection collection to initialize the standardCompliance + * Adds all elements from a collection to the initial typeOfModel collection + * @parameter typeOfModelCollection collection to initialize the typeOfModel * @return this for chaining **/ - AIPackageBuilder addAllStandardCompliance(Collection standardComplianceCollection) { - if (Objects.nonNull(standardComplianceCollection)) { - standardCompliances.addAll(standardComplianceCollection); + public AIPackageBuilder addAllTypeOfModel(Collection typeOfModelCollection) { + if (Objects.nonNull(typeOfModelCollection)) { + typeOfModels.addAll(typeOfModelCollection); } return this; } @@ -548,7 +524,7 @@ AIPackageBuilder addAllStandardCompliance(Collection standardComplianceC * @parameter modelDataPreprocessing modelDataPreprocessing to add * @return this for chaining **/ - AIPackageBuilder addModelDataPreprocessing(String modelDataPreprocessing) { + public AIPackageBuilder addModelDataPreprocessing(String modelDataPreprocessing) { if (Objects.nonNull(modelDataPreprocessing)) { modelDataPreprocessings.add(modelDataPreprocessing); } @@ -560,7 +536,7 @@ AIPackageBuilder addModelDataPreprocessing(String modelDataPreprocessing) { * @parameter modelDataPreprocessingCollection collection to initialize the modelDataPreprocessing * @return this for chaining **/ - AIPackageBuilder addAllModelDataPreprocessing(Collection modelDataPreprocessingCollection) { + public AIPackageBuilder addAllModelDataPreprocessing(Collection modelDataPreprocessingCollection) { if (Objects.nonNull(modelDataPreprocessingCollection)) { modelDataPreprocessings.addAll(modelDataPreprocessingCollection); } @@ -568,25 +544,25 @@ AIPackageBuilder addAllModelDataPreprocessing(Collection modelDataPrepro } /** - * Adds a typeOfModel to the initial collection - * @parameter typeOfModel typeOfModel to add + * Adds a standardCompliance to the initial collection + * @parameter standardCompliance standardCompliance to add * @return this for chaining **/ - AIPackageBuilder addTypeOfModel(String typeOfModel) { - if (Objects.nonNull(typeOfModel)) { - typeOfModels.add(typeOfModel); + public AIPackageBuilder addStandardCompliance(String standardCompliance) { + if (Objects.nonNull(standardCompliance)) { + standardCompliances.add(standardCompliance); } return this; } /** - * Adds all elements from a collection to the initial typeOfModel collection - * @parameter typeOfModelCollection collection to initialize the typeOfModel + * Adds all elements from a collection to the initial standardCompliance collection + * @parameter standardComplianceCollection collection to initialize the standardCompliance * @return this for chaining **/ - AIPackageBuilder addAllTypeOfModel(Collection typeOfModelCollection) { - if (Objects.nonNull(typeOfModelCollection)) { - typeOfModels.addAll(typeOfModelCollection); + public AIPackageBuilder addAllStandardCompliance(Collection standardComplianceCollection) { + if (Objects.nonNull(standardComplianceCollection)) { + standardCompliances.addAll(standardComplianceCollection); } return this; } @@ -596,7 +572,7 @@ AIPackageBuilder addAllTypeOfModel(Collection typeOfModelCollection) { * @parameter modelExplainability modelExplainability to add * @return this for chaining **/ - AIPackageBuilder addModelExplainability(String modelExplainability) { + public AIPackageBuilder addModelExplainability(String modelExplainability) { if (Objects.nonNull(modelExplainability)) { modelExplainabilitys.add(modelExplainability); } @@ -608,19 +584,43 @@ AIPackageBuilder addModelExplainability(String modelExplainability) { * @parameter modelExplainabilityCollection collection to initialize the modelExplainability * @return this for chaining **/ - AIPackageBuilder addAllModelExplainability(Collection modelExplainabilityCollection) { + public AIPackageBuilder addAllModelExplainability(Collection modelExplainabilityCollection) { if (Objects.nonNull(modelExplainabilityCollection)) { modelExplainabilitys.addAll(modelExplainabilityCollection); } return this; } + /** + * Adds a domain to the initial collection + * @parameter domain domain to add + * @return this for chaining + **/ + public AIPackageBuilder addDomain(String domain) { + if (Objects.nonNull(domain)) { + domains.add(domain); + } + return this; + } + + /** + * Adds all elements from a collection to the initial domain collection + * @parameter domainCollection collection to initialize the domain + * @return this for chaining + **/ + public AIPackageBuilder addAllDomain(Collection domainCollection) { + if (Objects.nonNull(domainCollection)) { + domains.addAll(domainCollection); + } + return this; + } + /** * Sets the initial value of sensitivePersonalInformation * @parameter sensitivePersonalInformation value to set * @return this for chaining **/ - AIPackageBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + public AIPackageBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { this.sensitivePersonalInformation = sensitivePersonalInformation; return this; } @@ -630,7 +630,7 @@ AIPackageBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalI * @parameter safetyRiskAssessment value to set * @return this for chaining **/ - AIPackageBuilder setSafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAssessment) { + public AIPackageBuilder setSafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAssessment) { this.safetyRiskAssessment = safetyRiskAssessment; return this; } @@ -640,27 +640,17 @@ AIPackageBuilder setSafetyRiskAssessment(SafetyRiskAssessmentType safetyRiskAsse * @parameter autonomyType value to set * @return this for chaining **/ - AIPackageBuilder setAutonomyType(PresenceType autonomyType) { + public AIPackageBuilder setAutonomyType(PresenceType autonomyType) { this.autonomyType = autonomyType; return this; } - /** - * Sets the initial value of informationAboutTraining - * @parameter informationAboutTraining value to set - * @return this for chaining - **/ - AIPackageBuilder setInformationAboutTraining(String informationAboutTraining) { - this.informationAboutTraining = informationAboutTraining; - return this; - } - /** * Sets the initial value of limitation * @parameter limitation value to set * @return this for chaining **/ - AIPackageBuilder setLimitation(String limitation) { + public AIPackageBuilder setLimitation(String limitation) { this.limitation = limitation; return this; } @@ -670,7 +660,7 @@ AIPackageBuilder setLimitation(String limitation) { * @parameter energyConsumption value to set * @return this for chaining **/ - AIPackageBuilder setEnergyConsumption(String energyConsumption) { + public AIPackageBuilder setEnergyConsumption(String energyConsumption) { this.energyConsumption = energyConsumption; return this; } @@ -680,10 +670,20 @@ AIPackageBuilder setEnergyConsumption(String energyConsumption) { * @parameter informationAboutApplication value to set * @return this for chaining **/ - AIPackageBuilder setInformationAboutApplication(String informationAboutApplication) { + public AIPackageBuilder setInformationAboutApplication(String informationAboutApplication) { this.informationAboutApplication = informationAboutApplication; return this; } + + /** + * Sets the initial value of informationAboutTraining + * @parameter informationAboutTraining value to set + * @return this for chaining + **/ + public AIPackageBuilder setInformationAboutTraining(String informationAboutTraining) { + this.informationAboutTraining = informationAboutTraining; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/ai/PresenceType.java b/generated/src/main/java/org/spdx/library/model/v3/ai/PresenceType.java similarity index 91% rename from generated/src/main/java/org/spdx/library/model/ai/PresenceType.java rename to generated/src/main/java/org/spdx/library/model/v3/ai/PresenceType.java index 0def2e7f2..b5cb42a0a 100644 --- a/generated/src/main/java/org/spdx/library/model/ai/PresenceType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/ai/PresenceType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.ai; +package org.spdx.library.model.v3.ai; import org.spdx.library.IndividualUriValue; @@ -29,8 +29,8 @@ public enum PresenceType implements IndividualUriValue { NO_ASSERTION("noAssertion"), - YES("yes"), - NO("no"); + NO("no"), + YES("yes"); private String longName; @@ -48,7 +48,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/AI/PresenceType"; + return "https://spdx.org/rdf/v3/AI/PresenceType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java b/generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java similarity index 91% rename from generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java rename to generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java index f220e7fcb..e7f835db7 100644 --- a/generated/src/main/java/org/spdx/library/model/ai/SafetyRiskAssessmentType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.ai; +package org.spdx.library.model.v3.ai; import org.spdx.library.IndividualUriValue; @@ -29,10 +29,10 @@ */ public enum SafetyRiskAssessmentType implements IndividualUriValue { - LOW("low"), HIGH("high"), - MEDIUM("medium"), - SERIOUS("serious"); + SERIOUS("serious"), + LOW("low"), + MEDIUM("medium"); private String longName; @@ -50,7 +50,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/AI/SafetyRiskAssessmentType"; + return "https://spdx.org/rdf/v3/AI/SafetyRiskAssessmentType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/build/Build.java b/generated/src/main/java/org/spdx/library/model/v3/build/Build.java similarity index 84% rename from generated/src/main/java/org/spdx/library/model/build/Build.java rename to generated/src/main/java/org/spdx/library/model/v3/build/Build.java index da6cbeac5..458f08c9c 100644 --- a/generated/src/main/java/org/spdx/library/model/build/Build.java +++ b/generated/src/main/java/org/spdx/library/model/v3/build/Build.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.build; +package org.spdx.library.model.v3.build; import javax.annotation.Nullable; @@ -38,10 +38,11 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.DictionaryEntry; -import org.spdx.library.model.core.Element; -import org.spdx.library.model.core.Hash; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.DateTime; +import org.spdx.library.model.v3.core.DictionaryEntry; +import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.Hash; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -59,11 +60,11 @@ */ public class Build extends Element { - Collection parameterss; Collection configSourceDigests; + Collection parameterss; Collection environments; - Collection configSourceEntrypoints; Collection configSourceUris; + Collection configSourceEntrypoints; /** * Create the Build with default model store and generated anonymous ID @@ -92,11 +93,11 @@ public Build(String objectUri) throws InvalidSPDXAnalysisException { public Build(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); configSourceDigests = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_DIGEST, Hash.class); + parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); - configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); configSourceUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_URI, String.class); + configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); } /** @@ -107,19 +108,19 @@ public Build(IModelStore modelStore, String objectUri, @Nullable ModelCopyManage @SuppressWarnings("unchecked") protected Build(BuildBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); configSourceDigests = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_DIGEST, Hash.class); + parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); - configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); configSourceUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_URI, String.class); - getParameterss().addAll(builder.parameterss); + configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); getConfigSourceDigests().addAll(builder.configSourceDigests); + getParameterss().addAll(builder.parameterss); getEnvironments().addAll(builder.environments); - getConfigSourceEntrypoints().addAll(builder.configSourceEntrypoints); getConfigSourceUris().addAll(builder.configSourceUris); + getConfigSourceEntrypoints().addAll(builder.configSourceEntrypoints); setBuildEndTime(builder.buildEndTime); - setBuildType(builder.buildType); setBuildStartTime(builder.buildStartTime); + setBuildType(builder.buildType); setBuildId(builder.buildId); } @@ -132,39 +133,75 @@ public String getType() { } // Getters and Setters - public Collection getParameterss() { - return parameterss; - } public Collection getConfigSourceDigests() { return configSourceDigests; } + public Collection getParameterss() { + return parameterss; + } public Collection getEnvironments() { return environments; } - public Collection getConfigSourceEntrypoints() { - return configSourceEntrypoints; - } public Collection getConfigSourceUris() { return configSourceUris; } + public Collection getConfigSourceEntrypoints() { + return configSourceEntrypoints; + } /** * @return the buildEndTime */ - public Optional getBuildEndTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME); + @SuppressWarnings("unchecked") + public Optional getBuildEndTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } + /** * @param buildEndTime the buildEndTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Build setBuildEndTime(@Nullable String buildEndTime) throws InvalidSPDXAnalysisException { + public Build setBuildEndTime(@Nullable DateTime buildEndTime) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME, buildEndTime); return this; } + /** + * @return the buildStartTime + */ + @SuppressWarnings("unchecked") + public Optional getBuildStartTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param buildStartTime the buildStartTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Build setBuildStartTime(@Nullable DateTime buildStartTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME, buildStartTime); + return this; + } + /** * @return the buildType */ @@ -185,22 +222,6 @@ public Build setBuildType(@Nullable String buildType) throws InvalidSPDXAnalysis return this; } - /** - * @return the buildStartTime - */ - public Optional getBuildStartTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME); - } - /** - * @param buildStartTime the buildStartTime to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Build setBuildStartTime(@Nullable String buildStartTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME, buildStartTime); - return this; - } - /** * @return the buildId */ @@ -230,12 +251,24 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional buildEndTime; try { - @SuppressWarnings("unused") - Optional buildEndTime = getBuildEndTime(); + buildEndTime = getBuildEndTime(); + if (buildEndTime.isPresent()) { + retval.addAll(buildEndTime.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildEndTime for Build: "+e.getMessage()); } + Optional buildStartTime; + try { + buildStartTime = getBuildStartTime(); + if (buildStartTime.isPresent()) { + retval.addAll(buildStartTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting buildStartTime for Build: "+e.getMessage()); + } try { String buildType = getBuildType(); if (Objects.isNull(buildType) && @@ -245,24 +278,18 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildType for Build: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional buildStartTime = getBuildStartTime(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting buildStartTime for Build: "+e.getMessage()); - } try { @SuppressWarnings("unused") Optional buildId = getBuildId(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildId for Build: "+e.getMessage()); } - for (DictionaryEntry parameters:parameterss) { - retval.addAll(parameters.verify(verifiedIds, specVersion, profiles)); - } for (Hash configSourceDigest:configSourceDigests) { retval.addAll(configSourceDigest.verify(verifiedIds, specVersion, profiles)); } + for (DictionaryEntry parameters:parameterss) { + retval.addAll(parameters.verify(verifiedIds, specVersion, profiles)); + } for (DictionaryEntry environment:environments) { retval.addAll(environment.verify(verifiedIds, specVersion, profiles)); } @@ -301,61 +328,61 @@ public BuildBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCop super(modelStore, objectUri, copyManager); } - Collection parameterss = new ArrayList<>(); Collection configSourceDigests = new ArrayList<>(); + Collection parameterss = new ArrayList<>(); Collection environments = new ArrayList<>(); - Collection configSourceEntrypoints = new ArrayList<>(); Collection configSourceUris = new ArrayList<>(); - String buildEndTime = null; + Collection configSourceEntrypoints = new ArrayList<>(); + DateTime buildEndTime = null; + DateTime buildStartTime = null; String buildType = null; - String buildStartTime = null; String buildId = null; /** - * Adds a parameters to the initial collection - * @parameter parameters parameters to add + * Adds a configSourceDigest to the initial collection + * @parameter configSourceDigest configSourceDigest to add * @return this for chaining **/ - BuildBuilder addParameters(DictionaryEntry parameters) { - if (Objects.nonNull(parameters)) { - parameterss.add(parameters); + public BuildBuilder addConfigSourceDigest(Hash configSourceDigest) { + if (Objects.nonNull(configSourceDigest)) { + configSourceDigests.add(configSourceDigest); } return this; } /** - * Adds all elements from a collection to the initial parameters collection - * @parameter parametersCollection collection to initialize the parameters + * Adds all elements from a collection to the initial configSourceDigest collection + * @parameter configSourceDigestCollection collection to initialize the configSourceDigest * @return this for chaining **/ - BuildBuilder addAllParameters(Collection parametersCollection) { - if (Objects.nonNull(parametersCollection)) { - parameterss.addAll(parametersCollection); + public BuildBuilder addAllConfigSourceDigest(Collection configSourceDigestCollection) { + if (Objects.nonNull(configSourceDigestCollection)) { + configSourceDigests.addAll(configSourceDigestCollection); } return this; } /** - * Adds a configSourceDigest to the initial collection - * @parameter configSourceDigest configSourceDigest to add + * Adds a parameters to the initial collection + * @parameter parameters parameters to add * @return this for chaining **/ - BuildBuilder addConfigSourceDigest(Hash configSourceDigest) { - if (Objects.nonNull(configSourceDigest)) { - configSourceDigests.add(configSourceDigest); + public BuildBuilder addParameters(DictionaryEntry parameters) { + if (Objects.nonNull(parameters)) { + parameterss.add(parameters); } return this; } /** - * Adds all elements from a collection to the initial configSourceDigest collection - * @parameter configSourceDigestCollection collection to initialize the configSourceDigest + * Adds all elements from a collection to the initial parameters collection + * @parameter parametersCollection collection to initialize the parameters * @return this for chaining **/ - BuildBuilder addAllConfigSourceDigest(Collection configSourceDigestCollection) { - if (Objects.nonNull(configSourceDigestCollection)) { - configSourceDigests.addAll(configSourceDigestCollection); + public BuildBuilder addAllParameters(Collection parametersCollection) { + if (Objects.nonNull(parametersCollection)) { + parameterss.addAll(parametersCollection); } return this; } @@ -365,7 +392,7 @@ BuildBuilder addAllConfigSourceDigest(Collection configSourceDigestCollect * @parameter environment environment to add * @return this for chaining **/ - BuildBuilder addEnvironment(DictionaryEntry environment) { + public BuildBuilder addEnvironment(DictionaryEntry environment) { if (Objects.nonNull(environment)) { environments.add(environment); } @@ -377,7 +404,7 @@ BuildBuilder addEnvironment(DictionaryEntry environment) { * @parameter environmentCollection collection to initialize the environment * @return this for chaining **/ - BuildBuilder addAllEnvironment(Collection environmentCollection) { + public BuildBuilder addAllEnvironment(Collection environmentCollection) { if (Objects.nonNull(environmentCollection)) { environments.addAll(environmentCollection); } @@ -385,49 +412,49 @@ BuildBuilder addAllEnvironment(Collection environmentCollection } /** - * Adds a configSourceEntrypoint to the initial collection - * @parameter configSourceEntrypoint configSourceEntrypoint to add + * Adds a configSourceUri to the initial collection + * @parameter configSourceUri configSourceUri to add * @return this for chaining **/ - BuildBuilder addConfigSourceEntrypoint(String configSourceEntrypoint) { - if (Objects.nonNull(configSourceEntrypoint)) { - configSourceEntrypoints.add(configSourceEntrypoint); + public BuildBuilder addConfigSourceUri(String configSourceUri) { + if (Objects.nonNull(configSourceUri)) { + configSourceUris.add(configSourceUri); } return this; } /** - * Adds all elements from a collection to the initial configSourceEntrypoint collection - * @parameter configSourceEntrypointCollection collection to initialize the configSourceEntrypoint + * Adds all elements from a collection to the initial configSourceUri collection + * @parameter configSourceUriCollection collection to initialize the configSourceUri * @return this for chaining **/ - BuildBuilder addAllConfigSourceEntrypoint(Collection configSourceEntrypointCollection) { - if (Objects.nonNull(configSourceEntrypointCollection)) { - configSourceEntrypoints.addAll(configSourceEntrypointCollection); + public BuildBuilder addAllConfigSourceUri(Collection configSourceUriCollection) { + if (Objects.nonNull(configSourceUriCollection)) { + configSourceUris.addAll(configSourceUriCollection); } return this; } /** - * Adds a configSourceUri to the initial collection - * @parameter configSourceUri configSourceUri to add + * Adds a configSourceEntrypoint to the initial collection + * @parameter configSourceEntrypoint configSourceEntrypoint to add * @return this for chaining **/ - BuildBuilder addConfigSourceUri(String configSourceUri) { - if (Objects.nonNull(configSourceUri)) { - configSourceUris.add(configSourceUri); + public BuildBuilder addConfigSourceEntrypoint(String configSourceEntrypoint) { + if (Objects.nonNull(configSourceEntrypoint)) { + configSourceEntrypoints.add(configSourceEntrypoint); } return this; } /** - * Adds all elements from a collection to the initial configSourceUri collection - * @parameter configSourceUriCollection collection to initialize the configSourceUri + * Adds all elements from a collection to the initial configSourceEntrypoint collection + * @parameter configSourceEntrypointCollection collection to initialize the configSourceEntrypoint * @return this for chaining **/ - BuildBuilder addAllConfigSourceUri(Collection configSourceUriCollection) { - if (Objects.nonNull(configSourceUriCollection)) { - configSourceUris.addAll(configSourceUriCollection); + public BuildBuilder addAllConfigSourceEntrypoint(Collection configSourceEntrypointCollection) { + if (Objects.nonNull(configSourceEntrypointCollection)) { + configSourceEntrypoints.addAll(configSourceEntrypointCollection); } return this; } @@ -437,28 +464,28 @@ BuildBuilder addAllConfigSourceUri(Collection configSourceUriCollection) * @parameter buildEndTime value to set * @return this for chaining **/ - BuildBuilder setBuildEndTime(String buildEndTime) { + public BuildBuilder setBuildEndTime(DateTime buildEndTime) { this.buildEndTime = buildEndTime; return this; } /** - * Sets the initial value of buildType - * @parameter buildType value to set + * Sets the initial value of buildStartTime + * @parameter buildStartTime value to set * @return this for chaining **/ - BuildBuilder setBuildType(String buildType) { - this.buildType = buildType; + public BuildBuilder setBuildStartTime(DateTime buildStartTime) { + this.buildStartTime = buildStartTime; return this; } /** - * Sets the initial value of buildStartTime - * @parameter buildStartTime value to set + * Sets the initial value of buildType + * @parameter buildType value to set * @return this for chaining **/ - BuildBuilder setBuildStartTime(String buildStartTime) { - this.buildStartTime = buildStartTime; + public BuildBuilder setBuildType(String buildType) { + this.buildType = buildType; return this; } @@ -467,7 +494,7 @@ BuildBuilder setBuildStartTime(String buildStartTime) { * @parameter buildId value to set * @return this for chaining **/ - BuildBuilder setBuildId(String buildId) { + public BuildBuilder setBuildId(String buildId) { this.buildId = buildId; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Agent.java b/generated/src/main/java/org/spdx/library/model/v3/core/Agent.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/core/Agent.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Agent.java index c56abcb74..869c45e1d 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Agent.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Agent.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/core/Annotation.java b/generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java similarity index 81% rename from generated/src/main/java/org/spdx/library/model/core/Annotation.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java index 9b5c2f62d..0e631744e 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Annotation.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -33,6 +33,7 @@ import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Objects; import java.util.Optional; @@ -46,6 +47,7 @@ */ public class Annotation extends Element { + Collection contentTypes; /** * Create the Annotation with default model store and generated anonymous ID @@ -70,9 +72,11 @@ public Annotation(String objectUri) throws InvalidSPDXAnalysisException { * @param create true if Annotation is to be created * @throws InvalidSPDXAnalysisException when unable to create the Annotation */ + @SuppressWarnings("unchecked") public Annotation(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); + contentTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CONTENT_TYPE, MediaType.class); } /** @@ -80,8 +84,11 @@ public Annotation(IModelStore modelStore, String objectUri, @Nullable ModelCopyM * @param builder Builder to create the Annotation from * @throws InvalidSPDXAnalysisException when unable to create the Annotation */ + @SuppressWarnings("unchecked") protected Annotation(AnnotationBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + contentTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CONTENT_TYPE, MediaType.class); + getContentTypes().addAll(builder.contentTypes); setSubject(builder.subject); setAnnotationType(builder.annotationType); setStatement(builder.statement); @@ -96,15 +103,27 @@ public String getType() { } // Getters and Setters + public Collection getContentTypes() { + return contentTypes; + } + /** * @return the subject */ + @SuppressWarnings("unchecked") public @Nullable Element getSubject() throws InvalidSPDXAnalysisException { - Optional retval = getElementPropertyValue(SpdxConstants.CORE_PROP_SUBJECT); - return retval.isPresent() ? retval.get() : null; + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_SUBJECT); + if (retval.isPresent()) { + if (!(retval.get() instanceof Element)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Element)(retval.get()); + } else { + return null; + } } - + /** * @param subject the subject to set * @return this to chain setters @@ -118,7 +137,6 @@ public Annotation setSubject(@Nullable Element subject) throws InvalidSPDXAnalys return this; } - /** * @return the annotationType */ @@ -181,7 +199,7 @@ protected List _verify(Set verifiedIds, String specVersion, List if (Objects.nonNull(subject)) { retval.addAll(subject.verify(verifiedIds, specVersion, profiles)); } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing subject in subject"); + retval.add("Missing subject in Annotation"); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting subject for Annotation: "+e.getMessage()); @@ -201,6 +219,9 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting statement for Annotation: "+e.getMessage()); } + for (MediaType contentType:contentTypes) { + retval.addAll(contentType.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -236,17 +257,42 @@ public AnnotationBuilder(IModelStore modelStore, String objectUri, @Nullable Mod super(modelStore, objectUri, copyManager); } + Collection contentTypes = new ArrayList<>(); Element subject = null; AnnotationType annotationType = null; String statement = null; + /** + * Adds a contentType to the initial collection + * @parameter contentType contentType to add + * @return this for chaining + **/ + public AnnotationBuilder addContentType(MediaType contentType) { + if (Objects.nonNull(contentType)) { + contentTypes.add(contentType); + } + return this; + } + + /** + * Adds all elements from a collection to the initial contentType collection + * @parameter contentTypeCollection collection to initialize the contentType + * @return this for chaining + **/ + public AnnotationBuilder addAllContentType(Collection contentTypeCollection) { + if (Objects.nonNull(contentTypeCollection)) { + contentTypes.addAll(contentTypeCollection); + } + return this; + } + /** * Sets the initial value of subject * @parameter subject value to set * @return this for chaining **/ - AnnotationBuilder setSubject(Element subject) { + public AnnotationBuilder setSubject(Element subject) { this.subject = subject; return this; } @@ -256,7 +302,7 @@ AnnotationBuilder setSubject(Element subject) { * @parameter annotationType value to set * @return this for chaining **/ - AnnotationBuilder setAnnotationType(AnnotationType annotationType) { + public AnnotationBuilder setAnnotationType(AnnotationType annotationType) { this.annotationType = annotationType; return this; } @@ -266,7 +312,7 @@ AnnotationBuilder setAnnotationType(AnnotationType annotationType) { * @parameter statement value to set * @return this for chaining **/ - AnnotationBuilder setStatement(String statement) { + public AnnotationBuilder setStatement(String statement) { this.statement = statement; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/AnnotationType.java b/generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/core/AnnotationType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java index 93c169f9d..fc532651f 100644 --- a/generated/src/main/java/org/spdx/library/model/core/AnnotationType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -28,8 +28,8 @@ */ public enum AnnotationType implements IndividualUriValue { - REVIEW("review"), - OTHER("other"); + OTHER("other"), + REVIEW("review"); private String longName; @@ -47,7 +47,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/AnnotationType"; + return "https://spdx.org/rdf/v3/Core/AnnotationType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/Artifact.java b/generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java similarity index 77% rename from generated/src/main/java/org/spdx/library/model/core/Artifact.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java index cb17f9eb3..6eff4c449 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Artifact.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -46,8 +46,8 @@ */ public class Artifact extends Element { - Collection originatedBys; Collection suppliedBys; + Collection originatedBys; Collection standards; /** @@ -77,8 +77,8 @@ public Artifact(String objectUri) throws InvalidSPDXAnalysisException { public Artifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); suppliedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SUPPLIED_BY, Agent.class); + originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); standards = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_STANDARD, String.class); } @@ -90,14 +90,14 @@ public Artifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyMan @SuppressWarnings("unchecked") protected Artifact(ArtifactBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); suppliedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SUPPLIED_BY, Agent.class); + originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); standards = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_STANDARD, String.class); - getOriginatedBys().addAll(builder.originatedBys); getSuppliedBys().addAll(builder.suppliedBys); + getOriginatedBys().addAll(builder.originatedBys); getStandards().addAll(builder.standards); - setReleaseTime(builder.releaseTime); setValidUntilTime(builder.validUntilTime); + setReleaseTime(builder.releaseTime); setBuiltTime(builder.builtTime); } @@ -110,61 +110,91 @@ public String getType() { } // Getters and Setters - public Collection getOriginatedBys() { - return originatedBys; - } public Collection getSuppliedBys() { return suppliedBys; } + public Collection getOriginatedBys() { + return originatedBys; + } public Collection getStandards() { return standards; } /** - * @return the releaseTime + * @return the validUntilTime */ - public Optional getReleaseTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME); + @SuppressWarnings("unchecked") + public Optional getValidUntilTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } + /** - * @param releaseTime the releaseTime to set + * @param validUntilTime the validUntilTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Artifact setReleaseTime(@Nullable String releaseTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME, releaseTime); + public Artifact setValidUntilTime(@Nullable DateTime validUntilTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME, validUntilTime); return this; } /** - * @return the validUntilTime + * @return the releaseTime */ - public Optional getValidUntilTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME); + @SuppressWarnings("unchecked") + public Optional getReleaseTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } + /** - * @param validUntilTime the validUntilTime to set + * @param releaseTime the releaseTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Artifact setValidUntilTime(@Nullable String validUntilTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME, validUntilTime); + public Artifact setReleaseTime(@Nullable DateTime releaseTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME, releaseTime); return this; } /** * @return the builtTime */ - public Optional getBuiltTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME); + @SuppressWarnings("unchecked") + public Optional getBuiltTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } + /** * @param builtTime the builtTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Artifact setBuiltTime(@Nullable String builtTime) throws InvalidSPDXAnalysisException { + public Artifact setBuiltTime(@Nullable DateTime builtTime) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME, builtTime); return this; } @@ -182,30 +212,39 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional validUntilTime; try { - @SuppressWarnings("unused") - Optional releaseTime = getReleaseTime(); + validUntilTime = getValidUntilTime(); + if (validUntilTime.isPresent()) { + retval.addAll(validUntilTime.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting releaseTime for Artifact: "+e.getMessage()); + retval.add("Error getting validUntilTime for Artifact: "+e.getMessage()); } + Optional releaseTime; try { - @SuppressWarnings("unused") - Optional validUntilTime = getValidUntilTime(); + releaseTime = getReleaseTime(); + if (releaseTime.isPresent()) { + retval.addAll(releaseTime.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting validUntilTime for Artifact: "+e.getMessage()); + retval.add("Error getting releaseTime for Artifact: "+e.getMessage()); } + Optional builtTime; try { - @SuppressWarnings("unused") - Optional builtTime = getBuiltTime(); + builtTime = getBuiltTime(); + if (builtTime.isPresent()) { + retval.addAll(builtTime.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting builtTime for Artifact: "+e.getMessage()); } - for (Agent originatedBy:originatedBys) { - retval.addAll(originatedBy.verify(verifiedIds, specVersion, profiles)); - } for (Agent suppliedBy:suppliedBys) { retval.addAll(suppliedBy.verify(verifiedIds, specVersion, profiles)); } + for (Agent originatedBy:originatedBys) { + retval.addAll(originatedBy.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -241,58 +280,58 @@ public ArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable Model super(modelStore, objectUri, copyManager); } - Collection originatedBys = new ArrayList<>(); Collection suppliedBys = new ArrayList<>(); + Collection originatedBys = new ArrayList<>(); Collection standards = new ArrayList<>(); - String releaseTime = null; - String validUntilTime = null; - String builtTime = null; + DateTime validUntilTime = null; + DateTime releaseTime = null; + DateTime builtTime = null; /** - * Adds a originatedBy to the initial collection - * @parameter originatedBy originatedBy to add + * Adds a suppliedBy to the initial collection + * @parameter suppliedBy suppliedBy to add * @return this for chaining **/ - ArtifactBuilder addOriginatedBy(Agent originatedBy) { - if (Objects.nonNull(originatedBy)) { - originatedBys.add(originatedBy); + public ArtifactBuilder addSuppliedBy(Agent suppliedBy) { + if (Objects.nonNull(suppliedBy)) { + suppliedBys.add(suppliedBy); } return this; } /** - * Adds all elements from a collection to the initial originatedBy collection - * @parameter originatedByCollection collection to initialize the originatedBy + * Adds all elements from a collection to the initial suppliedBy collection + * @parameter suppliedByCollection collection to initialize the suppliedBy * @return this for chaining **/ - ArtifactBuilder addAllOriginatedBy(Collection originatedByCollection) { - if (Objects.nonNull(originatedByCollection)) { - originatedBys.addAll(originatedByCollection); + public ArtifactBuilder addAllSuppliedBy(Collection suppliedByCollection) { + if (Objects.nonNull(suppliedByCollection)) { + suppliedBys.addAll(suppliedByCollection); } return this; } /** - * Adds a suppliedBy to the initial collection - * @parameter suppliedBy suppliedBy to add + * Adds a originatedBy to the initial collection + * @parameter originatedBy originatedBy to add * @return this for chaining **/ - ArtifactBuilder addSuppliedBy(Agent suppliedBy) { - if (Objects.nonNull(suppliedBy)) { - suppliedBys.add(suppliedBy); + public ArtifactBuilder addOriginatedBy(Agent originatedBy) { + if (Objects.nonNull(originatedBy)) { + originatedBys.add(originatedBy); } return this; } /** - * Adds all elements from a collection to the initial suppliedBy collection - * @parameter suppliedByCollection collection to initialize the suppliedBy + * Adds all elements from a collection to the initial originatedBy collection + * @parameter originatedByCollection collection to initialize the originatedBy * @return this for chaining **/ - ArtifactBuilder addAllSuppliedBy(Collection suppliedByCollection) { - if (Objects.nonNull(suppliedByCollection)) { - suppliedBys.addAll(suppliedByCollection); + public ArtifactBuilder addAllOriginatedBy(Collection originatedByCollection) { + if (Objects.nonNull(originatedByCollection)) { + originatedBys.addAll(originatedByCollection); } return this; } @@ -302,7 +341,7 @@ ArtifactBuilder addAllSuppliedBy(Collection suppliedByCollection) { * @parameter standard standard to add * @return this for chaining **/ - ArtifactBuilder addStandard(String standard) { + public ArtifactBuilder addStandard(String standard) { if (Objects.nonNull(standard)) { standards.add(standard); } @@ -314,7 +353,7 @@ ArtifactBuilder addStandard(String standard) { * @parameter standardCollection collection to initialize the standard * @return this for chaining **/ - ArtifactBuilder addAllStandard(Collection standardCollection) { + public ArtifactBuilder addAllStandard(Collection standardCollection) { if (Objects.nonNull(standardCollection)) { standards.addAll(standardCollection); } @@ -322,22 +361,22 @@ ArtifactBuilder addAllStandard(Collection standardCollection) { } /** - * Sets the initial value of releaseTime - * @parameter releaseTime value to set + * Sets the initial value of validUntilTime + * @parameter validUntilTime value to set * @return this for chaining **/ - ArtifactBuilder setReleaseTime(String releaseTime) { - this.releaseTime = releaseTime; + public ArtifactBuilder setValidUntilTime(DateTime validUntilTime) { + this.validUntilTime = validUntilTime; return this; } /** - * Sets the initial value of validUntilTime - * @parameter validUntilTime value to set + * Sets the initial value of releaseTime + * @parameter releaseTime value to set * @return this for chaining **/ - ArtifactBuilder setValidUntilTime(String validUntilTime) { - this.validUntilTime = validUntilTime; + public ArtifactBuilder setReleaseTime(DateTime releaseTime) { + this.releaseTime = releaseTime; return this; } @@ -346,7 +385,7 @@ ArtifactBuilder setValidUntilTime(String validUntilTime) { * @parameter builtTime value to set * @return this for chaining **/ - ArtifactBuilder setBuiltTime(String builtTime) { + public ArtifactBuilder setBuiltTime(DateTime builtTime) { this.builtTime = builtTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Bom.java b/generated/src/main/java/org/spdx/library/model/v3/core/Bom.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/core/Bom.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Bom.java index 52ffdf895..1df0a1db7 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Bom.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Bom.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/core/Bundle.java b/generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/core/Bundle.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java index fdb5ee912..85689cb8f 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Bundle.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -171,7 +171,7 @@ public BundleBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCo * @parameter context value to set * @return this for chaining **/ - BundleBuilder setContext(String context) { + public BundleBuilder setContext(String context) { this.context = context; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java b/generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java similarity index 69% rename from generated/src/main/java/org/spdx/library/model/core/CreationInfo.java rename to generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java index ba3a8188e..c17e5b950 100644 --- a/generated/src/main/java/org/spdx/library/model/core/CreationInfo.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -50,11 +50,8 @@ */ public class CreationInfo extends ModelObject { - Collection createdUsings; Collection createdBys; - Collection createds; - Collection dataLicenses; - Collection specVersions; + Collection createdUsings; Collection profiles; /** @@ -84,12 +81,9 @@ public CreationInfo(String objectUri) throws InvalidSPDXAnalysisException { public CreationInfo(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); createdBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_BY, Agent.class); + createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); profiles = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_PROFILE, ProfileIdentifierType.class); - createds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED, String.class); - dataLicenses = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_DATA_LICENSE, String.class); - specVersions = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SPEC_VERSION, String.class); } /** @@ -100,18 +94,15 @@ public CreationInfo(IModelStore modelStore, String objectUri, @Nullable ModelCop @SuppressWarnings("unchecked") protected CreationInfo(CreationInfoBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); createdBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_BY, Agent.class); + createdUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED_USING, Tool.class); profiles = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_PROFILE, ProfileIdentifierType.class); - createds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CREATED, String.class); - dataLicenses = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_DATA_LICENSE, String.class); - specVersions = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SPEC_VERSION, String.class); - getCreatedUsings().addAll(builder.createdUsings); getCreatedBys().addAll(builder.createdBys); + getCreatedUsings().addAll(builder.createdUsings); getProfiles().addAll(builder.profiles); - getCreateds().addAll(builder.createds); - getDataLicenses().addAll(builder.dataLicenses); - getSpecVersions().addAll(builder.specVersions); + setCreated(builder.created); + setSpecVersion(builder.specVersion); + setDataLicense(builder.dataLicense); setComment(builder.comment); } @@ -124,25 +115,87 @@ public String getType() { } // Getters and Setters - public Collection getCreatedUsings() { - return createdUsings; - } public Collection getCreatedBys() { return createdBys; } + public Collection getCreatedUsings() { + return createdUsings; + } public Collection getProfiles() { return profiles; } - public Collection getCreateds() { - return createds; + + + /** + * @return the created + */ + @SuppressWarnings("unchecked") + public Optional getCreated() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CREATED); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } - public Collection getDataLicenses() { - return dataLicenses; + + /** + * @param created the created to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CreationInfo setCreated(@Nullable DateTime created) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_CREATED, created); + return this; } - public Collection getSpecVersions() { - return specVersions; + + /** + * @return the specVersion + */ + @SuppressWarnings("unchecked") + public @Nullable SemVer getSpecVersion() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_SPEC_VERSION); + if (retval.isPresent()) { + if (!(retval.get() instanceof SemVer)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (SemVer)(retval.get()); + } else { + return null; + } + } + + /** + * @param specVersion the specVersion to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CreationInfo setSpecVersion(@Nullable SemVer specVersion) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(specVersion)) { + throw new InvalidSPDXAnalysisException("specVersion is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_SPEC_VERSION, specVersion); + return this; + } + + /** + * @return the dataLicense + */ + public Optional getDataLicense() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_DATA_LICENSE); + } + /** + * @param dataLicense the dataLicense to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CreationInfo setDataLicense(@Nullable String dataLicense) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_DATA_LICENSE, dataLicense); + return this; } - /** * @return the comment @@ -172,18 +225,44 @@ public String toString() { @Override protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); + Optional created; + try { + created = getCreated(); + if (created.isPresent()) { + retval.addAll(created.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting created for CreationInfo: "+e.getMessage()); + } + SemVer specVersion; + try { + specVersion = getSpecVersion(); + if (Objects.nonNull(specVersion)) { + retval.addAll(specVersion.verify(verifiedIds, specVersion, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing specVersion in CreationInfo"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting specVersion for CreationInfo: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional dataLicense = getDataLicense(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting dataLicense for CreationInfo: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting comment for CreationInfo: "+e.getMessage()); } - for (Tool createdUsing:createdUsings) { - retval.addAll(createdUsing.verify(verifiedIds, specVersion, profiles)); - } for (Agent createdBy:createdBys) { retval.addAll(createdBy.verify(verifiedIds, specVersion, profiles)); } + for (Tool createdUsing:createdUsings) { + retval.addAll(createdUsing.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -219,45 +298,21 @@ public CreationInfoBuilder(IModelStore modelStore, String objectUri, @Nullable M super(modelStore, objectUri, copyManager); } - Collection createdUsings = new ArrayList<>(); Collection createdBys = new ArrayList<>(); + Collection createdUsings = new ArrayList<>(); Collection profiles = new ArrayList<>(); - Collection createds = new ArrayList<>(); - Collection dataLicenses = new ArrayList<>(); - Collection specVersions = new ArrayList<>(); + DateTime created = null; + SemVer specVersion = null; + String dataLicense = null; String comment = null; - /** - * Adds a createdUsing to the initial collection - * @parameter createdUsing createdUsing to add - * @return this for chaining - **/ - CreationInfoBuilder addCreatedUsing(Tool createdUsing) { - if (Objects.nonNull(createdUsing)) { - createdUsings.add(createdUsing); - } - return this; - } - - /** - * Adds all elements from a collection to the initial createdUsing collection - * @parameter createdUsingCollection collection to initialize the createdUsing - * @return this for chaining - **/ - CreationInfoBuilder addAllCreatedUsing(Collection createdUsingCollection) { - if (Objects.nonNull(createdUsingCollection)) { - createdUsings.addAll(createdUsingCollection); - } - return this; - } - /** * Adds a createdBy to the initial collection * @parameter createdBy createdBy to add * @return this for chaining **/ - CreationInfoBuilder addCreatedBy(Agent createdBy) { + public CreationInfoBuilder addCreatedBy(Agent createdBy) { if (Objects.nonNull(createdBy)) { createdBys.add(createdBy); } @@ -269,7 +324,7 @@ CreationInfoBuilder addCreatedBy(Agent createdBy) { * @parameter createdByCollection collection to initialize the createdBy * @return this for chaining **/ - CreationInfoBuilder addAllCreatedBy(Collection createdByCollection) { + public CreationInfoBuilder addAllCreatedBy(Collection createdByCollection) { if (Objects.nonNull(createdByCollection)) { createdBys.addAll(createdByCollection); } @@ -277,98 +332,80 @@ CreationInfoBuilder addAllCreatedBy(Collection createdByCollection) { } /** - * Adds a profile to the initial collection - * @parameter profile profile to add - * @return this for chaining - **/ - CreationInfoBuilder addProfile(ProfileIdentifierType profile) { - if (Objects.nonNull(profile)) { - profiles.add(profile); - } - return this; - } - - /** - * Adds all elements from a collection to the initial profile collection - * @parameter profileCollection collection to initialize the profile + * Adds a createdUsing to the initial collection + * @parameter createdUsing createdUsing to add * @return this for chaining **/ - CreationInfoBuilder addAllProfile(Collection profileCollection) { - if (Objects.nonNull(profileCollection)) { - profiles.addAll(profileCollection); + public CreationInfoBuilder addCreatedUsing(Tool createdUsing) { + if (Objects.nonNull(createdUsing)) { + createdUsings.add(createdUsing); } return this; } /** - * Adds a created to the initial collection - * @parameter created created to add + * Adds all elements from a collection to the initial createdUsing collection + * @parameter createdUsingCollection collection to initialize the createdUsing * @return this for chaining **/ - CreationInfoBuilder addCreated(String created) { - if (Objects.nonNull(created)) { - createds.add(created); + public CreationInfoBuilder addAllCreatedUsing(Collection createdUsingCollection) { + if (Objects.nonNull(createdUsingCollection)) { + createdUsings.addAll(createdUsingCollection); } return this; } /** - * Adds all elements from a collection to the initial created collection - * @parameter createdCollection collection to initialize the created + * Adds a profile to the initial collection + * @parameter profile profile to add * @return this for chaining **/ - CreationInfoBuilder addAllCreated(Collection createdCollection) { - if (Objects.nonNull(createdCollection)) { - createds.addAll(createdCollection); + public CreationInfoBuilder addProfile(ProfileIdentifierType profile) { + if (Objects.nonNull(profile)) { + profiles.add(profile); } return this; } /** - * Adds a dataLicense to the initial collection - * @parameter dataLicense dataLicense to add + * Adds all elements from a collection to the initial profile collection + * @parameter profileCollection collection to initialize the profile * @return this for chaining **/ - CreationInfoBuilder addDataLicense(String dataLicense) { - if (Objects.nonNull(dataLicense)) { - dataLicenses.add(dataLicense); + public CreationInfoBuilder addAllProfile(Collection profileCollection) { + if (Objects.nonNull(profileCollection)) { + profiles.addAll(profileCollection); } return this; } /** - * Adds all elements from a collection to the initial dataLicense collection - * @parameter dataLicenseCollection collection to initialize the dataLicense + * Sets the initial value of created + * @parameter created value to set * @return this for chaining **/ - CreationInfoBuilder addAllDataLicense(Collection dataLicenseCollection) { - if (Objects.nonNull(dataLicenseCollection)) { - dataLicenses.addAll(dataLicenseCollection); - } + public CreationInfoBuilder setCreated(DateTime created) { + this.created = created; return this; } /** - * Adds a specVersion to the initial collection - * @parameter specVersion specVersion to add + * Sets the initial value of specVersion + * @parameter specVersion value to set * @return this for chaining **/ - CreationInfoBuilder addSpecVersion(String specVersion) { - if (Objects.nonNull(specVersion)) { - specVersions.add(specVersion); - } + public CreationInfoBuilder setSpecVersion(SemVer specVersion) { + this.specVersion = specVersion; return this; } /** - * Adds all elements from a collection to the initial specVersion collection - * @parameter specVersionCollection collection to initialize the specVersion + * Sets the initial value of dataLicense + * @parameter dataLicense value to set * @return this for chaining **/ - CreationInfoBuilder addAllSpecVersion(Collection specVersionCollection) { - if (Objects.nonNull(specVersionCollection)) { - specVersions.addAll(specVersionCollection); - } + public CreationInfoBuilder setDataLicense(String dataLicense) { + this.dataLicense = dataLicense; return this; } @@ -377,7 +414,7 @@ CreationInfoBuilder addAllSpecVersion(Collection specVersionCollection) * @parameter comment value to set * @return this for chaining **/ - CreationInfoBuilder setComment(String comment) { + public CreationInfoBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java b/generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java rename to generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java index 6f5722e06..3794533cc 100644 --- a/generated/src/main/java/org/spdx/library/model/core/DictionaryEntry.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -207,7 +207,7 @@ public DictionaryEntryBuilder(IModelStore modelStore, String objectUri, @Nullabl * @parameter key value to set * @return this for chaining **/ - DictionaryEntryBuilder setKey(String key) { + public DictionaryEntryBuilder setKey(String key) { this.key = key; return this; } @@ -217,7 +217,7 @@ DictionaryEntryBuilder setKey(String key) { * @parameter value value to set * @return this for chaining **/ - DictionaryEntryBuilder setValue(String value) { + public DictionaryEntryBuilder setValue(String value) { this.value = value; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Element.java b/generated/src/main/java/org/spdx/library/model/v3/core/Element.java similarity index 63% rename from generated/src/main/java/org/spdx/library/model/core/Element.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Element.java index b8c75175f..cf650e8ff 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Element.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Element.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -32,7 +32,9 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; @@ -47,10 +49,11 @@ * structure this is the base class acting as a consistent, unifying, and interoperable * foundation for all explicit and inter-relatable content objects. */ -public class Element extends Payload { +public class Element extends ModelObject { - Collection externalReferences; Collection externalIdentifiers; + Collection verifiedUsings; + Collection externalReferences; /** * Create the Element with default model store and generated anonymous ID @@ -79,8 +82,9 @@ public Element(String objectUri) throws InvalidSPDXAnalysisException { public Element(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); externalIdentifiers = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER, ExternalIdentifier.class); + verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); + externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); } /** @@ -91,10 +95,15 @@ public Element(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana @SuppressWarnings("unchecked") protected Element(ElementBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); externalIdentifiers = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER, ExternalIdentifier.class); - getExternalReferences().addAll(builder.externalReferences); + verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); + externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); getExternalIdentifiers().addAll(builder.externalIdentifiers); + getVerifiedUsings().addAll(builder.verifiedUsings); + getExternalReferences().addAll(builder.externalReferences); + setCreationInfo(builder.creationInfo); + setComment(builder.comment); + setName(builder.name); setDescription(builder.description); setSummary(builder.summary); } @@ -108,14 +117,77 @@ public String getType() { } // Getters and Setters - public Collection getExternalReferences() { - return externalReferences; - } public Collection getExternalIdentifiers() { return externalIdentifiers; } + public Collection getVerifiedUsings() { + return verifiedUsings; + } + public Collection getExternalReferences() { + return externalReferences; + } + /** + * @return the creationInfo + */ + public @Nullable CreationInfo getCreationInfo() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO); + if (retval.isPresent()) { + if (!(retval.get() instanceof CreationInfo)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (CreationInfo)(retval.get()); + } else { + return null; + } + } + + /** + * @param creationInfo the creationInfo to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Element setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(creationInfo)) { + throw new InvalidSPDXAnalysisException("creationInfo is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO, creationInfo); + return this; + } + + /** + * @return the comment + */ + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + } + /** + * @param comment the comment to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Element setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + return this; + } + + /** + * @return the name + */ + public Optional getName() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_NAME); + } + /** + * @param name the name to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Element setName(@Nullable String name) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_NAME, name); + return this; + } + /** * @return the description */ @@ -160,7 +232,29 @@ public String toString() { @Override protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + CreationInfo creationInfo; + try { + creationInfo = getCreationInfo(); + if (Objects.nonNull(creationInfo)) { + retval.addAll(creationInfo.verify(verifiedIds, specVersion, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing creationInfo in Element"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting creationInfo for Element: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional comment = getComment(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting comment for Element: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional name = getName(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting name for Element: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional description = getDescription(); @@ -173,16 +267,19 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting summary for Element: "+e.getMessage()); } - for (ExternalReference externalReference:externalReferences) { - retval.addAll(externalReference.verify(verifiedIds, specVersion, profiles)); - } for (ExternalIdentifier externalIdentifier:externalIdentifiers) { retval.addAll(externalIdentifier.verify(verifiedIds, specVersion, profiles)); } + for (IntegrityMethod verifiedUsing:verifiedUsings) { + retval.addAll(verifiedUsing.verify(verifiedIds, specVersion, profiles)); + } + for (ExternalReference externalReference:externalReferences) { + retval.addAll(externalReference.verify(verifiedIds, specVersion, profiles)); + } return retval; } - public static class ElementBuilder extends PayloadBuilder { + public static class ElementBuilder extends ModelObjectBuilder { /** * Create an ElementBuilder from another model object copying the modelStore and copyManager and using an anonymous ID @@ -214,18 +311,70 @@ public ElementBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC super(modelStore, objectUri, copyManager); } - Collection externalReferences = new ArrayList<>(); Collection externalIdentifiers = new ArrayList<>(); + Collection verifiedUsings = new ArrayList<>(); + Collection externalReferences = new ArrayList<>(); + CreationInfo creationInfo = null; + String comment = null; + String name = null; String description = null; String summary = null; + /** + * Adds a externalIdentifier to the initial collection + * @parameter externalIdentifier externalIdentifier to add + * @return this for chaining + **/ + public ElementBuilder addExternalIdentifier(ExternalIdentifier externalIdentifier) { + if (Objects.nonNull(externalIdentifier)) { + externalIdentifiers.add(externalIdentifier); + } + return this; + } + + /** + * Adds all elements from a collection to the initial externalIdentifier collection + * @parameter externalIdentifierCollection collection to initialize the externalIdentifier + * @return this for chaining + **/ + public ElementBuilder addAllExternalIdentifier(Collection externalIdentifierCollection) { + if (Objects.nonNull(externalIdentifierCollection)) { + externalIdentifiers.addAll(externalIdentifierCollection); + } + return this; + } + + /** + * Adds a verifiedUsing to the initial collection + * @parameter verifiedUsing verifiedUsing to add + * @return this for chaining + **/ + public ElementBuilder addVerifiedUsing(IntegrityMethod verifiedUsing) { + if (Objects.nonNull(verifiedUsing)) { + verifiedUsings.add(verifiedUsing); + } + return this; + } + + /** + * Adds all elements from a collection to the initial verifiedUsing collection + * @parameter verifiedUsingCollection collection to initialize the verifiedUsing + * @return this for chaining + **/ + public ElementBuilder addAllVerifiedUsing(Collection verifiedUsingCollection) { + if (Objects.nonNull(verifiedUsingCollection)) { + verifiedUsings.addAll(verifiedUsingCollection); + } + return this; + } + /** * Adds a externalReference to the initial collection * @parameter externalReference externalReference to add * @return this for chaining **/ - ElementBuilder addExternalReference(ExternalReference externalReference) { + public ElementBuilder addExternalReference(ExternalReference externalReference) { if (Objects.nonNull(externalReference)) { externalReferences.add(externalReference); } @@ -237,7 +386,7 @@ ElementBuilder addExternalReference(ExternalReference externalReference) { * @parameter externalReferenceCollection collection to initialize the externalReference * @return this for chaining **/ - ElementBuilder addAllExternalReference(Collection externalReferenceCollection) { + public ElementBuilder addAllExternalReference(Collection externalReferenceCollection) { if (Objects.nonNull(externalReferenceCollection)) { externalReferences.addAll(externalReferenceCollection); } @@ -245,26 +394,32 @@ ElementBuilder addAllExternalReference(Collection externalRef } /** - * Adds a externalIdentifier to the initial collection - * @parameter externalIdentifier externalIdentifier to add + * Sets the initial value of creationInfo + * @parameter creationInfo value to set * @return this for chaining **/ - ElementBuilder addExternalIdentifier(ExternalIdentifier externalIdentifier) { - if (Objects.nonNull(externalIdentifier)) { - externalIdentifiers.add(externalIdentifier); - } + public ElementBuilder setCreationInfo(CreationInfo creationInfo) { + this.creationInfo = creationInfo; return this; } /** - * Adds all elements from a collection to the initial externalIdentifier collection - * @parameter externalIdentifierCollection collection to initialize the externalIdentifier + * Sets the initial value of comment + * @parameter comment value to set * @return this for chaining **/ - ElementBuilder addAllExternalIdentifier(Collection externalIdentifierCollection) { - if (Objects.nonNull(externalIdentifierCollection)) { - externalIdentifiers.addAll(externalIdentifierCollection); - } + public ElementBuilder setComment(String comment) { + this.comment = comment; + return this; + } + + /** + * Sets the initial value of name + * @parameter name value to set + * @return this for chaining + **/ + public ElementBuilder setName(String name) { + this.name = name; return this; } @@ -273,7 +428,7 @@ ElementBuilder addAllExternalIdentifier(Collection externalI * @parameter description value to set * @return this for chaining **/ - ElementBuilder setDescription(String description) { + public ElementBuilder setDescription(String description) { this.description = description; return this; } @@ -283,7 +438,7 @@ ElementBuilder setDescription(String description) { * @parameter summary value to set * @return this for chaining **/ - ElementBuilder setSummary(String summary) { + public ElementBuilder setSummary(String summary) { this.summary = summary; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java b/generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java similarity index 82% rename from generated/src/main/java/org/spdx/library/model/core/ElementCollection.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java index 2f1eeefa9..d4adc0198 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ElementCollection.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -47,8 +47,9 @@ */ public class ElementCollection extends Element { - Collection elements; + Collection importss; Collection rootElements; + Collection elements; /** * Create the ElementCollection with default model store and generated anonymous ID @@ -77,8 +78,9 @@ public ElementCollection(String objectUri) throws InvalidSPDXAnalysisException { public ElementCollection(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); + elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); } /** @@ -89,10 +91,12 @@ public ElementCollection(IModelStore modelStore, String objectUri, @Nullable Mod @SuppressWarnings("unchecked") protected ElementCollection(ElementCollectionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); - getElements().addAll(builder.elements); + elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + getImportss().addAll(builder.importss); getRootElements().addAll(builder.rootElements); + getElements().addAll(builder.elements); } /* (non-Javadoc) @@ -104,12 +108,15 @@ public String getType() { } // Getters and Setters - public Collection getElements() { - return elements; + public Collection getImportss() { + return importss; } public Collection getRootElements() { return rootElements; } + public Collection getElements() { + return elements; + } @@ -125,12 +132,15 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - for (Element element:elements) { - retval.addAll(element.verify(verifiedIds, specVersion, profiles)); + for (ExternalMap imports:importss) { + retval.addAll(imports.verify(verifiedIds, specVersion, profiles)); } for (Element rootElement:rootElements) { retval.addAll(rootElement.verify(verifiedIds, specVersion, profiles)); } + for (Element element:elements) { + retval.addAll(element.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -166,30 +176,31 @@ public ElementCollectionBuilder(IModelStore modelStore, String objectUri, @Nulla super(modelStore, objectUri, copyManager); } - Collection elements = new ArrayList<>(); + Collection importss = new ArrayList<>(); Collection rootElements = new ArrayList<>(); + Collection elements = new ArrayList<>(); /** - * Adds a element to the initial collection - * @parameter element element to add + * Adds a imports to the initial collection + * @parameter imports imports to add * @return this for chaining **/ - ElementCollectionBuilder addElement(Element element) { - if (Objects.nonNull(element)) { - elements.add(element); + public ElementCollectionBuilder addImports(ExternalMap imports) { + if (Objects.nonNull(imports)) { + importss.add(imports); } return this; } /** - * Adds all elements from a collection to the initial element collection - * @parameter elementCollection collection to initialize the element + * Adds all elements from a collection to the initial imports collection + * @parameter importsCollection collection to initialize the imports * @return this for chaining **/ - ElementCollectionBuilder addAllElement(Collection elementCollection) { - if (Objects.nonNull(elementCollection)) { - elements.addAll(elementCollection); + public ElementCollectionBuilder addAllImports(Collection importsCollection) { + if (Objects.nonNull(importsCollection)) { + importss.addAll(importsCollection); } return this; } @@ -199,7 +210,7 @@ ElementCollectionBuilder addAllElement(Collection elementCollection) { * @parameter rootElement rootElement to add * @return this for chaining **/ - ElementCollectionBuilder addRootElement(Element rootElement) { + public ElementCollectionBuilder addRootElement(Element rootElement) { if (Objects.nonNull(rootElement)) { rootElements.add(rootElement); } @@ -211,12 +222,36 @@ ElementCollectionBuilder addRootElement(Element rootElement) { * @parameter rootElementCollection collection to initialize the rootElement * @return this for chaining **/ - ElementCollectionBuilder addAllRootElement(Collection rootElementCollection) { + public ElementCollectionBuilder addAllRootElement(Collection rootElementCollection) { if (Objects.nonNull(rootElementCollection)) { rootElements.addAll(rootElementCollection); } return this; } + + /** + * Adds a element to the initial collection + * @parameter element element to add + * @return this for chaining + **/ + public ElementCollectionBuilder addElement(Element element) { + if (Objects.nonNull(element)) { + elements.add(element); + } + return this; + } + + /** + * Adds all elements from a collection to the initial element collection + * @parameter elementCollection collection to initialize the element + * @return this for chaining + **/ + public ElementCollectionBuilder addAllElement(Collection elementCollection) { + if (Objects.nonNull(elementCollection)) { + elements.addAll(elementCollection); + } + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java similarity index 95% rename from generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java index f3b6db022..9cca4d760 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifier.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -91,9 +91,9 @@ protected ExternalIdentifier(ExternalIdentifierBuilder builder) throws InvalidSP identifierLocators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IDENTIFIER_LOCATOR, String.class); getIdentifierLocators().addAll(builder.identifierLocators); setExternalIdentifierType(builder.externalIdentifierType); - setIssuingAuthority(builder.issuingAuthority); - setIdentifier(builder.identifier); setComment(builder.comment); + setIdentifier(builder.identifier); + setIssuingAuthority(builder.issuingAuthority); } /* (non-Javadoc) @@ -138,18 +138,18 @@ public ExternalIdentifier setExternalIdentifierType(@Nullable ExternalIdentifier } /** - * @return the issuingAuthority + * @return the comment */ - public Optional getIssuingAuthority() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY); + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); } /** - * @param issuingAuthority the issuingAuthority to set + * @param comment the comment to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ExternalIdentifier setIssuingAuthority(@Nullable String issuingAuthority) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY, issuingAuthority); + public ExternalIdentifier setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); return this; } @@ -174,18 +174,18 @@ public ExternalIdentifier setIdentifier(@Nullable String identifier) throws Inva } /** - * @return the comment + * @return the issuingAuthority */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + public Optional getIssuingAuthority() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY); } /** - * @param comment the comment to set + * @param issuingAuthority the issuingAuthority to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ExternalIdentifier setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + public ExternalIdentifier setIssuingAuthority(@Nullable String issuingAuthority) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY, issuingAuthority); return this; } @@ -212,9 +212,9 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional issuingAuthority = getIssuingAuthority(); + Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting issuingAuthority for ExternalIdentifier: "+e.getMessage()); + retval.add("Error getting comment for ExternalIdentifier: "+e.getMessage()); } try { String identifier = getIdentifier(); @@ -227,9 +227,9 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional comment = getComment(); + Optional issuingAuthority = getIssuingAuthority(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting comment for ExternalIdentifier: "+e.getMessage()); + retval.add("Error getting issuingAuthority for ExternalIdentifier: "+e.getMessage()); } return retval; } @@ -268,9 +268,9 @@ public ExternalIdentifierBuilder(IModelStore modelStore, String objectUri, @Null Collection identifierLocators = new ArrayList<>(); ExternalIdentifierType externalIdentifierType = null; - String issuingAuthority = null; - String identifier = null; String comment = null; + String identifier = null; + String issuingAuthority = null; /** @@ -278,7 +278,7 @@ public ExternalIdentifierBuilder(IModelStore modelStore, String objectUri, @Null * @parameter identifierLocator identifierLocator to add * @return this for chaining **/ - ExternalIdentifierBuilder addIdentifierLocator(String identifierLocator) { + public ExternalIdentifierBuilder addIdentifierLocator(String identifierLocator) { if (Objects.nonNull(identifierLocator)) { identifierLocators.add(identifierLocator); } @@ -290,7 +290,7 @@ ExternalIdentifierBuilder addIdentifierLocator(String identifierLocator) { * @parameter identifierLocatorCollection collection to initialize the identifierLocator * @return this for chaining **/ - ExternalIdentifierBuilder addAllIdentifierLocator(Collection identifierLocatorCollection) { + public ExternalIdentifierBuilder addAllIdentifierLocator(Collection identifierLocatorCollection) { if (Objects.nonNull(identifierLocatorCollection)) { identifierLocators.addAll(identifierLocatorCollection); } @@ -302,18 +302,18 @@ ExternalIdentifierBuilder addAllIdentifierLocator(Collection identifierL * @parameter externalIdentifierType value to set * @return this for chaining **/ - ExternalIdentifierBuilder setExternalIdentifierType(ExternalIdentifierType externalIdentifierType) { + public ExternalIdentifierBuilder setExternalIdentifierType(ExternalIdentifierType externalIdentifierType) { this.externalIdentifierType = externalIdentifierType; return this; } /** - * Sets the initial value of issuingAuthority - * @parameter issuingAuthority value to set + * Sets the initial value of comment + * @parameter comment value to set * @return this for chaining **/ - ExternalIdentifierBuilder setIssuingAuthority(String issuingAuthority) { - this.issuingAuthority = issuingAuthority; + public ExternalIdentifierBuilder setComment(String comment) { + this.comment = comment; return this; } @@ -322,18 +322,18 @@ ExternalIdentifierBuilder setIssuingAuthority(String issuingAuthority) { * @parameter identifier value to set * @return this for chaining **/ - ExternalIdentifierBuilder setIdentifier(String identifier) { + public ExternalIdentifierBuilder setIdentifier(String identifier) { this.identifier = identifier; return this; } /** - * Sets the initial value of comment - * @parameter comment value to set + * Sets the initial value of issuingAuthority + * @parameter issuingAuthority value to set * @return this for chaining **/ - ExternalIdentifierBuilder setComment(String comment) { - this.comment = comment; + public ExternalIdentifierBuilder setIssuingAuthority(String issuingAuthority) { + this.issuingAuthority = issuingAuthority; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java similarity index 88% rename from generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java index aec6594b5..f9b6e20eb 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalIdentifierType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -28,17 +28,17 @@ */ public enum ExternalIdentifierType implements IndividualUriValue { - SWHID("swhid"), - SECURITY_OTHER("securityOther"), - URL_SCHEME("urlScheme"), + CPE23("cpe23"), + CVE("cve"), + CPE22("cpe22"), PKG_URL("pkgUrl"), - CPE_2_3("cpe23"), + SWHID("swhid"), GITOID("gitoid"), - SWID("swid"), - CPE_2_2("cpe22"), EMAIL("email"), - CVE("cve"), - OTHER("other"); + OTHER("other"), + SWID("swid"), + SECURITY_OTHER("securityOther"), + URL_SCHEME("urlScheme"); private String longName; @@ -56,7 +56,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/ExternalIdentifierType"; + return "https://spdx.org/rdf/v3/Core/ExternalIdentifierType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java similarity index 96% rename from generated/src/main/java/org/spdx/library/model/core/ExternalMap.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java index 6c687e16d..1d98e0422 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalMap.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -91,9 +91,9 @@ protected ExternalMap(ExternalMapBuilder builder) throws InvalidSPDXAnalysisExce super(builder); verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); getVerifiedUsings().addAll(builder.verifiedUsings); + setExternalId(builder.externalId); setDefiningDocument(builder.definingDocument); setLocationHint(builder.locationHint); - setExternalId(builder.externalId); } /* (non-Javadoc) @@ -110,6 +110,26 @@ public Collection getVerifiedUsings() { } + /** + * @return the externalId + */ + public @Nullable String getExternalId() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_ID); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param externalId the externalId to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalMap setExternalId(@Nullable String externalId) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(externalId)) { + throw new InvalidSPDXAnalysisException("externalId is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_ID, externalId); + return this; + } + /** * @return the definingDocument */ @@ -141,26 +161,6 @@ public ExternalMap setLocationHint(@Nullable String locationHint) throws Invalid setPropertyValue(SpdxConstants.CORE_PROP_LOCATION_HINT, locationHint); return this; } - - /** - * @return the externalId - */ - public @Nullable String getExternalId() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_ID); - return retval.isPresent() ? retval.get() : null; - } - /** - * @param externalId the externalId to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalMap setExternalId(@Nullable String externalId) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(externalId)) { - throw new InvalidSPDXAnalysisException("externalId is a required property"); - } - setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_ID, externalId); - return this; - } @Override @@ -174,6 +174,15 @@ public String toString() { @Override protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); + try { + String externalId = getExternalId(); + if (Objects.isNull(externalId) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing externalId in ExternalMap"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting externalId for ExternalMap: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional definingDocument = getDefiningDocument(); @@ -186,15 +195,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting locationHint for ExternalMap: "+e.getMessage()); } - try { - String externalId = getExternalId(); - if (Objects.isNull(externalId) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing externalId in ExternalMap"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting externalId for ExternalMap: "+e.getMessage()); - } for (IntegrityMethod verifiedUsing:verifiedUsings) { retval.addAll(verifiedUsing.verify(verifiedIds, specVersion, profiles)); } @@ -234,9 +234,9 @@ public ExternalMapBuilder(IModelStore modelStore, String objectUri, @Nullable Mo } Collection verifiedUsings = new ArrayList<>(); + String externalId = null; String definingDocument = null; String locationHint = null; - String externalId = null; /** @@ -244,7 +244,7 @@ public ExternalMapBuilder(IModelStore modelStore, String objectUri, @Nullable Mo * @parameter verifiedUsing verifiedUsing to add * @return this for chaining **/ - ExternalMapBuilder addVerifiedUsing(IntegrityMethod verifiedUsing) { + public ExternalMapBuilder addVerifiedUsing(IntegrityMethod verifiedUsing) { if (Objects.nonNull(verifiedUsing)) { verifiedUsings.add(verifiedUsing); } @@ -256,7 +256,7 @@ ExternalMapBuilder addVerifiedUsing(IntegrityMethod verifiedUsing) { * @parameter verifiedUsingCollection collection to initialize the verifiedUsing * @return this for chaining **/ - ExternalMapBuilder addAllVerifiedUsing(Collection verifiedUsingCollection) { + public ExternalMapBuilder addAllVerifiedUsing(Collection verifiedUsingCollection) { if (Objects.nonNull(verifiedUsingCollection)) { verifiedUsings.addAll(verifiedUsingCollection); } @@ -264,32 +264,32 @@ ExternalMapBuilder addAllVerifiedUsing(Collection verifiedUsing } /** - * Sets the initial value of definingDocument - * @parameter definingDocument value to set + * Sets the initial value of externalId + * @parameter externalId value to set * @return this for chaining **/ - ExternalMapBuilder setDefiningDocument(String definingDocument) { - this.definingDocument = definingDocument; + public ExternalMapBuilder setExternalId(String externalId) { + this.externalId = externalId; return this; } /** - * Sets the initial value of locationHint - * @parameter locationHint value to set + * Sets the initial value of definingDocument + * @parameter definingDocument value to set * @return this for chaining **/ - ExternalMapBuilder setLocationHint(String locationHint) { - this.locationHint = locationHint; + public ExternalMapBuilder setDefiningDocument(String definingDocument) { + this.definingDocument = definingDocument; return this; } /** - * Sets the initial value of externalId - * @parameter externalId value to set + * Sets the initial value of locationHint + * @parameter locationHint value to set * @return this for chaining **/ - ExternalMapBuilder setExternalId(String externalId) { - this.externalId = externalId; + public ExternalMapBuilder setLocationHint(String locationHint) { + this.locationHint = locationHint; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReference.java similarity index 88% rename from generated/src/main/java/org/spdx/library/model/core/ExternalReference.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalReference.java index 66dfdbdbc..75bab2fa6 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalReference.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReference.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -88,8 +88,8 @@ protected ExternalReference(ExternalReferenceBuilder builder) throws InvalidSPDX super(builder); locators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_LOCATOR, String.class); getLocators().addAll(builder.locators); - setExternalReferenceType(builder.externalReferenceType); setContentType(builder.contentType); + setExternalReferenceType(builder.externalReferenceType); setComment(builder.comment); } @@ -106,6 +106,32 @@ public Collection getLocators() { return locators; } + + /** + * @return the contentType + */ + @SuppressWarnings("unchecked") + public Optional getContentType() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof MediaType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param contentType the contentType to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalReference setContentType(@Nullable MediaType contentType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE, contentType); + return this; + } /** * @return the externalReferenceType @@ -132,22 +158,6 @@ public ExternalReference setExternalReferenceType(@Nullable ExternalReferenceTyp return this; } - /** - * @return the contentType - */ - public Optional getContentType() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE); - } - /** - * @param contentType the contentType to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalReference setContentType(@Nullable String contentType) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE, contentType); - return this; - } - /** * @return the comment */ @@ -176,17 +186,20 @@ public String toString() { @Override protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); + Optional contentType; try { - @SuppressWarnings("unused") - Optional externalReferenceType = getExternalReferenceType(); + contentType = getContentType(); + if (contentType.isPresent()) { + retval.addAll(contentType.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting externalReferenceType for ExternalReference: "+e.getMessage()); + retval.add("Error getting contentType for ExternalReference: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional contentType = getContentType(); + Optional externalReferenceType = getExternalReferenceType(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting contentType for ExternalReference: "+e.getMessage()); + retval.add("Error getting externalReferenceType for ExternalReference: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -230,8 +243,8 @@ public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nulla } Collection locators = new ArrayList<>(); + MediaType contentType = null; ExternalReferenceType externalReferenceType = null; - String contentType = null; String comment = null; @@ -240,7 +253,7 @@ public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nulla * @parameter locator locator to add * @return this for chaining **/ - ExternalReferenceBuilder addLocator(String locator) { + public ExternalReferenceBuilder addLocator(String locator) { if (Objects.nonNull(locator)) { locators.add(locator); } @@ -252,7 +265,7 @@ ExternalReferenceBuilder addLocator(String locator) { * @parameter locatorCollection collection to initialize the locator * @return this for chaining **/ - ExternalReferenceBuilder addAllLocator(Collection locatorCollection) { + public ExternalReferenceBuilder addAllLocator(Collection locatorCollection) { if (Objects.nonNull(locatorCollection)) { locators.addAll(locatorCollection); } @@ -260,22 +273,22 @@ ExternalReferenceBuilder addAllLocator(Collection locatorCollection) { } /** - * Sets the initial value of externalReferenceType - * @parameter externalReferenceType value to set + * Sets the initial value of contentType + * @parameter contentType value to set * @return this for chaining **/ - ExternalReferenceBuilder setExternalReferenceType(ExternalReferenceType externalReferenceType) { - this.externalReferenceType = externalReferenceType; + public ExternalReferenceBuilder setContentType(MediaType contentType) { + this.contentType = contentType; return this; } /** - * Sets the initial value of contentType - * @parameter contentType value to set + * Sets the initial value of externalReferenceType + * @parameter externalReferenceType value to set * @return this for chaining **/ - ExternalReferenceBuilder setContentType(String contentType) { - this.contentType = contentType; + public ExternalReferenceBuilder setExternalReferenceType(ExternalReferenceType externalReferenceType) { + this.externalReferenceType = externalReferenceType; return this; } @@ -284,7 +297,7 @@ ExternalReferenceBuilder setContentType(String contentType) { * @parameter comment value to set * @return this for chaining **/ - ExternalReferenceBuilder setComment(String comment) { + public ExternalReferenceBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReferenceType.java similarity index 89% rename from generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalReferenceType.java index 9de382914..779fbefc3 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ExternalReferenceType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReferenceType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -28,44 +28,47 @@ */ public enum ExternalReferenceType implements IndividualUriValue { + DYNAMIC_ANALYSIS_REPORT("dynamicAnalysisReport"), + EXPORT_CONTROL_ASSESSMENT("exportControlAssessment"), + BUILD_META("buildMeta"), + PRIVACY_ASSESSMENT("privacyAssessment"), VULNERABILITY_EXPLOITABILITY_ASSESSMENT("vulnerabilityExploitabilityAssessment"), - BINARY_ARTIFACT("binaryArtifact"), + DOCUMENTATION("documentation"), + RISK_ASSESSMENT("riskAssessment"), + QUALITY_ASSESSMENT_REPORT("qualityAssessmentReport"), + SECURITY_ADVERSARY_MODEL("securityAdversaryModel"), + SECURITY_FIX("securityFix"), + OTHER("other"), RELEASE_HISTORY("releaseHistory"), - FUNDING("funding"), - BUILD_META("buildMeta"), - PRODUCT_METADATA("productMetadata"), - STATIC_ANALYSIS_REPORT("staticAnalysisReport"), - DYNAMIC_ANALYSIS_REPORT("dynamicAnalysisReport"), - MAILING_LIST("mailingList"), - ALT_DOWNLOAD_LOCATION("altDownloadLocation"), - CHAT("chat"), - LICENSE("license"), + VCS("vcs"), + SECURITY_THREAT_MODEL("securityThreatModel"), VULNERABILITY_DISCLOSURE_REPORT("vulnerabilityDisclosureReport"), - QUALITY_ASSESSMENT_REPORT("qualityAssessmentReport"), + SOURCE_ARTIFACT("sourceArtifact"), + FUNDING("funding"), BUILD_SYSTEM("buildSystem"), - SECURITY_THREAT_MODEL("securityThreatModel"), - METRICS("metrics"), - EOL_NOTICE("eolNotice"), - SECURITY_PEN_TEST_REPORT("securityPenTestReport"), - SECURITY_ADVISORY("securityAdvisory"), - DOCUMENTATION("documentation"), - VCS("vcs"), + CHAT("chat"), SUPPORT("support"), - SECURITY_FIX("securityFix"), - SECURE_SOFTWARE_ATTESTATION("secureSoftwareAttestation"), - SOURCE_ARTIFACT("sourceArtifact"), - SECURITY_ADVERSARY_MODEL("securityAdversaryModel"), + ALT_DOWNLOAD_LOCATION("altDownloadLocation"), RELEASE_NOTES("releaseNotes"), - SECURITY_POLICY("securityPolicy"), - ALT_WEB_PAGE("altWebPage"), - RISK_ASSESSMENT("riskAssessment"), SECURITY_OTHER("securityOther"), - CERTIFICATION_REPORT("certificationReport"), + SECURITY_POLICY("securityPolicy"), RUNTIME_ANALYSIS_REPORT("runtimeAnalysisReport"), - OTHER("other"), - ISSUE_TRACKER("issueTracker"), + SECURITY_PEN_TEST_REPORT("securityPenTestReport"), + EOL_NOTICE("eolNotice"), + SECURE_SOFTWARE_ATTESTATION("secureSoftwareAttestation"), + CERTIFICATION_REPORT("certificationReport"), + STATIC_ANALYSIS_REPORT("staticAnalysisReport"), + LICENSE("license"), + ALT_WEB_PAGE("altWebPage"), + SECURITY_ADVISORY("securityAdvisory"), + BINARY_ARTIFACT("binaryArtifact"), + MAILING_LIST("mailingList"), + PRODUCT_METADATA("productMetadata"), + METRICS("metrics"), + PURCHASE_ORDER("purchaseOrder"), SOCIAL_MEDIA("socialMedia"), - COMPONENT_ANALYSIS_REPORT("componentAnalysisReport"); + COMPONENT_ANALYSIS_REPORT("componentAnalysisReport"), + ISSUE_TRACKER("issueTracker"); private String longName; @@ -83,7 +86,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/ExternalReferenceType"; + return "https://spdx.org/rdf/v3/Core/ExternalReferenceType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/Hash.java b/generated/src/main/java/org/spdx/library/model/v3/core/Hash.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/core/Hash.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Hash.java index cdca98f22..a67c06665 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Hash.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Hash.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -222,7 +222,7 @@ public HashBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopy * @parameter algorithm value to set * @return this for chaining **/ - HashBuilder setAlgorithm(HashAlgorithm algorithm) { + public HashBuilder setAlgorithm(HashAlgorithm algorithm) { this.algorithm = algorithm; return this; } @@ -232,7 +232,7 @@ HashBuilder setAlgorithm(HashAlgorithm algorithm) { * @parameter hashValue value to set * @return this for chaining **/ - HashBuilder setHashValue(String hashValue) { + public HashBuilder setHashValue(String hashValue) { this.hashValue = hashValue; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java b/generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java similarity index 73% rename from generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java rename to generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java index fb897baac..7e7448d4b 100644 --- a/generated/src/main/java/org/spdx/library/model/core/HashAlgorithm.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -30,30 +30,30 @@ */ public enum HashAlgorithm implements IndividualUriValue { - SHA_3___5_1_2("sha3_512"), - SPDX_PVC_SHA_1("spdxPvcSha1"), - SHA_5_1_2("sha512"), - FALCON("falcon"), - SHA_2_5_6("sha256"), - SPDX_PVC_SHA_2_5_6("spdxPvcSha256"), - MD_2("md2"), - SHA_3___2_5_6("sha3_256"), - SHA_1("sha1"), - MD_4("md4"), - SHA_3___3_8_4("sha3_384"), - MD_6("md6"), - SPHINCS_PLUS("sphincsPlus"), - SHA_3_8_4("sha384"), - MD_5("md5"), - BLAKE_2B_2_5_6("blake2b256"), - BLAKE_3("blake3"), - OTHER("other"), - BLAKE_2B_5_1_2("blake2b512"), CRYSTALS_DILITHIUM("crystalsDilithium"), - BLAKE_2B_3_8_4("blake2b384"), - SHA_2_2_4("sha224"), + BLAKE2B256("blake2b256"), + SHA3_224("sha3_224"), + MD2("md2"), + BLAKE2B512("blake2b512"), + SPDX_PVC_SHA256("spdxPvcSha256"), + OTHER("other"), + SHA3_256("sha3_256"), + SHA1("sha1"), + SPDX_PVC_SHA1("spdxPvcSha1"), + BLAKE2B384("blake2b384"), + SHA3_512("sha3_512"), + SHA224("sha224"), + SHA3_384("sha3_384"), + SHA256("sha256"), + SHA384("sha384"), + SPHINCS_PLUS("sphincsPlus"), CRYSTALS_KYBER("crystalsKyber"), - SHA_3___2_2_4("sha3_224"); + BLAKE3("blake3"), + MD6("md6"), + FALCON("falcon"), + MD5("md5"), + SHA512("sha512"), + MD4("md4"); private String longName; @@ -71,7 +71,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/HashAlgorithm"; + return "https://spdx.org/rdf/v3/Core/HashAlgorithm"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java b/generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java rename to generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java index d20f1da06..f6ab8cdbf 100644 --- a/generated/src/main/java/org/spdx/library/model/core/IntegrityMethod.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -174,7 +174,7 @@ public IntegrityMethodBuilder(IModelStore modelStore, String objectUri, @Nullabl * @parameter comment value to set * @return this for chaining **/ - IntegrityMethodBuilder setComment(String comment) { + public IntegrityMethodBuilder setComment(String comment) { this.comment = comment; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java index 96a01825d..e26cc59b8 100644 --- a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopeType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -28,12 +28,12 @@ */ public enum LifecycleScopeType implements IndividualUriValue { - RUNTIME("runtime"), - DEVELOPMENT("development"), - DESIGN("design"), - BUILD("build"), TEST("test"), - OTHER("other"); + BUILD("build"), + OTHER("other"), + DESIGN("design"), + DEVELOPMENT("development"), + RUNTIME("runtime"); private String longName; @@ -51,7 +51,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/LifecycleScopeType"; + return "https://spdx.org/rdf/v3/Core/LifecycleScopeType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java index 486fe8de1..907842cc8 100644 --- a/generated/src/main/java/org/spdx/library/model/core/LifecycleScopedRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -180,7 +180,7 @@ public LifecycleScopedRelationshipBuilder(IModelStore modelStore, String objectU * @parameter scope value to set * @return this for chaining **/ - LifecycleScopedRelationshipBuilder setScope(LifecycleScopeType scope) { + public LifecycleScopedRelationshipBuilder setScope(LifecycleScopeType scope) { this.scope = scope; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/Organization.java b/generated/src/main/java/org/spdx/library/model/v3/core/Organization.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/core/Organization.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Organization.java index bd80bd456..719422758 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Organization.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Organization.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/core/Person.java b/generated/src/main/java/org/spdx/library/model/v3/core/Person.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/core/Person.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Person.java index 888a08ec1..5522cbec9 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Person.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Person.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java b/generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java rename to generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java index fb201c64b..54cce752a 100644 --- a/generated/src/main/java/org/spdx/library/model/core/PositiveIntegerRange.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -83,8 +83,8 @@ public PositiveIntegerRange(IModelStore modelStore, String objectUri, @Nullable */ protected PositiveIntegerRange(PositiveIntegerRangeBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setEnd(builder.end); setBegin(builder.begin); + setEnd(builder.end); } /* (non-Javadoc) @@ -99,50 +99,50 @@ public String getType() { /** - * @return the end + * @return the begin */ - public @Nullable Integer getEnd() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_END); + public @Nullable Integer getBegin() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_BEGIN); return retval.isPresent() ? retval.get() : null; } /** - * @param end the end to set + * @param begin the begin to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public PositiveIntegerRange setEnd(@Nullable Integer end) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(end)) { - throw new InvalidSPDXAnalysisException("end is a required property"); + public PositiveIntegerRange setBegin(@Nullable Integer begin) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(begin)) { + throw new InvalidSPDXAnalysisException("begin is a required property"); } - if (isStrict() && Objects.nonNull(end) && end < 1) { - throw new InvalidSPDXAnalysisException("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); + if (isStrict() && Objects.nonNull(begin) && begin < 1) { + throw new InvalidSPDXAnalysisException("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); } - setPropertyValue(SpdxConstants.CORE_PROP_END, end); + setPropertyValue(SpdxConstants.CORE_PROP_BEGIN, begin); return this; } /** - * @return the begin + * @return the end */ - public @Nullable Integer getBegin() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_BEGIN); + public @Nullable Integer getEnd() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_END); return retval.isPresent() ? retval.get() : null; } /** - * @param begin the begin to set + * @param end the end to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public PositiveIntegerRange setBegin(@Nullable Integer begin) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(begin)) { - throw new InvalidSPDXAnalysisException("begin is a required property"); + public PositiveIntegerRange setEnd(@Nullable Integer end) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(end)) { + throw new InvalidSPDXAnalysisException("end is a required property"); } - if (isStrict() && Objects.nonNull(begin) && begin < 1) { - throw new InvalidSPDXAnalysisException("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); + if (isStrict() && Objects.nonNull(end) && end < 1) { + throw new InvalidSPDXAnalysisException("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); } - setPropertyValue(SpdxConstants.CORE_PROP_BEGIN, begin); + setPropertyValue(SpdxConstants.CORE_PROP_END, end); return this; } @@ -158,18 +158,6 @@ public String toString() { @Override protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); - try { - Integer end = getEnd(); - if (Objects.isNull(end) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing end in PositiveIntegerRange"); - } - if (Objects.nonNull(end) && end < 1) { - retval.add("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting end for PositiveIntegerRange: "+e.getMessage()); - } try { Integer begin = getBegin(); if (Objects.isNull(begin) && @@ -182,6 +170,18 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting begin for PositiveIntegerRange: "+e.getMessage()); } + try { + Integer end = getEnd(); + if (Objects.isNull(end) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing end in PositiveIntegerRange"); + } + if (Objects.nonNull(end) && end < 1) { + retval.add("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting end for PositiveIntegerRange: "+e.getMessage()); + } return retval; } @@ -217,27 +217,27 @@ public PositiveIntegerRangeBuilder(IModelStore modelStore, String objectUri, @Nu super(modelStore, objectUri, copyManager); } - Integer end = null; Integer begin = null; + Integer end = null; /** - * Sets the initial value of end - * @parameter end value to set + * Sets the initial value of begin + * @parameter begin value to set * @return this for chaining **/ - PositiveIntegerRangeBuilder setEnd(Integer end) { - this.end = end; + public PositiveIntegerRangeBuilder setBegin(Integer begin) { + this.begin = begin; return this; } /** - * Sets the initial value of begin - * @parameter begin value to set + * Sets the initial value of end + * @parameter end value to set * @return this for chaining **/ - PositiveIntegerRangeBuilder setBegin(Integer begin) { - this.begin = begin; + public PositiveIntegerRangeBuilder setEnd(Integer end) { + this.end = end; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java b/generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java index 61cc41ffd..390e3cfc3 100644 --- a/generated/src/main/java/org/spdx/library/model/core/ProfileIdentifierType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -30,15 +30,15 @@ */ public enum ProfileIdentifierType implements IndividualUriValue { - USAGE("usage"), + BUILD("build"), + EXTENSION("extension"), SECURITY("security"), + DATASET("dataset"), + USAGE("usage"), SOFTWARE("software"), - EXTENSION("extension"), - BUILD("build"), - AI("ai"), CORE("core"), LICENSING("licensing"), - DATASET("dataset"); + AI("ai"); private String longName; @@ -56,7 +56,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/ProfileIdentifierType"; + return "https://spdx.org/rdf/v3/Core/ProfileIdentifierType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/Relationship.java b/generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java similarity index 83% rename from generated/src/main/java/org/spdx/library/model/core/Relationship.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java index 78873e66d..a423e0046 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Relationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -90,11 +90,11 @@ protected Relationship(RelationshipBuilder builder) throws InvalidSPDXAnalysisEx super(builder); tos = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_TO, Element.class); getTos().addAll(builder.tos); + setEndTime(builder.endTime); setFrom(builder.from); + setStartTime(builder.startTime); setRelationshipType(builder.relationshipType); setCompleteness(builder.completeness); - setStartTime(builder.startTime); - setEndTime(builder.endTime); } /* (non-Javadoc) @@ -110,14 +110,49 @@ public Collection getTos() { return tos; } + + /** + * @return the endTime + */ + @SuppressWarnings("unchecked") + public Optional getEndTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_END_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param endTime the endTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setEndTime(@Nullable DateTime endTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_END_TIME, endTime); + return this; + } + /** * @return the from */ + @SuppressWarnings("unchecked") public @Nullable Element getFrom() throws InvalidSPDXAnalysisException { - Optional retval = getElementPropertyValue(SpdxConstants.CORE_PROP_FROM); - return retval.isPresent() ? retval.get() : null; + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_FROM); + if (retval.isPresent()) { + if (!(retval.get() instanceof Element)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Element)(retval.get()); + } else { + return null; + } } - + /** * @param from the from to set * @return this to chain setters @@ -130,7 +165,32 @@ public Relationship setFrom(@Nullable Element from) throws InvalidSPDXAnalysisEx setPropertyValue(SpdxConstants.CORE_PROP_FROM, from); return this; } + + /** + * @return the startTime + */ + @SuppressWarnings("unchecked") + public Optional getStartTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_START_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param startTime the startTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Relationship setStartTime(@Nullable DateTime startTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_START_TIME, startTime); + return this; + } /** * @return the relationshipType @@ -183,38 +243,6 @@ public Relationship setCompleteness(@Nullable RelationshipCompleteness completen setPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS, completeness); return this; } - - /** - * @return the startTime - */ - public Optional getStartTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_START_TIME); - } - /** - * @param startTime the startTime to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Relationship setStartTime(@Nullable String startTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_START_TIME, startTime); - return this; - } - - /** - * @return the endTime - */ - public Optional getEndTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_END_TIME); - } - /** - * @param endTime the endTime to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Relationship setEndTime(@Nullable String endTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_END_TIME, endTime); - return this; - } @Override @@ -229,17 +257,35 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional endTime; + try { + endTime = getEndTime(); + if (endTime.isPresent()) { + retval.addAll(endTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting endTime for Relationship: "+e.getMessage()); + } Element from; try { from = getFrom(); if (Objects.nonNull(from)) { retval.addAll(from.verify(verifiedIds, specVersion, profiles)); } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing from in from"); + retval.add("Missing from in Relationship"); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting from for Relationship: "+e.getMessage()); } + Optional startTime; + try { + startTime = getStartTime(); + if (startTime.isPresent()) { + retval.addAll(startTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting startTime for Relationship: "+e.getMessage()); + } try { RelationshipType relationshipType = getRelationshipType(); if (Objects.isNull(relationshipType) && @@ -255,18 +301,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting completeness for Relationship: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional startTime = getStartTime(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting startTime for Relationship: "+e.getMessage()); - } - try { - @SuppressWarnings("unused") - Optional endTime = getEndTime(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting endTime for Relationship: "+e.getMessage()); - } for (Element to:tos) { retval.addAll(to.verify(verifiedIds, specVersion, profiles)); } @@ -306,11 +340,11 @@ public RelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable M } Collection tos = new ArrayList<>(); + DateTime endTime = null; Element from = null; + DateTime startTime = null; RelationshipType relationshipType = null; RelationshipCompleteness completeness = null; - String startTime = null; - String endTime = null; /** @@ -318,7 +352,7 @@ public RelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable M * @parameter to to to add * @return this for chaining **/ - RelationshipBuilder addTo(Element to) { + public RelationshipBuilder addTo(Element to) { if (Objects.nonNull(to)) { tos.add(to); } @@ -330,7 +364,7 @@ RelationshipBuilder addTo(Element to) { * @parameter toCollection collection to initialize the to * @return this for chaining **/ - RelationshipBuilder addAllTo(Collection toCollection) { + public RelationshipBuilder addAllTo(Collection toCollection) { if (Objects.nonNull(toCollection)) { tos.addAll(toCollection); } @@ -338,52 +372,52 @@ RelationshipBuilder addAllTo(Collection toCollection) { } /** - * Sets the initial value of from - * @parameter from value to set + * Sets the initial value of endTime + * @parameter endTime value to set * @return this for chaining **/ - RelationshipBuilder setFrom(Element from) { - this.from = from; + public RelationshipBuilder setEndTime(DateTime endTime) { + this.endTime = endTime; return this; } /** - * Sets the initial value of relationshipType - * @parameter relationshipType value to set + * Sets the initial value of from + * @parameter from value to set * @return this for chaining **/ - RelationshipBuilder setRelationshipType(RelationshipType relationshipType) { - this.relationshipType = relationshipType; + public RelationshipBuilder setFrom(Element from) { + this.from = from; return this; } /** - * Sets the initial value of completeness - * @parameter completeness value to set + * Sets the initial value of startTime + * @parameter startTime value to set * @return this for chaining **/ - RelationshipBuilder setCompleteness(RelationshipCompleteness completeness) { - this.completeness = completeness; + public RelationshipBuilder setStartTime(DateTime startTime) { + this.startTime = startTime; return this; } /** - * Sets the initial value of startTime - * @parameter startTime value to set + * Sets the initial value of relationshipType + * @parameter relationshipType value to set * @return this for chaining **/ - RelationshipBuilder setStartTime(String startTime) { - this.startTime = startTime; + public RelationshipBuilder setRelationshipType(RelationshipType relationshipType) { + this.relationshipType = relationshipType; return this; } /** - * Sets the initial value of endTime - * @parameter endTime value to set + * Sets the initial value of completeness + * @parameter completeness value to set * @return this for chaining **/ - RelationshipBuilder setEndTime(String endTime) { - this.endTime = endTime; + public RelationshipBuilder setCompleteness(RelationshipCompleteness completeness) { + this.completeness = completeness; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java similarity index 89% rename from generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java rename to generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java index 553581601..a269818c0 100644 --- a/generated/src/main/java/org/spdx/library/model/core/RelationshipCompleteness.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -29,9 +29,9 @@ */ public enum RelationshipCompleteness implements IndividualUriValue { + INCOMPLETE("incomplete"), COMPLETE("complete"), - NO_ASSERTION("noAssertion"), - INCOMPLETE("incomplete"); + NO_ASSERTION("noAssertion"); private String longName; @@ -49,7 +49,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/RelationshipCompleteness"; + return "https://spdx.org/rdf/v3/Core/RelationshipCompleteness"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/RelationshipType.java b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java similarity index 95% rename from generated/src/main/java/org/spdx/library/model/core/RelationshipType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java index 517c7cc40..197a41365 100644 --- a/generated/src/main/java/org/spdx/library/model/core/RelationshipType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -30,68 +30,68 @@ */ public enum RelationshipType implements IndividualUriValue { + DISTRIBUTION_ARTIFACT("distributionArtifact"), + INVOKED_BY("invokedBy"), + VARIANT("variant"), DOES_NOT_AFFECT("doesNotAffect"), - EXPANDED_FROM_ARCHIVE("expandedFromArchive"), - CONFIG_OF("configOf"), + TEST_TOOL("testTool"), + FIXED_IN("fixedIn"), FILE_DELETED("fileDeleted"), - HAS_ASSESSMENT_FOR("hasAssessmentFor"), COPY("copy"), - ANCESTOR("ancestor"), - HAS_ASSOCIATED_VULNERABILITY("hasAssociatedVulnerability"), - HOST_OF("hostOf"), - PROVIDED_DEPENDENCY("providedDependency"), + OPTIONAL_DEPENDENCY("optionalDependency"), COORDINATED_BY("coordinatedBy"), - REQUIREMENT_FOR("requirementFor"), - AFFECTS("affects"), - CONTAINS("contains"), - DOCUMENTATION("documentation"), - TEST_TOOL("testTool"), - ON_BEHALF_OF("onBehalfOf"), - TRAINED_ON("trainedOn"), - EXAMPLE("example"), - DEV_TOOL("devTool"), INPUT_OF("inputOf"), - DEPENDENCY_MANIFEST("dependencyManifest"), - TEST("test"), - REPORTED_BY("reportedBy"), - FOUND_BY("foundBy"), - FIXED_BY("fixedBy"), + OUTPUT_OF("outputOf"), + SPECIFICATION_FOR("specificationFor"), + DESCRIBES("describes"), AMENDS("amends"), - EVIDENCE_FOR("evidenceFor"), - PACKAGES("packages"), - TEST_CASE("testCase"), - TEST_DEPENDENCY("testDependency"), - BUILD_TOOL("buildTool"), - FILE_MODIFIED("fileModified"), - DYNAMIC_LINK("dynamicLink"), - PREREQUISITE("prerequisite"), - AVAILABLE_FROM("availableFrom"), - UNDER_INVESTIGATION_FOR("underInvestigationFor"), - REPUBLISHED_BY("republishedBy"), - DESCENDANT("descendant"), - PUBLISHED_BY("publishedBy"), - GENERATES("generates"), - DISTRIBUTION_ARTIFACT("distributionArtifact"), EXPLOIT_CREATED_BY("exploitCreatedBy"), - OPTIONAL_DEPENDENCY("optionalDependency"), + PATCH("patch"), + REPORTED_BY("reportedBy"), + DEPENDS_ON("dependsOn"), + METAFILE("metafile"), DATA_FILE("dataFile"), + GENERATES("generates"), + EXPANDED_FROM_ARCHIVE("expandedFromArchive"), + HAS_ASSOCIATED_VULNERABILITY("hasAssociatedVulnerability"), + TRAINED_ON("trainedOn"), + TESTED_ON("testedOn"), + PUBLISHED_BY("publishedBy"), + HOST_OF("hostOf"), + AVAILABLE_FROM("availableFrom"), + CONTAINS("contains"), + DESCENDANT("descendant"), + TEST_CASE("testCase"), + PREREQUISITE("prerequisite"), + REQUIREMENT_FOR("requirementFor"), OTHER("other"), - SPECIFICATION_FOR("specificationFor"), - INVOKED_BY("invokedBy"), - DEPENDS_ON("dependsOn"), - VARIANT("variant"), + ANCESTOR("ancestor"), + FILE_MODIFIED("fileModified"), + TEST_DEPENDENCY("testDependency"), DEV_DEPENDENCY("devDependency"), STATIC_LINK("staticLink"), - TESTED_ON("testedOn"), - PATCH("patch"), + AFFECTS("affects"), + ON_BEHALF_OF("onBehalfOf"), + EVIDENCE_FOR("evidenceFor"), FILE_ADDED("fileAdded"), - OUTPUT_OF("outputOf"), - BUILD_DEPENDENCY("buildDependency"), - DESCRIBES("describes"), - METAFILE("metafile"), + PROVIDED_DEPENDENCY("providedDependency"), + REPUBLISHED_BY("republishedBy"), + HAS_ASSESSMENT_FOR("hasAssessmentFor"), + DYNAMIC_LINK("dynamicLink"), + DOCUMENTATION("documentation"), + TEST("test"), + RUNTIME_DEPENDENCY("runtimeDependency"), + DEPENDENCY_MANIFEST("dependencyManifest"), + FOUND_BY("foundBy"), + UNDER_INVESTIGATION_FOR("underInvestigationFor"), + PACKAGES("packages"), + EXAMPLE("example"), OPTIONAL_COMPONENT("optionalComponent"), - FIXED_IN("fixedIn"), - RUNTIME_DEPENDENCY("runtimeDependency"); + FIXED_BY("fixedBy"), + CONFIG_OF("configOf"), + BUILD_DEPENDENCY("buildDependency"), + BUILD_TOOL("buildTool"), + DEV_TOOL("devTool"); private String longName; @@ -109,7 +109,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Core/RelationshipType"; + return "https://spdx.org/rdf/v3/Core/RelationshipType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java b/generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java rename to generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java index ca5f6bb00..6d98287ca 100644 --- a/generated/src/main/java/org/spdx/library/model/core/SoftwareAgent.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java b/generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java similarity index 79% rename from generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java rename to generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java index 0b7fb421a..8531b0010 100644 --- a/generated/src/main/java/org/spdx/library/model/core/SpdxDocument.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -32,6 +32,11 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -79,6 +84,7 @@ public SpdxDocument(IModelStore modelStore, String objectUri, @Nullable ModelCop */ protected SpdxDocument(SpdxDocumentBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setName(builder.name); } /* (non-Javadoc) @@ -91,6 +97,25 @@ public String getType() { // Getters and Setters + + /** + * @return the name + */ + public Optional getName() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_NAME); + } + /** + * @param name the name to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SpdxDocument setName(@Nullable String name) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(name)) { + throw new InvalidSPDXAnalysisException("name is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_NAME, name); + return this; + } @Override @@ -105,6 +130,15 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Optional name = getName(); + if (!name.isPresent() && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing name in SpdxDocument"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting name for SpdxDocument: "+e.getMessage()); + } return retval; } @@ -140,7 +174,18 @@ public SpdxDocumentBuilder(IModelStore modelStore, String objectUri, @Nullable M super(modelStore, objectUri, copyManager); } + String name = null; + + /** + * Sets the initial value of name + * @parameter name value to set + * @return this for chaining + **/ + public SpdxDocumentBuilder setName(String name) { + this.name = name; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/core/Tool.java b/generated/src/main/java/org/spdx/library/model/v3/core/Tool.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/core/Tool.java rename to generated/src/main/java/org/spdx/library/model/v3/core/Tool.java index 77a09229d..4235e59f2 100644 --- a/generated/src/main/java/org/spdx/library/model/core/Tool.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Tool.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java rename to generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java index e3b86277e..9e8f20537 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/ConfidentialityLevelType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.dataset; +package org.spdx.library.model.v3.dataset; import org.spdx.library.IndividualUriValue; @@ -28,10 +28,10 @@ */ public enum ConfidentialityLevelType implements IndividualUriValue { - GREEN("Green"), CLEAR("Clear"), + AMBER("Amber"), RED("Red"), - AMBER("Amber"); + GREEN("Green"); private String longName; @@ -49,7 +49,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Dataset/ConfidentialityLevelType"; + return "https://spdx.org/rdf/v3/Dataset/ConfidentialityLevelType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java similarity index 93% rename from generated/src/main/java/org/spdx/library/model/dataset/Dataset.java rename to generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java index dfa0628a5..49ee58f25 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/Dataset.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.dataset; +package org.spdx.library.model.v3.dataset; import javax.annotation.Nullable; @@ -38,9 +38,9 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.DictionaryEntry; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.software.SpdxPackage; +import org.spdx.library.model.v3.core.DictionaryEntry; +import org.spdx.library.model.v3.software.SpdxPackage; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -433,7 +433,7 @@ public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter sensor sensor to add * @return this for chaining **/ - DatasetBuilder addSensor(DictionaryEntry sensor) { + public DatasetBuilder addSensor(DictionaryEntry sensor) { if (Objects.nonNull(sensor)) { sensors.add(sensor); } @@ -445,7 +445,7 @@ DatasetBuilder addSensor(DictionaryEntry sensor) { * @parameter sensorCollection collection to initialize the sensor * @return this for chaining **/ - DatasetBuilder addAllSensor(Collection sensorCollection) { + public DatasetBuilder addAllSensor(Collection sensorCollection) { if (Objects.nonNull(sensorCollection)) { sensors.addAll(sensorCollection); } @@ -457,7 +457,7 @@ DatasetBuilder addAllSensor(Collection sensorCollection) { * @parameter datasetType datasetType to add * @return this for chaining **/ - DatasetBuilder addDatasetType(DatasetType datasetType) { + public DatasetBuilder addDatasetType(DatasetType datasetType) { if (Objects.nonNull(datasetType)) { datasetTypes.add(datasetType); } @@ -469,7 +469,7 @@ DatasetBuilder addDatasetType(DatasetType datasetType) { * @parameter datasetTypeCollection collection to initialize the datasetType * @return this for chaining **/ - DatasetBuilder addAllDatasetType(Collection datasetTypeCollection) { + public DatasetBuilder addAllDatasetType(Collection datasetTypeCollection) { if (Objects.nonNull(datasetTypeCollection)) { datasetTypes.addAll(datasetTypeCollection); } @@ -481,7 +481,7 @@ DatasetBuilder addAllDatasetType(Collection datasetTypeCollection) * @parameter anonymizationMethodUsed anonymizationMethodUsed to add * @return this for chaining **/ - DatasetBuilder addAnonymizationMethodUsed(String anonymizationMethodUsed) { + public DatasetBuilder addAnonymizationMethodUsed(String anonymizationMethodUsed) { if (Objects.nonNull(anonymizationMethodUsed)) { anonymizationMethodUseds.add(anonymizationMethodUsed); } @@ -493,7 +493,7 @@ DatasetBuilder addAnonymizationMethodUsed(String anonymizationMethodUsed) { * @parameter anonymizationMethodUsedCollection collection to initialize the anonymizationMethodUsed * @return this for chaining **/ - DatasetBuilder addAllAnonymizationMethodUsed(Collection anonymizationMethodUsedCollection) { + public DatasetBuilder addAllAnonymizationMethodUsed(Collection anonymizationMethodUsedCollection) { if (Objects.nonNull(anonymizationMethodUsedCollection)) { anonymizationMethodUseds.addAll(anonymizationMethodUsedCollection); } @@ -505,7 +505,7 @@ DatasetBuilder addAllAnonymizationMethodUsed(Collection anonymizationMet * @parameter dataPreprocessing dataPreprocessing to add * @return this for chaining **/ - DatasetBuilder addDataPreprocessing(String dataPreprocessing) { + public DatasetBuilder addDataPreprocessing(String dataPreprocessing) { if (Objects.nonNull(dataPreprocessing)) { dataPreprocessings.add(dataPreprocessing); } @@ -517,7 +517,7 @@ DatasetBuilder addDataPreprocessing(String dataPreprocessing) { * @parameter dataPreprocessingCollection collection to initialize the dataPreprocessing * @return this for chaining **/ - DatasetBuilder addAllDataPreprocessing(Collection dataPreprocessingCollection) { + public DatasetBuilder addAllDataPreprocessing(Collection dataPreprocessingCollection) { if (Objects.nonNull(dataPreprocessingCollection)) { dataPreprocessings.addAll(dataPreprocessingCollection); } @@ -529,7 +529,7 @@ DatasetBuilder addAllDataPreprocessing(Collection dataPreprocessingColle * @parameter knownBias knownBias to add * @return this for chaining **/ - DatasetBuilder addKnownBias(String knownBias) { + public DatasetBuilder addKnownBias(String knownBias) { if (Objects.nonNull(knownBias)) { knownBiass.add(knownBias); } @@ -541,7 +541,7 @@ DatasetBuilder addKnownBias(String knownBias) { * @parameter knownBiasCollection collection to initialize the knownBias * @return this for chaining **/ - DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { + public DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { if (Objects.nonNull(knownBiasCollection)) { knownBiass.addAll(knownBiasCollection); } @@ -553,7 +553,7 @@ DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { * @parameter sensitivePersonalInformation value to set * @return this for chaining **/ - DatasetBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + public DatasetBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { this.sensitivePersonalInformation = sensitivePersonalInformation; return this; } @@ -563,7 +563,7 @@ DatasetBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInf * @parameter confidentialityLevel value to set * @return this for chaining **/ - DatasetBuilder setConfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { + public DatasetBuilder setConfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { this.confidentialityLevel = confidentialityLevel; return this; } @@ -573,7 +573,7 @@ DatasetBuilder setConfidentialityLevel(ConfidentialityLevelType confidentialityL * @parameter datasetAvailability value to set * @return this for chaining **/ - DatasetBuilder setDatasetAvailability(DatasetAvailabilityType datasetAvailability) { + public DatasetBuilder setDatasetAvailability(DatasetAvailabilityType datasetAvailability) { this.datasetAvailability = datasetAvailability; return this; } @@ -583,7 +583,7 @@ DatasetBuilder setDatasetAvailability(DatasetAvailabilityType datasetAvailabilit * @parameter datasetSize value to set * @return this for chaining **/ - DatasetBuilder setDatasetSize(Integer datasetSize) { + public DatasetBuilder setDatasetSize(Integer datasetSize) { this.datasetSize = datasetSize; return this; } @@ -593,7 +593,7 @@ DatasetBuilder setDatasetSize(Integer datasetSize) { * @parameter intendedUse value to set * @return this for chaining **/ - DatasetBuilder setIntendedUse(String intendedUse) { + public DatasetBuilder setIntendedUse(String intendedUse) { this.intendedUse = intendedUse; return this; } @@ -603,7 +603,7 @@ DatasetBuilder setIntendedUse(String intendedUse) { * @parameter datasetNoise value to set * @return this for chaining **/ - DatasetBuilder setDatasetNoise(String datasetNoise) { + public DatasetBuilder setDatasetNoise(String datasetNoise) { this.datasetNoise = datasetNoise; return this; } @@ -613,7 +613,7 @@ DatasetBuilder setDatasetNoise(String datasetNoise) { * @parameter dataCollectionProcess value to set * @return this for chaining **/ - DatasetBuilder setDataCollectionProcess(String dataCollectionProcess) { + public DatasetBuilder setDataCollectionProcess(String dataCollectionProcess) { this.dataCollectionProcess = dataCollectionProcess; return this; } @@ -623,7 +623,7 @@ DatasetBuilder setDataCollectionProcess(String dataCollectionProcess) { * @parameter datasetUpdateMechanism value to set * @return this for chaining **/ - DatasetBuilder setDatasetUpdateMechanism(String datasetUpdateMechanism) { + public DatasetBuilder setDatasetUpdateMechanism(String datasetUpdateMechanism) { this.datasetUpdateMechanism = datasetUpdateMechanism; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java similarity index 89% rename from generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java rename to generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java index d11ea7533..ea6279535 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/DatasetAvailabilityType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.dataset; +package org.spdx.library.model.v3.dataset; import org.spdx.library.IndividualUriValue; @@ -30,8 +30,8 @@ */ public enum DatasetAvailabilityType implements IndividualUriValue { - SCRAPING___SCRIPT("Scraping-Script"), - DIRECT___DOWNLOAD("Direct-Download"), + SCRAPING__SCRIPT("Scraping-Script"), + DIRECT__DOWNLOAD("Direct-Download"), QUERY("Query"), CLICKTHROUGH("Clickthrough"), REGISTRATION("Registration"); @@ -52,7 +52,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Dataset/DatasetAvailabilityType"; + return "https://spdx.org/rdf/v3/Dataset/DatasetAvailabilityType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java rename to generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java index 6cfbefbf8..80e16edb8 100644 --- a/generated/src/main/java/org/spdx/library/model/dataset/DatasetType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.dataset; +package org.spdx.library.model.v3.dataset; import org.spdx.library.IndividualUriValue; @@ -31,20 +31,20 @@ */ public enum DatasetType implements IndividualUriValue { - SYNTACTIC("syntactic"), - GRAPH("graph"), - NUMERIC("numeric"), - TIMESERIES("timeseries"), - NO_ASSERTION("noAssertion"), - IMAGE("image"), - CATEGORICAL("categorical"), AUDIO("audio"), - SENSOR("sensor"), OTHER("other"), - TIMESTAMP("timestamp"), + CATEGORICAL("categorical"), VIDEO("video"), + NO_ASSERTION("noAssertion"), STRUCTURED("structured"), - TEXT("text"); + SYNTACTIC("syntactic"), + GRAPH("graph"), + TIMESERIES("timeseries"), + TEXT("text"), + SENSOR("sensor"), + IMAGE("image"), + NUMERIC("numeric"), + TIMESTAMP("timestamp"); private String longName; @@ -62,7 +62,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Dataset/DatasetType"; + return "https://spdx.org/rdf/v3/Dataset/DatasetType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSet.java similarity index 78% rename from generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSet.java index 5b029bb5f..b51f44639 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSet.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.expandedlicense; +package org.spdx.library.model.v3.expandedlicense; import javax.annotation.Nullable; @@ -32,8 +32,14 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.licensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -51,6 +57,7 @@ */ public class ConjunctiveLicenseSet extends AnyLicenseInfo { + Collection members; /** * Create the ConjunctiveLicenseSet with default model store and generated anonymous ID @@ -75,9 +82,11 @@ public ConjunctiveLicenseSet(String objectUri) throws InvalidSPDXAnalysisExcepti * @param create true if ConjunctiveLicenseSet is to be created * @throws InvalidSPDXAnalysisException when unable to create the ConjunctiveLicenseSet */ + @SuppressWarnings("unchecked") public ConjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); } /** @@ -85,8 +94,11 @@ public ConjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable * @param builder Builder to create the ConjunctiveLicenseSet from * @throws InvalidSPDXAnalysisException when unable to create the ConjunctiveLicenseSet */ + @SuppressWarnings("unchecked") protected ConjunctiveLicenseSet(ConjunctiveLicenseSetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); + getMembers().addAll(builder.members); } /* (non-Javadoc) @@ -98,6 +110,9 @@ public String getType() { } // Getters and Setters + public Collection getMembers() { + return members; + } @@ -113,6 +128,9 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + for (AnyLicenseInfo member:members) { + retval.addAll(member.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -148,7 +166,32 @@ public ConjunctiveLicenseSetBuilder(IModelStore modelStore, String objectUri, @N super(modelStore, objectUri, copyManager); } + Collection members = new ArrayList<>(); + + + /** + * Adds a member to the initial collection + * @parameter member member to add + * @return this for chaining + **/ + public ConjunctiveLicenseSetBuilder addMember(AnyLicenseInfo member) { + if (Objects.nonNull(member)) { + members.add(member); + } + return this; + } + /** + * Adds all elements from a collection to the initial member collection + * @parameter memberCollection collection to initialize the member + * @return this for chaining + **/ + public ConjunctiveLicenseSetBuilder addAllMember(Collection memberCollection) { + if (Objects.nonNull(memberCollection)) { + members.addAll(memberCollection); + } + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSet.java similarity index 78% rename from generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSet.java index 5d4083dcd..49ec22c72 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSet.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.expandedlicense; +package org.spdx.library.model.v3.expandedlicense; import javax.annotation.Nullable; @@ -32,8 +32,14 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.licensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -49,6 +55,7 @@ */ public class DisjunctiveLicenseSet extends AnyLicenseInfo { + Collection members; /** * Create the DisjunctiveLicenseSet with default model store and generated anonymous ID @@ -73,9 +80,11 @@ public DisjunctiveLicenseSet(String objectUri) throws InvalidSPDXAnalysisExcepti * @param create true if DisjunctiveLicenseSet is to be created * @throws InvalidSPDXAnalysisException when unable to create the DisjunctiveLicenseSet */ + @SuppressWarnings("unchecked") public DisjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); } /** @@ -83,8 +92,11 @@ public DisjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable * @param builder Builder to create the DisjunctiveLicenseSet from * @throws InvalidSPDXAnalysisException when unable to create the DisjunctiveLicenseSet */ + @SuppressWarnings("unchecked") protected DisjunctiveLicenseSet(DisjunctiveLicenseSetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); + getMembers().addAll(builder.members); } /* (non-Javadoc) @@ -96,6 +108,9 @@ public String getType() { } // Getters and Setters + public Collection getMembers() { + return members; + } @@ -111,6 +126,9 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + for (AnyLicenseInfo member:members) { + retval.addAll(member.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -146,7 +164,32 @@ public DisjunctiveLicenseSetBuilder(IModelStore modelStore, String objectUri, @N super(modelStore, objectUri, copyManager); } + Collection members = new ArrayList<>(); + + + /** + * Adds a member to the initial collection + * @parameter member member to add + * @return this for chaining + **/ + public DisjunctiveLicenseSetBuilder addMember(AnyLicenseInfo member) { + if (Objects.nonNull(member)) { + members.add(member); + } + return this; + } + /** + * Adds all elements from a collection to the initial member collection + * @parameter memberCollection collection to initialize the member + * @return this for chaining + **/ + public DisjunctiveLicenseSetBuilder addAllMember(Collection memberCollection) { + if (Objects.nonNull(memberCollection)) { + members.addAll(memberCollection); + } + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/AnyLicenseInfo.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/AnyLicenseInfo.java index 9d8cb7451..d136a0bc3 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/AnyLicenseInfo.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/AnyLicenseInfo.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -32,8 +32,8 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.Element; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicense.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicense.java index 1ff015f47..2494797d8 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicense.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicense.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicenseAddition.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicenseAddition.java index 69081fd0b..478f8afaa 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/CustomLicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicenseAddition.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/ExtendableLicense.java similarity index 97% rename from generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/ExtendableLicense.java index b5166515a..1bf775571 100644 --- a/generated/src/main/java/org/spdx/library/model/expandedlicense/ExtendableLicense.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/ExtendableLicense.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.expandedlicense; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -33,7 +33,6 @@ import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.licensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -87,7 +86,7 @@ protected ExtendableLicense(ExtendableLicenseBuilder builder) throws InvalidSPDX */ @Override public String getType() { - return "ExpandedLicense.ExtendableLicense"; + return "Licensing.ExtendableLicense"; } // Getters and Setters diff --git a/generated/src/main/java/org/spdx/library/model/licensing/License.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/License.java similarity index 88% rename from generated/src/main/java/org/spdx/library/model/licensing/License.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/License.java index 685e07645..db263c86d 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/License.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/License.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -38,7 +38,6 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.expandedlicense.ExtendableLicense; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,9 +85,10 @@ public License(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana protected License(LicenseBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setIsFsfLibre(builder.isFsfLibre); - setIsDeprecatedLicenseId(builder.isDeprecatedLicenseId); setIsOsiApproved(builder.isOsiApproved); + setIsDeprecatedLicenseId(builder.isDeprecatedLicenseId); setStandardLicenseTemplate(builder.standardLicenseTemplate); + setObsoletedBy(builder.obsoletedBy); setStandardLicenseHeader(builder.standardLicenseHeader); setLicenseText(builder.licenseText); } @@ -122,36 +122,36 @@ public License setIsFsfLibre(@Nullable Boolean isFsfLibre) throws InvalidSPDXAna } /** - * @return the isDeprecatedLicenseId + * @return the isOsiApproved */ - public Optional getIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID); + public Optional getIsOsiApproved() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED); } /** - * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set + * @param isOsiApproved the isOsiApproved to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public License setIsDeprecatedLicenseId(@Nullable Boolean isDeprecatedLicenseId) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID, isDeprecatedLicenseId); + public License setIsOsiApproved(@Nullable Boolean isOsiApproved) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED, isOsiApproved); return this; } /** - * @return the isOsiApproved + * @return the isDeprecatedLicenseId */ - public Optional getIsOsiApproved() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED); + public Optional getIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID); } /** - * @param isOsiApproved the isOsiApproved to set + * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public License setIsOsiApproved(@Nullable Boolean isOsiApproved) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED, isOsiApproved); + public License setIsDeprecatedLicenseId(@Nullable Boolean isDeprecatedLicenseId) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID, isDeprecatedLicenseId); return this; } @@ -171,6 +171,22 @@ public License setStandardLicenseTemplate(@Nullable String standardLicenseTempla return this; } + /** + * @return the obsoletedBy + */ + public Optional getObsoletedBy() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY); + } + /** + * @param obsoletedBy the obsoletedBy to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setObsoletedBy(@Nullable String obsoletedBy) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY, obsoletedBy); + return this; + } + /** * @return the standardLicenseHeader */ @@ -228,15 +244,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional isDeprecatedLicenseId = getIsDeprecatedLicenseId(); + Optional isOsiApproved = getIsOsiApproved(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting isDeprecatedLicenseId for License: "+e.getMessage()); + retval.add("Error getting isOsiApproved for License: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional isOsiApproved = getIsOsiApproved(); + Optional isDeprecatedLicenseId = getIsDeprecatedLicenseId(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting isOsiApproved for License: "+e.getMessage()); + retval.add("Error getting isDeprecatedLicenseId for License: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -244,6 +260,12 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting standardLicenseTemplate for License: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional obsoletedBy = getObsoletedBy(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting obsoletedBy for License: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional standardLicenseHeader = getStandardLicenseHeader(); @@ -295,9 +317,10 @@ public LicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC } Boolean isFsfLibre = null; - Boolean isDeprecatedLicenseId = null; Boolean isOsiApproved = null; + Boolean isDeprecatedLicenseId = null; String standardLicenseTemplate = null; + String obsoletedBy = null; String standardLicenseHeader = null; String licenseText = null; @@ -307,28 +330,28 @@ public LicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC * @parameter isFsfLibre value to set * @return this for chaining **/ - LicenseBuilder setIsFsfLibre(Boolean isFsfLibre) { + public LicenseBuilder setIsFsfLibre(Boolean isFsfLibre) { this.isFsfLibre = isFsfLibre; return this; } /** - * Sets the initial value of isDeprecatedLicenseId - * @parameter isDeprecatedLicenseId value to set + * Sets the initial value of isOsiApproved + * @parameter isOsiApproved value to set * @return this for chaining **/ - LicenseBuilder setIsDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { - this.isDeprecatedLicenseId = isDeprecatedLicenseId; + public LicenseBuilder setIsOsiApproved(Boolean isOsiApproved) { + this.isOsiApproved = isOsiApproved; return this; } /** - * Sets the initial value of isOsiApproved - * @parameter isOsiApproved value to set + * Sets the initial value of isDeprecatedLicenseId + * @parameter isDeprecatedLicenseId value to set * @return this for chaining **/ - LicenseBuilder setIsOsiApproved(Boolean isOsiApproved) { - this.isOsiApproved = isOsiApproved; + public LicenseBuilder setIsDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { + this.isDeprecatedLicenseId = isDeprecatedLicenseId; return this; } @@ -337,17 +360,27 @@ LicenseBuilder setIsOsiApproved(Boolean isOsiApproved) { * @parameter standardLicenseTemplate value to set * @return this for chaining **/ - LicenseBuilder setStandardLicenseTemplate(String standardLicenseTemplate) { + public LicenseBuilder setStandardLicenseTemplate(String standardLicenseTemplate) { this.standardLicenseTemplate = standardLicenseTemplate; return this; } + /** + * Sets the initial value of obsoletedBy + * @parameter obsoletedBy value to set + * @return this for chaining + **/ + public LicenseBuilder setObsoletedBy(String obsoletedBy) { + this.obsoletedBy = obsoletedBy; + return this; + } + /** * Sets the initial value of standardLicenseHeader * @parameter standardLicenseHeader value to set * @return this for chaining **/ - LicenseBuilder setStandardLicenseHeader(String standardLicenseHeader) { + public LicenseBuilder setStandardLicenseHeader(String standardLicenseHeader) { this.standardLicenseHeader = standardLicenseHeader; return this; } @@ -357,7 +390,7 @@ LicenseBuilder setStandardLicenseHeader(String standardLicenseHeader) { * @parameter licenseText value to set * @return this for chaining **/ - LicenseBuilder setLicenseText(String licenseText) { + public LicenseBuilder setLicenseText(String licenseText) { this.licenseText = licenseText; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseAddition.java similarity index 87% rename from generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseAddition.java index 26c11d5c1..04fedc878 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseAddition.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -37,8 +37,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.Element; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -89,6 +89,7 @@ public LicenseAddition(IModelStore modelStore, String objectUri, @Nullable Model protected LicenseAddition(LicenseAdditionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setIsDeprecatedAdditionId(builder.isDeprecatedAdditionId); + setObsoletedBy(builder.obsoletedBy); setStandardAdditionTemplate(builder.standardAdditionTemplate); setAdditionText(builder.additionText); } @@ -121,6 +122,22 @@ public LicenseAddition setIsDeprecatedAdditionId(@Nullable Boolean isDeprecatedA return this; } + /** + * @return the obsoletedBy + */ + public Optional getObsoletedBy() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY); + } + /** + * @param obsoletedBy the obsoletedBy to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseAddition setObsoletedBy(@Nullable String obsoletedBy) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY, obsoletedBy); + return this; + } + /** * @return the standardAdditionTemplate */ @@ -176,6 +193,12 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isDeprecatedAdditionId for LicenseAddition: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional obsoletedBy = getObsoletedBy(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting obsoletedBy for LicenseAddition: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional standardAdditionTemplate = getStandardAdditionTemplate(); @@ -227,6 +250,7 @@ public LicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullabl } Boolean isDeprecatedAdditionId = null; + String obsoletedBy = null; String standardAdditionTemplate = null; String additionText = null; @@ -236,17 +260,27 @@ public LicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullabl * @parameter isDeprecatedAdditionId value to set * @return this for chaining **/ - LicenseAdditionBuilder setIsDeprecatedAdditionId(Boolean isDeprecatedAdditionId) { + public LicenseAdditionBuilder setIsDeprecatedAdditionId(Boolean isDeprecatedAdditionId) { this.isDeprecatedAdditionId = isDeprecatedAdditionId; return this; } + /** + * Sets the initial value of obsoletedBy + * @parameter obsoletedBy value to set + * @return this for chaining + **/ + public LicenseAdditionBuilder setObsoletedBy(String obsoletedBy) { + this.obsoletedBy = obsoletedBy; + return this; + } + /** * Sets the initial value of standardAdditionTemplate * @parameter standardAdditionTemplate value to set * @return this for chaining **/ - LicenseAdditionBuilder setStandardAdditionTemplate(String standardAdditionTemplate) { + public LicenseAdditionBuilder setStandardAdditionTemplate(String standardAdditionTemplate) { this.standardAdditionTemplate = standardAdditionTemplate; return this; } @@ -256,7 +290,7 @@ LicenseAdditionBuilder setStandardAdditionTemplate(String standardAdditionTempla * @parameter additionText value to set * @return this for chaining **/ - LicenseAdditionBuilder setAdditionText(String additionText) { + public LicenseAdditionBuilder setAdditionText(String additionText) { this.additionText = additionText; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseExpression.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseExpression.java index 83966cd6f..2f389dea0 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/LicenseExpression.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseExpression.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -196,7 +196,7 @@ public LicenseExpressionBuilder(IModelStore modelStore, String objectUri, @Nulla * @parameter licenseExpression value to set * @return this for chaining **/ - LicenseExpressionBuilder setLicenseExpression(String licenseExpression) { + public LicenseExpressionBuilder setLicenseExpression(String licenseExpression) { this.licenseExpression = licenseExpression; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicense.java similarity index 68% rename from generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicense.java index 45165e5e1..ce88112ee 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicense.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicense.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -32,6 +32,8 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -78,6 +80,8 @@ public ListedLicense(IModelStore modelStore, String objectUri, @Nullable ModelCo */ protected ListedLicense(ListedLicenseBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setDeprecatedVersion(builder.deprecatedVersion); + setListVersionAdded(builder.listVersionAdded); } /* (non-Javadoc) @@ -90,6 +94,38 @@ public String getType() { // Getters and Setters + + /** + * @return the deprecatedVersion + */ + public Optional getDeprecatedVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION); + } + /** + * @param deprecatedVersion the deprecatedVersion to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ListedLicense setDeprecatedVersion(@Nullable String deprecatedVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION, deprecatedVersion); + return this; + } + + /** + * @return the listVersionAdded + */ + public Optional getListVersionAdded() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED); + } + /** + * @param listVersionAdded the listVersionAdded to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ListedLicense setListVersionAdded(@Nullable String listVersionAdded) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED, listVersionAdded); + return this; + } @Override @@ -104,6 +140,18 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + @SuppressWarnings("unused") + Optional deprecatedVersion = getDeprecatedVersion(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting deprecatedVersion for ListedLicense: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional listVersionAdded = getListVersionAdded(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting listVersionAdded for ListedLicense: "+e.getMessage()); + } return retval; } @@ -139,7 +187,29 @@ public ListedLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable super(modelStore, objectUri, copyManager); } + String deprecatedVersion = null; + String listVersionAdded = null; + + /** + * Sets the initial value of deprecatedVersion + * @parameter deprecatedVersion value to set + * @return this for chaining + **/ + public ListedLicenseBuilder setDeprecatedVersion(String deprecatedVersion) { + this.deprecatedVersion = deprecatedVersion; + return this; + } + + /** + * Sets the initial value of listVersionAdded + * @parameter listVersionAdded value to set + * @return this for chaining + **/ + public ListedLicenseBuilder setListVersionAdded(String listVersionAdded) { + this.listVersionAdded = listVersionAdded; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicenseException.java similarity index 69% rename from generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicenseException.java index 2aed94300..4710fd1c0 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/ListedLicenseException.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicenseException.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -32,6 +32,8 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -80,6 +82,8 @@ public ListedLicenseException(IModelStore modelStore, String objectUri, @Nullabl */ protected ListedLicenseException(ListedLicenseExceptionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setDeprecatedVersion(builder.deprecatedVersion); + setListVersionAdded(builder.listVersionAdded); } /* (non-Javadoc) @@ -92,6 +96,38 @@ public String getType() { // Getters and Setters + + /** + * @return the deprecatedVersion + */ + public Optional getDeprecatedVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION); + } + /** + * @param deprecatedVersion the deprecatedVersion to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ListedLicenseException setDeprecatedVersion(@Nullable String deprecatedVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION, deprecatedVersion); + return this; + } + + /** + * @return the listVersionAdded + */ + public Optional getListVersionAdded() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED); + } + /** + * @param listVersionAdded the listVersionAdded to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ListedLicenseException setListVersionAdded(@Nullable String listVersionAdded) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED, listVersionAdded); + return this; + } @Override @@ -106,6 +142,18 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + @SuppressWarnings("unused") + Optional deprecatedVersion = getDeprecatedVersion(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting deprecatedVersion for ListedLicenseException: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional listVersionAdded = getListVersionAdded(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting listVersionAdded for ListedLicenseException: "+e.getMessage()); + } return retval; } @@ -141,7 +189,29 @@ public ListedLicenseExceptionBuilder(IModelStore modelStore, String objectUri, @ super(modelStore, objectUri, copyManager); } + String deprecatedVersion = null; + String listVersionAdded = null; + + /** + * Sets the initial value of deprecatedVersion + * @parameter deprecatedVersion value to set + * @return this for chaining + **/ + public ListedLicenseExceptionBuilder setDeprecatedVersion(String deprecatedVersion) { + this.deprecatedVersion = deprecatedVersion; + return this; + } + + /** + * Sets the initial value of listVersionAdded + * @parameter listVersionAdded value to set + * @return this for chaining + **/ + public ListedLicenseExceptionBuilder setListVersionAdded(String listVersionAdded) { + this.listVersionAdded = listVersionAdded; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/OrLaterOperator.java similarity index 74% rename from generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/OrLaterOperator.java index 5384e2350..a49548057 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/OrLaterOperator.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/OrLaterOperator.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -32,8 +32,12 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.expandedlicense.ExtendableLicense; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,6 +90,7 @@ public OrLaterOperator(IModelStore modelStore, String objectUri, @Nullable Model */ protected OrLaterOperator(OrLaterOperatorBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setSubjectLicense(builder.subjectLicense); } /* (non-Javadoc) @@ -98,6 +103,35 @@ public String getType() { // Getters and Setters + + /** + * @return the subjectLicense + */ + @SuppressWarnings("unchecked") + public @Nullable License getSubjectLicense() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE); + if (retval.isPresent()) { + if (!(retval.get() instanceof License)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (License)(retval.get()); + } else { + return null; + } + } + + /** + * @param subjectLicense the subjectLicense to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public OrLaterOperator setSubjectLicense(@Nullable License subjectLicense) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(subjectLicense)) { + throw new InvalidSPDXAnalysisException("subjectLicense is a required property"); + } + setPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE, subjectLicense); + return this; + } @Override @@ -112,6 +146,17 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + License subjectLicense; + try { + subjectLicense = getSubjectLicense(); + if (Objects.nonNull(subjectLicense)) { + retval.addAll(subjectLicense.verify(verifiedIds, specVersion, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + retval.add("Missing subjectLicense in OrLaterOperator"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting subjectLicense for OrLaterOperator: "+e.getMessage()); + } return retval; } @@ -147,7 +192,18 @@ public OrLaterOperatorBuilder(IModelStore modelStore, String objectUri, @Nullabl super(modelStore, objectUri, copyManager); } + License subjectLicense = null; + + /** + * Sets the initial value of subjectLicense + * @parameter subjectLicense value to set + * @return this for chaining + **/ + public OrLaterOperatorBuilder setSubjectLicense(License subjectLicense) { + this.subjectLicense = subjectLicense; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java b/generated/src/main/java/org/spdx/library/model/v3/licensing/WithAdditionOperator.java similarity index 58% rename from generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java rename to generated/src/main/java/org/spdx/library/model/v3/licensing/WithAdditionOperator.java index 95ba3ff09..447245c8c 100644 --- a/generated/src/main/java/org/spdx/library/model/licensing/WithAdditionOperator.java +++ b/generated/src/main/java/org/spdx/library/model/v3/licensing/WithAdditionOperator.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -32,6 +32,11 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -81,6 +86,8 @@ public WithAdditionOperator(IModelStore modelStore, String objectUri, @Nullable */ protected WithAdditionOperator(WithAdditionOperatorBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setSubjectAddition(builder.subjectAddition); + setSubjectLicense(builder.subjectLicense); } /* (non-Javadoc) @@ -93,6 +100,64 @@ public String getType() { // Getters and Setters + + /** + * @return the subjectAddition + */ + @SuppressWarnings("unchecked") + public @Nullable LicenseAddition getSubjectAddition() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_ADDITION); + if (retval.isPresent()) { + if (!(retval.get() instanceof LicenseAddition)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (LicenseAddition)(retval.get()); + } else { + return null; + } + } + + /** + * @param subjectAddition the subjectAddition to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public WithAdditionOperator setSubjectAddition(@Nullable LicenseAddition subjectAddition) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(subjectAddition)) { + throw new InvalidSPDXAnalysisException("subjectAddition is a required property"); + } + setPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_ADDITION, subjectAddition); + return this; + } + + /** + * @return the subjectLicense + */ + @SuppressWarnings("unchecked") + public @Nullable ExtendableLicense getSubjectLicense() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE); + if (retval.isPresent()) { + if (!(retval.get() instanceof ExtendableLicense)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (ExtendableLicense)(retval.get()); + } else { + return null; + } + } + + /** + * @param subjectLicense the subjectLicense to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public WithAdditionOperator setSubjectLicense(@Nullable ExtendableLicense subjectLicense) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(subjectLicense)) { + throw new InvalidSPDXAnalysisException("subjectLicense is a required property"); + } + setPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE, subjectLicense); + return this; + } @Override @@ -107,6 +172,28 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + LicenseAddition subjectAddition; + try { + subjectAddition = getSubjectAddition(); + if (Objects.nonNull(subjectAddition)) { + retval.addAll(subjectAddition.verify(verifiedIds, specVersion, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + retval.add("Missing subjectAddition in WithAdditionOperator"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting subjectAddition for WithAdditionOperator: "+e.getMessage()); + } + ExtendableLicense subjectLicense; + try { + subjectLicense = getSubjectLicense(); + if (Objects.nonNull(subjectLicense)) { + retval.addAll(subjectLicense.verify(verifiedIds, specVersion, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + retval.add("Missing subjectLicense in WithAdditionOperator"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting subjectLicense for WithAdditionOperator: "+e.getMessage()); + } return retval; } @@ -142,7 +229,29 @@ public WithAdditionOperatorBuilder(IModelStore modelStore, String objectUri, @Nu super(modelStore, objectUri, copyManager); } + LicenseAddition subjectAddition = null; + ExtendableLicense subjectLicense = null; + + + /** + * Sets the initial value of subjectAddition + * @parameter subjectAddition value to set + * @return this for chaining + **/ + public WithAdditionOperatorBuilder setSubjectAddition(LicenseAddition subjectAddition) { + this.subjectAddition = subjectAddition; + return this; + } + /** + * Sets the initial value of subjectLicense + * @parameter subjectLicense value to set + * @return this for chaining + **/ + public WithAdditionOperatorBuilder setSubjectLicense(ExtendableLicense subjectLicense) { + this.subjectLicense = subjectLicense; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java similarity index 67% rename from generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java index 2fb4bb9d4..e46388270 100644 --- a/generated/src/main/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -32,6 +32,11 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -96,6 +101,9 @@ public CvssV2VulnAssessmentRelationship(IModelStore modelStore, String objectUri */ protected CvssV2VulnAssessmentRelationship(CvssV2VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setScore(builder.score); + setSeverity(builder.severity); + setVector(builder.vector); } /* (non-Javadoc) @@ -109,6 +117,59 @@ public String getType() { // Getters and Setters + /** + * @return the score + */ + public @Nullable Integer getScore() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.SECURITY_PROP_SCORE); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param score the score to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CvssV2VulnAssessmentRelationship setScore(@Nullable Integer score) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(score)) { + throw new InvalidSPDXAnalysisException("score is a required property"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_SCORE, score); + return this; + } + + /** + * @return the severity + */ + public Optional getSeverity() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY); + } + /** + * @param severity the severity to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CvssV2VulnAssessmentRelationship setSeverity(@Nullable String severity) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY, severity); + return this; + } + + /** + * @return the vector + */ + public Optional getVector() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR); + } + /** + * @param vector the vector to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CvssV2VulnAssessmentRelationship setVector(@Nullable String vector) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR, vector); + return this; + } + @Override public String toString() { @@ -122,6 +183,27 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Integer score = getScore(); + if (Objects.isNull(score) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { + retval.add("Missing score in CvssV2VulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting score for CvssV2VulnAssessmentRelationship: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional severity = getSeverity(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting severity for CvssV2VulnAssessmentRelationship: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional vector = getVector(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting vector for CvssV2VulnAssessmentRelationship: "+e.getMessage()); + } return retval; } @@ -157,7 +239,40 @@ public CvssV2VulnAssessmentRelationshipBuilder(IModelStore modelStore, String ob super(modelStore, objectUri, copyManager); } + Integer score = null; + String severity = null; + String vector = null; + + /** + * Sets the initial value of score + * @parameter score value to set + * @return this for chaining + **/ + public CvssV2VulnAssessmentRelationshipBuilder setScore(Integer score) { + this.score = score; + return this; + } + + /** + * Sets the initial value of severity + * @parameter severity value to set + * @return this for chaining + **/ + public CvssV2VulnAssessmentRelationshipBuilder setSeverity(String severity) { + this.severity = severity; + return this; + } + + /** + * Sets the initial value of vector + * @parameter vector value to set + * @return this for chaining + **/ + public CvssV2VulnAssessmentRelationshipBuilder setVector(String vector) { + this.vector = vector; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java similarity index 67% rename from generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java index ccae6a41d..b4e812009 100644 --- a/generated/src/main/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -32,6 +32,11 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; /** @@ -97,6 +102,9 @@ public CvssV3VulnAssessmentRelationship(IModelStore modelStore, String objectUri */ protected CvssV3VulnAssessmentRelationship(CvssV3VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setScore(builder.score); + setVector(builder.vector); + setSeverity(builder.severity); } /* (non-Javadoc) @@ -110,6 +118,59 @@ public String getType() { // Getters and Setters + /** + * @return the score + */ + public @Nullable Integer getScore() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.SECURITY_PROP_SCORE); + return retval.isPresent() ? retval.get() : null; + } + + /** + * @param score the score to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CvssV3VulnAssessmentRelationship setScore(@Nullable Integer score) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(score)) { + throw new InvalidSPDXAnalysisException("score is a required property"); + } + setPropertyValue(SpdxConstants.SECURITY_PROP_SCORE, score); + return this; + } + + /** + * @return the vector + */ + public Optional getVector() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR); + } + /** + * @param vector the vector to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CvssV3VulnAssessmentRelationship setVector(@Nullable String vector) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR, vector); + return this; + } + + /** + * @return the severity + */ + public Optional getSeverity() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY); + } + /** + * @param severity the severity to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public CvssV3VulnAssessmentRelationship setSeverity(@Nullable String severity) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY, severity); + return this; + } + @Override public String toString() { @@ -123,6 +184,27 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + try { + Integer score = getScore(); + if (Objects.isNull(score) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { + retval.add("Missing score in CvssV3VulnAssessmentRelationship"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting score for CvssV3VulnAssessmentRelationship: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional vector = getVector(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting vector for CvssV3VulnAssessmentRelationship: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional severity = getSeverity(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting severity for CvssV3VulnAssessmentRelationship: "+e.getMessage()); + } return retval; } @@ -158,7 +240,40 @@ public CvssV3VulnAssessmentRelationshipBuilder(IModelStore modelStore, String ob super(modelStore, objectUri, copyManager); } + Integer score = null; + String vector = null; + String severity = null; + + /** + * Sets the initial value of score + * @parameter score value to set + * @return this for chaining + **/ + public CvssV3VulnAssessmentRelationshipBuilder setScore(Integer score) { + this.score = score; + return this; + } + + /** + * Sets the initial value of vector + * @parameter vector value to set + * @return this for chaining + **/ + public CvssV3VulnAssessmentRelationshipBuilder setVector(String vector) { + this.vector = vector; + return this; + } + + /** + * Sets the initial value of severity + * @parameter severity value to set + * @return this for chaining + **/ + public CvssV3VulnAssessmentRelationshipBuilder setSeverity(String severity) { + this.severity = severity; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java similarity index 83% rename from generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java index a1b2baa56..af744632d 100644 --- a/generated/src/main/java/org/spdx/library/model/security/EpssVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -91,6 +91,7 @@ public EpssVulnAssessmentRelationship(IModelStore modelStore, String objectUri, protected EpssVulnAssessmentRelationship(EpssVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setProbability(builder.probability); + setSeverity(builder.severity); } /* (non-Javadoc) @@ -121,9 +122,28 @@ public EpssVulnAssessmentRelationship setProbability(@Nullable Integer probabili if (isStrict() && Objects.isNull(probability)) { throw new InvalidSPDXAnalysisException("probability is a required property"); } + if (isStrict() && Objects.nonNull(probability) && probability < 0) { + throw new InvalidSPDXAnalysisException("probability value " + probability + " is less than the minimum 0 in EpssVulnAssessmentRelationship"); + } setPropertyValue(SpdxConstants.SECURITY_PROP_PROBABILITY, probability); return this; } + + /** + * @return the severity + */ + public Optional getSeverity() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY); + } + /** + * @param severity the severity to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public EpssVulnAssessmentRelationship setSeverity(@Nullable String severity) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY, severity); + return this; + } @Override @@ -144,9 +164,18 @@ protected List _verify(Set verifiedIds, String specVersion, List Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SECURITY }))) { retval.add("Missing probability in EpssVulnAssessmentRelationship"); } + if (Objects.nonNull(probability) && probability < 0) { + retval.add("probability value " + probability + " is less than the minimum 0 in EpssVulnAssessmentRelationship"); + } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting probability for EpssVulnAssessmentRelationship: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional severity = getSeverity(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting severity for EpssVulnAssessmentRelationship: "+e.getMessage()); + } return retval; } @@ -183,6 +212,7 @@ public EpssVulnAssessmentRelationshipBuilder(IModelStore modelStore, String obje } Integer probability = null; + String severity = null; /** @@ -190,10 +220,20 @@ public EpssVulnAssessmentRelationshipBuilder(IModelStore modelStore, String obje * @parameter probability value to set * @return this for chaining **/ - EpssVulnAssessmentRelationshipBuilder setProbability(Integer probability) { + public EpssVulnAssessmentRelationshipBuilder setProbability(Integer probability) { this.probability = probability; return this; } + + /** + * Sets the initial value of severity + * @parameter severity value to set + * @return this for chaining + **/ + public EpssVulnAssessmentRelationshipBuilder setSeverity(String severity) { + this.severity = severity; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java rename to generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java index 2d1b88f89..13037522a 100644 --- a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import org.spdx.library.IndividualUriValue; @@ -48,7 +48,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Security/ExploitCatalogType"; + return "https://spdx.org/rdf/v3/Security/ExploitCatalogType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java similarity index 97% rename from generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java index 787be6687..763772102 100644 --- a/generated/src/main/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -261,7 +261,7 @@ public ExploitCatalogVulnAssessmentRelationshipBuilder(IModelStore modelStore, S * @parameter catalogType value to set * @return this for chaining **/ - ExploitCatalogVulnAssessmentRelationshipBuilder setCatalogType(ExploitCatalogType catalogType) { + public ExploitCatalogVulnAssessmentRelationshipBuilder setCatalogType(ExploitCatalogType catalogType) { this.catalogType = catalogType; return this; } @@ -271,7 +271,7 @@ ExploitCatalogVulnAssessmentRelationshipBuilder setCatalogType(ExploitCatalogTyp * @parameter exploited value to set * @return this for chaining **/ - ExploitCatalogVulnAssessmentRelationshipBuilder setExploited(Boolean exploited) { + public ExploitCatalogVulnAssessmentRelationshipBuilder setExploited(Boolean exploited) { this.exploited = exploited; return this; } @@ -281,7 +281,7 @@ ExploitCatalogVulnAssessmentRelationshipBuilder setExploited(Boolean exploited) * @parameter locator value to set * @return this for chaining **/ - ExploitCatalogVulnAssessmentRelationshipBuilder setLocator(String locator) { + public ExploitCatalogVulnAssessmentRelationshipBuilder setLocator(String locator) { this.locator = locator; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java similarity index 91% rename from generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java rename to generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java index a36975c0c..f7475adb6 100644 --- a/generated/src/main/java/org/spdx/library/model/security/SsvcDecisionType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import org.spdx.library.IndividualUriValue; @@ -29,10 +29,10 @@ */ public enum SsvcDecisionType implements IndividualUriValue { + TRACK("track"), ACT("act"), TRACK_STAR("trackStar"), - ATTEND("attend"), - TRACK("track"); + ATTEND("attend"); private String longName; @@ -50,7 +50,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Security/SsvcDecisionType"; + return "https://spdx.org/rdf/v3/Security/SsvcDecisionType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java similarity index 98% rename from generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java index 54aedeb7d..bb903fd55 100644 --- a/generated/src/main/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -197,7 +197,7 @@ public SsvcVulnAssessmentRelationshipBuilder(IModelStore modelStore, String obje * @parameter decisionType value to set * @return this for chaining **/ - SsvcVulnAssessmentRelationshipBuilder setDecisionType(SsvcDecisionType decisionType) { + public SsvcVulnAssessmentRelationshipBuilder setDecisionType(SsvcDecisionType decisionType) { this.decisionType = decisionType; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java similarity index 89% rename from generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java index ffdb0ec30..d5573201c 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -37,6 +37,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.DateTime; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -57,7 +58,7 @@ */ public class VexAffectedVulnAssessmentRelationship extends VexVulnAssessmentRelationship { - Collection actionStatementTimes; + Collection actionStatementTimes; /** * Create the VexAffectedVulnAssessmentRelationship with default model store and generated anonymous ID @@ -86,7 +87,7 @@ public VexAffectedVulnAssessmentRelationship(String objectUri) throws InvalidSPD public VexAffectedVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); + actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, DateTime.class); } /** @@ -97,7 +98,7 @@ public VexAffectedVulnAssessmentRelationship(IModelStore modelStore, String obje @SuppressWarnings("unchecked") protected VexAffectedVulnAssessmentRelationship(VexAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); + actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, DateTime.class); getActionStatementTimes().addAll(builder.actionStatementTimes); setActionStatement(builder.actionStatement); } @@ -111,7 +112,7 @@ public String getType() { } // Getters and Setters - public Collection getActionStatementTimes() { + public Collection getActionStatementTimes() { return actionStatementTimes; } @@ -151,6 +152,9 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting actionStatement for VexAffectedVulnAssessmentRelationship: "+e.getMessage()); } + for (DateTime actionStatementTime:actionStatementTimes) { + retval.addAll(actionStatementTime.verify(verifiedIds, specVersion, profiles)); + } return retval; } @@ -186,7 +190,7 @@ public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, Stri super(modelStore, objectUri, copyManager); } - Collection actionStatementTimes = new ArrayList<>(); + Collection actionStatementTimes = new ArrayList<>(); String actionStatement = null; @@ -195,7 +199,7 @@ public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, Stri * @parameter actionStatementTime actionStatementTime to add * @return this for chaining **/ - VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(String actionStatementTime) { + public VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(DateTime actionStatementTime) { if (Objects.nonNull(actionStatementTime)) { actionStatementTimes.add(actionStatementTime); } @@ -207,7 +211,7 @@ VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(String actio * @parameter actionStatementTimeCollection collection to initialize the actionStatementTime * @return this for chaining **/ - VexAffectedVulnAssessmentRelationshipBuilder addAllActionStatementTime(Collection actionStatementTimeCollection) { + public VexAffectedVulnAssessmentRelationshipBuilder addAllActionStatementTime(Collection actionStatementTimeCollection) { if (Objects.nonNull(actionStatementTimeCollection)) { actionStatementTimes.addAll(actionStatementTimeCollection); } @@ -219,7 +223,7 @@ VexAffectedVulnAssessmentRelationshipBuilder addAllActionStatementTime(Collectio * @parameter actionStatement value to set * @return this for chaining **/ - VexAffectedVulnAssessmentRelationshipBuilder setActionStatement(String actionStatement) { + public VexAffectedVulnAssessmentRelationshipBuilder setActionStatement(String actionStatement) { this.actionStatement = actionStatement; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java index bd36318e4..3f3c8fbdb 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java index 71402500c..3896477a5 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexJustificationType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import org.spdx.library.IndividualUriValue; @@ -29,11 +29,11 @@ */ public enum VexJustificationType implements IndividualUriValue { + VULNERABLE_CODE_NOT_PRESENT("vulnerableCodeNotPresent"), + VULNERABLE_CODE_CANNOT_BE_CONTROLLED_BY_ADVERSARY("vulnerableCodeCannotBeControlledByAdversary"), COMPONENT_NOT_PRESENT("componentNotPresent"), - INLINE_MITIGATIONS_ALREADY_EXIST("inlineMitigationsAlreadyExist"), VULNERABLE_CODE_NOT_IN_EXECUTE_PATH("vulnerableCodeNotInExecutePath"), - VULNERABLE_CODE_CANNOT_BE_CONTROLLED_BY_ADVERSARY("vulnerableCodeCannotBeControlledByAdversary"), - VULNERABLE_CODE_NOT_PRESENT("vulnerableCodeNotPresent"); + INLINE_MITIGATIONS_ALREADY_EXIST("inlineMitigationsAlreadyExist"); private String longName; @@ -51,7 +51,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Security/VexJustificationType"; + return "https://spdx.org/rdf/v3/Security/VexJustificationType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java similarity index 89% rename from generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java index db63752f8..2c5b366a4 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -35,6 +35,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.DateTime; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -95,8 +96,8 @@ public VexNotAffectedVulnAssessmentRelationship(IModelStore modelStore, String o */ protected VexNotAffectedVulnAssessmentRelationship(VexNotAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setJustificationType(builder.justificationType); setImpactStatementTime(builder.impactStatementTime); + setJustificationType(builder.justificationType); setImpactStatement(builder.impactStatement); } @@ -110,6 +111,32 @@ public String getType() { // Getters and Setters + + /** + * @return the impactStatementTime + */ + @SuppressWarnings("unchecked") + public Optional getImpactStatementTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param impactStatementTime the impactStatementTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexNotAffectedVulnAssessmentRelationship setImpactStatementTime(@Nullable DateTime impactStatementTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME, impactStatementTime); + return this; + } /** * @return the justificationType @@ -136,22 +163,6 @@ public VexNotAffectedVulnAssessmentRelationship setJustificationType(@Nullable V return this; } - /** - * @return the impactStatementTime - */ - public Optional getImpactStatementTime() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME); - } - /** - * @param impactStatementTime the impactStatementTime to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public VexNotAffectedVulnAssessmentRelationship setImpactStatementTime(@Nullable String impactStatementTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME, impactStatementTime); - return this; - } - /** * @return the impactStatement */ @@ -181,17 +192,20 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional impactStatementTime; try { - @SuppressWarnings("unused") - Optional justificationType = getJustificationType(); + impactStatementTime = getImpactStatementTime(); + if (impactStatementTime.isPresent()) { + retval.addAll(impactStatementTime.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting justificationType for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting impactStatementTime for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional impactStatementTime = getImpactStatementTime(); + Optional justificationType = getJustificationType(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting impactStatementTime for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting justificationType for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -234,28 +248,28 @@ public VexNotAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, S super(modelStore, objectUri, copyManager); } + DateTime impactStatementTime = null; VexJustificationType justificationType = null; - String impactStatementTime = null; String impactStatement = null; /** - * Sets the initial value of justificationType - * @parameter justificationType value to set + * Sets the initial value of impactStatementTime + * @parameter impactStatementTime value to set * @return this for chaining **/ - VexNotAffectedVulnAssessmentRelationshipBuilder setJustificationType(VexJustificationType justificationType) { - this.justificationType = justificationType; + public VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatementTime(DateTime impactStatementTime) { + this.impactStatementTime = impactStatementTime; return this; } /** - * Sets the initial value of impactStatementTime - * @parameter impactStatementTime value to set + * Sets the initial value of justificationType + * @parameter justificationType value to set * @return this for chaining **/ - VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatementTime(String impactStatementTime) { - this.impactStatementTime = impactStatementTime; + public VexNotAffectedVulnAssessmentRelationshipBuilder setJustificationType(VexJustificationType justificationType) { + this.justificationType = justificationType; return this; } @@ -264,7 +278,7 @@ VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatementTime(String im * @parameter impactStatement value to set * @return this for chaining **/ - VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatement(String impactStatement) { + public VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatement(String impactStatement) { this.impactStatement = impactStatement; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java similarity index 99% rename from generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java index f7dd84e98..9db728f90 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; diff --git a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java similarity index 97% rename from generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java index 7bd12225d..dbb002f61 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VexVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -208,7 +208,7 @@ public VexVulnAssessmentRelationshipBuilder(IModelStore modelStore, String objec * @parameter statusNotes value to set * @return this for chaining **/ - VexVulnAssessmentRelationshipBuilder setStatusNotes(String statusNotes) { + public VexVulnAssessmentRelationshipBuilder setStatusNotes(String statusNotes) { this.statusNotes = statusNotes; return this; } @@ -218,7 +218,7 @@ VexVulnAssessmentRelationshipBuilder setStatusNotes(String statusNotes) { * @parameter vexVersion value to set * @return this for chaining **/ - VexVulnAssessmentRelationshipBuilder setVexVersion(String vexVersion) { + public VexVulnAssessmentRelationshipBuilder setVexVersion(String vexVersion) { this.vexVersion = vexVersion; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java similarity index 56% rename from generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java index 8f74a67be..803a83416 100644 --- a/generated/src/main/java/org/spdx/library/model/security/VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -34,10 +34,11 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.Agent; -import org.spdx.library.model.core.Element; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.core.Relationship; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.library.model.v3.core.DateTime; +import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.Relationship; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -85,8 +86,11 @@ public VulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nul */ protected VulnAssessmentRelationship(VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setAssessedElement(builder.assessedElement); setSuppliedBy(builder.suppliedBy); + setPublishedTime(builder.publishedTime); + setWithdrawnTime(builder.withdrawnTime); + setAssessedElement(builder.assessedElement); + setModifiedTime(builder.modifiedTime); } /* (non-Javadoc) @@ -99,11 +103,99 @@ public String getType() { // Getters and Setters + + /** + * @return the suppliedBy + */ + @SuppressWarnings("unchecked") + public Optional getSuppliedBy() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_SUPPLIED_BY); + if (retval.isPresent()) { + if (!(retval.get() instanceof Agent)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param suppliedBy the suppliedBy to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VulnAssessmentRelationship setSuppliedBy(@Nullable Agent suppliedBy) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_SUPPLIED_BY, suppliedBy); + return this; + } + + /** + * @return the publishedTime + */ + @SuppressWarnings("unchecked") + public Optional getPublishedTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param publishedTime the publishedTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VulnAssessmentRelationship setPublishedTime(@Nullable DateTime publishedTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME, publishedTime); + return this; + } + + /** + * @return the withdrawnTime + */ + @SuppressWarnings("unchecked") + public Optional getWithdrawnTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + /** + * @param withdrawnTime the withdrawnTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VulnAssessmentRelationship setWithdrawnTime(@Nullable DateTime withdrawnTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME, withdrawnTime); + return this; + } + + /** * @return the assessedElement */ + @SuppressWarnings("unchecked") public Optional getAssessedElement() throws InvalidSPDXAnalysisException { - return getElementPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT); + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT); + if (retval.isPresent()) { + if (!(retval.get() instanceof Element)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } /** @@ -115,26 +207,34 @@ public VulnAssessmentRelationship setAssessedElement(@Nullable Element assessedE setPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT, assessedElement); return this; } - - /** - * @return the suppliedBy + + /** + * @return the modifiedTime */ - public Optional getSuppliedBy() throws InvalidSPDXAnalysisException { - return getElementPropertyValue(SpdxConstants.SECURITY_PROP_SUPPLIED_BY); + @SuppressWarnings("unchecked") + public Optional getModifiedTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } /** - * @param suppliedBy the suppliedBy to set + * @param modifiedTime the modifiedTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public VulnAssessmentRelationship setSuppliedBy(@Nullable Element suppliedBy) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_SUPPLIED_BY, suppliedBy); + public VulnAssessmentRelationship setModifiedTime(@Nullable DateTime modifiedTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME, modifiedTime); return this; } - @Override public String toString() { return "VulnAssessmentRelationship: "+getObjectUri(); @@ -147,6 +247,33 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional suppliedBy; + try { + suppliedBy = getSuppliedBy(); + if (suppliedBy.isPresent()) { + retval.addAll(suppliedBy.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting suppliedBy for VulnAssessmentRelationship: "+e.getMessage()); + } + Optional publishedTime; + try { + publishedTime = getPublishedTime(); + if (publishedTime.isPresent()) { + retval.addAll(publishedTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting publishedTime for VulnAssessmentRelationship: "+e.getMessage()); + } + Optional withdrawnTime; + try { + withdrawnTime = getWithdrawnTime(); + if (withdrawnTime.isPresent()) { + retval.addAll(withdrawnTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting withdrawnTime for VulnAssessmentRelationship: "+e.getMessage()); + } Optional assessedElement; try { assessedElement = getAssessedElement(); @@ -156,14 +283,14 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting assessedElement for VulnAssessmentRelationship: "+e.getMessage()); } - Optional suppliedBy; + Optional modifiedTime; try { - suppliedBy = getSuppliedBy(); - if (suppliedBy.isPresent()) { - retval.addAll(suppliedBy.get().verify(verifiedIds, specVersion, profiles)); + modifiedTime = getModifiedTime(); + if (modifiedTime.isPresent()) { + retval.addAll(modifiedTime.get().verify(verifiedIds, specVersion, profiles)); } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting suppliedBy for VulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting modifiedTime for VulnAssessmentRelationship: "+e.getMessage()); } return retval; } @@ -200,27 +327,60 @@ public VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUr super(modelStore, objectUri, copyManager); } - Element assessedElement = null; Agent suppliedBy = null; + DateTime publishedTime = null; + DateTime withdrawnTime = null; + Element assessedElement = null; + DateTime modifiedTime = null; + /** + * Sets the initial value of suppliedBy + * @parameter suppliedBy value to set + * @return this for chaining + **/ + public VulnAssessmentRelationshipBuilder setSuppliedBy(Agent suppliedBy) { + this.suppliedBy = suppliedBy; + return this; + } + + /** + * Sets the initial value of publishedTime + * @parameter publishedTime value to set + * @return this for chaining + **/ + public VulnAssessmentRelationshipBuilder setPublishedTime(DateTime publishedTime) { + this.publishedTime = publishedTime; + return this; + } + + /** + * Sets the initial value of withdrawnTime + * @parameter withdrawnTime value to set + * @return this for chaining + **/ + public VulnAssessmentRelationshipBuilder setWithdrawnTime(DateTime withdrawnTime) { + this.withdrawnTime = withdrawnTime; + return this; + } + /** * Sets the initial value of assessedElement * @parameter assessedElement value to set * @return this for chaining **/ - VulnAssessmentRelationshipBuilder setAssessedElement(Element assessedElement) { + public VulnAssessmentRelationshipBuilder setAssessedElement(Element assessedElement) { this.assessedElement = assessedElement; return this; } /** - * Sets the initial value of suppliedBy - * @parameter suppliedBy value to set + * Sets the initial value of modifiedTime + * @parameter modifiedTime value to set * @return this for chaining **/ - VulnAssessmentRelationshipBuilder setSuppliedBy(Agent suppliedBy) { - this.suppliedBy = suppliedBy; + public VulnAssessmentRelationshipBuilder setModifiedTime(DateTime modifiedTime) { + this.modifiedTime = modifiedTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java b/generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java similarity index 62% rename from generated/src/main/java/org/spdx/library/model/security/Vulnerability.java rename to generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java index 2993c9d46..914faa7f2 100644 --- a/generated/src/main/java/org/spdx/library/model/security/Vulnerability.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -32,8 +32,11 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.Element; +import java.util.Optional; +import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.DateTime; +import org.spdx.library.model.v3.core.Element; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -107,6 +110,9 @@ public Vulnerability(IModelStore modelStore, String objectUri, @Nullable ModelCo */ protected Vulnerability(VulnerabilityBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + setModifiedTime(builder.modifiedTime); + setWithdrawnTime(builder.withdrawnTime); + setPublishedTime(builder.publishedTime); } /* (non-Javadoc) @@ -119,6 +125,84 @@ public String getType() { // Getters and Setters + + /** + * @return the modifiedTime + */ + @SuppressWarnings("unchecked") + public Optional getModifiedTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param modifiedTime the modifiedTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Vulnerability setModifiedTime(@Nullable DateTime modifiedTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME, modifiedTime); + return this; + } + + /** + * @return the withdrawnTime + */ + @SuppressWarnings("unchecked") + public Optional getWithdrawnTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param withdrawnTime the withdrawnTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Vulnerability setWithdrawnTime(@Nullable DateTime withdrawnTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME, withdrawnTime); + return this; + } + + /** + * @return the publishedTime + */ + @SuppressWarnings("unchecked") + public Optional getPublishedTime() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME); + if (retval.isPresent()) { + if (!(retval.get() instanceof DateTime)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } + } + + /** + * @param publishedTime the publishedTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Vulnerability setPublishedTime(@Nullable DateTime publishedTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME, publishedTime); + return this; + } @Override @@ -133,6 +217,33 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional modifiedTime; + try { + modifiedTime = getModifiedTime(); + if (modifiedTime.isPresent()) { + retval.addAll(modifiedTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting modifiedTime for Vulnerability: "+e.getMessage()); + } + Optional withdrawnTime; + try { + withdrawnTime = getWithdrawnTime(); + if (withdrawnTime.isPresent()) { + retval.addAll(withdrawnTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting withdrawnTime for Vulnerability: "+e.getMessage()); + } + Optional publishedTime; + try { + publishedTime = getPublishedTime(); + if (publishedTime.isPresent()) { + retval.addAll(publishedTime.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting publishedTime for Vulnerability: "+e.getMessage()); + } return retval; } @@ -168,7 +279,40 @@ public VulnerabilityBuilder(IModelStore modelStore, String objectUri, @Nullable super(modelStore, objectUri, copyManager); } + DateTime modifiedTime = null; + DateTime withdrawnTime = null; + DateTime publishedTime = null; + + + /** + * Sets the initial value of modifiedTime + * @parameter modifiedTime value to set + * @return this for chaining + **/ + public VulnerabilityBuilder setModifiedTime(DateTime modifiedTime) { + this.modifiedTime = modifiedTime; + return this; + } + /** + * Sets the initial value of withdrawnTime + * @parameter withdrawnTime value to set + * @return this for chaining + **/ + public VulnerabilityBuilder setWithdrawnTime(DateTime withdrawnTime) { + this.withdrawnTime = withdrawnTime; + return this; + } + + /** + * Sets the initial value of publishedTime + * @parameter publishedTime value to set + * @return this for chaining + **/ + public VulnerabilityBuilder setPublishedTime(DateTime publishedTime) { + this.publishedTime = publishedTime; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java b/generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java similarity index 91% rename from generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java rename to generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java index 16bec94be..11dcf53e3 100644 --- a/generated/src/main/java/org/spdx/library/model/software/DependencyConditionalityType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import org.spdx.library.IndividualUriValue; @@ -28,10 +28,10 @@ */ public enum DependencyConditionalityType implements IndividualUriValue { - OTHER("other"), + PROVIDED("provided"), REQUIRED("required"), OPTIONAL("optional"), - PROVIDED("provided"), + OTHER("other"), PREREQUISITE("prerequisite"); private String longName; @@ -50,7 +50,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Software/DependencyConditionalityType"; + return "https://spdx.org/rdf/v3/Software/DependencyConditionalityType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/software/Sbom.java b/generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/software/Sbom.java rename to generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java index aa80b32d4..018f4a94f 100644 --- a/generated/src/main/java/org/spdx/library/model/software/Sbom.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -36,8 +36,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.Bom; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.Bom; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -50,7 +50,7 @@ */ public class Sbom extends Bom { - Collection sbomTypes; + Collection sbomTypes; /** * Create the Sbom with default model store and generated anonymous ID @@ -78,7 +78,7 @@ public Sbom(String objectUri) throws InvalidSPDXAnalysisException { public Sbom(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - sbomTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_SBOM_TYPE, SBOMType.class); + sbomTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_SBOM_TYPE, SbomType.class); } /** @@ -88,7 +88,7 @@ public Sbom(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager */ protected Sbom(SbomBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - sbomTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_SBOM_TYPE, SBOMType.class); + sbomTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_SBOM_TYPE, SbomType.class); getSbomTypes().addAll(builder.sbomTypes); } @@ -101,7 +101,7 @@ public String getType() { } // Getters and Setters - public Collection getSbomTypes() { + public Collection getSbomTypes() { return sbomTypes; } @@ -154,7 +154,7 @@ public SbomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopy super(modelStore, objectUri, copyManager); } - Collection sbomTypes = new ArrayList<>(); + Collection sbomTypes = new ArrayList<>(); /** @@ -162,7 +162,7 @@ public SbomBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopy * @parameter sbomType sbomType to add * @return this for chaining **/ - SbomBuilder addSbomType(SBOMType sbomType) { + public SbomBuilder addSbomType(SbomType sbomType) { if (Objects.nonNull(sbomType)) { sbomTypes.add(sbomType); } @@ -174,7 +174,7 @@ SbomBuilder addSbomType(SBOMType sbomType) { * @parameter sbomTypeCollection collection to initialize the sbomType * @return this for chaining **/ - SbomBuilder addAllSbomType(Collection sbomTypeCollection) { + public SbomBuilder addAllSbomType(Collection sbomTypeCollection) { if (Objects.nonNull(sbomTypeCollection)) { sbomTypes.addAll(sbomTypeCollection); } diff --git a/generated/src/main/java/org/spdx/library/model/software/SBOMType.java b/generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java similarity index 87% rename from generated/src/main/java/org/spdx/library/model/software/SBOMType.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java index d6884f9a1..b84e5391b 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SBOMType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import org.spdx.library.IndividualUriValue; @@ -31,18 +31,18 @@ * data inside an SBOM. A single SBOM can have multiple SBOM document types associated * with it. */ -public enum SBOMType implements IndividualUriValue { +public enum SbomType implements IndividualUriValue { + ANALYZED("analyzed"), SOURCE("source"), - BUILD("build"), + DESIGN("design"), DEPLOYED("deployed"), - ANALYZED("analyzed"), - RUNTIME("runtime"), - DESIGN("design"); + BUILD("build"), + RUNTIME("runtime"); private String longName; - private SBOMType(String longName) { + private SbomType(String longName) { this.longName = longName; } @@ -56,7 +56,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Software/SBOMType"; + return "https://spdx.org/rdf/v3/Software/SbomType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/software/Snippet.java b/generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java similarity index 97% rename from generated/src/main/java/org/spdx/library/model/software/Snippet.java rename to generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java index 491c22634..8c8b71193 100644 --- a/generated/src/main/java/org/spdx/library/model/software/Snippet.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -34,8 +34,8 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.PositiveIntegerRange; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.PositiveIntegerRange; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -84,8 +84,8 @@ public Snippet(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana */ protected Snippet(SnippetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setByteRange(builder.byteRange); setLineRange(builder.lineRange); + setByteRange(builder.byteRange); } /* (non-Javadoc) @@ -100,11 +100,11 @@ public String getType() { /** - * @return the byteRange + * @return the lineRange */ @SuppressWarnings("unchecked") - public Optional getByteRange() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_BYTE_RANGE); + public Optional getLineRange() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_LINE_RANGE); if (retval.isPresent()) { if (!(retval.get() instanceof PositiveIntegerRange)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -116,21 +116,21 @@ public Optional getByteRange() throws InvalidSPDXAnalysisE } /** - * @param byteRange the byteRange to set + * @param lineRange the lineRange to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Snippet setByteRange(@Nullable PositiveIntegerRange byteRange) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_BYTE_RANGE, byteRange); + public Snippet setLineRange(@Nullable PositiveIntegerRange lineRange) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_LINE_RANGE, lineRange); return this; } /** - * @return the lineRange + * @return the byteRange */ @SuppressWarnings("unchecked") - public Optional getLineRange() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_LINE_RANGE); + public Optional getByteRange() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_BYTE_RANGE); if (retval.isPresent()) { if (!(retval.get() instanceof PositiveIntegerRange)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -142,12 +142,12 @@ public Optional getLineRange() throws InvalidSPDXAnalysisE } /** - * @param lineRange the lineRange to set + * @param byteRange the byteRange to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Snippet setLineRange(@Nullable PositiveIntegerRange lineRange) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_LINE_RANGE, lineRange); + public Snippet setByteRange(@Nullable PositiveIntegerRange byteRange) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_BYTE_RANGE, byteRange); return this; } @@ -164,15 +164,6 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional byteRange; - try { - byteRange = getByteRange(); - if (byteRange.isPresent()) { - retval.addAll(byteRange.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting byteRange for Snippet: "+e.getMessage()); - } Optional lineRange; try { lineRange = getLineRange(); @@ -182,6 +173,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting lineRange for Snippet: "+e.getMessage()); } + Optional byteRange; + try { + byteRange = getByteRange(); + if (byteRange.isPresent()) { + retval.addAll(byteRange.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting byteRange for Snippet: "+e.getMessage()); + } return retval; } @@ -217,27 +217,27 @@ public SnippetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC super(modelStore, objectUri, copyManager); } - PositiveIntegerRange byteRange = null; PositiveIntegerRange lineRange = null; + PositiveIntegerRange byteRange = null; /** - * Sets the initial value of byteRange - * @parameter byteRange value to set + * Sets the initial value of lineRange + * @parameter lineRange value to set * @return this for chaining **/ - SnippetBuilder setByteRange(PositiveIntegerRange byteRange) { - this.byteRange = byteRange; + public SnippetBuilder setLineRange(PositiveIntegerRange lineRange) { + this.lineRange = lineRange; return this; } /** - * Sets the initial value of lineRange - * @parameter lineRange value to set + * Sets the initial value of byteRange + * @parameter byteRange value to set * @return this for chaining **/ - SnippetBuilder setLineRange(PositiveIntegerRange lineRange) { - this.lineRange = lineRange; + public SnippetBuilder setByteRange(PositiveIntegerRange byteRange) { + this.byteRange = byteRange; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java similarity index 89% rename from generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java index dd4158077..cafa26e81 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareArtifact.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -36,9 +36,9 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.Artifact; import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.core.Artifact; +import org.spdx.library.model.v3.licensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -89,11 +89,11 @@ protected SoftwareArtifact(SoftwareArtifactBuilder builder) throws InvalidSPDXAn super(builder); additionalPurposes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ADDITIONAL_PURPOSE, SoftwarePurpose.class); getAdditionalPurposes().addAll(builder.additionalPurposes); - setDeclaredLicense(builder.declaredLicense); setConcludedLicense(builder.concludedLicense); + setDeclaredLicense(builder.declaredLicense); setPrimaryPurpose(builder.primaryPurpose); - setContentIdentifier(builder.contentIdentifier); setAttributionText(builder.attributionText); + setContentIdentifier(builder.contentIdentifier); setCopyrightText(builder.copyrightText); } @@ -110,38 +110,56 @@ public Collection getAdditionalPurposes() { return additionalPurposes; } - - /** - * @return the declaredLicense + + /** + * @return the concludedLicense */ - public Optional getDeclaredLicense() throws InvalidSPDXAnalysisException { - return getAnyLicenseInfoPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE); + @SuppressWarnings("unchecked") + public Optional getConcludedLicense() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE); + if (retval.isPresent()) { + if (!(retval.get() instanceof AnyLicenseInfo)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } - + /** - * @param declaredLicense the declaredLicense to set + * @param concludedLicense the concludedLicense to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SoftwareArtifact setDeclaredLicense(@Nullable AnyLicenseInfo declaredLicense) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE, declaredLicense); + public SoftwareArtifact setConcludedLicense(@Nullable AnyLicenseInfo concludedLicense) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE, concludedLicense); return this; } - - /** - * @return the concludedLicense + + /** + * @return the declaredLicense */ - public Optional getConcludedLicense() throws InvalidSPDXAnalysisException { - return getAnyLicenseInfoPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE); + @SuppressWarnings("unchecked") + public Optional getDeclaredLicense() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE); + if (retval.isPresent()) { + if (!(retval.get() instanceof AnyLicenseInfo)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } - + /** - * @param concludedLicense the concludedLicense to set + * @param declaredLicense the declaredLicense to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SoftwareArtifact setConcludedLicense(@Nullable AnyLicenseInfo concludedLicense) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE, concludedLicense); + public SoftwareArtifact setDeclaredLicense(@Nullable AnyLicenseInfo declaredLicense) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE, declaredLicense); return this; } @@ -171,34 +189,34 @@ public SoftwareArtifact setPrimaryPurpose(@Nullable SoftwarePurpose primaryPurpo } /** - * @return the contentIdentifier + * @return the attributionText */ - public Optional getContentIdentifier() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_IDENTIFIER); + public Optional getAttributionText() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT); } /** - * @param contentIdentifier the contentIdentifier to set + * @param attributionText the attributionText to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SoftwareArtifact setContentIdentifier(@Nullable String contentIdentifier) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_IDENTIFIER, contentIdentifier); + public SoftwareArtifact setAttributionText(@Nullable String attributionText) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT, attributionText); return this; } /** - * @return the attributionText + * @return the contentIdentifier */ - public Optional getAttributionText() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT); + public Optional getContentIdentifier() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_IDENTIFIER); } /** - * @param attributionText the attributionText to set + * @param contentIdentifier the contentIdentifier to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SoftwareArtifact setAttributionText(@Nullable String attributionText) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT, attributionText); + public SoftwareArtifact setContentIdentifier(@Nullable String contentIdentifier) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_IDENTIFIER, contentIdentifier); return this; } @@ -231,15 +249,6 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional declaredLicense; - try { - declaredLicense = getDeclaredLicense(); - if (declaredLicense.isPresent()) { - retval.addAll(declaredLicense.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting declaredLicense for SoftwareArtifact: "+e.getMessage()); - } Optional concludedLicense; try { concludedLicense = getConcludedLicense(); @@ -249,6 +258,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting concludedLicense for SoftwareArtifact: "+e.getMessage()); } + Optional declaredLicense; + try { + declaredLicense = getDeclaredLicense(); + if (declaredLicense.isPresent()) { + retval.addAll(declaredLicense.get().verify(verifiedIds, specVersion, profiles)); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting declaredLicense for SoftwareArtifact: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional primaryPurpose = getPrimaryPurpose(); @@ -257,15 +275,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional contentIdentifier = getContentIdentifier(); + Optional attributionText = getAttributionText(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting contentIdentifier for SoftwareArtifact: "+e.getMessage()); + retval.add("Error getting attributionText for SoftwareArtifact: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional attributionText = getAttributionText(); + Optional contentIdentifier = getContentIdentifier(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting attributionText for SoftwareArtifact: "+e.getMessage()); + retval.add("Error getting contentIdentifier for SoftwareArtifact: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -309,11 +327,11 @@ public SoftwareArtifactBuilder(IModelStore modelStore, String objectUri, @Nullab } Collection additionalPurposes = new ArrayList<>(); - AnyLicenseInfo declaredLicense = null; AnyLicenseInfo concludedLicense = null; + AnyLicenseInfo declaredLicense = null; SoftwarePurpose primaryPurpose = null; - String contentIdentifier = null; String attributionText = null; + String contentIdentifier = null; String copyrightText = null; @@ -322,7 +340,7 @@ public SoftwareArtifactBuilder(IModelStore modelStore, String objectUri, @Nullab * @parameter additionalPurpose additionalPurpose to add * @return this for chaining **/ - SoftwareArtifactBuilder addAdditionalPurpose(SoftwarePurpose additionalPurpose) { + public SoftwareArtifactBuilder addAdditionalPurpose(SoftwarePurpose additionalPurpose) { if (Objects.nonNull(additionalPurpose)) { additionalPurposes.add(additionalPurpose); } @@ -334,7 +352,7 @@ SoftwareArtifactBuilder addAdditionalPurpose(SoftwarePurpose additionalPurpose) * @parameter additionalPurposeCollection collection to initialize the additionalPurpose * @return this for chaining **/ - SoftwareArtifactBuilder addAllAdditionalPurpose(Collection additionalPurposeCollection) { + public SoftwareArtifactBuilder addAllAdditionalPurpose(Collection additionalPurposeCollection) { if (Objects.nonNull(additionalPurposeCollection)) { additionalPurposes.addAll(additionalPurposeCollection); } @@ -342,22 +360,22 @@ SoftwareArtifactBuilder addAllAdditionalPurpose(Collection addi } /** - * Sets the initial value of declaredLicense - * @parameter declaredLicense value to set + * Sets the initial value of concludedLicense + * @parameter concludedLicense value to set * @return this for chaining **/ - SoftwareArtifactBuilder setDeclaredLicense(AnyLicenseInfo declaredLicense) { - this.declaredLicense = declaredLicense; + public SoftwareArtifactBuilder setConcludedLicense(AnyLicenseInfo concludedLicense) { + this.concludedLicense = concludedLicense; return this; } /** - * Sets the initial value of concludedLicense - * @parameter concludedLicense value to set + * Sets the initial value of declaredLicense + * @parameter declaredLicense value to set * @return this for chaining **/ - SoftwareArtifactBuilder setConcludedLicense(AnyLicenseInfo concludedLicense) { - this.concludedLicense = concludedLicense; + public SoftwareArtifactBuilder setDeclaredLicense(AnyLicenseInfo declaredLicense) { + this.declaredLicense = declaredLicense; return this; } @@ -366,28 +384,28 @@ SoftwareArtifactBuilder setConcludedLicense(AnyLicenseInfo concludedLicense) { * @parameter primaryPurpose value to set * @return this for chaining **/ - SoftwareArtifactBuilder setPrimaryPurpose(SoftwarePurpose primaryPurpose) { + public SoftwareArtifactBuilder setPrimaryPurpose(SoftwarePurpose primaryPurpose) { this.primaryPurpose = primaryPurpose; return this; } /** - * Sets the initial value of contentIdentifier - * @parameter contentIdentifier value to set + * Sets the initial value of attributionText + * @parameter attributionText value to set * @return this for chaining **/ - SoftwareArtifactBuilder setContentIdentifier(String contentIdentifier) { - this.contentIdentifier = contentIdentifier; + public SoftwareArtifactBuilder setAttributionText(String attributionText) { + this.attributionText = attributionText; return this; } /** - * Sets the initial value of attributionText - * @parameter attributionText value to set + * Sets the initial value of contentIdentifier + * @parameter contentIdentifier value to set * @return this for chaining **/ - SoftwareArtifactBuilder setAttributionText(String attributionText) { - this.attributionText = attributionText; + public SoftwareArtifactBuilder setContentIdentifier(String contentIdentifier) { + this.contentIdentifier = contentIdentifier; return this; } @@ -396,7 +414,7 @@ SoftwareArtifactBuilder setAttributionText(String attributionText) { * @parameter copyrightText value to set * @return this for chaining **/ - SoftwareArtifactBuilder setCopyrightText(String copyrightText) { + public SoftwareArtifactBuilder setCopyrightText(String copyrightText) { this.copyrightText = copyrightText; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java similarity index 91% rename from generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java index 6bd6a2b8a..b2bbe6851 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyLinkType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import org.spdx.library.IndividualUriValue; @@ -28,9 +28,9 @@ */ public enum SoftwareDependencyLinkType implements IndividualUriValue { - STATIC("static"), OTHER("other"), DYNAMIC("dynamic"), + STATIC("static"), TOOL("tool"); private String longName; @@ -49,7 +49,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Software/SoftwareDependencyLinkType"; + return "https://spdx.org/rdf/v3/Software/SoftwareDependencyLinkType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java similarity index 96% rename from generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java index 78437fe9a..4425bb285 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwareDependencyRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -34,8 +34,8 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.LifecycleScopedRelationship; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.LifecycleScopedRelationship; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -215,7 +215,7 @@ public SoftwareDependencyRelationshipBuilder(IModelStore modelStore, String obje * @parameter softwareLinkage value to set * @return this for chaining **/ - SoftwareDependencyRelationshipBuilder setSoftwareLinkage(SoftwareDependencyLinkType softwareLinkage) { + public SoftwareDependencyRelationshipBuilder setSoftwareLinkage(SoftwareDependencyLinkType softwareLinkage) { this.softwareLinkage = softwareLinkage; return this; } @@ -225,7 +225,7 @@ SoftwareDependencyRelationshipBuilder setSoftwareLinkage(SoftwareDependencyLinkT * @parameter conditionality value to set * @return this for chaining **/ - SoftwareDependencyRelationshipBuilder setConditionality(DependencyConditionalityType conditionality) { + public SoftwareDependencyRelationshipBuilder setConditionality(DependencyConditionalityType conditionality) { this.conditionality = conditionality; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java similarity index 93% rename from generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java index b88e751ab..958507784 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SoftwarePurpose.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import org.spdx.library.IndividualUriValue; @@ -32,31 +32,31 @@ */ public enum SoftwarePurpose implements IndividualUriValue { - CONFIGURATION("configuration"), - FILE("file"), - FIRMWARE("firmware"), + TEST("test"), EXECUTABLE("executable"), - ARCHIVE("archive"), - MODEL("model"), - REQUIREMENT("requirement"), + OPERATING_SYSTEM("operatingSystem"), + DOCUMENTATION("documentation"), + EVIDENCE("evidence"), + INSTALL("install"), SPECIFICATION("specification"), + MODULE("module"), FRAMEWORK("framework"), - PATCH("patch"), + REQUIREMENT("requirement"), + MODEL("model"), + ARCHIVE("archive"), + SOURCE("source"), + CONFIGURATION("configuration"), + CONTAINER("container"), + FILE("file"), DATA("data"), + MANIFEST("manifest"), LIBRARY("library"), - EVIDENCE("evidence"), - TEST("test"), - INSTALL("install"), - CONTAINER("container"), - SOURCE("source"), - OPERATING_SYSTEM("operatingSystem"), - DOCUMENTATION("documentation"), - MODULE("module"), - DEVICE("device"), - APPLICATION("application"), - OTHER("other"), BOM("bom"), - MANIFEST("manifest"); + OTHER("other"), + DEVICE("device"), + PATCH("patch"), + FIRMWARE("firmware"), + APPLICATION("application"); private String longName; @@ -74,7 +74,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/Software/SoftwarePurpose"; + return "https://spdx.org/rdf/v3/Software/SoftwarePurpose"; } } diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java similarity index 86% rename from generated/src/main/java/org/spdx/library/model/software/SpdxFile.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java index a6deea6c3..398514f0a 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SpdxFile.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -35,6 +35,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.MediaType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -99,15 +100,25 @@ public String getType() { /** * @return the contentType */ - public Optional getContentType() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE); + @SuppressWarnings("unchecked") + public Optional getContentType() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE); + if (retval.isPresent()) { + if (!(retval.get() instanceof MediaType)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (Optional)(Optional)(retval); + } else { + return Optional.empty(); + } } + /** * @param contentType the contentType to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxFile setContentType(@Nullable String contentType) throws InvalidSPDXAnalysisException { + public SpdxFile setContentType(@Nullable MediaType contentType) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE, contentType); return this; } @@ -125,9 +136,12 @@ public String toString() { protected List _verify(Set verifiedIds, String specVersion, List profiles) { List retval = new ArrayList<>(); retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + Optional contentType; try { - @SuppressWarnings("unused") - Optional contentType = getContentType(); + contentType = getContentType(); + if (contentType.isPresent()) { + retval.addAll(contentType.get().verify(verifiedIds, specVersion, profiles)); + } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting contentType for SpdxFile: "+e.getMessage()); } @@ -166,7 +180,7 @@ public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable Model super(modelStore, objectUri, copyManager); } - String contentType = null; + MediaType contentType = null; /** @@ -174,7 +188,7 @@ public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable Model * @parameter contentType value to set * @return this for chaining **/ - SpdxFileBuilder setContentType(String contentType) { + public SpdxFileBuilder setContentType(MediaType contentType) { this.contentType = contentType; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java similarity index 96% rename from generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java rename to generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java index afc7c4b5c..f417930f3 100644 --- a/generated/src/main/java/org/spdx/library/model/software/SpdxPackage.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -89,11 +89,11 @@ public SpdxPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopy */ protected SpdxPackage(SpdxPackageBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setDownloadLocation(builder.downloadLocation); setSourceInfo(builder.sourceInfo); - setPackageVersion(builder.packageVersion); setHomePage(builder.homePage); + setPackageVersion(builder.packageVersion); setPackageUrl(builder.packageUrl); + setDownloadLocation(builder.downloadLocation); } /* (non-Javadoc) @@ -108,34 +108,34 @@ public String getType() { /** - * @return the downloadLocation + * @return the sourceInfo */ - public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION); + public Optional getSourceInfo() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO); } /** - * @param downloadLocation the downloadLocation to set + * @param sourceInfo the sourceInfo to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setDownloadLocation(@Nullable String downloadLocation) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION, downloadLocation); + public SpdxPackage setSourceInfo(@Nullable String sourceInfo) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO, sourceInfo); return this; } /** - * @return the sourceInfo + * @return the homePage */ - public Optional getSourceInfo() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO); + public Optional getHomePage() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_HOME_PAGE); } /** - * @param sourceInfo the sourceInfo to set + * @param homePage the homePage to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setSourceInfo(@Nullable String sourceInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO, sourceInfo); + public SpdxPackage setHomePage(@Nullable String homePage) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_HOME_PAGE, homePage); return this; } @@ -156,34 +156,34 @@ public SpdxPackage setPackageVersion(@Nullable String packageVersion) throws Inv } /** - * @return the homePage + * @return the packageUrl */ - public Optional getHomePage() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_HOME_PAGE); + public Optional getPackageUrl() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL); } /** - * @param homePage the homePage to set + * @param packageUrl the packageUrl to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setHomePage(@Nullable String homePage) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_HOME_PAGE, homePage); + public SpdxPackage setPackageUrl(@Nullable String packageUrl) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL, packageUrl); return this; } /** - * @return the packageUrl + * @return the downloadLocation */ - public Optional getPackageUrl() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL); + public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION); } /** - * @param packageUrl the packageUrl to set + * @param downloadLocation the downloadLocation to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setPackageUrl(@Nullable String packageUrl) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL, packageUrl); + public SpdxPackage setDownloadLocation(@Nullable String downloadLocation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION, downloadLocation); return this; } @@ -202,15 +202,15 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.addAll(super._verify(verifiedIds, specVersion, profiles)); try { @SuppressWarnings("unused") - Optional downloadLocation = getDownloadLocation(); + Optional sourceInfo = getSourceInfo(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting downloadLocation for SpdxPackage: "+e.getMessage()); + retval.add("Error getting sourceInfo for SpdxPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional sourceInfo = getSourceInfo(); + Optional homePage = getHomePage(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting sourceInfo for SpdxPackage: "+e.getMessage()); + retval.add("Error getting homePage for SpdxPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -220,15 +220,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional homePage = getHomePage(); + Optional packageUrl = getPackageUrl(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting homePage for SpdxPackage: "+e.getMessage()); + retval.add("Error getting packageUrl for SpdxPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional packageUrl = getPackageUrl(); + Optional downloadLocation = getDownloadLocation(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting packageUrl for SpdxPackage: "+e.getMessage()); + retval.add("Error getting downloadLocation for SpdxPackage: "+e.getMessage()); } return retval; } @@ -265,30 +265,30 @@ public SpdxPackageBuilder(IModelStore modelStore, String objectUri, @Nullable Mo super(modelStore, objectUri, copyManager); } - String downloadLocation = null; String sourceInfo = null; - String packageVersion = null; String homePage = null; + String packageVersion = null; String packageUrl = null; + String downloadLocation = null; /** - * Sets the initial value of downloadLocation - * @parameter downloadLocation value to set + * Sets the initial value of sourceInfo + * @parameter sourceInfo value to set * @return this for chaining **/ - SpdxPackageBuilder setDownloadLocation(String downloadLocation) { - this.downloadLocation = downloadLocation; + public SpdxPackageBuilder setSourceInfo(String sourceInfo) { + this.sourceInfo = sourceInfo; return this; } /** - * Sets the initial value of sourceInfo - * @parameter sourceInfo value to set + * Sets the initial value of homePage + * @parameter homePage value to set * @return this for chaining **/ - SpdxPackageBuilder setSourceInfo(String sourceInfo) { - this.sourceInfo = sourceInfo; + public SpdxPackageBuilder setHomePage(String homePage) { + this.homePage = homePage; return this; } @@ -297,28 +297,28 @@ SpdxPackageBuilder setSourceInfo(String sourceInfo) { * @parameter packageVersion value to set * @return this for chaining **/ - SpdxPackageBuilder setPackageVersion(String packageVersion) { + public SpdxPackageBuilder setPackageVersion(String packageVersion) { this.packageVersion = packageVersion; return this; } /** - * Sets the initial value of homePage - * @parameter homePage value to set + * Sets the initial value of packageUrl + * @parameter packageUrl value to set * @return this for chaining **/ - SpdxPackageBuilder setHomePage(String homePage) { - this.homePage = homePage; + public SpdxPackageBuilder setPackageUrl(String packageUrl) { + this.packageUrl = packageUrl; return this; } /** - * Sets the initial value of packageUrl - * @parameter packageUrl value to set + * Sets the initial value of downloadLocation + * @parameter downloadLocation value to set * @return this for chaining **/ - SpdxPackageBuilder setPackageUrl(String packageUrl) { - this.packageUrl = packageUrl; + public SpdxPackageBuilder setDownloadLocation(String downloadLocation) { + this.downloadLocation = downloadLocation; return this; } diff --git a/src/main/java/org/spdx/library/SimpleUriValue.java b/src/main/java/org/spdx/library/SimpleUriValue.java index d168db003..3bbec28f5 100644 --- a/src/main/java/org/spdx/library/SimpleUriValue.java +++ b/src/main/java/org/spdx/library/SimpleUriValue.java @@ -28,7 +28,7 @@ import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.ExternalElement; import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; -import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.storage.IModelStore; /** diff --git a/src/main/java/org/spdx/library/TypedValue.java b/src/main/java/org/spdx/library/TypedValue.java index 98769fa46..0417f4b87 100644 --- a/src/main/java/org/spdx/library/TypedValue.java +++ b/src/main/java/org/spdx/library/TypedValue.java @@ -36,6 +36,8 @@ public TypedValue(String objectUri, String type) throws SpdxInvalidIdException, throw new SpdxInvalidTypeException("Null type"); } if (!SPDX_CLASSES.contains(type) && !GenericModelObject.GENERIC_MODEL_OBJECT_TYPE.equals(type) + &&!"ModelObjectForTesting".equals(type) + &&!"ElementForTest".equals(type) &&!GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE.equals(type) &&!GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE.equals(type)) { throw new SpdxInvalidTypeException(type + " is not a valid SPDX class"); diff --git a/src/main/java/org/spdx/library/model/ExternalElement.java b/src/main/java/org/spdx/library/model/ExternalElement.java index 7a8c7eb98..7d499ab84 100644 --- a/src/main/java/org/spdx/library/model/ExternalElement.java +++ b/src/main/java/org/spdx/library/model/ExternalElement.java @@ -28,14 +28,12 @@ import org.spdx.library.IndividualUriValue; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.CreationInfo; -import org.spdx.library.model.core.Element; -import org.spdx.library.model.core.ExternalIdentifier; -import org.spdx.library.model.core.ExternalMap; -import org.spdx.library.model.core.ExternalReference; -import org.spdx.library.model.core.NamespaceMap; -import org.spdx.library.model.core.Payload; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ExternalIdentifier; +import org.spdx.library.model.v3.core.ExternalMap; +import org.spdx.library.model.v3.core.ExternalReference; +import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.storage.IModelStore; /** @@ -80,11 +78,7 @@ public String getType() { } // Getters and Setters - - @Override - public Collection getNamespacess() { - throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); - } + /** * @return the externalMap */ @@ -92,30 +86,16 @@ public ExternalMap getExternal() { return this.external; } - @Override - public Collection getImportss() { - throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); - } /** * @return the creationInfo */ @Override - public Optional getCreationInfo() throws InvalidSPDXAnalysisException { + public CreationInfo getCreationInfo() throws InvalidSPDXAnalysisException { throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); } - /** - * @param creationInfo the creationInfo to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - @Override - public Payload setCreationInfo(@Nullable CreationInfo creationInfo) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); - } - @Override public Collection getExternalReferences() { throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); diff --git a/src/main/java/org/spdx/library/model/ModelCollection.java b/src/main/java/org/spdx/library/model/ModelCollection.java index 440acfc69..efcb6e82c 100644 --- a/src/main/java/org/spdx/library/model/ModelCollection.java +++ b/src/main/java/org/spdx/library/model/ModelCollection.java @@ -37,7 +37,7 @@ import org.spdx.library.SpdxIdNotFoundException; import org.spdx.library.SpdxInvalidTypeException; import org.spdx.library.SpdxObjectNotInStoreException; -import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 251b8c9a2..3c4c02789 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -47,11 +47,11 @@ import org.spdx.library.SpdxConstants; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; -import org.spdx.library.model.core.CreationInfo; -import org.spdx.library.model.core.Element; -import org.spdx.library.model.core.ExternalMap; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ExternalMap; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.licensing.AnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; @@ -242,11 +242,11 @@ public List verify(Set verifiedElementUris, String specVersion, public List verify(Set verifiedElementUris, String specVersion) { List profiles = new ArrayList<>(); if (this instanceof Element) { - Optional creationInfo; + CreationInfo creationInfo; try { creationInfo = ((Element)this).getCreationInfo(); - if (creationInfo.isPresent()) { - profiles = new ArrayList<>(creationInfo.get().getProfiles()); + if (Objects.nonNull(creationInfo)) { + profiles = new ArrayList<>(creationInfo.getProfiles()); } } catch (InvalidSPDXAnalysisException e) { logger.error("Error getting element profile for verification", e); diff --git a/src/main/java/org/spdx/library/model/ModelObjectHelper.java b/src/main/java/org/spdx/library/model/ModelObjectHelper.java index 491e95ec1..e86d244a6 100644 --- a/src/main/java/org/spdx/library/model/ModelObjectHelper.java +++ b/src/main/java/org/spdx/library/model/ModelObjectHelper.java @@ -35,7 +35,7 @@ import org.spdx.library.SpdxModelFactory; import org.spdx.library.SpdxObjectNotInStoreException; import org.spdx.library.TypedValue; -import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; diff --git a/src/main/java/org/spdx/library/model/ModelSet.java b/src/main/java/org/spdx/library/model/ModelSet.java index 75f16d733..9689d990a 100644 --- a/src/main/java/org/spdx/library/model/ModelSet.java +++ b/src/main/java/org/spdx/library/model/ModelSet.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.PropertyDescriptor; diff --git a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java new file mode 100644 index 000000000..80c19295f --- /dev/null +++ b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; + +/** + * Concrete subclass of ModelObject for testing purposes + * + * @author Gary O'Neall + * + */ +public class ModelObjectForTesting extends ModelObject { + + public static final String TYPE = "ModelObjectForTesting"; + + /** + * @throws InvalidSPDXAnalysisException + */ + public ModelObjectForTesting() throws InvalidSPDXAnalysisException { + super(); + } + + /** + * @param objectUri + * @throws InvalidSPDXAnalysisException + */ + public ModelObjectForTesting(String objectUri) + throws InvalidSPDXAnalysisException { + super(objectUri); + } + + /** + * @param modelStore + * @param objectUri + * @param copyManager + * @param create + * @throws InvalidSPDXAnalysisException + */ + public ModelObjectForTesting(IModelStore modelStore, String objectUri, + ModelCopyManager copyManager, boolean create) + throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * @param builder + * @throws InvalidSPDXAnalysisException + */ + public ModelObjectForTesting(ModelObjectBuilder builder) + throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return TYPE; + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.Set, java.lang.String, java.util.List) + */ + @Override + protected List _verify(Set verifiedElementIds, + String specVersion, List profiles) { + return new ArrayList(); + } + + public static class ModelObjectForTestingBuilder extends ModelObjectBuilder { + + /** + * Create an ElementBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ModelObjectForTestingBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ElementBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ModelObjectForTestingBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + setExternalMap(from.externalMap); + } + + /** + * Creates a ElementBuilder + * @param modelStore model store for the built Element + * @param objectUri objectUri for the built Element + * @param copyManager optional copyManager for the built Element + */ + public ModelObjectForTestingBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + } + +} diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/ModelObjectTest.java index 5b10ec439..210f34f38 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/ModelObjectTest.java @@ -17,6 +17,29 @@ */ package org.spdx.library.model; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.ModelObjectForTesting.ModelObjectForTestingBuilder; +import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.core.HashAlgorithm; +import org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet; +import org.spdx.library.model.licensing.AnyLicenseInfo; +import org.spdx.library.model.licensing.CustomLicense; +import org.spdx.library.model.licensing.ListedLicense; +import org.spdx.library.model.licensing.ListedLicenseException; +import org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.simple.InMemSpdxStore; + import junit.framework.TestCase; /** @@ -24,12 +47,142 @@ * */ public class ModelObjectTest extends TestCase { + + private static final String TEST_OBJECT_URI = "https://spdx.test/testId"; + private static final String TEST_OBJECT_URI2 = "https://spdx.test/testId2"; + private static final Object TEST_VALUE1 = "value1"; + private static final PropertyDescriptor TEST_PROPERTY1 = new PropertyDescriptor("property1", SpdxConstants.CORE_NAMESPACE); + private static final PropertyDescriptor TEST_PROPERTY2 = new PropertyDescriptor("property2", SpdxConstants.CORE_NAMESPACE); + static final String TEST_TYPE1 = "Core.Element"; + static final String TEST_TYPE2 = "Core.Annotation"; + + static final String EXTERNAL_ID1 = "http://externalMap1"; + static final String EXTERNAL_DEFINING_DOCUMENT1 = "http://externalDoc1"; + static final String EXTERNAL_ID2 = "http://externalMap2"; + static final String EXTERNAL_DEFINING_DOCUMENT2 = "http://externalDoc2"; + + static final PropertyDescriptor[] TEST_STRING_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("valueProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("valueProp2", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("valueProp3", SpdxConstants.CORE_NAMESPACE)}; + static final Object[] TEST_STRING_VALUE_PROPERTY_VALUES = new Object[] {"value1", "value2", "value3"}; + static final PropertyDescriptor[] TEST_INTEGER_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("intProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("intProp2", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("Intprop3", SpdxConstants.CORE_NAMESPACE)}; + static final Object[] TEST_INTEGER_VALUE_PROPERTY_VALUES = new Object[] {Integer.valueOf(3), Integer.valueOf(0), Integer.valueOf(-1)}; + static final PropertyDescriptor[] TEST_BOOLEAN_VALUE_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("boolProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("boolProp2", SpdxConstants.CORE_NAMESPACE)}; + static final Object[] TEST_BOOLEAN_VALUE_PROPERTY_VALUES = new Object[] {true, false}; + static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("listProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("listProp2", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("listProp3", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("listProp4", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("listProp5", SpdxConstants.CORE_NAMESPACE)}; + static final PropertyDescriptor[] TEST_MODEL_OJBECT_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("typeProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("typeProp2", SpdxConstants.CORE_NAMESPACE)}; + static final PropertyDescriptor[] TEST_ENUM_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("enumProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("enumProp2", SpdxConstants.CORE_NAMESPACE)}; + static final HashAlgorithm[] TEST_ENUM_VALUES = new HashAlgorithm[] {HashAlgorithm.MD5, HashAlgorithm.SHA1}; + static final PropertyDescriptor[] TEST_ANYLICENSEINFO_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("anylicenseProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("anylicenseProp2", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("anylicenseProp3", SpdxConstants.CORE_NAMESPACE)}; + static final PropertyDescriptor[] TEST_ANYLICENSEINFO_LIST_PROPERTIES = new PropertyDescriptor[] { + new PropertyDescriptor("anylicenseListProp1", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("anylicensListProp2", SpdxConstants.CORE_NAMESPACE), + new PropertyDescriptor("anylicenseListProp3", SpdxConstants.CORE_NAMESPACE)}; + + ModelObject[] TEST_MODEL_OBJECT_PROP_VALUES; + List[] TEST_LIST_PROPERTY_VALUES; + AnyLicenseInfo[] TEST_ANYLICENSEINFO_PROP_VALUES; + List[] TEST_ANYLICENSEINFO_LIST_PROP_VALUES; + Map ALL_PROPERTY_VALUES; + + IModelStore store; + ModelCopyManager copyManager; + Map externalMap; + /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); + store = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + externalMap = new HashMap<>(); + externalMap.put(EXTERNAL_ID1, new ExternalMap.ExternalMapBuilder(store, EXTERNAL_ID1, copyManager) + .setDefiningDocument(EXTERNAL_DEFINING_DOCUMENT1) + .setExternalId(EXTERNAL_ID1) + .build()); + externalMap.put(EXTERNAL_ID2, new ExternalMap.ExternalMapBuilder(store, EXTERNAL_ID2, copyManager) + .setDefiningDocument(EXTERNAL_DEFINING_DOCUMENT2) + .setExternalId(EXTERNAL_ID2) + .build()); + ListedLicenseExceptionBuilder llbldr = new ListedLicenseExceptionBuilder(store, "http://spdx.org/licenses/Autoconf-exception-2.0", copyManager); + llbldr.setAdditionText("Autoconf exception 2.0 text"); + llbldr.setName("Autoconf exception 2.0 name"); + ListedLicenseException lex = llbldr.build(); + + CustomLicense eli1 = new CustomLicense(store.getNextId(IdType.LicenseRef, null)); + eli1.setName("eli1"); + eli1.setLicenseText("eli1 text"); + ConjunctiveLicenseSet cls = new ConjunctiveLicenseSet(store, store.getNextId(IdType.Anonymous, null), copyManager, true); + + cls.addMember(new ListedLicense(store, "Apache-2.0", copyManager, true)); + cls.addMember(eli1); + TEST_LIST_PROPERTY_VALUES = new List[] {Arrays.asList("ListItem1", "listItem2", "listItem3"), + Arrays.asList(true, false, true), + Arrays.asList(new ModelObject[] {lex, eli1}), + Arrays.asList(new HashAlgorithm[] {HashAlgorithm.SHA256, HashAlgorithm.SHA1}), + Arrays.asList(new Integer[] {1, 3, 5})}; + TEST_MODEL_OBJECT_PROP_VALUES = new ModelObject[] {lex, eli1}; + TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true), + eli1, new SpdxNoneLicense()}; + TEST_ANYLICENSEINFO_LIST_PROP_VALUES = new List[] {Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "MIT", copyManager, true), + eli1, new ListedLicense(store, "GPL-2.0-only", copyManager, true)}), + Arrays.asList(new AnyLicenseInfo[] {new SpdxNoAssertionLicense()}), + Arrays.asList(new AnyLicenseInfo[] {cls, eli1}) + }; + + ALL_PROPERTY_VALUES = new HashMap<>(); + for (int i = 0; i < TEST_STRING_VALUE_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_STRING_VALUE_PROPERTIES[i], + TEST_STRING_VALUE_PROPERTY_VALUES[i]); + } + for (int i = 0; i < TEST_BOOLEAN_VALUE_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_BOOLEAN_VALUE_PROPERTIES[i], + TEST_BOOLEAN_VALUE_PROPERTY_VALUES[i]); + } + for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_LIST_PROPERTIES[i], + TEST_LIST_PROPERTY_VALUES[i]); + } + for (int i = 0; i < TEST_MODEL_OJBECT_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_MODEL_OJBECT_PROPERTIES[i], + TEST_MODEL_OBJECT_PROP_VALUES[i]); + } + for (int i = 0; i < TEST_ENUM_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_ENUM_PROPERTIES[i], + TEST_ENUM_VALUES[i]); + } + for (int i = 0; i < TEST_ANYLICENSEINFO_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_PROPERTIES[i], + TEST_ANYLICENSEINFO_PROP_VALUES[i]); + } + for (int i = 0; i < TEST_ANYLICENSEINFO_LIST_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_LIST_PROPERTIES[i], + TEST_ANYLICENSEINFO_LIST_PROP_VALUES[i]); + } + for (int i = 0; i < TEST_INTEGER_VALUE_PROPERTIES.length; i++) { + ALL_PROPERTY_VALUES.put(TEST_INTEGER_VALUE_PROPERTIES[i], + TEST_INTEGER_VALUE_PROPERTY_VALUES[i]); + } } /* (non-Javadoc) @@ -40,254 +193,300 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.ModelObject#hashCode()}. + * Test method for {@link org.spdx.library.model.ModelObject#ModelObject(org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager, boolean)}. + * @throws InvalidSPDXAnalysisException */ - public void testHashCode() { - fail("Not yet implemented"); + public void testModelObjectIModelStoreStringModelCopyManagerBoolean() throws InvalidSPDXAnalysisException { + try { + new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, false); + fail("This should not have worked since created is set to false and the ID does not exist"); + } catch (InvalidSPDXAnalysisException ex) { + // expected + } + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + moft.setPropertyValue(TEST_PROPERTY1, TEST_VALUE1); + ModelObjectForTesting moft2 = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, false); + assertTrue(moft2.getStringPropertyValue(TEST_PROPERTY1).isPresent()); + assertEquals(moft2.getStringPropertyValue(TEST_PROPERTY1).get(), TEST_VALUE1); } /** - * Test method for {@link org.spdx.library.model.ModelObject#ModelObject(org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager, boolean)}. + * Test method for {@link org.spdx.library.model.ModelObject#ModelObject(org.spdx.library.mobdel.ModelObjectBuilder)}. */ - public void testModelObjectIModelStoreStringModelCopyManagerBoolean() { - fail("Not yet implemented"); + public void testModelObjectModelObjectBuilder() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + moft.setPropertyValue(TEST_PROPERTY1, TEST_VALUE1); + moft.setExternalMap(externalMap); + ModelObjectForTestingBuilder moftBuilder = new ModelObjectForTestingBuilder(moft, TEST_OBJECT_URI2); + ModelObjectForTesting moft2 = new ModelObjectForTesting(moftBuilder); + assertEquals(moft.getCopyManager(), moft2.getCopyManager()); + assertEquals(moft.getModelStore(), moft2.getModelStore()); + assertEquals(moft.getExternalMap(), moft2.getExternalMap()); + assertFalse(moft2.getStringPropertyValue(TEST_PROPERTY1).isPresent()); + } + + public void testSetExternalMap() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + assertTrue(moft.getExternalMap().isEmpty()); + moft.setExternalMap(externalMap); + assertEquals(externalMap, moft.getExternalMap()); } /** * Test method for {@link org.spdx.library.model.ModelObject#verify(java.lang.String)}. */ - public void testVerifyString() { - fail("Not yet implemented"); + public void testVerifyString() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + assertTrue(moft.verify().isEmpty()); } /** * Test method for {@link org.spdx.library.model.ModelObject#getObjectUri()}. */ - public void testGetObjectUri() { - fail("Not yet implemented"); + public void testGetObjectUri() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + assertEquals(TEST_OBJECT_URI, moft.getObjectUri()); } /** * Test method for {@link org.spdx.library.model.ModelObject#getModelStore()}. */ - public void testGetModelStore() { - fail("Not yet implemented"); + public void testGetModelStore() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + assertEquals(store, moft.getModelStore()); } /** * Test method for {@link org.spdx.library.model.ModelObject#setStrict(boolean)}. */ - public void testSetStrict() { - fail("Not yet implemented"); + public void testSetStrict() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + assertFalse(moft.isStrict()); + moft.setStrict(true); + assertTrue(moft.isStrict()); } /** * Test method for {@link org.spdx.library.model.ModelObject#getPropertyValueDescriptors()}. */ - public void testGetPropertyValueDescriptors() { - fail("Not yet implemented"); + public void testGetPropertyValueDescriptors() throws InvalidSPDXAnalysisException { + ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); + List result = moft.getPropertyValueDescriptors(); + assertEquals(0, result.size()); + addTestValues(moft); + result =moft.getPropertyValueDescriptors(); + assertEquals(ALL_PROPERTY_VALUES.size(), result.size()); + for (PropertyDescriptor property:ALL_PROPERTY_VALUES.keySet()) { + assertTrue(result.contains(property)); + } + } + + protected void addTestValues(ModelObject mo) throws InvalidSPDXAnalysisException { + for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { + mo.setPropertyValue(entry.getKey(), entry.getValue()); + } } /** * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetObjectPropertyValue() { + public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#setPropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ - public void testSetPropertyValue() { + public void testSetPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#updatePropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ - public void testUpdatePropertyValue() { + public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getStringPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetStringPropertyValue() { + public void testGetStringPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getIntegerPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetIntegerPropertyValue() { + public void testGetIntegerPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getEnumPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetEnumPropertyValue() { + public void testGetEnumPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getBooleanPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetBooleanPropertyValue() { + public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetAnyLicenseInfoPropertyValue() { + public void testGetAnyLicenseInfoPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getElementPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetElementPropertyValue() { + public void testGetElementPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#removeProperty(org.spdx.storage.PropertyDescriptor)}. */ - public void testRemoveProperty() { + public void testRemoveProperty() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#updateRemoveProperty(org.spdx.storage.PropertyDescriptor)}. */ - public void testUpdateRemoveProperty() { + public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#clearValueCollection(org.spdx.storage.PropertyDescriptor)}. */ - public void testClearValueCollection() { + public void testClearValueCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#updateClearValueCollection(org.spdx.storage.PropertyDescriptor)}. */ - public void testUpdateClearValueCollection() { + public void testUpdateClearValueCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#addPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ - public void testAddPropertyValueToCollection() { + public void testAddPropertyValueToCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#updateAddPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ - public void testUpdateAddPropertyValueToCollection() { + public void testUpdateAddPropertyValueToCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#removePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ - public void testRemovePropertyValueFromCollection() { + public void testRemovePropertyValueFromCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#updateRemovePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ - public void testUpdateRemovePropertyValueFromCollection() { + public void testUpdateRemovePropertyValueFromCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValueSet(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. */ - public void testGetObjectPropertyValueSet() { + public void testGetObjectPropertyValueSet() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValueCollection(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. */ - public void testGetObjectPropertyValueCollection() { + public void testGetObjectPropertyValueCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getStringCollection(org.spdx.storage.PropertyDescriptor)}. */ - public void testGetStringCollection() { + public void testGetStringCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. */ - public void testIsCollectionMembersAssignableTo() { + public void testIsCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#equivalent(org.spdx.library.model.ModelObject)}. */ - public void testEquivalentModelObject() { + public void testEquivalentModelObject() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#equals(java.lang.Object)}. */ - public void testEqualsObject() { + public void testEqualsObject() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#clone(org.spdx.storage.IModelStore)}. */ - public void testCloneIModelStore() { + public void testCloneIModelStore() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#copyFrom(org.spdx.library.model.ModelObject)}. */ - public void testCopyFrom() { + public void testCopyFrom() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#copyFromV2(org.spdx.library.model.compat.v2.ModelObject)}. */ - public void testCopyFromV2() { + public void testCopyFromV2() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#setCopyManager(org.spdx.library.ModelCopyManager)}. */ - public void testSetCopyManager() { + public void testSetCopyManager() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#getCopyManager()}. */ - public void testGetCopyManager() { + public void testGetCopyManager() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** * Test method for {@link org.spdx.library.model.ModelObject#toTypedValue()}. */ - public void testToTypedValue() { + public void testToTypedValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } diff --git a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java index 388137ed4..e294f4d81 100644 --- a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java +++ b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java @@ -111,5 +111,4 @@ public void testToModelObjectV2() throws InvalidSPDXAnalysisException { public void testToModelObject() throws InvalidSPDXAnalysisException { fail("Unimplemented"); } - } diff --git a/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java b/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java deleted file mode 100644 index 5582ee346..000000000 --- a/src/test/java/org/spdx/library/model/core/AnonymousPayloadTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.AnonymousPayload.AnonymousPayloadBuilder; -import org.spdx.storage.IModelStore; -import org.spdx.storage.simple.InMemSpdxStore; -import org.spdx.utility.compare.UnitTestHelper; - -import junit.framework.TestCase; - -public class AnonymousPayloadTest extends TestCase { - - static final String TEST_OBJECT_URI = "https://test.uri/testuri"; - - - IModelStore modelStore; - ModelCopyManager copyManager; - - - protected void setUp() throws Exception { - super.setUp(); - modelStore = new InMemSpdxStore(); - copyManager = new ModelCopyManager(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public static AnonymousPayloadBuilder builderForAnonymousPayloadTests( - IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AnonymousPayloadBuilder retval = new AnonymousPayloadBuilder(modelStore, objectUri, copyManager) - //TODO: Add in test values - /******************** - ***************/ - ; - return retval; - } - - /** - * Test method for {@link org.spdx.library.model.core.AnonymousPayload#verify()}. - * @throws InvalidSPDXAnalysisException on errors - */ - public void testVerify() throws InvalidSPDXAnalysisException { - AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - List result = testAnonymousPayload.verify(); - assertTrue(result.isEmpty()); - // TODO - add negative tests - } - - /** - * Test method for {@link org.spdx.library.model.core.AnonymousPayload#getType()}. - */ - public void testGetType() throws InvalidSPDXAnalysisException { - AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Core.AnonymousPayload", testAnonymousPayload.getType()); - } - - /** - * Test method for {@link org.spdx.library.model.core.AnonymousPayload#toString()}. - */ - public void testToString() throws InvalidSPDXAnalysisException { - AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("AnonymousPayload: "+TEST_OBJECT_URI, testAnonymousPayload.toString()); - } - - /** - * Test method for {@link org.spdx.library.model.core.AnonymousPayload#Element(org.spdx.library.model.core.AnonymousPayload.AnonymousPayloadBuilder)}. - */ - public void testAnonymousPayloadAnonymousPayloadBuilder() throws InvalidSPDXAnalysisException { - builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - } - - public void testEquivalent() throws InvalidSPDXAnalysisException { - AnonymousPayload testAnonymousPayload = builderForAnonymousPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - AnonymousPayload test2AnonymousPayload = builderForAnonymousPayloadTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); - assertTrue(testAnonymousPayload.equivalent(test2AnonymousPayload)); - assertTrue(test2AnonymousPayload.equivalent(testAnonymousPayload)); - // TODO change some parameters for negative tests - } -} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java b/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java deleted file mode 100644 index ce0d4f681..000000000 --- a/src/test/java/org/spdx/library/model/core/NamespaceMapTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.NamespaceMap.NamespaceMapBuilder; -import org.spdx.storage.IModelStore; -import org.spdx.storage.simple.InMemSpdxStore; -import org.spdx.utility.compare.UnitTestHelper; - -import junit.framework.TestCase; - -public class NamespaceMapTest extends TestCase { - - static final String TEST_OBJECT_URI = "https://test.uri/testuri"; - - - IModelStore modelStore; - ModelCopyManager copyManager; - - static final String PREFIX_TEST_VALUE = "test prefix"; - static final String NAMESPACE_TEST_VALUE = "test namespace"; - - protected void setUp() throws Exception { - super.setUp(); - modelStore = new InMemSpdxStore(); - copyManager = new ModelCopyManager(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public static NamespaceMapBuilder builderForNamespaceMapTests( - IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - NamespaceMapBuilder retval = new NamespaceMapBuilder(modelStore, objectUri, copyManager) - .setPrefix(PREFIX_TEST_VALUE) - .setNamespace(NAMESPACE_TEST_VALUE) - //TODO: Add in test values - /******************** - ***************/ - ; - return retval; - } - - /** - * Test method for {@link org.spdx.library.model.core.NamespaceMap#verify()}. - * @throws InvalidSPDXAnalysisException on errors - */ - public void testVerify() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - List result = testNamespaceMap.verify(); - assertTrue(result.isEmpty()); - // TODO - add negative tests - } - - /** - * Test method for {@link org.spdx.library.model.core.NamespaceMap#getType()}. - */ - public void testGetType() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Core.NamespaceMap", testNamespaceMap.getType()); - } - - /** - * Test method for {@link org.spdx.library.model.core.NamespaceMap#toString()}. - */ - public void testToString() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("NamespaceMap: "+TEST_OBJECT_URI, testNamespaceMap.toString()); - } - - /** - * Test method for {@link org.spdx.library.model.core.NamespaceMap#Element(org.spdx.library.model.core.NamespaceMap.NamespaceMapBuilder)}. - */ - public void testNamespaceMapNamespaceMapBuilder() throws InvalidSPDXAnalysisException { - builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - } - - public void testEquivalent() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - NamespaceMap test2NamespaceMap = builderForNamespaceMapTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); - assertTrue(testNamespaceMap.equivalent(test2NamespaceMap)); - assertTrue(test2NamespaceMap.equivalent(testNamespaceMap)); - // TODO change some parameters for negative tests - } - - /** - * Test method for {@link org.spdx.library.model.core.NamespaceMap#setPrefix}. - */ - public void testNamespaceMapsetPrefix() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(PREFIX_TEST_VALUE, testNamespaceMap.getPrefix()); - testNamespaceMap.setPrefix("new prefix value"); - assertEquals("new prefix value", testNamespaceMap.getPrefix()); - } - - /** - * Test method for {@link org.spdx.library.model.core.NamespaceMap#setNamespace}. - */ - public void testNamespaceMapsetNamespace() throws InvalidSPDXAnalysisException { - NamespaceMap testNamespaceMap = builderForNamespaceMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(NAMESPACE_TEST_VALUE, testNamespaceMap.getNamespace()); - testNamespaceMap.setNamespace("new namespace value"); - assertEquals("new namespace value", testNamespaceMap.getNamespace()); - } -} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/PayloadTest.java b/src/test/java/org/spdx/library/model/core/PayloadTest.java deleted file mode 100644 index b04cf3290..000000000 --- a/src/test/java/org/spdx/library/model/core/PayloadTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Payload.PayloadBuilder; -import org.spdx.storage.IModelStore; -import org.spdx.storage.simple.InMemSpdxStore; -import org.spdx.utility.compare.UnitTestHelper; - -import junit.framework.TestCase; - -public class PayloadTest extends TestCase { - - static final String TEST_OBJECT_URI = "https://test.uri/testuri"; - - - IModelStore modelStore; - ModelCopyManager copyManager; - - - protected void setUp() throws Exception { - super.setUp(); - modelStore = new InMemSpdxStore(); - copyManager = new ModelCopyManager(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public static PayloadBuilder builderForPayloadTests( - IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - PayloadBuilder retval = new PayloadBuilder(modelStore, objectUri, copyManager) - //TODO: Add in test values - /******************** - .setCreationInfo(new CreationInfo()) - .addNamespaces(NamespaceMap) - .addImports(ExternalMap) - ***************/ - ; - return retval; - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#verify()}. - * @throws InvalidSPDXAnalysisException on errors - */ - public void testVerify() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - List result = testPayload.verify(); - assertTrue(result.isEmpty()); - // TODO - add negative tests - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#getType()}. - */ - public void testGetType() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Core.Payload", testPayload.getType()); - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#toString()}. - */ - public void testToString() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Payload: "+TEST_OBJECT_URI, testPayload.toString()); - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#Element(org.spdx.library.model.core.Payload.PayloadBuilder)}. - */ - public void testPayloadPayloadBuilder() throws InvalidSPDXAnalysisException { - builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - } - - public void testEquivalent() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - Payload test2Payload = builderForPayloadTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); - assertTrue(testPayload.equivalent(test2Payload)); - assertTrue(test2Payload.equivalent(testPayload)); - // TODO change some parameters for negative tests - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#setCreationInfo}. - */ - public void testPayloadsetCreationInfo() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testPayload.getCreationInfo()); -// testPayload.setCreationInfo(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testPayload.getCreationInfo()); - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#getNamespaces}. - */ - public void testPayloadgetNamespacess() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getNamespacess()))); -// testPayload.getNamespacess().clear(); -// testPayload.getNamespacess().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getNamespacess()))); - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.core.Payload#getImports}. - */ - public void testPayloadgetImportss() throws InvalidSPDXAnalysisException { - Payload testPayload = builderForPayloadTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testPayload.getImportss()))); -// testPayload.getImportss().clear(); -// testPayload.getImportss().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testPayload.getImportss()))); - fail("Not yet implemented"); - } -} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java similarity index 89% rename from src/test/java/org/spdx/library/model/ai/AIPackageTest.java rename to src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java index 7b0e1d9f6..9522cc578 100644 --- a/src/test/java/org/spdx/library/model/ai/AIPackageTest.java +++ b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.ai; +package org.spdx.library.model.v3.ai; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.ai.AIPackage.AIPackageBuilder; +import org.spdx.library.model.v3.ai.AIPackage.AIPackageBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,41 +42,41 @@ public class AIPackageTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String INFORMATION_ABOUT_TRAINING_TEST_VALUE = "test informationAboutTraining"; static final String LIMITATION_TEST_VALUE = "test limitation"; static final String ENERGY_CONSUMPTION_TEST_VALUE = "test energyConsumption"; static final String INFORMATION_ABOUT_APPLICATION_TEST_VALUE = "test informationAboutApplication"; + static final String INFORMATION_ABOUT_TRAINING_TEST_VALUE = "test informationAboutTraining"; static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1 = PresenceType.values()[0]; static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2 = PresenceType.values()[1]; static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE1 = SafetyRiskAssessmentType.values()[0]; static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE2 = SafetyRiskAssessmentType.values()[1]; static final PresenceType AUTONOMY_TYPE_TEST_VALUE1 = PresenceType.values()[0]; static final PresenceType AUTONOMY_TYPE_TEST_VALUE2 = PresenceType.values()[1]; - static final String DOMAIN_TEST_VALUE1 = "test 1 domain"; - static final String DOMAIN_TEST_VALUE2 = "test 2 domain"; - static final String DOMAIN_TEST_VALUE3 = "test 3 domain"; - static final List DOMAIN_TEST_LIST1 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE1, DOMAIN_TEST_VALUE2 }); - static final List DOMAIN_TEST_LIST2 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE3 }); - static final String STANDARD_COMPLIANCE_TEST_VALUE1 = "test 1 standardCompliance"; - static final String STANDARD_COMPLIANCE_TEST_VALUE2 = "test 2 standardCompliance"; - static final String STANDARD_COMPLIANCE_TEST_VALUE3 = "test 3 standardCompliance"; - static final List STANDARD_COMPLIANCE_TEST_LIST1 = Arrays.asList(new String[] { STANDARD_COMPLIANCE_TEST_VALUE1, STANDARD_COMPLIANCE_TEST_VALUE2 }); - static final List STANDARD_COMPLIANCE_TEST_LIST2 = Arrays.asList(new String[] { STANDARD_COMPLIANCE_TEST_VALUE3 }); - static final String MODEL_DATA_PREPROCESSING_TEST_VALUE1 = "test 1 modelDataPreprocessing"; - static final String MODEL_DATA_PREPROCESSING_TEST_VALUE2 = "test 2 modelDataPreprocessing"; - static final String MODEL_DATA_PREPROCESSING_TEST_VALUE3 = "test 3 modelDataPreprocessing"; - static final List MODEL_DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE1, MODEL_DATA_PREPROCESSING_TEST_VALUE2 }); - static final List MODEL_DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE3 }); static final String TYPE_OF_MODEL_TEST_VALUE1 = "test 1 typeOfModel"; static final String TYPE_OF_MODEL_TEST_VALUE2 = "test 2 typeOfModel"; static final String TYPE_OF_MODEL_TEST_VALUE3 = "test 3 typeOfModel"; static final List TYPE_OF_MODEL_TEST_LIST1 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE1, TYPE_OF_MODEL_TEST_VALUE2 }); static final List TYPE_OF_MODEL_TEST_LIST2 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE3 }); + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE1 = "test 1 modelDataPreprocessing"; + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE2 = "test 2 modelDataPreprocessing"; + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE3 = "test 3 modelDataPreprocessing"; + static final List MODEL_DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE1, MODEL_DATA_PREPROCESSING_TEST_VALUE2 }); + static final List MODEL_DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE3 }); + static final String STANDARD_COMPLIANCE_TEST_VALUE1 = "test 1 standardCompliance"; + static final String STANDARD_COMPLIANCE_TEST_VALUE2 = "test 2 standardCompliance"; + static final String STANDARD_COMPLIANCE_TEST_VALUE3 = "test 3 standardCompliance"; + static final List STANDARD_COMPLIANCE_TEST_LIST1 = Arrays.asList(new String[] { STANDARD_COMPLIANCE_TEST_VALUE1, STANDARD_COMPLIANCE_TEST_VALUE2 }); + static final List STANDARD_COMPLIANCE_TEST_LIST2 = Arrays.asList(new String[] { STANDARD_COMPLIANCE_TEST_VALUE3 }); static final String MODEL_EXPLAINABILITY_TEST_VALUE1 = "test 1 modelExplainability"; static final String MODEL_EXPLAINABILITY_TEST_VALUE2 = "test 2 modelExplainability"; static final String MODEL_EXPLAINABILITY_TEST_VALUE3 = "test 3 modelExplainability"; static final List MODEL_EXPLAINABILITY_TEST_LIST1 = Arrays.asList(new String[] { MODEL_EXPLAINABILITY_TEST_VALUE1, MODEL_EXPLAINABILITY_TEST_VALUE2 }); static final List MODEL_EXPLAINABILITY_TEST_LIST2 = Arrays.asList(new String[] { MODEL_EXPLAINABILITY_TEST_VALUE3 }); + static final String DOMAIN_TEST_VALUE1 = "test 1 domain"; + static final String DOMAIN_TEST_VALUE2 = "test 2 domain"; + static final String DOMAIN_TEST_VALUE3 = "test 3 domain"; + static final List DOMAIN_TEST_LIST1 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE1, DOMAIN_TEST_VALUE2 }); + static final List DOMAIN_TEST_LIST2 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE3 }); protected void setUp() throws Exception { super.setUp(); @@ -91,35 +91,35 @@ protected void tearDown() throws Exception { public static AIPackageBuilder builderForAIPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager) - .setInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) .setLimitation(LIMITATION_TEST_VALUE) .setEnergyConsumption(ENERGY_CONSUMPTION_TEST_VALUE) .setInformationAboutApplication(INFORMATION_ABOUT_APPLICATION_TEST_VALUE) - .addDomain(DOMAIN_TEST_VALUE1) - .addDomain(DOMAIN_TEST_VALUE2) - .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) - .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE2) - .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) - .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) + .setInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE1) .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) + .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) + .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) + .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) + .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE2) .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE1) .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE2) + .addDomain(DOMAIN_TEST_VALUE1) + .addDomain(DOMAIN_TEST_VALUE2) .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) .setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE1) .setAutonomyType(AUTONOMY_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .addMetric(DictionaryEntry) .addHyperparameter(DictionaryEntry) .addMetricDecisionThreshold(DictionaryEntry) + .addMetric(DictionaryEntry) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#verify()}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -130,7 +130,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getType()}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -138,7 +138,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#toString()}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -146,7 +146,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#Element(org.spdx.library.model.ai.AIPackage.AIPackageBuilder)}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#Element(org.spdx.library.model.v3.ai.AIPackage.AIPackageBuilder)}. */ public void testAIPackageAIPackageBuilder() throws InvalidSPDXAnalysisException { builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -161,7 +161,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setSensitivePersonalInformation}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSensitivePersonalInformation}. */ public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -171,7 +171,7 @@ public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAna } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setSafetyRiskAssessment}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSafetyRiskAssessment}. */ public void testAIPackagesetSafetyRiskAssessment() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -181,7 +181,7 @@ public void testAIPackagesetSafetyRiskAssessment() throws InvalidSPDXAnalysisExc } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setAutonomyType}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setAutonomyType}. */ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -191,17 +191,7 @@ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setInformationAboutTraining}. - */ - public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(INFORMATION_ABOUT_TRAINING_TEST_VALUE), testAIPackage.getInformationAboutTraining()); - testAIPackage.setInformationAboutTraining("new informationAboutTraining value"); - assertEquals(Optional.of("new informationAboutTraining value"), testAIPackage.getInformationAboutTraining()); - } - - /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setLimitation}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setLimitation}. */ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -211,7 +201,7 @@ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setEnergyConsumption}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setEnergyConsumption}. */ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -221,7 +211,7 @@ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisExcept } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#setInformationAboutApplication}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setInformationAboutApplication}. */ public void testAIPackagesetInformationAboutApplication() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -231,19 +221,17 @@ public void testAIPackagesetInformationAboutApplication() throws InvalidSPDXAnal } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getMetric}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setInformationAboutTraining}. */ - public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { + public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); -// testAIPackage.getMetrics().clear(); -// testAIPackage.getMetrics().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); - fail("Not yet implemented"); + assertEquals(Optional.of(INFORMATION_ABOUT_TRAINING_TEST_VALUE), testAIPackage.getInformationAboutTraining()); + testAIPackage.setInformationAboutTraining("new informationAboutTraining value"); + assertEquals(Optional.of("new informationAboutTraining value"), testAIPackage.getInformationAboutTraining()); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getHyperparameter}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getHyperparameter}. */ public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -255,7 +243,7 @@ public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisExceptio } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getMetricDecisionThreshold}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getMetricDecisionThreshold}. */ public void testAIPackagegetMetricDecisionThresholds() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -267,29 +255,30 @@ public void testAIPackagegetMetricDecisionThresholds() throws InvalidSPDXAnalysi } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getDomains}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getMetric}. */ - public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { + public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getDomains()))); - testAIPackage.getDomains().clear(); - testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); +// testAIPackage.getMetrics().clear(); +// testAIPackage.getMetrics().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getStandardCompliances}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getTypeOfModels}. */ - public void testAIPackagegetStandardCompliances() throws InvalidSPDXAnalysisException { + public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST1, new ArrayList<>(testAIPackage.getStandardCompliances()))); - testAIPackage.getStandardCompliances().clear(); - testAIPackage.getStandardCompliances().addAll(STANDARD_COMPLIANCE_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST2, new ArrayList<>(testAIPackage.getStandardCompliances()))); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getTypeOfModels()))); + testAIPackage.getTypeOfModels().clear(); + testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelDataPreprocessings}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getModelDataPreprocessings}. */ public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -300,18 +289,18 @@ public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysis } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getTypeOfModels}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getStandardCompliances}. */ - public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { + public void testAIPackagegetStandardCompliances() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getTypeOfModels()))); - testAIPackage.getTypeOfModels().clear(); - testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST1, new ArrayList<>(testAIPackage.getStandardCompliances()))); + testAIPackage.getStandardCompliances().clear(); + testAIPackage.getStandardCompliances().addAll(STANDARD_COMPLIANCE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST2, new ArrayList<>(testAIPackage.getStandardCompliances()))); } /** - * Test method for {@link org.spdx.library.model.ai.AIPackage#getModelExplainabilitys}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getModelExplainabilitys}. */ public void testAIPackagegetModelExplainabilitys() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -320,4 +309,15 @@ public void testAIPackagegetModelExplainabilitys() throws InvalidSPDXAnalysisExc testAIPackage.getModelExplainabilitys().addAll(MODEL_EXPLAINABILITY_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST2, new ArrayList<>(testAIPackage.getModelExplainabilitys()))); } + + /** + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getDomains}. + */ + public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getDomains()))); + testAIPackage.getDomains().clear(); + testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/build/BuildTest.java b/src/test/java/org/spdx/library/model/v3/build/BuildTest.java similarity index 82% rename from src/test/java/org/spdx/library/model/build/BuildTest.java rename to src/test/java/org/spdx/library/model/v3/build/BuildTest.java index 4a57ee5c5..edf382087 100644 --- a/src/test/java/org/spdx/library/model/build/BuildTest.java +++ b/src/test/java/org/spdx/library/model/v3/build/BuildTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.build; +package org.spdx.library.model.v3.build; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.build.Build.BuildBuilder; +import org.spdx.library.model.v3.build.Build.BuildBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,20 +42,18 @@ public class BuildTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String BUILD_END_TIME_TEST_VALUE = "test buildEndTime"; static final String BUILD_TYPE_TEST_VALUE = "test buildType"; - static final String BUILD_START_TIME_TEST_VALUE = "test buildStartTime"; static final String BUILD_ID_TEST_VALUE = "test buildId"; - static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1 = "test 1 configSourceEntrypoint"; - static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2 = "test 2 configSourceEntrypoint"; - static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE3 = "test 3 configSourceEntrypoint"; - static final List CONFIG_SOURCE_ENTRYPOINT_TEST_LIST1 = Arrays.asList(new String[] { CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1, CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2 }); - static final List CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2 = Arrays.asList(new String[] { CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE3 }); static final String CONFIG_SOURCE_URI_TEST_VALUE1 = "test 1 configSourceUri"; static final String CONFIG_SOURCE_URI_TEST_VALUE2 = "test 2 configSourceUri"; static final String CONFIG_SOURCE_URI_TEST_VALUE3 = "test 3 configSourceUri"; static final List CONFIG_SOURCE_URI_TEST_LIST1 = Arrays.asList(new String[] { CONFIG_SOURCE_URI_TEST_VALUE1, CONFIG_SOURCE_URI_TEST_VALUE2 }); static final List CONFIG_SOURCE_URI_TEST_LIST2 = Arrays.asList(new String[] { CONFIG_SOURCE_URI_TEST_VALUE3 }); + static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1 = "test 1 configSourceEntrypoint"; + static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2 = "test 2 configSourceEntrypoint"; + static final String CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE3 = "test 3 configSourceEntrypoint"; + static final List CONFIG_SOURCE_ENTRYPOINT_TEST_LIST1 = Arrays.asList(new String[] { CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1, CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2 }); + static final List CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2 = Arrays.asList(new String[] { CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE3 }); protected void setUp() throws Exception { super.setUp(); @@ -70,18 +68,18 @@ protected void tearDown() throws Exception { public static BuildBuilder builderForBuildTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { BuildBuilder retval = new BuildBuilder(modelStore, objectUri, copyManager) - .setBuildEndTime(BUILD_END_TIME_TEST_VALUE) .setBuildType(BUILD_TYPE_TEST_VALUE) - .setBuildStartTime(BUILD_START_TIME_TEST_VALUE) .setBuildId(BUILD_ID_TEST_VALUE) - .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1) - .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2) .addConfigSourceUri(CONFIG_SOURCE_URI_TEST_VALUE1) .addConfigSourceUri(CONFIG_SOURCE_URI_TEST_VALUE2) + .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE1) + .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2) //TODO: Add in test values /******************** - .addParameters(DictionaryEntry) + .setBuildEndTime(new DateTime()) + .setBuildStartTime(new DateTime()) .addConfigSourceDigest(Hash) + .addParameters(DictionaryEntry) .addEnvironment(DictionaryEntry) ***************/ ; @@ -89,7 +87,7 @@ public static BuildBuilder builderForBuildTests( } /** - * Test method for {@link org.spdx.library.model.build.Build#verify()}. + * Test method for {@link org.spdx.library.model.v3.build.Build#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -100,7 +98,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.build.Build#getType()}. + * Test method for {@link org.spdx.library.model.v3.build.Build#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +106,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.build.Build#toString()}. + * Test method for {@link org.spdx.library.model.v3.build.Build#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -116,7 +114,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.build.Build#Element(org.spdx.library.model.build.Build.BuildBuilder)}. + * Test method for {@link org.spdx.library.model.v3.build.Build#Element(org.spdx.library.model.v3.build.Build.BuildBuilder)}. */ public void testBuildBuildBuilder() throws InvalidSPDXAnalysisException { builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -131,37 +129,39 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.build.Build#setBuildEndTime}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildEndTime}. */ public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(BUILD_END_TIME_TEST_VALUE), testBuild.getBuildEndTime()); - testBuild.setBuildEndTime("new buildEndTime value"); - assertEquals(Optional.of("new buildEndTime value"), testBuild.getBuildEndTime()); +// assertEquals(Optional.of(TEST_VALUE), testBuild.getBuildEndTime()); +// testBuild.setBuildEndTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testBuild.getBuildEndTime()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.build.Build#setBuildType}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildStartTime}. */ - public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { + public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BUILD_TYPE_TEST_VALUE, testBuild.getBuildType()); - testBuild.setBuildType("new buildType value"); - assertEquals("new buildType value", testBuild.getBuildType()); +// assertEquals(Optional.of(TEST_VALUE), testBuild.getBuildStartTime()); +// testBuild.setBuildStartTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testBuild.getBuildStartTime()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.build.Build#setBuildStartTime}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildType}. */ - public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { + public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(BUILD_START_TIME_TEST_VALUE), testBuild.getBuildStartTime()); - testBuild.setBuildStartTime("new buildStartTime value"); - assertEquals(Optional.of("new buildStartTime value"), testBuild.getBuildStartTime()); + assertEquals(BUILD_TYPE_TEST_VALUE, testBuild.getBuildType()); + testBuild.setBuildType("new buildType value"); + assertEquals("new buildType value", testBuild.getBuildType()); } /** - * Test method for {@link org.spdx.library.model.build.Build#setBuildId}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildId}. */ public void testBuildsetBuildId() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -171,31 +171,31 @@ public void testBuildsetBuildId() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.build.Build#getParameters}. + * Test method for {@link org.spdx.library.model.v3.build.Build#getConfigSourceDigest}. */ - public void testBuildgetParameterss() throws InvalidSPDXAnalysisException { + public void testBuildgetConfigSourceDigests() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getParameterss()))); -// testBuild.getParameterss().clear(); -// testBuild.getParameterss().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getParameterss()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigests()))); +// testBuild.getConfigSourceDigests().clear(); +// testBuild.getConfigSourceDigests().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigests()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceDigest}. + * Test method for {@link org.spdx.library.model.v3.build.Build#getParameters}. */ - public void testBuildgetConfigSourceDigests() throws InvalidSPDXAnalysisException { + public void testBuildgetParameterss() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigests()))); -// testBuild.getConfigSourceDigests().clear(); -// testBuild.getConfigSourceDigests().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getConfigSourceDigests()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getParameterss()))); +// testBuild.getParameterss().clear(); +// testBuild.getParameterss().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getParameterss()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.build.Build#getEnvironment}. + * Test method for {@link org.spdx.library.model.v3.build.Build#getEnvironment}. */ public void testBuildgetEnvironments() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -207,18 +207,7 @@ public void testBuildgetEnvironments() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceEntrypoints}. - */ - public void testBuildgetConfigSourceEntrypoints() throws InvalidSPDXAnalysisException { - Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST1, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); - testBuild.getConfigSourceEntrypoints().clear(); - testBuild.getConfigSourceEntrypoints().addAll(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); - } - - /** - * Test method for {@link org.spdx.library.model.build.Build#getConfigSourceUris}. + * Test method for {@link org.spdx.library.model.v3.build.Build#getConfigSourceUris}. */ public void testBuildgetConfigSourceUris() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -227,4 +216,15 @@ public void testBuildgetConfigSourceUris() throws InvalidSPDXAnalysisException { testBuild.getConfigSourceUris().addAll(CONFIG_SOURCE_URI_TEST_LIST2); assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_URI_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceUris()))); } + + /** + * Test method for {@link org.spdx.library.model.v3.build.Build#getConfigSourceEntrypoints}. + */ + public void testBuildgetConfigSourceEntrypoints() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST1, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); + testBuild.getConfigSourceEntrypoints().clear(); + testBuild.getConfigSourceEntrypoints().addAll(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(CONFIG_SOURCE_ENTRYPOINT_TEST_LIST2, new ArrayList<>(testBuild.getConfigSourceEntrypoints()))); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/AgentTest.java b/src/test/java/org/spdx/library/model/v3/core/AgentTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/AgentTest.java rename to src/test/java/org/spdx/library/model/v3/core/AgentTest.java index 90aed3af1..1a4bad5d1 100644 --- a/src/test/java/org/spdx/library/model/core/AgentTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/AgentTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Agent.AgentBuilder; +import org.spdx.library.model.v3.core.Agent.AgentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static AgentBuilder builderForAgentTests( } /** - * Test method for {@link org.spdx.library.model.core.Agent#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Agent#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Agent#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Agent#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Agent#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Agent#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Agent testAgent = builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Agent#Element(org.spdx.library.model.core.Agent.AgentBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Agent#Element(org.spdx.library.model.v3.core.Agent.AgentBuilder)}. */ public void testAgentAgentBuilder() throws InvalidSPDXAnalysisException { builderForAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/AnnotationTest.java b/src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java similarity index 77% rename from src/test/java/org/spdx/library/model/core/AnnotationTest.java rename to src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java index c54550e02..11f83e0d8 100644 --- a/src/test/java/org/spdx/library/model/core/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Annotation.AnnotationBuilder; +import org.spdx.library.model.v3.core.Annotation.AnnotationBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -63,14 +63,15 @@ public static AnnotationBuilder builderForAnnotationTests( .setAnnotationType(ANNOTATION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setSubject(Element testElement) + .setSubject(new Element()) + .addContentType(MediaType) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.core.Annotation#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -81,7 +82,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Annotation#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -89,7 +90,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Annotation#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -97,7 +98,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Annotation#Element(org.spdx.library.model.core.Annotation.AnnotationBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#Element(org.spdx.library.model.v3.core.Annotation.AnnotationBuilder)}. */ public void testAnnotationAnnotationBuilder() throws InvalidSPDXAnalysisException { builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -112,7 +113,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Annotation#setSubject}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#setSubject}. */ public void testAnnotationsetSubject() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -123,7 +124,7 @@ public void testAnnotationsetSubject() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Annotation#setAnnotationType}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#setAnnotationType}. */ public void testAnnotationsetAnnotationType() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -133,7 +134,7 @@ public void testAnnotationsetAnnotationType() throws InvalidSPDXAnalysisExceptio } /** - * Test method for {@link org.spdx.library.model.core.Annotation#setStatement}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#setStatement}. */ public void testAnnotationsetStatement() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -141,4 +142,16 @@ public void testAnnotationsetStatement() throws InvalidSPDXAnalysisException { testAnnotation.setStatement("new statement value"); assertEquals(Optional.of("new statement value"), testAnnotation.getStatement()); } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Annotation#getContentType}. + */ + public void testAnnotationgetContentTypes() throws InvalidSPDXAnalysisException { + Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAnnotation.getContentTypes()))); +// testAnnotation.getContentTypes().clear(); +// testAnnotation.getContentTypes().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAnnotation.getContentTypes()))); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ArtifactTest.java b/src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java similarity index 75% rename from src/test/java/org/spdx/library/model/core/ArtifactTest.java rename to src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java index 86267a02f..017b2c439 100644 --- a/src/test/java/org/spdx/library/model/core/ArtifactTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Artifact.ArtifactBuilder; +import org.spdx.library.model.v3.core.Artifact.ArtifactBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,9 +42,6 @@ public class ArtifactTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String RELEASE_TIME_TEST_VALUE = "test releaseTime"; - static final String VALID_UNTIL_TIME_TEST_VALUE = "test validUntilTime"; - static final String BUILT_TIME_TEST_VALUE = "test builtTime"; static final String STANDARD_TEST_VALUE1 = "test 1 standard"; static final String STANDARD_TEST_VALUE2 = "test 2 standard"; static final String STANDARD_TEST_VALUE3 = "test 3 standard"; @@ -64,22 +61,22 @@ protected void tearDown() throws Exception { public static ArtifactBuilder builderForArtifactTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ArtifactBuilder retval = new ArtifactBuilder(modelStore, objectUri, copyManager) - .setReleaseTime(RELEASE_TIME_TEST_VALUE) - .setValidUntilTime(VALID_UNTIL_TIME_TEST_VALUE) - .setBuiltTime(BUILT_TIME_TEST_VALUE) .addStandard(STANDARD_TEST_VALUE1) .addStandard(STANDARD_TEST_VALUE2) //TODO: Add in test values /******************** - .addOriginatedBy(Agent) + .setValidUntilTime(new DateTime()) + .setReleaseTime(new DateTime()) + .setBuiltTime(new DateTime()) .addSuppliedBy(Agent) + .addOriginatedBy(Agent) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.core.Artifact#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -90,7 +87,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Artifact#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -98,7 +95,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Artifact#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -106,7 +103,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Artifact#Element(org.spdx.library.model.core.Artifact.ArtifactBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#Element(org.spdx.library.model.v3.core.Artifact.ArtifactBuilder)}. */ public void testArtifactArtifactBuilder() throws InvalidSPDXAnalysisException { builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -121,49 +118,40 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Artifact#setReleaseTime}. - */ - public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { - Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(RELEASE_TIME_TEST_VALUE), testArtifact.getReleaseTime()); - testArtifact.setReleaseTime("new releaseTime value"); - assertEquals(Optional.of("new releaseTime value"), testArtifact.getReleaseTime()); - } - - /** - * Test method for {@link org.spdx.library.model.core.Artifact#setValidUntilTime}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#setValidUntilTime}. */ public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(VALID_UNTIL_TIME_TEST_VALUE), testArtifact.getValidUntilTime()); - testArtifact.setValidUntilTime("new validUntilTime value"); - assertEquals(Optional.of("new validUntilTime value"), testArtifact.getValidUntilTime()); +// assertEquals(Optional.of(TEST_VALUE), testArtifact.getValidUntilTime()); +// testArtifact.setValidUntilTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getValidUntilTime()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.Artifact#setBuiltTime}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#setReleaseTime}. */ - public void testArtifactsetBuiltTime() throws InvalidSPDXAnalysisException { + public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(BUILT_TIME_TEST_VALUE), testArtifact.getBuiltTime()); - testArtifact.setBuiltTime("new builtTime value"); - assertEquals(Optional.of("new builtTime value"), testArtifact.getBuiltTime()); +// assertEquals(Optional.of(TEST_VALUE), testArtifact.getReleaseTime()); +// testArtifact.setReleaseTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getReleaseTime()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.Artifact#getOriginatedBy}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#setBuiltTime}. */ - public void testArtifactgetOriginatedBys() throws InvalidSPDXAnalysisException { + public void testArtifactsetBuiltTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBys()))); -// testArtifact.getOriginatedBys().clear(); -// testArtifact.getOriginatedBys().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBys()))); +// assertEquals(Optional.of(TEST_VALUE), testArtifact.getBuiltTime()); +// testArtifact.setBuiltTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getBuiltTime()); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.Artifact#getSuppliedBy}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#getSuppliedBy}. */ public void testArtifactgetSuppliedBys() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -175,7 +163,19 @@ public void testArtifactgetSuppliedBys() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Artifact#getStandards}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#getOriginatedBy}. + */ + public void testArtifactgetOriginatedBys() throws InvalidSPDXAnalysisException { + Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBys()))); +// testArtifact.getOriginatedBys().clear(); +// testArtifact.getOriginatedBys().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getOriginatedBys()))); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Artifact#getStandards}. */ public void testArtifactgetStandards() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/BomTest.java b/src/test/java/org/spdx/library/model/v3/core/BomTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/BomTest.java rename to src/test/java/org/spdx/library/model/v3/core/BomTest.java index 3456d7208..9241b8a61 100644 --- a/src/test/java/org/spdx/library/model/core/BomTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/BomTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Bom.BomBuilder; +import org.spdx.library.model.v3.core.Bom.BomBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static BomBuilder builderForBomTests( } /** - * Test method for {@link org.spdx.library.model.core.Bom#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Bom#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bom#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Bom#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bom#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Bom#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Bom testBom = builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bom#Element(org.spdx.library.model.core.Bom.BomBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Bom#Element(org.spdx.library.model.v3.core.Bom.BomBuilder)}. */ public void testBomBomBuilder() throws InvalidSPDXAnalysisException { builderForBomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/BundleTest.java b/src/test/java/org/spdx/library/model/v3/core/BundleTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/BundleTest.java rename to src/test/java/org/spdx/library/model/v3/core/BundleTest.java index d7c825055..c4dec3092 100644 --- a/src/test/java/org/spdx/library/model/core/BundleTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/BundleTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Bundle.BundleBuilder; +import org.spdx.library.model.v3.core.Bundle.BundleBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -66,7 +66,7 @@ public static BundleBuilder builderForBundleTests( } /** - * Test method for {@link org.spdx.library.model.core.Bundle#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Bundle#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +77,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bundle#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Bundle#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +85,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bundle#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Bundle#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bundle#Element(org.spdx.library.model.core.Bundle.BundleBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Bundle#Element(org.spdx.library.model.v3.core.Bundle.BundleBuilder)}. */ public void testBundleBundleBuilder() throws InvalidSPDXAnalysisException { builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +108,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Bundle#setContext}. + * Test method for {@link org.spdx.library.model.v3.core.Bundle#setContext}. */ public void testBundlesetContext() throws InvalidSPDXAnalysisException { Bundle testBundle = builderForBundleTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/CreationInfoTest.java b/src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java similarity index 62% rename from src/test/java/org/spdx/library/model/core/CreationInfoTest.java rename to src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java index cb35f3f04..f4b9ae75c 100644 --- a/src/test/java/org/spdx/library/model/core/CreationInfoTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.CreationInfo.CreationInfoBuilder; +import org.spdx.library.model.v3.core.CreationInfo.CreationInfoBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,22 +42,8 @@ public class CreationInfoTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String DATA_LICENSE_TEST_VALUE = "test dataLicense"; static final String COMMENT_TEST_VALUE = "test comment"; - static final String CREATED_TEST_VALUE1 = "test 1 created"; - static final String CREATED_TEST_VALUE2 = "test 2 created"; - static final String CREATED_TEST_VALUE3 = "test 3 created"; - static final List CREATED_TEST_LIST1 = Arrays.asList(new String[] { CREATED_TEST_VALUE1, CREATED_TEST_VALUE2 }); - static final List CREATED_TEST_LIST2 = Arrays.asList(new String[] { CREATED_TEST_VALUE3 }); - static final String DATA_LICENSE_TEST_VALUE1 = "test 1 dataLicense"; - static final String DATA_LICENSE_TEST_VALUE2 = "test 2 dataLicense"; - static final String DATA_LICENSE_TEST_VALUE3 = "test 3 dataLicense"; - static final List DATA_LICENSE_TEST_LIST1 = Arrays.asList(new String[] { DATA_LICENSE_TEST_VALUE1, DATA_LICENSE_TEST_VALUE2 }); - static final List DATA_LICENSE_TEST_LIST2 = Arrays.asList(new String[] { DATA_LICENSE_TEST_VALUE3 }); - static final String SPEC_VERSION_TEST_VALUE1 = "test 1 specVersion"; - static final String SPEC_VERSION_TEST_VALUE2 = "test 2 specVersion"; - static final String SPEC_VERSION_TEST_VALUE3 = "test 3 specVersion"; - static final List SPEC_VERSION_TEST_LIST1 = Arrays.asList(new String[] { SPEC_VERSION_TEST_VALUE1, SPEC_VERSION_TEST_VALUE2 }); - static final List SPEC_VERSION_TEST_LIST2 = Arrays.asList(new String[] { SPEC_VERSION_TEST_VALUE3 }); static final ProfileIdentifierType PROFILE_TEST_VALUE1 = ProfileIdentifierType.values()[0]; static final ProfileIdentifierType PROFILE_TEST_VALUE2 = ProfileIdentifierType.values()[1]; static final List PROFILE_TEST_LIST1 = Arrays.asList(new ProfileIdentifierType[] { PROFILE_TEST_VALUE1, PROFILE_TEST_VALUE2 }); @@ -76,26 +62,23 @@ protected void tearDown() throws Exception { public static CreationInfoBuilder builderForCreationInfoTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { CreationInfoBuilder retval = new CreationInfoBuilder(modelStore, objectUri, copyManager) + .setDataLicense(DATA_LICENSE_TEST_VALUE) .setComment(COMMENT_TEST_VALUE) - .addCreated(CREATED_TEST_VALUE1) - .addCreated(CREATED_TEST_VALUE2) - .addDataLicense(DATA_LICENSE_TEST_VALUE1) - .addDataLicense(DATA_LICENSE_TEST_VALUE2) - .addSpecVersion(SPEC_VERSION_TEST_VALUE1) - .addSpecVersion(SPEC_VERSION_TEST_VALUE2) .addProfile(PROFILE_TEST_VALUE1) .addProfile(PROFILE_TEST_VALUE2) //TODO: Add in test values /******************** - .addCreatedUsing(Tool) + .setCreated(new DateTime()) + .setSpecVersion(new SemVer()) .addCreatedBy(Agent) + .addCreatedUsing(Tool) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -106,7 +89,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -114,7 +97,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -122,7 +105,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#Element(org.spdx.library.model.core.CreationInfo.CreationInfoBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#Element(org.spdx.library.model.v3.core.CreationInfo.CreationInfoBuilder)}. */ public void testCreationInfoCreationInfoBuilder() throws InvalidSPDXAnalysisException { builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -137,74 +120,73 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#setComment}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setCreated}. */ - public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { + public void testCreationInfosetCreated() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(COMMENT_TEST_VALUE), testCreationInfo.getComment()); - testCreationInfo.setComment("new comment value"); - assertEquals(Optional.of("new comment value"), testCreationInfo.getComment()); +// assertEquals(Optional.of(TEST_VALUE), testCreationInfo.getCreated()); +// testCreationInfo.setCreated(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testCreationInfo.getCreated()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreatedUsing}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setSpecVersion}. */ - public void testCreationInfogetCreatedUsings() throws InvalidSPDXAnalysisException { + public void testCreationInfosetSpecVersion() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsings()))); -// testCreationInfo.getCreatedUsings().clear(); -// testCreationInfo.getCreatedUsings().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsings()))); +// assertEquals(TEST_VALUE, testCreationInfo.getSpecVersion()); +// testCreationInfo.setSpecVersion(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testCreationInfo.getSpecVersion()); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreatedBy}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setDataLicense}. */ - public void testCreationInfogetCreatedBys() throws InvalidSPDXAnalysisException { + public void testCreationInfosetDataLicense() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBys()))); -// testCreationInfo.getCreatedBys().clear(); -// testCreationInfo.getCreatedBys().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBys()))); - fail("Not yet implemented"); + assertEquals(Optional.of(DATA_LICENSE_TEST_VALUE), testCreationInfo.getDataLicense()); + testCreationInfo.setDataLicense("new dataLicense value"); + assertEquals(Optional.of("new dataLicense value"), testCreationInfo.getDataLicense()); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getCreateds}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setComment}. */ - public void testCreationInfogetCreateds() throws InvalidSPDXAnalysisException { + public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(CREATED_TEST_LIST1, new ArrayList<>(testCreationInfo.getCreateds()))); - testCreationInfo.getCreateds().clear(); - testCreationInfo.getCreateds().addAll(CREATED_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(CREATED_TEST_LIST2, new ArrayList<>(testCreationInfo.getCreateds()))); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testCreationInfo.getComment()); + testCreationInfo.setComment("new comment value"); + assertEquals(Optional.of("new comment value"), testCreationInfo.getComment()); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getDataLicenses}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#getCreatedBy}. */ - public void testCreationInfogetDataLicenses() throws InvalidSPDXAnalysisException { + public void testCreationInfogetCreatedBys() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(DATA_LICENSE_TEST_LIST1, new ArrayList<>(testCreationInfo.getDataLicenses()))); - testCreationInfo.getDataLicenses().clear(); - testCreationInfo.getDataLicenses().addAll(DATA_LICENSE_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(DATA_LICENSE_TEST_LIST2, new ArrayList<>(testCreationInfo.getDataLicenses()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBys()))); +// testCreationInfo.getCreatedBys().clear(); +// testCreationInfo.getCreatedBys().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedBys()))); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getSpecVersions}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#getCreatedUsing}. */ - public void testCreationInfogetSpecVersions() throws InvalidSPDXAnalysisException { + public void testCreationInfogetCreatedUsings() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(SPEC_VERSION_TEST_LIST1, new ArrayList<>(testCreationInfo.getSpecVersions()))); - testCreationInfo.getSpecVersions().clear(); - testCreationInfo.getSpecVersions().addAll(SPEC_VERSION_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(SPEC_VERSION_TEST_LIST2, new ArrayList<>(testCreationInfo.getSpecVersions()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsings()))); +// testCreationInfo.getCreatedUsings().clear(); +// testCreationInfo.getCreatedUsings().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testCreationInfo.getCreatedUsings()))); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.CreationInfo#getProfile}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#getProfile}. */ public void testCreationInfogetProfiles() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java b/src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java rename to src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java index 3f78c32fa..b192195b9 100644 --- a/src/test/java/org/spdx/library/model/core/DictionaryEntryTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.DictionaryEntry.DictionaryEntryBuilder; +import org.spdx.library.model.v3.core.DictionaryEntry.DictionaryEntryBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -68,7 +68,7 @@ public static DictionaryEntryBuilder builderForDictionaryEntryTests( } /** - * Test method for {@link org.spdx.library.model.core.DictionaryEntry#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -79,7 +79,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.DictionaryEntry#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -87,7 +87,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.DictionaryEntry#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -95,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.DictionaryEntry#Element(org.spdx.library.model.core.DictionaryEntry.DictionaryEntryBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#Element(org.spdx.library.model.v3.core.DictionaryEntry.DictionaryEntryBuilder)}. */ public void testDictionaryEntryDictionaryEntryBuilder() throws InvalidSPDXAnalysisException { builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -110,7 +110,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.DictionaryEntry#setKey}. + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#setKey}. */ public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -120,7 +120,7 @@ public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.DictionaryEntry#setValue}. + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#setValue}. */ public void testDictionaryEntrysetValue() throws InvalidSPDXAnalysisException { DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java b/src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java similarity index 76% rename from src/test/java/org/spdx/library/model/core/ElementCollectionTest.java rename to src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java index c52744cf6..5adc3f0d7 100644 --- a/src/test/java/org/spdx/library/model/core/ElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.ElementCollection.ElementCollectionBuilder; +import org.spdx.library.model.v3.core.ElementCollection.ElementCollectionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,15 +58,16 @@ public static ElementCollectionBuilder builderForElementCollectionTests( ElementCollectionBuilder retval = new ElementCollectionBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** - .addElement(Element) + .addImports(ExternalMap) .addRootElement(Element) + .addElement(Element) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.core.ElementCollection#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +78,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ElementCollection#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +86,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ElementCollection#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ElementCollection#Element(org.spdx.library.model.core.ElementCollection.ElementCollectionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#Element(org.spdx.library.model.v3.core.ElementCollection.ElementCollectionBuilder)}. */ public void testElementCollectionElementCollectionBuilder() throws InvalidSPDXAnalysisException { builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,19 +109,19 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ElementCollection#getElement}. + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getImports}. */ - public void testElementCollectiongetElements() throws InvalidSPDXAnalysisException { + public void testElementCollectiongetImportss() throws InvalidSPDXAnalysisException { ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); -// testElementCollection.getElements().clear(); -// testElementCollection.getElements().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getImportss()))); +// testElementCollection.getImportss().clear(); +// testElementCollection.getImportss().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getImportss()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.ElementCollection#getRootElement}. + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getRootElement}. */ public void testElementCollectiongetRootElements() throws InvalidSPDXAnalysisException { ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -130,4 +131,16 @@ public void testElementCollectiongetRootElements() throws InvalidSPDXAnalysisExc // assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); fail("Not yet implemented"); } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getElement}. + */ + public void testElementCollectiongetElements() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); +// testElementCollection.getElements().clear(); +// testElementCollection.getElements().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ElementTest.java b/src/test/java/org/spdx/library/model/v3/core/ElementTest.java similarity index 64% rename from src/test/java/org/spdx/library/model/core/ElementTest.java rename to src/test/java/org/spdx/library/model/v3/core/ElementTest.java index baeda7623..3dc7d6a54 100644 --- a/src/test/java/org/spdx/library/model/core/ElementTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ElementTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Element.ElementBuilder; +import org.spdx.library.model.v3.core.Element.ElementBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,8 @@ public class ElementTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String COMMENT_TEST_VALUE = "test comment"; + static final String NAME_TEST_VALUE = "test name"; static final String DESCRIPTION_TEST_VALUE = "test description"; static final String SUMMARY_TEST_VALUE = "test summary"; @@ -58,19 +60,23 @@ protected void tearDown() throws Exception { public static ElementBuilder builderForElementTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ElementBuilder retval = new ElementBuilder(modelStore, objectUri, copyManager) + .setComment(COMMENT_TEST_VALUE) + .setName(NAME_TEST_VALUE) .setDescription(DESCRIPTION_TEST_VALUE) .setSummary(SUMMARY_TEST_VALUE) //TODO: Add in test values /******************** - .addExternalReference(ExternalReference) + .setCreationInfo(new CreationInfo()) .addExternalIdentifier(ExternalIdentifier) + .addVerifiedUsing(IntegrityMethod) + .addExternalReference(ExternalReference) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.core.Element#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Element#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -81,7 +87,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Element#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Element#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -89,7 +95,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Element#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Element#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -97,7 +103,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Element#Element(org.spdx.library.model.core.Element.ElementBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Element#Element(org.spdx.library.model.v3.core.Element.ElementBuilder)}. */ public void testElementElementBuilder() throws InvalidSPDXAnalysisException { builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -112,7 +118,38 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Element#setDescription}. + * Test method for {@link org.spdx.library.model.v3.core.Element#setCreationInfo}. + */ + public void testElementsetCreationInfo() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testElement.getCreationInfo()); +// testElement.setCreationInfo(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testElement.getCreationInfo()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Element#setComment}. + */ + public void testElementsetComment() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testElement.getComment()); + testElement.setComment("new comment value"); + assertEquals(Optional.of("new comment value"), testElement.getComment()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Element#setName}. + */ + public void testElementsetName() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(NAME_TEST_VALUE), testElement.getName()); + testElement.setName("new name value"); + assertEquals(Optional.of("new name value"), testElement.getName()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Element#setDescription}. */ public void testElementsetDescription() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -122,7 +159,7 @@ public void testElementsetDescription() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Element#setSummary}. + * Test method for {@link org.spdx.library.model.v3.core.Element#setSummary}. */ public void testElementsetSummary() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -132,26 +169,38 @@ public void testElementsetSummary() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Element#getExternalReference}. + * Test method for {@link org.spdx.library.model.v3.core.Element#getExternalIdentifier}. */ - public void testElementgetExternalReferences() throws InvalidSPDXAnalysisException { + public void testElementgetExternalIdentifiers() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); -// testElement.getExternalReferences().clear(); -// testElement.getExternalReferences().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifiers()))); +// testElement.getExternalIdentifiers().clear(); +// testElement.getExternalIdentifiers().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifiers()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.Element#getExternalIdentifier}. + * Test method for {@link org.spdx.library.model.v3.core.Element#getVerifiedUsing}. */ - public void testElementgetExternalIdentifiers() throws InvalidSPDXAnalysisException { + public void testElementgetVerifiedUsings() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifiers()))); -// testElement.getExternalIdentifiers().clear(); -// testElement.getExternalIdentifiers().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalIdentifiers()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getVerifiedUsings()))); +// testElement.getVerifiedUsings().clear(); +// testElement.getVerifiedUsings().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getVerifiedUsings()))); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Element#getExternalReference}. + */ + public void testElementgetExternalReferences() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); +// testElement.getExternalReferences().clear(); +// testElement.getExternalReferences().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java rename to src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java index 711d48430..3d0796697 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalIdentifierTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.ExternalIdentifier.ExternalIdentifierBuilder; +import org.spdx.library.model.v3.core.ExternalIdentifier.ExternalIdentifierBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,9 +42,9 @@ public class ExternalIdentifierTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String ISSUING_AUTHORITY_TEST_VALUE = "test issuingAuthority"; - static final String IDENTIFIER_TEST_VALUE = "test identifier"; static final String COMMENT_TEST_VALUE = "test comment"; + static final String IDENTIFIER_TEST_VALUE = "test identifier"; + static final String ISSUING_AUTHORITY_TEST_VALUE = "test issuingAuthority"; static final ExternalIdentifierType EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1 = ExternalIdentifierType.values()[0]; static final ExternalIdentifierType EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE2 = ExternalIdentifierType.values()[1]; static final String IDENTIFIER_LOCATOR_TEST_VALUE1 = "test 1 identifierLocator"; @@ -66,9 +66,9 @@ protected void tearDown() throws Exception { public static ExternalIdentifierBuilder builderForExternalIdentifierTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ExternalIdentifierBuilder retval = new ExternalIdentifierBuilder(modelStore, objectUri, copyManager) - .setIssuingAuthority(ISSUING_AUTHORITY_TEST_VALUE) - .setIdentifier(IDENTIFIER_TEST_VALUE) .setComment(COMMENT_TEST_VALUE) + .setIdentifier(IDENTIFIER_TEST_VALUE) + .setIssuingAuthority(ISSUING_AUTHORITY_TEST_VALUE) .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE1) .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE2) .setExternalIdentifierType(EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1) @@ -80,7 +80,7 @@ public static ExternalIdentifierBuilder builderForExternalIdentifierTests( } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -91,7 +91,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -99,7 +99,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -107,7 +107,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#Element(org.spdx.library.model.core.ExternalIdentifier.ExternalIdentifierBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#Element(org.spdx.library.model.v3.core.ExternalIdentifier.ExternalIdentifierBuilder)}. */ public void testExternalIdentifierExternalIdentifierBuilder() throws InvalidSPDXAnalysisException { builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -122,7 +122,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setExternalIdentifierType}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setExternalIdentifierType}. */ public void testExternalIdentifiersetExternalIdentifierType() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -132,17 +132,17 @@ public void testExternalIdentifiersetExternalIdentifierType() throws InvalidSPDX } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setIssuingAuthority}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setComment}. */ - public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalysisException { + public void testExternalIdentifiersetComment() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(ISSUING_AUTHORITY_TEST_VALUE), testExternalIdentifier.getIssuingAuthority()); - testExternalIdentifier.setIssuingAuthority("new issuingAuthority value"); - assertEquals(Optional.of("new issuingAuthority value"), testExternalIdentifier.getIssuingAuthority()); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testExternalIdentifier.getComment()); + testExternalIdentifier.setComment("new comment value"); + assertEquals(Optional.of("new comment value"), testExternalIdentifier.getComment()); } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setIdentifier}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setIdentifier}. */ public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -152,17 +152,17 @@ public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#setComment}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setIssuingAuthority}. */ - public void testExternalIdentifiersetComment() throws InvalidSPDXAnalysisException { + public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(COMMENT_TEST_VALUE), testExternalIdentifier.getComment()); - testExternalIdentifier.setComment("new comment value"); - assertEquals(Optional.of("new comment value"), testExternalIdentifier.getComment()); + assertEquals(Optional.of(ISSUING_AUTHORITY_TEST_VALUE), testExternalIdentifier.getIssuingAuthority()); + testExternalIdentifier.setIssuingAuthority("new issuingAuthority value"); + assertEquals(Optional.of("new issuingAuthority value"), testExternalIdentifier.getIssuingAuthority()); } /** - * Test method for {@link org.spdx.library.model.core.ExternalIdentifier#getIdentifierLocators}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#getIdentifierLocators}. */ public void testExternalIdentifiergetIdentifierLocators() throws InvalidSPDXAnalysisException { ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/ExternalMapTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/core/ExternalMapTest.java rename to src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java index 96b0f5bef..810aac1da 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalMapTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.ExternalMap.ExternalMapBuilder; +import org.spdx.library.model.v3.core.ExternalMap.ExternalMapBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,9 +42,9 @@ public class ExternalMapTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String EXTERNAL_ID_TEST_VALUE = "test externalId"; static final String DEFINING_DOCUMENT_TEST_VALUE = "test definingDocument"; static final String LOCATION_HINT_TEST_VALUE = "test locationHint"; - static final String EXTERNAL_ID_TEST_VALUE = "test externalId"; protected void setUp() throws Exception { super.setUp(); @@ -59,9 +59,9 @@ protected void tearDown() throws Exception { public static ExternalMapBuilder builderForExternalMapTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ExternalMapBuilder retval = new ExternalMapBuilder(modelStore, objectUri, copyManager) + .setExternalId(EXTERNAL_ID_TEST_VALUE) .setDefiningDocument(DEFINING_DOCUMENT_TEST_VALUE) .setLocationHint(LOCATION_HINT_TEST_VALUE) - .setExternalId(EXTERNAL_ID_TEST_VALUE) //TODO: Add in test values /******************** .addVerifiedUsing(IntegrityMethod) @@ -71,7 +71,7 @@ public static ExternalMapBuilder builderForExternalMapTests( } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -82,7 +82,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -90,7 +90,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -98,7 +98,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#Element(org.spdx.library.model.core.ExternalMap.ExternalMapBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#Element(org.spdx.library.model.v3.core.ExternalMap.ExternalMapBuilder)}. */ public void testExternalMapExternalMapBuilder() throws InvalidSPDXAnalysisException { builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -113,7 +113,17 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#setDefiningDocument}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setExternalId}. + */ + public void testExternalMapsetExternalId() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(EXTERNAL_ID_TEST_VALUE, testExternalMap.getExternalId()); + testExternalMap.setExternalId("new externalId value"); + assertEquals("new externalId value", testExternalMap.getExternalId()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setDefiningDocument}. */ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -123,7 +133,7 @@ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisExcep } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#setLocationHint}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setLocationHint}. */ public void testExternalMapsetLocationHint() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -133,17 +143,7 @@ public void testExternalMapsetLocationHint() throws InvalidSPDXAnalysisException } /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#setExternalId}. - */ - public void testExternalMapsetExternalId() throws InvalidSPDXAnalysisException { - ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(EXTERNAL_ID_TEST_VALUE, testExternalMap.getExternalId()); - testExternalMap.setExternalId("new externalId value"); - assertEquals("new externalId value", testExternalMap.getExternalId()); - } - - /** - * Test method for {@link org.spdx.library.model.core.ExternalMap#getVerifiedUsing}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#getVerifiedUsing}. */ public void testExternalMapgetVerifiedUsings() throws InvalidSPDXAnalysisException { ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java similarity index 83% rename from src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java rename to src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java index 75b483b30..c0390060f 100644 --- a/src/test/java/org/spdx/library/model/core/ExternalReferenceTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.ExternalReference.ExternalReferenceBuilder; +import org.spdx.library.model.v3.core.ExternalReference.ExternalReferenceBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,7 +42,6 @@ public class ExternalReferenceTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; static final String COMMENT_TEST_VALUE = "test comment"; static final ExternalReferenceType EXTERNAL_REFERENCE_TYPE_TEST_VALUE1 = ExternalReferenceType.values()[0]; static final ExternalReferenceType EXTERNAL_REFERENCE_TYPE_TEST_VALUE2 = ExternalReferenceType.values()[1]; @@ -65,20 +64,20 @@ protected void tearDown() throws Exception { public static ExternalReferenceBuilder builderForExternalReferenceTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ExternalReferenceBuilder retval = new ExternalReferenceBuilder(modelStore, objectUri, copyManager) - .setContentType(CONTENT_TYPE_TEST_VALUE) .setComment(COMMENT_TEST_VALUE) .addLocator(LOCATOR_TEST_VALUE1) .addLocator(LOCATOR_TEST_VALUE2) .setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** + .setContentType(new MediaType()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -89,7 +88,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -97,7 +96,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -105,7 +104,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#Element(org.spdx.library.model.core.ExternalReference.ExternalReferenceBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#Element(org.spdx.library.model.v3.core.ExternalReference.ExternalReferenceBuilder)}. */ public void testExternalReferenceExternalReferenceBuilder() throws InvalidSPDXAnalysisException { builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -120,27 +119,28 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#setExternalReferenceType}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#setContentType}. */ - public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAnalysisException { + public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1), testExternalReference.getExternalReferenceType()); - testExternalReference.setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2); - assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2), testExternalReference.getExternalReferenceType()); +// assertEquals(Optional.of(TEST_VALUE), testExternalReference.getContentType()); +// testExternalReference.setContentType(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testExternalReference.getContentType()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#setContentType}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#setExternalReferenceType}. */ - public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisException { + public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(CONTENT_TYPE_TEST_VALUE), testExternalReference.getContentType()); - testExternalReference.setContentType("new contentType value"); - assertEquals(Optional.of("new contentType value"), testExternalReference.getContentType()); + assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1), testExternalReference.getExternalReferenceType()); + testExternalReference.setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2); + assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2), testExternalReference.getExternalReferenceType()); } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#setComment}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#setComment}. */ public void testExternalReferencesetComment() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -150,7 +150,7 @@ public void testExternalReferencesetComment() throws InvalidSPDXAnalysisExceptio } /** - * Test method for {@link org.spdx.library.model.core.ExternalReference#getLocators}. + * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#getLocators}. */ public void testExternalReferencegetLocators() throws InvalidSPDXAnalysisException { ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/HashTest.java b/src/test/java/org/spdx/library/model/v3/core/HashTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/HashTest.java rename to src/test/java/org/spdx/library/model/v3/core/HashTest.java index baa57276f..bfd1b2754 100644 --- a/src/test/java/org/spdx/library/model/core/HashTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/HashTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Hash.HashBuilder; +import org.spdx.library.model.v3.core.Hash.HashBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -69,7 +69,7 @@ public static HashBuilder builderForHashTests( } /** - * Test method for {@link org.spdx.library.model.core.Hash#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Hash#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -80,7 +80,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Hash#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Hash#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -88,7 +88,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Hash#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Hash#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -96,7 +96,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Hash#Element(org.spdx.library.model.core.Hash.HashBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Hash#Element(org.spdx.library.model.v3.core.Hash.HashBuilder)}. */ public void testHashHashBuilder() throws InvalidSPDXAnalysisException { builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -111,7 +111,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Hash#setAlgorithm}. + * Test method for {@link org.spdx.library.model.v3.core.Hash#setAlgorithm}. */ public void testHashsetAlgorithm() throws InvalidSPDXAnalysisException { Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -121,7 +121,7 @@ public void testHashsetAlgorithm() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Hash#setHashValue}. + * Test method for {@link org.spdx.library.model.v3.core.Hash#setHashValue}. */ public void testHashsetHashValue() throws InvalidSPDXAnalysisException { Hash testHash = builderForHashTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java b/src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java rename to src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java index 892a229f5..b7c2b08ca 100644 --- a/src/test/java/org/spdx/library/model/core/IntegrityMethodTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.IntegrityMethod.IntegrityMethodBuilder; +import org.spdx.library.model.v3.core.IntegrityMethod.IntegrityMethodBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -66,7 +66,7 @@ public static IntegrityMethodBuilder builderForIntegrityMethodTests( } /** - * Test method for {@link org.spdx.library.model.core.IntegrityMethod#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.IntegrityMethod#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +77,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.IntegrityMethod#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.IntegrityMethod#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +85,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.IntegrityMethod#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.IntegrityMethod#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.IntegrityMethod#Element(org.spdx.library.model.core.IntegrityMethod.IntegrityMethodBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.IntegrityMethod#Element(org.spdx.library.model.v3.core.IntegrityMethod.IntegrityMethodBuilder)}. */ public void testIntegrityMethodIntegrityMethodBuilder() throws InvalidSPDXAnalysisException { builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +108,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.IntegrityMethod#setComment}. + * Test method for {@link org.spdx.library.model.v3.core.IntegrityMethod#setComment}. */ public void testIntegrityMethodsetComment() throws InvalidSPDXAnalysisException { IntegrityMethod testIntegrityMethod = builderForIntegrityMethodTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java index 7285ae8d4..c21264007 100644 --- a/src/test/java/org/spdx/library/model/core/LifecycleScopedRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder; +import org.spdx.library.model.v3.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -67,7 +67,7 @@ public static LifecycleScopedRelationshipBuilder builderForLifecycleScopedRelati } /** - * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.LifecycleScopedRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -78,7 +78,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.LifecycleScopedRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -86,7 +86,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.LifecycleScopedRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -94,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#Element(org.spdx.library.model.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.LifecycleScopedRelationship#Element(org.spdx.library.model.v3.core.LifecycleScopedRelationship.LifecycleScopedRelationshipBuilder)}. */ public void testLifecycleScopedRelationshipLifecycleScopedRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -109,7 +109,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.LifecycleScopedRelationship#setScope}. + * Test method for {@link org.spdx.library.model.v3.core.LifecycleScopedRelationship#setScope}. */ public void testLifecycleScopedRelationshipsetScope() throws InvalidSPDXAnalysisException { LifecycleScopedRelationship testLifecycleScopedRelationship = builderForLifecycleScopedRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/OrganizationTest.java b/src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/OrganizationTest.java rename to src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java index a487c3fee..7d610fc4e 100644 --- a/src/test/java/org/spdx/library/model/core/OrganizationTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Organization.OrganizationBuilder; +import org.spdx.library.model.v3.core.Organization.OrganizationBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static OrganizationBuilder builderForOrganizationTests( } /** - * Test method for {@link org.spdx.library.model.core.Organization#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Organization#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Organization#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Organization#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Organization#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Organization#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Organization testOrganization = builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Organization#Element(org.spdx.library.model.core.Organization.OrganizationBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Organization#Element(org.spdx.library.model.v3.core.Organization.OrganizationBuilder)}. */ public void testOrganizationOrganizationBuilder() throws InvalidSPDXAnalysisException { builderForOrganizationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/PersonTest.java b/src/test/java/org/spdx/library/model/v3/core/PersonTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/PersonTest.java rename to src/test/java/org/spdx/library/model/v3/core/PersonTest.java index 77ee1d63e..bd12a4b8f 100644 --- a/src/test/java/org/spdx/library/model/core/PersonTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/PersonTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Person.PersonBuilder; +import org.spdx.library.model.v3.core.Person.PersonBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static PersonBuilder builderForPersonTests( } /** - * Test method for {@link org.spdx.library.model.core.Person#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Person#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Person#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Person#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Person#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Person#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Person testPerson = builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Person#Element(org.spdx.library.model.core.Person.PersonBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Person#Element(org.spdx.library.model.v3.core.Person.PersonBuilder)}. */ public void testPersonPersonBuilder() throws InvalidSPDXAnalysisException { builderForPersonTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java b/src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java rename to src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java index 9ac1f3022..8ca56bf58 100644 --- a/src/test/java/org/spdx/library/model/core/PositiveIntegerRangeTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.PositiveIntegerRange.PositiveIntegerRangeBuilder; +import org.spdx.library.model.v3.core.PositiveIntegerRange.PositiveIntegerRangeBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,8 +42,8 @@ public class PositiveIntegerRangeTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final Integer END_TEST_VALUE = 55; static final Integer BEGIN_TEST_VALUE = 55; + static final Integer END_TEST_VALUE = 55; protected void setUp() throws Exception { super.setUp(); @@ -58,8 +58,8 @@ protected void tearDown() throws Exception { public static PositiveIntegerRangeBuilder builderForPositiveIntegerRangeTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { PositiveIntegerRangeBuilder retval = new PositiveIntegerRangeBuilder(modelStore, objectUri, copyManager) - .setEnd(END_TEST_VALUE) .setBegin(BEGIN_TEST_VALUE) + .setEnd(END_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -68,7 +68,7 @@ public static PositiveIntegerRangeBuilder builderForPositiveIntegerRangeTests( } /** - * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -79,7 +79,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -87,7 +87,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -95,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#Element(org.spdx.library.model.core.PositiveIntegerRange.PositiveIntegerRangeBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#Element(org.spdx.library.model.v3.core.PositiveIntegerRange.PositiveIntegerRangeBuilder)}. */ public void testPositiveIntegerRangePositiveIntegerRangeBuilder() throws InvalidSPDXAnalysisException { builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -110,22 +110,22 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#setEnd}. + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#setBegin}. */ - public void testPositiveIntegerRangesetEnd() throws InvalidSPDXAnalysisException { + public void testPositiveIntegerRangesetBegin() throws InvalidSPDXAnalysisException { PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(END_TEST_VALUE, testPositiveIntegerRange.getEnd()); - testPositiveIntegerRange.setEnd(new Integer(653)); - assertEquals(new Integer(653), testPositiveIntegerRange.getEnd()); + assertEquals(BEGIN_TEST_VALUE, testPositiveIntegerRange.getBegin()); + testPositiveIntegerRange.setBegin(new Integer(653)); + assertEquals(new Integer(653), testPositiveIntegerRange.getBegin()); } /** - * Test method for {@link org.spdx.library.model.core.PositiveIntegerRange#setBegin}. + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#setEnd}. */ - public void testPositiveIntegerRangesetBegin() throws InvalidSPDXAnalysisException { + public void testPositiveIntegerRangesetEnd() throws InvalidSPDXAnalysisException { PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BEGIN_TEST_VALUE, testPositiveIntegerRange.getBegin()); - testPositiveIntegerRange.setBegin(new Integer(653)); - assertEquals(new Integer(653), testPositiveIntegerRange.getBegin()); + assertEquals(END_TEST_VALUE, testPositiveIntegerRange.getEnd()); + testPositiveIntegerRange.setEnd(new Integer(653)); + assertEquals(new Integer(653), testPositiveIntegerRange.getEnd()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/RelationshipTest.java b/src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java similarity index 78% rename from src/test/java/org/spdx/library/model/core/RelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java index 56d68abe8..f21808008 100644 --- a/src/test/java/org/spdx/library/model/core/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Relationship.RelationshipBuilder; +import org.spdx.library.model.v3.core.Relationship.RelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,8 +42,6 @@ public class RelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String START_TIME_TEST_VALUE = "test startTime"; - static final String END_TIME_TEST_VALUE = "test endTime"; static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE1 = RelationshipType.values()[0]; static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE2 = RelationshipType.values()[1]; static final RelationshipCompleteness COMPLETENESS_TEST_VALUE1 = RelationshipCompleteness.values()[0]; @@ -62,13 +60,13 @@ protected void tearDown() throws Exception { public static RelationshipBuilder builderForRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { RelationshipBuilder retval = new RelationshipBuilder(modelStore, objectUri, copyManager) - .setStartTime(START_TIME_TEST_VALUE) - .setEndTime(END_TIME_TEST_VALUE) .setRelationshipType(RELATIONSHIP_TYPE_TEST_VALUE1) .setCompleteness(COMPLETENESS_TEST_VALUE1) //TODO: Add in test values /******************** - .setFrom(Element testElement) + .setEndTime(new DateTime()) + .setFrom(new Element()) + .setStartTime(new DateTime()) .addTo(Element) ***************/ ; @@ -76,7 +74,7 @@ public static RelationshipBuilder builderForRelationshipTests( } /** - * Test method for {@link org.spdx.library.model.core.Relationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -87,7 +85,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Relationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -95,7 +93,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Relationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -103,7 +101,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Relationship#Element(org.spdx.library.model.core.Relationship.RelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#Element(org.spdx.library.model.v3.core.Relationship.RelationshipBuilder)}. */ public void testRelationshipRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -118,7 +116,18 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Relationship#setFrom}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setEndTime}. + */ + public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testRelationship.getEndTime()); +// testRelationship.setEndTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testRelationship.getEndTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setFrom}. */ public void testRelationshipsetFrom() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -129,7 +138,18 @@ public void testRelationshipsetFrom() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Relationship#setRelationshipType}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setStartTime}. + */ + public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testRelationship.getStartTime()); +// testRelationship.setStartTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testRelationship.getStartTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setRelationshipType}. */ public void testRelationshipsetRelationshipType() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -139,7 +159,7 @@ public void testRelationshipsetRelationshipType() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.core.Relationship#setCompleteness}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setCompleteness}. */ public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -149,27 +169,7 @@ public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisExceptio } /** - * Test method for {@link org.spdx.library.model.core.Relationship#setStartTime}. - */ - public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { - Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(START_TIME_TEST_VALUE), testRelationship.getStartTime()); - testRelationship.setStartTime("new startTime value"); - assertEquals(Optional.of("new startTime value"), testRelationship.getStartTime()); - } - - /** - * Test method for {@link org.spdx.library.model.core.Relationship#setEndTime}. - */ - public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { - Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(END_TIME_TEST_VALUE), testRelationship.getEndTime()); - testRelationship.setEndTime("new endTime value"); - assertEquals(Optional.of("new endTime value"), testRelationship.getEndTime()); - } - - /** - * Test method for {@link org.spdx.library.model.core.Relationship#getTo}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#getTo}. */ public void testRelationshipgetTos() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java b/src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java rename to src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java index 8332d662e..73ec5c0a5 100644 --- a/src/test/java/org/spdx/library/model/core/SoftwareAgentTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.SoftwareAgent.SoftwareAgentBuilder; +import org.spdx.library.model.v3.core.SoftwareAgent.SoftwareAgentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static SoftwareAgentBuilder builderForSoftwareAgentTests( } /** - * Test method for {@link org.spdx.library.model.core.SoftwareAgent#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.SoftwareAgent#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.SoftwareAgent#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.SoftwareAgent#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.SoftwareAgent#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.SoftwareAgent#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SoftwareAgent testSoftwareAgent = builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.SoftwareAgent#Element(org.spdx.library.model.core.SoftwareAgent.SoftwareAgentBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.SoftwareAgent#Element(org.spdx.library.model.v3.core.SoftwareAgent.SoftwareAgentBuilder)}. */ public void testSoftwareAgentSoftwareAgentBuilder() throws InvalidSPDXAnalysisException { builderForSoftwareAgentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java similarity index 76% rename from src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java rename to src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java index d6d6fc3b6..398e9bee3 100644 --- a/src/test/java/org/spdx/library/model/core/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.SpdxDocument.SpdxDocumentBuilder; +import org.spdx.library.model.v3.core.SpdxDocument.SpdxDocumentBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,7 @@ public class SpdxDocumentTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String NAME_TEST_VALUE = "test name"; protected void setUp() throws Exception { super.setUp(); @@ -56,6 +57,7 @@ protected void tearDown() throws Exception { public static SpdxDocumentBuilder builderForSpdxDocumentTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SpdxDocumentBuilder retval = new SpdxDocumentBuilder(modelStore, objectUri, copyManager) + .setName(NAME_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -64,7 +66,7 @@ public static SpdxDocumentBuilder builderForSpdxDocumentTests( } /** - * Test method for {@link org.spdx.library.model.core.SpdxDocument#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.SpdxDocument#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +77,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.SpdxDocument#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.SpdxDocument#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +85,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.SpdxDocument#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.SpdxDocument#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.SpdxDocument#Element(org.spdx.library.model.core.SpdxDocument.SpdxDocumentBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.SpdxDocument#Element(org.spdx.library.model.v3.core.SpdxDocument.SpdxDocumentBuilder)}. */ public void testSpdxDocumentSpdxDocumentBuilder() throws InvalidSPDXAnalysisException { builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +106,14 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2SpdxDocument.equivalent(testSpdxDocument)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.core.SpdxDocument#setName}. + */ + public void testSpdxDocumentsetName() throws InvalidSPDXAnalysisException { + SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(NAME_TEST_VALUE), testSpdxDocument.getName()); + testSpdxDocument.setName("new name value"); + assertEquals(Optional.of("new name value"), testSpdxDocument.getName()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/core/ToolTest.java b/src/test/java/org/spdx/library/model/v3/core/ToolTest.java similarity index 87% rename from src/test/java/org/spdx/library/model/core/ToolTest.java rename to src/test/java/org/spdx/library/model/v3/core/ToolTest.java index 38c2c192c..94be2f375 100644 --- a/src/test/java/org/spdx/library/model/core/ToolTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ToolTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.core; +package org.spdx.library.model.v3.core; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.Tool.ToolBuilder; +import org.spdx.library.model.v3.core.Tool.ToolBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static ToolBuilder builderForToolTests( } /** - * Test method for {@link org.spdx.library.model.core.Tool#verify()}. + * Test method for {@link org.spdx.library.model.v3.core.Tool#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Tool#getType()}. + * Test method for {@link org.spdx.library.model.v3.core.Tool#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Tool#toString()}. + * Test method for {@link org.spdx.library.model.v3.core.Tool#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Tool testTool = builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.core.Tool#Element(org.spdx.library.model.core.Tool.ToolBuilder)}. + * Test method for {@link org.spdx.library.model.v3.core.Tool#Element(org.spdx.library.model.v3.core.Tool.ToolBuilder)}. */ public void testToolToolBuilder() throws InvalidSPDXAnalysisException { builderForToolTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/dataset/DatasetTest.java b/src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java similarity index 88% rename from src/test/java/org/spdx/library/model/dataset/DatasetTest.java rename to src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java index f42327fe5..6deeda4e6 100644 --- a/src/test/java/org/spdx/library/model/dataset/DatasetTest.java +++ b/src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.dataset; +package org.spdx.library.model.v3.dataset; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.dataset.Dataset.DatasetBuilder; +import org.spdx.library.model.v3.dataset.Dataset.DatasetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -109,7 +109,7 @@ public static DatasetBuilder builderForDatasetTests( } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#verify()}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -120,7 +120,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getType()}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -128,7 +128,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#toString()}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -136,7 +136,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#Element(org.spdx.library.model.dataset.Dataset.DatasetBuilder)}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#Element(org.spdx.library.model.v3.dataset.Dataset.DatasetBuilder)}. */ public void testDatasetDatasetBuilder() throws InvalidSPDXAnalysisException { builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -151,7 +151,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setSensitivePersonalInformation}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setSensitivePersonalInformation}. */ public void testDatasetsetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -162,7 +162,7 @@ public void testDatasetsetSensitivePersonalInformation() throws InvalidSPDXAnaly } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setConfidentialityLevel}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setConfidentialityLevel}. */ public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -172,7 +172,7 @@ public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisExcep } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetAvailability}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetAvailability}. */ public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -182,7 +182,7 @@ public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisExcept } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetSize}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetSize}. */ public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -192,7 +192,7 @@ public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setIntendedUse}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setIntendedUse}. */ public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -202,7 +202,7 @@ public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetNoise}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetNoise}. */ public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -212,7 +212,7 @@ public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setDataCollectionProcess}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDataCollectionProcess}. */ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -222,7 +222,7 @@ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#setDatasetUpdateMechanism}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetUpdateMechanism}. */ public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -232,7 +232,7 @@ public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisExc } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getSensor}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getSensor}. */ public void testDatasetgetSensors() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -244,7 +244,7 @@ public void testDatasetgetSensors() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getAnonymizationMethodUseds}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getAnonymizationMethodUseds}. */ public void testDatasetgetAnonymizationMethodUseds() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -255,7 +255,7 @@ public void testDatasetgetAnonymizationMethodUseds() throws InvalidSPDXAnalysisE } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getDataPreprocessings}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getDataPreprocessings}. */ public void testDatasetgetDataPreprocessings() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -266,7 +266,7 @@ public void testDatasetgetDataPreprocessings() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getKnownBiass}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getKnownBiass}. */ public void testDatasetgetKnownBiass() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -277,7 +277,7 @@ public void testDatasetgetKnownBiass() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.dataset.Dataset#getDatasetType}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getDatasetType}. */ public void testDatasetgetDatasetTypes() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSetTest.java similarity index 72% rename from src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSetTest.java index c99a13ea6..7b3975b59 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSetTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.expandedlicense; +package org.spdx.library.model.v3.expandedlicense; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder; +import org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,13 +58,14 @@ public static ConjunctiveLicenseSetBuilder builderForConjunctiveLicenseSetTests( ConjunctiveLicenseSetBuilder retval = new ConjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** + .addMember(AnyLicenseInfo) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +76,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +84,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet#Element(org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#Element(org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder)}. */ public void testConjunctiveLicenseSetConjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +105,16 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ConjunctiveLicenseSet.equivalent(testConjunctiveLicenseSet)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#getMember}. + */ + public void testConjunctiveLicenseSetgetMembers() throws InvalidSPDXAnalysisException { + ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testConjunctiveLicenseSet.getMembers()))); +// testConjunctiveLicenseSet.getMembers().clear(); +// testConjunctiveLicenseSet.getMembers().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testConjunctiveLicenseSet.getMembers()))); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSetTest.java similarity index 72% rename from src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSetTest.java index b1eeea727..90f6e2a32 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/DisjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSetTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.expandedlicense; +package org.spdx.library.model.v3.expandedlicense; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder; +import org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,13 +58,14 @@ public static DisjunctiveLicenseSetBuilder builderForDisjunctiveLicenseSetTests( DisjunctiveLicenseSetBuilder retval = new DisjunctiveLicenseSetBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** + .addMember(AnyLicenseInfo) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +76,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +84,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet#Element(org.spdx.library.model.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#Element(org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder)}. */ public void testDisjunctiveLicenseSetDisjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +105,16 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2DisjunctiveLicenseSet.equivalent(testDisjunctiveLicenseSet)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#getMember}. + */ + public void testDisjunctiveLicenseSetgetMembers() throws InvalidSPDXAnalysisException { + DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testDisjunctiveLicenseSet.getMembers()))); +// testDisjunctiveLicenseSet.getMembers().clear(); +// testDisjunctiveLicenseSet.getMembers().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testDisjunctiveLicenseSet.getMembers()))); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java b/src/test/java/org/spdx/library/model/v3/licensing/AnyLicenseInfoTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/AnyLicenseInfoTest.java index f8910fa3c..02d84135b 100644 --- a/src/test/java/org/spdx/library/model/licensing/AnyLicenseInfoTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/AnyLicenseInfoTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder; +import org.spdx.library.model.v3.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static AnyLicenseInfoBuilder builderForAnyLicenseInfoTests( } /** - * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.AnyLicenseInfo#Element(org.spdx.library.model.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#Element(org.spdx.library.model.v3.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder)}. */ public void testAnyLicenseInfoAnyLicenseInfoBuilder() throws InvalidSPDXAnalysisException { builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java b/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseAdditionTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseAdditionTest.java index 7c448b6ca..e1dc4380a 100644 --- a/src/test/java/org/spdx/library/model/licensing/CustomLicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseAdditionTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder; +import org.spdx.library.model.v3.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static CustomLicenseAdditionBuilder builderForCustomLicenseAdditionTests( } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicenseAddition#Element(org.spdx.library.model.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#Element(org.spdx.library.model.v3.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder)}. */ public void testCustomLicenseAdditionCustomLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java b/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseTest.java index 7170de5ad..a7b2c1ee2 100644 --- a/src/test/java/org/spdx/library/model/licensing/CustomLicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.CustomLicense.CustomLicenseBuilder; +import org.spdx.library.model.v3.licensing.CustomLicense.CustomLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static CustomLicenseBuilder builderForCustomLicenseTests( } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicense#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicense#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicense#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.CustomLicense#Element(org.spdx.library.model.licensing.CustomLicense.CustomLicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#Element(org.spdx.library.model.v3.licensing.CustomLicense.CustomLicenseBuilder)}. */ public void testCustomLicenseCustomLicenseBuilder() throws InvalidSPDXAnalysisException { builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java b/src/test/java/org/spdx/library/model/v3/licensing/ExtendableLicenseTest.java similarity index 83% rename from src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/ExtendableLicenseTest.java index fb59258f7..146dc77e5 100644 --- a/src/test/java/org/spdx/library/model/expandedlicense/ExtendableLicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/ExtendableLicenseTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.expandedlicense; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.expandedlicense.ExtendableLicense.ExtendableLicenseBuilder; +import org.spdx.library.model.v3.licensing.ExtendableLicense.ExtendableLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static ExtendableLicenseBuilder builderForExtendableLicenseTests( } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,15 +75,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("ExpandedLicense.ExtendableLicense", testExtendableLicense.getType()); + assertEquals("Licensing.ExtendableLicense", testExtendableLicense.getType()); } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.expandedlicense.ExtendableLicense#Element(org.spdx.library.model.expandedlicense.ExtendableLicense.ExtendableLicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#Element(org.spdx.library.model.v3.licensing.ExtendableLicense.ExtendableLicenseBuilder)}. */ public void testExtendableLicenseExtendableLicenseBuilder() throws InvalidSPDXAnalysisException { builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java b/src/test/java/org/spdx/library/model/v3/licensing/LicenseAdditionTest.java similarity index 77% rename from src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/LicenseAdditionTest.java index b228ed7b5..101774520 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/LicenseAdditionTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.LicenseAddition.LicenseAdditionBuilder; +import org.spdx.library.model.v3.licensing.LicenseAddition.LicenseAdditionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,7 @@ public class LicenseAdditionTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String OBSOLETED_BY_TEST_VALUE = "test obsoletedBy"; static final String STANDARD_ADDITION_TEMPLATE_TEST_VALUE = "test standardAdditionTemplate"; static final String ADDITION_TEXT_TEST_VALUE = "test additionText"; @@ -59,6 +60,7 @@ public static LicenseAdditionBuilder builderForLicenseAdditionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { LicenseAdditionBuilder retval = new LicenseAdditionBuilder(modelStore, objectUri, copyManager) .setIsDeprecatedAdditionId(true) + .setObsoletedBy(OBSOLETED_BY_TEST_VALUE) .setStandardAdditionTemplate(STANDARD_ADDITION_TEMPLATE_TEST_VALUE) .setAdditionText(ADDITION_TEXT_TEST_VALUE) //TODO: Add in test values @@ -69,7 +71,7 @@ public static LicenseAdditionBuilder builderForLicenseAdditionTests( } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -80,7 +82,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -88,7 +90,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -96,7 +98,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#Element(org.spdx.library.model.licensing.LicenseAddition.LicenseAdditionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#Element(org.spdx.library.model.v3.licensing.LicenseAddition.LicenseAdditionBuilder)}. */ public void testLicenseAdditionLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -111,7 +113,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#setIsDeprecatedAdditionId}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setIsDeprecatedAdditionId}. */ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -121,7 +123,17 @@ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAna } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#setStandardAdditionTemplate}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setObsoletedBy}. + */ + public void testLicenseAdditionsetObsoletedBy() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(OBSOLETED_BY_TEST_VALUE), testLicenseAddition.getObsoletedBy()); + testLicenseAddition.setObsoletedBy("new obsoletedBy value"); + assertEquals(Optional.of("new obsoletedBy value"), testLicenseAddition.getObsoletedBy()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setStandardAdditionTemplate}. */ public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -131,7 +143,7 @@ public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXA } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseAddition#setAdditionText}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setAdditionText}. */ public void testLicenseAdditionsetAdditionText() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java b/src/test/java/org/spdx/library/model/v3/licensing/LicenseExpressionTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/LicenseExpressionTest.java index 2d39bdb45..4650600da 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseExpressionTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/LicenseExpressionTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.LicenseExpression.LicenseExpressionBuilder; +import org.spdx.library.model.v3.licensing.LicenseExpression.LicenseExpressionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -66,7 +66,7 @@ public static LicenseExpressionBuilder builderForLicenseExpressionTests( } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +77,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +85,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#Element(org.spdx.library.model.licensing.LicenseExpression.LicenseExpressionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#Element(org.spdx.library.model.v3.licensing.LicenseExpression.LicenseExpressionBuilder)}. */ public void testLicenseExpressionLicenseExpressionBuilder() throws InvalidSPDXAnalysisException { builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +108,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.LicenseExpression#setLicenseExpression}. + * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#setLicenseExpression}. */ public void testLicenseExpressionsetLicenseExpression() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/licensing/LicenseTest.java b/src/test/java/org/spdx/library/model/v3/licensing/LicenseTest.java similarity index 79% rename from src/test/java/org/spdx/library/model/licensing/LicenseTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/LicenseTest.java index cb1bf6db3..55f8327bd 100644 --- a/src/test/java/org/spdx/library/model/licensing/LicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/LicenseTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.License.LicenseBuilder; +import org.spdx.library.model.v3.licensing.License.LicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -43,6 +43,7 @@ public class LicenseTest extends TestCase { ModelCopyManager copyManager; static final String STANDARD_LICENSE_TEMPLATE_TEST_VALUE = "test standardLicenseTemplate"; + static final String OBSOLETED_BY_TEST_VALUE = "test obsoletedBy"; static final String STANDARD_LICENSE_HEADER_TEST_VALUE = "test standardLicenseHeader"; static final String LICENSE_TEXT_TEST_VALUE = "test licenseText"; @@ -60,9 +61,10 @@ public static LicenseBuilder builderForLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { LicenseBuilder retval = new LicenseBuilder(modelStore, objectUri, copyManager) .setIsFsfLibre(true) - .setIsDeprecatedLicenseId(true) .setIsOsiApproved(true) + .setIsDeprecatedLicenseId(true) .setStandardLicenseTemplate(STANDARD_LICENSE_TEMPLATE_TEST_VALUE) + .setObsoletedBy(OBSOLETED_BY_TEST_VALUE) .setStandardLicenseHeader(STANDARD_LICENSE_HEADER_TEST_VALUE) .setLicenseText(LICENSE_TEXT_TEST_VALUE) //TODO: Add in test values @@ -73,7 +75,7 @@ public static LicenseBuilder builderForLicenseTests( } /** - * Test method for {@link org.spdx.library.model.licensing.License#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -84,7 +86,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.License#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -92,7 +94,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.License#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -100,7 +102,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.License#Element(org.spdx.library.model.licensing.License.LicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#Element(org.spdx.library.model.v3.licensing.License.LicenseBuilder)}. */ public void testLicenseLicenseBuilder() throws InvalidSPDXAnalysisException { builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -115,7 +117,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.License#setIsFsfLibre}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#setIsFsfLibre}. */ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -125,27 +127,27 @@ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.License#setIsDeprecatedLicenseId}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#setIsOsiApproved}. */ - public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { + public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(new Boolean(true)), testLicense.getIsDeprecatedLicenseId()); - testLicense.setIsDeprecatedLicenseId(false); - assertEquals(Optional.of(new Boolean(false)), testLicense.getIsDeprecatedLicenseId()); + assertEquals(Optional.of(new Boolean(true)), testLicense.getIsOsiApproved()); + testLicense.setIsOsiApproved(false); + assertEquals(Optional.of(new Boolean(false)), testLicense.getIsOsiApproved()); } /** - * Test method for {@link org.spdx.library.model.licensing.License#setIsOsiApproved}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#setIsDeprecatedLicenseId}. */ - public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { + public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(new Boolean(true)), testLicense.getIsOsiApproved()); - testLicense.setIsOsiApproved(false); - assertEquals(Optional.of(new Boolean(false)), testLicense.getIsOsiApproved()); + assertEquals(Optional.of(new Boolean(true)), testLicense.getIsDeprecatedLicenseId()); + testLicense.setIsDeprecatedLicenseId(false); + assertEquals(Optional.of(new Boolean(false)), testLicense.getIsDeprecatedLicenseId()); } /** - * Test method for {@link org.spdx.library.model.licensing.License#setStandardLicenseTemplate}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#setStandardLicenseTemplate}. */ public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -155,7 +157,17 @@ public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisEx } /** - * Test method for {@link org.spdx.library.model.licensing.License#setStandardLicenseHeader}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#setObsoletedBy}. + */ + public void testLicensesetObsoletedBy() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(OBSOLETED_BY_TEST_VALUE), testLicense.getObsoletedBy()); + testLicense.setObsoletedBy("new obsoletedBy value"); + assertEquals(Optional.of("new obsoletedBy value"), testLicense.getObsoletedBy()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.License#setStandardLicenseHeader}. */ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -165,7 +177,7 @@ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.licensing.License#setLicenseText}. + * Test method for {@link org.spdx.library.model.v3.licensing.License#setLicenseText}. */ public void testLicensesetLicenseText() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java b/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseExceptionTest.java similarity index 62% rename from src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseExceptionTest.java index 4d11b3245..1d73685e6 100644 --- a/src/test/java/org/spdx/library/model/licensing/ListedLicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseExceptionTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; +import org.spdx.library.model.v3.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,8 @@ public class ListedLicenseExceptionTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String DEPRECATED_VERSION_TEST_VALUE = "test deprecatedVersion"; + static final String LIST_VERSION_ADDED_TEST_VALUE = "test listVersionAdded"; protected void setUp() throws Exception { super.setUp(); @@ -56,6 +58,8 @@ protected void tearDown() throws Exception { public static ListedLicenseExceptionBuilder builderForListedLicenseExceptionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ListedLicenseExceptionBuilder retval = new ListedLicenseExceptionBuilder(modelStore, objectUri, copyManager) + .setDeprecatedVersion(DEPRECATED_VERSION_TEST_VALUE) + .setListVersionAdded(LIST_VERSION_ADDED_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -64,7 +68,7 @@ public static ListedLicenseExceptionBuilder builderForListedLicenseExceptionTest } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +79,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +87,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicenseException#Element(org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#Element(org.spdx.library.model.v3.licensing.ListedLicenseException.ListedLicenseExceptionBuilder)}. */ public void testListedLicenseExceptionListedLicenseExceptionBuilder() throws InvalidSPDXAnalysisException { builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +108,24 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ListedLicenseException.equivalent(testListedLicenseException)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#setDeprecatedVersion}. + */ + public void testListedLicenseExceptionsetDeprecatedVersion() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(DEPRECATED_VERSION_TEST_VALUE), testListedLicenseException.getDeprecatedVersion()); + testListedLicenseException.setDeprecatedVersion("new deprecatedVersion value"); + assertEquals(Optional.of("new deprecatedVersion value"), testListedLicenseException.getDeprecatedVersion()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#setListVersionAdded}. + */ + public void testListedLicenseExceptionsetListVersionAdded() throws InvalidSPDXAnalysisException { + ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(LIST_VERSION_ADDED_TEST_VALUE), testListedLicenseException.getListVersionAdded()); + testListedLicenseException.setListVersionAdded("new listVersionAdded value"); + assertEquals(Optional.of("new listVersionAdded value"), testListedLicenseException.getListVersionAdded()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java b/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseTest.java similarity index 63% rename from src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseTest.java index 6954dc45e..9aa2fdf0e 100644 --- a/src/test/java/org/spdx/library/model/licensing/ListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.ListedLicense.ListedLicenseBuilder; +import org.spdx.library.model.v3.licensing.ListedLicense.ListedLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,8 @@ public class ListedLicenseTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String DEPRECATED_VERSION_TEST_VALUE = "test deprecatedVersion"; + static final String LIST_VERSION_ADDED_TEST_VALUE = "test listVersionAdded"; protected void setUp() throws Exception { super.setUp(); @@ -56,6 +58,8 @@ protected void tearDown() throws Exception { public static ListedLicenseBuilder builderForListedLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ListedLicenseBuilder retval = new ListedLicenseBuilder(modelStore, objectUri, copyManager) + .setDeprecatedVersion(DEPRECATED_VERSION_TEST_VALUE) + .setListVersionAdded(LIST_VERSION_ADDED_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -64,7 +68,7 @@ public static ListedLicenseBuilder builderForListedLicenseTests( } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicense#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +79,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicense#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +87,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicense#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.ListedLicense#Element(org.spdx.library.model.licensing.ListedLicense.ListedLicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#Element(org.spdx.library.model.v3.licensing.ListedLicense.ListedLicenseBuilder)}. */ public void testListedLicenseListedLicenseBuilder() throws InvalidSPDXAnalysisException { builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +108,24 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2ListedLicense.equivalent(testListedLicense)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#setDeprecatedVersion}. + */ + public void testListedLicensesetDeprecatedVersion() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(DEPRECATED_VERSION_TEST_VALUE), testListedLicense.getDeprecatedVersion()); + testListedLicense.setDeprecatedVersion("new deprecatedVersion value"); + assertEquals(Optional.of("new deprecatedVersion value"), testListedLicense.getDeprecatedVersion()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#setListVersionAdded}. + */ + public void testListedLicensesetListVersionAdded() throws InvalidSPDXAnalysisException { + ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(LIST_VERSION_ADDED_TEST_VALUE), testListedLicense.getListVersionAdded()); + testListedLicense.setListVersionAdded("new listVersionAdded value"); + assertEquals(Optional.of("new listVersionAdded value"), testListedLicense.getListVersionAdded()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/v3/licensing/OrLaterOperatorTest.java similarity index 75% rename from src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/OrLaterOperatorTest.java index 6c1b2c521..44643fcfb 100644 --- a/src/test/java/org/spdx/library/model/licensing/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/OrLaterOperatorTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.OrLaterOperator.OrLaterOperatorBuilder; +import org.spdx.library.model.v3.licensing.OrLaterOperator.OrLaterOperatorBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,13 +58,14 @@ public static OrLaterOperatorBuilder builderForOrLaterOperatorTests( OrLaterOperatorBuilder retval = new OrLaterOperatorBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** + .setSubjectLicense(new License()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +76,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +84,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.OrLaterOperator#Element(org.spdx.library.model.licensing.OrLaterOperator.OrLaterOperatorBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#Element(org.spdx.library.model.v3.licensing.OrLaterOperator.OrLaterOperatorBuilder)}. */ public void testOrLaterOperatorOrLaterOperatorBuilder() throws InvalidSPDXAnalysisException { builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +105,15 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2OrLaterOperator.equivalent(testOrLaterOperator)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#setSubjectLicense}. + */ + public void testOrLaterOperatorsetSubjectLicense() throws InvalidSPDXAnalysisException { + OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testOrLaterOperator.getSubjectLicense()); +// testOrLaterOperator.setSubjectLicense(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testOrLaterOperator.getSubjectLicense()); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java b/src/test/java/org/spdx/library/model/v3/licensing/WithAdditionOperatorTest.java similarity index 65% rename from src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java rename to src/test/java/org/spdx/library/model/v3/licensing/WithAdditionOperatorTest.java index ffa322e47..ceb959468 100644 --- a/src/test/java/org/spdx/library/model/licensing/WithAdditionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/v3/licensing/WithAdditionOperatorTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.licensing; +package org.spdx.library.model.v3.licensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.licensing.WithAdditionOperator.WithAdditionOperatorBuilder; +import org.spdx.library.model.v3.licensing.WithAdditionOperator.WithAdditionOperatorBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,13 +58,15 @@ public static WithAdditionOperatorBuilder builderForWithAdditionOperatorTests( WithAdditionOperatorBuilder retval = new WithAdditionOperatorBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** + .setSubjectAddition(new LicenseAddition()) + .setSubjectLicense(new ExtendableLicense()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#verify()}. + * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +77,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#getType()}. + * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +85,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#toString()}. + * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.licensing.WithAdditionOperator#Element(org.spdx.library.model.licensing.WithAdditionOperator.WithAdditionOperatorBuilder)}. + * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#Element(org.spdx.library.model.v3.licensing.WithAdditionOperator.WithAdditionOperatorBuilder)}. */ public void testWithAdditionOperatorWithAdditionOperatorBuilder() throws InvalidSPDXAnalysisException { builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +106,26 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2WithAdditionOperator.equivalent(testWithAdditionOperator)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#setSubjectAddition}. + */ + public void testWithAdditionOperatorsetSubjectAddition() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testWithAdditionOperator.getSubjectAddition()); +// testWithAdditionOperator.setSubjectAddition(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testWithAdditionOperator.getSubjectAddition()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#setSubjectLicense}. + */ + public void testWithAdditionOperatorsetSubjectLicense() throws InvalidSPDXAnalysisException { + WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testWithAdditionOperator.getSubjectLicense()); +// testWithAdditionOperator.setSubjectLicense(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testWithAdditionOperator.getSubjectLicense()); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java similarity index 58% rename from src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java index 03cf794d4..e30f1ba08 100644 --- a/src/test/java/org/spdx/library/model/security/CvssV2VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,9 @@ public class CvssV2VulnAssessmentRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final Integer SCORE_TEST_VALUE = 55; + static final String SEVERITY_TEST_VALUE = "test severity"; + static final String VECTOR_TEST_VALUE = "test vector"; protected void setUp() throws Exception { super.setUp(); @@ -56,6 +59,9 @@ protected void tearDown() throws Exception { public static CvssV2VulnAssessmentRelationshipBuilder builderForCvssV2VulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { CvssV2VulnAssessmentRelationshipBuilder retval = new CvssV2VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setScore(SCORE_TEST_VALUE) + .setSeverity(SEVERITY_TEST_VALUE) + .setVector(VECTOR_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -64,7 +70,7 @@ public static CvssV2VulnAssessmentRelationshipBuilder builderForCvssV2VulnAssess } /** - * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +81,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +89,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.CvssV2VulnAssessmentRelationship#Element(org.spdx.library.model.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship.CvssV2VulnAssessmentRelationshipBuilder)}. */ public void testCvssV2VulnAssessmentRelationshipCvssV2VulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +110,34 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2CvssV2VulnAssessmentRelationship.equivalent(testCvssV2VulnAssessmentRelationship)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#setScore}. + */ + public void testCvssV2VulnAssessmentRelationshipsetScore() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(SCORE_TEST_VALUE, testCvssV2VulnAssessmentRelationship.getScore()); + testCvssV2VulnAssessmentRelationship.setScore(new Integer(653)); + assertEquals(new Integer(653), testCvssV2VulnAssessmentRelationship.getScore()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#setSeverity}. + */ + public void testCvssV2VulnAssessmentRelationshipsetSeverity() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(SEVERITY_TEST_VALUE), testCvssV2VulnAssessmentRelationship.getSeverity()); + testCvssV2VulnAssessmentRelationship.setSeverity("new severity value"); + assertEquals(Optional.of("new severity value"), testCvssV2VulnAssessmentRelationship.getSeverity()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#setVector}. + */ + public void testCvssV2VulnAssessmentRelationshipsetVector() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(VECTOR_TEST_VALUE), testCvssV2VulnAssessmentRelationship.getVector()); + testCvssV2VulnAssessmentRelationship.setVector("new vector value"); + assertEquals(Optional.of("new vector value"), testCvssV2VulnAssessmentRelationship.getVector()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java similarity index 58% rename from src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java index 87762c85f..e5e83b67a 100644 --- a/src/test/java/org/spdx/library/model/security/CvssV3VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,6 +42,9 @@ public class CvssV3VulnAssessmentRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final Integer SCORE_TEST_VALUE = 55; + static final String VECTOR_TEST_VALUE = "test vector"; + static final String SEVERITY_TEST_VALUE = "test severity"; protected void setUp() throws Exception { super.setUp(); @@ -56,6 +59,9 @@ protected void tearDown() throws Exception { public static CvssV3VulnAssessmentRelationshipBuilder builderForCvssV3VulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { CvssV3VulnAssessmentRelationshipBuilder retval = new CvssV3VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setScore(SCORE_TEST_VALUE) + .setVector(VECTOR_TEST_VALUE) + .setSeverity(SEVERITY_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -64,7 +70,7 @@ public static CvssV3VulnAssessmentRelationshipBuilder builderForCvssV3VulnAssess } /** - * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +81,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +89,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.CvssV3VulnAssessmentRelationship#Element(org.spdx.library.model.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship.CvssV3VulnAssessmentRelationshipBuilder)}. */ public void testCvssV3VulnAssessmentRelationshipCvssV3VulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +110,34 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2CvssV3VulnAssessmentRelationship.equivalent(testCvssV3VulnAssessmentRelationship)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#setScore}. + */ + public void testCvssV3VulnAssessmentRelationshipsetScore() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(SCORE_TEST_VALUE, testCvssV3VulnAssessmentRelationship.getScore()); + testCvssV3VulnAssessmentRelationship.setScore(new Integer(653)); + assertEquals(new Integer(653), testCvssV3VulnAssessmentRelationship.getScore()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#setVector}. + */ + public void testCvssV3VulnAssessmentRelationshipsetVector() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(VECTOR_TEST_VALUE), testCvssV3VulnAssessmentRelationship.getVector()); + testCvssV3VulnAssessmentRelationship.setVector("new vector value"); + assertEquals(Optional.of("new vector value"), testCvssV3VulnAssessmentRelationship.getVector()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV3VulnAssessmentRelationship#setSeverity}. + */ + public void testCvssV3VulnAssessmentRelationshipsetSeverity() throws InvalidSPDXAnalysisException { + CvssV3VulnAssessmentRelationship testCvssV3VulnAssessmentRelationship = builderForCvssV3VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(SEVERITY_TEST_VALUE), testCvssV3VulnAssessmentRelationship.getSeverity()); + testCvssV3VulnAssessmentRelationship.setSeverity("new severity value"); + assertEquals(Optional.of("new severity value"), testCvssV3VulnAssessmentRelationship.getSeverity()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java similarity index 74% rename from src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java index 318d456b8..80ddcb3b8 100644 --- a/src/test/java/org/spdx/library/model/security/EpssVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -43,6 +43,7 @@ public class EpssVulnAssessmentRelationshipTest extends TestCase { ModelCopyManager copyManager; static final Integer PROBABILITY_TEST_VALUE = 55; + static final String SEVERITY_TEST_VALUE = "test severity"; protected void setUp() throws Exception { super.setUp(); @@ -58,6 +59,7 @@ public static EpssVulnAssessmentRelationshipBuilder builderForEpssVulnAssessment IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { EpssVulnAssessmentRelationshipBuilder retval = new EpssVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) .setProbability(PROBABILITY_TEST_VALUE) + .setSeverity(SEVERITY_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -66,7 +68,7 @@ public static EpssVulnAssessmentRelationshipBuilder builderForEpssVulnAssessment } /** - * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +79,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +87,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#Element(org.spdx.library.model.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship.EpssVulnAssessmentRelationshipBuilder)}. */ public void testEpssVulnAssessmentRelationshipEpssVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +110,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.EpssVulnAssessmentRelationship#setProbability}. + * Test method for {@link org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship#setProbability}. */ public void testEpssVulnAssessmentRelationshipsetProbability() throws InvalidSPDXAnalysisException { EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -116,4 +118,14 @@ public void testEpssVulnAssessmentRelationshipsetProbability() throws InvalidSPD testEpssVulnAssessmentRelationship.setProbability(new Integer(653)); assertEquals(new Integer(653), testEpssVulnAssessmentRelationship.getProbability()); } + + /** + * Test method for {@link org.spdx.library.model.v3.security.EpssVulnAssessmentRelationship#setSeverity}. + */ + public void testEpssVulnAssessmentRelationshipsetSeverity() throws InvalidSPDXAnalysisException { + EpssVulnAssessmentRelationship testEpssVulnAssessmentRelationship = builderForEpssVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(SEVERITY_TEST_VALUE), testEpssVulnAssessmentRelationship.getSeverity()); + testEpssVulnAssessmentRelationship.setSeverity("new severity value"); + assertEquals(Optional.of("new severity value"), testEpssVulnAssessmentRelationship.getSeverity()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java index 1b011a702..658060c29 100644 --- a/src/test/java/org/spdx/library/model/security/ExploitCatalogVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -70,7 +70,7 @@ public static ExploitCatalogVulnAssessmentRelationshipBuilder builderForExploitC } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -81,7 +81,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -89,7 +89,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -97,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#Element(org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship.ExploitCatalogVulnAssessmentRelationshipBuilder)}. */ public void testExploitCatalogVulnAssessmentRelationshipExploitCatalogVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -112,7 +112,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#setCatalogType}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#setCatalogType}. */ public void testExploitCatalogVulnAssessmentRelationshipsetCatalogType() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -122,7 +122,7 @@ public void testExploitCatalogVulnAssessmentRelationshipsetCatalogType() throws } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#setExploited}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#setExploited}. */ public void testExploitCatalogVulnAssessmentRelationshipsetExploited() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -132,7 +132,7 @@ public void testExploitCatalogVulnAssessmentRelationshipsetExploited() throws In } /** - * Test method for {@link org.spdx.library.model.security.ExploitCatalogVulnAssessmentRelationship#setLocator}. + * Test method for {@link org.spdx.library.model.v3.security.ExploitCatalogVulnAssessmentRelationship#setLocator}. */ public void testExploitCatalogVulnAssessmentRelationshipsetLocator() throws InvalidSPDXAnalysisException { ExploitCatalogVulnAssessmentRelationship testExploitCatalogVulnAssessmentRelationship = builderForExploitCatalogVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java index a30c0277c..d5885758d 100644 --- a/src/test/java/org/spdx/library/model/security/SsvcVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -67,7 +67,7 @@ public static SsvcVulnAssessmentRelationshipBuilder builderForSsvcVulnAssessment } /** - * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -78,7 +78,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -86,7 +86,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -94,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#Element(org.spdx.library.model.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship.SsvcVulnAssessmentRelationshipBuilder)}. */ public void testSsvcVulnAssessmentRelationshipSsvcVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -109,7 +109,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.SsvcVulnAssessmentRelationship#setDecisionType}. + * Test method for {@link org.spdx.library.model.v3.security.SsvcVulnAssessmentRelationship#setDecisionType}. */ public void testSsvcVulnAssessmentRelationshipsetDecisionType() throws InvalidSPDXAnalysisException { SsvcVulnAssessmentRelationship testSsvcVulnAssessmentRelationship = builderForSsvcVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java similarity index 71% rename from src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java index d0c51be10..93a52c51a 100644 --- a/src/test/java/org/spdx/library/model/security/VexAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -43,11 +43,6 @@ public class VexAffectedVulnAssessmentRelationshipTest extends TestCase { ModelCopyManager copyManager; static final String ACTION_STATEMENT_TEST_VALUE = "test actionStatement"; - static final String ACTION_STATEMENT_TIME_TEST_VALUE1 = "test 1 actionStatementTime"; - static final String ACTION_STATEMENT_TIME_TEST_VALUE2 = "test 2 actionStatementTime"; - static final String ACTION_STATEMENT_TIME_TEST_VALUE3 = "test 3 actionStatementTime"; - static final List ACTION_STATEMENT_TIME_TEST_LIST1 = Arrays.asList(new String[] { ACTION_STATEMENT_TIME_TEST_VALUE1, ACTION_STATEMENT_TIME_TEST_VALUE2 }); - static final List ACTION_STATEMENT_TIME_TEST_LIST2 = Arrays.asList(new String[] { ACTION_STATEMENT_TIME_TEST_VALUE3 }); protected void setUp() throws Exception { super.setUp(); @@ -63,17 +58,16 @@ public static VexAffectedVulnAssessmentRelationshipBuilder builderForVexAffected IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationshipBuilder retval = new VexAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) .setActionStatement(ACTION_STATEMENT_TEST_VALUE) - .addActionStatementTime(ACTION_STATEMENT_TIME_TEST_VALUE1) - .addActionStatementTime(ACTION_STATEMENT_TIME_TEST_VALUE2) //TODO: Add in test values /******************** + .addActionStatementTime(DateTime) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -84,7 +78,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -92,7 +86,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -100,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship.VexAffectedVulnAssessmentRelationshipBuilder)}. */ public void testVexAffectedVulnAssessmentRelationshipVexAffectedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -115,7 +109,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#setActionStatement}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#setActionStatement}. */ public void testVexAffectedVulnAssessmentRelationshipsetActionStatement() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -125,13 +119,14 @@ public void testVexAffectedVulnAssessmentRelationshipsetActionStatement() throws } /** - * Test method for {@link org.spdx.library.model.security.VexAffectedVulnAssessmentRelationship#getActionStatementTimes}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#getActionStatementTime}. */ public void testVexAffectedVulnAssessmentRelationshipgetActionStatementTimes() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST1, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); - testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().clear(); - testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().addAll(ACTION_STATEMENT_TIME_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST2, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); +// testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().clear(); +// testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); + fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java index dd9be2e56..67733a3b0 100644 --- a/src/test/java/org/spdx/library/model/security/VexFixedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static VexFixedVulnAssessmentRelationshipBuilder builderForVexFixedVulnAs } /** - * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.VexFixedVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.VexFixedVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.VexFixedVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { VexFixedVulnAssessmentRelationship testVexFixedVulnAssessmentRelationship = builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexFixedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.VexFixedVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.VexFixedVulnAssessmentRelationship.VexFixedVulnAssessmentRelationshipBuilder)}. */ public void testVexFixedVulnAssessmentRelationshipVexFixedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForVexFixedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java similarity index 79% rename from src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java index 847f2f3ed..fca827fab 100644 --- a/src/test/java/org/spdx/library/model/security/VexNotAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,7 +42,6 @@ public class VexNotAffectedVulnAssessmentRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String IMPACT_STATEMENT_TIME_TEST_VALUE = "test impactStatementTime"; static final String IMPACT_STATEMENT_TEST_VALUE = "test impactStatement"; static final VexJustificationType JUSTIFICATION_TYPE_TEST_VALUE1 = VexJustificationType.values()[0]; static final VexJustificationType JUSTIFICATION_TYPE_TEST_VALUE2 = VexJustificationType.values()[1]; @@ -60,18 +59,18 @@ protected void tearDown() throws Exception { public static VexNotAffectedVulnAssessmentRelationshipBuilder builderForVexNotAffectedVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationshipBuilder retval = new VexNotAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) - .setImpactStatementTime(IMPACT_STATEMENT_TIME_TEST_VALUE) .setImpactStatement(IMPACT_STATEMENT_TEST_VALUE) .setJustificationType(JUSTIFICATION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** + .setImpactStatementTime(new DateTime()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -82,7 +81,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -90,7 +89,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -98,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship.VexNotAffectedVulnAssessmentRelationshipBuilder)}. */ public void testVexNotAffectedVulnAssessmentRelationshipVexNotAffectedVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -113,27 +112,28 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#setJustificationType}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatementTime}. */ - public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() throws InvalidSPDXAnalysisException { + public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE1), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); - testVexNotAffectedVulnAssessmentRelationship.setJustificationType(JUSTIFICATION_TYPE_TEST_VALUE2); - assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE2), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); +// assertEquals(Optional.of(TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); +// testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatementTime}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setJustificationType}. */ - public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { + public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(IMPACT_STATEMENT_TIME_TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); - testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime("new impactStatementTime value"); - assertEquals(Optional.of("new impactStatementTime value"), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE1), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); + testVexNotAffectedVulnAssessmentRelationship.setJustificationType(JUSTIFICATION_TYPE_TEST_VALUE2); + assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE2), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); } /** - * Test method for {@link org.spdx.library.model.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatement}. + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatement}. */ public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatement() throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java similarity index 84% rename from src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java index 770a4f146..268aeaea7 100644 --- a/src/test/java/org/spdx/library/model/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static VexUnderInvestigationVulnAssessmentRelationshipBuilder builderForV } /** - * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.VexUnderInvestigationVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +75,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.VexUnderInvestigationVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +83,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.VexUnderInvestigationVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { VexUnderInvestigationVulnAssessmentRelationship testVexUnderInvestigationVulnAssessmentRelationship = builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.VexUnderInvestigationVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.VexUnderInvestigationVulnAssessmentRelationship.VexUnderInvestigationVulnAssessmentRelationshipBuilder)}. */ public void testVexUnderInvestigationVulnAssessmentRelationshipVexUnderInvestigationVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForVexUnderInvestigationVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java similarity index 85% rename from src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java index cbb9fa7ad..9d5628919 100644 --- a/src/test/java/org/spdx/library/model/security/VexVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -68,7 +68,7 @@ public static VexVulnAssessmentRelationshipBuilder builderForVexVulnAssessmentRe } /** - * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.VexVulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -79,7 +79,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.VexVulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -87,7 +87,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.VexVulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -95,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#Element(org.spdx.library.model.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.VexVulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.VexVulnAssessmentRelationship.VexVulnAssessmentRelationshipBuilder)}. */ public void testVexVulnAssessmentRelationshipVexVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -110,7 +110,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#setStatusNotes}. + * Test method for {@link org.spdx.library.model.v3.security.VexVulnAssessmentRelationship#setStatusNotes}. */ public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -120,7 +120,7 @@ public void testVexVulnAssessmentRelationshipsetStatusNotes() throws InvalidSPDX } /** - * Test method for {@link org.spdx.library.model.security.VexVulnAssessmentRelationship#setVexVersion}. + * Test method for {@link org.spdx.library.model.v3.security.VexVulnAssessmentRelationship#setVexVersion}. */ public void testVexVulnAssessmentRelationshipsetVexVersion() throws InvalidSPDXAnalysisException { VexVulnAssessmentRelationship testVexVulnAssessmentRelationship = builderForVexVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java similarity index 62% rename from src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java index 13d7ebc9a..a477c6bea 100644 --- a/src/test/java/org/spdx/library/model/security/VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder; +import org.spdx.library.model.v3.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,15 +58,18 @@ public static VulnAssessmentRelationshipBuilder builderForVulnAssessmentRelation VulnAssessmentRelationshipBuilder retval = new VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** - .setAssessedElement(Element testElement) - .setSuppliedBy(Element testElement) + .setSuppliedBy(new Agent()) + .setPublishedTime(new DateTime()) + .setWithdrawnTime(new DateTime()) + .setAssessedElement(new Element()) + .setModifiedTime(new DateTime()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +80,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +88,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +96,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#Element(org.spdx.library.model.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#Element(org.spdx.library.model.v3.security.VulnAssessmentRelationship.VulnAssessmentRelationshipBuilder)}. */ public void testVulnAssessmentRelationshipVulnAssessmentRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +111,40 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#setAssessedElement}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setSuppliedBy}. + */ + public void testVulnAssessmentRelationshipsetSuppliedBy() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getSuppliedBy()); +// testVulnAssessmentRelationship.setSuppliedBy(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getSuppliedBy()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setPublishedTime}. + */ + public void testVulnAssessmentRelationshipsetPublishedTime() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getPublishedTime()); +// testVulnAssessmentRelationship.setPublishedTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getPublishedTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setWithdrawnTime}. + */ + public void testVulnAssessmentRelationshipsetWithdrawnTime() throws InvalidSPDXAnalysisException { + VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getWithdrawnTime()); +// testVulnAssessmentRelationship.setWithdrawnTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getWithdrawnTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setAssessedElement}. */ public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -119,13 +155,13 @@ public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPD } /** - * Test method for {@link org.spdx.library.model.security.VulnAssessmentRelationship#setSuppliedBy}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setModifiedTime}. */ - public void testVulnAssessmentRelationshipsetSuppliedBy() throws InvalidSPDXAnalysisException { + public void testVulnAssessmentRelationshipsetModifiedTime() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getSuppliedBy()); -// testVulnAssessmentRelationship.setSuppliedBy(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getSuppliedBy()); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getModifiedTime()); +// testVulnAssessmentRelationship.setModifiedTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getModifiedTime()); fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java b/src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java similarity index 59% rename from src/test/java/org/spdx/library/model/security/VulnerabilityTest.java rename to src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java index 463525f9b..37e1ae327 100644 --- a/src/test/java/org/spdx/library/model/security/VulnerabilityTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.security; +package org.spdx.library.model.v3.security; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.security.Vulnerability.VulnerabilityBuilder; +import org.spdx.library.model.v3.security.Vulnerability.VulnerabilityBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,13 +58,16 @@ public static VulnerabilityBuilder builderForVulnerabilityTests( VulnerabilityBuilder retval = new VulnerabilityBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** + .setModifiedTime(new DateTime()) + .setWithdrawnTime(new DateTime()) + .setPublishedTime(new DateTime()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.security.Vulnerability#verify()}. + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,7 +78,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.Vulnerability#getType()}. + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -83,7 +86,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.Vulnerability#toString()}. + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +94,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.security.Vulnerability#Element(org.spdx.library.model.security.Vulnerability.VulnerabilityBuilder)}. + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#Element(org.spdx.library.model.v3.security.Vulnerability.VulnerabilityBuilder)}. */ public void testVulnerabilityVulnerabilityBuilder() throws InvalidSPDXAnalysisException { builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -104,4 +107,37 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2Vulnerability.equivalent(testVulnerability)); // TODO change some parameters for negative tests } + + /** + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setModifiedTime}. + */ + public void testVulnerabilitysetModifiedTime() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testVulnerability.getModifiedTime()); +// testVulnerability.setModifiedTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnerability.getModifiedTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setWithdrawnTime}. + */ + public void testVulnerabilitysetWithdrawnTime() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testVulnerability.getWithdrawnTime()); +// testVulnerability.setWithdrawnTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnerability.getWithdrawnTime()); + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setPublishedTime}. + */ + public void testVulnerabilitysetPublishedTime() throws InvalidSPDXAnalysisException { + Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(TEST_VALUE), testVulnerability.getPublishedTime()); +// testVulnerability.setPublishedTime(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnerability.getPublishedTime()); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SbomTest.java b/src/test/java/org/spdx/library/model/v3/software/SbomTest.java similarity index 80% rename from src/test/java/org/spdx/library/model/software/SbomTest.java rename to src/test/java/org/spdx/library/model/v3/software/SbomTest.java index 036154a09..ed815211b 100644 --- a/src/test/java/org/spdx/library/model/software/SbomTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SbomTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.software.Sbom.SbomBuilder; +import org.spdx.library.model.v3.software.Sbom.SbomBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,10 +42,10 @@ public class SbomTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final SBOMType SBOM_TYPE_TEST_VALUE1 = SBOMType.values()[0]; - static final SBOMType SBOM_TYPE_TEST_VALUE2 = SBOMType.values()[1]; - static final List SBOM_TYPE_TEST_LIST1 = Arrays.asList(new SBOMType[] { SBOM_TYPE_TEST_VALUE1, SBOM_TYPE_TEST_VALUE2 }); - static final List SBOM_TYPE_TEST_LIST2 = Arrays.asList(new SBOMType[] { SBOM_TYPE_TEST_VALUE1 }); + static final SbomType SBOM_TYPE_TEST_VALUE1 = SbomType.values()[0]; + static final SbomType SBOM_TYPE_TEST_VALUE2 = SbomType.values()[1]; + static final List SBOM_TYPE_TEST_LIST1 = Arrays.asList(new SbomType[] { SBOM_TYPE_TEST_VALUE1, SBOM_TYPE_TEST_VALUE2 }); + static final List SBOM_TYPE_TEST_LIST2 = Arrays.asList(new SbomType[] { SBOM_TYPE_TEST_VALUE1 }); protected void setUp() throws Exception { super.setUp(); @@ -70,7 +70,7 @@ public static SbomBuilder builderForSbomTests( } /** - * Test method for {@link org.spdx.library.model.software.Sbom#verify()}. + * Test method for {@link org.spdx.library.model.v3.software.Sbom#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -81,7 +81,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Sbom#getType()}. + * Test method for {@link org.spdx.library.model.v3.software.Sbom#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -89,7 +89,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Sbom#toString()}. + * Test method for {@link org.spdx.library.model.v3.software.Sbom#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -97,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Sbom#Element(org.spdx.library.model.software.Sbom.SbomBuilder)}. + * Test method for {@link org.spdx.library.model.v3.software.Sbom#Element(org.spdx.library.model.v3.software.Sbom.SbomBuilder)}. */ public void testSbomSbomBuilder() throws InvalidSPDXAnalysisException { builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -112,7 +112,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Sbom#getSbomType}. + * Test method for {@link org.spdx.library.model.v3.software.Sbom#getSbomType}. */ public void testSbomgetSbomTypes() throws InvalidSPDXAnalysisException { Sbom testSbom = builderForSbomTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/software/SnippetTest.java b/src/test/java/org/spdx/library/model/v3/software/SnippetTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/software/SnippetTest.java rename to src/test/java/org/spdx/library/model/v3/software/SnippetTest.java index e5e1623e6..a1b6946db 100644 --- a/src/test/java/org/spdx/library/model/software/SnippetTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SnippetTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.software.Snippet.SnippetBuilder; +import org.spdx.library.model.v3.software.Snippet.SnippetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -58,15 +58,15 @@ public static SnippetBuilder builderForSnippetTests( SnippetBuilder retval = new SnippetBuilder(modelStore, objectUri, copyManager) //TODO: Add in test values /******************** - .setByteRange(new PositiveIntegerRange()) .setLineRange(new PositiveIntegerRange()) + .setByteRange(new PositiveIntegerRange()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.software.Snippet#verify()}. + * Test method for {@link org.spdx.library.model.v3.software.Snippet#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +77,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Snippet#getType()}. + * Test method for {@link org.spdx.library.model.v3.software.Snippet#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +85,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Snippet#toString()}. + * Test method for {@link org.spdx.library.model.v3.software.Snippet#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Snippet#Element(org.spdx.library.model.software.Snippet.SnippetBuilder)}. + * Test method for {@link org.spdx.library.model.v3.software.Snippet#Element(org.spdx.library.model.v3.software.Snippet.SnippetBuilder)}. */ public void testSnippetSnippetBuilder() throws InvalidSPDXAnalysisException { builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,24 +108,24 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.Snippet#setByteRange}. + * Test method for {@link org.spdx.library.model.v3.software.Snippet#setLineRange}. */ - public void testSnippetsetByteRange() throws InvalidSPDXAnalysisException { + public void testSnippetsetLineRange() throws InvalidSPDXAnalysisException { Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSnippet.getByteRange()); -// testSnippet.setByteRange(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSnippet.getByteRange()); +// assertEquals(Optional.of(TEST_VALUE), testSnippet.getLineRange()); +// testSnippet.setLineRange(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSnippet.getLineRange()); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.software.Snippet#setLineRange}. + * Test method for {@link org.spdx.library.model.v3.software.Snippet#setByteRange}. */ - public void testSnippetsetLineRange() throws InvalidSPDXAnalysisException { + public void testSnippetsetByteRange() throws InvalidSPDXAnalysisException { Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSnippet.getLineRange()); -// testSnippet.setLineRange(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSnippet.getLineRange()); +// assertEquals(Optional.of(TEST_VALUE), testSnippet.getByteRange()); +// testSnippet.setByteRange(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSnippet.getByteRange()); fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java b/src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java rename to src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java index 00c54bd05..65d5f3530 100644 --- a/src/test/java/org/spdx/library/model/software/SoftwareArtifactTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.software.SoftwareArtifact.SoftwareArtifactBuilder; +import org.spdx.library.model.v3.software.SoftwareArtifact.SoftwareArtifactBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,8 +42,8 @@ public class SoftwareArtifactTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String CONTENT_IDENTIFIER_TEST_VALUE = "test contentIdentifier"; static final String ATTRIBUTION_TEXT_TEST_VALUE = "test attributionText"; + static final String CONTENT_IDENTIFIER_TEST_VALUE = "test contentIdentifier"; static final String COPYRIGHT_TEXT_TEST_VALUE = "test copyrightText"; static final SoftwarePurpose PRIMARY_PURPOSE_TEST_VALUE1 = SoftwarePurpose.values()[0]; static final SoftwarePurpose PRIMARY_PURPOSE_TEST_VALUE2 = SoftwarePurpose.values()[1]; @@ -65,23 +65,23 @@ protected void tearDown() throws Exception { public static SoftwareArtifactBuilder builderForSoftwareArtifactTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SoftwareArtifactBuilder retval = new SoftwareArtifactBuilder(modelStore, objectUri, copyManager) - .setContentIdentifier(CONTENT_IDENTIFIER_TEST_VALUE) .setAttributionText(ATTRIBUTION_TEXT_TEST_VALUE) + .setContentIdentifier(CONTENT_IDENTIFIER_TEST_VALUE) .setCopyrightText(COPYRIGHT_TEXT_TEST_VALUE) .setPrimaryPurpose(PRIMARY_PURPOSE_TEST_VALUE1) .addAdditionalPurpose(ADDITIONAL_PURPOSE_TEST_VALUE1) .addAdditionalPurpose(ADDITIONAL_PURPOSE_TEST_VALUE2) //TODO: Add in test values /******************** - .setDeclaredLicense(TEST_ANYLICENSE_INFO) - .setConcludedLicense(TEST_ANYLICENSE_INFO) + .setConcludedLicense(new AnyLicenseInfo()) + .setDeclaredLicense(new AnyLicenseInfo()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#verify()}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -92,7 +92,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#getType()}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -100,7 +100,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#toString()}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +108,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#Element(org.spdx.library.model.software.SoftwareArtifact.SoftwareArtifactBuilder)}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#Element(org.spdx.library.model.v3.software.SoftwareArtifact.SoftwareArtifactBuilder)}. */ public void testSoftwareArtifactSoftwareArtifactBuilder() throws InvalidSPDXAnalysisException { builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -123,29 +123,29 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setDeclaredLicense}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setConcludedLicense}. */ - public void testSoftwareArtifactsetDeclaredLicense() throws InvalidSPDXAnalysisException { + public void testSoftwareArtifactsetConcludedLicense() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); -// testSoftwareArtifact.setDeclaredLicense(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); +// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); +// testSoftwareArtifact.setConcludedLicense(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setConcludedLicense}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setDeclaredLicense}. */ - public void testSoftwareArtifactsetConcludedLicense() throws InvalidSPDXAnalysisException { + public void testSoftwareArtifactsetDeclaredLicense() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); -// testSoftwareArtifact.setConcludedLicense(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); +// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); +// testSoftwareArtifact.setDeclaredLicense(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setPrimaryPurpose}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setPrimaryPurpose}. */ public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -155,27 +155,27 @@ public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisEx } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setContentIdentifier}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setAttributionText}. */ - public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysisException { + public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(CONTENT_IDENTIFIER_TEST_VALUE), testSoftwareArtifact.getContentIdentifier()); - testSoftwareArtifact.setContentIdentifier("new contentIdentifier value"); - assertEquals(Optional.of("new contentIdentifier value"), testSoftwareArtifact.getContentIdentifier()); + assertEquals(Optional.of(ATTRIBUTION_TEXT_TEST_VALUE), testSoftwareArtifact.getAttributionText()); + testSoftwareArtifact.setAttributionText("new attributionText value"); + assertEquals(Optional.of("new attributionText value"), testSoftwareArtifact.getAttributionText()); } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setAttributionText}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setContentIdentifier}. */ - public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisException { + public void testSoftwareArtifactsetContentIdentifier() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(ATTRIBUTION_TEXT_TEST_VALUE), testSoftwareArtifact.getAttributionText()); - testSoftwareArtifact.setAttributionText("new attributionText value"); - assertEquals(Optional.of("new attributionText value"), testSoftwareArtifact.getAttributionText()); + assertEquals(Optional.of(CONTENT_IDENTIFIER_TEST_VALUE), testSoftwareArtifact.getContentIdentifier()); + testSoftwareArtifact.setContentIdentifier("new contentIdentifier value"); + assertEquals(Optional.of("new contentIdentifier value"), testSoftwareArtifact.getContentIdentifier()); } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#setCopyrightText}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setCopyrightText}. */ public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -185,7 +185,7 @@ public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisExc } /** - * Test method for {@link org.spdx.library.model.software.SoftwareArtifact#getAdditionalPurpose}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#getAdditionalPurpose}. */ public void testSoftwareArtifactgetAdditionalPurposes() throws InvalidSPDXAnalysisException { SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java rename to src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java index 62de02a8d..bc9c15dc1 100644 --- a/src/test/java/org/spdx/library/model/software/SoftwareDependencyRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder; +import org.spdx.library.model.v3.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -70,7 +70,7 @@ public static SoftwareDependencyRelationshipBuilder builderForSoftwareDependency } /** - * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#verify()}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareDependencyRelationship#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -81,7 +81,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#getType()}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareDependencyRelationship#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -89,7 +89,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#toString()}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareDependencyRelationship#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -97,7 +97,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#Element(org.spdx.library.model.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder)}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareDependencyRelationship#Element(org.spdx.library.model.v3.software.SoftwareDependencyRelationship.SoftwareDependencyRelationshipBuilder)}. */ public void testSoftwareDependencyRelationshipSoftwareDependencyRelationshipBuilder() throws InvalidSPDXAnalysisException { builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -112,7 +112,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#setSoftwareLinkage}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareDependencyRelationship#setSoftwareLinkage}. */ public void testSoftwareDependencyRelationshipsetSoftwareLinkage() throws InvalidSPDXAnalysisException { SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -122,7 +122,7 @@ public void testSoftwareDependencyRelationshipsetSoftwareLinkage() throws Invali } /** - * Test method for {@link org.spdx.library.model.software.SoftwareDependencyRelationship#setConditionality}. + * Test method for {@link org.spdx.library.model.v3.software.SoftwareDependencyRelationship#setConditionality}. */ public void testSoftwareDependencyRelationshipsetConditionality() throws InvalidSPDXAnalysisException { SoftwareDependencyRelationship testSoftwareDependencyRelationship = builderForSoftwareDependencyRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/software/SpdxFileTest.java b/src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java similarity index 79% rename from src/test/java/org/spdx/library/model/software/SpdxFileTest.java rename to src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java index 259f59f7f..81132984a 100644 --- a/src/test/java/org/spdx/library/model/software/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.software.SpdxFile.SpdxFileBuilder; +import org.spdx.library.model.v3.software.SpdxFile.SpdxFileBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,7 +42,6 @@ public class SpdxFileTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; protected void setUp() throws Exception { super.setUp(); @@ -57,16 +56,16 @@ protected void tearDown() throws Exception { public static SpdxFileBuilder builderForSpdxFileTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SpdxFileBuilder retval = new SpdxFileBuilder(modelStore, objectUri, copyManager) - .setContentType(CONTENT_TYPE_TEST_VALUE) //TODO: Add in test values /******************** + .setContentType(new MediaType()) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.software.SpdxFile#verify()}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxFile#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,7 +76,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxFile#getType()}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxFile#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -85,7 +84,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxFile#toString()}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxFile#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxFile#Element(org.spdx.library.model.software.SpdxFile.SpdxFileBuilder)}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxFile#Element(org.spdx.library.model.v3.software.SpdxFile.SpdxFileBuilder)}. */ public void testSpdxFileSpdxFileBuilder() throws InvalidSPDXAnalysisException { builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,12 +107,13 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxFile#setContentType}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxFile#setContentType}. */ public void testSpdxFilesetContentType() throws InvalidSPDXAnalysisException { SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(CONTENT_TYPE_TEST_VALUE), testSpdxFile.getContentType()); - testSpdxFile.setContentType("new contentType value"); - assertEquals(Optional.of("new contentType value"), testSpdxFile.getContentType()); +// assertEquals(Optional.of(TEST_VALUE), testSpdxFile.getContentType()); +// testSpdxFile.setContentType(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testSpdxFile.getContentType()); + fail("Not yet implemented"); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java similarity index 86% rename from src/test/java/org/spdx/library/model/software/SpdxPackageTest.java rename to src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java index 75f1d828a..eb89f3d0a 100644 --- a/src/test/java/org/spdx/library/model/software/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.software; +package org.spdx.library.model.v3.software; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.software.SpdxPackage.SpdxPackageBuilder; +import org.spdx.library.model.v3.software.SpdxPackage.SpdxPackageBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,11 +42,11 @@ public class SpdxPackageTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String DOWNLOAD_LOCATION_TEST_VALUE = "test downloadLocation"; static final String SOURCE_INFO_TEST_VALUE = "test sourceInfo"; - static final String PACKAGE_VERSION_TEST_VALUE = "test packageVersion"; static final String HOME_PAGE_TEST_VALUE = "test homePage"; + static final String PACKAGE_VERSION_TEST_VALUE = "test packageVersion"; static final String PACKAGE_URL_TEST_VALUE = "test packageUrl"; + static final String DOWNLOAD_LOCATION_TEST_VALUE = "test downloadLocation"; protected void setUp() throws Exception { super.setUp(); @@ -61,11 +61,11 @@ protected void tearDown() throws Exception { public static SpdxPackageBuilder builderForSpdxPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SpdxPackageBuilder retval = new SpdxPackageBuilder(modelStore, objectUri, copyManager) - .setDownloadLocation(DOWNLOAD_LOCATION_TEST_VALUE) .setSourceInfo(SOURCE_INFO_TEST_VALUE) - .setPackageVersion(PACKAGE_VERSION_TEST_VALUE) .setHomePage(HOME_PAGE_TEST_VALUE) + .setPackageVersion(PACKAGE_VERSION_TEST_VALUE) .setPackageUrl(PACKAGE_URL_TEST_VALUE) + .setDownloadLocation(DOWNLOAD_LOCATION_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -74,7 +74,7 @@ public static SpdxPackageBuilder builderForSpdxPackageTests( } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#verify()}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -85,7 +85,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#getType()}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +93,7 @@ public void testGetType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#toString()}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -101,7 +101,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#Element(org.spdx.library.model.software.SpdxPackage.SpdxPackageBuilder)}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#Element(org.spdx.library.model.v3.software.SpdxPackage.SpdxPackageBuilder)}. */ public void testSpdxPackageSpdxPackageBuilder() throws InvalidSPDXAnalysisException { builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -116,27 +116,27 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#setDownloadLocation}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setSourceInfo}. */ - public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DOWNLOAD_LOCATION_TEST_VALUE), testSpdxPackage.getDownloadLocation()); - testSpdxPackage.setDownloadLocation("new downloadLocation value"); - assertEquals(Optional.of("new downloadLocation value"), testSpdxPackage.getDownloadLocation()); + assertEquals(Optional.of(SOURCE_INFO_TEST_VALUE), testSpdxPackage.getSourceInfo()); + testSpdxPackage.setSourceInfo("new sourceInfo value"); + assertEquals(Optional.of("new sourceInfo value"), testSpdxPackage.getSourceInfo()); } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#setSourceInfo}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setHomePage}. */ - public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SOURCE_INFO_TEST_VALUE), testSpdxPackage.getSourceInfo()); - testSpdxPackage.setSourceInfo("new sourceInfo value"); - assertEquals(Optional.of("new sourceInfo value"), testSpdxPackage.getSourceInfo()); + assertEquals(Optional.of(HOME_PAGE_TEST_VALUE), testSpdxPackage.getHomePage()); + testSpdxPackage.setHomePage("new homePage value"); + assertEquals(Optional.of("new homePage value"), testSpdxPackage.getHomePage()); } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#setPackageVersion}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setPackageVersion}. */ public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -146,22 +146,22 @@ public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#setHomePage}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setPackageUrl}. */ - public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(HOME_PAGE_TEST_VALUE), testSpdxPackage.getHomePage()); - testSpdxPackage.setHomePage("new homePage value"); - assertEquals(Optional.of("new homePage value"), testSpdxPackage.getHomePage()); + assertEquals(Optional.of(PACKAGE_URL_TEST_VALUE), testSpdxPackage.getPackageUrl()); + testSpdxPackage.setPackageUrl("new packageUrl value"); + assertEquals(Optional.of("new packageUrl value"), testSpdxPackage.getPackageUrl()); } /** - * Test method for {@link org.spdx.library.model.software.SpdxPackage#setPackageUrl}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setDownloadLocation}. */ - public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(PACKAGE_URL_TEST_VALUE), testSpdxPackage.getPackageUrl()); - testSpdxPackage.setPackageUrl("new packageUrl value"); - assertEquals(Optional.of("new packageUrl value"), testSpdxPackage.getPackageUrl()); + assertEquals(Optional.of(DOWNLOAD_LOCATION_TEST_VALUE), testSpdxPackage.getDownloadLocation()); + testSpdxPackage.setDownloadLocation("new downloadLocation value"); + assertEquals(Optional.of("new downloadLocation value"), testSpdxPackage.getDownloadLocation()); } } \ No newline at end of file From c78b3daf1c616a0b4517fcb143880d23d0eeac7f Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sat, 27 Jan 2024 17:26:13 -0800 Subject: [PATCH 23/62] Update generated files Now compiles - unit test are currently failing Signed-off-by: Gary O'Neall --- .../java/org/spdx/library/SpdxConstants.java | 140 +++---- .../org/spdx/library/SpdxEnumFactory.java | 16 +- .../spdx/library/model/v3/ai/AIPackage.java | 347 +++++++++--------- .../model/v3/ai/SafetyRiskAssessmentType.java | 2 +- .../spdx/library/model/v3/build/Build.java | 213 +++++------ .../org/spdx/library/model/v3/core/Agent.java | 6 +- .../library/model/v3/core/Annotation.java | 25 +- .../library/model/v3/core/AnnotationType.java | 2 +- .../spdx/library/model/v3/core/Artifact.java | 181 ++++----- .../org/spdx/library/model/v3/core/Bom.java | 6 +- .../spdx/library/model/v3/core/Bundle.java | 6 +- .../library/model/v3/core/CreationInfo.java | 168 ++++----- .../model/v3/core/DictionaryEntry.java | 68 ++-- .../spdx/library/model/v3/core/Element.java | 214 ++++++----- .../model/v3/core/ElementCollection.java | 72 ++-- .../spdx/library/model/v3/core/Extension.java | 156 ++++++++ .../model/v3/core/ExternalIdentifier.java | 68 ++-- .../model/v3/core/ExternalIdentifierType.java | 2 +- .../library/model/v3/core/ExternalMap.java | 70 ++-- ...xternalReference.java => ExternalRef.java} | 179 +++++---- ...eferenceType.java => ExternalRefType.java} | 78 ++-- .../org/spdx/library/model/v3/core/Hash.java | 6 +- .../library/model/v3/core/HashAlgorithm.java | 2 +- .../model/v3/core/IntegrityMethod.java | 4 +- .../model/v3/core/LifecycleScopeType.java | 2 +- .../v3/core/LifecycleScopedRelationship.java | 6 +- .../library/model/v3/core/Organization.java | 6 +- .../spdx/library/model/v3/core/Person.java | 6 +- .../model/v3/core/PositiveIntegerRange.java | 88 ++--- .../model/v3/{ai => core}/PresenceType.java | 10 +- .../model/v3/core/ProfileIdentifierType.java | 5 +- .../library/model/v3/core/Relationship.java | 172 ++++----- .../v3/core/RelationshipCompleteness.java | 7 +- .../model/v3/core/RelationshipType.java | 4 +- .../library/model/v3/core/SoftwareAgent.java | 6 +- .../library/model/v3/core/SpdxDocument.java | 51 +-- .../org/spdx/library/model/v3/core/Tool.java | 6 +- .../v3/dataset/ConfidentialityLevelType.java | 2 +- .../library/model/v3/dataset/Dataset.java | 245 ++++++------- .../v3/dataset/DatasetAvailabilityType.java | 2 +- .../library/model/v3/dataset/DatasetType.java | 2 +- .../ConjunctiveLicenseSet.java | 20 +- .../CustomLicense.java | 12 +- .../CustomLicenseAddition.java | 12 +- .../DisjunctiveLicenseSet.java | 20 +- .../ExtendableLicense.java | 13 +- .../License.java | 166 +++++---- .../LicenseAddition.java | 88 +++-- .../ListedLicense.java | 64 ++-- .../ListedLicenseException.java | 20 +- .../OrLaterOperator.java | 20 +- .../WithAdditionOperator.java | 29 +- .../CvssV2VulnAssessmentRelationship.java | 80 ++-- .../CvssV3VulnAssessmentRelationship.java | 27 +- .../EpssVulnAssessmentRelationship.java | 8 +- .../model/v3/security/ExploitCatalogType.java | 2 +- ...loitCatalogVulnAssessmentRelationship.java | 8 +- .../model/v3/security/SsvcDecisionType.java | 2 +- .../SsvcVulnAssessmentRelationship.java | 8 +- ...VexAffectedVulnAssessmentRelationship.java | 26 +- .../VexFixedVulnAssessmentRelationship.java | 8 +- .../v3/security/VexJustificationType.java | 2 +- ...NotAffectedVulnAssessmentRelationship.java | 84 ++--- ...vestigationVulnAssessmentRelationship.java | 8 +- .../VexVulnAssessmentRelationship.java | 8 +- .../security/VulnAssessmentRelationship.java | 144 +++----- .../model/v3/security/Vulnerability.java | 139 +++---- .../AnyLicenseInfo.java | 12 +- .../LicenseExpression.java | 91 ++++- .../simplelicensing/SimpleLicensingText.java | 207 +++++++++++ .../DependencyConditionalityType.java | 2 +- .../spdx/library/model/v3/software/Sbom.java | 8 +- .../library/model/v3/software/SbomType.java | 2 +- .../library/model/v3/software/Snippet.java | 67 +++- .../model/v3/software/SoftwareArtifact.java | 145 ++------ .../software/SoftwareDependencyLinkType.java | 2 +- .../SoftwareDependencyRelationship.java | 8 +- .../model/v3/software/SoftwarePurpose.java | 2 +- .../library/model/v3/software/SpdxFile.java | 36 +- .../model/v3/software/SpdxPackage.java | 116 +++--- pom.xml | 20 + .../spdx/library/model/ExternalElement.java | 6 +- .../org/spdx/library/model/ModelObject.java | 2 +- .../library/model/ModelCollectionTest.java | 4 +- .../library/model/ModelObjectForTesting.java | 2 +- .../spdx/library/model/ModelObjectTest.java | 32 +- .../library/model/SimpleUriValueTest.java | 2 +- .../library/model/v3/ai/AIPackageTest.java | 169 ++++----- .../library/model/v3/build/BuildTest.java | 66 ++-- .../spdx/library/model/v3/core/AgentTest.java | 2 +- .../library/model/v3/core/AnnotationTest.java | 21 +- .../library/model/v3/core/ArtifactTest.java | 53 ++- .../spdx/library/model/v3/core/BomTest.java | 2 +- .../library/model/v3/core/BundleTest.java | 2 +- .../model/v3/core/CreationInfoTest.java | 48 +-- .../model/v3/core/DictionaryEntryTest.java | 26 +- .../model/v3/core/ElementCollectionTest.java | 28 +- .../library/model/v3/core/ElementTest.java | 69 ++-- .../library/model/v3/core/ExtensionTest.java | 107 ++++++ .../model/v3/core/ExternalIdentifierTest.java | 26 +- .../model/v3/core/ExternalMapTest.java | 26 +- .../model/v3/core/ExternalRefTest.java | 162 ++++++++ .../model/v3/core/ExternalReferenceTest.java | 162 -------- .../spdx/library/model/v3/core/HashTest.java | 2 +- .../model/v3/core/IntegrityMethodTest.java | 2 +- .../core/LifecycleScopedRelationshipTest.java | 2 +- .../model/v3/core/OrganizationTest.java | 2 +- .../library/model/v3/core/PersonTest.java | 2 +- .../v3/core/PositiveIntegerRangeTest.java | 26 +- .../model/v3/core/RelationshipTest.java | 56 +-- .../model/v3/core/SoftwareAgentTest.java | 2 +- .../model/v3/core/SpdxDocumentTest.java | 14 +- .../spdx/library/model/v3/core/ToolTest.java | 2 +- .../library/model/v3/dataset/DatasetTest.java | 124 ++++--- .../ConjunctiveLicenseSetTest.java | 18 +- .../CustomLicenseAdditionTest.java | 16 +- .../CustomLicenseTest.java | 16 +- .../DisjunctiveLicenseSetTest.java | 18 +- .../ExtendableLicenseTest.java | 16 +- .../LicenseAdditionTest.java | 48 ++- .../LicenseTest.java | 74 ++-- .../ListedLicenseExceptionTest.java | 20 +- .../ListedLicenseTest.java | 40 +- .../OrLaterOperatorTest.java | 18 +- .../WithAdditionOperatorTest.java | 20 +- .../CvssV2VulnAssessmentRelationshipTest.java | 26 +- .../CvssV3VulnAssessmentRelationshipTest.java | 2 +- .../EpssVulnAssessmentRelationshipTest.java | 2 +- ...CatalogVulnAssessmentRelationshipTest.java | 2 +- .../SsvcVulnAssessmentRelationshipTest.java | 2 +- ...ffectedVulnAssessmentRelationshipTest.java | 21 +- ...exFixedVulnAssessmentRelationshipTest.java | 2 +- ...ffectedVulnAssessmentRelationshipTest.java | 26 +- ...igationVulnAssessmentRelationshipTest.java | 2 +- .../VexVulnAssessmentRelationshipTest.java | 2 +- .../VulnAssessmentRelationshipTest.java | 46 +-- .../model/v3/security/VulnerabilityTest.java | 40 +- .../AnyLicenseInfoTest.java | 16 +- .../LicenseExpressionTest.java | 43 ++- .../SimpleLicensingTextTest.java | 119 ++++++ .../library/model/v3/software/SbomTest.java | 2 +- .../model/v3/software/SnippetTest.java | 14 +- .../v3/software/SoftwareArtifactTest.java | 56 +-- .../SoftwareDependencyRelationshipTest.java | 2 +- .../model/v3/software/SpdxFileTest.java | 12 +- .../model/v3/software/SpdxPackageTest.java | 54 +-- 146 files changed, 3498 insertions(+), 2935 deletions(-) create mode 100644 generated/src/main/java/org/spdx/library/model/v3/core/Extension.java rename generated/src/main/java/org/spdx/library/model/v3/core/{ExternalReference.java => ExternalRef.java} (56%) rename generated/src/main/java/org/spdx/library/model/v3/core/{ExternalReferenceType.java => ExternalRefType.java} (85%) rename generated/src/main/java/org/spdx/library/model/v3/{ai => core}/PresenceType.java (87%) rename generated/src/main/java/org/spdx/library/model/v3/{expandedlicense => expandedlicensing}/ConjunctiveLicenseSet.java (90%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/CustomLicense.java (92%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/CustomLicenseAddition.java (93%) rename generated/src/main/java/org/spdx/library/model/v3/{expandedlicense => expandedlicensing}/DisjunctiveLicenseSet.java (90%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/ExtendableLicense.java (91%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/License.java (81%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/LicenseAddition.java (81%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/ListedLicense.java (90%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/ListedLicenseException.java (90%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/OrLaterOperator.java (92%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/WithAdditionOperator.java (90%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => simplelicensing}/AnyLicenseInfo.java (93%) rename generated/src/main/java/org/spdx/library/model/v3/{licensing => simplelicensing}/LicenseExpression.java (69%) create mode 100644 generated/src/main/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingText.java create mode 100644 src/test/java/org/spdx/library/model/v3/core/ExtensionTest.java create mode 100644 src/test/java/org/spdx/library/model/v3/core/ExternalRefTest.java delete mode 100644 src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java rename src/test/java/org/spdx/library/model/v3/{expandedlicense => expandedlicensing}/ConjunctiveLicenseSetTest.java (88%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/CustomLicenseAdditionTest.java (81%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/CustomLicenseTest.java (82%) rename src/test/java/org/spdx/library/model/v3/{expandedlicense => expandedlicensing}/DisjunctiveLicenseSetTest.java (88%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/ExtendableLicenseTest.java (81%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/LicenseAdditionTest.java (75%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/LicenseTest.java (77%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/ListedLicenseExceptionTest.java (82%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/ListedLicenseTest.java (82%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/OrLaterOperatorTest.java (82%) rename src/test/java/org/spdx/library/model/v3/{licensing => expandedlicensing}/WithAdditionOperatorTest.java (81%) rename src/test/java/org/spdx/library/model/v3/{licensing => simplelicensing}/AnyLicenseInfoTest.java (82%) rename src/test/java/org/spdx/library/model/v3/{licensing => simplelicensing}/LicenseExpressionTest.java (62%) create mode 100644 src/test/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingTextTest.java diff --git a/generated/src/main/java/org/spdx/library/SpdxConstants.java b/generated/src/main/java/org/spdx/library/SpdxConstants.java index 8a2b61931..ce015941f 100644 --- a/generated/src/main/java/org/spdx/library/SpdxConstants.java +++ b/generated/src/main/java/org/spdx/library/SpdxConstants.java @@ -92,11 +92,12 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor CORE_PROP_ELEMENT = new PropertyDescriptor("element", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_END = new PropertyDescriptor("end", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_END_TIME = new PropertyDescriptor("endTime", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTENSION = new PropertyDescriptor("extension", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_EXTERNAL_ID = new PropertyDescriptor("externalId", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_EXTERNAL_IDENTIFIER = new PropertyDescriptor("externalIdentifier", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_EXTERNAL_IDENTIFIER_TYPE = new PropertyDescriptor("externalIdentifierType", CORE_NAMESPACE); - public static final PropertyDescriptor CORE_PROP_EXTERNAL_REFERENCE = new PropertyDescriptor("externalReference", CORE_NAMESPACE); - public static final PropertyDescriptor CORE_PROP_EXTERNAL_REFERENCE_TYPE = new PropertyDescriptor("externalReferenceType", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_REF = new PropertyDescriptor("externalRef", CORE_NAMESPACE); + public static final PropertyDescriptor CORE_PROP_EXTERNAL_REF_TYPE = new PropertyDescriptor("externalRefType", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_FROM = new PropertyDescriptor("from", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_HASH_VALUE = new PropertyDescriptor("hashValue", CORE_NAMESPACE); public static final PropertyDescriptor CORE_PROP_IDENTIFIER = new PropertyDescriptor("identifier", CORE_NAMESPACE); @@ -144,30 +145,24 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor DATASET_PROP_SENSOR = new PropertyDescriptor("sensor", DATASET_NAMESPACE); /** - * ExpandedLicense namespace + * ExpandedLicensing namespace */ - public static final String EXPANDED_LICENSE_NAMESPACE = "https://spdx.org/rdf/v3/ExpandedLicense"; - public static final PropertyDescriptor EXPANDED_LICENSE_PROP_MEMBER = new PropertyDescriptor("member", EXPANDED_LICENSE_NAMESPACE); - - /** - * Licensing namespace - */ - public static final String LICENSING_NAMESPACE = "https://spdx.org/rdf/v3/Licensing"; - public static final PropertyDescriptor LICENSING_PROP_ADDITION_TEXT = new PropertyDescriptor("additionText", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_DEPRECATED_VERSION = new PropertyDescriptor("deprecatedVersion", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_IS_DEPRECATED_ADDITION_ID = new PropertyDescriptor("isDeprecatedAdditionId", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_IS_DEPRECATED_LICENSE_ID = new PropertyDescriptor("isDeprecatedLicenseId", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_IS_FSF_LIBRE = new PropertyDescriptor("isFsfLibre", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_IS_OSI_APPROVED = new PropertyDescriptor("isOsiApproved", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_LICENSE_EXPRESSION = new PropertyDescriptor("licenseExpression", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_LICENSE_TEXT = new PropertyDescriptor("licenseText", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_LIST_VERSION_ADDED = new PropertyDescriptor("listVersionAdded", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_OBSOLETED_BY = new PropertyDescriptor("obsoletedBy", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_STANDARD_ADDITION_TEMPLATE = new PropertyDescriptor("standardAdditionTemplate", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_STANDARD_LICENSE_HEADER = new PropertyDescriptor("standardLicenseHeader", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_STANDARD_LICENSE_TEMPLATE = new PropertyDescriptor("standardLicenseTemplate", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_SUBJECT_ADDITION = new PropertyDescriptor("subjectAddition", LICENSING_NAMESPACE); - public static final PropertyDescriptor LICENSING_PROP_SUBJECT_LICENSE = new PropertyDescriptor("subjectLicense", LICENSING_NAMESPACE); + public static final String EXPANDED_LICENSING_NAMESPACE = "https://spdx.org/rdf/v3/ExpandedLicensing"; + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_ADDITION_TEXT = new PropertyDescriptor("additionText", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_DEPRECATED_VERSION = new PropertyDescriptor("deprecatedVersion", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_IS_DEPRECATED_ADDITION_ID = new PropertyDescriptor("isDeprecatedAdditionId", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_IS_DEPRECATED_LICENSE_ID = new PropertyDescriptor("isDeprecatedLicenseId", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_IS_FSF_LIBRE = new PropertyDescriptor("isFsfLibre", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_IS_OSI_APPROVED = new PropertyDescriptor("isOsiApproved", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_LICENSE_XML = new PropertyDescriptor("licenseXml", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_LIST_VERSION_ADDED = new PropertyDescriptor("listVersionAdded", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_MEMBER = new PropertyDescriptor("member", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_OBSOLETED_BY = new PropertyDescriptor("obsoletedBy", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_STANDARD_ADDITION_TEMPLATE = new PropertyDescriptor("standardAdditionTemplate", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_STANDARD_LICENSE_HEADER = new PropertyDescriptor("standardLicenseHeader", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_STANDARD_LICENSE_TEMPLATE = new PropertyDescriptor("standardLicenseTemplate", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_SUBJECT_ADDITION = new PropertyDescriptor("subjectAddition", EXPANDED_LICENSING_NAMESPACE); + public static final PropertyDescriptor EXPANDED_LICENSING_PROP_SUBJECT_LICENSE = new PropertyDescriptor("subjectLicense", EXPANDED_LICENSING_NAMESPACE); /** * Security namespace @@ -194,6 +189,15 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor SECURITY_PROP_VEX_VERSION = new PropertyDescriptor("vexVersion", SECURITY_NAMESPACE); public static final PropertyDescriptor SECURITY_PROP_WITHDRAWN_TIME = new PropertyDescriptor("withdrawnTime", SECURITY_NAMESPACE); + /** + * SimpleLicensing namespace + */ + public static final String SIMPLE_LICENSING_NAMESPACE = "https://spdx.org/rdf/v3/SimpleLicensing"; + public static final PropertyDescriptor SIMPLE_LICENSING_PROP_CUSTOM_ID_TO_URI = new PropertyDescriptor("customIdToUri", SIMPLE_LICENSING_NAMESPACE); + public static final PropertyDescriptor SIMPLE_LICENSING_PROP_LICENSE_EXPRESSION = new PropertyDescriptor("licenseExpression", SIMPLE_LICENSING_NAMESPACE); + public static final PropertyDescriptor SIMPLE_LICENSING_PROP_LICENSE_LIST_VERSION = new PropertyDescriptor("licenseListVersion", SIMPLE_LICENSING_NAMESPACE); + public static final PropertyDescriptor SIMPLE_LICENSING_PROP_LICENSE_TEXT = new PropertyDescriptor("licenseText", SIMPLE_LICENSING_NAMESPACE); + /** * Software namespace */ @@ -201,12 +205,10 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor SOFTWARE_PROP_ADDITIONAL_PURPOSE = new PropertyDescriptor("additionalPurpose", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_ATTRIBUTION_TEXT = new PropertyDescriptor("attributionText", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_BYTE_RANGE = new PropertyDescriptor("byteRange", SOFTWARE_NAMESPACE); - public static final PropertyDescriptor SOFTWARE_PROP_CONCLUDED_LICENSE = new PropertyDescriptor("concludedLicense", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_CONDITIONALITY = new PropertyDescriptor("conditionality", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_CONTENT_IDENTIFIER = new PropertyDescriptor("contentIdentifier", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_CONTENT_TYPE = new PropertyDescriptor("contentType", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_COPYRIGHT_TEXT = new PropertyDescriptor("copyrightText", SOFTWARE_NAMESPACE); - public static final PropertyDescriptor SOFTWARE_PROP_DECLARED_LICENSE = new PropertyDescriptor("declaredLicense", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_DOWNLOAD_LOCATION = new PropertyDescriptor("downloadLocation", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_HOME_PAGE = new PropertyDescriptor("homePage", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_LINE_RANGE = new PropertyDescriptor("lineRange", SOFTWARE_NAMESPACE); @@ -214,63 +216,67 @@ public static SpdxMajorVersion latestVersion() { public static final PropertyDescriptor SOFTWARE_PROP_PACKAGE_VERSION = new PropertyDescriptor("packageVersion", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_PRIMARY_PURPOSE = new PropertyDescriptor("primaryPurpose", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_SBOM_TYPE = new PropertyDescriptor("sbomType", SOFTWARE_NAMESPACE); + public static final PropertyDescriptor SOFTWARE_PROP_SNIPPET_FROM_FILE = new PropertyDescriptor("snippetFromFile", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_SOFTWARE_LINKAGE = new PropertyDescriptor("softwareLinkage", SOFTWARE_NAMESPACE); public static final PropertyDescriptor SOFTWARE_PROP_SOURCE_INFO = new PropertyDescriptor("sourceInfo", SOFTWARE_NAMESPACE); // class types public static final String CORE_DICTIONARY_ENTRY = "Core.DictionaryEntry"; + public static final String SIMPLE_LICENSING_LICENSE_EXPRESSION = "SimpleLicensing.LicenseExpression"; public static final String DATASET_CONFIDENTIALITY_LEVEL_TYPE = "Dataset.ConfidentialityLevelType"; - public static final String CORE_BOM = "Core.Bom"; public static final String A_I_SAFETY_RISK_ASSESSMENT_TYPE = "AI.SafetyRiskAssessmentType"; - public static final String LICENSING_LICENSE_EXPRESSION = "Licensing.LicenseExpression"; - public static final String LICENSING_CUSTOM_LICENSE_ADDITION = "Licensing.CustomLicenseAddition"; + public static final String CORE_BOM = "Core.Bom"; + public static final String EXPANDED_LICENSING_OR_LATER_OPERATOR = "ExpandedLicensing.OrLaterOperator"; + public static final String SIMPLE_LICENSING_SIMPLE_LICENSING_TEXT = "SimpleLicensing.SimpleLicensingText"; + public static final String EXPANDED_LICENSING_LICENSE = "ExpandedLicensing.License"; public static final String CORE_ANNOTATION = "Core.Annotation"; public static final String SOFTWARE_SPDX_FILE = "Software.SpdxFile"; + public static final String EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION = "ExpandedLicensing.ListedLicenseException"; + public static final String EXPANDED_LICENSING_LICENSE_ADDITION = "ExpandedLicensing.LicenseAddition"; public static final String SOFTWARE_SOFTWARE_ARTIFACT = "Software.SoftwareArtifact"; public static final String SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexAffectedVulnAssessmentRelationship"; public static final String DATASET_DATASET = "Dataset.Dataset"; public static final String SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP = "Security.SsvcVulnAssessmentRelationship"; - public static final String LICENSING_LISTED_LICENSE = "Licensing.ListedLicense"; public static final String CORE_INTEGRITY_METHOD = "Core.IntegrityMethod"; public static final String SOFTWARE_SNIPPET = "Software.Snippet"; - public static final String LICENSING_LICENSE_ADDITION = "Licensing.LicenseAddition"; + public static final String CORE_EXTENSION = "Core.Extension"; public static final String SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP = "Security.EpssVulnAssessmentRelationship"; - public static final String LICENSING_EXTENDABLE_LICENSE = "Licensing.ExtendableLicense"; - public static final String EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET = "ExpandedLicense.ConjunctiveLicenseSet"; - public static final String LICENSING_WITH_ADDITION_OPERATOR = "Licensing.WithAdditionOperator"; public static final String SOFTWARE_SBOM_TYPE = "Software.SbomType"; public static final String CORE_TOOL = "Core.Tool"; + public static final String CORE_EXTERNAL_REF = "Core.ExternalRef"; public static final String CORE_EXTERNAL_IDENTIFIER = "Core.ExternalIdentifier"; public static final String CORE_ELEMENT_COLLECTION = "Core.ElementCollection"; public static final String CORE_ANNOTATION_TYPE = "Core.AnnotationType"; public static final String SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP = "Software.SoftwareDependencyRelationship"; public static final String SECURITY_VEX_JUSTIFICATION_TYPE = "Security.VexJustificationType"; public static final String A_I_A_I_PACKAGE = "AI.AIPackage"; - public static final String LICENSING_ANY_LICENSE_INFO = "Licensing.AnyLicenseInfo"; + public static final String EXPANDED_LICENSING_CONJUNCTIVE_LICENSE_SET = "ExpandedLicensing.ConjunctiveLicenseSet"; + public static final String CORE_EXTERNAL_REF_TYPE = "Core.ExternalRefType"; public static final String SECURITY_EXPLOIT_CATALOG_TYPE = "Security.ExploitCatalogType"; - public static final String LICENSING_LISTED_LICENSE_EXCEPTION = "Licensing.ListedLicenseException"; - public static final String A_I_PRESENCE_TYPE = "AI.PresenceType"; public static final String SOFTWARE_SOFTWARE_PURPOSE = "Software.SoftwarePurpose"; + public static final String EXPANDED_LICENSING_CUSTOM_LICENSE_ADDITION = "ExpandedLicensing.CustomLicenseAddition"; public static final String CORE_ELEMENT = "Core.Element"; public static final String CORE_PERSON = "Core.Person"; public static final String SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE = "Software.DependencyConditionalityType"; public static final String DATASET_DATASET_AVAILABILITY_TYPE = "Dataset.DatasetAvailabilityType"; - public static final String LICENSING_OR_LATER_OPERATOR = "Licensing.OrLaterOperator"; public static final String CORE_EXTERNAL_MAP = "Core.ExternalMap"; - public static final String LICENSING_LICENSE = "Licensing.License"; + public static final String EXPANDED_LICENSING_LISTED_LICENSE = "ExpandedLicensing.ListedLicense"; public static final String SECURITY_VULN_ASSESSMENT_RELATIONSHIP = "Security.VulnAssessmentRelationship"; public static final String CORE_AGENT = "Core.Agent"; public static final String SOFTWARE_SPDX_PACKAGE = "Software.SpdxPackage"; public static final String CORE_EXTERNAL_IDENTIFIER_TYPE = "Core.ExternalIdentifierType"; public static final String SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE = "Software.SoftwareDependencyLinkType"; public static final String CORE_POSITIVE_INTEGER_RANGE = "Core.PositiveIntegerRange"; + public static final String CORE_PRESENCE_TYPE = "Core.PresenceType"; + public static final String EXPANDED_LICENSING_DISJUNCTIVE_LICENSE_SET = "ExpandedLicensing.DisjunctiveLicenseSet"; public static final String CORE_HASH = "Core.Hash"; public static final String DATASET_DATASET_TYPE = "Dataset.DatasetType"; - public static final String CORE_EXTERNAL_REFERENCE = "Core.ExternalReference"; + public static final String EXPANDED_LICENSING_CUSTOM_LICENSE = "ExpandedLicensing.CustomLicense"; public static final String CORE_SPDX_DOCUMENT = "Core.SpdxDocument"; + public static final String SIMPLE_LICENSING_ANY_LICENSE_INFO = "SimpleLicensing.AnyLicenseInfo"; public static final String SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexVulnAssessmentRelationship"; public static final String SECURITY_CVSS_V2_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV2VulnAssessmentRelationship"; - public static final String EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET = "ExpandedLicense.DisjunctiveLicenseSet"; + public static final String EXPANDED_LICENSING_WITH_ADDITION_OPERATOR = "ExpandedLicensing.WithAdditionOperator"; public static final String CORE_BUNDLE = "Core.Bundle"; public static final String SOFTWARE_SBOM = "Software.Sbom"; public static final String CORE_LIFECYCLE_SCOPE_TYPE = "Core.LifecycleScopeType"; @@ -283,7 +289,6 @@ public static SpdxMajorVersion latestVersion() { public static final String SECURITY_CVSS_V3_VULN_ASSESSMENT_RELATIONSHIP = "Security.CvssV3VulnAssessmentRelationship"; public static final String CORE_ORGANIZATION = "Core.Organization"; public static final String CORE_RELATIONSHIP = "Core.Relationship"; - public static final String LICENSING_CUSTOM_LICENSE = "Licensing.CustomLicense"; public static final String CORE_RELATIONSHIP_TYPE = "Core.RelationshipType"; public static final String CORE_RELATIONSHIP_COMPLETENESS = "Core.RelationshipCompleteness"; public static final String CORE_ARTIFACT = "Core.Artifact"; @@ -291,33 +296,34 @@ public static SpdxMajorVersion latestVersion() { public static final String SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP = "Security.VexNotAffectedVulnAssessmentRelationship"; public static final String CORE_PROFILE_IDENTIFIER_TYPE = "Core.ProfileIdentifierType"; public static final String BUILD_BUILD = "Build.Build"; + public static final String EXPANDED_LICENSING_EXTENDABLE_LICENSE = "ExpandedLicensing.ExtendableLicense"; public static final String SECURITY_SSVC_DECISION_TYPE = "Security.SsvcDecisionType"; public static final String SECURITY_VULNERABILITY = "Security.Vulnerability"; - public static final String CORE_EXTERNAL_REFERENCE_TYPE = "Core.ExternalReferenceType"; - public static final String[] ALL_SPDX_CLASSES = {CORE_DICTIONARY_ENTRY, DATASET_CONFIDENTIALITY_LEVEL_TYPE, - CORE_BOM, A_I_SAFETY_RISK_ASSESSMENT_TYPE, LICENSING_LICENSE_EXPRESSION, - LICENSING_CUSTOM_LICENSE_ADDITION, CORE_ANNOTATION, SOFTWARE_SPDX_FILE, - SOFTWARE_SOFTWARE_ARTIFACT, SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, - DATASET_DATASET, SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP, LICENSING_LISTED_LICENSE, - CORE_INTEGRITY_METHOD, SOFTWARE_SNIPPET, LICENSING_LICENSE_ADDITION, SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP, - LICENSING_EXTENDABLE_LICENSE, EXPANDED_LICENSE_CONJUNCTIVE_LICENSE_SET, - LICENSING_WITH_ADDITION_OPERATOR, SOFTWARE_SBOM_TYPE, CORE_TOOL, CORE_EXTERNAL_IDENTIFIER, + public static final String[] ALL_SPDX_CLASSES = {CORE_DICTIONARY_ENTRY, SIMPLE_LICENSING_LICENSE_EXPRESSION, + DATASET_CONFIDENTIALITY_LEVEL_TYPE, A_I_SAFETY_RISK_ASSESSMENT_TYPE, CORE_BOM, + EXPANDED_LICENSING_OR_LATER_OPERATOR, SIMPLE_LICENSING_SIMPLE_LICENSING_TEXT, + EXPANDED_LICENSING_LICENSE, CORE_ANNOTATION, SOFTWARE_SPDX_FILE, EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION, + EXPANDED_LICENSING_LICENSE_ADDITION, SOFTWARE_SOFTWARE_ARTIFACT, SECURITY_VEX_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, + DATASET_DATASET, SECURITY_SSVC_VULN_ASSESSMENT_RELATIONSHIP, CORE_INTEGRITY_METHOD, + SOFTWARE_SNIPPET, CORE_EXTENSION, SECURITY_EPSS_VULN_ASSESSMENT_RELATIONSHIP, + SOFTWARE_SBOM_TYPE, CORE_TOOL, CORE_EXTERNAL_REF, CORE_EXTERNAL_IDENTIFIER, CORE_ELEMENT_COLLECTION, CORE_ANNOTATION_TYPE, SOFTWARE_SOFTWARE_DEPENDENCY_RELATIONSHIP, - SECURITY_VEX_JUSTIFICATION_TYPE, A_I_A_I_PACKAGE, LICENSING_ANY_LICENSE_INFO, - SECURITY_EXPLOIT_CATALOG_TYPE, LICENSING_LISTED_LICENSE_EXCEPTION, A_I_PRESENCE_TYPE, - SOFTWARE_SOFTWARE_PURPOSE, CORE_ELEMENT, CORE_PERSON, SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE, - DATASET_DATASET_AVAILABILITY_TYPE, LICENSING_OR_LATER_OPERATOR, CORE_EXTERNAL_MAP, - LICENSING_LICENSE, SECURITY_VULN_ASSESSMENT_RELATIONSHIP, CORE_AGENT, SOFTWARE_SPDX_PACKAGE, - CORE_EXTERNAL_IDENTIFIER_TYPE, SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE, - CORE_POSITIVE_INTEGER_RANGE, CORE_HASH, DATASET_DATASET_TYPE, CORE_EXTERNAL_REFERENCE, - CORE_SPDX_DOCUMENT, SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_CVSS_V2_VULN_ASSESSMENT_RELATIONSHIP, - EXPANDED_LICENSE_DISJUNCTIVE_LICENSE_SET, CORE_BUNDLE, SOFTWARE_SBOM, CORE_LIFECYCLE_SCOPE_TYPE, - SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP, SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP, - CORE_HASH_ALGORITHM, SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP, + SECURITY_VEX_JUSTIFICATION_TYPE, A_I_A_I_PACKAGE, EXPANDED_LICENSING_CONJUNCTIVE_LICENSE_SET, + CORE_EXTERNAL_REF_TYPE, SECURITY_EXPLOIT_CATALOG_TYPE, SOFTWARE_SOFTWARE_PURPOSE, + EXPANDED_LICENSING_CUSTOM_LICENSE_ADDITION, CORE_ELEMENT, CORE_PERSON, + SOFTWARE_DEPENDENCY_CONDITIONALITY_TYPE, DATASET_DATASET_AVAILABILITY_TYPE, + CORE_EXTERNAL_MAP, EXPANDED_LICENSING_LISTED_LICENSE, SECURITY_VULN_ASSESSMENT_RELATIONSHIP, + CORE_AGENT, SOFTWARE_SPDX_PACKAGE, CORE_EXTERNAL_IDENTIFIER_TYPE, SOFTWARE_SOFTWARE_DEPENDENCY_LINK_TYPE, + CORE_POSITIVE_INTEGER_RANGE, CORE_PRESENCE_TYPE, EXPANDED_LICENSING_DISJUNCTIVE_LICENSE_SET, + CORE_HASH, DATASET_DATASET_TYPE, EXPANDED_LICENSING_CUSTOM_LICENSE, CORE_SPDX_DOCUMENT, + SIMPLE_LICENSING_ANY_LICENSE_INFO, SECURITY_VEX_VULN_ASSESSMENT_RELATIONSHIP, + SECURITY_CVSS_V2_VULN_ASSESSMENT_RELATIONSHIP, EXPANDED_LICENSING_WITH_ADDITION_OPERATOR, + CORE_BUNDLE, SOFTWARE_SBOM, CORE_LIFECYCLE_SCOPE_TYPE, SECURITY_VEX_UNDER_INVESTIGATION_VULN_ASSESSMENT_RELATIONSHIP, + SECURITY_VEX_FIXED_VULN_ASSESSMENT_RELATIONSHIP, CORE_HASH_ALGORITHM, SECURITY_EXPLOIT_CATALOG_VULN_ASSESSMENT_RELATIONSHIP, CORE_SOFTWARE_AGENT, CORE_CREATION_INFO, SECURITY_CVSS_V3_VULN_ASSESSMENT_RELATIONSHIP, - CORE_ORGANIZATION, CORE_RELATIONSHIP, LICENSING_CUSTOM_LICENSE, CORE_RELATIONSHIP_TYPE, - CORE_RELATIONSHIP_COMPLETENESS, CORE_ARTIFACT, CORE_LIFECYCLE_SCOPED_RELATIONSHIP, - SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, CORE_PROFILE_IDENTIFIER_TYPE, - BUILD_BUILD, SECURITY_SSVC_DECISION_TYPE, SECURITY_VULNERABILITY, CORE_EXTERNAL_REFERENCE_TYPE}; + CORE_ORGANIZATION, CORE_RELATIONSHIP, CORE_RELATIONSHIP_TYPE, CORE_RELATIONSHIP_COMPLETENESS, + CORE_ARTIFACT, CORE_LIFECYCLE_SCOPED_RELATIONSHIP, SECURITY_VEX_NOT_AFFECTED_VULN_ASSESSMENT_RELATIONSHIP, + CORE_PROFILE_IDENTIFIER_TYPE, BUILD_BUILD, EXPANDED_LICENSING_EXTENDABLE_LICENSE, + SECURITY_SSVC_DECISION_TYPE, SECURITY_VULNERABILITY}; } diff --git a/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java b/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java index 94ce6192e..68ced9888 100644 --- a/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java +++ b/generated/src/main/java/org/spdx/library/SpdxEnumFactory.java @@ -22,13 +22,13 @@ import java.util.HashMap; import java.util.Map; -import org.spdx.library.model.v3.ai.PresenceType; import org.spdx.library.model.v3.ai.SafetyRiskAssessmentType; import org.spdx.library.model.v3.core.AnnotationType; import org.spdx.library.model.v3.core.ExternalIdentifierType; -import org.spdx.library.model.v3.core.ExternalReferenceType; +import org.spdx.library.model.v3.core.ExternalRefType; import org.spdx.library.model.v3.core.HashAlgorithm; import org.spdx.library.model.v3.core.LifecycleScopeType; +import org.spdx.library.model.v3.core.PresenceType; import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.RelationshipCompleteness; import org.spdx.library.model.v3.core.RelationshipType; @@ -79,11 +79,11 @@ public class SpdxEnumFactory { map.put(enumVal.getIndividualURI(), enumVal); } - for (ExploitCatalogType enumVal:ExploitCatalogType.values()) { + for (ExternalRefType enumVal:ExternalRefType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - for (PresenceType enumVal:PresenceType.values()) { + for (ExploitCatalogType enumVal:ExploitCatalogType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } @@ -107,6 +107,10 @@ public class SpdxEnumFactory { map.put(enumVal.getIndividualURI(), enumVal); } + for (PresenceType enumVal:PresenceType.values()) { + map.put(enumVal.getIndividualURI(), enumVal); + } + for (DatasetType enumVal:DatasetType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } @@ -134,10 +138,6 @@ public class SpdxEnumFactory { for (SsvcDecisionType enumVal:SsvcDecisionType.values()) { map.put(enumVal.getIndividualURI(), enumVal); } - - for (ExternalReferenceType enumVal:ExternalReferenceType.values()) { - map.put(enumVal.getIndividualURI(), enumVal); - } uriToEnum = Collections.unmodifiableMap(map); } diff --git a/generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java b/generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java index a84598e2c..acceb0e2c 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java +++ b/generated/src/main/java/org/spdx/library/model/v3/ai/AIPackage.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -36,8 +36,9 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.DictionaryEntry; +import org.spdx.library.model.v3.core.PresenceType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.library.model.v3.software.SpdxPackage; /** @@ -54,14 +55,14 @@ */ public class AIPackage extends SpdxPackage { - Collection hyperparameters; - Collection metricDecisionThresholds; Collection metrics; - Collection typeOfModels; - Collection modelDataPreprocessings; + Collection metricDecisionThresholds; + Collection hyperparameters; + Collection domains; Collection standardCompliances; Collection modelExplainabilitys; - Collection domains; + Collection typeOfModels; + Collection modelDataPreprocessings; /** * Create the AIPackage with default model store and generated anonymous ID @@ -90,14 +91,14 @@ public AIPackage(String objectUri) throws InvalidSPDXAnalysisException { public AIPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); - metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); - typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); - modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); + hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); + domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); modelExplainabilitys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_EXPLAINABILITY, String.class); - domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); + typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); + modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); } /** @@ -108,29 +109,29 @@ public AIPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopyMa @SuppressWarnings("unchecked") protected AIPackage(AIPackageBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); - metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); metrics = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC, DictionaryEntry.class); - typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); - modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); + metricDecisionThresholds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_METRIC_DECISION_THRESHOLD, DictionaryEntry.class); + hyperparameters = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_HYPERPARAMETER, DictionaryEntry.class); + domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); standardCompliances = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_STANDARD_COMPLIANCE, String.class); modelExplainabilitys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_EXPLAINABILITY, String.class); - domains = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_DOMAIN, String.class); - getHyperparameters().addAll(builder.hyperparameters); - getMetricDecisionThresholds().addAll(builder.metricDecisionThresholds); + typeOfModels = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_TYPE_OF_MODEL, String.class); + modelDataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.A_I_PROP_MODEL_DATA_PREPROCESSING, String.class); getMetrics().addAll(builder.metrics); - getTypeOfModels().addAll(builder.typeOfModels); - getModelDataPreprocessings().addAll(builder.modelDataPreprocessings); + getMetricDecisionThresholds().addAll(builder.metricDecisionThresholds); + getHyperparameters().addAll(builder.hyperparameters); + getDomains().addAll(builder.domains); getStandardCompliances().addAll(builder.standardCompliances); getModelExplainabilitys().addAll(builder.modelExplainabilitys); - getDomains().addAll(builder.domains); - setSensitivePersonalInformation(builder.sensitivePersonalInformation); + getTypeOfModels().addAll(builder.typeOfModels); + getModelDataPreprocessings().addAll(builder.modelDataPreprocessings); setSafetyRiskAssessment(builder.safetyRiskAssessment); setAutonomyType(builder.autonomyType); + setSensitivePersonalInformation(builder.sensitivePersonalInformation); setLimitation(builder.limitation); - setEnergyConsumption(builder.energyConsumption); setInformationAboutApplication(builder.informationAboutApplication); setInformationAboutTraining(builder.informationAboutTraining); + setEnergyConsumption(builder.energyConsumption); } /* (non-Javadoc) @@ -142,20 +143,17 @@ public String getType() { } // Getters and Setters - public Collection getHyperparameters() { - return hyperparameters; + public Collection getMetrics() { + return metrics; } public Collection getMetricDecisionThresholds() { return metricDecisionThresholds; } - public Collection getMetrics() { - return metrics; - } - public Collection getTypeOfModels() { - return typeOfModels; + public Collection getHyperparameters() { + return hyperparameters; } - public Collection getModelDataPreprocessings() { - return modelDataPreprocessings; + public Collection getDomains() { + return domains; } public Collection getStandardCompliances() { return standardCompliances; @@ -163,67 +161,70 @@ public Collection getStandardCompliances() { public Collection getModelExplainabilitys() { return modelExplainabilitys; } - public Collection getDomains() { - return domains; + public Collection getTypeOfModels() { + return typeOfModels; + } + public Collection getModelDataPreprocessings() { + return modelDataPreprocessings; } /** - * @return the sensitivePersonalInformation + * @return the safetyRiskAssessment */ @SuppressWarnings("unchecked") - public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_SENSITIVE_PERSONAL_INFORMATION); + public Optional getSafetyRiskAssessment() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_SAFETY_RISK_ASSESSMENT); if (retval.isPresent()) { - if (!(retval.get() instanceof PresenceType)) { + if (!(retval.get() instanceof SafetyRiskAssessmentType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } /** - * @param sensitivePersonalInformation the sensitivePersonalInformation to set + * @param safetyRiskAssessment the safetyRiskAssessment to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public AIPackage setSensitivePersonalInformation(@Nullable PresenceType sensitivePersonalInformation) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.A_I_PROP_SENSITIVE_PERSONAL_INFORMATION, sensitivePersonalInformation); + public AIPackage setSafetyRiskAssessment(@Nullable SafetyRiskAssessmentType safetyRiskAssessment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_SAFETY_RISK_ASSESSMENT, safetyRiskAssessment); return this; } /** - * @return the safetyRiskAssessment + * @return the autonomyType */ @SuppressWarnings("unchecked") - public Optional getSafetyRiskAssessment() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_SAFETY_RISK_ASSESSMENT); + public Optional getAutonomyType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_AUTONOMY_TYPE); if (retval.isPresent()) { - if (!(retval.get() instanceof SafetyRiskAssessmentType)) { + if (!(retval.get() instanceof PresenceType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } /** - * @param safetyRiskAssessment the safetyRiskAssessment to set + * @param autonomyType the autonomyType to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public AIPackage setSafetyRiskAssessment(@Nullable SafetyRiskAssessmentType safetyRiskAssessment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.A_I_PROP_SAFETY_RISK_ASSESSMENT, safetyRiskAssessment); + public AIPackage setAutonomyType(@Nullable PresenceType autonomyType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_AUTONOMY_TYPE, autonomyType); return this; } /** - * @return the autonomyType + * @return the sensitivePersonalInformation */ @SuppressWarnings("unchecked") - public Optional getAutonomyType() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_AUTONOMY_TYPE); + public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.A_I_PROP_SENSITIVE_PERSONAL_INFORMATION); if (retval.isPresent()) { if (!(retval.get() instanceof PresenceType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -234,12 +235,12 @@ public Optional getAutonomyType() throws InvalidSPDXAnalysisExcept } } /** - * @param autonomyType the autonomyType to set + * @param sensitivePersonalInformation the sensitivePersonalInformation to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public AIPackage setAutonomyType(@Nullable PresenceType autonomyType) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.A_I_PROP_AUTONOMY_TYPE, autonomyType); + public AIPackage setSensitivePersonalInformation(@Nullable PresenceType sensitivePersonalInformation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_SENSITIVE_PERSONAL_INFORMATION, sensitivePersonalInformation); return this; } @@ -259,22 +260,6 @@ public AIPackage setLimitation(@Nullable String limitation) throws InvalidSPDXAn return this; } - /** - * @return the energyConsumption - */ - public Optional getEnergyConsumption() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.A_I_PROP_ENERGY_CONSUMPTION); - } - /** - * @param energyConsumption the energyConsumption to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public AIPackage setEnergyConsumption(@Nullable String energyConsumption) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.A_I_PROP_ENERGY_CONSUMPTION, energyConsumption); - return this; - } - /** * @return the informationAboutApplication */ @@ -306,6 +291,22 @@ public AIPackage setInformationAboutTraining(@Nullable String informationAboutTr setPropertyValue(SpdxConstants.A_I_PROP_INFORMATION_ABOUT_TRAINING, informationAboutTraining); return this; } + + /** + * @return the energyConsumption + */ + public Optional getEnergyConsumption() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.A_I_PROP_ENERGY_CONSUMPTION); + } + /** + * @param energyConsumption the energyConsumption to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public AIPackage setEnergyConsumption(@Nullable String energyConsumption) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.A_I_PROP_ENERGY_CONSUMPTION, energyConsumption); + return this; + } @Override @@ -317,15 +318,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - try { - @SuppressWarnings("unused") - Optional sensitivePersonalInformation = getSensitivePersonalInformation(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting sensitivePersonalInformation for AIPackage: "+e.getMessage()); - } + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional safetyRiskAssessment = getSafetyRiskAssessment(); @@ -340,15 +335,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional limitation = getLimitation(); + Optional sensitivePersonalInformation = getSensitivePersonalInformation(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting limitation for AIPackage: "+e.getMessage()); + retval.add("Error getting sensitivePersonalInformation for AIPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional energyConsumption = getEnergyConsumption(); + Optional limitation = getLimitation(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting energyConsumption for AIPackage: "+e.getMessage()); + retval.add("Error getting limitation for AIPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -362,14 +357,20 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting informationAboutTraining for AIPackage: "+e.getMessage()); } - for (DictionaryEntry hyperparameter:hyperparameters) { - retval.addAll(hyperparameter.verify(verifiedIds, specVersion, profiles)); + try { + @SuppressWarnings("unused") + Optional energyConsumption = getEnergyConsumption(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting energyConsumption for AIPackage: "+e.getMessage()); + } + for (DictionaryEntry metric:metrics) { + retval.addAll(metric.verify(verifiedIds, specVersionForVerify, profiles)); } for (DictionaryEntry metricDecisionThreshold:metricDecisionThresholds) { - retval.addAll(metricDecisionThreshold.verify(verifiedIds, specVersion, profiles)); + retval.addAll(metricDecisionThreshold.verify(verifiedIds, specVersionForVerify, profiles)); } - for (DictionaryEntry metric:metrics) { - retval.addAll(metric.verify(verifiedIds, specVersion, profiles)); + for (DictionaryEntry hyperparameter:hyperparameters) { + retval.addAll(hyperparameter.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -406,43 +407,43 @@ public AIPackageBuilder(IModelStore modelStore, String objectUri, @Nullable Mode super(modelStore, objectUri, copyManager); } - Collection hyperparameters = new ArrayList<>(); - Collection metricDecisionThresholds = new ArrayList<>(); Collection metrics = new ArrayList<>(); - Collection typeOfModels = new ArrayList<>(); - Collection modelDataPreprocessings = new ArrayList<>(); + Collection metricDecisionThresholds = new ArrayList<>(); + Collection hyperparameters = new ArrayList<>(); + Collection domains = new ArrayList<>(); Collection standardCompliances = new ArrayList<>(); Collection modelExplainabilitys = new ArrayList<>(); - Collection domains = new ArrayList<>(); - PresenceType sensitivePersonalInformation = null; + Collection typeOfModels = new ArrayList<>(); + Collection modelDataPreprocessings = new ArrayList<>(); SafetyRiskAssessmentType safetyRiskAssessment = null; PresenceType autonomyType = null; + PresenceType sensitivePersonalInformation = null; String limitation = null; - String energyConsumption = null; String informationAboutApplication = null; String informationAboutTraining = null; + String energyConsumption = null; /** - * Adds a hyperparameter to the initial collection - * @parameter hyperparameter hyperparameter to add + * Adds a metric to the initial collection + * @parameter metric metric to add * @return this for chaining **/ - public AIPackageBuilder addHyperparameter(DictionaryEntry hyperparameter) { - if (Objects.nonNull(hyperparameter)) { - hyperparameters.add(hyperparameter); + public AIPackageBuilder addMetric(DictionaryEntry metric) { + if (Objects.nonNull(metric)) { + metrics.add(metric); } return this; } /** - * Adds all elements from a collection to the initial hyperparameter collection - * @parameter hyperparameterCollection collection to initialize the hyperparameter + * Adds all elements from a collection to the initial metric collection + * @parameter metricCollection collection to initialize the metric * @return this for chaining **/ - public AIPackageBuilder addAllHyperparameter(Collection hyperparameterCollection) { - if (Objects.nonNull(hyperparameterCollection)) { - hyperparameters.addAll(hyperparameterCollection); + public AIPackageBuilder addAllMetric(Collection metricCollection) { + if (Objects.nonNull(metricCollection)) { + metrics.addAll(metricCollection); } return this; } @@ -472,73 +473,49 @@ public AIPackageBuilder addAllMetricDecisionThreshold(Collection metricCollection) { - if (Objects.nonNull(metricCollection)) { - metrics.addAll(metricCollection); - } - return this; - } - - /** - * Adds a typeOfModel to the initial collection - * @parameter typeOfModel typeOfModel to add + * Adds a hyperparameter to the initial collection + * @parameter hyperparameter hyperparameter to add * @return this for chaining **/ - public AIPackageBuilder addTypeOfModel(String typeOfModel) { - if (Objects.nonNull(typeOfModel)) { - typeOfModels.add(typeOfModel); + public AIPackageBuilder addHyperparameter(DictionaryEntry hyperparameter) { + if (Objects.nonNull(hyperparameter)) { + hyperparameters.add(hyperparameter); } return this; } /** - * Adds all elements from a collection to the initial typeOfModel collection - * @parameter typeOfModelCollection collection to initialize the typeOfModel + * Adds all elements from a collection to the initial hyperparameter collection + * @parameter hyperparameterCollection collection to initialize the hyperparameter * @return this for chaining **/ - public AIPackageBuilder addAllTypeOfModel(Collection typeOfModelCollection) { - if (Objects.nonNull(typeOfModelCollection)) { - typeOfModels.addAll(typeOfModelCollection); + public AIPackageBuilder addAllHyperparameter(Collection hyperparameterCollection) { + if (Objects.nonNull(hyperparameterCollection)) { + hyperparameters.addAll(hyperparameterCollection); } return this; } /** - * Adds a modelDataPreprocessing to the initial collection - * @parameter modelDataPreprocessing modelDataPreprocessing to add + * Adds a domain to the initial collection + * @parameter domain domain to add * @return this for chaining **/ - public AIPackageBuilder addModelDataPreprocessing(String modelDataPreprocessing) { - if (Objects.nonNull(modelDataPreprocessing)) { - modelDataPreprocessings.add(modelDataPreprocessing); + public AIPackageBuilder addDomain(String domain) { + if (Objects.nonNull(domain)) { + domains.add(domain); } return this; } /** - * Adds all elements from a collection to the initial modelDataPreprocessing collection - * @parameter modelDataPreprocessingCollection collection to initialize the modelDataPreprocessing + * Adds all elements from a collection to the initial domain collection + * @parameter domainCollection collection to initialize the domain * @return this for chaining **/ - public AIPackageBuilder addAllModelDataPreprocessing(Collection modelDataPreprocessingCollection) { - if (Objects.nonNull(modelDataPreprocessingCollection)) { - modelDataPreprocessings.addAll(modelDataPreprocessingCollection); + public AIPackageBuilder addAllDomain(Collection domainCollection) { + if (Objects.nonNull(domainCollection)) { + domains.addAll(domainCollection); } return this; } @@ -592,36 +569,50 @@ public AIPackageBuilder addAllModelExplainability(Collection modelExplai } /** - * Adds a domain to the initial collection - * @parameter domain domain to add + * Adds a typeOfModel to the initial collection + * @parameter typeOfModel typeOfModel to add * @return this for chaining **/ - public AIPackageBuilder addDomain(String domain) { - if (Objects.nonNull(domain)) { - domains.add(domain); + public AIPackageBuilder addTypeOfModel(String typeOfModel) { + if (Objects.nonNull(typeOfModel)) { + typeOfModels.add(typeOfModel); } return this; } /** - * Adds all elements from a collection to the initial domain collection - * @parameter domainCollection collection to initialize the domain + * Adds all elements from a collection to the initial typeOfModel collection + * @parameter typeOfModelCollection collection to initialize the typeOfModel * @return this for chaining **/ - public AIPackageBuilder addAllDomain(Collection domainCollection) { - if (Objects.nonNull(domainCollection)) { - domains.addAll(domainCollection); + public AIPackageBuilder addAllTypeOfModel(Collection typeOfModelCollection) { + if (Objects.nonNull(typeOfModelCollection)) { + typeOfModels.addAll(typeOfModelCollection); } return this; } /** - * Sets the initial value of sensitivePersonalInformation - * @parameter sensitivePersonalInformation value to set + * Adds a modelDataPreprocessing to the initial collection + * @parameter modelDataPreprocessing modelDataPreprocessing to add * @return this for chaining **/ - public AIPackageBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { - this.sensitivePersonalInformation = sensitivePersonalInformation; + public AIPackageBuilder addModelDataPreprocessing(String modelDataPreprocessing) { + if (Objects.nonNull(modelDataPreprocessing)) { + modelDataPreprocessings.add(modelDataPreprocessing); + } + return this; + } + + /** + * Adds all elements from a collection to the initial modelDataPreprocessing collection + * @parameter modelDataPreprocessingCollection collection to initialize the modelDataPreprocessing + * @return this for chaining + **/ + public AIPackageBuilder addAllModelDataPreprocessing(Collection modelDataPreprocessingCollection) { + if (Objects.nonNull(modelDataPreprocessingCollection)) { + modelDataPreprocessings.addAll(modelDataPreprocessingCollection); + } return this; } @@ -646,22 +637,22 @@ public AIPackageBuilder setAutonomyType(PresenceType autonomyType) { } /** - * Sets the initial value of limitation - * @parameter limitation value to set + * Sets the initial value of sensitivePersonalInformation + * @parameter sensitivePersonalInformation value to set * @return this for chaining **/ - public AIPackageBuilder setLimitation(String limitation) { - this.limitation = limitation; + public AIPackageBuilder setSensitivePersonalInformation(PresenceType sensitivePersonalInformation) { + this.sensitivePersonalInformation = sensitivePersonalInformation; return this; } /** - * Sets the initial value of energyConsumption - * @parameter energyConsumption value to set + * Sets the initial value of limitation + * @parameter limitation value to set * @return this for chaining **/ - public AIPackageBuilder setEnergyConsumption(String energyConsumption) { - this.energyConsumption = energyConsumption; + public AIPackageBuilder setLimitation(String limitation) { + this.limitation = limitation; return this; } @@ -684,6 +675,16 @@ public AIPackageBuilder setInformationAboutTraining(String informationAboutTrain this.informationAboutTraining = informationAboutTraining; return this; } + + /** + * Sets the initial value of energyConsumption + * @parameter energyConsumption value to set + * @return this for chaining + **/ + public AIPackageBuilder setEnergyConsumption(String energyConsumption) { + this.energyConsumption = energyConsumption; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java b/generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java index e7f835db7..8cc747e6c 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/ai/SafetyRiskAssessmentType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/build/Build.java b/generated/src/main/java/org/spdx/library/model/v3/build/Build.java index 458f08c9c..cc449d75f 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/build/Build.java +++ b/generated/src/main/java/org/spdx/library/model/v3/build/Build.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -38,11 +38,10 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.core.DateTime; import org.spdx.library.model.v3.core.DictionaryEntry; import org.spdx.library.model.v3.core.Element; import org.spdx.library.model.v3.core.Hash; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -60,9 +59,9 @@ */ public class Build extends Element { + Collection environments; Collection configSourceDigests; Collection parameterss; - Collection environments; Collection configSourceUris; Collection configSourceEntrypoints; @@ -93,9 +92,9 @@ public Build(String objectUri) throws InvalidSPDXAnalysisException { public Build(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); + environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); configSourceDigests = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_DIGEST, Hash.class); parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); - environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); configSourceUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_URI, String.class); configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); } @@ -108,19 +107,19 @@ public Build(IModelStore modelStore, String objectUri, @Nullable ModelCopyManage @SuppressWarnings("unchecked") protected Build(BuildBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); configSourceDigests = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_DIGEST, Hash.class); parameterss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_PARAMETERS, DictionaryEntry.class); - environments = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_ENVIRONMENT, DictionaryEntry.class); configSourceUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_URI, String.class); configSourceEntrypoints = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.BUILD_PROP_CONFIG_SOURCE_ENTRYPOINT, String.class); + getEnvironments().addAll(builder.environments); getConfigSourceDigests().addAll(builder.configSourceDigests); getParameterss().addAll(builder.parameterss); - getEnvironments().addAll(builder.environments); getConfigSourceUris().addAll(builder.configSourceUris); getConfigSourceEntrypoints().addAll(builder.configSourceEntrypoints); + setBuildType(builder.buildType); setBuildEndTime(builder.buildEndTime); setBuildStartTime(builder.buildStartTime); - setBuildType(builder.buildType); setBuildId(builder.buildId); } @@ -133,15 +132,15 @@ public String getType() { } // Getters and Setters + public Collection getEnvironments() { + return environments; + } public Collection getConfigSourceDigests() { return configSourceDigests; } public Collection getParameterss() { return parameterss; } - public Collection getEnvironments() { - return environments; - } public Collection getConfigSourceUris() { return configSourceUris; } @@ -150,75 +149,55 @@ public Collection getConfigSourceEntrypoints() { } - /** - * @return the buildEndTime + /** + * @return the buildType */ - @SuppressWarnings("unchecked") - public Optional getBuildEndTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public @Nullable String getBuildType() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_TYPE); + return retval.isPresent() ? retval.get() : null; } - - /** - * @param buildEndTime the buildEndTime to set + /** + * @param buildType the buildType to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Build setBuildEndTime(@Nullable DateTime buildEndTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME, buildEndTime); + public Build setBuildType(@Nullable String buildType) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(buildType)) { + throw new InvalidSPDXAnalysisException("buildType is a required property"); + } + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_TYPE, buildType); return this; } /** - * @return the buildStartTime + * @return the buildEndTime */ - @SuppressWarnings("unchecked") - public Optional getBuildStartTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getBuildEndTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME); } - /** - * @param buildStartTime the buildStartTime to set + * @param buildEndTime the buildEndTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Build setBuildStartTime(@Nullable DateTime buildStartTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME, buildStartTime); + public Build setBuildEndTime(@Nullable String buildEndTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_END_TIME, buildEndTime); return this; } - /** - * @return the buildType + /** + * @return the buildStartTime */ - public @Nullable String getBuildType() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_TYPE); - return retval.isPresent() ? retval.get() : null; + public Optional getBuildStartTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME); } - /** - * @param buildType the buildType to set + /** + * @param buildStartTime the buildStartTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Build setBuildType(@Nullable String buildType) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(buildType)) { - throw new InvalidSPDXAnalysisException("buildType is a required property"); - } - setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_TYPE, buildType); + public Build setBuildStartTime(@Nullable String buildStartTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.BUILD_PROP_BUILD_START_TIME, buildStartTime); return this; } @@ -248,35 +227,29 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional buildEndTime; + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { - buildEndTime = getBuildEndTime(); - if (buildEndTime.isPresent()) { - retval.addAll(buildEndTime.get().verify(verifiedIds, specVersion, profiles)); + String buildType = getBuildType(); + if (Objects.isNull(buildType) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.BUILD }))) { + retval.add("Missing buildType in Build"); } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting buildEndTime for Build: "+e.getMessage()); + retval.add("Error getting buildType for Build: "+e.getMessage()); } - Optional buildStartTime; try { - buildStartTime = getBuildStartTime(); - if (buildStartTime.isPresent()) { - retval.addAll(buildStartTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional buildEndTime = getBuildEndTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting buildStartTime for Build: "+e.getMessage()); + retval.add("Error getting buildEndTime for Build: "+e.getMessage()); } try { - String buildType = getBuildType(); - if (Objects.isNull(buildType) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.BUILD }))) { - retval.add("Missing buildType in Build"); - } + @SuppressWarnings("unused") + Optional buildStartTime = getBuildStartTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting buildType for Build: "+e.getMessage()); + retval.add("Error getting buildStartTime for Build: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -284,14 +257,14 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting buildId for Build: "+e.getMessage()); } + for (DictionaryEntry environment:environments) { + retval.addAll(environment.verify(verifiedIds, specVersionForVerify, profiles)); + } for (Hash configSourceDigest:configSourceDigests) { - retval.addAll(configSourceDigest.verify(verifiedIds, specVersion, profiles)); + retval.addAll(configSourceDigest.verify(verifiedIds, specVersionForVerify, profiles)); } for (DictionaryEntry parameters:parameterss) { - retval.addAll(parameters.verify(verifiedIds, specVersion, profiles)); - } - for (DictionaryEntry environment:environments) { - retval.addAll(environment.verify(verifiedIds, specVersion, profiles)); + retval.addAll(parameters.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -328,17 +301,41 @@ public BuildBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCop super(modelStore, objectUri, copyManager); } + Collection environments = new ArrayList<>(); Collection configSourceDigests = new ArrayList<>(); Collection parameterss = new ArrayList<>(); - Collection environments = new ArrayList<>(); Collection configSourceUris = new ArrayList<>(); Collection configSourceEntrypoints = new ArrayList<>(); - DateTime buildEndTime = null; - DateTime buildStartTime = null; String buildType = null; + String buildEndTime = null; + String buildStartTime = null; String buildId = null; + /** + * Adds a environment to the initial collection + * @parameter environment environment to add + * @return this for chaining + **/ + public BuildBuilder addEnvironment(DictionaryEntry environment) { + if (Objects.nonNull(environment)) { + environments.add(environment); + } + return this; + } + + /** + * Adds all elements from a collection to the initial environment collection + * @parameter environmentCollection collection to initialize the environment + * @return this for chaining + **/ + public BuildBuilder addAllEnvironment(Collection environmentCollection) { + if (Objects.nonNull(environmentCollection)) { + environments.addAll(environmentCollection); + } + return this; + } + /** * Adds a configSourceDigest to the initial collection * @parameter configSourceDigest configSourceDigest to add @@ -387,30 +384,6 @@ public BuildBuilder addAllParameters(Collection parametersColle return this; } - /** - * Adds a environment to the initial collection - * @parameter environment environment to add - * @return this for chaining - **/ - public BuildBuilder addEnvironment(DictionaryEntry environment) { - if (Objects.nonNull(environment)) { - environments.add(environment); - } - return this; - } - - /** - * Adds all elements from a collection to the initial environment collection - * @parameter environmentCollection collection to initialize the environment - * @return this for chaining - **/ - public BuildBuilder addAllEnvironment(Collection environmentCollection) { - if (Objects.nonNull(environmentCollection)) { - environments.addAll(environmentCollection); - } - return this; - } - /** * Adds a configSourceUri to the initial collection * @parameter configSourceUri configSourceUri to add @@ -460,32 +433,32 @@ public BuildBuilder addAllConfigSourceEntrypoint(Collection configSource } /** - * Sets the initial value of buildEndTime - * @parameter buildEndTime value to set + * Sets the initial value of buildType + * @parameter buildType value to set * @return this for chaining **/ - public BuildBuilder setBuildEndTime(DateTime buildEndTime) { - this.buildEndTime = buildEndTime; + public BuildBuilder setBuildType(String buildType) { + this.buildType = buildType; return this; } /** - * Sets the initial value of buildStartTime - * @parameter buildStartTime value to set + * Sets the initial value of buildEndTime + * @parameter buildEndTime value to set * @return this for chaining **/ - public BuildBuilder setBuildStartTime(DateTime buildStartTime) { - this.buildStartTime = buildStartTime; + public BuildBuilder setBuildEndTime(String buildEndTime) { + this.buildEndTime = buildEndTime; return this; } /** - * Sets the initial value of buildType - * @parameter buildType value to set + * Sets the initial value of buildStartTime + * @parameter buildStartTime value to set * @return this for chaining **/ - public BuildBuilder setBuildType(String buildType) { - this.buildType = buildType; + public BuildBuilder setBuildStartTime(String buildStartTime) { + this.buildStartTime = buildStartTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Agent.java b/generated/src/main/java/org/spdx/library/model/v3/core/Agent.java index 869c45e1d..ded11d647 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Agent.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Agent.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -102,9 +102,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java b/generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java index 0e631744e..4f34a6b90 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Annotation.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -47,7 +47,7 @@ */ public class Annotation extends Element { - Collection contentTypes; + Collection contentTypes; /** * Create the Annotation with default model store and generated anonymous ID @@ -76,7 +76,7 @@ public Annotation(String objectUri) throws InvalidSPDXAnalysisException { public Annotation(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - contentTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CONTENT_TYPE, MediaType.class); + contentTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CONTENT_TYPE, String.class); } /** @@ -87,7 +87,7 @@ public Annotation(IModelStore modelStore, String objectUri, @Nullable ModelCopyM @SuppressWarnings("unchecked") protected Annotation(AnnotationBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - contentTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CONTENT_TYPE, MediaType.class); + contentTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_CONTENT_TYPE, String.class); getContentTypes().addAll(builder.contentTypes); setSubject(builder.subject); setAnnotationType(builder.annotationType); @@ -103,7 +103,7 @@ public String getType() { } // Getters and Setters - public Collection getContentTypes() { + public Collection getContentTypes() { return contentTypes; } @@ -190,14 +190,14 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); Element subject; try { subject = getSubject(); if (Objects.nonNull(subject)) { - retval.addAll(subject.verify(verifiedIds, specVersion, profiles)); + retval.addAll(subject.verify(verifiedIds, specVersionForVerify, profiles)); } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing subject in Annotation"); } @@ -219,9 +219,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting statement for Annotation: "+e.getMessage()); } - for (MediaType contentType:contentTypes) { - retval.addAll(contentType.verify(verifiedIds, specVersion, profiles)); - } return retval; } @@ -257,7 +254,7 @@ public AnnotationBuilder(IModelStore modelStore, String objectUri, @Nullable Mod super(modelStore, objectUri, copyManager); } - Collection contentTypes = new ArrayList<>(); + Collection contentTypes = new ArrayList<>(); Element subject = null; AnnotationType annotationType = null; String statement = null; @@ -268,7 +265,7 @@ public AnnotationBuilder(IModelStore modelStore, String objectUri, @Nullable Mod * @parameter contentType contentType to add * @return this for chaining **/ - public AnnotationBuilder addContentType(MediaType contentType) { + public AnnotationBuilder addContentType(String contentType) { if (Objects.nonNull(contentType)) { contentTypes.add(contentType); } @@ -280,7 +277,7 @@ public AnnotationBuilder addContentType(MediaType contentType) { * @parameter contentTypeCollection collection to initialize the contentType * @return this for chaining **/ - public AnnotationBuilder addAllContentType(Collection contentTypeCollection) { + public AnnotationBuilder addAllContentType(Collection contentTypeCollection) { if (Objects.nonNull(contentTypeCollection)) { contentTypes.addAll(contentTypeCollection); } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java b/generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java index fc532651f..f85e3e35e 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/AnnotationType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java b/generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java index 6eff4c449..19031f522 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Artifact.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -46,7 +46,6 @@ */ public class Artifact extends Element { - Collection suppliedBys; Collection originatedBys; Collection standards; @@ -77,7 +76,6 @@ public Artifact(String objectUri) throws InvalidSPDXAnalysisException { public Artifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - suppliedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SUPPLIED_BY, Agent.class); originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); standards = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_STANDARD, String.class); } @@ -90,15 +88,14 @@ public Artifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyMan @SuppressWarnings("unchecked") protected Artifact(ArtifactBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - suppliedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_SUPPLIED_BY, Agent.class); originatedBys = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ORIGINATED_BY, Agent.class); standards = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_STANDARD, String.class); - getSuppliedBys().addAll(builder.suppliedBys); getOriginatedBys().addAll(builder.originatedBys); getStandards().addAll(builder.standards); + setSuppliedBy(builder.suppliedBy); setValidUntilTime(builder.validUntilTime); - setReleaseTime(builder.releaseTime); setBuiltTime(builder.builtTime); + setReleaseTime(builder.releaseTime); } /* (non-Javadoc) @@ -110,9 +107,6 @@ public String getType() { } // Getters and Setters - public Collection getSuppliedBys() { - return suppliedBys; - } public Collection getOriginatedBys() { return originatedBys; } @@ -122,82 +116,78 @@ public Collection getStandards() { /** - * @return the validUntilTime + * @return the suppliedBy */ @SuppressWarnings("unchecked") - public Optional getValidUntilTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME); + public Optional getSuppliedBy() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_SUPPLIED_BY); if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { + if (!(retval.get() instanceof Agent)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } /** - * @param validUntilTime the validUntilTime to set + * @param suppliedBy the suppliedBy to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Artifact setValidUntilTime(@Nullable DateTime validUntilTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME, validUntilTime); + public Artifact setSuppliedBy(@Nullable Agent suppliedBy) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_SUPPLIED_BY, suppliedBy); return this; } /** - * @return the releaseTime + * @return the validUntilTime */ - @SuppressWarnings("unchecked") - public Optional getReleaseTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getValidUntilTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME); } - /** - * @param releaseTime the releaseTime to set + * @param validUntilTime the validUntilTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Artifact setReleaseTime(@Nullable DateTime releaseTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME, releaseTime); + public Artifact setValidUntilTime(@Nullable String validUntilTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_VALID_UNTIL_TIME, validUntilTime); return this; } /** * @return the builtTime */ - @SuppressWarnings("unchecked") - public Optional getBuiltTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getBuiltTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME); } - /** * @param builtTime the builtTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Artifact setBuiltTime(@Nullable DateTime builtTime) throws InvalidSPDXAnalysisException { + public Artifact setBuiltTime(@Nullable String builtTime) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.CORE_PROP_BUILT_TIME, builtTime); return this; } + + /** + * @return the releaseTime + */ + public Optional getReleaseTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME); + } + /** + * @param releaseTime the releaseTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Artifact setReleaseTime(@Nullable String releaseTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_RELEASE_TIME, releaseTime); + return this; + } @Override @@ -209,41 +199,38 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional validUntilTime; + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); + Optional suppliedBy; try { - validUntilTime = getValidUntilTime(); - if (validUntilTime.isPresent()) { - retval.addAll(validUntilTime.get().verify(verifiedIds, specVersion, profiles)); + suppliedBy = getSuppliedBy(); + if (suppliedBy.isPresent()) { + retval.addAll(suppliedBy.get().verify(verifiedIds, specVersionForVerify, profiles)); } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting validUntilTime for Artifact: "+e.getMessage()); + retval.add("Error getting suppliedBy for Artifact: "+e.getMessage()); } - Optional releaseTime; try { - releaseTime = getReleaseTime(); - if (releaseTime.isPresent()) { - retval.addAll(releaseTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional validUntilTime = getValidUntilTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting releaseTime for Artifact: "+e.getMessage()); + retval.add("Error getting validUntilTime for Artifact: "+e.getMessage()); } - Optional builtTime; try { - builtTime = getBuiltTime(); - if (builtTime.isPresent()) { - retval.addAll(builtTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional builtTime = getBuiltTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting builtTime for Artifact: "+e.getMessage()); } - for (Agent suppliedBy:suppliedBys) { - retval.addAll(suppliedBy.verify(verifiedIds, specVersion, profiles)); + try { + @SuppressWarnings("unused") + Optional releaseTime = getReleaseTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting releaseTime for Artifact: "+e.getMessage()); } for (Agent originatedBy:originatedBys) { - retval.addAll(originatedBy.verify(verifiedIds, specVersion, profiles)); + retval.addAll(originatedBy.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -280,37 +267,13 @@ public ArtifactBuilder(IModelStore modelStore, String objectUri, @Nullable Model super(modelStore, objectUri, copyManager); } - Collection suppliedBys = new ArrayList<>(); Collection originatedBys = new ArrayList<>(); Collection standards = new ArrayList<>(); - DateTime validUntilTime = null; - DateTime releaseTime = null; - DateTime builtTime = null; - - - /** - * Adds a suppliedBy to the initial collection - * @parameter suppliedBy suppliedBy to add - * @return this for chaining - **/ - public ArtifactBuilder addSuppliedBy(Agent suppliedBy) { - if (Objects.nonNull(suppliedBy)) { - suppliedBys.add(suppliedBy); - } - return this; - } + Agent suppliedBy = null; + String validUntilTime = null; + String builtTime = null; + String releaseTime = null; - /** - * Adds all elements from a collection to the initial suppliedBy collection - * @parameter suppliedByCollection collection to initialize the suppliedBy - * @return this for chaining - **/ - public ArtifactBuilder addAllSuppliedBy(Collection suppliedByCollection) { - if (Objects.nonNull(suppliedByCollection)) { - suppliedBys.addAll(suppliedByCollection); - } - return this; - } /** * Adds a originatedBy to the initial collection @@ -361,22 +324,22 @@ public ArtifactBuilder addAllStandard(Collection standardCollection) { } /** - * Sets the initial value of validUntilTime - * @parameter validUntilTime value to set + * Sets the initial value of suppliedBy + * @parameter suppliedBy value to set * @return this for chaining **/ - public ArtifactBuilder setValidUntilTime(DateTime validUntilTime) { - this.validUntilTime = validUntilTime; + public ArtifactBuilder setSuppliedBy(Agent suppliedBy) { + this.suppliedBy = suppliedBy; return this; } /** - * Sets the initial value of releaseTime - * @parameter releaseTime value to set + * Sets the initial value of validUntilTime + * @parameter validUntilTime value to set * @return this for chaining **/ - public ArtifactBuilder setReleaseTime(DateTime releaseTime) { - this.releaseTime = releaseTime; + public ArtifactBuilder setValidUntilTime(String validUntilTime) { + this.validUntilTime = validUntilTime; return this; } @@ -385,10 +348,20 @@ public ArtifactBuilder setReleaseTime(DateTime releaseTime) { * @parameter builtTime value to set * @return this for chaining **/ - public ArtifactBuilder setBuiltTime(DateTime builtTime) { + public ArtifactBuilder setBuiltTime(String builtTime) { this.builtTime = builtTime; return this; } + + /** + * Sets the initial value of releaseTime + * @parameter releaseTime value to set + * @return this for chaining + **/ + public ArtifactBuilder setReleaseTime(String releaseTime) { + this.releaseTime = releaseTime; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Bom.java b/generated/src/main/java/org/spdx/library/model/v3/core/Bom.java index 1df0a1db7..f911b0581 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Bom.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Bom.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -103,9 +103,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java b/generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java index 85689cb8f..5c5710cb5 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Bundle.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -119,9 +119,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional context = getContext(); diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java b/generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java index c17e5b950..d57df49d9 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/CreationInfo.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -100,10 +100,10 @@ protected CreationInfo(CreationInfoBuilder builder) throws InvalidSPDXAnalysisEx getCreatedBys().addAll(builder.createdBys); getCreatedUsings().addAll(builder.createdUsings); getProfiles().addAll(builder.profiles); - setCreated(builder.created); setSpecVersion(builder.specVersion); - setDataLicense(builder.dataLicense); setComment(builder.comment); + setDataLicense(builder.dataLicense); + setCreated(builder.created); } /* (non-Javadoc) @@ -126,90 +126,79 @@ public Collection getProfiles() { } - /** - * @return the created + /** + * @return the specVersion */ - @SuppressWarnings("unchecked") - public Optional getCreated() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CREATED); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public @Nullable String getSpecVersion() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_SPEC_VERSION); + return retval.isPresent() ? retval.get() : null; } - - /** - * @param created the created to set + /** + * @param specVersion the specVersion to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public CreationInfo setCreated(@Nullable DateTime created) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_CREATED, created); + public CreationInfo setSpecVersion(@Nullable String specVersion) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(specVersion)) { + throw new InvalidSPDXAnalysisException("specVersion is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_SPEC_VERSION, specVersion); return this; } - /** - * @return the specVersion + /** + * @return the comment */ - @SuppressWarnings("unchecked") - public @Nullable SemVer getSpecVersion() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_SPEC_VERSION); - if (retval.isPresent()) { - if (!(retval.get() instanceof SemVer)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (SemVer)(retval.get()); - } else { - return null; - } + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); } - /** - * @param specVersion the specVersion to set + * @param comment the comment to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public CreationInfo setSpecVersion(@Nullable SemVer specVersion) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(specVersion)) { - throw new InvalidSPDXAnalysisException("specVersion is a required property"); - } - setPropertyValue(SpdxConstants.CORE_PROP_SPEC_VERSION, specVersion); + public CreationInfo setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); return this; } - /** + /** * @return the dataLicense */ - public Optional getDataLicense() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_DATA_LICENSE); + public @Nullable String getDataLicense() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_DATA_LICENSE); + return retval.isPresent() ? retval.get() : null; } - /** + /** * @param dataLicense the dataLicense to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ public CreationInfo setDataLicense(@Nullable String dataLicense) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(dataLicense)) { + throw new InvalidSPDXAnalysisException("dataLicense is a required property"); + } setPropertyValue(SpdxConstants.CORE_PROP_DATA_LICENSE, dataLicense); return this; } - /** - * @return the comment + /** + * @return the created */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + public @Nullable String getCreated() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.CORE_PROP_CREATED); + return retval.isPresent() ? retval.get() : null; } - /** - * @param comment the comment to set + /** + * @param created the created to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public CreationInfo setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + public CreationInfo setCreated(@Nullable String created) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(created)) { + throw new InvalidSPDXAnalysisException("created is a required property"); + } + setPropertyValue(SpdxConstants.CORE_PROP_CREATED, created); return this; } @@ -223,45 +212,46 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - Optional created; try { - created = getCreated(); - if (created.isPresent()) { - retval.addAll(created.get().verify(verifiedIds, specVersion, profiles)); + String specVersion = getSpecVersion(); + if (Objects.isNull(specVersion) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing specVersion in CreationInfo"); } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting created for CreationInfo: "+e.getMessage()); + retval.add("Error getting specVersion for CreationInfo: "+e.getMessage()); } - SemVer specVersion; try { - specVersion = getSpecVersion(); - if (Objects.nonNull(specVersion)) { - retval.addAll(specVersion.verify(verifiedIds, specVersion, profiles)); - } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing specVersion in CreationInfo"); - } + @SuppressWarnings("unused") + Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting specVersion for CreationInfo: "+e.getMessage()); + retval.add("Error getting comment for CreationInfo: "+e.getMessage()); } try { - @SuppressWarnings("unused") - Optional dataLicense = getDataLicense(); + String dataLicense = getDataLicense(); + if (Objects.isNull(dataLicense) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing dataLicense in CreationInfo"); + } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting dataLicense for CreationInfo: "+e.getMessage()); } try { - @SuppressWarnings("unused") - Optional comment = getComment(); + String created = getCreated(); + if (Objects.isNull(created) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing created in CreationInfo"); + } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting comment for CreationInfo: "+e.getMessage()); + retval.add("Error getting created for CreationInfo: "+e.getMessage()); } for (Agent createdBy:createdBys) { - retval.addAll(createdBy.verify(verifiedIds, specVersion, profiles)); + retval.addAll(createdBy.verify(verifiedIds, specVersionForVerify, profiles)); } for (Tool createdUsing:createdUsings) { - retval.addAll(createdUsing.verify(verifiedIds, specVersion, profiles)); + retval.addAll(createdUsing.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -301,10 +291,10 @@ public CreationInfoBuilder(IModelStore modelStore, String objectUri, @Nullable M Collection createdBys = new ArrayList<>(); Collection createdUsings = new ArrayList<>(); Collection profiles = new ArrayList<>(); - DateTime created = null; - SemVer specVersion = null; - String dataLicense = null; + String specVersion = null; String comment = null; + String dataLicense = null; + String created = null; /** @@ -380,22 +370,22 @@ public CreationInfoBuilder addAllProfile(Collection profi } /** - * Sets the initial value of created - * @parameter created value to set + * Sets the initial value of specVersion + * @parameter specVersion value to set * @return this for chaining **/ - public CreationInfoBuilder setCreated(DateTime created) { - this.created = created; + public CreationInfoBuilder setSpecVersion(String specVersion) { + this.specVersion = specVersion; return this; } /** - * Sets the initial value of specVersion - * @parameter specVersion value to set + * Sets the initial value of comment + * @parameter comment value to set * @return this for chaining **/ - public CreationInfoBuilder setSpecVersion(SemVer specVersion) { - this.specVersion = specVersion; + public CreationInfoBuilder setComment(String comment) { + this.comment = comment; return this; } @@ -410,12 +400,12 @@ public CreationInfoBuilder setDataLicense(String dataLicense) { } /** - * Sets the initial value of comment - * @parameter comment value to set + * Sets the initial value of created + * @parameter created value to set * @return this for chaining **/ - public CreationInfoBuilder setComment(String comment) { - this.comment = comment; + public CreationInfoBuilder setCreated(String created) { + this.created = created; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java b/generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java index 3794533cc..70e364222 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/DictionaryEntry.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -85,8 +85,8 @@ public DictionaryEntry(IModelStore modelStore, String objectUri, @Nullable Model */ protected DictionaryEntry(DictionaryEntryBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setKey(builder.key); setValue(builder.value); + setKey(builder.key); } /* (non-Javadoc) @@ -100,6 +100,22 @@ public String getType() { // Getters and Setters + /** + * @return the value + */ + public Optional getValue() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_VALUE); + } + /** + * @param value the value to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public DictionaryEntry setValue(@Nullable String value) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_VALUE, value); + return this; + } + /** * @return the key */ @@ -119,22 +135,6 @@ public DictionaryEntry setKey(@Nullable String key) throws InvalidSPDXAnalysisEx setPropertyValue(SpdxConstants.CORE_PROP_KEY, key); return this; } - - /** - * @return the value - */ - public Optional getValue() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_VALUE); - } - /** - * @param value the value to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public DictionaryEntry setValue(@Nullable String value) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_VALUE, value); - return this; - } @Override @@ -146,8 +146,14 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); + try { + @SuppressWarnings("unused") + Optional value = getValue(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting value for DictionaryEntry: "+e.getMessage()); + } try { String key = getKey(); if (Objects.isNull(key) && @@ -157,12 +163,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting key for DictionaryEntry: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional value = getValue(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting value for DictionaryEntry: "+e.getMessage()); - } return retval; } @@ -198,27 +198,27 @@ public DictionaryEntryBuilder(IModelStore modelStore, String objectUri, @Nullabl super(modelStore, objectUri, copyManager); } - String key = null; String value = null; + String key = null; /** - * Sets the initial value of key - * @parameter key value to set + * Sets the initial value of value + * @parameter value value to set * @return this for chaining **/ - public DictionaryEntryBuilder setKey(String key) { - this.key = key; + public DictionaryEntryBuilder setValue(String value) { + this.value = value; return this; } /** - * Sets the initial value of value - * @parameter value value to set + * Sets the initial value of key + * @parameter key value to set * @return this for chaining **/ - public DictionaryEntryBuilder setValue(String value) { - this.value = value; + public DictionaryEntryBuilder setKey(String key) { + this.key = key; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Element.java b/generated/src/main/java/org/spdx/library/model/v3/core/Element.java index cf650e8ff..9ecae672d 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Element.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Element.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -51,9 +51,10 @@ */ public class Element extends ModelObject { + Collection externalRefs; + Collection extensions; Collection externalIdentifiers; Collection verifiedUsings; - Collection externalReferences; /** * Create the Element with default model store and generated anonymous ID @@ -82,9 +83,10 @@ public Element(String objectUri) throws InvalidSPDXAnalysisException { public Element(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); + externalRefs = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REF, ExternalRef.class); + extensions = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTENSION, Extension.class); externalIdentifiers = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER, ExternalIdentifier.class); verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); - externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); } /** @@ -95,17 +97,19 @@ public Element(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana @SuppressWarnings("unchecked") protected Element(ElementBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + externalRefs = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REF, ExternalRef.class); + extensions = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTENSION, Extension.class); externalIdentifiers = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_IDENTIFIER, ExternalIdentifier.class); verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); - externalReferences = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE, ExternalReference.class); + getExternalRefs().addAll(builder.externalRefs); + getExtensions().addAll(builder.extensions); getExternalIdentifiers().addAll(builder.externalIdentifiers); getVerifiedUsings().addAll(builder.verifiedUsings); - getExternalReferences().addAll(builder.externalReferences); setCreationInfo(builder.creationInfo); + setSummary(builder.summary); + setDescription(builder.description); setComment(builder.comment); setName(builder.name); - setDescription(builder.description); - setSummary(builder.summary); } /* (non-Javadoc) @@ -117,21 +121,25 @@ public String getType() { } // Getters and Setters + public Collection getExternalRefs() { + return externalRefs; + } + public Collection getExtensions() { + return extensions; + } public Collection getExternalIdentifiers() { return externalIdentifiers; } public Collection getVerifiedUsings() { return verifiedUsings; } - public Collection getExternalReferences() { - return externalReferences; - } /** * @return the creationInfo */ - public @Nullable CreationInfo getCreationInfo() throws InvalidSPDXAnalysisException { + @SuppressWarnings("unchecked") + public @Nullable CreationInfo getCreationInfo() throws InvalidSPDXAnalysisException { Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CREATION_INFO); if (retval.isPresent()) { if (!(retval.get() instanceof CreationInfo)) { @@ -157,66 +165,66 @@ public Element setCreationInfo(@Nullable CreationInfo creationInfo) throws Inval } /** - * @return the comment + * @return the summary */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + public Optional getSummary() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_SUMMARY); } /** - * @param comment the comment to set + * @param summary the summary to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Element setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + public Element setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_SUMMARY, summary); return this; } /** - * @return the name + * @return the description */ - public Optional getName() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_NAME); + public Optional getDescription() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_DESCRIPTION); } /** - * @param name the name to set + * @param description the description to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Element setName(@Nullable String name) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_NAME, name); + public Element setDescription(@Nullable String description) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_DESCRIPTION, description); return this; } /** - * @return the description + * @return the comment */ - public Optional getDescription() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_DESCRIPTION); + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); } /** - * @param description the description to set + * @param comment the comment to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Element setDescription(@Nullable String description) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_DESCRIPTION, description); + public Element setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); return this; } /** - * @return the summary + * @return the name */ - public Optional getSummary() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_SUMMARY); + public Optional getName() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_NAME); } /** - * @param summary the summary to set + * @param name the name to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Element setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_SUMMARY, summary); + public Element setName(@Nullable String name) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_NAME, name); return this; } @@ -230,13 +238,13 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); CreationInfo creationInfo; try { creationInfo = getCreationInfo(); if (Objects.nonNull(creationInfo)) { - retval.addAll(creationInfo.verify(verifiedIds, specVersion, profiles)); + retval.addAll(creationInfo.verify(verifiedIds, specVersionForVerify, profiles)); } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing creationInfo in Element"); } @@ -245,36 +253,39 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional comment = getComment(); + Optional summary = getSummary(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting comment for Element: "+e.getMessage()); + retval.add("Error getting summary for Element: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional name = getName(); + Optional description = getDescription(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting name for Element: "+e.getMessage()); + retval.add("Error getting description for Element: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional description = getDescription(); + Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting description for Element: "+e.getMessage()); + retval.add("Error getting comment for Element: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional summary = getSummary(); + Optional name = getName(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting summary for Element: "+e.getMessage()); + retval.add("Error getting name for Element: "+e.getMessage()); + } + for (ExternalRef externalRef:externalRefs) { + retval.addAll(externalRef.verify(verifiedIds, specVersionForVerify, profiles)); + } + for (Extension extension:extensions) { + retval.addAll(extension.verify(verifiedIds, specVersionForVerify, profiles)); } for (ExternalIdentifier externalIdentifier:externalIdentifiers) { - retval.addAll(externalIdentifier.verify(verifiedIds, specVersion, profiles)); + retval.addAll(externalIdentifier.verify(verifiedIds, specVersionForVerify, profiles)); } for (IntegrityMethod verifiedUsing:verifiedUsings) { - retval.addAll(verifiedUsing.verify(verifiedIds, specVersion, profiles)); - } - for (ExternalReference externalReference:externalReferences) { - retval.addAll(externalReference.verify(verifiedIds, specVersion, profiles)); + retval.addAll(verifiedUsing.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -311,16 +322,65 @@ public ElementBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC super(modelStore, objectUri, copyManager); } + Collection externalRefs = new ArrayList<>(); + Collection extensions = new ArrayList<>(); Collection externalIdentifiers = new ArrayList<>(); Collection verifiedUsings = new ArrayList<>(); - Collection externalReferences = new ArrayList<>(); CreationInfo creationInfo = null; + String summary = null; + String description = null; String comment = null; String name = null; - String description = null; - String summary = null; + /** + * Adds a externalRef to the initial collection + * @parameter externalRef externalRef to add + * @return this for chaining + **/ + public ElementBuilder addExternalRef(ExternalRef externalRef) { + if (Objects.nonNull(externalRef)) { + externalRefs.add(externalRef); + } + return this; + } + + /** + * Adds all elements from a collection to the initial externalRef collection + * @parameter externalRefCollection collection to initialize the externalRef + * @return this for chaining + **/ + public ElementBuilder addAllExternalRef(Collection externalRefCollection) { + if (Objects.nonNull(externalRefCollection)) { + externalRefs.addAll(externalRefCollection); + } + return this; + } + + /** + * Adds a extension to the initial collection + * @parameter extension extension to add + * @return this for chaining + **/ + public ElementBuilder addExtension(Extension extension) { + if (Objects.nonNull(extension)) { + extensions.add(extension); + } + return this; + } + + /** + * Adds all elements from a collection to the initial extension collection + * @parameter extensionCollection collection to initialize the extension + * @return this for chaining + **/ + public ElementBuilder addAllExtension(Collection extensionCollection) { + if (Objects.nonNull(extensionCollection)) { + extensions.addAll(extensionCollection); + } + return this; + } + /** * Adds a externalIdentifier to the initial collection * @parameter externalIdentifier externalIdentifier to add @@ -370,36 +430,32 @@ public ElementBuilder addAllVerifiedUsing(Collection verifiedUs } /** - * Adds a externalReference to the initial collection - * @parameter externalReference externalReference to add + * Sets the initial value of creationInfo + * @parameter creationInfo value to set * @return this for chaining **/ - public ElementBuilder addExternalReference(ExternalReference externalReference) { - if (Objects.nonNull(externalReference)) { - externalReferences.add(externalReference); - } + public ElementBuilder setCreationInfo(CreationInfo creationInfo) { + this.creationInfo = creationInfo; return this; } /** - * Adds all elements from a collection to the initial externalReference collection - * @parameter externalReferenceCollection collection to initialize the externalReference + * Sets the initial value of summary + * @parameter summary value to set * @return this for chaining **/ - public ElementBuilder addAllExternalReference(Collection externalReferenceCollection) { - if (Objects.nonNull(externalReferenceCollection)) { - externalReferences.addAll(externalReferenceCollection); - } + public ElementBuilder setSummary(String summary) { + this.summary = summary; return this; } /** - * Sets the initial value of creationInfo - * @parameter creationInfo value to set + * Sets the initial value of description + * @parameter description value to set * @return this for chaining **/ - public ElementBuilder setCreationInfo(CreationInfo creationInfo) { - this.creationInfo = creationInfo; + public ElementBuilder setDescription(String description) { + this.description = description; return this; } @@ -422,26 +478,6 @@ public ElementBuilder setName(String name) { this.name = name; return this; } - - /** - * Sets the initial value of description - * @parameter description value to set - * @return this for chaining - **/ - public ElementBuilder setDescription(String description) { - this.description = description; - return this; - } - - /** - * Sets the initial value of summary - * @parameter summary value to set - * @return this for chaining - **/ - public ElementBuilder setSummary(String summary) { - this.summary = summary; - return this; - } /** diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java b/generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java index d4adc0198..236149baa 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ElementCollection.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -48,8 +48,8 @@ public class ElementCollection extends Element { Collection importss; - Collection rootElements; Collection elements; + Collection rootElements; /** * Create the ElementCollection with default model store and generated anonymous ID @@ -79,8 +79,8 @@ public ElementCollection(IModelStore modelStore, String objectUri, @Nullable Mod boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); - rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); } /** @@ -92,11 +92,11 @@ public ElementCollection(IModelStore modelStore, String objectUri, @Nullable Mod protected ElementCollection(ElementCollectionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); importss = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_IMPORTS, ExternalMap.class); - rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); elements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ELEMENT, Element.class); + rootElements = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_ROOT_ELEMENT, Element.class); getImportss().addAll(builder.importss); - getRootElements().addAll(builder.rootElements); getElements().addAll(builder.elements); + getRootElements().addAll(builder.rootElements); } /* (non-Javadoc) @@ -111,12 +111,12 @@ public String getType() { public Collection getImportss() { return importss; } - public Collection getRootElements() { - return rootElements; - } public Collection getElements() { return elements; } + public Collection getRootElements() { + return rootElements; + } @@ -129,17 +129,17 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); for (ExternalMap imports:importss) { - retval.addAll(imports.verify(verifiedIds, specVersion, profiles)); - } - for (Element rootElement:rootElements) { - retval.addAll(rootElement.verify(verifiedIds, specVersion, profiles)); + retval.addAll(imports.verify(verifiedIds, specVersionForVerify, profiles)); } for (Element element:elements) { - retval.addAll(element.verify(verifiedIds, specVersion, profiles)); + retval.addAll(element.verify(verifiedIds, specVersionForVerify, profiles)); + } + for (Element rootElement:rootElements) { + retval.addAll(rootElement.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -177,8 +177,8 @@ public ElementCollectionBuilder(IModelStore modelStore, String objectUri, @Nulla } Collection importss = new ArrayList<>(); - Collection rootElements = new ArrayList<>(); Collection elements = new ArrayList<>(); + Collection rootElements = new ArrayList<>(); /** @@ -206,49 +206,49 @@ public ElementCollectionBuilder addAllImports(Collection importsCol } /** - * Adds a rootElement to the initial collection - * @parameter rootElement rootElement to add + * Adds a element to the initial collection + * @parameter element element to add * @return this for chaining **/ - public ElementCollectionBuilder addRootElement(Element rootElement) { - if (Objects.nonNull(rootElement)) { - rootElements.add(rootElement); + public ElementCollectionBuilder addElement(Element element) { + if (Objects.nonNull(element)) { + elements.add(element); } return this; } /** - * Adds all elements from a collection to the initial rootElement collection - * @parameter rootElementCollection collection to initialize the rootElement + * Adds all elements from a collection to the initial element collection + * @parameter elementCollection collection to initialize the element * @return this for chaining **/ - public ElementCollectionBuilder addAllRootElement(Collection rootElementCollection) { - if (Objects.nonNull(rootElementCollection)) { - rootElements.addAll(rootElementCollection); + public ElementCollectionBuilder addAllElement(Collection elementCollection) { + if (Objects.nonNull(elementCollection)) { + elements.addAll(elementCollection); } return this; } /** - * Adds a element to the initial collection - * @parameter element element to add + * Adds a rootElement to the initial collection + * @parameter rootElement rootElement to add * @return this for chaining **/ - public ElementCollectionBuilder addElement(Element element) { - if (Objects.nonNull(element)) { - elements.add(element); + public ElementCollectionBuilder addRootElement(Element rootElement) { + if (Objects.nonNull(rootElement)) { + rootElements.add(rootElement); } return this; } /** - * Adds all elements from a collection to the initial element collection - * @parameter elementCollection collection to initialize the element + * Adds all elements from a collection to the initial rootElement collection + * @parameter rootElementCollection collection to initialize the rootElement * @return this for chaining **/ - public ElementCollectionBuilder addAllElement(Collection elementCollection) { - if (Objects.nonNull(elementCollection)) { - elements.addAll(elementCollection); + public ElementCollectionBuilder addAllRootElement(Collection rootElementCollection) { + if (Objects.nonNull(rootElementCollection)) { + rootElements.addAll(rootElementCollection); } return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Extension.java b/generated/src/main/java/org/spdx/library/model/v3/core/Extension.java new file mode 100644 index 000000000..aa5ba61e2 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Extension.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.v3.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * TODO + */ +public class Extension extends ModelObject { + + + /** + * Create the Extension with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the Extension + */ + public Extension() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the Extension + * @throws InvalidSPDXAnalysisException when unable to create the Extension + */ + public Extension(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the Extension is to be stored + * @param objectUri URI or anonymous ID for the Extension + * @param copyManager Copy manager for the Extension - can be null if copying is not required + * @param create true if Extension is to be created + * @throws InvalidSPDXAnalysisException when unable to create the Extension + */ + public Extension(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the Extension from the builder - used in the builder class + * @param builder Builder to create the Extension from + * @throws InvalidSPDXAnalysisException when unable to create the Extension + */ + protected Extension(ExtensionBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "Core.Extension"; + } + + // Getters and Setters + + + + @Override + public String toString() { + return "Extension: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { + List retval = new ArrayList<>(); + return retval; + } + + public static class ExtensionBuilder extends ModelObjectBuilder { + + /** + * Create an ExtensionBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public ExtensionBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an ExtensionBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public ExtensionBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a ExtensionBuilder + * @param modelStore model store for the built Extension + * @param objectUri objectUri for the built Extension + * @param copyManager optional copyManager for the built Extension + */ + public ExtensionBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + + + + /** + * @return the Extension + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public Extension build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new Extension(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java index 9cca4d760..f9d2d6c6a 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifier.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -92,8 +92,8 @@ protected ExternalIdentifier(ExternalIdentifierBuilder builder) throws InvalidSP getIdentifierLocators().addAll(builder.identifierLocators); setExternalIdentifierType(builder.externalIdentifierType); setComment(builder.comment); - setIdentifier(builder.identifier); setIssuingAuthority(builder.issuingAuthority); + setIdentifier(builder.identifier); } /* (non-Javadoc) @@ -153,6 +153,22 @@ public ExternalIdentifier setComment(@Nullable String comment) throws InvalidSPD return this; } + /** + * @return the issuingAuthority + */ + public Optional getIssuingAuthority() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY); + } + /** + * @param issuingAuthority the issuingAuthority to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalIdentifier setIssuingAuthority(@Nullable String issuingAuthority) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY, issuingAuthority); + return this; + } + /** * @return the identifier */ @@ -172,22 +188,6 @@ public ExternalIdentifier setIdentifier(@Nullable String identifier) throws Inva setPropertyValue(SpdxConstants.CORE_PROP_IDENTIFIER, identifier); return this; } - - /** - * @return the issuingAuthority - */ - public Optional getIssuingAuthority() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY); - } - /** - * @param issuingAuthority the issuingAuthority to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalIdentifier setIssuingAuthority(@Nullable String issuingAuthority) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_ISSUING_AUTHORITY, issuingAuthority); - return this; - } @Override @@ -199,7 +199,7 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); try { ExternalIdentifierType externalIdentifierType = getExternalIdentifierType(); @@ -216,6 +216,12 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting comment for ExternalIdentifier: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional issuingAuthority = getIssuingAuthority(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting issuingAuthority for ExternalIdentifier: "+e.getMessage()); + } try { String identifier = getIdentifier(); if (Objects.isNull(identifier) && @@ -225,12 +231,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting identifier for ExternalIdentifier: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional issuingAuthority = getIssuingAuthority(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting issuingAuthority for ExternalIdentifier: "+e.getMessage()); - } return retval; } @@ -269,8 +269,8 @@ public ExternalIdentifierBuilder(IModelStore modelStore, String objectUri, @Null Collection identifierLocators = new ArrayList<>(); ExternalIdentifierType externalIdentifierType = null; String comment = null; - String identifier = null; String issuingAuthority = null; + String identifier = null; /** @@ -318,22 +318,22 @@ public ExternalIdentifierBuilder setComment(String comment) { } /** - * Sets the initial value of identifier - * @parameter identifier value to set + * Sets the initial value of issuingAuthority + * @parameter issuingAuthority value to set * @return this for chaining **/ - public ExternalIdentifierBuilder setIdentifier(String identifier) { - this.identifier = identifier; + public ExternalIdentifierBuilder setIssuingAuthority(String issuingAuthority) { + this.issuingAuthority = issuingAuthority; return this; } /** - * Sets the initial value of issuingAuthority - * @parameter issuingAuthority value to set + * Sets the initial value of identifier + * @parameter identifier value to set * @return this for chaining **/ - public ExternalIdentifierBuilder setIssuingAuthority(String issuingAuthority) { - this.issuingAuthority = issuingAuthority; + public ExternalIdentifierBuilder setIdentifier(String identifier) { + this.identifier = identifier; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java index f9b6e20eb..09f8e78dd 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalIdentifierType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java index 1d98e0422..5b464ddc1 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalMap.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -91,8 +91,8 @@ protected ExternalMap(ExternalMapBuilder builder) throws InvalidSPDXAnalysisExce super(builder); verifiedUsings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_VERIFIED_USING, IntegrityMethod.class); getVerifiedUsings().addAll(builder.verifiedUsings); - setExternalId(builder.externalId); setDefiningDocument(builder.definingDocument); + setExternalId(builder.externalId); setLocationHint(builder.locationHint); } @@ -110,6 +110,22 @@ public Collection getVerifiedUsings() { } + /** + * @return the definingDocument + */ + public Optional getDefiningDocument() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_DEFINING_DOCUMENT); + } + /** + * @param definingDocument the definingDocument to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public ExternalMap setDefiningDocument(@Nullable String definingDocument) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_DEFINING_DOCUMENT, definingDocument); + return this; + } + /** * @return the externalId */ @@ -130,22 +146,6 @@ public ExternalMap setExternalId(@Nullable String externalId) throws InvalidSPDX return this; } - /** - * @return the definingDocument - */ - public Optional getDefiningDocument() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_DEFINING_DOCUMENT); - } - /** - * @param definingDocument the definingDocument to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalMap setDefiningDocument(@Nullable String definingDocument) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_DEFINING_DOCUMENT, definingDocument); - return this; - } - /** * @return the locationHint */ @@ -172,8 +172,14 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); + try { + @SuppressWarnings("unused") + Optional definingDocument = getDefiningDocument(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting definingDocument for ExternalMap: "+e.getMessage()); + } try { String externalId = getExternalId(); if (Objects.isNull(externalId) && @@ -183,12 +189,6 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting externalId for ExternalMap: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional definingDocument = getDefiningDocument(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting definingDocument for ExternalMap: "+e.getMessage()); - } try { @SuppressWarnings("unused") Optional locationHint = getLocationHint(); @@ -196,7 +196,7 @@ protected List _verify(Set verifiedIds, String specVersion, List retval.add("Error getting locationHint for ExternalMap: "+e.getMessage()); } for (IntegrityMethod verifiedUsing:verifiedUsings) { - retval.addAll(verifiedUsing.verify(verifiedIds, specVersion, profiles)); + retval.addAll(verifiedUsing.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -234,8 +234,8 @@ public ExternalMapBuilder(IModelStore modelStore, String objectUri, @Nullable Mo } Collection verifiedUsings = new ArrayList<>(); - String externalId = null; String definingDocument = null; + String externalId = null; String locationHint = null; @@ -264,22 +264,22 @@ public ExternalMapBuilder addAllVerifiedUsing(Collection verifi } /** - * Sets the initial value of externalId - * @parameter externalId value to set + * Sets the initial value of definingDocument + * @parameter definingDocument value to set * @return this for chaining **/ - public ExternalMapBuilder setExternalId(String externalId) { - this.externalId = externalId; + public ExternalMapBuilder setDefiningDocument(String definingDocument) { + this.definingDocument = definingDocument; return this; } /** - * Sets the initial value of definingDocument - * @parameter definingDocument value to set + * Sets the initial value of externalId + * @parameter externalId value to set * @return this for chaining **/ - public ExternalMapBuilder setDefiningDocument(String definingDocument) { - this.definingDocument = definingDocument; + public ExternalMapBuilder setExternalId(String externalId) { + this.externalId = externalId; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReference.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalRef.java similarity index 56% rename from generated/src/main/java/org/spdx/library/model/v3/core/ExternalReference.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalRef.java index 75bab2fa6..24ee8020b 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReference.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalRef.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -44,53 +44,53 @@ * An External Reference points to a resource outside the scope of the SPDX-3.0 content * that provides additional characteristics of an Element. */ -public class ExternalReference extends ModelObject { +public class ExternalRef extends ModelObject { Collection locators; /** - * Create the ExternalReference with default model store and generated anonymous ID - * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + * Create the ExternalRef with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the ExternalRef */ - public ExternalReference() throws InvalidSPDXAnalysisException { + public ExternalRef() throws InvalidSPDXAnalysisException { this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); } /** - * @param objectUri URI or anonymous ID for the ExternalReference - * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + * @param objectUri URI or anonymous ID for the ExternalRef + * @throws InvalidSPDXAnalysisException when unable to create the ExternalRef */ - public ExternalReference(String objectUri) throws InvalidSPDXAnalysisException { + public ExternalRef(String objectUri) throws InvalidSPDXAnalysisException { this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); } /** - * @param modelStore Model store where the ExternalReference is to be stored - * @param objectUri URI or anonymous ID for the ExternalReference - * @param copyManager Copy manager for the ExternalReference - can be null if copying is not required - * @param create true if ExternalReference is to be created - * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + * @param modelStore Model store where the ExternalRef is to be stored + * @param objectUri URI or anonymous ID for the ExternalRef + * @param copyManager Copy manager for the ExternalRef - can be null if copying is not required + * @param create true if ExternalRef is to be created + * @throws InvalidSPDXAnalysisException when unable to create the ExternalRef */ @SuppressWarnings("unchecked") - public ExternalReference(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + public ExternalRef(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); locators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_LOCATOR, String.class); } /** - * Create the ExternalReference from the builder - used in the builder class - * @param builder Builder to create the ExternalReference from - * @throws InvalidSPDXAnalysisException when unable to create the ExternalReference + * Create the ExternalRef from the builder - used in the builder class + * @param builder Builder to create the ExternalRef from + * @throws InvalidSPDXAnalysisException when unable to create the ExternalRef */ @SuppressWarnings("unchecked") - protected ExternalReference(ExternalReferenceBuilder builder) throws InvalidSPDXAnalysisException { + protected ExternalRef(ExternalRefBuilder builder) throws InvalidSPDXAnalysisException { super(builder); locators = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_LOCATOR, String.class); getLocators().addAll(builder.locators); - setContentType(builder.contentType); - setExternalReferenceType(builder.externalReferenceType); + setExternalRefType(builder.externalRefType); setComment(builder.comment); + setContentType(builder.contentType); } /* (non-Javadoc) @@ -98,7 +98,7 @@ protected ExternalReference(ExternalReferenceBuilder builder) throws InvalidSPDX */ @Override public String getType() { - return "Core.ExternalReference"; + return "Core.ExternalRef"; } // Getters and Setters @@ -106,146 +106,133 @@ public Collection getLocators() { return locators; } - - /** - * @return the contentType + + /** + * @return the externalRefType */ @SuppressWarnings("unchecked") - public Optional getContentType() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE); + public Optional getExternalRefType() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_REF_TYPE); if (retval.isPresent()) { - if (!(retval.get() instanceof MediaType)) { + if (!(retval.get() instanceof ExternalRefType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } - /** - * @param contentType the contentType to set + * @param externalRefType the externalRefType to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ExternalReference setContentType(@Nullable MediaType contentType) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE, contentType); + public ExternalRef setExternalRefType(@Nullable ExternalRefType externalRefType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_REF_TYPE, externalRefType); return this; } - - /** - * @return the externalReferenceType + + /** + * @return the comment */ - @SuppressWarnings("unchecked") - public Optional getExternalReferenceType() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE_TYPE); - if (retval.isPresent()) { - if (!(retval.get() instanceof ExternalReferenceType)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getComment() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); } /** - * @param externalReferenceType the externalReferenceType to set + * @param comment the comment to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ExternalReference setExternalReferenceType(@Nullable ExternalReferenceType externalReferenceType) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_EXTERNAL_REFERENCE_TYPE, externalReferenceType); + public ExternalRef setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); return this; } /** - * @return the comment + * @return the contentType */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_COMMENT); + public Optional getContentType() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE); } /** - * @param comment the comment to set + * @param contentType the contentType to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ExternalReference setComment(@Nullable String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_COMMENT, comment); + public ExternalRef setContentType(@Nullable String contentType) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_CONTENT_TYPE, contentType); return this; } @Override public String toString() { - return "ExternalReference: "+getObjectUri(); + return "ExternalRef: "+getObjectUri(); } /* (non-Javadoc) * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - Optional contentType; try { - contentType = getContentType(); - if (contentType.isPresent()) { - retval.addAll(contentType.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional externalRefType = getExternalRefType(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting contentType for ExternalReference: "+e.getMessage()); + retval.add("Error getting externalRefType for ExternalRef: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional externalReferenceType = getExternalReferenceType(); + Optional comment = getComment(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting externalReferenceType for ExternalReference: "+e.getMessage()); + retval.add("Error getting comment for ExternalRef: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional comment = getComment(); + Optional contentType = getContentType(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting comment for ExternalReference: "+e.getMessage()); + retval.add("Error getting contentType for ExternalRef: "+e.getMessage()); } return retval; } - public static class ExternalReferenceBuilder extends ModelObjectBuilder { + public static class ExternalRefBuilder extends ModelObjectBuilder { /** - * Create an ExternalReferenceBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * Create an ExternalRefBuilder from another model object copying the modelStore and copyManager and using an anonymous ID * @param from model object to copy the model store and copyManager from * @throws InvalidSPDXAnalysisException */ - public ExternalReferenceBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + public ExternalRefBuilder(ModelObject from) throws InvalidSPDXAnalysisException { this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); } /** - * Create an ExternalReferenceBuilder from another model object copying the modelStore and copyManager + * Create an ExternalRefBuilder from another model object copying the modelStore and copyManager * @param from model object to copy the model store and copyManager from * @param objectUri URI for the object * @param objectUri */ - public ExternalReferenceBuilder(ModelObject from, String objectUri) { + public ExternalRefBuilder(ModelObject from, String objectUri) { this(from.getModelStore(), objectUri, from.getCopyManager()); setStrict(from.isStrict()); } /** - * Creates a ExternalReferenceBuilder - * @param modelStore model store for the built ExternalReference - * @param objectUri objectUri for the built ExternalReference - * @param copyManager optional copyManager for the built ExternalReference + * Creates a ExternalRefBuilder + * @param modelStore model store for the built ExternalRef + * @param objectUri objectUri for the built ExternalRef + * @param copyManager optional copyManager for the built ExternalRef */ - public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + public ExternalRefBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { super(modelStore, objectUri, copyManager); } Collection locators = new ArrayList<>(); - MediaType contentType = null; - ExternalReferenceType externalReferenceType = null; + ExternalRefType externalRefType = null; String comment = null; + String contentType = null; /** @@ -253,7 +240,7 @@ public ExternalReferenceBuilder(IModelStore modelStore, String objectUri, @Nulla * @parameter locator locator to add * @return this for chaining **/ - public ExternalReferenceBuilder addLocator(String locator) { + public ExternalRefBuilder addLocator(String locator) { if (Objects.nonNull(locator)) { locators.add(locator); } @@ -265,7 +252,7 @@ public ExternalReferenceBuilder addLocator(String locator) { * @parameter locatorCollection collection to initialize the locator * @return this for chaining **/ - public ExternalReferenceBuilder addAllLocator(Collection locatorCollection) { + public ExternalRefBuilder addAllLocator(Collection locatorCollection) { if (Objects.nonNull(locatorCollection)) { locators.addAll(locatorCollection); } @@ -273,44 +260,44 @@ public ExternalReferenceBuilder addAllLocator(Collection locatorCollecti } /** - * Sets the initial value of contentType - * @parameter contentType value to set + * Sets the initial value of externalRefType + * @parameter externalRefType value to set * @return this for chaining **/ - public ExternalReferenceBuilder setContentType(MediaType contentType) { - this.contentType = contentType; + public ExternalRefBuilder setExternalRefType(ExternalRefType externalRefType) { + this.externalRefType = externalRefType; return this; } /** - * Sets the initial value of externalReferenceType - * @parameter externalReferenceType value to set + * Sets the initial value of comment + * @parameter comment value to set * @return this for chaining **/ - public ExternalReferenceBuilder setExternalReferenceType(ExternalReferenceType externalReferenceType) { - this.externalReferenceType = externalReferenceType; + public ExternalRefBuilder setComment(String comment) { + this.comment = comment; return this; } /** - * Sets the initial value of comment - * @parameter comment value to set + * Sets the initial value of contentType + * @parameter contentType value to set * @return this for chaining **/ - public ExternalReferenceBuilder setComment(String comment) { - this.comment = comment; + public ExternalRefBuilder setContentType(String contentType) { + this.contentType = contentType; return this; } /** - * @return the ExternalReference + * @return the ExternalRef * @throws InvalidSPDXAnalysisException on any errors during build */ - public ExternalReference build() throws InvalidSPDXAnalysisException { + public ExternalRef build() throws InvalidSPDXAnalysisException { IModelStoreLock lock = modelStore.enterCriticalSection(false); try { - return new ExternalReference(this); + return new ExternalRef(this); } finally { modelStore.leaveCriticalSection(lock); } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReferenceType.java b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalRefType.java similarity index 85% rename from generated/src/main/java/org/spdx/library/model/v3/core/ExternalReferenceType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/ExternalRefType.java index 779fbefc3..3c0fa3a98 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ExternalReferenceType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ExternalRefType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -24,55 +24,59 @@ * DO NOT EDIT - this file is generated by the Owl to Java Utility * See: https://github.com/spdx/tools-java * - * ExteralReferenceType specifies the type of an external reference. + * ExternalRefType specifies the type of an external reference. */ -public enum ExternalReferenceType implements IndividualUriValue { +public enum ExternalRefType implements IndividualUriValue { - DYNAMIC_ANALYSIS_REPORT("dynamicAnalysisReport"), - EXPORT_CONTROL_ASSESSMENT("exportControlAssessment"), - BUILD_META("buildMeta"), - PRIVACY_ASSESSMENT("privacyAssessment"), - VULNERABILITY_EXPLOITABILITY_ASSESSMENT("vulnerabilityExploitabilityAssessment"), - DOCUMENTATION("documentation"), - RISK_ASSESSMENT("riskAssessment"), - QUALITY_ASSESSMENT_REPORT("qualityAssessmentReport"), - SECURITY_ADVERSARY_MODEL("securityAdversaryModel"), - SECURITY_FIX("securityFix"), - OTHER("other"), + BINARY_ARTIFACT("binaryArtifact"), + PURCHASE_ORDER("purchaseOrder"), + CHAT("chat"), RELEASE_HISTORY("releaseHistory"), - VCS("vcs"), - SECURITY_THREAT_MODEL("securityThreatModel"), - VULNERABILITY_DISCLOSURE_REPORT("vulnerabilityDisclosureReport"), - SOURCE_ARTIFACT("sourceArtifact"), + PRODUCT_METADATA("productMetadata"), FUNDING("funding"), BUILD_SYSTEM("buildSystem"), - CHAT("chat"), - SUPPORT("support"), - ALT_DOWNLOAD_LOCATION("altDownloadLocation"), - RELEASE_NOTES("releaseNotes"), - SECURITY_OTHER("securityOther"), + MAILING_LIST("mailingList"), + NPM("npm"), + SECURITY_ADVISORY("securityAdvisory"), SECURITY_POLICY("securityPolicy"), - RUNTIME_ANALYSIS_REPORT("runtimeAnalysisReport"), - SECURITY_PEN_TEST_REPORT("securityPenTestReport"), + RELEASE_NOTES("releaseNotes"), + DYNAMIC_ANALYSIS_REPORT("dynamicAnalysisReport"), + RISK_ASSESSMENT("riskAssessment"), EOL_NOTICE("eolNotice"), SECURE_SOFTWARE_ATTESTATION("secureSoftwareAttestation"), - CERTIFICATION_REPORT("certificationReport"), + SOCIAL_MEDIA("socialMedia"), + SECURITY_PEN_TEST_REPORT("securityPenTestReport"), + ISSUE_TRACKER("issueTracker"), + PRIVACY_ASSESSMENT("privacyAssessment"), + METRICS("metrics"), + NUGET("nuget"), + QUALITY_ASSESSMENT_REPORT("qualityAssessmentReport"), + VCS("vcs"), STATIC_ANALYSIS_REPORT("staticAnalysisReport"), + MAVEN_CENTRAL("maven-central"), LICENSE("license"), - ALT_WEB_PAGE("altWebPage"), - SECURITY_ADVISORY("securityAdvisory"), - BINARY_ARTIFACT("binaryArtifact"), - MAILING_LIST("mailingList"), - PRODUCT_METADATA("productMetadata"), - METRICS("metrics"), - PURCHASE_ORDER("purchaseOrder"), - SOCIAL_MEDIA("socialMedia"), + ALT_DOWNLOAD_LOCATION("altDownloadLocation"), + CERTIFICATION_REPORT("certificationReport"), + VULNERABILITY_DISCLOSURE_REPORT("vulnerabilityDisclosureReport"), + SECURITY_ADVERSARY_MODEL("securityAdversaryModel"), + BOWER("bower"), + SOURCE_ARTIFACT("sourceArtifact"), + EXPORT_CONTROL_ASSESSMENT("exportControlAssessment"), + SECURITY_OTHER("securityOther"), COMPONENT_ANALYSIS_REPORT("componentAnalysisReport"), - ISSUE_TRACKER("issueTracker"); + ALT_WEB_PAGE("altWebPage"), + BUILD_META("buildMeta"), + VULNERABILITY_EXPLOITABILITY_ASSESSMENT("vulnerabilityExploitabilityAssessment"), + SUPPORT("support"), + SECURITY_FIX("securityFix"), + OTHER("other"), + DOCUMENTATION("documentation"), + SECURITY_THREAT_MODEL("securityThreatModel"), + RUNTIME_ANALYSIS_REPORT("runtimeAnalysisReport"); private String longName; - private ExternalReferenceType(String longName) { + private ExternalRefType(String longName) { this.longName = longName; } @@ -86,7 +90,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/v3/Core/ExternalReferenceType"; + return "https://spdx.org/rdf/v3/Core/ExternalRefType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Hash.java b/generated/src/main/java/org/spdx/library/model/v3/core/Hash.java index a67c06665..7eb37e270 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Hash.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Hash.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -157,9 +157,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { HashAlgorithm algorithm = getAlgorithm(); if (Objects.isNull(algorithm) && diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java b/generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java index 7e7448d4b..db3d9bf2a 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/HashAlgorithm.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java b/generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java index f6ab8cdbf..df443bc7f 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/IntegrityMethod.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -123,7 +123,7 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); try { @SuppressWarnings("unused") diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java index e26cc59b8..a3d6d437b 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopeType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java index 907842cc8..68d580fae 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/LifecycleScopedRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -128,9 +128,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional scope = getScope(); diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Organization.java b/generated/src/main/java/org/spdx/library/model/v3/core/Organization.java index 719422758..15467184c 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Organization.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Organization.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -101,9 +101,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Person.java b/generated/src/main/java/org/spdx/library/model/v3/core/Person.java index 5522cbec9..b72ea8ed4 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Person.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Person.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -100,9 +100,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java b/generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java index 54cce752a..c28786372 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/PositiveIntegerRange.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -83,8 +83,8 @@ public PositiveIntegerRange(IModelStore modelStore, String objectUri, @Nullable */ protected PositiveIntegerRange(PositiveIntegerRangeBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setBegin(builder.begin); setEnd(builder.end); + setBegin(builder.begin); } /* (non-Javadoc) @@ -99,50 +99,50 @@ public String getType() { /** - * @return the begin + * @return the end */ - public @Nullable Integer getBegin() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_BEGIN); + public @Nullable Integer getEnd() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_END); return retval.isPresent() ? retval.get() : null; } /** - * @param begin the begin to set + * @param end the end to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public PositiveIntegerRange setBegin(@Nullable Integer begin) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(begin)) { - throw new InvalidSPDXAnalysisException("begin is a required property"); + public PositiveIntegerRange setEnd(@Nullable Integer end) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(end)) { + throw new InvalidSPDXAnalysisException("end is a required property"); } - if (isStrict() && Objects.nonNull(begin) && begin < 1) { - throw new InvalidSPDXAnalysisException("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); + if (isStrict() && Objects.nonNull(end) && end < 1) { + throw new InvalidSPDXAnalysisException("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); } - setPropertyValue(SpdxConstants.CORE_PROP_BEGIN, begin); + setPropertyValue(SpdxConstants.CORE_PROP_END, end); return this; } /** - * @return the end + * @return the begin */ - public @Nullable Integer getEnd() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_END); + public @Nullable Integer getBegin() throws InvalidSPDXAnalysisException { + Optional retval = getIntegerPropertyValue(SpdxConstants.CORE_PROP_BEGIN); return retval.isPresent() ? retval.get() : null; } /** - * @param end the end to set + * @param begin the begin to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public PositiveIntegerRange setEnd(@Nullable Integer end) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(end)) { - throw new InvalidSPDXAnalysisException("end is a required property"); + public PositiveIntegerRange setBegin(@Nullable Integer begin) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(begin)) { + throw new InvalidSPDXAnalysisException("begin is a required property"); } - if (isStrict() && Objects.nonNull(end) && end < 1) { - throw new InvalidSPDXAnalysisException("end value " + end + " is less than the minimum 1 in PositiveIntegerRange"); + if (isStrict() && Objects.nonNull(begin) && begin < 1) { + throw new InvalidSPDXAnalysisException("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); } - setPropertyValue(SpdxConstants.CORE_PROP_END, end); + setPropertyValue(SpdxConstants.CORE_PROP_BEGIN, begin); return this; } @@ -156,20 +156,8 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - try { - Integer begin = getBegin(); - if (Objects.isNull(begin) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing begin in PositiveIntegerRange"); - } - if (Objects.nonNull(begin) && begin < 1) { - retval.add("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting begin for PositiveIntegerRange: "+e.getMessage()); - } try { Integer end = getEnd(); if (Objects.isNull(end) && @@ -182,6 +170,18 @@ protected List _verify(Set verifiedIds, String specVersion, List } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting end for PositiveIntegerRange: "+e.getMessage()); } + try { + Integer begin = getBegin(); + if (Objects.isNull(begin) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { + retval.add("Missing begin in PositiveIntegerRange"); + } + if (Objects.nonNull(begin) && begin < 1) { + retval.add("begin value " + begin + " is less than the minimum 1 in PositiveIntegerRange"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting begin for PositiveIntegerRange: "+e.getMessage()); + } return retval; } @@ -217,27 +217,27 @@ public PositiveIntegerRangeBuilder(IModelStore modelStore, String objectUri, @Nu super(modelStore, objectUri, copyManager); } - Integer begin = null; Integer end = null; + Integer begin = null; /** - * Sets the initial value of begin - * @parameter begin value to set + * Sets the initial value of end + * @parameter end value to set * @return this for chaining **/ - public PositiveIntegerRangeBuilder setBegin(Integer begin) { - this.begin = begin; + public PositiveIntegerRangeBuilder setEnd(Integer end) { + this.end = end; return this; } /** - * Sets the initial value of end - * @parameter end value to set + * Sets the initial value of begin + * @parameter begin value to set * @return this for chaining **/ - public PositiveIntegerRangeBuilder setEnd(Integer end) { - this.end = end; + public PositiveIntegerRangeBuilder setBegin(Integer begin) { + this.begin = begin; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/ai/PresenceType.java b/generated/src/main/java/org/spdx/library/model/v3/core/PresenceType.java similarity index 87% rename from generated/src/main/java/org/spdx/library/model/v3/ai/PresenceType.java rename to generated/src/main/java/org/spdx/library/model/v3/core/PresenceType.java index b5cb42a0a..9685cbb71 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/ai/PresenceType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/PresenceType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.ai; +package org.spdx.library.model.v3.core; import org.spdx.library.IndividualUriValue; @@ -28,9 +28,9 @@ */ public enum PresenceType implements IndividualUriValue { - NO_ASSERTION("noAssertion"), NO("no"), - YES("yes"); + YES("yes"), + NO_ASSERTION("noAssertion"); private String longName; @@ -48,7 +48,7 @@ public String getLongName() { } public String getNameSpace() { - return "https://spdx.org/rdf/v3/AI/PresenceType"; + return "https://spdx.org/rdf/v3/Core/PresenceType"; } } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java b/generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java index 390e3cfc3..2e5772c44 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/ProfileIdentifierType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -30,14 +30,15 @@ */ public enum ProfileIdentifierType implements IndividualUriValue { + EXPANDED_LICENSING("expandedLicensing"), BUILD("build"), EXTENSION("extension"), SECURITY("security"), DATASET("dataset"), + SIMPLE_LICENSING("simpleLicensing"), USAGE("usage"), SOFTWARE("software"), CORE("core"), - LICENSING("licensing"), AI("ai"); private String longName; diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java b/generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java index a423e0046..afddacc69 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Relationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -90,11 +90,11 @@ protected Relationship(RelationshipBuilder builder) throws InvalidSPDXAnalysisEx super(builder); tos = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.CORE_PROP_TO, Element.class); getTos().addAll(builder.tos); - setEndTime(builder.endTime); setFrom(builder.from); - setStartTime(builder.startTime); - setRelationshipType(builder.relationshipType); setCompleteness(builder.completeness); + setRelationshipType(builder.relationshipType); + setStartTime(builder.startTime); + setEndTime(builder.endTime); } /* (non-Javadoc) @@ -111,32 +111,6 @@ public Collection getTos() { } - /** - * @return the endTime - */ - @SuppressWarnings("unchecked") - public Optional getEndTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_END_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } - } - - /** - * @param endTime the endTime to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Relationship setEndTime(@Nullable DateTime endTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_END_TIME, endTime); - return this; - } - /** * @return the from */ @@ -165,30 +139,29 @@ public Relationship setFrom(@Nullable Element from) throws InvalidSPDXAnalysisEx setPropertyValue(SpdxConstants.CORE_PROP_FROM, from); return this; } - - /** - * @return the startTime + + /** + * @return the completeness */ @SuppressWarnings("unchecked") - public Optional getStartTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.CORE_PROP_START_TIME); + public Optional getCompleteness() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS); if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { + if (!(retval.get() instanceof RelationshipCompleteness)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } - /** - * @param startTime the startTime to set + * @param completeness the completeness to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Relationship setStartTime(@Nullable DateTime startTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_START_TIME, startTime); + public Relationship setCompleteness(@Nullable RelationshipCompleteness completeness) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS, completeness); return this; } @@ -218,29 +191,36 @@ public Relationship setRelationshipType(@Nullable RelationshipType relationshipT setPropertyValue(SpdxConstants.CORE_PROP_RELATIONSHIP_TYPE, relationshipType); return this; } - + + /** + * @return the startTime + */ + public Optional getStartTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_START_TIME); + } /** - * @return the completeness + * @param startTime the startTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException */ - @SuppressWarnings("unchecked") - public Optional getCompleteness() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS); - if (retval.isPresent()) { - if (!(retval.get() instanceof RelationshipCompleteness)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Relationship setStartTime(@Nullable String startTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_START_TIME, startTime); + return this; + } + + /** + * @return the endTime + */ + public Optional getEndTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.CORE_PROP_END_TIME); } /** - * @param completeness the completeness to set + * @param endTime the endTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Relationship setCompleteness(@Nullable RelationshipCompleteness completeness) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.CORE_PROP_COMPLETENESS, completeness); + public Relationship setEndTime(@Nullable String endTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.CORE_PROP_END_TIME, endTime); return this; } @@ -254,37 +234,25 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional endTime; - try { - endTime = getEndTime(); - if (endTime.isPresent()) { - retval.addAll(endTime.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting endTime for Relationship: "+e.getMessage()); - } + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); Element from; try { from = getFrom(); if (Objects.nonNull(from)) { - retval.addAll(from.verify(verifiedIds, specVersion, profiles)); + retval.addAll(from.verify(verifiedIds, specVersionForVerify, profiles)); } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { retval.add("Missing from in Relationship"); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting from for Relationship: "+e.getMessage()); } - Optional startTime; try { - startTime = getStartTime(); - if (startTime.isPresent()) { - retval.addAll(startTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional completeness = getCompleteness(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting startTime for Relationship: "+e.getMessage()); + retval.add("Error getting completeness for Relationship: "+e.getMessage()); } try { RelationshipType relationshipType = getRelationshipType(); @@ -297,12 +265,18 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional completeness = getCompleteness(); + Optional startTime = getStartTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting completeness for Relationship: "+e.getMessage()); + retval.add("Error getting startTime for Relationship: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional endTime = getEndTime(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting endTime for Relationship: "+e.getMessage()); } for (Element to:tos) { - retval.addAll(to.verify(verifiedIds, specVersion, profiles)); + retval.addAll(to.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -340,11 +314,11 @@ public RelationshipBuilder(IModelStore modelStore, String objectUri, @Nullable M } Collection tos = new ArrayList<>(); - DateTime endTime = null; Element from = null; - DateTime startTime = null; - RelationshipType relationshipType = null; RelationshipCompleteness completeness = null; + RelationshipType relationshipType = null; + String startTime = null; + String endTime = null; /** @@ -371,16 +345,6 @@ public RelationshipBuilder addAllTo(Collection toCollection) { return this; } - /** - * Sets the initial value of endTime - * @parameter endTime value to set - * @return this for chaining - **/ - public RelationshipBuilder setEndTime(DateTime endTime) { - this.endTime = endTime; - return this; - } - /** * Sets the initial value of from * @parameter from value to set @@ -392,12 +356,12 @@ public RelationshipBuilder setFrom(Element from) { } /** - * Sets the initial value of startTime - * @parameter startTime value to set + * Sets the initial value of completeness + * @parameter completeness value to set * @return this for chaining **/ - public RelationshipBuilder setStartTime(DateTime startTime) { - this.startTime = startTime; + public RelationshipBuilder setCompleteness(RelationshipCompleteness completeness) { + this.completeness = completeness; return this; } @@ -412,12 +376,22 @@ public RelationshipBuilder setRelationshipType(RelationshipType relationshipType } /** - * Sets the initial value of completeness - * @parameter completeness value to set + * Sets the initial value of startTime + * @parameter startTime value to set * @return this for chaining **/ - public RelationshipBuilder setCompleteness(RelationshipCompleteness completeness) { - this.completeness = completeness; + public RelationshipBuilder setStartTime(String startTime) { + this.startTime = startTime; + return this; + } + + /** + * Sets the initial value of endTime + * @parameter endTime value to set + * @return this for chaining + **/ + public RelationshipBuilder setEndTime(String endTime) { + this.endTime = endTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java index a269818c0..d33e0d0bc 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipCompleteness.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -24,8 +24,9 @@ * DO NOT EDIT - this file is generated by the Owl to Java Utility * See: https://github.com/spdx/tools-java * - * RelationshipCompleteness indicates whether a relationship is complete or known - * to be incomplete or if there is made no assertion either way. + * RelationshipCompleteness indicates whether the provided relationship is known + * to be complete, known to be incomplete, or if no assertion is made by the relationship + * creator. */ public enum RelationshipCompleteness implements IndividualUriValue { diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java index 197a41365..976c69369 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/RelationshipType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -62,6 +62,7 @@ public enum RelationshipType implements IndividualUriValue { CONTAINS("contains"), DESCENDANT("descendant"), TEST_CASE("testCase"), + CONCLUDED_LICENSE("concludedLicense"), PREREQUISITE("prerequisite"), REQUIREMENT_FOR("requirementFor"), OTHER("other"), @@ -70,6 +71,7 @@ public enum RelationshipType implements IndividualUriValue { TEST_DEPENDENCY("testDependency"), DEV_DEPENDENCY("devDependency"), STATIC_LINK("staticLink"), + DECLARED_LICENSE("declaredLicense"), AFFECTS("affects"), ON_BEHALF_OF("onBehalfOf"), EVIDENCE_FOR("evidenceFor"), diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java b/generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java index 6d98287ca..4e59cb106 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/SoftwareAgent.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -101,9 +101,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java b/generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java index 8531b0010..cecc2407b 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/SpdxDocument.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -32,11 +32,6 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import java.util.Arrays; -import java.util.Collections; -import java.util.Objects; -import java.util.Optional; -import org.spdx.library.SpdxConstants; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -84,7 +79,6 @@ public SpdxDocument(IModelStore modelStore, String objectUri, @Nullable ModelCop */ protected SpdxDocument(SpdxDocumentBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setName(builder.name); } /* (non-Javadoc) @@ -97,25 +91,6 @@ public String getType() { // Getters and Setters - - /** - * @return the name - */ - public Optional getName() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.CORE_PROP_NAME); - } - /** - * @param name the name to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxDocument setName(@Nullable String name) throws InvalidSPDXAnalysisException { - if (isStrict() && Objects.isNull(name)) { - throw new InvalidSPDXAnalysisException("name is a required property"); - } - setPropertyValue(SpdxConstants.CORE_PROP_NAME, name); - return this; - } @Override @@ -127,18 +102,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - try { - Optional name = getName(); - if (!name.isPresent() && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.CORE }))) { - retval.add("Missing name in SpdxDocument"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting name for SpdxDocument: "+e.getMessage()); - } + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } @@ -174,18 +140,7 @@ public SpdxDocumentBuilder(IModelStore modelStore, String objectUri, @Nullable M super(modelStore, objectUri, copyManager); } - String name = null; - - /** - * Sets the initial value of name - * @parameter name value to set - * @return this for chaining - **/ - public SpdxDocumentBuilder setName(String name) { - this.name = name; - return this; - } /** diff --git a/generated/src/main/java/org/spdx/library/model/v3/core/Tool.java b/generated/src/main/java/org/spdx/library/model/v3/core/Tool.java index 4235e59f2..223781561 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/core/Tool.java +++ b/generated/src/main/java/org/spdx/library/model/v3/core/Tool.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -101,9 +101,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java index 9e8f20537..b2322e951 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/ConfidentialityLevelType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java index 49ee58f25..5569b322a 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/Dataset.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -38,8 +38,9 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.DictionaryEntry; +import org.spdx.library.model.v3.core.PresenceType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.library.model.v3.software.SpdxPackage; /** @@ -57,8 +58,8 @@ public class Dataset extends SpdxPackage { Collection sensors; Collection anonymizationMethodUseds; - Collection dataPreprocessings; Collection knownBiass; + Collection dataPreprocessings; Collection datasetTypes; /** @@ -91,8 +92,8 @@ public Dataset(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana sensors = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_SENSOR, DictionaryEntry.class); datasetTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATASET_TYPE, DatasetType.class); anonymizationMethodUseds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_ANONYMIZATION_METHOD_USED, String.class); - dataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATA_PREPROCESSING, String.class); knownBiass = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_KNOWN_BIAS, String.class); + dataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATA_PREPROCESSING, String.class); } /** @@ -106,21 +107,21 @@ protected Dataset(DatasetBuilder builder) throws InvalidSPDXAnalysisException { sensors = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_SENSOR, DictionaryEntry.class); datasetTypes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATASET_TYPE, DatasetType.class); anonymizationMethodUseds = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_ANONYMIZATION_METHOD_USED, String.class); - dataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATA_PREPROCESSING, String.class); knownBiass = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_KNOWN_BIAS, String.class); + dataPreprocessings = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.DATASET_PROP_DATA_PREPROCESSING, String.class); getSensors().addAll(builder.sensors); getDatasetTypes().addAll(builder.datasetTypes); getAnonymizationMethodUseds().addAll(builder.anonymizationMethodUseds); - getDataPreprocessings().addAll(builder.dataPreprocessings); getKnownBiass().addAll(builder.knownBiass); + getDataPreprocessings().addAll(builder.dataPreprocessings); setSensitivePersonalInformation(builder.sensitivePersonalInformation); - setConfidentialityLevel(builder.confidentialityLevel); setDatasetAvailability(builder.datasetAvailability); + setConfidentialityLevel(builder.confidentialityLevel); setDatasetSize(builder.datasetSize); + setDatasetUpdateMechanism(builder.datasetUpdateMechanism); + setDataCollectionProcess(builder.dataCollectionProcess); setIntendedUse(builder.intendedUse); setDatasetNoise(builder.datasetNoise); - setDataCollectionProcess(builder.dataCollectionProcess); - setDatasetUpdateMechanism(builder.datasetUpdateMechanism); } /* (non-Javadoc) @@ -141,20 +142,20 @@ public Collection getDatasetTypes() { public Collection getAnonymizationMethodUseds() { return anonymizationMethodUseds; } - public Collection getDataPreprocessings() { - return dataPreprocessings; - } public Collection getKnownBiass() { return knownBiass; } + public Collection getDataPreprocessings() { + return dataPreprocessings; + } - - /** + + /** * @return the sensitivePersonalInformation */ @SuppressWarnings("unchecked") public Optional getSensitivePersonalInformation() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION); + Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_SENSITIVE_PERSONAL_INFORMATION); if (retval.isPresent()) { if (!(retval.get() instanceof PresenceType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -164,7 +165,6 @@ public Optional getSensitivePersonalInformation() throws InvalidSP return Optional.empty(); } } - /** * @param sensitivePersonalInformation the sensitivePersonalInformation to set * @return this to chain setters @@ -176,52 +176,52 @@ public Dataset setSensitivePersonalInformation(@Nullable PresenceType sensitiveP } /** - * @return the confidentialityLevel + * @return the datasetAvailability */ @SuppressWarnings("unchecked") - public Optional getConfidentialityLevel() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_CONFIDENTIALITY_LEVEL); + public Optional getDatasetAvailability() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_DATASET_AVAILABILITY); if (retval.isPresent()) { - if (!(retval.get() instanceof ConfidentialityLevelType)) { + if (!(retval.get() instanceof DatasetAvailabilityType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } /** - * @param confidentialityLevel the confidentialityLevel to set + * @param datasetAvailability the datasetAvailability to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Dataset setConfidentialityLevel(@Nullable ConfidentialityLevelType confidentialityLevel) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_CONFIDENTIALITY_LEVEL, confidentialityLevel); + public Dataset setDatasetAvailability(@Nullable DatasetAvailabilityType datasetAvailability) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_AVAILABILITY, datasetAvailability); return this; } /** - * @return the datasetAvailability + * @return the confidentialityLevel */ @SuppressWarnings("unchecked") - public Optional getDatasetAvailability() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_DATASET_AVAILABILITY); + public Optional getConfidentialityLevel() throws InvalidSPDXAnalysisException { + Optional> retval = getEnumPropertyValue(SpdxConstants.DATASET_PROP_CONFIDENTIALITY_LEVEL); if (retval.isPresent()) { - if (!(retval.get() instanceof DatasetAvailabilityType)) { + if (!(retval.get() instanceof ConfidentialityLevelType)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } /** - * @param datasetAvailability the datasetAvailability to set + * @param confidentialityLevel the confidentialityLevel to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Dataset setDatasetAvailability(@Nullable DatasetAvailabilityType datasetAvailability) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_AVAILABILITY, datasetAvailability); + public Dataset setConfidentialityLevel(@Nullable ConfidentialityLevelType confidentialityLevel) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_CONFIDENTIALITY_LEVEL, confidentialityLevel); return this; } @@ -246,66 +246,66 @@ public Dataset setDatasetSize(@Nullable Integer datasetSize) throws InvalidSPDXA } /** - * @return the intendedUse + * @return the datasetUpdateMechanism */ - public Optional getIntendedUse() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.DATASET_PROP_INTENDED_USE); + public Optional getDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATASET_UPDATE_MECHANISM); } /** - * @param intendedUse the intendedUse to set + * @param datasetUpdateMechanism the datasetUpdateMechanism to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Dataset setIntendedUse(@Nullable String intendedUse) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_INTENDED_USE, intendedUse); + public Dataset setDatasetUpdateMechanism(@Nullable String datasetUpdateMechanism) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_UPDATE_MECHANISM, datasetUpdateMechanism); return this; } /** - * @return the datasetNoise + * @return the dataCollectionProcess */ - public Optional getDatasetNoise() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATASET_NOISE); + public Optional getDataCollectionProcess() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATA_COLLECTION_PROCESS); } /** - * @param datasetNoise the datasetNoise to set + * @param dataCollectionProcess the dataCollectionProcess to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Dataset setDatasetNoise(@Nullable String datasetNoise) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_NOISE, datasetNoise); + public Dataset setDataCollectionProcess(@Nullable String dataCollectionProcess) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATA_COLLECTION_PROCESS, dataCollectionProcess); return this; } /** - * @return the dataCollectionProcess + * @return the intendedUse */ - public Optional getDataCollectionProcess() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATA_COLLECTION_PROCESS); + public Optional getIntendedUse() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_INTENDED_USE); } /** - * @param dataCollectionProcess the dataCollectionProcess to set + * @param intendedUse the intendedUse to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Dataset setDataCollectionProcess(@Nullable String dataCollectionProcess) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_DATA_COLLECTION_PROCESS, dataCollectionProcess); + public Dataset setIntendedUse(@Nullable String intendedUse) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_INTENDED_USE, intendedUse); return this; } /** - * @return the datasetUpdateMechanism + * @return the datasetNoise */ - public Optional getDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATASET_UPDATE_MECHANISM); + public Optional getDatasetNoise() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.DATASET_PROP_DATASET_NOISE); } /** - * @param datasetUpdateMechanism the datasetUpdateMechanism to set + * @param datasetNoise the datasetNoise to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Dataset setDatasetUpdateMechanism(@Nullable String datasetUpdateMechanism) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_UPDATE_MECHANISM, datasetUpdateMechanism); + public Dataset setDatasetNoise(@Nullable String datasetNoise) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.DATASET_PROP_DATASET_NOISE, datasetNoise); return this; } @@ -319,29 +319,26 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional sensitivePersonalInformation; + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { - sensitivePersonalInformation = getSensitivePersonalInformation(); - if (sensitivePersonalInformation.isPresent()) { - retval.addAll(sensitivePersonalInformation.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional sensitivePersonalInformation = getSensitivePersonalInformation(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting sensitivePersonalInformation for Dataset: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional confidentialityLevel = getConfidentialityLevel(); + Optional datasetAvailability = getDatasetAvailability(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting confidentialityLevel for Dataset: "+e.getMessage()); + retval.add("Error getting datasetAvailability for Dataset: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional datasetAvailability = getDatasetAvailability(); + Optional confidentialityLevel = getConfidentialityLevel(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting datasetAvailability for Dataset: "+e.getMessage()); + retval.add("Error getting confidentialityLevel for Dataset: "+e.getMessage()); } try { Optional datasetSize = getDatasetSize(); @@ -353,30 +350,30 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional intendedUse = getIntendedUse(); + Optional datasetUpdateMechanism = getDatasetUpdateMechanism(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting intendedUse for Dataset: "+e.getMessage()); + retval.add("Error getting datasetUpdateMechanism for Dataset: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional datasetNoise = getDatasetNoise(); + Optional dataCollectionProcess = getDataCollectionProcess(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting datasetNoise for Dataset: "+e.getMessage()); + retval.add("Error getting dataCollectionProcess for Dataset: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional dataCollectionProcess = getDataCollectionProcess(); + Optional intendedUse = getIntendedUse(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting dataCollectionProcess for Dataset: "+e.getMessage()); + retval.add("Error getting intendedUse for Dataset: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional datasetUpdateMechanism = getDatasetUpdateMechanism(); + Optional datasetNoise = getDatasetNoise(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting datasetUpdateMechanism for Dataset: "+e.getMessage()); + retval.add("Error getting datasetNoise for Dataset: "+e.getMessage()); } for (DictionaryEntry sensor:sensors) { - retval.addAll(sensor.verify(verifiedIds, specVersion, profiles)); + retval.addAll(sensor.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } @@ -416,16 +413,16 @@ public DatasetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC Collection sensors = new ArrayList<>(); Collection datasetTypes = new ArrayList<>(); Collection anonymizationMethodUseds = new ArrayList<>(); - Collection dataPreprocessings = new ArrayList<>(); Collection knownBiass = new ArrayList<>(); + Collection dataPreprocessings = new ArrayList<>(); PresenceType sensitivePersonalInformation = null; - ConfidentialityLevelType confidentialityLevel = null; DatasetAvailabilityType datasetAvailability = null; + ConfidentialityLevelType confidentialityLevel = null; Integer datasetSize = null; + String datasetUpdateMechanism = null; + String dataCollectionProcess = null; String intendedUse = null; String datasetNoise = null; - String dataCollectionProcess = null; - String datasetUpdateMechanism = null; /** @@ -501,49 +498,49 @@ public DatasetBuilder addAllAnonymizationMethodUsed(Collection anonymiza } /** - * Adds a dataPreprocessing to the initial collection - * @parameter dataPreprocessing dataPreprocessing to add + * Adds a knownBias to the initial collection + * @parameter knownBias knownBias to add * @return this for chaining **/ - public DatasetBuilder addDataPreprocessing(String dataPreprocessing) { - if (Objects.nonNull(dataPreprocessing)) { - dataPreprocessings.add(dataPreprocessing); + public DatasetBuilder addKnownBias(String knownBias) { + if (Objects.nonNull(knownBias)) { + knownBiass.add(knownBias); } return this; } /** - * Adds all elements from a collection to the initial dataPreprocessing collection - * @parameter dataPreprocessingCollection collection to initialize the dataPreprocessing + * Adds all elements from a collection to the initial knownBias collection + * @parameter knownBiasCollection collection to initialize the knownBias * @return this for chaining **/ - public DatasetBuilder addAllDataPreprocessing(Collection dataPreprocessingCollection) { - if (Objects.nonNull(dataPreprocessingCollection)) { - dataPreprocessings.addAll(dataPreprocessingCollection); + public DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { + if (Objects.nonNull(knownBiasCollection)) { + knownBiass.addAll(knownBiasCollection); } return this; } /** - * Adds a knownBias to the initial collection - * @parameter knownBias knownBias to add + * Adds a dataPreprocessing to the initial collection + * @parameter dataPreprocessing dataPreprocessing to add * @return this for chaining **/ - public DatasetBuilder addKnownBias(String knownBias) { - if (Objects.nonNull(knownBias)) { - knownBiass.add(knownBias); + public DatasetBuilder addDataPreprocessing(String dataPreprocessing) { + if (Objects.nonNull(dataPreprocessing)) { + dataPreprocessings.add(dataPreprocessing); } return this; } /** - * Adds all elements from a collection to the initial knownBias collection - * @parameter knownBiasCollection collection to initialize the knownBias + * Adds all elements from a collection to the initial dataPreprocessing collection + * @parameter dataPreprocessingCollection collection to initialize the dataPreprocessing * @return this for chaining **/ - public DatasetBuilder addAllKnownBias(Collection knownBiasCollection) { - if (Objects.nonNull(knownBiasCollection)) { - knownBiass.addAll(knownBiasCollection); + public DatasetBuilder addAllDataPreprocessing(Collection dataPreprocessingCollection) { + if (Objects.nonNull(dataPreprocessingCollection)) { + dataPreprocessings.addAll(dataPreprocessingCollection); } return this; } @@ -559,22 +556,22 @@ public DatasetBuilder setSensitivePersonalInformation(PresenceType sensitivePers } /** - * Sets the initial value of confidentialityLevel - * @parameter confidentialityLevel value to set + * Sets the initial value of datasetAvailability + * @parameter datasetAvailability value to set * @return this for chaining **/ - public DatasetBuilder setConfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { - this.confidentialityLevel = confidentialityLevel; + public DatasetBuilder setDatasetAvailability(DatasetAvailabilityType datasetAvailability) { + this.datasetAvailability = datasetAvailability; return this; } /** - * Sets the initial value of datasetAvailability - * @parameter datasetAvailability value to set + * Sets the initial value of confidentialityLevel + * @parameter confidentialityLevel value to set * @return this for chaining **/ - public DatasetBuilder setDatasetAvailability(DatasetAvailabilityType datasetAvailability) { - this.datasetAvailability = datasetAvailability; + public DatasetBuilder setConfidentialityLevel(ConfidentialityLevelType confidentialityLevel) { + this.confidentialityLevel = confidentialityLevel; return this; } @@ -589,42 +586,42 @@ public DatasetBuilder setDatasetSize(Integer datasetSize) { } /** - * Sets the initial value of intendedUse - * @parameter intendedUse value to set + * Sets the initial value of datasetUpdateMechanism + * @parameter datasetUpdateMechanism value to set * @return this for chaining **/ - public DatasetBuilder setIntendedUse(String intendedUse) { - this.intendedUse = intendedUse; + public DatasetBuilder setDatasetUpdateMechanism(String datasetUpdateMechanism) { + this.datasetUpdateMechanism = datasetUpdateMechanism; return this; } /** - * Sets the initial value of datasetNoise - * @parameter datasetNoise value to set + * Sets the initial value of dataCollectionProcess + * @parameter dataCollectionProcess value to set * @return this for chaining **/ - public DatasetBuilder setDatasetNoise(String datasetNoise) { - this.datasetNoise = datasetNoise; + public DatasetBuilder setDataCollectionProcess(String dataCollectionProcess) { + this.dataCollectionProcess = dataCollectionProcess; return this; } /** - * Sets the initial value of dataCollectionProcess - * @parameter dataCollectionProcess value to set + * Sets the initial value of intendedUse + * @parameter intendedUse value to set * @return this for chaining **/ - public DatasetBuilder setDataCollectionProcess(String dataCollectionProcess) { - this.dataCollectionProcess = dataCollectionProcess; + public DatasetBuilder setIntendedUse(String intendedUse) { + this.intendedUse = intendedUse; return this; } /** - * Sets the initial value of datasetUpdateMechanism - * @parameter datasetUpdateMechanism value to set + * Sets the initial value of datasetNoise + * @parameter datasetNoise value to set * @return this for chaining **/ - public DatasetBuilder setDatasetUpdateMechanism(String datasetUpdateMechanism) { - this.datasetUpdateMechanism = datasetUpdateMechanism; + public DatasetBuilder setDatasetNoise(String datasetNoise) { + this.datasetNoise = datasetNoise; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java index ea6279535..5d6987bb0 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetAvailabilityType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java index 80e16edb8..d744e0034 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/dataset/DatasetType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ConjunctiveLicenseSet.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSet.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ConjunctiveLicenseSet.java index b51f44639..2b22208ef 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ConjunctiveLicenseSet.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.expandedlicense; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -38,8 +38,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,7 +86,7 @@ public ConjunctiveLicenseSet(String objectUri) throws InvalidSPDXAnalysisExcepti public ConjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSING_PROP_MEMBER, AnyLicenseInfo.class); } /** @@ -97,7 +97,7 @@ public ConjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable @SuppressWarnings("unchecked") protected ConjunctiveLicenseSet(ConjunctiveLicenseSetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSING_PROP_MEMBER, AnyLicenseInfo.class); getMembers().addAll(builder.members); } @@ -106,7 +106,7 @@ protected ConjunctiveLicenseSet(ConjunctiveLicenseSetBuilder builder) throws Inv */ @Override public String getType() { - return "ExpandedLicense.ConjunctiveLicenseSet"; + return "ExpandedLicensing.ConjunctiveLicenseSet"; } // Getters and Setters @@ -125,11 +125,11 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); for (AnyLicenseInfo member:members) { - retval.addAll(member.verify(verifiedIds, specVersion, profiles)); + retval.addAll(member.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicense.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/CustomLicense.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicense.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/CustomLicense.java index 2494797d8..202dddfb2 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicense.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/CustomLicense.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -32,7 +32,7 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,7 +86,7 @@ protected CustomLicense(CustomLicenseBuilder builder) throws InvalidSPDXAnalysis */ @Override public String getType() { - return "Licensing.CustomLicense"; + return "ExpandedLicensing.CustomLicense"; } // Getters and Setters @@ -102,9 +102,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicenseAddition.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseAddition.java similarity index 93% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicenseAddition.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseAddition.java index 478f8afaa..ff1ce7767 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/CustomLicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseAddition.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -32,7 +32,7 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -89,7 +89,7 @@ protected CustomLicenseAddition(CustomLicenseAdditionBuilder builder) throws Inv */ @Override public String getType() { - return "Licensing.CustomLicenseAddition"; + return "ExpandedLicensing.CustomLicenseAddition"; } // Getters and Setters @@ -105,9 +105,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSet.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/DisjunctiveLicenseSet.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSet.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/DisjunctiveLicenseSet.java index 49ec22c72..5fa4e12c0 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSet.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/DisjunctiveLicenseSet.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.expandedlicense; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -38,8 +38,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -84,7 +84,7 @@ public DisjunctiveLicenseSet(String objectUri) throws InvalidSPDXAnalysisExcepti public DisjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSING_PROP_MEMBER, AnyLicenseInfo.class); } /** @@ -95,7 +95,7 @@ public DisjunctiveLicenseSet(IModelStore modelStore, String objectUri, @Nullable @SuppressWarnings("unchecked") protected DisjunctiveLicenseSet(DisjunctiveLicenseSetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSE_PROP_MEMBER, AnyLicenseInfo.class); + members = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.EXPANDED_LICENSING_PROP_MEMBER, AnyLicenseInfo.class); getMembers().addAll(builder.members); } @@ -104,7 +104,7 @@ protected DisjunctiveLicenseSet(DisjunctiveLicenseSetBuilder builder) throws Inv */ @Override public String getType() { - return "ExpandedLicense.DisjunctiveLicenseSet"; + return "ExpandedLicensing.DisjunctiveLicenseSet"; } // Getters and Setters @@ -123,11 +123,11 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); for (AnyLicenseInfo member:members) { - retval.addAll(member.verify(verifiedIds, specVersion, profiles)); + retval.addAll(member.verify(verifiedIds, specVersionForVerify, profiles)); } return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/ExtendableLicense.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ExtendableLicense.java similarity index 91% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/ExtendableLicense.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ExtendableLicense.java index 1bf775571..7786588d0 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/ExtendableLicense.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ExtendableLicense.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -32,7 +32,8 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -86,7 +87,7 @@ protected ExtendableLicense(ExtendableLicenseBuilder builder) throws InvalidSPDX */ @Override public String getType() { - return "Licensing.ExtendableLicense"; + return "ExpandedLicensing.ExtendableLicense"; } // Getters and Setters @@ -102,9 +103,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/License.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/License.java similarity index 81% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/License.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/License.java index db263c86d..db5d7d23f 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/License.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/License.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -85,12 +85,13 @@ public License(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana protected License(LicenseBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setIsFsfLibre(builder.isFsfLibre); - setIsOsiApproved(builder.isOsiApproved); setIsDeprecatedLicenseId(builder.isDeprecatedLicenseId); - setStandardLicenseTemplate(builder.standardLicenseTemplate); + setIsOsiApproved(builder.isOsiApproved); setObsoletedBy(builder.obsoletedBy); setStandardLicenseHeader(builder.standardLicenseHeader); setLicenseText(builder.licenseText); + setLicenseXml(builder.licenseXml); + setStandardLicenseTemplate(builder.standardLicenseTemplate); } /* (non-Javadoc) @@ -98,7 +99,7 @@ protected License(LicenseBuilder builder) throws InvalidSPDXAnalysisException { */ @Override public String getType() { - return "Licensing.License"; + return "ExpandedLicensing.License"; } // Getters and Setters @@ -108,7 +109,7 @@ public String getType() { * @return the isFsfLibre */ public Optional getIsFsfLibre() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_FSF_LIBRE); + return getBooleanPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_FSF_LIBRE); } /** @@ -117,24 +118,7 @@ public Optional getIsFsfLibre() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public License setIsFsfLibre(@Nullable Boolean isFsfLibre) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_IS_FSF_LIBRE, isFsfLibre); - return this; - } - - /** - * @return the isOsiApproved - */ - public Optional getIsOsiApproved() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED); - } - - /** - * @param isOsiApproved the isOsiApproved to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public License setIsOsiApproved(@Nullable Boolean isOsiApproved) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_IS_OSI_APPROVED, isOsiApproved); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_FSF_LIBRE, isFsfLibre); return this; } @@ -142,7 +126,7 @@ public License setIsOsiApproved(@Nullable Boolean isOsiApproved) throws InvalidS * @return the isDeprecatedLicenseId */ public Optional getIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID); + return getBooleanPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_DEPRECATED_LICENSE_ID); } /** @@ -151,23 +135,24 @@ public Optional getIsDeprecatedLicenseId() throws InvalidSPDXAnalysisEx * @throws InvalidSPDXAnalysisException */ public License setIsDeprecatedLicenseId(@Nullable Boolean isDeprecatedLicenseId) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_LICENSE_ID, isDeprecatedLicenseId); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_DEPRECATED_LICENSE_ID, isDeprecatedLicenseId); return this; } /** - * @return the standardLicenseTemplate + * @return the isOsiApproved */ - public Optional getStandardLicenseTemplate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_TEMPLATE); + public Optional getIsOsiApproved() throws InvalidSPDXAnalysisException { + return getBooleanPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_OSI_APPROVED); } + /** - * @param standardLicenseTemplate the standardLicenseTemplate to set + * @param isOsiApproved the isOsiApproved to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public License setStandardLicenseTemplate(@Nullable String standardLicenseTemplate) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_TEMPLATE, standardLicenseTemplate); + public License setIsOsiApproved(@Nullable Boolean isOsiApproved) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_OSI_APPROVED, isOsiApproved); return this; } @@ -175,7 +160,7 @@ public License setStandardLicenseTemplate(@Nullable String standardLicenseTempla * @return the obsoletedBy */ public Optional getObsoletedBy() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY); + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_OBSOLETED_BY); } /** * @param obsoletedBy the obsoletedBy to set @@ -183,7 +168,7 @@ public Optional getObsoletedBy() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public License setObsoletedBy(@Nullable String obsoletedBy) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY, obsoletedBy); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_OBSOLETED_BY, obsoletedBy); return this; } @@ -191,7 +176,7 @@ public License setObsoletedBy(@Nullable String obsoletedBy) throws InvalidSPDXAn * @return the standardLicenseHeader */ public Optional getStandardLicenseHeader() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_HEADER); + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_STANDARD_LICENSE_HEADER); } /** * @param standardLicenseHeader the standardLicenseHeader to set @@ -199,7 +184,7 @@ public Optional getStandardLicenseHeader() throws InvalidSPDXAnalysisExc * @throws InvalidSPDXAnalysisException */ public License setStandardLicenseHeader(@Nullable String standardLicenseHeader) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_LICENSE_HEADER, standardLicenseHeader); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_STANDARD_LICENSE_HEADER, standardLicenseHeader); return this; } @@ -207,7 +192,7 @@ public License setStandardLicenseHeader(@Nullable String standardLicenseHeader) * @return the licenseText */ public @Nullable String getLicenseText() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_TEXT); + Optional retval = getStringPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_TEXT); return retval.isPresent() ? retval.get() : null; } /** @@ -219,7 +204,39 @@ public License setLicenseText(@Nullable String licenseText) throws InvalidSPDXAn if (isStrict() && Objects.isNull(licenseText)) { throw new InvalidSPDXAnalysisException("licenseText is a required property"); } - setPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_TEXT, licenseText); + setPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_TEXT, licenseText); + return this; + } + + /** + * @return the licenseXml + */ + public Optional getLicenseXml() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LICENSE_XML); + } + /** + * @param licenseXml the licenseXml to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setLicenseXml(@Nullable String licenseXml) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LICENSE_XML, licenseXml); + return this; + } + + /** + * @return the standardLicenseTemplate + */ + public Optional getStandardLicenseTemplate() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_STANDARD_LICENSE_TEMPLATE); + } + /** + * @param standardLicenseTemplate the standardLicenseTemplate to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public License setStandardLicenseTemplate(@Nullable String standardLicenseTemplate) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_STANDARD_LICENSE_TEMPLATE, standardLicenseTemplate); return this; } @@ -233,21 +250,15 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional isFsfLibre = getIsFsfLibre(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isFsfLibre for License: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional isOsiApproved = getIsOsiApproved(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting isOsiApproved for License: "+e.getMessage()); - } try { @SuppressWarnings("unused") Optional isDeprecatedLicenseId = getIsDeprecatedLicenseId(); @@ -256,9 +267,9 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional standardLicenseTemplate = getStandardLicenseTemplate(); + Optional isOsiApproved = getIsOsiApproved(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting standardLicenseTemplate for License: "+e.getMessage()); + retval.add("Error getting isOsiApproved for License: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -275,12 +286,24 @@ protected List _verify(Set verifiedIds, String specVersion, List try { String licenseText = getLicenseText(); if (Objects.isNull(licenseText) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.EXPANDED_LICENSING }))) { retval.add("Missing licenseText in License"); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting licenseText for License: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional licenseXml = getLicenseXml(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting licenseXml for License: "+e.getMessage()); + } + try { + @SuppressWarnings("unused") + Optional standardLicenseTemplate = getStandardLicenseTemplate(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting standardLicenseTemplate for License: "+e.getMessage()); + } return retval; } @@ -317,12 +340,13 @@ public LicenseBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC } Boolean isFsfLibre = null; - Boolean isOsiApproved = null; Boolean isDeprecatedLicenseId = null; - String standardLicenseTemplate = null; + Boolean isOsiApproved = null; String obsoletedBy = null; String standardLicenseHeader = null; String licenseText = null; + String licenseXml = null; + String standardLicenseTemplate = null; /** @@ -335,16 +359,6 @@ public LicenseBuilder setIsFsfLibre(Boolean isFsfLibre) { return this; } - /** - * Sets the initial value of isOsiApproved - * @parameter isOsiApproved value to set - * @return this for chaining - **/ - public LicenseBuilder setIsOsiApproved(Boolean isOsiApproved) { - this.isOsiApproved = isOsiApproved; - return this; - } - /** * Sets the initial value of isDeprecatedLicenseId * @parameter isDeprecatedLicenseId value to set @@ -356,12 +370,12 @@ public LicenseBuilder setIsDeprecatedLicenseId(Boolean isDeprecatedLicenseId) { } /** - * Sets the initial value of standardLicenseTemplate - * @parameter standardLicenseTemplate value to set + * Sets the initial value of isOsiApproved + * @parameter isOsiApproved value to set * @return this for chaining **/ - public LicenseBuilder setStandardLicenseTemplate(String standardLicenseTemplate) { - this.standardLicenseTemplate = standardLicenseTemplate; + public LicenseBuilder setIsOsiApproved(Boolean isOsiApproved) { + this.isOsiApproved = isOsiApproved; return this; } @@ -394,6 +408,26 @@ public LicenseBuilder setLicenseText(String licenseText) { this.licenseText = licenseText; return this; } + + /** + * Sets the initial value of licenseXml + * @parameter licenseXml value to set + * @return this for chaining + **/ + public LicenseBuilder setLicenseXml(String licenseXml) { + this.licenseXml = licenseXml; + return this; + } + + /** + * Sets the initial value of standardLicenseTemplate + * @parameter standardLicenseTemplate value to set + * @return this for chaining + **/ + public LicenseBuilder setStandardLicenseTemplate(String standardLicenseTemplate) { + this.standardLicenseTemplate = standardLicenseTemplate; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseAddition.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/LicenseAddition.java similarity index 81% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseAddition.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/LicenseAddition.java index 04fedc878..0a4d04515 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseAddition.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/LicenseAddition.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -37,8 +37,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -89,8 +89,9 @@ public LicenseAddition(IModelStore modelStore, String objectUri, @Nullable Model protected LicenseAddition(LicenseAdditionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setIsDeprecatedAdditionId(builder.isDeprecatedAdditionId); - setObsoletedBy(builder.obsoletedBy); setStandardAdditionTemplate(builder.standardAdditionTemplate); + setObsoletedBy(builder.obsoletedBy); + setLicenseXml(builder.licenseXml); setAdditionText(builder.additionText); } @@ -99,7 +100,7 @@ protected LicenseAddition(LicenseAdditionBuilder builder) throws InvalidSPDXAnal */ @Override public String getType() { - return "Licensing.LicenseAddition"; + return "ExpandedLicensing.LicenseAddition"; } // Getters and Setters @@ -109,7 +110,7 @@ public String getType() { * @return the isDeprecatedAdditionId */ public Optional getIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_ADDITION_ID); + return getBooleanPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_DEPRECATED_ADDITION_ID); } /** @@ -118,7 +119,23 @@ public Optional getIsDeprecatedAdditionId() throws InvalidSPDXAnalysisE * @throws InvalidSPDXAnalysisException */ public LicenseAddition setIsDeprecatedAdditionId(@Nullable Boolean isDeprecatedAdditionId) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_IS_DEPRECATED_ADDITION_ID, isDeprecatedAdditionId); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_IS_DEPRECATED_ADDITION_ID, isDeprecatedAdditionId); + return this; + } + + /** + * @return the standardAdditionTemplate + */ + public Optional getStandardAdditionTemplate() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_STANDARD_ADDITION_TEMPLATE); + } + /** + * @param standardAdditionTemplate the standardAdditionTemplate to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseAddition setStandardAdditionTemplate(@Nullable String standardAdditionTemplate) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_STANDARD_ADDITION_TEMPLATE, standardAdditionTemplate); return this; } @@ -126,7 +143,7 @@ public LicenseAddition setIsDeprecatedAdditionId(@Nullable Boolean isDeprecatedA * @return the obsoletedBy */ public Optional getObsoletedBy() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY); + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_OBSOLETED_BY); } /** * @param obsoletedBy the obsoletedBy to set @@ -134,23 +151,23 @@ public Optional getObsoletedBy() throws InvalidSPDXAnalysisException { * @throws InvalidSPDXAnalysisException */ public LicenseAddition setObsoletedBy(@Nullable String obsoletedBy) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_OBSOLETED_BY, obsoletedBy); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_OBSOLETED_BY, obsoletedBy); return this; } /** - * @return the standardAdditionTemplate + * @return the licenseXml */ - public Optional getStandardAdditionTemplate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_ADDITION_TEMPLATE); + public Optional getLicenseXml() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LICENSE_XML); } /** - * @param standardAdditionTemplate the standardAdditionTemplate to set + * @param licenseXml the licenseXml to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public LicenseAddition setStandardAdditionTemplate(@Nullable String standardAdditionTemplate) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_STANDARD_ADDITION_TEMPLATE, standardAdditionTemplate); + public LicenseAddition setLicenseXml(@Nullable String licenseXml) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LICENSE_XML, licenseXml); return this; } @@ -158,7 +175,7 @@ public LicenseAddition setStandardAdditionTemplate(@Nullable String standardAddi * @return the additionText */ public @Nullable String getAdditionText() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.LICENSING_PROP_ADDITION_TEXT); + Optional retval = getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_ADDITION_TEXT); return retval.isPresent() ? retval.get() : null; } /** @@ -170,7 +187,7 @@ public LicenseAddition setAdditionText(@Nullable String additionText) throws Inv if (isStrict() && Objects.isNull(additionText)) { throw new InvalidSPDXAnalysisException("additionText is a required property"); } - setPropertyValue(SpdxConstants.LICENSING_PROP_ADDITION_TEXT, additionText); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_ADDITION_TEXT, additionText); return this; } @@ -184,15 +201,21 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional isDeprecatedAdditionId = getIsDeprecatedAdditionId(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting isDeprecatedAdditionId for LicenseAddition: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional standardAdditionTemplate = getStandardAdditionTemplate(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting standardAdditionTemplate for LicenseAddition: "+e.getMessage()); + } try { @SuppressWarnings("unused") Optional obsoletedBy = getObsoletedBy(); @@ -201,14 +224,14 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional standardAdditionTemplate = getStandardAdditionTemplate(); + Optional licenseXml = getLicenseXml(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting standardAdditionTemplate for LicenseAddition: "+e.getMessage()); + retval.add("Error getting licenseXml for LicenseAddition: "+e.getMessage()); } try { String additionText = getAdditionText(); if (Objects.isNull(additionText) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.EXPANDED_LICENSING }))) { retval.add("Missing additionText in LicenseAddition"); } } catch (InvalidSPDXAnalysisException e) { @@ -250,8 +273,9 @@ public LicenseAdditionBuilder(IModelStore modelStore, String objectUri, @Nullabl } Boolean isDeprecatedAdditionId = null; - String obsoletedBy = null; String standardAdditionTemplate = null; + String obsoletedBy = null; + String licenseXml = null; String additionText = null; @@ -265,6 +289,16 @@ public LicenseAdditionBuilder setIsDeprecatedAdditionId(Boolean isDeprecatedAddi return this; } + /** + * Sets the initial value of standardAdditionTemplate + * @parameter standardAdditionTemplate value to set + * @return this for chaining + **/ + public LicenseAdditionBuilder setStandardAdditionTemplate(String standardAdditionTemplate) { + this.standardAdditionTemplate = standardAdditionTemplate; + return this; + } + /** * Sets the initial value of obsoletedBy * @parameter obsoletedBy value to set @@ -276,12 +310,12 @@ public LicenseAdditionBuilder setObsoletedBy(String obsoletedBy) { } /** - * Sets the initial value of standardAdditionTemplate - * @parameter standardAdditionTemplate value to set + * Sets the initial value of licenseXml + * @parameter licenseXml value to set * @return this for chaining **/ - public LicenseAdditionBuilder setStandardAdditionTemplate(String standardAdditionTemplate) { - this.standardAdditionTemplate = standardAdditionTemplate; + public LicenseAdditionBuilder setLicenseXml(String licenseXml) { + this.licenseXml = licenseXml; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicense.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ListedLicense.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicense.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ListedLicense.java index ce88112ee..d38fd8667 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicense.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ListedLicense.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -34,7 +34,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -80,8 +80,8 @@ public ListedLicense(IModelStore modelStore, String objectUri, @Nullable ModelCo */ protected ListedLicense(ListedLicenseBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setDeprecatedVersion(builder.deprecatedVersion); setListVersionAdded(builder.listVersionAdded); + setDeprecatedVersion(builder.deprecatedVersion); } /* (non-Javadoc) @@ -89,41 +89,41 @@ protected ListedLicense(ListedLicenseBuilder builder) throws InvalidSPDXAnalysis */ @Override public String getType() { - return "Licensing.ListedLicense"; + return "ExpandedLicensing.ListedLicense"; } // Getters and Setters /** - * @return the deprecatedVersion + * @return the listVersionAdded */ - public Optional getDeprecatedVersion() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION); + public Optional getListVersionAdded() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LIST_VERSION_ADDED); } /** - * @param deprecatedVersion the deprecatedVersion to set + * @param listVersionAdded the listVersionAdded to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ListedLicense setDeprecatedVersion(@Nullable String deprecatedVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION, deprecatedVersion); + public ListedLicense setListVersionAdded(@Nullable String listVersionAdded) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LIST_VERSION_ADDED, listVersionAdded); return this; } /** - * @return the listVersionAdded + * @return the deprecatedVersion */ - public Optional getListVersionAdded() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED); + public Optional getDeprecatedVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_DEPRECATED_VERSION); } /** - * @param listVersionAdded the listVersionAdded to set + * @param deprecatedVersion the deprecatedVersion to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public ListedLicense setListVersionAdded(@Nullable String listVersionAdded) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED, listVersionAdded); + public ListedLicense setDeprecatedVersion(@Nullable String deprecatedVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_DEPRECATED_VERSION, deprecatedVersion); return this; } @@ -137,20 +137,20 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") - Optional deprecatedVersion = getDeprecatedVersion(); + Optional listVersionAdded = getListVersionAdded(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting deprecatedVersion for ListedLicense: "+e.getMessage()); + retval.add("Error getting listVersionAdded for ListedLicense: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional listVersionAdded = getListVersionAdded(); + Optional deprecatedVersion = getDeprecatedVersion(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting listVersionAdded for ListedLicense: "+e.getMessage()); + retval.add("Error getting deprecatedVersion for ListedLicense: "+e.getMessage()); } return retval; } @@ -187,27 +187,27 @@ public ListedLicenseBuilder(IModelStore modelStore, String objectUri, @Nullable super(modelStore, objectUri, copyManager); } - String deprecatedVersion = null; String listVersionAdded = null; + String deprecatedVersion = null; /** - * Sets the initial value of deprecatedVersion - * @parameter deprecatedVersion value to set + * Sets the initial value of listVersionAdded + * @parameter listVersionAdded value to set * @return this for chaining **/ - public ListedLicenseBuilder setDeprecatedVersion(String deprecatedVersion) { - this.deprecatedVersion = deprecatedVersion; + public ListedLicenseBuilder setListVersionAdded(String listVersionAdded) { + this.listVersionAdded = listVersionAdded; return this; } /** - * Sets the initial value of listVersionAdded - * @parameter listVersionAdded value to set + * Sets the initial value of deprecatedVersion + * @parameter deprecatedVersion value to set * @return this for chaining **/ - public ListedLicenseBuilder setListVersionAdded(String listVersionAdded) { - this.listVersionAdded = listVersionAdded; + public ListedLicenseBuilder setDeprecatedVersion(String deprecatedVersion) { + this.deprecatedVersion = deprecatedVersion; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicenseException.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseException.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicenseException.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseException.java index 4710fd1c0..0f1e3cd1c 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/ListedLicenseException.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseException.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -34,7 +34,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -91,7 +91,7 @@ protected ListedLicenseException(ListedLicenseExceptionBuilder builder) throws I */ @Override public String getType() { - return "Licensing.ListedLicenseException"; + return "ExpandedLicensing.ListedLicenseException"; } // Getters and Setters @@ -101,7 +101,7 @@ public String getType() { * @return the deprecatedVersion */ public Optional getDeprecatedVersion() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION); + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_DEPRECATED_VERSION); } /** * @param deprecatedVersion the deprecatedVersion to set @@ -109,7 +109,7 @@ public Optional getDeprecatedVersion() throws InvalidSPDXAnalysisExcepti * @throws InvalidSPDXAnalysisException */ public ListedLicenseException setDeprecatedVersion(@Nullable String deprecatedVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_DEPRECATED_VERSION, deprecatedVersion); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_DEPRECATED_VERSION, deprecatedVersion); return this; } @@ -117,7 +117,7 @@ public ListedLicenseException setDeprecatedVersion(@Nullable String deprecatedVe * @return the listVersionAdded */ public Optional getListVersionAdded() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED); + return getStringPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LIST_VERSION_ADDED); } /** * @param listVersionAdded the listVersionAdded to set @@ -125,7 +125,7 @@ public Optional getListVersionAdded() throws InvalidSPDXAnalysisExceptio * @throws InvalidSPDXAnalysisException */ public ListedLicenseException setListVersionAdded(@Nullable String listVersionAdded) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.LICENSING_PROP_LIST_VERSION_ADDED, listVersionAdded); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_LIST_VERSION_ADDED, listVersionAdded); return this; } @@ -139,9 +139,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional deprecatedVersion = getDeprecatedVersion(); diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/OrLaterOperator.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/OrLaterOperator.java similarity index 92% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/OrLaterOperator.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/OrLaterOperator.java index a49548057..cd7a0f053 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/OrLaterOperator.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/OrLaterOperator.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -98,7 +98,7 @@ protected OrLaterOperator(OrLaterOperatorBuilder builder) throws InvalidSPDXAnal */ @Override public String getType() { - return "Licensing.OrLaterOperator"; + return "ExpandedLicensing.OrLaterOperator"; } // Getters and Setters @@ -109,7 +109,7 @@ public String getType() { */ @SuppressWarnings("unchecked") public @Nullable License getSubjectLicense() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE); + Optional retval = getObjectPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_SUBJECT_LICENSE); if (retval.isPresent()) { if (!(retval.get() instanceof License)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -129,7 +129,7 @@ public OrLaterOperator setSubjectLicense(@Nullable License subjectLicense) throw if (isStrict() && Objects.isNull(subjectLicense)) { throw new InvalidSPDXAnalysisException("subjectLicense is a required property"); } - setPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE, subjectLicense); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_SUBJECT_LICENSE, subjectLicense); return this; } @@ -143,15 +143,15 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); License subjectLicense; try { subjectLicense = getSubjectLicense(); if (Objects.nonNull(subjectLicense)) { - retval.addAll(subjectLicense.verify(verifiedIds, specVersion, profiles)); - } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + retval.addAll(subjectLicense.verify(verifiedIds, specVersionForVerify, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.EXPANDED_LICENSING }))) { retval.add("Missing subjectLicense in OrLaterOperator"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/WithAdditionOperator.java b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/WithAdditionOperator.java similarity index 90% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/WithAdditionOperator.java rename to generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/WithAdditionOperator.java index 447245c8c..55153f375 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/WithAdditionOperator.java +++ b/generated/src/main/java/org/spdx/library/model/v3/expandedlicensing/WithAdditionOperator.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -37,7 +37,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -95,7 +96,7 @@ protected WithAdditionOperator(WithAdditionOperatorBuilder builder) throws Inval */ @Override public String getType() { - return "Licensing.WithAdditionOperator"; + return "ExpandedLicensing.WithAdditionOperator"; } // Getters and Setters @@ -106,7 +107,7 @@ public String getType() { */ @SuppressWarnings("unchecked") public @Nullable LicenseAddition getSubjectAddition() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_ADDITION); + Optional retval = getObjectPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_SUBJECT_ADDITION); if (retval.isPresent()) { if (!(retval.get() instanceof LicenseAddition)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -126,7 +127,7 @@ public WithAdditionOperator setSubjectAddition(@Nullable LicenseAddition subject if (isStrict() && Objects.isNull(subjectAddition)) { throw new InvalidSPDXAnalysisException("subjectAddition is a required property"); } - setPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_ADDITION, subjectAddition); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_SUBJECT_ADDITION, subjectAddition); return this; } @@ -135,7 +136,7 @@ public WithAdditionOperator setSubjectAddition(@Nullable LicenseAddition subject */ @SuppressWarnings("unchecked") public @Nullable ExtendableLicense getSubjectLicense() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE); + Optional retval = getObjectPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_SUBJECT_LICENSE); if (retval.isPresent()) { if (!(retval.get() instanceof ExtendableLicense)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); @@ -155,7 +156,7 @@ public WithAdditionOperator setSubjectLicense(@Nullable ExtendableLicense subjec if (isStrict() && Objects.isNull(subjectLicense)) { throw new InvalidSPDXAnalysisException("subjectLicense is a required property"); } - setPropertyValue(SpdxConstants.LICENSING_PROP_SUBJECT_LICENSE, subjectLicense); + setPropertyValue(SpdxConstants.EXPANDED_LICENSING_PROP_SUBJECT_LICENSE, subjectLicense); return this; } @@ -169,15 +170,15 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); LicenseAddition subjectAddition; try { subjectAddition = getSubjectAddition(); if (Objects.nonNull(subjectAddition)) { - retval.addAll(subjectAddition.verify(verifiedIds, specVersion, profiles)); - } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + retval.addAll(subjectAddition.verify(verifiedIds, specVersionForVerify, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.EXPANDED_LICENSING }))) { retval.add("Missing subjectAddition in WithAdditionOperator"); } } catch (InvalidSPDXAnalysisException e) { @@ -187,8 +188,8 @@ protected List _verify(Set verifiedIds, String specVersion, List try { subjectLicense = getSubjectLicense(); if (Objects.nonNull(subjectLicense)) { - retval.addAll(subjectLicense.verify(verifiedIds, specVersion, profiles)); - } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + retval.addAll(subjectLicense.verify(verifiedIds, specVersionForVerify, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.EXPANDED_LICENSING }))) { retval.add("Missing subjectLicense in WithAdditionOperator"); } } catch (InvalidSPDXAnalysisException e) { diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java index e46388270..fcc5a3c40 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -52,16 +52,16 @@ * "@id": "urn:spdx.dev:cvssv2-cve-2020-28498", "relationshipType": "hasAssessmentFor", * "score": 4.3, "vector": "(AV:N/AC:M/Au:N/C:P/I:N/A:N)", "severity": "low", * "from": "urn:spdx.dev:vuln-cve-2020-28498", "to": ["urn:product-acme-application-1.3"], - * "assessedElement": "urn:npm-elliptic-6.5.2", "externalReferences": [ { "@type": - * "ExternalReference", "externalReferenceType": "securityAdvisory", "locator": - * "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" }, { "@type": "ExternalReference", - * "externalReferenceType": "securityAdvisory", "locator": "https://snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" - * }, { "@type": "ExternalReference", "externalReferenceType": "securityFix", - * "locator": "https://github.com/indutny/elliptic/commit/441b742" } ], "suppliedBy": - * ["urn:spdx.dev:agent-my-security-vendor"], "publishedTime": "2023-05-06T10:06:13Z" - * }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", "relationshipType": - * "publishedBy", "from": "urn:spdx.dev:cvssv2-cve-2020-28498", "to": ["urn:spdx.dev:agent-snyk"], - * "startTime": "2021-03-08T16:06:50Z" } ``` + * "assessedElement": "urn:npm-elliptic-6.5.2", "externalRefs": [ { "@type": + * "ExternalRef", "externalRefType": "securityAdvisory", "locator": "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" + * }, { "@type": "ExternalRef", "externalRefType": "securityAdvisory", "locator": + * "https://snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" }, { "@type": "ExternalRef", + * "externalRefType": "securityFix", "locator": "https://github.com/indutny/elliptic/commit/441b742" + * } ], "suppliedBy": ["urn:spdx.dev:agent-my-security-vendor"], "publishedTime": + * "2023-05-06T10:06:13Z" }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", + * "relationshipType": "publishedBy", "from": "urn:spdx.dev:cvssv2-cve-2020-28498", + * "to": ["urn:spdx.dev:agent-snyk"], "startTime": "2021-03-08T16:06:50Z" } + * ``` */ public class CvssV2VulnAssessmentRelationship extends VulnAssessmentRelationship { @@ -102,8 +102,8 @@ public CvssV2VulnAssessmentRelationship(IModelStore modelStore, String objectUri protected CvssV2VulnAssessmentRelationship(CvssV2VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setScore(builder.score); - setSeverity(builder.severity); setVector(builder.vector); + setSeverity(builder.severity); } /* (non-Javadoc) @@ -139,34 +139,34 @@ public CvssV2VulnAssessmentRelationship setScore(@Nullable Integer score) throws } /** - * @return the severity + * @return the vector */ - public Optional getSeverity() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY); + public Optional getVector() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR); } /** - * @param severity the severity to set + * @param vector the vector to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public CvssV2VulnAssessmentRelationship setSeverity(@Nullable String severity) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY, severity); + public CvssV2VulnAssessmentRelationship setVector(@Nullable String vector) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR, vector); return this; } /** - * @return the vector + * @return the severity */ - public Optional getVector() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR); + public Optional getSeverity() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY); } /** - * @param vector the vector to set + * @param severity the severity to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public CvssV2VulnAssessmentRelationship setVector(@Nullable String vector) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_VECTOR, vector); + public CvssV2VulnAssessmentRelationship setSeverity(@Nullable String severity) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_SEVERITY, severity); return this; } @@ -180,9 +180,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { Integer score = getScore(); if (Objects.isNull(score) && @@ -194,15 +194,15 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional severity = getSeverity(); + Optional vector = getVector(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting severity for CvssV2VulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting vector for CvssV2VulnAssessmentRelationship: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional vector = getVector(); + Optional severity = getSeverity(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting vector for CvssV2VulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting severity for CvssV2VulnAssessmentRelationship: "+e.getMessage()); } return retval; } @@ -240,8 +240,8 @@ public CvssV2VulnAssessmentRelationshipBuilder(IModelStore modelStore, String ob } Integer score = null; - String severity = null; String vector = null; + String severity = null; /** @@ -255,22 +255,22 @@ public CvssV2VulnAssessmentRelationshipBuilder setScore(Integer score) { } /** - * Sets the initial value of severity - * @parameter severity value to set + * Sets the initial value of vector + * @parameter vector value to set * @return this for chaining **/ - public CvssV2VulnAssessmentRelationshipBuilder setSeverity(String severity) { - this.severity = severity; + public CvssV2VulnAssessmentRelationshipBuilder setVector(String vector) { + this.vector = vector; return this; } /** - * Sets the initial value of vector - * @parameter vector value to set + * Sets the initial value of severity + * @parameter severity value to set * @return this for chaining **/ - public CvssV2VulnAssessmentRelationshipBuilder setVector(String vector) { - this.vector = vector; + public CvssV2VulnAssessmentRelationshipBuilder setSeverity(String severity) { + this.severity = severity; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java index b4e812009..b45551022 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -53,16 +53,15 @@ * "@id": "urn:spdx.dev:cvssv3-cve-2020-28498", "relationshipType": "hasAssessmentFor", * "severity": "medium", "score": 6.8, "vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:N/A:N", * "from": "urn:spdx.dev:vuln-cve-2020-28498", "to": ["urn:product-acme-application-1.3"], - * "assessedElement": "urn:npm-elliptic-6.5.2", "externalReferences": [ { "@type": - * "ExternalReference", "externalReferenceType": "securityAdvisory", "locator": - * "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" }, { "@type": "ExternalReference", - * "externalReferenceType": "securityAdvisory", "locator": "https://snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" - * }, { "@type": "ExternalReference", "externalReferenceType": "securityFix", - * "locator": "https://github.com/indutny/elliptic/commit/441b742" } ], "suppliedBy": - * ["urn:spdx.dev:agent-my-security-vendor"], "publishedTime": "2023-05-06T10:06:13Z" - * }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", "relationshipType": - * "publishedBy", "from": "urn:spdx.dev:cvssv3-cve-2020-28498", "to": "urn:spdx.dev:agent-snyk", - * "startTime": "2021-03-08T16:06:50Z" } ``` + * "assessedElement": "urn:npm-elliptic-6.5.2", "externalRefs": [ { "@type": + * "ExternalRef", "externalRefType": "securityAdvisory", "locator": "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" + * }, { "@type": "ExternalRef", "externalRefType": "securityAdvisory", "locator": + * "https://snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" }, { "@type": "ExternalRef", + * "externalRefType": "securityFix", "locator": "https://github.com/indutny/elliptic/commit/441b742" + * } ], "suppliedBy": ["urn:spdx.dev:agent-my-security-vendor"], "publishedTime": + * "2023-05-06T10:06:13Z" }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnAgentRel-1", + * "relationshipType": "publishedBy", "from": "urn:spdx.dev:cvssv3-cve-2020-28498", + * "to": "urn:spdx.dev:agent-snyk", "startTime": "2021-03-08T16:06:50Z" } ``` */ public class CvssV3VulnAssessmentRelationship extends VulnAssessmentRelationship { @@ -181,9 +180,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { Integer score = getScore(); if (Objects.isNull(score) && diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java index af744632d..65980258e 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -155,9 +155,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { Integer probability = getProbability(); if (Objects.isNull(probability) && diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java index 13037522a..e40d14875 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java index 763772102..17ab2fbff 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -186,9 +186,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { ExploitCatalogType catalogType = getCatalogType(); if (Objects.isNull(catalogType) && diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java index f7475adb6..1d7255068 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcDecisionType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java index bb903fd55..3d61b1dd5 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -37,7 +37,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -142,9 +142,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { SsvcDecisionType decisionType = getDecisionType(); if (Objects.isNull(decisionType) && diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java index d5573201c..f58e9da40 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -36,8 +36,7 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.core.DateTime; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -58,7 +57,7 @@ */ public class VexAffectedVulnAssessmentRelationship extends VexVulnAssessmentRelationship { - Collection actionStatementTimes; + Collection actionStatementTimes; /** * Create the VexAffectedVulnAssessmentRelationship with default model store and generated anonymous ID @@ -87,7 +86,7 @@ public VexAffectedVulnAssessmentRelationship(String objectUri) throws InvalidSPD public VexAffectedVulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); - actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, DateTime.class); + actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); } /** @@ -98,7 +97,7 @@ public VexAffectedVulnAssessmentRelationship(IModelStore modelStore, String obje @SuppressWarnings("unchecked") protected VexAffectedVulnAssessmentRelationship(VexAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, DateTime.class); + actionStatementTimes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SECURITY_PROP_ACTION_STATEMENT_TIME, String.class); getActionStatementTimes().addAll(builder.actionStatementTimes); setActionStatement(builder.actionStatement); } @@ -112,7 +111,7 @@ public String getType() { } // Getters and Setters - public Collection getActionStatementTimes() { + public Collection getActionStatementTimes() { return actionStatementTimes; } @@ -143,18 +142,15 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional actionStatement = getActionStatement(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting actionStatement for VexAffectedVulnAssessmentRelationship: "+e.getMessage()); } - for (DateTime actionStatementTime:actionStatementTimes) { - retval.addAll(actionStatementTime.verify(verifiedIds, specVersion, profiles)); - } return retval; } @@ -190,7 +186,7 @@ public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, Stri super(modelStore, objectUri, copyManager); } - Collection actionStatementTimes = new ArrayList<>(); + Collection actionStatementTimes = new ArrayList<>(); String actionStatement = null; @@ -199,7 +195,7 @@ public VexAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, Stri * @parameter actionStatementTime actionStatementTime to add * @return this for chaining **/ - public VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(DateTime actionStatementTime) { + public VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(String actionStatementTime) { if (Objects.nonNull(actionStatementTime)) { actionStatementTimes.add(actionStatementTime); } @@ -211,7 +207,7 @@ public VexAffectedVulnAssessmentRelationshipBuilder addActionStatementTime(DateT * @parameter actionStatementTimeCollection collection to initialize the actionStatementTime * @return this for chaining **/ - public VexAffectedVulnAssessmentRelationshipBuilder addAllActionStatementTime(Collection actionStatementTimeCollection) { + public VexAffectedVulnAssessmentRelationshipBuilder addAllActionStatementTime(Collection actionStatementTimeCollection) { if (Objects.nonNull(actionStatementTimeCollection)) { actionStatementTimes.addAll(actionStatementTimeCollection); } diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java index 3f3c8fbdb..74880ceba 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -32,7 +32,7 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -112,9 +112,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java index 3896477a5..f342e444a 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexJustificationType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java index 2c5b366a4..478e5b30c 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,8 +34,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.core.DateTime; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -96,8 +95,8 @@ public VexNotAffectedVulnAssessmentRelationship(IModelStore modelStore, String o */ protected VexNotAffectedVulnAssessmentRelationship(VexNotAffectedVulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setImpactStatementTime(builder.impactStatementTime); setJustificationType(builder.justificationType); + setImpactStatementTime(builder.impactStatementTime); setImpactStatement(builder.impactStatement); } @@ -111,32 +110,6 @@ public String getType() { // Getters and Setters - - /** - * @return the impactStatementTime - */ - @SuppressWarnings("unchecked") - public Optional getImpactStatementTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } - } - - /** - * @param impactStatementTime the impactStatementTime to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public VexNotAffectedVulnAssessmentRelationship setImpactStatementTime(@Nullable DateTime impactStatementTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME, impactStatementTime); - return this; - } /** * @return the justificationType @@ -163,6 +136,22 @@ public VexNotAffectedVulnAssessmentRelationship setJustificationType(@Nullable V return this; } + /** + * @return the impactStatementTime + */ + public Optional getImpactStatementTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME); + } + /** + * @param impactStatementTime the impactStatementTime to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public VexNotAffectedVulnAssessmentRelationship setImpactStatementTime(@Nullable String impactStatementTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_IMPACT_STATEMENT_TIME, impactStatementTime); + return this; + } + /** * @return the impactStatement */ @@ -189,23 +178,20 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional impactStatementTime; + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { - impactStatementTime = getImpactStatementTime(); - if (impactStatementTime.isPresent()) { - retval.addAll(impactStatementTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional justificationType = getJustificationType(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting impactStatementTime for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting justificationType for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional justificationType = getJustificationType(); + Optional impactStatementTime = getImpactStatementTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting justificationType for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting impactStatementTime for VexNotAffectedVulnAssessmentRelationship: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -248,28 +234,28 @@ public VexNotAffectedVulnAssessmentRelationshipBuilder(IModelStore modelStore, S super(modelStore, objectUri, copyManager); } - DateTime impactStatementTime = null; VexJustificationType justificationType = null; + String impactStatementTime = null; String impactStatement = null; /** - * Sets the initial value of impactStatementTime - * @parameter impactStatementTime value to set + * Sets the initial value of justificationType + * @parameter justificationType value to set * @return this for chaining **/ - public VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatementTime(DateTime impactStatementTime) { - this.impactStatementTime = impactStatementTime; + public VexNotAffectedVulnAssessmentRelationshipBuilder setJustificationType(VexJustificationType justificationType) { + this.justificationType = justificationType; return this; } /** - * Sets the initial value of justificationType - * @parameter justificationType value to set + * Sets the initial value of impactStatementTime + * @parameter impactStatementTime value to set * @return this for chaining **/ - public VexNotAffectedVulnAssessmentRelationshipBuilder setJustificationType(VexJustificationType justificationType) { - this.justificationType = justificationType; + public VexNotAffectedVulnAssessmentRelationshipBuilder setImpactStatementTime(String impactStatementTime) { + this.impactStatementTime = impactStatementTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java index 9db728f90..29abf750d 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -32,7 +32,7 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -112,9 +112,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java index dbb002f61..e2e8241db 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,7 +34,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -149,9 +149,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional statusNotes = getStatusNotes(); diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java index 803a83416..a84929811 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/VulnAssessmentRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,10 +34,9 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.Agent; -import org.spdx.library.model.v3.core.DateTime; import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.Relationship; /** @@ -87,9 +86,9 @@ public VulnAssessmentRelationship(IModelStore modelStore, String objectUri, @Nul protected VulnAssessmentRelationship(VulnAssessmentRelationshipBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setSuppliedBy(builder.suppliedBy); - setPublishedTime(builder.publishedTime); - setWithdrawnTime(builder.withdrawnTime); setAssessedElement(builder.assessedElement); + setWithdrawnTime(builder.withdrawnTime); + setPublishedTime(builder.publishedTime); setModifiedTime(builder.modifiedTime); } @@ -131,105 +130,75 @@ public VulnAssessmentRelationship setSuppliedBy(@Nullable Agent suppliedBy) thro } /** - * @return the publishedTime + * @return the assessedElement */ @SuppressWarnings("unchecked") - public Optional getPublishedTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME); + public Optional getAssessedElement() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT); if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { + if (!(retval.get() instanceof Element)) { throw new InvalidSPDXAnalysisException("Incorrect type stored for "); } - return (Optional)(Optional)(retval); + return (Optional)(Optional)(retval); } else { return Optional.empty(); } } /** - * @param publishedTime the publishedTime to set + * @param assessedElement the assessedElement to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public VulnAssessmentRelationship setPublishedTime(@Nullable DateTime publishedTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME, publishedTime); + public VulnAssessmentRelationship setAssessedElement(@Nullable Element assessedElement) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT, assessedElement); return this; } /** * @return the withdrawnTime */ - @SuppressWarnings("unchecked") - public Optional getWithdrawnTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getWithdrawnTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME); } - /** * @param withdrawnTime the withdrawnTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public VulnAssessmentRelationship setWithdrawnTime(@Nullable DateTime withdrawnTime) throws InvalidSPDXAnalysisException { + public VulnAssessmentRelationship setWithdrawnTime(@Nullable String withdrawnTime) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME, withdrawnTime); return this; } /** - * @return the assessedElement + * @return the publishedTime */ - @SuppressWarnings("unchecked") - public Optional getAssessedElement() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT); - if (retval.isPresent()) { - if (!(retval.get() instanceof Element)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getPublishedTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME); } - /** - * @param assessedElement the assessedElement to set + * @param publishedTime the publishedTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public VulnAssessmentRelationship setAssessedElement(@Nullable Element assessedElement) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_ASSESSED_ELEMENT, assessedElement); + public VulnAssessmentRelationship setPublishedTime(@Nullable String publishedTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME, publishedTime); return this; } /** * @return the modifiedTime */ - @SuppressWarnings("unchecked") - public Optional getModifiedTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getModifiedTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME); } - /** * @param modifiedTime the modifiedTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public VulnAssessmentRelationship setModifiedTime(@Nullable DateTime modifiedTime) throws InvalidSPDXAnalysisException { + public VulnAssessmentRelationship setModifiedTime(@Nullable String modifiedTime) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME, modifiedTime); return this; } @@ -244,51 +213,42 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); Optional suppliedBy; try { suppliedBy = getSuppliedBy(); if (suppliedBy.isPresent()) { - retval.addAll(suppliedBy.get().verify(verifiedIds, specVersion, profiles)); + retval.addAll(suppliedBy.get().verify(verifiedIds, specVersionForVerify, profiles)); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting suppliedBy for VulnAssessmentRelationship: "+e.getMessage()); } - Optional publishedTime; + Optional assessedElement; try { - publishedTime = getPublishedTime(); - if (publishedTime.isPresent()) { - retval.addAll(publishedTime.get().verify(verifiedIds, specVersion, profiles)); + assessedElement = getAssessedElement(); + if (assessedElement.isPresent()) { + retval.addAll(assessedElement.get().verify(verifiedIds, specVersionForVerify, profiles)); } } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting publishedTime for VulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting assessedElement for VulnAssessmentRelationship: "+e.getMessage()); } - Optional withdrawnTime; try { - withdrawnTime = getWithdrawnTime(); - if (withdrawnTime.isPresent()) { - retval.addAll(withdrawnTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional withdrawnTime = getWithdrawnTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting withdrawnTime for VulnAssessmentRelationship: "+e.getMessage()); } - Optional assessedElement; try { - assessedElement = getAssessedElement(); - if (assessedElement.isPresent()) { - retval.addAll(assessedElement.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional publishedTime = getPublishedTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting assessedElement for VulnAssessmentRelationship: "+e.getMessage()); + retval.add("Error getting publishedTime for VulnAssessmentRelationship: "+e.getMessage()); } - Optional modifiedTime; try { - modifiedTime = getModifiedTime(); - if (modifiedTime.isPresent()) { - retval.addAll(modifiedTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional modifiedTime = getModifiedTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting modifiedTime for VulnAssessmentRelationship: "+e.getMessage()); } @@ -328,10 +288,10 @@ public VulnAssessmentRelationshipBuilder(IModelStore modelStore, String objectUr } Agent suppliedBy = null; - DateTime publishedTime = null; - DateTime withdrawnTime = null; Element assessedElement = null; - DateTime modifiedTime = null; + String withdrawnTime = null; + String publishedTime = null; + String modifiedTime = null; /** @@ -345,12 +305,12 @@ public VulnAssessmentRelationshipBuilder setSuppliedBy(Agent suppliedBy) { } /** - * Sets the initial value of publishedTime - * @parameter publishedTime value to set + * Sets the initial value of assessedElement + * @parameter assessedElement value to set * @return this for chaining **/ - public VulnAssessmentRelationshipBuilder setPublishedTime(DateTime publishedTime) { - this.publishedTime = publishedTime; + public VulnAssessmentRelationshipBuilder setAssessedElement(Element assessedElement) { + this.assessedElement = assessedElement; return this; } @@ -359,18 +319,18 @@ public VulnAssessmentRelationshipBuilder setPublishedTime(DateTime publishedTime * @parameter withdrawnTime value to set * @return this for chaining **/ - public VulnAssessmentRelationshipBuilder setWithdrawnTime(DateTime withdrawnTime) { + public VulnAssessmentRelationshipBuilder setWithdrawnTime(String withdrawnTime) { this.withdrawnTime = withdrawnTime; return this; } /** - * Sets the initial value of assessedElement - * @parameter assessedElement value to set + * Sets the initial value of publishedTime + * @parameter publishedTime value to set * @return this for chaining **/ - public VulnAssessmentRelationshipBuilder setAssessedElement(Element assessedElement) { - this.assessedElement = assessedElement; + public VulnAssessmentRelationshipBuilder setPublishedTime(String publishedTime) { + this.publishedTime = publishedTime; return this; } @@ -379,7 +339,7 @@ public VulnAssessmentRelationshipBuilder setAssessedElement(Element assessedElem * @parameter modifiedTime value to set * @return this for chaining **/ - public VulnAssessmentRelationshipBuilder setModifiedTime(DateTime modifiedTime) { + public VulnAssessmentRelationshipBuilder setModifiedTime(String modifiedTime) { this.modifiedTime = modifiedTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java b/generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java index 914faa7f2..75e3deafd 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java +++ b/generated/src/main/java/org/spdx/library/model/v3/security/Vulnerability.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,9 +34,8 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.core.DateTime; -import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.Artifact; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -58,13 +57,12 @@ * "identifierLocator": "https://github.com/advisories/GHSA-r9p9-mrjm-926w" * }, { "type": "ExternalIdentifier", "externalIdentifierType": "securityOther", * "identifier": "SNYK-JS-ELLIPTIC-1064899", "identifierLocator": "https://security.snyk.io/vuln/SNYK-JS-ELLIPTIC-1064899" - * } ], "externalReferences": [ { "@type": "ExternalReference", "externalReferenceType": - * "securityAdvisory", "locator": "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" - * }, { "@type": "ExternalReference", "externalReferenceType": "securityAdvisory", - * "locator": "https://ubuntu.com/security/CVE-2020-28498" }, { "@type": "ExternalReference", - * "externalReferenceType": "securityOther", "locator": "https://github.com/indutny/elliptic/pull/244/commits" - * }, { "@type": "ExternalReference", "externalReferenceType": "securityOther", - * "locator": "https://github.com/christianlundkvist/blog/blob/master/2020_05_26_secp256k1_twist_attacks/secp256k1_twist_attacks.md" + * } ], "externalRefs": [ { "@type": "ExternalRef", "externalRefType": "securityAdvisory", + * "locator": "https://nvd.nist.gov/vuln/detail/CVE-2020-28498" }, { "@type": + * "ExternalRef", "externalRefType": "securityAdvisory", "locator": "https://ubuntu.com/security/CVE-2020-28498" + * }, { "@type": "ExternalRef", "externalRefType": "securityOther", "locator": + * "https://github.com/indutny/elliptic/pull/244/commits" }, { "@type": "ExternalRef", + * "externalRefType": "securityOther", "locator": "https://github.com/christianlundkvist/blog/blob/master/2020_05_26_secp256k1_twist_attacks/secp256k1_twist_attacks.md" * } ] }, { "@type": "Relationship", "@id": "urn:spdx.dev:vulnRelationship-1", * "relationshipType": "hasAssociatedVulnerability", "from": "urn:npm-elliptic-6.5.2", * "to": ["urn:spdx.dev:vuln-1"], "startTime": "2021-03-08T16:06:50Z" }, { "@type": @@ -72,7 +70,7 @@ * "publishedBy", "from": "urn:spdx.dev:vuln-1", "to": ["urn:spdx.dev:agent-snyk"], * "startTime": "2021-03-08T16:06:50Z" } ``` */ -public class Vulnerability extends Element { +public class Vulnerability extends Artifact { /** @@ -110,8 +108,8 @@ public Vulnerability(IModelStore modelStore, String objectUri, @Nullable ModelCo */ protected Vulnerability(VulnerabilityBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setModifiedTime(builder.modifiedTime); setWithdrawnTime(builder.withdrawnTime); + setModifiedTime(builder.modifiedTime); setPublishedTime(builder.publishedTime); } @@ -127,79 +125,49 @@ public String getType() { /** - * @return the modifiedTime + * @return the withdrawnTime */ - @SuppressWarnings("unchecked") - public Optional getModifiedTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getWithdrawnTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME); } - /** - * @param modifiedTime the modifiedTime to set + * @param withdrawnTime the withdrawnTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Vulnerability setModifiedTime(@Nullable DateTime modifiedTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME, modifiedTime); + public Vulnerability setWithdrawnTime(@Nullable String withdrawnTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME, withdrawnTime); return this; } /** - * @return the withdrawnTime + * @return the modifiedTime */ - @SuppressWarnings("unchecked") - public Optional getWithdrawnTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getModifiedTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME); } - /** - * @param withdrawnTime the withdrawnTime to set + * @param modifiedTime the modifiedTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Vulnerability setWithdrawnTime(@Nullable DateTime withdrawnTime) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SECURITY_PROP_WITHDRAWN_TIME, withdrawnTime); + public Vulnerability setModifiedTime(@Nullable String modifiedTime) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SECURITY_PROP_MODIFIED_TIME, modifiedTime); return this; } /** * @return the publishedTime */ - @SuppressWarnings("unchecked") - public Optional getPublishedTime() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME); - if (retval.isPresent()) { - if (!(retval.get() instanceof DateTime)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getPublishedTime() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME); } - /** * @param publishedTime the publishedTime to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public Vulnerability setPublishedTime(@Nullable DateTime publishedTime) throws InvalidSPDXAnalysisException { + public Vulnerability setPublishedTime(@Nullable String publishedTime) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.SECURITY_PROP_PUBLISHED_TIME, publishedTime); return this; } @@ -214,40 +182,31 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional modifiedTime; + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { - modifiedTime = getModifiedTime(); - if (modifiedTime.isPresent()) { - retval.addAll(modifiedTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional withdrawnTime = getWithdrawnTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting modifiedTime for Vulnerability: "+e.getMessage()); + retval.add("Error getting withdrawnTime for Vulnerability: "+e.getMessage()); } - Optional withdrawnTime; try { - withdrawnTime = getWithdrawnTime(); - if (withdrawnTime.isPresent()) { - retval.addAll(withdrawnTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional modifiedTime = getModifiedTime(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting withdrawnTime for Vulnerability: "+e.getMessage()); + retval.add("Error getting modifiedTime for Vulnerability: "+e.getMessage()); } - Optional publishedTime; try { - publishedTime = getPublishedTime(); - if (publishedTime.isPresent()) { - retval.addAll(publishedTime.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional publishedTime = getPublishedTime(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting publishedTime for Vulnerability: "+e.getMessage()); } return retval; } - public static class VulnerabilityBuilder extends ElementBuilder { + public static class VulnerabilityBuilder extends ArtifactBuilder { /** * Create an VulnerabilityBuilder from another model object copying the modelStore and copyManager and using an anonymous ID @@ -279,28 +238,28 @@ public VulnerabilityBuilder(IModelStore modelStore, String objectUri, @Nullable super(modelStore, objectUri, copyManager); } - DateTime modifiedTime = null; - DateTime withdrawnTime = null; - DateTime publishedTime = null; + String withdrawnTime = null; + String modifiedTime = null; + String publishedTime = null; /** - * Sets the initial value of modifiedTime - * @parameter modifiedTime value to set + * Sets the initial value of withdrawnTime + * @parameter withdrawnTime value to set * @return this for chaining **/ - public VulnerabilityBuilder setModifiedTime(DateTime modifiedTime) { - this.modifiedTime = modifiedTime; + public VulnerabilityBuilder setWithdrawnTime(String withdrawnTime) { + this.withdrawnTime = withdrawnTime; return this; } /** - * Sets the initial value of withdrawnTime - * @parameter withdrawnTime value to set + * Sets the initial value of modifiedTime + * @parameter modifiedTime value to set * @return this for chaining **/ - public VulnerabilityBuilder setWithdrawnTime(DateTime withdrawnTime) { - this.withdrawnTime = withdrawnTime; + public VulnerabilityBuilder setModifiedTime(String modifiedTime) { + this.modifiedTime = modifiedTime; return this; } @@ -309,7 +268,7 @@ public VulnerabilityBuilder setWithdrawnTime(DateTime withdrawnTime) { * @parameter publishedTime value to set * @return this for chaining **/ - public VulnerabilityBuilder setPublishedTime(DateTime publishedTime) { + public VulnerabilityBuilder setPublishedTime(String publishedTime) { this.publishedTime = publishedTime; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/AnyLicenseInfo.java b/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/AnyLicenseInfo.java similarity index 93% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/AnyLicenseInfo.java rename to generated/src/main/java/org/spdx/library/model/v3/simplelicensing/AnyLicenseInfo.java index d136a0bc3..a55851cf6 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/AnyLicenseInfo.java +++ b/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/AnyLicenseInfo.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.simplelicensing; import javax.annotation.Nullable; @@ -32,8 +32,8 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -90,7 +90,7 @@ protected AnyLicenseInfo(AnyLicenseInfoBuilder builder) throws InvalidSPDXAnalys */ @Override public String getType() { - return "Licensing.AnyLicenseInfo"; + return "SimpleLicensing.AnyLicenseInfo"; } // Getters and Setters @@ -106,9 +106,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseExpression.java b/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/LicenseExpression.java similarity index 69% rename from generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseExpression.java rename to generated/src/main/java/org/spdx/library/model/v3/simplelicensing/LicenseExpression.java index 2f389dea0..f85792b01 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/licensing/LicenseExpression.java +++ b/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/LicenseExpression.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.simplelicensing; import javax.annotation.Nullable; @@ -33,11 +33,13 @@ import org.spdx.storage.IModelStore.IModelStoreLock; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.DictionaryEntry; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -61,6 +63,7 @@ */ public class LicenseExpression extends AnyLicenseInfo { + Collection customIdToUris; /** * Create the LicenseExpression with default model store and generated anonymous ID @@ -85,9 +88,11 @@ public LicenseExpression(String objectUri) throws InvalidSPDXAnalysisException { * @param create true if LicenseExpression is to be created * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression */ + @SuppressWarnings("unchecked") public LicenseExpression(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); + customIdToUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SIMPLE_LICENSING_PROP_CUSTOM_ID_TO_URI, DictionaryEntry.class); } /** @@ -95,9 +100,13 @@ public LicenseExpression(IModelStore modelStore, String objectUri, @Nullable Mod * @param builder Builder to create the LicenseExpression from * @throws InvalidSPDXAnalysisException when unable to create the LicenseExpression */ + @SuppressWarnings("unchecked") protected LicenseExpression(LicenseExpressionBuilder builder) throws InvalidSPDXAnalysisException { super(builder); + customIdToUris = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SIMPLE_LICENSING_PROP_CUSTOM_ID_TO_URI, DictionaryEntry.class); + getCustomIdToUris().addAll(builder.customIdToUris); setLicenseExpression(builder.licenseExpression); + setLicenseListVersion(builder.licenseListVersion); } /* (non-Javadoc) @@ -105,17 +114,20 @@ protected LicenseExpression(LicenseExpressionBuilder builder) throws InvalidSPDX */ @Override public String getType() { - return "Licensing.LicenseExpression"; + return "SimpleLicensing.LicenseExpression"; } // Getters and Setters + public Collection getCustomIdToUris() { + return customIdToUris; + } /** * @return the licenseExpression */ public @Nullable String getLicenseExpression() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_EXPRESSION); + Optional retval = getStringPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_EXPRESSION); return retval.isPresent() ? retval.get() : null; } /** @@ -127,7 +139,23 @@ public LicenseExpression setLicenseExpression(@Nullable String licenseExpression if (isStrict() && Objects.isNull(licenseExpression)) { throw new InvalidSPDXAnalysisException("licenseExpression is a required property"); } - setPropertyValue(SpdxConstants.LICENSING_PROP_LICENSE_EXPRESSION, licenseExpression); + setPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_EXPRESSION, licenseExpression); + return this; + } + + /** + * @return the licenseListVersion + */ + public Optional getLicenseListVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_LIST_VERSION); + } + /** + * @param licenseListVersion the licenseListVersion to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public LicenseExpression setLicenseListVersion(@Nullable String licenseListVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_LIST_VERSION, licenseListVersion); return this; } @@ -141,18 +169,27 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { String licenseExpression = getLicenseExpression(); if (Objects.isNull(licenseExpression) && - Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.LICENSING }))) { + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SIMPLE_LICENSING }))) { retval.add("Missing licenseExpression in LicenseExpression"); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting licenseExpression for LicenseExpression: "+e.getMessage()); } + try { + @SuppressWarnings("unused") + Optional licenseListVersion = getLicenseListVersion(); + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting licenseListVersion for LicenseExpression: "+e.getMessage()); + } + for (DictionaryEntry customIdToUri:customIdToUris) { + retval.addAll(customIdToUri.verify(verifiedIds, specVersionForVerify, profiles)); + } return retval; } @@ -188,9 +225,35 @@ public LicenseExpressionBuilder(IModelStore modelStore, String objectUri, @Nulla super(modelStore, objectUri, copyManager); } + Collection customIdToUris = new ArrayList<>(); String licenseExpression = null; + String licenseListVersion = null; + /** + * Adds a customIdToUri to the initial collection + * @parameter customIdToUri customIdToUri to add + * @return this for chaining + **/ + public LicenseExpressionBuilder addCustomIdToUri(DictionaryEntry customIdToUri) { + if (Objects.nonNull(customIdToUri)) { + customIdToUris.add(customIdToUri); + } + return this; + } + + /** + * Adds all elements from a collection to the initial customIdToUri collection + * @parameter customIdToUriCollection collection to initialize the customIdToUri + * @return this for chaining + **/ + public LicenseExpressionBuilder addAllCustomIdToUri(Collection customIdToUriCollection) { + if (Objects.nonNull(customIdToUriCollection)) { + customIdToUris.addAll(customIdToUriCollection); + } + return this; + } + /** * Sets the initial value of licenseExpression * @parameter licenseExpression value to set @@ -200,6 +263,16 @@ public LicenseExpressionBuilder setLicenseExpression(String licenseExpression) { this.licenseExpression = licenseExpression; return this; } + + /** + * Sets the initial value of licenseListVersion + * @parameter licenseListVersion value to set + * @return this for chaining + **/ + public LicenseExpressionBuilder setLicenseListVersion(String licenseListVersion) { + this.licenseListVersion = licenseListVersion; + return this; + } /** diff --git a/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingText.java b/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingText.java new file mode 100644 index 000000000..b17a2fe90 --- /dev/null +++ b/generated/src/main/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingText.java @@ -0,0 +1,207 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.v3.simplelicensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.spdx.library.DefaultModelStore; +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.ModelObject; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.IModelStore.IModelStoreLock; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import org.spdx.library.SpdxConstants; +import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ProfileIdentifierType; + +/** + * DO NOT EDIT - this file is generated by the Owl to Java Utility + * See: https://github.com/spdx/tools-java + * + * A SimpleLicensingText represents a License or Addition that is not listed on the + * SPDX License List at https://spdx.org/licenses, and is therefore defined by an + * SPDX data creator. + */ +public class SimpleLicensingText extends Element { + + + /** + * Create the SimpleLicensingText with default model store and generated anonymous ID + * @throws InvalidSPDXAnalysisException when unable to create the SimpleLicensingText + */ + public SimpleLicensingText() throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * @param objectUri URI or anonymous ID for the SimpleLicensingText + * @throws InvalidSPDXAnalysisException when unable to create the SimpleLicensingText + */ + public SimpleLicensingText(String objectUri) throws InvalidSPDXAnalysisException { + this(DefaultModelStore.getDefaultModelStore(), objectUri, DefaultModelStore.getDefaultCopyManager(), true); + } + + /** + * @param modelStore Model store where the SimpleLicensingText is to be stored + * @param objectUri URI or anonymous ID for the SimpleLicensingText + * @param copyManager Copy manager for the SimpleLicensingText - can be null if copying is not required + * @param create true if SimpleLicensingText is to be created + * @throws InvalidSPDXAnalysisException when unable to create the SimpleLicensingText + */ + public SimpleLicensingText(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, + boolean create) throws InvalidSPDXAnalysisException { + super(modelStore, objectUri, copyManager, create); + } + + /** + * Create the SimpleLicensingText from the builder - used in the builder class + * @param builder Builder to create the SimpleLicensingText from + * @throws InvalidSPDXAnalysisException when unable to create the SimpleLicensingText + */ + protected SimpleLicensingText(SimpleLicensingTextBuilder builder) throws InvalidSPDXAnalysisException { + super(builder); + setLicenseText(builder.licenseText); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#getType() + */ + @Override + public String getType() { + return "SimpleLicensing.SimpleLicensingText"; + } + + // Getters and Setters + + + /** + * @return the licenseText + */ + public @Nullable String getLicenseText() throws InvalidSPDXAnalysisException { + Optional retval = getStringPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_TEXT); + return retval.isPresent() ? retval.get() : null; + } + /** + * @param licenseText the licenseText to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public SimpleLicensingText setLicenseText(@Nullable String licenseText) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(licenseText)) { + throw new InvalidSPDXAnalysisException("licenseText is a required property"); + } + setPropertyValue(SpdxConstants.SIMPLE_LICENSING_PROP_LICENSE_TEXT, licenseText); + return this; + } + + + @Override + public String toString() { + return "SimpleLicensingText: "+getObjectUri(); + } + + /* (non-Javadoc) + * @see org.spdx.library.model.ModelObject#_verify(java.util.List) + */ + @Override + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { + List retval = new ArrayList<>(); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); + try { + String licenseText = getLicenseText(); + if (Objects.isNull(licenseText) && + Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SIMPLE_LICENSING }))) { + retval.add("Missing licenseText in SimpleLicensingText"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting licenseText for SimpleLicensingText: "+e.getMessage()); + } + return retval; + } + + public static class SimpleLicensingTextBuilder extends ElementBuilder { + + /** + * Create an SimpleLicensingTextBuilder from another model object copying the modelStore and copyManager and using an anonymous ID + * @param from model object to copy the model store and copyManager from + * @throws InvalidSPDXAnalysisException + */ + public SimpleLicensingTextBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); + } + + /** + * Create an SimpleLicensingTextBuilder from another model object copying the modelStore and copyManager + * @param from model object to copy the model store and copyManager from + * @param objectUri URI for the object + * @param objectUri + */ + public SimpleLicensingTextBuilder(ModelObject from, String objectUri) { + this(from.getModelStore(), objectUri, from.getCopyManager()); + setStrict(from.isStrict()); + } + + /** + * Creates a SimpleLicensingTextBuilder + * @param modelStore model store for the built SimpleLicensingText + * @param objectUri objectUri for the built SimpleLicensingText + * @param copyManager optional copyManager for the built SimpleLicensingText + */ + public SimpleLicensingTextBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { + super(modelStore, objectUri, copyManager); + } + + String licenseText = null; + + + /** + * Sets the initial value of licenseText + * @parameter licenseText value to set + * @return this for chaining + **/ + public SimpleLicensingTextBuilder setLicenseText(String licenseText) { + this.licenseText = licenseText; + return this; + } + + + /** + * @return the SimpleLicensingText + * @throws InvalidSPDXAnalysisException on any errors during build + */ + public SimpleLicensingText build() throws InvalidSPDXAnalysisException { + IModelStoreLock lock = modelStore.enterCriticalSection(false); + try { + return new SimpleLicensingText(this); + } finally { + modelStore.leaveCriticalSection(lock); + } + } + } +} diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java b/generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java index 11dcf53e3..8a8fdbd26 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/DependencyConditionalityType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java b/generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java index 018f4a94f..81fd43b3b 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/Sbom.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -36,8 +36,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.Bom; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -116,9 +116,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); return retval; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java b/generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java index b84e5391b..256d4a639 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SbomType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java b/generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java index 8c8b71193..f47b733d1 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/Snippet.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -32,10 +32,13 @@ import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.IModelStore.IModelStoreLock; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.PositiveIntegerRange; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -85,6 +88,7 @@ public Snippet(IModelStore modelStore, String objectUri, @Nullable ModelCopyMana protected Snippet(SnippetBuilder builder) throws InvalidSPDXAnalysisException { super(builder); setLineRange(builder.lineRange); + setSnippetFromFile(builder.snippetFromFile); setByteRange(builder.byteRange); } @@ -125,6 +129,35 @@ public Snippet setLineRange(@Nullable PositiveIntegerRange lineRange) throws Inv return this; } + /** + * @return the snippetFromFile + */ + @SuppressWarnings("unchecked") + public @Nullable SpdxFile getSnippetFromFile() throws InvalidSPDXAnalysisException { + Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_SNIPPET_FROM_FILE); + if (retval.isPresent()) { + if (!(retval.get() instanceof SpdxFile)) { + throw new InvalidSPDXAnalysisException("Incorrect type stored for "); + } + return (SpdxFile)(retval.get()); + } else { + return null; + } + } + + /** + * @param snippetFromFile the snippetFromFile to set + * @return this to chain setters + * @throws InvalidSPDXAnalysisException + */ + public Snippet setSnippetFromFile(@Nullable SpdxFile snippetFromFile) throws InvalidSPDXAnalysisException { + if (isStrict() && Objects.isNull(snippetFromFile)) { + throw new InvalidSPDXAnalysisException("snippetFromFile is a required property"); + } + setPropertyValue(SpdxConstants.SOFTWARE_PROP_SNIPPET_FROM_FILE, snippetFromFile); + return this; + } + /** * @return the byteRange */ @@ -161,23 +194,34 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); Optional lineRange; try { lineRange = getLineRange(); if (lineRange.isPresent()) { - retval.addAll(lineRange.get().verify(verifiedIds, specVersion, profiles)); + retval.addAll(lineRange.get().verify(verifiedIds, specVersionForVerify, profiles)); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting lineRange for Snippet: "+e.getMessage()); } + SpdxFile snippetFromFile; + try { + snippetFromFile = getSnippetFromFile(); + if (Objects.nonNull(snippetFromFile)) { + retval.addAll(snippetFromFile.verify(verifiedIds, specVersionForVerify, profiles)); + } else if (!Collections.disjoint(profiles, Arrays.asList(new ProfileIdentifierType[] { ProfileIdentifierType.SOFTWARE }))) { + retval.add("Missing snippetFromFile in Snippet"); + } + } catch (InvalidSPDXAnalysisException e) { + retval.add("Error getting snippetFromFile for Snippet: "+e.getMessage()); + } Optional byteRange; try { byteRange = getByteRange(); if (byteRange.isPresent()) { - retval.addAll(byteRange.get().verify(verifiedIds, specVersion, profiles)); + retval.addAll(byteRange.get().verify(verifiedIds, specVersionForVerify, profiles)); } } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting byteRange for Snippet: "+e.getMessage()); @@ -218,6 +262,7 @@ public SnippetBuilder(IModelStore modelStore, String objectUri, @Nullable ModelC } PositiveIntegerRange lineRange = null; + SpdxFile snippetFromFile = null; PositiveIntegerRange byteRange = null; @@ -231,6 +276,16 @@ public SnippetBuilder setLineRange(PositiveIntegerRange lineRange) { return this; } + /** + * Sets the initial value of snippetFromFile + * @parameter snippetFromFile value to set + * @return this for chaining + **/ + public SnippetBuilder setSnippetFromFile(SpdxFile snippetFromFile) { + this.snippetFromFile = snippetFromFile; + return this; + } + /** * Sets the initial value of byteRange * @parameter byteRange value to set diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java index cafa26e81..fb89ed1f8 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareArtifact.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -36,9 +36,8 @@ import java.util.Objects; import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.Artifact; -import org.spdx.library.model.v3.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -49,6 +48,7 @@ */ public class SoftwareArtifact extends Artifact { + Collection attributionTexts; Collection additionalPurposes; /** @@ -74,10 +74,12 @@ public SoftwareArtifact(String objectUri) throws InvalidSPDXAnalysisException { * @param create true if SoftwareArtifact is to be created * @throws InvalidSPDXAnalysisException when unable to create the SoftwareArtifact */ + @SuppressWarnings("unchecked") public SoftwareArtifact(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { super(modelStore, objectUri, copyManager, create); additionalPurposes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ADDITIONAL_PURPOSE, SoftwarePurpose.class); + attributionTexts = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT, String.class); } /** @@ -85,14 +87,14 @@ public SoftwareArtifact(IModelStore modelStore, String objectUri, @Nullable Mode * @param builder Builder to create the SoftwareArtifact from * @throws InvalidSPDXAnalysisException when unable to create the SoftwareArtifact */ + @SuppressWarnings("unchecked") protected SoftwareArtifact(SoftwareArtifactBuilder builder) throws InvalidSPDXAnalysisException { super(builder); additionalPurposes = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ADDITIONAL_PURPOSE, SoftwarePurpose.class); + attributionTexts = (Collection)(Collection)this.getObjectPropertyValueCollection(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT, String.class); getAdditionalPurposes().addAll(builder.additionalPurposes); - setConcludedLicense(builder.concludedLicense); - setDeclaredLicense(builder.declaredLicense); + getAttributionTexts().addAll(builder.attributionTexts); setPrimaryPurpose(builder.primaryPurpose); - setAttributionText(builder.attributionText); setContentIdentifier(builder.contentIdentifier); setCopyrightText(builder.copyrightText); } @@ -109,59 +111,10 @@ public String getType() { public Collection getAdditionalPurposes() { return additionalPurposes; } - - - /** - * @return the concludedLicense - */ - @SuppressWarnings("unchecked") - public Optional getConcludedLicense() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE); - if (retval.isPresent()) { - if (!(retval.get() instanceof AnyLicenseInfo)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Collection getAttributionTexts() { + return attributionTexts; } - /** - * @param concludedLicense the concludedLicense to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SoftwareArtifact setConcludedLicense(@Nullable AnyLicenseInfo concludedLicense) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONCLUDED_LICENSE, concludedLicense); - return this; - } - - /** - * @return the declaredLicense - */ - @SuppressWarnings("unchecked") - public Optional getDeclaredLicense() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE); - if (retval.isPresent()) { - if (!(retval.get() instanceof AnyLicenseInfo)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } - } - - /** - * @param declaredLicense the declaredLicense to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SoftwareArtifact setDeclaredLicense(@Nullable AnyLicenseInfo declaredLicense) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_DECLARED_LICENSE, declaredLicense); - return this; - } /** * @return the primaryPurpose @@ -188,22 +141,6 @@ public SoftwareArtifact setPrimaryPurpose(@Nullable SoftwarePurpose primaryPurpo return this; } - /** - * @return the attributionText - */ - public Optional getAttributionText() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT); - } - /** - * @param attributionText the attributionText to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SoftwareArtifact setAttributionText(@Nullable String attributionText) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_ATTRIBUTION_TEXT, attributionText); - return this; - } - /** * @return the contentIdentifier */ @@ -246,39 +183,15 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional concludedLicense; - try { - concludedLicense = getConcludedLicense(); - if (concludedLicense.isPresent()) { - retval.addAll(concludedLicense.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting concludedLicense for SoftwareArtifact: "+e.getMessage()); - } - Optional declaredLicense; - try { - declaredLicense = getDeclaredLicense(); - if (declaredLicense.isPresent()) { - retval.addAll(declaredLicense.get().verify(verifiedIds, specVersion, profiles)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting declaredLicense for SoftwareArtifact: "+e.getMessage()); - } + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional primaryPurpose = getPrimaryPurpose(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting primaryPurpose for SoftwareArtifact: "+e.getMessage()); } - try { - @SuppressWarnings("unused") - Optional attributionText = getAttributionText(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting attributionText for SoftwareArtifact: "+e.getMessage()); - } try { @SuppressWarnings("unused") Optional contentIdentifier = getContentIdentifier(); @@ -327,10 +240,8 @@ public SoftwareArtifactBuilder(IModelStore modelStore, String objectUri, @Nullab } Collection additionalPurposes = new ArrayList<>(); - AnyLicenseInfo concludedLicense = null; - AnyLicenseInfo declaredLicense = null; + Collection attributionTexts = new ArrayList<>(); SoftwarePurpose primaryPurpose = null; - String attributionText = null; String contentIdentifier = null; String copyrightText = null; @@ -360,22 +271,26 @@ public SoftwareArtifactBuilder addAllAdditionalPurpose(Collection attributionTextCollection) { + if (Objects.nonNull(attributionTextCollection)) { + attributionTexts.addAll(attributionTextCollection); + } return this; } @@ -389,16 +304,6 @@ public SoftwareArtifactBuilder setPrimaryPurpose(SoftwarePurpose primaryPurpose) return this; } - /** - * Sets the initial value of attributionText - * @parameter attributionText value to set - * @return this for chaining - **/ - public SoftwareArtifactBuilder setAttributionText(String attributionText) { - this.attributionText = attributionText; - return this; - } - /** * Sets the initial value of contentIdentifier * @parameter contentIdentifier value to set diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java index b2bbe6851..c83256e31 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyLinkType.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java index 4425bb285..6ae41c285 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationship.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,8 +34,8 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; import org.spdx.library.model.v3.core.LifecycleScopedRelationship; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -156,9 +156,9 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") Optional softwareLinkage = getSoftwareLinkage(); diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java index 958507784..832248cd4 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SoftwarePurpose.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java index 398514f0a..b809de426 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxFile.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,8 +34,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; -import org.spdx.library.model.v3.core.MediaType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -100,25 +99,15 @@ public String getType() { /** * @return the contentType */ - @SuppressWarnings("unchecked") - public Optional getContentType() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE); - if (retval.isPresent()) { - if (!(retval.get() instanceof MediaType)) { - throw new InvalidSPDXAnalysisException("Incorrect type stored for "); - } - return (Optional)(Optional)(retval); - } else { - return Optional.empty(); - } + public Optional getContentType() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE); } - /** * @param contentType the contentType to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxFile setContentType(@Nullable MediaType contentType) throws InvalidSPDXAnalysisException { + public SpdxFile setContentType(@Nullable String contentType) throws InvalidSPDXAnalysisException { setPropertyValue(SpdxConstants.SOFTWARE_PROP_CONTENT_TYPE, contentType); return this; } @@ -133,15 +122,12 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); - Optional contentType; + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { - contentType = getContentType(); - if (contentType.isPresent()) { - retval.addAll(contentType.get().verify(verifiedIds, specVersion, profiles)); - } + @SuppressWarnings("unused") + Optional contentType = getContentType(); } catch (InvalidSPDXAnalysisException e) { retval.add("Error getting contentType for SpdxFile: "+e.getMessage()); } @@ -180,7 +166,7 @@ public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable Model super(modelStore, objectUri, copyManager); } - MediaType contentType = null; + String contentType = null; /** @@ -188,7 +174,7 @@ public SpdxFileBuilder(IModelStore modelStore, String objectUri, @Nullable Model * @parameter contentType value to set * @return this for chaining **/ - public SpdxFileBuilder setContentType(MediaType contentType) { + public SpdxFileBuilder setContentType(String contentType) { this.contentType = contentType; return this; } diff --git a/generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java index f417930f3..8100c1b27 100644 --- a/generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java +++ b/generated/src/main/java/org/spdx/library/model/v3/software/SpdxPackage.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -34,7 +34,7 @@ import java.util.Optional; import org.spdx.library.SpdxConstants; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; /** * DO NOT EDIT - this file is generated by the Owl to Java Utility @@ -89,11 +89,11 @@ public SpdxPackage(IModelStore modelStore, String objectUri, @Nullable ModelCopy */ protected SpdxPackage(SpdxPackageBuilder builder) throws InvalidSPDXAnalysisException { super(builder); - setSourceInfo(builder.sourceInfo); - setHomePage(builder.homePage); - setPackageVersion(builder.packageVersion); setPackageUrl(builder.packageUrl); + setHomePage(builder.homePage); setDownloadLocation(builder.downloadLocation); + setPackageVersion(builder.packageVersion); + setSourceInfo(builder.sourceInfo); } /* (non-Javadoc) @@ -108,18 +108,18 @@ public String getType() { /** - * @return the sourceInfo + * @return the packageUrl */ - public Optional getSourceInfo() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO); + public Optional getPackageUrl() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL); } /** - * @param sourceInfo the sourceInfo to set + * @param packageUrl the packageUrl to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setSourceInfo(@Nullable String sourceInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO, sourceInfo); + public SpdxPackage setPackageUrl(@Nullable String packageUrl) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL, packageUrl); return this; } @@ -140,50 +140,50 @@ public SpdxPackage setHomePage(@Nullable String homePage) throws InvalidSPDXAnal } /** - * @return the packageVersion + * @return the downloadLocation */ - public Optional getPackageVersion() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_VERSION); + public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION); } /** - * @param packageVersion the packageVersion to set + * @param downloadLocation the downloadLocation to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setPackageVersion(@Nullable String packageVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_VERSION, packageVersion); + public SpdxPackage setDownloadLocation(@Nullable String downloadLocation) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION, downloadLocation); return this; } /** - * @return the packageUrl + * @return the packageVersion */ - public Optional getPackageUrl() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL); + public Optional getPackageVersion() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_VERSION); } /** - * @param packageUrl the packageUrl to set + * @param packageVersion the packageVersion to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setPackageUrl(@Nullable String packageUrl) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_URL, packageUrl); + public SpdxPackage setPackageVersion(@Nullable String packageVersion) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_PACKAGE_VERSION, packageVersion); return this; } /** - * @return the downloadLocation + * @return the sourceInfo */ - public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION); + public Optional getSourceInfo() throws InvalidSPDXAnalysisException { + return getStringPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO); } /** - * @param downloadLocation the downloadLocation to set + * @param sourceInfo the sourceInfo to set * @return this to chain setters * @throws InvalidSPDXAnalysisException */ - public SpdxPackage setDownloadLocation(@Nullable String downloadLocation) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstants.SOFTWARE_PROP_DOWNLOAD_LOCATION, downloadLocation); + public SpdxPackage setSourceInfo(@Nullable String sourceInfo) throws InvalidSPDXAnalysisException { + setPropertyValue(SpdxConstants.SOFTWARE_PROP_SOURCE_INFO, sourceInfo); return this; } @@ -197,14 +197,14 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersionForVerify, List profiles) { List retval = new ArrayList<>(); - retval.addAll(super._verify(verifiedIds, specVersion, profiles)); + retval.addAll(super._verify(verifiedIds, specVersionForVerify, profiles)); try { @SuppressWarnings("unused") - Optional sourceInfo = getSourceInfo(); + Optional packageUrl = getPackageUrl(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting sourceInfo for SpdxPackage: "+e.getMessage()); + retval.add("Error getting packageUrl for SpdxPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") @@ -214,21 +214,21 @@ protected List _verify(Set verifiedIds, String specVersion, List } try { @SuppressWarnings("unused") - Optional packageVersion = getPackageVersion(); + Optional downloadLocation = getDownloadLocation(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting packageVersion for SpdxPackage: "+e.getMessage()); + retval.add("Error getting downloadLocation for SpdxPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional packageUrl = getPackageUrl(); + Optional packageVersion = getPackageVersion(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting packageUrl for SpdxPackage: "+e.getMessage()); + retval.add("Error getting packageVersion for SpdxPackage: "+e.getMessage()); } try { @SuppressWarnings("unused") - Optional downloadLocation = getDownloadLocation(); + Optional sourceInfo = getSourceInfo(); } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting downloadLocation for SpdxPackage: "+e.getMessage()); + retval.add("Error getting sourceInfo for SpdxPackage: "+e.getMessage()); } return retval; } @@ -265,20 +265,20 @@ public SpdxPackageBuilder(IModelStore modelStore, String objectUri, @Nullable Mo super(modelStore, objectUri, copyManager); } - String sourceInfo = null; - String homePage = null; - String packageVersion = null; String packageUrl = null; + String homePage = null; String downloadLocation = null; + String packageVersion = null; + String sourceInfo = null; /** - * Sets the initial value of sourceInfo - * @parameter sourceInfo value to set + * Sets the initial value of packageUrl + * @parameter packageUrl value to set * @return this for chaining **/ - public SpdxPackageBuilder setSourceInfo(String sourceInfo) { - this.sourceInfo = sourceInfo; + public SpdxPackageBuilder setPackageUrl(String packageUrl) { + this.packageUrl = packageUrl; return this; } @@ -293,32 +293,32 @@ public SpdxPackageBuilder setHomePage(String homePage) { } /** - * Sets the initial value of packageVersion - * @parameter packageVersion value to set + * Sets the initial value of downloadLocation + * @parameter downloadLocation value to set * @return this for chaining **/ - public SpdxPackageBuilder setPackageVersion(String packageVersion) { - this.packageVersion = packageVersion; + public SpdxPackageBuilder setDownloadLocation(String downloadLocation) { + this.downloadLocation = downloadLocation; return this; } /** - * Sets the initial value of packageUrl - * @parameter packageUrl value to set + * Sets the initial value of packageVersion + * @parameter packageVersion value to set * @return this for chaining **/ - public SpdxPackageBuilder setPackageUrl(String packageUrl) { - this.packageUrl = packageUrl; + public SpdxPackageBuilder setPackageVersion(String packageVersion) { + this.packageVersion = packageVersion; return this; } /** - * Sets the initial value of downloadLocation - * @parameter downloadLocation value to set + * Sets the initial value of sourceInfo + * @parameter sourceInfo value to set * @return this for chaining **/ - public SpdxPackageBuilder setDownloadLocation(String downloadLocation) { - this.downloadLocation = downloadLocation; + public SpdxPackageBuilder setSourceInfo(String sourceInfo) { + this.sourceInfo = sourceInfo; return this; } diff --git a/pom.xml b/pom.xml index c8f82cb82..3f4f870ab 100644 --- a/pom.xml +++ b/pom.xml @@ -187,6 +187,7 @@ + src/main/java src/test @@ -214,6 +215,25 @@ true + + org.codehaus.mojo + build-helper-maven-plugin + 3.5.0 + + + add-source + generate-sources + + add-source + + + + generated/src/main/java + + + + + org.apache.maven.plugins maven-javadoc-plugin diff --git a/src/main/java/org/spdx/library/model/ExternalElement.java b/src/main/java/org/spdx/library/model/ExternalElement.java index 7d499ab84..c9395fbaf 100644 --- a/src/main/java/org/spdx/library/model/ExternalElement.java +++ b/src/main/java/org/spdx/library/model/ExternalElement.java @@ -32,7 +32,7 @@ import org.spdx.library.model.v3.core.Element; import org.spdx.library.model.v3.core.ExternalIdentifier; import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.library.model.v3.core.ExternalReference; +import org.spdx.library.model.v3.core.ExternalRef; import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.storage.IModelStore; @@ -97,7 +97,7 @@ public CreationInfo getCreationInfo() throws InvalidSPDXAnalysisException { } @Override - public Collection getExternalReferences() { + public Collection getExternalRefs() { throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); } @Override @@ -149,7 +149,7 @@ public String toString() { * @see org.spdx.library.model.ModelObject#_verify(java.util.List) */ @Override - protected List _verify(Set verifiedIds, String specVersion, List profiles) { + public List _verify(Set verifiedIds, String specVersion, List profiles) { return new ArrayList<>(); } diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java index 3c4c02789..74cd1a824 100644 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ b/src/main/java/org/spdx/library/model/ModelObject.java @@ -51,7 +51,7 @@ import org.spdx.library.model.v3.core.Element; import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.library.model.v3.core.ProfileIdentifierType; -import org.spdx.library.model.v3.licensing.AnyLicenseInfo; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; diff --git a/src/test/java/org/spdx/library/model/ModelCollectionTest.java b/src/test/java/org/spdx/library/model/ModelCollectionTest.java index a7e171142..02bf028bf 100644 --- a/src/test/java/org/spdx/library/model/ModelCollectionTest.java +++ b/src/test/java/org/spdx/library/model/ModelCollectionTest.java @@ -9,8 +9,8 @@ import org.spdx.library.DefaultModelStore; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.core.Element; -import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.v3.core.Element; +import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java index 80c19295f..7673789a3 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java +++ b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java @@ -25,7 +25,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/ModelObjectTest.java index 210f34f38..229c4c21b 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/ModelObjectTest.java @@ -27,14 +27,14 @@ import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstants; import org.spdx.library.model.ModelObjectForTesting.ModelObjectForTestingBuilder; -import org.spdx.library.model.core.ExternalMap; -import org.spdx.library.model.core.HashAlgorithm; -import org.spdx.library.model.expandedlicense.ConjunctiveLicenseSet; -import org.spdx.library.model.licensing.AnyLicenseInfo; -import org.spdx.library.model.licensing.CustomLicense; -import org.spdx.library.model.licensing.ListedLicense; -import org.spdx.library.model.licensing.ListedLicenseException; -import org.spdx.library.model.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; +import org.spdx.library.model.v3.core.ExternalMap; +import org.spdx.library.model.v3.core.HashAlgorithm; +import org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet; +import org.spdx.library.model.v3.expandedlicensing.CustomLicense; +import org.spdx.library.model.v3.expandedlicensing.ListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ListedLicenseException; +import org.spdx.library.model.v3.expandedlicensing.ListedLicenseException.ListedLicenseExceptionBuilder; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IdType; @@ -134,14 +134,16 @@ protected void setUp() throws Exception { eli1.setLicenseText("eli1 text"); ConjunctiveLicenseSet cls = new ConjunctiveLicenseSet(store, store.getNextId(IdType.Anonymous, null), copyManager, true); - cls.addMember(new ListedLicense(store, "Apache-2.0", copyManager, true)); - cls.addMember(eli1); + cls.getMembers().add(new ListedLicense(store, "Apache-2.0", copyManager, true)); + cls.getMembers().add(eli1); TEST_LIST_PROPERTY_VALUES = new List[] {Arrays.asList("ListItem1", "listItem2", "listItem3"), Arrays.asList(true, false, true), Arrays.asList(new ModelObject[] {lex, eli1}), Arrays.asList(new HashAlgorithm[] {HashAlgorithm.SHA256, HashAlgorithm.SHA1}), Arrays.asList(new Integer[] {1, 3, 5})}; TEST_MODEL_OBJECT_PROP_VALUES = new ModelObject[] {lex, eli1}; + // TODO: Changes these back once we have the individuals implemented + /* TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true), eli1, new SpdxNoneLicense()}; TEST_ANYLICENSEINFO_LIST_PROP_VALUES = new List[] {Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "MIT", copyManager, true), @@ -149,6 +151,16 @@ eli1, new ListedLicense(store, "GPL-2.0-only", copyManager, true)}), Arrays.asList(new AnyLicenseInfo[] {new SpdxNoAssertionLicense()}), Arrays.asList(new AnyLicenseInfo[] {cls, eli1}) }; + */ + + TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true), + eli1}; + TEST_ANYLICENSEINFO_LIST_PROP_VALUES = new List[] {Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "MIT", copyManager, true), + eli1, new ListedLicense(store, "GPL-2.0-only", copyManager, true)}), + Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true)}), + Arrays.asList(new AnyLicenseInfo[] {cls, eli1}) + }; + ALL_PROPERTY_VALUES = new HashMap<>(); for (int i = 0; i < TEST_STRING_VALUE_PROPERTIES.length; i++) { diff --git a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java index e294f4d81..a1982c4c8 100644 --- a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java +++ b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java @@ -27,7 +27,7 @@ import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.core.ExternalMap; +import org.spdx.library.model.v3.core.ExternalMap; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; diff --git a/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java index 9522cc578..dc602232e 100644 --- a/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java +++ b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -28,6 +28,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; import org.spdx.library.model.v3.ai.AIPackage.AIPackageBuilder; +import org.spdx.library.model.v3.core.PresenceType; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -43,25 +44,20 @@ public class AIPackageTest extends TestCase { ModelCopyManager copyManager; static final String LIMITATION_TEST_VALUE = "test limitation"; - static final String ENERGY_CONSUMPTION_TEST_VALUE = "test energyConsumption"; static final String INFORMATION_ABOUT_APPLICATION_TEST_VALUE = "test informationAboutApplication"; static final String INFORMATION_ABOUT_TRAINING_TEST_VALUE = "test informationAboutTraining"; - static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1 = PresenceType.values()[0]; - static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2 = PresenceType.values()[1]; + static final String ENERGY_CONSUMPTION_TEST_VALUE = "test energyConsumption"; static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE1 = SafetyRiskAssessmentType.values()[0]; static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE2 = SafetyRiskAssessmentType.values()[1]; static final PresenceType AUTONOMY_TYPE_TEST_VALUE1 = PresenceType.values()[0]; static final PresenceType AUTONOMY_TYPE_TEST_VALUE2 = PresenceType.values()[1]; - static final String TYPE_OF_MODEL_TEST_VALUE1 = "test 1 typeOfModel"; - static final String TYPE_OF_MODEL_TEST_VALUE2 = "test 2 typeOfModel"; - static final String TYPE_OF_MODEL_TEST_VALUE3 = "test 3 typeOfModel"; - static final List TYPE_OF_MODEL_TEST_LIST1 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE1, TYPE_OF_MODEL_TEST_VALUE2 }); - static final List TYPE_OF_MODEL_TEST_LIST2 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE3 }); - static final String MODEL_DATA_PREPROCESSING_TEST_VALUE1 = "test 1 modelDataPreprocessing"; - static final String MODEL_DATA_PREPROCESSING_TEST_VALUE2 = "test 2 modelDataPreprocessing"; - static final String MODEL_DATA_PREPROCESSING_TEST_VALUE3 = "test 3 modelDataPreprocessing"; - static final List MODEL_DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE1, MODEL_DATA_PREPROCESSING_TEST_VALUE2 }); - static final List MODEL_DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE3 }); + static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1 = PresenceType.values()[0]; + static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2 = PresenceType.values()[1]; + static final String DOMAIN_TEST_VALUE1 = "test 1 domain"; + static final String DOMAIN_TEST_VALUE2 = "test 2 domain"; + static final String DOMAIN_TEST_VALUE3 = "test 3 domain"; + static final List DOMAIN_TEST_LIST1 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE1, DOMAIN_TEST_VALUE2 }); + static final List DOMAIN_TEST_LIST2 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE3 }); static final String STANDARD_COMPLIANCE_TEST_VALUE1 = "test 1 standardCompliance"; static final String STANDARD_COMPLIANCE_TEST_VALUE2 = "test 2 standardCompliance"; static final String STANDARD_COMPLIANCE_TEST_VALUE3 = "test 3 standardCompliance"; @@ -72,11 +68,16 @@ public class AIPackageTest extends TestCase { static final String MODEL_EXPLAINABILITY_TEST_VALUE3 = "test 3 modelExplainability"; static final List MODEL_EXPLAINABILITY_TEST_LIST1 = Arrays.asList(new String[] { MODEL_EXPLAINABILITY_TEST_VALUE1, MODEL_EXPLAINABILITY_TEST_VALUE2 }); static final List MODEL_EXPLAINABILITY_TEST_LIST2 = Arrays.asList(new String[] { MODEL_EXPLAINABILITY_TEST_VALUE3 }); - static final String DOMAIN_TEST_VALUE1 = "test 1 domain"; - static final String DOMAIN_TEST_VALUE2 = "test 2 domain"; - static final String DOMAIN_TEST_VALUE3 = "test 3 domain"; - static final List DOMAIN_TEST_LIST1 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE1, DOMAIN_TEST_VALUE2 }); - static final List DOMAIN_TEST_LIST2 = Arrays.asList(new String[] { DOMAIN_TEST_VALUE3 }); + static final String TYPE_OF_MODEL_TEST_VALUE1 = "test 1 typeOfModel"; + static final String TYPE_OF_MODEL_TEST_VALUE2 = "test 2 typeOfModel"; + static final String TYPE_OF_MODEL_TEST_VALUE3 = "test 3 typeOfModel"; + static final List TYPE_OF_MODEL_TEST_LIST1 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE1, TYPE_OF_MODEL_TEST_VALUE2 }); + static final List TYPE_OF_MODEL_TEST_LIST2 = Arrays.asList(new String[] { TYPE_OF_MODEL_TEST_VALUE3 }); + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE1 = "test 1 modelDataPreprocessing"; + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE2 = "test 2 modelDataPreprocessing"; + static final String MODEL_DATA_PREPROCESSING_TEST_VALUE3 = "test 3 modelDataPreprocessing"; + static final List MODEL_DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE1, MODEL_DATA_PREPROCESSING_TEST_VALUE2 }); + static final List MODEL_DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE3 }); protected void setUp() throws Exception { super.setUp(); @@ -92,27 +93,27 @@ public static AIPackageBuilder builderForAIPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager) .setLimitation(LIMITATION_TEST_VALUE) - .setEnergyConsumption(ENERGY_CONSUMPTION_TEST_VALUE) .setInformationAboutApplication(INFORMATION_ABOUT_APPLICATION_TEST_VALUE) .setInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) - .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE1) - .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) - .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) - .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) + .setEnergyConsumption(ENERGY_CONSUMPTION_TEST_VALUE) + .addDomain(DOMAIN_TEST_VALUE1) + .addDomain(DOMAIN_TEST_VALUE2) .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE2) .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE1) .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE2) - .addDomain(DOMAIN_TEST_VALUE1) - .addDomain(DOMAIN_TEST_VALUE2) - .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) + .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE1) + .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) + .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) + .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) .setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE1) .setAutonomyType(AUTONOMY_TYPE_TEST_VALUE1) + .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) //TODO: Add in test values /******************** - .addHyperparameter(DictionaryEntry) - .addMetricDecisionThreshold(DictionaryEntry) .addMetric(DictionaryEntry) + .addMetricDecisionThreshold(DictionaryEntry) + .addHyperparameter(DictionaryEntry) ***************/ ; return retval; @@ -160,16 +161,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSensitivePersonalInformation}. - */ - public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1), testAIPackage.getSensitivePersonalInformation()); - testAIPackage.setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2); - assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2), testAIPackage.getSensitivePersonalInformation()); - } - /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSafetyRiskAssessment}. */ @@ -191,23 +182,23 @@ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setLimitation}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSensitivePersonalInformation}. */ - public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { + public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(LIMITATION_TEST_VALUE), testAIPackage.getLimitation()); - testAIPackage.setLimitation("new limitation value"); - assertEquals(Optional.of("new limitation value"), testAIPackage.getLimitation()); + assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1), testAIPackage.getSensitivePersonalInformation()); + testAIPackage.setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2); + assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2), testAIPackage.getSensitivePersonalInformation()); } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setEnergyConsumption}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setLimitation}. */ - public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { + public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(ENERGY_CONSUMPTION_TEST_VALUE), testAIPackage.getEnergyConsumption()); - testAIPackage.setEnergyConsumption("new energyConsumption value"); - assertEquals(Optional.of("new energyConsumption value"), testAIPackage.getEnergyConsumption()); + assertEquals(Optional.of(LIMITATION_TEST_VALUE), testAIPackage.getLimitation()); + testAIPackage.setLimitation("new limitation value"); + assertEquals(Optional.of("new limitation value"), testAIPackage.getLimitation()); } /** @@ -231,14 +222,24 @@ public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysi } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getHyperparameter}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setEnergyConsumption}. */ - public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisException { + public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); -// testAIPackage.getHyperparameters().clear(); -// testAIPackage.getHyperparameters().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); + assertEquals(Optional.of(ENERGY_CONSUMPTION_TEST_VALUE), testAIPackage.getEnergyConsumption()); + testAIPackage.setEnergyConsumption("new energyConsumption value"); + assertEquals(Optional.of("new energyConsumption value"), testAIPackage.getEnergyConsumption()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getMetric}. + */ + public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); +// testAIPackage.getMetrics().clear(); +// testAIPackage.getMetrics().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); fail("Not yet implemented"); } @@ -255,37 +256,26 @@ public void testAIPackagegetMetricDecisionThresholds() throws InvalidSPDXAnalysi } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getMetric}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getHyperparameter}. */ - public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { + public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); -// testAIPackage.getMetrics().clear(); -// testAIPackage.getMetrics().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); +// testAIPackage.getHyperparameters().clear(); +// testAIPackage.getHyperparameters().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getTypeOfModels}. - */ - public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getTypeOfModels()))); - testAIPackage.getTypeOfModels().clear(); - testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); - } - - /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getModelDataPreprocessings}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getDomains}. */ - public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysisException { + public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); - testAIPackage.getModelDataPreprocessings().clear(); - testAIPackage.getModelDataPreprocessings().addAll(MODEL_DATA_PREPROCESSING_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getDomains()))); + testAIPackage.getDomains().clear(); + testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); } /** @@ -311,13 +301,24 @@ public void testAIPackagegetModelExplainabilitys() throws InvalidSPDXAnalysisExc } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getDomains}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getTypeOfModels}. */ - public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { + public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getDomains()))); - testAIPackage.getDomains().clear(); - testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getTypeOfModels()))); + testAIPackage.getTypeOfModels().clear(); + testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); + } + + /** + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getModelDataPreprocessings}. + */ + public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysisException { + AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); + testAIPackage.getModelDataPreprocessings().clear(); + testAIPackage.getModelDataPreprocessings().addAll(MODEL_DATA_PREPROCESSING_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/build/BuildTest.java b/src/test/java/org/spdx/library/model/v3/build/BuildTest.java index edf382087..fe7d27cbc 100644 --- a/src/test/java/org/spdx/library/model/v3/build/BuildTest.java +++ b/src/test/java/org/spdx/library/model/v3/build/BuildTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -43,6 +43,8 @@ public class BuildTest extends TestCase { ModelCopyManager copyManager; static final String BUILD_TYPE_TEST_VALUE = "test buildType"; + static final String BUILD_END_TIME_TEST_VALUE = "test buildEndTime"; + static final String BUILD_START_TIME_TEST_VALUE = "test buildStartTime"; static final String BUILD_ID_TEST_VALUE = "test buildId"; static final String CONFIG_SOURCE_URI_TEST_VALUE1 = "test 1 configSourceUri"; static final String CONFIG_SOURCE_URI_TEST_VALUE2 = "test 2 configSourceUri"; @@ -69,6 +71,8 @@ public static BuildBuilder builderForBuildTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { BuildBuilder retval = new BuildBuilder(modelStore, objectUri, copyManager) .setBuildType(BUILD_TYPE_TEST_VALUE) + .setBuildEndTime(BUILD_END_TIME_TEST_VALUE) + .setBuildStartTime(BUILD_START_TIME_TEST_VALUE) .setBuildId(BUILD_ID_TEST_VALUE) .addConfigSourceUri(CONFIG_SOURCE_URI_TEST_VALUE1) .addConfigSourceUri(CONFIG_SOURCE_URI_TEST_VALUE2) @@ -76,11 +80,9 @@ public static BuildBuilder builderForBuildTests( .addConfigSourceEntrypoint(CONFIG_SOURCE_ENTRYPOINT_TEST_VALUE2) //TODO: Add in test values /******************** - .setBuildEndTime(new DateTime()) - .setBuildStartTime(new DateTime()) + .addEnvironment(DictionaryEntry) .addConfigSourceDigest(Hash) .addParameters(DictionaryEntry) - .addEnvironment(DictionaryEntry) ***************/ ; return retval; @@ -129,35 +131,33 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildEndTime}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildType}. */ - public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { + public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testBuild.getBuildEndTime()); -// testBuild.setBuildEndTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testBuild.getBuildEndTime()); - fail("Not yet implemented"); + assertEquals(BUILD_TYPE_TEST_VALUE, testBuild.getBuildType()); + testBuild.setBuildType("new buildType value"); + assertEquals("new buildType value", testBuild.getBuildType()); } /** - * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildStartTime}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildEndTime}. */ - public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { + public void testBuildsetBuildEndTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testBuild.getBuildStartTime()); -// testBuild.setBuildStartTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testBuild.getBuildStartTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(BUILD_END_TIME_TEST_VALUE), testBuild.getBuildEndTime()); + testBuild.setBuildEndTime("new buildEndTime value"); + assertEquals(Optional.of("new buildEndTime value"), testBuild.getBuildEndTime()); } /** - * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildType}. + * Test method for {@link org.spdx.library.model.v3.build.Build#setBuildStartTime}. */ - public void testBuildsetBuildType() throws InvalidSPDXAnalysisException { + public void testBuildsetBuildStartTime() throws InvalidSPDXAnalysisException { Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BUILD_TYPE_TEST_VALUE, testBuild.getBuildType()); - testBuild.setBuildType("new buildType value"); - assertEquals("new buildType value", testBuild.getBuildType()); + assertEquals(Optional.of(BUILD_START_TIME_TEST_VALUE), testBuild.getBuildStartTime()); + testBuild.setBuildStartTime("new buildStartTime value"); + assertEquals(Optional.of("new buildStartTime value"), testBuild.getBuildStartTime()); } /** @@ -170,6 +170,18 @@ public void testBuildsetBuildId() throws InvalidSPDXAnalysisException { assertEquals(Optional.of("new buildId value"), testBuild.getBuildId()); } + /** + * Test method for {@link org.spdx.library.model.v3.build.Build#getEnvironment}. + */ + public void testBuildgetEnvironments() throws InvalidSPDXAnalysisException { + Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getEnvironments()))); +// testBuild.getEnvironments().clear(); +// testBuild.getEnvironments().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getEnvironments()))); + fail("Not yet implemented"); + } + /** * Test method for {@link org.spdx.library.model.v3.build.Build#getConfigSourceDigest}. */ @@ -194,18 +206,6 @@ public void testBuildgetParameterss() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } - /** - * Test method for {@link org.spdx.library.model.v3.build.Build#getEnvironment}. - */ - public void testBuildgetEnvironments() throws InvalidSPDXAnalysisException { - Build testBuild = builderForBuildTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testBuild.getEnvironments()))); -// testBuild.getEnvironments().clear(); -// testBuild.getEnvironments().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testBuild.getEnvironments()))); - fail("Not yet implemented"); - } - /** * Test method for {@link org.spdx.library.model.v3.build.Build#getConfigSourceUris}. */ diff --git a/src/test/java/org/spdx/library/model/v3/core/AgentTest.java b/src/test/java/org/spdx/library/model/v3/core/AgentTest.java index 1a4bad5d1..64c94bed6 100644 --- a/src/test/java/org/spdx/library/model/v3/core/AgentTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/AgentTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java b/src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java index 11f83e0d8..ab12a94bc 100644 --- a/src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/AnnotationTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -45,6 +45,11 @@ public class AnnotationTest extends TestCase { static final String STATEMENT_TEST_VALUE = "test statement"; static final AnnotationType ANNOTATION_TYPE_TEST_VALUE1 = AnnotationType.values()[0]; static final AnnotationType ANNOTATION_TYPE_TEST_VALUE2 = AnnotationType.values()[1]; + static final String CONTENT_TYPE_TEST_VALUE1 = "test 1 contentType"; + static final String CONTENT_TYPE_TEST_VALUE2 = "test 2 contentType"; + static final String CONTENT_TYPE_TEST_VALUE3 = "test 3 contentType"; + static final List CONTENT_TYPE_TEST_LIST1 = Arrays.asList(new String[] { CONTENT_TYPE_TEST_VALUE1, CONTENT_TYPE_TEST_VALUE2 }); + static final List CONTENT_TYPE_TEST_LIST2 = Arrays.asList(new String[] { CONTENT_TYPE_TEST_VALUE3 }); protected void setUp() throws Exception { super.setUp(); @@ -60,11 +65,12 @@ public static AnnotationBuilder builderForAnnotationTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { AnnotationBuilder retval = new AnnotationBuilder(modelStore, objectUri, copyManager) .setStatement(STATEMENT_TEST_VALUE) + .addContentType(CONTENT_TYPE_TEST_VALUE1) + .addContentType(CONTENT_TYPE_TEST_VALUE2) .setAnnotationType(ANNOTATION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** .setSubject(new Element()) - .addContentType(MediaType) ***************/ ; return retval; @@ -144,14 +150,13 @@ public void testAnnotationsetStatement() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.core.Annotation#getContentType}. + * Test method for {@link org.spdx.library.model.v3.core.Annotation#getContentTypes}. */ public void testAnnotationgetContentTypes() throws InvalidSPDXAnalysisException { Annotation testAnnotation = builderForAnnotationTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAnnotation.getContentTypes()))); -// testAnnotation.getContentTypes().clear(); -// testAnnotation.getContentTypes().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testAnnotation.getContentTypes()))); - fail("Not yet implemented"); + assertTrue(UnitTestHelper.isListsEqual(CONTENT_TYPE_TEST_LIST1, new ArrayList<>(testAnnotation.getContentTypes()))); + testAnnotation.getContentTypes().clear(); + testAnnotation.getContentTypes().addAll(CONTENT_TYPE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(CONTENT_TYPE_TEST_LIST2, new ArrayList<>(testAnnotation.getContentTypes()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java b/src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java index 017b2c439..92281a62a 100644 --- a/src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ArtifactTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,6 +42,9 @@ public class ArtifactTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String VALID_UNTIL_TIME_TEST_VALUE = "test validUntilTime"; + static final String BUILT_TIME_TEST_VALUE = "test builtTime"; + static final String RELEASE_TIME_TEST_VALUE = "test releaseTime"; static final String STANDARD_TEST_VALUE1 = "test 1 standard"; static final String STANDARD_TEST_VALUE2 = "test 2 standard"; static final String STANDARD_TEST_VALUE3 = "test 3 standard"; @@ -61,14 +64,14 @@ protected void tearDown() throws Exception { public static ArtifactBuilder builderForArtifactTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ArtifactBuilder retval = new ArtifactBuilder(modelStore, objectUri, copyManager) + .setValidUntilTime(VALID_UNTIL_TIME_TEST_VALUE) + .setBuiltTime(BUILT_TIME_TEST_VALUE) + .setReleaseTime(RELEASE_TIME_TEST_VALUE) .addStandard(STANDARD_TEST_VALUE1) .addStandard(STANDARD_TEST_VALUE2) //TODO: Add in test values /******************** - .setValidUntilTime(new DateTime()) - .setReleaseTime(new DateTime()) - .setBuiltTime(new DateTime()) - .addSuppliedBy(Agent) + .setSuppliedBy(new Agent()) .addOriginatedBy(Agent) ***************/ ; @@ -118,25 +121,24 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.core.Artifact#setValidUntilTime}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#setSuppliedBy}. */ - public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException { + public void testArtifactsetSuppliedBy() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testArtifact.getValidUntilTime()); -// testArtifact.setValidUntilTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getValidUntilTime()); +// assertEquals(Optional.of(TEST_VALUE), testArtifact.getSuppliedBy()); +// testArtifact.setSuppliedBy(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getSuppliedBy()); fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.v3.core.Artifact#setReleaseTime}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#setValidUntilTime}. */ - public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { + public void testArtifactsetValidUntilTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testArtifact.getReleaseTime()); -// testArtifact.setReleaseTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getReleaseTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(VALID_UNTIL_TIME_TEST_VALUE), testArtifact.getValidUntilTime()); + testArtifact.setValidUntilTime("new validUntilTime value"); + assertEquals(Optional.of("new validUntilTime value"), testArtifact.getValidUntilTime()); } /** @@ -144,22 +146,19 @@ public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { */ public void testArtifactsetBuiltTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testArtifact.getBuiltTime()); -// testArtifact.setBuiltTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testArtifact.getBuiltTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(BUILT_TIME_TEST_VALUE), testArtifact.getBuiltTime()); + testArtifact.setBuiltTime("new builtTime value"); + assertEquals(Optional.of("new builtTime value"), testArtifact.getBuiltTime()); } /** - * Test method for {@link org.spdx.library.model.v3.core.Artifact#getSuppliedBy}. + * Test method for {@link org.spdx.library.model.v3.core.Artifact#setReleaseTime}. */ - public void testArtifactgetSuppliedBys() throws InvalidSPDXAnalysisException { + public void testArtifactsetReleaseTime() throws InvalidSPDXAnalysisException { Artifact testArtifact = builderForArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBys()))); -// testArtifact.getSuppliedBys().clear(); -// testArtifact.getSuppliedBys().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testArtifact.getSuppliedBys()))); - fail("Not yet implemented"); + assertEquals(Optional.of(RELEASE_TIME_TEST_VALUE), testArtifact.getReleaseTime()); + testArtifact.setReleaseTime("new releaseTime value"); + assertEquals(Optional.of("new releaseTime value"), testArtifact.getReleaseTime()); } /** diff --git a/src/test/java/org/spdx/library/model/v3/core/BomTest.java b/src/test/java/org/spdx/library/model/v3/core/BomTest.java index 9241b8a61..a2e674a06 100644 --- a/src/test/java/org/spdx/library/model/v3/core/BomTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/BomTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/BundleTest.java b/src/test/java/org/spdx/library/model/v3/core/BundleTest.java index c4dec3092..b1c6a14be 100644 --- a/src/test/java/org/spdx/library/model/v3/core/BundleTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/BundleTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java b/src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java index f4b9ae75c..0ff30253c 100644 --- a/src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/CreationInfoTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,8 +42,10 @@ public class CreationInfoTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String DATA_LICENSE_TEST_VALUE = "test dataLicense"; + static final String SPEC_VERSION_TEST_VALUE = "test specVersion"; static final String COMMENT_TEST_VALUE = "test comment"; + static final String DATA_LICENSE_TEST_VALUE = "test dataLicense"; + static final String CREATED_TEST_VALUE = "test created"; static final ProfileIdentifierType PROFILE_TEST_VALUE1 = ProfileIdentifierType.values()[0]; static final ProfileIdentifierType PROFILE_TEST_VALUE2 = ProfileIdentifierType.values()[1]; static final List PROFILE_TEST_LIST1 = Arrays.asList(new ProfileIdentifierType[] { PROFILE_TEST_VALUE1, PROFILE_TEST_VALUE2 }); @@ -62,14 +64,14 @@ protected void tearDown() throws Exception { public static CreationInfoBuilder builderForCreationInfoTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { CreationInfoBuilder retval = new CreationInfoBuilder(modelStore, objectUri, copyManager) - .setDataLicense(DATA_LICENSE_TEST_VALUE) + .setSpecVersion(SPEC_VERSION_TEST_VALUE) .setComment(COMMENT_TEST_VALUE) + .setDataLicense(DATA_LICENSE_TEST_VALUE) + .setCreated(CREATED_TEST_VALUE) .addProfile(PROFILE_TEST_VALUE1) .addProfile(PROFILE_TEST_VALUE2) //TODO: Add in test values /******************** - .setCreated(new DateTime()) - .setSpecVersion(new SemVer()) .addCreatedBy(Agent) .addCreatedUsing(Tool) ***************/ @@ -120,25 +122,23 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setCreated}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setSpecVersion}. */ - public void testCreationInfosetCreated() throws InvalidSPDXAnalysisException { + public void testCreationInfosetSpecVersion() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testCreationInfo.getCreated()); -// testCreationInfo.setCreated(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testCreationInfo.getCreated()); - fail("Not yet implemented"); + assertEquals(SPEC_VERSION_TEST_VALUE, testCreationInfo.getSpecVersion()); + testCreationInfo.setSpecVersion("new specVersion value"); + assertEquals("new specVersion value", testCreationInfo.getSpecVersion()); } /** - * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setSpecVersion}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setComment}. */ - public void testCreationInfosetSpecVersion() throws InvalidSPDXAnalysisException { + public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(TEST_VALUE, testCreationInfo.getSpecVersion()); -// testCreationInfo.setSpecVersion(NEW_TEST_VALUE); -// assertEquals(NEW_TEST_VALUE, testCreationInfo.getSpecVersion()); - fail("Not yet implemented"); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testCreationInfo.getComment()); + testCreationInfo.setComment("new comment value"); + assertEquals(Optional.of("new comment value"), testCreationInfo.getComment()); } /** @@ -146,19 +146,19 @@ public void testCreationInfosetSpecVersion() throws InvalidSPDXAnalysisException */ public void testCreationInfosetDataLicense() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DATA_LICENSE_TEST_VALUE), testCreationInfo.getDataLicense()); + assertEquals(DATA_LICENSE_TEST_VALUE, testCreationInfo.getDataLicense()); testCreationInfo.setDataLicense("new dataLicense value"); - assertEquals(Optional.of("new dataLicense value"), testCreationInfo.getDataLicense()); + assertEquals("new dataLicense value", testCreationInfo.getDataLicense()); } /** - * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setComment}. + * Test method for {@link org.spdx.library.model.v3.core.CreationInfo#setCreated}. */ - public void testCreationInfosetComment() throws InvalidSPDXAnalysisException { + public void testCreationInfosetCreated() throws InvalidSPDXAnalysisException { CreationInfo testCreationInfo = builderForCreationInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(COMMENT_TEST_VALUE), testCreationInfo.getComment()); - testCreationInfo.setComment("new comment value"); - assertEquals(Optional.of("new comment value"), testCreationInfo.getComment()); + assertEquals(CREATED_TEST_VALUE, testCreationInfo.getCreated()); + testCreationInfo.setCreated("new created value"); + assertEquals("new created value", testCreationInfo.getCreated()); } /** diff --git a/src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java b/src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java index b192195b9..da1bfde14 100644 --- a/src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/DictionaryEntryTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,8 +42,8 @@ public class DictionaryEntryTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String KEY_TEST_VALUE = "test key"; static final String VALUE_TEST_VALUE = "test value"; + static final String KEY_TEST_VALUE = "test key"; protected void setUp() throws Exception { super.setUp(); @@ -58,8 +58,8 @@ protected void tearDown() throws Exception { public static DictionaryEntryBuilder builderForDictionaryEntryTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { DictionaryEntryBuilder retval = new DictionaryEntryBuilder(modelStore, objectUri, copyManager) - .setKey(KEY_TEST_VALUE) .setValue(VALUE_TEST_VALUE) + .setKey(KEY_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -109,16 +109,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#setKey}. - */ - public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { - DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(KEY_TEST_VALUE, testDictionaryEntry.getKey()); - testDictionaryEntry.setKey("new key value"); - assertEquals("new key value", testDictionaryEntry.getKey()); - } - /** * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#setValue}. */ @@ -128,4 +118,14 @@ public void testDictionaryEntrysetValue() throws InvalidSPDXAnalysisException { testDictionaryEntry.setValue("new value value"); assertEquals(Optional.of("new value value"), testDictionaryEntry.getValue()); } + + /** + * Test method for {@link org.spdx.library.model.v3.core.DictionaryEntry#setKey}. + */ + public void testDictionaryEntrysetKey() throws InvalidSPDXAnalysisException { + DictionaryEntry testDictionaryEntry = builderForDictionaryEntryTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(KEY_TEST_VALUE, testDictionaryEntry.getKey()); + testDictionaryEntry.setKey("new key value"); + assertEquals("new key value", testDictionaryEntry.getKey()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java b/src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java index 5adc3f0d7..2b5f0501a 100644 --- a/src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ElementCollectionTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -59,8 +59,8 @@ public static ElementCollectionBuilder builderForElementCollectionTests( //TODO: Add in test values /******************** .addImports(ExternalMap) - .addRootElement(Element) .addElement(Element) + .addRootElement(Element) ***************/ ; return retval; @@ -120,18 +120,6 @@ public void testElementCollectiongetImportss() throws InvalidSPDXAnalysisExcepti fail("Not yet implemented"); } - /** - * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getRootElement}. - */ - public void testElementCollectiongetRootElements() throws InvalidSPDXAnalysisException { - ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); -// testElementCollection.getRootElements().clear(); -// testElementCollection.getRootElements().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); - fail("Not yet implemented"); - } - /** * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getElement}. */ @@ -143,4 +131,16 @@ public void testElementCollectiongetElements() throws InvalidSPDXAnalysisExcepti // assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getElements()))); fail("Not yet implemented"); } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ElementCollection#getRootElement}. + */ + public void testElementCollectiongetRootElements() throws InvalidSPDXAnalysisException { + ElementCollection testElementCollection = builderForElementCollectionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); +// testElementCollection.getRootElements().clear(); +// testElementCollection.getRootElements().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElementCollection.getRootElements()))); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ElementTest.java b/src/test/java/org/spdx/library/model/v3/core/ElementTest.java index 3dc7d6a54..dffb9e8f0 100644 --- a/src/test/java/org/spdx/library/model/v3/core/ElementTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ElementTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,10 +42,10 @@ public class ElementTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String SUMMARY_TEST_VALUE = "test summary"; + static final String DESCRIPTION_TEST_VALUE = "test description"; static final String COMMENT_TEST_VALUE = "test comment"; static final String NAME_TEST_VALUE = "test name"; - static final String DESCRIPTION_TEST_VALUE = "test description"; - static final String SUMMARY_TEST_VALUE = "test summary"; protected void setUp() throws Exception { super.setUp(); @@ -60,16 +60,17 @@ protected void tearDown() throws Exception { public static ElementBuilder builderForElementTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ElementBuilder retval = new ElementBuilder(modelStore, objectUri, copyManager) + .setSummary(SUMMARY_TEST_VALUE) + .setDescription(DESCRIPTION_TEST_VALUE) .setComment(COMMENT_TEST_VALUE) .setName(NAME_TEST_VALUE) - .setDescription(DESCRIPTION_TEST_VALUE) - .setSummary(SUMMARY_TEST_VALUE) //TODO: Add in test values /******************** .setCreationInfo(new CreationInfo()) + .addExternalRef(ExternalRef) + .addExtension(Extension) .addExternalIdentifier(ExternalIdentifier) .addVerifiedUsing(IntegrityMethod) - .addExternalReference(ExternalReference) ***************/ ; return retval; @@ -128,6 +129,26 @@ public void testElementsetCreationInfo() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } + /** + * Test method for {@link org.spdx.library.model.v3.core.Element#setSummary}. + */ + public void testElementsetSummary() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(SUMMARY_TEST_VALUE), testElement.getSummary()); + testElement.setSummary("new summary value"); + assertEquals(Optional.of("new summary value"), testElement.getSummary()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Element#setDescription}. + */ + public void testElementsetDescription() throws InvalidSPDXAnalysisException { + Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(DESCRIPTION_TEST_VALUE), testElement.getDescription()); + testElement.setDescription("new description value"); + assertEquals(Optional.of("new description value"), testElement.getDescription()); + } + /** * Test method for {@link org.spdx.library.model.v3.core.Element#setComment}. */ @@ -149,23 +170,27 @@ public void testElementsetName() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.core.Element#setDescription}. + * Test method for {@link org.spdx.library.model.v3.core.Element#getExternalRef}. */ - public void testElementsetDescription() throws InvalidSPDXAnalysisException { + public void testElementgetExternalRefs() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DESCRIPTION_TEST_VALUE), testElement.getDescription()); - testElement.setDescription("new description value"); - assertEquals(Optional.of("new description value"), testElement.getDescription()); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalRefs()))); +// testElement.getExternalRefs().clear(); +// testElement.getExternalRefs().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalRefs()))); + fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.v3.core.Element#setSummary}. + * Test method for {@link org.spdx.library.model.v3.core.Element#getExtension}. */ - public void testElementsetSummary() throws InvalidSPDXAnalysisException { + public void testElementgetExtensions() throws InvalidSPDXAnalysisException { Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SUMMARY_TEST_VALUE), testElement.getSummary()); - testElement.setSummary("new summary value"); - assertEquals(Optional.of("new summary value"), testElement.getSummary()); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExtensions()))); +// testElement.getExtensions().clear(); +// testElement.getExtensions().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExtensions()))); + fail("Not yet implemented"); } /** @@ -191,16 +216,4 @@ public void testElementgetVerifiedUsings() throws InvalidSPDXAnalysisException { // assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getVerifiedUsings()))); fail("Not yet implemented"); } - - /** - * Test method for {@link org.spdx.library.model.v3.core.Element#getExternalReference}. - */ - public void testElementgetExternalReferences() throws InvalidSPDXAnalysisException { - Element testElement = builderForElementTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); -// testElement.getExternalReferences().clear(); -// testElement.getExternalReferences().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testElement.getExternalReferences()))); - fail("Not yet implemented"); - } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ExtensionTest.java b/src/test/java/org/spdx/library/model/v3/core/ExtensionTest.java new file mode 100644 index 000000000..a9d1fa220 --- /dev/null +++ b/src/test/java/org/spdx/library/model/v3/core/ExtensionTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.v3.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v3.core.Extension.ExtensionBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExtensionTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + + IModelStore modelStore; + ModelCopyManager copyManager; + + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExtensionBuilder builderForExtensionTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExtensionBuilder retval = new ExtensionBuilder(modelStore, objectUri, copyManager) + //TODO: Add in test values + /******************** + ***************/ + ; + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Extension#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + Extension testExtension = builderForExtensionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExtension.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Extension#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + Extension testExtension = builderForExtensionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.Extension", testExtension.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Extension#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + Extension testExtension = builderForExtensionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Extension: "+TEST_OBJECT_URI, testExtension.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Extension#Element(org.spdx.library.model.v3.core.Extension.ExtensionBuilder)}. + */ + public void testExtensionExtensionBuilder() throws InvalidSPDXAnalysisException { + builderForExtensionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + Extension testExtension = builderForExtensionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + Extension test2Extension = builderForExtensionTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExtension.equivalent(test2Extension)); + assertTrue(test2Extension.equivalent(testExtension)); + // TODO change some parameters for negative tests + } +} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java index 3d0796697..0e415d92c 100644 --- a/src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ExternalIdentifierTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -43,8 +43,8 @@ public class ExternalIdentifierTest extends TestCase { ModelCopyManager copyManager; static final String COMMENT_TEST_VALUE = "test comment"; - static final String IDENTIFIER_TEST_VALUE = "test identifier"; static final String ISSUING_AUTHORITY_TEST_VALUE = "test issuingAuthority"; + static final String IDENTIFIER_TEST_VALUE = "test identifier"; static final ExternalIdentifierType EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1 = ExternalIdentifierType.values()[0]; static final ExternalIdentifierType EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE2 = ExternalIdentifierType.values()[1]; static final String IDENTIFIER_LOCATOR_TEST_VALUE1 = "test 1 identifierLocator"; @@ -67,8 +67,8 @@ public static ExternalIdentifierBuilder builderForExternalIdentifierTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ExternalIdentifierBuilder retval = new ExternalIdentifierBuilder(modelStore, objectUri, copyManager) .setComment(COMMENT_TEST_VALUE) - .setIdentifier(IDENTIFIER_TEST_VALUE) .setIssuingAuthority(ISSUING_AUTHORITY_TEST_VALUE) + .setIdentifier(IDENTIFIER_TEST_VALUE) .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE1) .addIdentifierLocator(IDENTIFIER_LOCATOR_TEST_VALUE2) .setExternalIdentifierType(EXTERNAL_IDENTIFIER_TYPE_TEST_VALUE1) @@ -141,16 +141,6 @@ public void testExternalIdentifiersetComment() throws InvalidSPDXAnalysisExcepti assertEquals(Optional.of("new comment value"), testExternalIdentifier.getComment()); } - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setIdentifier}. - */ - public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisException { - ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(IDENTIFIER_TEST_VALUE, testExternalIdentifier.getIdentifier()); - testExternalIdentifier.setIdentifier("new identifier value"); - assertEquals("new identifier value", testExternalIdentifier.getIdentifier()); - } - /** * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setIssuingAuthority}. */ @@ -161,6 +151,16 @@ public void testExternalIdentifiersetIssuingAuthority() throws InvalidSPDXAnalys assertEquals(Optional.of("new issuingAuthority value"), testExternalIdentifier.getIssuingAuthority()); } + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#setIdentifier}. + */ + public void testExternalIdentifiersetIdentifier() throws InvalidSPDXAnalysisException { + ExternalIdentifier testExternalIdentifier = builderForExternalIdentifierTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(IDENTIFIER_TEST_VALUE, testExternalIdentifier.getIdentifier()); + testExternalIdentifier.setIdentifier("new identifier value"); + assertEquals("new identifier value", testExternalIdentifier.getIdentifier()); + } + /** * Test method for {@link org.spdx.library.model.v3.core.ExternalIdentifier#getIdentifierLocators}. */ diff --git a/src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java index 810aac1da..8aa1323d6 100644 --- a/src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ExternalMapTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,8 +42,8 @@ public class ExternalMapTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String EXTERNAL_ID_TEST_VALUE = "test externalId"; static final String DEFINING_DOCUMENT_TEST_VALUE = "test definingDocument"; + static final String EXTERNAL_ID_TEST_VALUE = "test externalId"; static final String LOCATION_HINT_TEST_VALUE = "test locationHint"; protected void setUp() throws Exception { @@ -59,8 +59,8 @@ protected void tearDown() throws Exception { public static ExternalMapBuilder builderForExternalMapTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ExternalMapBuilder retval = new ExternalMapBuilder(modelStore, objectUri, copyManager) - .setExternalId(EXTERNAL_ID_TEST_VALUE) .setDefiningDocument(DEFINING_DOCUMENT_TEST_VALUE) + .setExternalId(EXTERNAL_ID_TEST_VALUE) .setLocationHint(LOCATION_HINT_TEST_VALUE) //TODO: Add in test values /******************** @@ -112,16 +112,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setExternalId}. - */ - public void testExternalMapsetExternalId() throws InvalidSPDXAnalysisException { - ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(EXTERNAL_ID_TEST_VALUE, testExternalMap.getExternalId()); - testExternalMap.setExternalId("new externalId value"); - assertEquals("new externalId value", testExternalMap.getExternalId()); - } - /** * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setDefiningDocument}. */ @@ -132,6 +122,16 @@ public void testExternalMapsetDefiningDocument() throws InvalidSPDXAnalysisExcep assertEquals(Optional.of("new definingDocument value"), testExternalMap.getDefiningDocument()); } + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setExternalId}. + */ + public void testExternalMapsetExternalId() throws InvalidSPDXAnalysisException { + ExternalMap testExternalMap = builderForExternalMapTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(EXTERNAL_ID_TEST_VALUE, testExternalMap.getExternalId()); + testExternalMap.setExternalId("new externalId value"); + assertEquals("new externalId value", testExternalMap.getExternalId()); + } + /** * Test method for {@link org.spdx.library.model.v3.core.ExternalMap#setLocationHint}. */ diff --git a/src/test/java/org/spdx/library/model/v3/core/ExternalRefTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalRefTest.java new file mode 100644 index 000000000..3174700e7 --- /dev/null +++ b/src/test/java/org/spdx/library/model/v3/core/ExternalRefTest.java @@ -0,0 +1,162 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.v3.core; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v3.core.ExternalRef.ExternalRefBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class ExternalRefTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + + IModelStore modelStore; + ModelCopyManager copyManager; + + static final String COMMENT_TEST_VALUE = "test comment"; + static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; + static final ExternalRefType EXTERNAL_REF_TYPE_TEST_VALUE1 = ExternalRefType.values()[0]; + static final ExternalRefType EXTERNAL_REF_TYPE_TEST_VALUE2 = ExternalRefType.values()[1]; + static final String LOCATOR_TEST_VALUE1 = "test 1 locator"; + static final String LOCATOR_TEST_VALUE2 = "test 2 locator"; + static final String LOCATOR_TEST_VALUE3 = "test 3 locator"; + static final List LOCATOR_TEST_LIST1 = Arrays.asList(new String[] { LOCATOR_TEST_VALUE1, LOCATOR_TEST_VALUE2 }); + static final List LOCATOR_TEST_LIST2 = Arrays.asList(new String[] { LOCATOR_TEST_VALUE3 }); + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static ExternalRefBuilder builderForExternalRefTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + ExternalRefBuilder retval = new ExternalRefBuilder(modelStore, objectUri, copyManager) + .setComment(COMMENT_TEST_VALUE) + .setContentType(CONTENT_TYPE_TEST_VALUE) + .addLocator(LOCATOR_TEST_VALUE1) + .addLocator(LOCATOR_TEST_VALUE2) + .setExternalRefType(EXTERNAL_REF_TYPE_TEST_VALUE1) + //TODO: Add in test values + /******************** + ***************/ + ; + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testExternalRef.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("Core.ExternalRef", testExternalRef.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("ExternalRef: "+TEST_OBJECT_URI, testExternalRef.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#Element(org.spdx.library.model.v3.core.ExternalRef.ExternalRefBuilder)}. + */ + public void testExternalRefExternalRefBuilder() throws InvalidSPDXAnalysisException { + builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + ExternalRef test2ExternalRef = builderForExternalRefTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testExternalRef.equivalent(test2ExternalRef)); + assertTrue(test2ExternalRef.equivalent(testExternalRef)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#setExternalRefType}. + */ + public void testExternalRefsetExternalRefType() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(EXTERNAL_REF_TYPE_TEST_VALUE1), testExternalRef.getExternalRefType()); + testExternalRef.setExternalRefType(EXTERNAL_REF_TYPE_TEST_VALUE2); + assertEquals(Optional.of(EXTERNAL_REF_TYPE_TEST_VALUE2), testExternalRef.getExternalRefType()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#setComment}. + */ + public void testExternalRefsetComment() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(COMMENT_TEST_VALUE), testExternalRef.getComment()); + testExternalRef.setComment("new comment value"); + assertEquals(Optional.of("new comment value"), testExternalRef.getComment()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#setContentType}. + */ + public void testExternalRefsetContentType() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(CONTENT_TYPE_TEST_VALUE), testExternalRef.getContentType()); + testExternalRef.setContentType("new contentType value"); + assertEquals(Optional.of("new contentType value"), testExternalRef.getContentType()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.ExternalRef#getLocators}. + */ + public void testExternalRefgetLocators() throws InvalidSPDXAnalysisException { + ExternalRef testExternalRef = builderForExternalRefTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST1, new ArrayList<>(testExternalRef.getLocators()))); + testExternalRef.getLocators().clear(); + testExternalRef.getLocators().addAll(LOCATOR_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST2, new ArrayList<>(testExternalRef.getLocators()))); + } +} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java b/src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java deleted file mode 100644 index c0390060f..000000000 --- a/src/test/java/org/spdx/library/model/v3/core/ExternalReferenceTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.library.model.v3.core; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.core.ExternalReference.ExternalReferenceBuilder; -import org.spdx.storage.IModelStore; -import org.spdx.storage.simple.InMemSpdxStore; -import org.spdx.utility.compare.UnitTestHelper; - -import junit.framework.TestCase; - -public class ExternalReferenceTest extends TestCase { - - static final String TEST_OBJECT_URI = "https://test.uri/testuri"; - - - IModelStore modelStore; - ModelCopyManager copyManager; - - static final String COMMENT_TEST_VALUE = "test comment"; - static final ExternalReferenceType EXTERNAL_REFERENCE_TYPE_TEST_VALUE1 = ExternalReferenceType.values()[0]; - static final ExternalReferenceType EXTERNAL_REFERENCE_TYPE_TEST_VALUE2 = ExternalReferenceType.values()[1]; - static final String LOCATOR_TEST_VALUE1 = "test 1 locator"; - static final String LOCATOR_TEST_VALUE2 = "test 2 locator"; - static final String LOCATOR_TEST_VALUE3 = "test 3 locator"; - static final List LOCATOR_TEST_LIST1 = Arrays.asList(new String[] { LOCATOR_TEST_VALUE1, LOCATOR_TEST_VALUE2 }); - static final List LOCATOR_TEST_LIST2 = Arrays.asList(new String[] { LOCATOR_TEST_VALUE3 }); - - protected void setUp() throws Exception { - super.setUp(); - modelStore = new InMemSpdxStore(); - copyManager = new ModelCopyManager(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public static ExternalReferenceBuilder builderForExternalReferenceTests( - IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - ExternalReferenceBuilder retval = new ExternalReferenceBuilder(modelStore, objectUri, copyManager) - .setComment(COMMENT_TEST_VALUE) - .addLocator(LOCATOR_TEST_VALUE1) - .addLocator(LOCATOR_TEST_VALUE2) - .setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1) - //TODO: Add in test values - /******************** - .setContentType(new MediaType()) - ***************/ - ; - return retval; - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#verify()}. - * @throws InvalidSPDXAnalysisException on errors - */ - public void testVerify() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - List result = testExternalReference.verify(); - assertTrue(result.isEmpty()); - // TODO - add negative tests - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#getType()}. - */ - public void testGetType() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Core.ExternalReference", testExternalReference.getType()); - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#toString()}. - */ - public void testToString() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("ExternalReference: "+TEST_OBJECT_URI, testExternalReference.toString()); - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#Element(org.spdx.library.model.v3.core.ExternalReference.ExternalReferenceBuilder)}. - */ - public void testExternalReferenceExternalReferenceBuilder() throws InvalidSPDXAnalysisException { - builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - } - - public void testEquivalent() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - ExternalReference test2ExternalReference = builderForExternalReferenceTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); - assertTrue(testExternalReference.equivalent(test2ExternalReference)); - assertTrue(test2ExternalReference.equivalent(testExternalReference)); - // TODO change some parameters for negative tests - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#setContentType}. - */ - public void testExternalReferencesetContentType() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testExternalReference.getContentType()); -// testExternalReference.setContentType(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testExternalReference.getContentType()); - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#setExternalReferenceType}. - */ - public void testExternalReferencesetExternalReferenceType() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE1), testExternalReference.getExternalReferenceType()); - testExternalReference.setExternalReferenceType(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2); - assertEquals(Optional.of(EXTERNAL_REFERENCE_TYPE_TEST_VALUE2), testExternalReference.getExternalReferenceType()); - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#setComment}. - */ - public void testExternalReferencesetComment() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(COMMENT_TEST_VALUE), testExternalReference.getComment()); - testExternalReference.setComment("new comment value"); - assertEquals(Optional.of("new comment value"), testExternalReference.getComment()); - } - - /** - * Test method for {@link org.spdx.library.model.v3.core.ExternalReference#getLocators}. - */ - public void testExternalReferencegetLocators() throws InvalidSPDXAnalysisException { - ExternalReference testExternalReference = builderForExternalReferenceTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST1, new ArrayList<>(testExternalReference.getLocators()))); - testExternalReference.getLocators().clear(); - testExternalReference.getLocators().addAll(LOCATOR_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(LOCATOR_TEST_LIST2, new ArrayList<>(testExternalReference.getLocators()))); - } -} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/HashTest.java b/src/test/java/org/spdx/library/model/v3/core/HashTest.java index bfd1b2754..81c6cda12 100644 --- a/src/test/java/org/spdx/library/model/v3/core/HashTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/HashTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java b/src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java index b7c2b08ca..828adcbfe 100644 --- a/src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/IntegrityMethodTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java index c21264007..f8734fb4d 100644 --- a/src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/LifecycleScopedRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java b/src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java index 7d610fc4e..45eb0f503 100644 --- a/src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/OrganizationTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/PersonTest.java b/src/test/java/org/spdx/library/model/v3/core/PersonTest.java index bd12a4b8f..a0d0efbf0 100644 --- a/src/test/java/org/spdx/library/model/v3/core/PersonTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/PersonTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java b/src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java index 8ca56bf58..dceda9a6e 100644 --- a/src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/PositiveIntegerRangeTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,8 +42,8 @@ public class PositiveIntegerRangeTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final Integer BEGIN_TEST_VALUE = 55; static final Integer END_TEST_VALUE = 55; + static final Integer BEGIN_TEST_VALUE = 55; protected void setUp() throws Exception { super.setUp(); @@ -58,8 +58,8 @@ protected void tearDown() throws Exception { public static PositiveIntegerRangeBuilder builderForPositiveIntegerRangeTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { PositiveIntegerRangeBuilder retval = new PositiveIntegerRangeBuilder(modelStore, objectUri, copyManager) - .setBegin(BEGIN_TEST_VALUE) .setEnd(END_TEST_VALUE) + .setBegin(BEGIN_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -109,16 +109,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#setBegin}. - */ - public void testPositiveIntegerRangesetBegin() throws InvalidSPDXAnalysisException { - PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(BEGIN_TEST_VALUE, testPositiveIntegerRange.getBegin()); - testPositiveIntegerRange.setBegin(new Integer(653)); - assertEquals(new Integer(653), testPositiveIntegerRange.getBegin()); - } - /** * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#setEnd}. */ @@ -128,4 +118,14 @@ public void testPositiveIntegerRangesetEnd() throws InvalidSPDXAnalysisException testPositiveIntegerRange.setEnd(new Integer(653)); assertEquals(new Integer(653), testPositiveIntegerRange.getEnd()); } + + /** + * Test method for {@link org.spdx.library.model.v3.core.PositiveIntegerRange#setBegin}. + */ + public void testPositiveIntegerRangesetBegin() throws InvalidSPDXAnalysisException { + PositiveIntegerRange testPositiveIntegerRange = builderForPositiveIntegerRangeTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(BEGIN_TEST_VALUE, testPositiveIntegerRange.getBegin()); + testPositiveIntegerRange.setBegin(new Integer(653)); + assertEquals(new Integer(653), testPositiveIntegerRange.getBegin()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java b/src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java index f21808008..e7fce63f8 100644 --- a/src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/RelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,10 +42,12 @@ public class RelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE1 = RelationshipType.values()[0]; - static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE2 = RelationshipType.values()[1]; + static final String START_TIME_TEST_VALUE = "test startTime"; + static final String END_TIME_TEST_VALUE = "test endTime"; static final RelationshipCompleteness COMPLETENESS_TEST_VALUE1 = RelationshipCompleteness.values()[0]; static final RelationshipCompleteness COMPLETENESS_TEST_VALUE2 = RelationshipCompleteness.values()[1]; + static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE1 = RelationshipType.values()[0]; + static final RelationshipType RELATIONSHIP_TYPE_TEST_VALUE2 = RelationshipType.values()[1]; protected void setUp() throws Exception { super.setUp(); @@ -60,13 +62,13 @@ protected void tearDown() throws Exception { public static RelationshipBuilder builderForRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { RelationshipBuilder retval = new RelationshipBuilder(modelStore, objectUri, copyManager) - .setRelationshipType(RELATIONSHIP_TYPE_TEST_VALUE1) + .setStartTime(START_TIME_TEST_VALUE) + .setEndTime(END_TIME_TEST_VALUE) .setCompleteness(COMPLETENESS_TEST_VALUE1) + .setRelationshipType(RELATIONSHIP_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setEndTime(new DateTime()) .setFrom(new Element()) - .setStartTime(new DateTime()) .addTo(Element) ***************/ ; @@ -115,17 +117,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.core.Relationship#setEndTime}. - */ - public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { - Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testRelationship.getEndTime()); -// testRelationship.setEndTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testRelationship.getEndTime()); - fail("Not yet implemented"); - } - /** * Test method for {@link org.spdx.library.model.v3.core.Relationship#setFrom}. */ @@ -138,14 +129,13 @@ public void testRelationshipsetFrom() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.core.Relationship#setStartTime}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setCompleteness}. */ - public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { + public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testRelationship.getStartTime()); -// testRelationship.setStartTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testRelationship.getStartTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(COMPLETENESS_TEST_VALUE1), testRelationship.getCompleteness()); + testRelationship.setCompleteness(COMPLETENESS_TEST_VALUE2); + assertEquals(Optional.of(COMPLETENESS_TEST_VALUE2), testRelationship.getCompleteness()); } /** @@ -159,13 +149,23 @@ public void testRelationshipsetRelationshipType() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.v3.core.Relationship#setCompleteness}. + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setStartTime}. */ - public void testRelationshipsetCompleteness() throws InvalidSPDXAnalysisException { + public void testRelationshipsetStartTime() throws InvalidSPDXAnalysisException { Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(COMPLETENESS_TEST_VALUE1), testRelationship.getCompleteness()); - testRelationship.setCompleteness(COMPLETENESS_TEST_VALUE2); - assertEquals(Optional.of(COMPLETENESS_TEST_VALUE2), testRelationship.getCompleteness()); + assertEquals(Optional.of(START_TIME_TEST_VALUE), testRelationship.getStartTime()); + testRelationship.setStartTime("new startTime value"); + assertEquals(Optional.of("new startTime value"), testRelationship.getStartTime()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.core.Relationship#setEndTime}. + */ + public void testRelationshipsetEndTime() throws InvalidSPDXAnalysisException { + Relationship testRelationship = builderForRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(END_TIME_TEST_VALUE), testRelationship.getEndTime()); + testRelationship.setEndTime("new endTime value"); + assertEquals(Optional.of("new endTime value"), testRelationship.getEndTime()); } /** diff --git a/src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java b/src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java index 73ec5c0a5..1c22c73eb 100644 --- a/src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/SoftwareAgentTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java index 398e9bee3..79efce2bf 100644 --- a/src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/SpdxDocumentTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,7 +42,6 @@ public class SpdxDocumentTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String NAME_TEST_VALUE = "test name"; protected void setUp() throws Exception { super.setUp(); @@ -57,7 +56,6 @@ protected void tearDown() throws Exception { public static SpdxDocumentBuilder builderForSpdxDocumentTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SpdxDocumentBuilder retval = new SpdxDocumentBuilder(modelStore, objectUri, copyManager) - .setName(NAME_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -106,14 +104,4 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(test2SpdxDocument.equivalent(testSpdxDocument)); // TODO change some parameters for negative tests } - - /** - * Test method for {@link org.spdx.library.model.v3.core.SpdxDocument#setName}. - */ - public void testSpdxDocumentsetName() throws InvalidSPDXAnalysisException { - SpdxDocument testSpdxDocument = builderForSpdxDocumentTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(NAME_TEST_VALUE), testSpdxDocument.getName()); - testSpdxDocument.setName("new name value"); - assertEquals(Optional.of("new name value"), testSpdxDocument.getName()); - } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/core/ToolTest.java b/src/test/java/org/spdx/library/model/v3/core/ToolTest.java index 94be2f375..45a47cd4e 100644 --- a/src/test/java/org/spdx/library/model/v3/core/ToolTest.java +++ b/src/test/java/org/spdx/library/model/v3/core/ToolTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java b/src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java index 6deeda4e6..4f17a8ee5 100644 --- a/src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java +++ b/src/test/java/org/spdx/library/model/v3/dataset/DatasetTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -27,6 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v3.core.PresenceType; import org.spdx.library.model.v3.dataset.Dataset.DatasetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; @@ -43,29 +44,31 @@ public class DatasetTest extends TestCase { ModelCopyManager copyManager; static final Integer DATASET_SIZE_TEST_VALUE = 55; + static final String DATASET_UPDATE_MECHANISM_TEST_VALUE = "test datasetUpdateMechanism"; + static final String DATA_COLLECTION_PROCESS_TEST_VALUE = "test dataCollectionProcess"; static final String INTENDED_USE_TEST_VALUE = "test intendedUse"; static final String DATASET_NOISE_TEST_VALUE = "test datasetNoise"; - static final String DATA_COLLECTION_PROCESS_TEST_VALUE = "test dataCollectionProcess"; - static final String DATASET_UPDATE_MECHANISM_TEST_VALUE = "test datasetUpdateMechanism"; - static final ConfidentialityLevelType CONFIDENTIALITY_LEVEL_TEST_VALUE1 = ConfidentialityLevelType.values()[0]; - static final ConfidentialityLevelType CONFIDENTIALITY_LEVEL_TEST_VALUE2 = ConfidentialityLevelType.values()[1]; + static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1 = PresenceType.values()[0]; + static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2 = PresenceType.values()[1]; static final DatasetAvailabilityType DATASET_AVAILABILITY_TEST_VALUE1 = DatasetAvailabilityType.values()[0]; static final DatasetAvailabilityType DATASET_AVAILABILITY_TEST_VALUE2 = DatasetAvailabilityType.values()[1]; + static final ConfidentialityLevelType CONFIDENTIALITY_LEVEL_TEST_VALUE1 = ConfidentialityLevelType.values()[0]; + static final ConfidentialityLevelType CONFIDENTIALITY_LEVEL_TEST_VALUE2 = ConfidentialityLevelType.values()[1]; static final String ANONYMIZATION_METHOD_USED_TEST_VALUE1 = "test 1 anonymizationMethodUsed"; static final String ANONYMIZATION_METHOD_USED_TEST_VALUE2 = "test 2 anonymizationMethodUsed"; static final String ANONYMIZATION_METHOD_USED_TEST_VALUE3 = "test 3 anonymizationMethodUsed"; static final List ANONYMIZATION_METHOD_USED_TEST_LIST1 = Arrays.asList(new String[] { ANONYMIZATION_METHOD_USED_TEST_VALUE1, ANONYMIZATION_METHOD_USED_TEST_VALUE2 }); static final List ANONYMIZATION_METHOD_USED_TEST_LIST2 = Arrays.asList(new String[] { ANONYMIZATION_METHOD_USED_TEST_VALUE3 }); - static final String DATA_PREPROCESSING_TEST_VALUE1 = "test 1 dataPreprocessing"; - static final String DATA_PREPROCESSING_TEST_VALUE2 = "test 2 dataPreprocessing"; - static final String DATA_PREPROCESSING_TEST_VALUE3 = "test 3 dataPreprocessing"; - static final List DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { DATA_PREPROCESSING_TEST_VALUE1, DATA_PREPROCESSING_TEST_VALUE2 }); - static final List DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { DATA_PREPROCESSING_TEST_VALUE3 }); static final String KNOWN_BIAS_TEST_VALUE1 = "test 1 knownBias"; static final String KNOWN_BIAS_TEST_VALUE2 = "test 2 knownBias"; static final String KNOWN_BIAS_TEST_VALUE3 = "test 3 knownBias"; static final List KNOWN_BIAS_TEST_LIST1 = Arrays.asList(new String[] { KNOWN_BIAS_TEST_VALUE1, KNOWN_BIAS_TEST_VALUE2 }); static final List KNOWN_BIAS_TEST_LIST2 = Arrays.asList(new String[] { KNOWN_BIAS_TEST_VALUE3 }); + static final String DATA_PREPROCESSING_TEST_VALUE1 = "test 1 dataPreprocessing"; + static final String DATA_PREPROCESSING_TEST_VALUE2 = "test 2 dataPreprocessing"; + static final String DATA_PREPROCESSING_TEST_VALUE3 = "test 3 dataPreprocessing"; + static final List DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { DATA_PREPROCESSING_TEST_VALUE1, DATA_PREPROCESSING_TEST_VALUE2 }); + static final List DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { DATA_PREPROCESSING_TEST_VALUE3 }); static final DatasetType DATASET_TYPE_TEST_VALUE1 = DatasetType.values()[0]; static final DatasetType DATASET_TYPE_TEST_VALUE2 = DatasetType.values()[1]; static final List DATASET_TYPE_TEST_LIST1 = Arrays.asList(new DatasetType[] { DATASET_TYPE_TEST_VALUE1, DATASET_TYPE_TEST_VALUE2 }); @@ -85,23 +88,23 @@ public static DatasetBuilder builderForDatasetTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { DatasetBuilder retval = new DatasetBuilder(modelStore, objectUri, copyManager) .setDatasetSize(DATASET_SIZE_TEST_VALUE) + .setDatasetUpdateMechanism(DATASET_UPDATE_MECHANISM_TEST_VALUE) + .setDataCollectionProcess(DATA_COLLECTION_PROCESS_TEST_VALUE) .setIntendedUse(INTENDED_USE_TEST_VALUE) .setDatasetNoise(DATASET_NOISE_TEST_VALUE) - .setDataCollectionProcess(DATA_COLLECTION_PROCESS_TEST_VALUE) - .setDatasetUpdateMechanism(DATASET_UPDATE_MECHANISM_TEST_VALUE) .addAnonymizationMethodUsed(ANONYMIZATION_METHOD_USED_TEST_VALUE1) .addAnonymizationMethodUsed(ANONYMIZATION_METHOD_USED_TEST_VALUE2) - .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE1) - .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE2) .addKnownBias(KNOWN_BIAS_TEST_VALUE1) .addKnownBias(KNOWN_BIAS_TEST_VALUE2) - .setConfidentialityLevel(CONFIDENTIALITY_LEVEL_TEST_VALUE1) + .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE1) + .addDataPreprocessing(DATA_PREPROCESSING_TEST_VALUE2) + .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) .setDatasetAvailability(DATASET_AVAILABILITY_TEST_VALUE1) + .setConfidentialityLevel(CONFIDENTIALITY_LEVEL_TEST_VALUE1) .addDatasetType(DATASET_TYPE_TEST_VALUE1) .addDatasetType(DATASET_TYPE_TEST_VALUE2) //TODO: Add in test values /******************** - .setSensitivePersonalInformation(new PresenceType()) .addSensor(DictionaryEntry) ***************/ ; @@ -155,20 +158,9 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testDatasetsetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testDataset.getSensitivePersonalInformation()); -// testDataset.setSensitivePersonalInformation(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testDataset.getSensitivePersonalInformation()); - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setConfidentialityLevel}. - */ - public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisException { - Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(CONFIDENTIALITY_LEVEL_TEST_VALUE1), testDataset.getConfidentialityLevel()); - testDataset.setConfidentialityLevel(CONFIDENTIALITY_LEVEL_TEST_VALUE2); - assertEquals(Optional.of(CONFIDENTIALITY_LEVEL_TEST_VALUE2), testDataset.getConfidentialityLevel()); + assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1), testDataset.getSensitivePersonalInformation()); + testDataset.setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2); + assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2), testDataset.getSensitivePersonalInformation()); } /** @@ -182,33 +174,33 @@ public void testDatasetsetDatasetAvailability() throws InvalidSPDXAnalysisExcept } /** - * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetSize}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setConfidentialityLevel}. */ - public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { + public void testDatasetsetConfidentialityLevel() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DATASET_SIZE_TEST_VALUE), testDataset.getDatasetSize()); - testDataset.setDatasetSize(new Integer(653)); - assertEquals(Optional.of(new Integer(653)), testDataset.getDatasetSize()); + assertEquals(Optional.of(CONFIDENTIALITY_LEVEL_TEST_VALUE1), testDataset.getConfidentialityLevel()); + testDataset.setConfidentialityLevel(CONFIDENTIALITY_LEVEL_TEST_VALUE2); + assertEquals(Optional.of(CONFIDENTIALITY_LEVEL_TEST_VALUE2), testDataset.getConfidentialityLevel()); } /** - * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setIntendedUse}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetSize}. */ - public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { + public void testDatasetsetDatasetSize() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(INTENDED_USE_TEST_VALUE), testDataset.getIntendedUse()); - testDataset.setIntendedUse("new intendedUse value"); - assertEquals(Optional.of("new intendedUse value"), testDataset.getIntendedUse()); + assertEquals(Optional.of(DATASET_SIZE_TEST_VALUE), testDataset.getDatasetSize()); + testDataset.setDatasetSize(new Integer(653)); + assertEquals(Optional.of(new Integer(653)), testDataset.getDatasetSize()); } /** - * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetNoise}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetUpdateMechanism}. */ - public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { + public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DATASET_NOISE_TEST_VALUE), testDataset.getDatasetNoise()); - testDataset.setDatasetNoise("new datasetNoise value"); - assertEquals(Optional.of("new datasetNoise value"), testDataset.getDatasetNoise()); + assertEquals(Optional.of(DATASET_UPDATE_MECHANISM_TEST_VALUE), testDataset.getDatasetUpdateMechanism()); + testDataset.setDatasetUpdateMechanism("new datasetUpdateMechanism value"); + assertEquals(Optional.of("new datasetUpdateMechanism value"), testDataset.getDatasetUpdateMechanism()); } /** @@ -222,13 +214,23 @@ public void testDatasetsetDataCollectionProcess() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetUpdateMechanism}. + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setIntendedUse}. */ - public void testDatasetsetDatasetUpdateMechanism() throws InvalidSPDXAnalysisException { + public void testDatasetsetIntendedUse() throws InvalidSPDXAnalysisException { Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DATASET_UPDATE_MECHANISM_TEST_VALUE), testDataset.getDatasetUpdateMechanism()); - testDataset.setDatasetUpdateMechanism("new datasetUpdateMechanism value"); - assertEquals(Optional.of("new datasetUpdateMechanism value"), testDataset.getDatasetUpdateMechanism()); + assertEquals(Optional.of(INTENDED_USE_TEST_VALUE), testDataset.getIntendedUse()); + testDataset.setIntendedUse("new intendedUse value"); + assertEquals(Optional.of("new intendedUse value"), testDataset.getIntendedUse()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#setDatasetNoise}. + */ + public void testDatasetsetDatasetNoise() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(DATASET_NOISE_TEST_VALUE), testDataset.getDatasetNoise()); + testDataset.setDatasetNoise("new datasetNoise value"); + assertEquals(Optional.of("new datasetNoise value"), testDataset.getDatasetNoise()); } /** @@ -254,17 +256,6 @@ public void testDatasetgetAnonymizationMethodUseds() throws InvalidSPDXAnalysisE assertTrue(UnitTestHelper.isListsEqual(ANONYMIZATION_METHOD_USED_TEST_LIST2, new ArrayList<>(testDataset.getAnonymizationMethodUseds()))); } - /** - * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getDataPreprocessings}. - */ - public void testDatasetgetDataPreprocessings() throws InvalidSPDXAnalysisException { - Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testDataset.getDataPreprocessings()))); - testDataset.getDataPreprocessings().clear(); - testDataset.getDataPreprocessings().addAll(DATA_PREPROCESSING_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testDataset.getDataPreprocessings()))); - } - /** * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getKnownBiass}. */ @@ -276,6 +267,17 @@ public void testDatasetgetKnownBiass() throws InvalidSPDXAnalysisException { assertTrue(UnitTestHelper.isListsEqual(KNOWN_BIAS_TEST_LIST2, new ArrayList<>(testDataset.getKnownBiass()))); } + /** + * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getDataPreprocessings}. + */ + public void testDatasetgetDataPreprocessings() throws InvalidSPDXAnalysisException { + Dataset testDataset = builderForDatasetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testDataset.getDataPreprocessings()))); + testDataset.getDataPreprocessings().clear(); + testDataset.getDataPreprocessings().addAll(DATA_PREPROCESSING_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testDataset.getDataPreprocessings()))); + } + /** * Test method for {@link org.spdx.library.model.v3.dataset.Dataset#getDatasetType}. */ diff --git a/src/test/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ConjunctiveLicenseSetTest.java similarity index 88% rename from src/test/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/ConjunctiveLicenseSetTest.java index 7b3975b59..a933034fd 100644 --- a/src/test/java/org/spdx/library/model/v3/expandedlicense/ConjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ConjunctiveLicenseSetTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.expandedlicense; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder; +import org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -65,7 +65,7 @@ public static ConjunctiveLicenseSetBuilder builderForConjunctiveLicenseSetTests( } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -76,15 +76,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("ExpandedLicense.ConjunctiveLicenseSet", testConjunctiveLicenseSet.getType()); + assertEquals("ExpandedLicensing.ConjunctiveLicenseSet", testConjunctiveLicenseSet.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -92,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#Element(org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet#Element(org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet.ConjunctiveLicenseSetBuilder)}. */ public void testConjunctiveLicenseSetConjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -107,7 +107,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.ConjunctiveLicenseSet#getMember}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet#getMember}. */ public void testConjunctiveLicenseSetgetMembers() throws InvalidSPDXAnalysisException { ConjunctiveLicenseSet testConjunctiveLicenseSet = builderForConjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseAdditionTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseAdditionTest.java similarity index 81% rename from src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseAdditionTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseAdditionTest.java index e1dc4380a..84f0ae3b1 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseAdditionTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder; +import org.spdx.library.model.v3.expandedlicensing.CustomLicenseAddition.CustomLicenseAdditionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static CustomLicenseAdditionBuilder builderForCustomLicenseAdditionTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicenseAddition#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,15 +75,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicenseAddition#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.CustomLicenseAddition", testCustomLicenseAddition.getType()); + assertEquals("ExpandedLicensing.CustomLicenseAddition", testCustomLicenseAddition.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicenseAddition#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CustomLicenseAddition testCustomLicenseAddition = builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicenseAddition#Element(org.spdx.library.model.v3.licensing.CustomLicenseAddition.CustomLicenseAdditionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicenseAddition#Element(org.spdx.library.model.v3.expandedlicensing.CustomLicenseAddition.CustomLicenseAdditionBuilder)}. */ public void testCustomLicenseAdditionCustomLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { builderForCustomLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseTest.java similarity index 82% rename from src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseTest.java index a7b2c1ee2..b8de291e3 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/CustomLicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/CustomLicenseTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.CustomLicense.CustomLicenseBuilder; +import org.spdx.library.model.v3.expandedlicensing.CustomLicense.CustomLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static CustomLicenseBuilder builderForCustomLicenseTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicense#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,15 +75,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicense#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.CustomLicense", testCustomLicense.getType()); + assertEquals("ExpandedLicensing.CustomLicense", testCustomLicense.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicense#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { CustomLicense testCustomLicense = builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.CustomLicense#Element(org.spdx.library.model.v3.licensing.CustomLicense.CustomLicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.CustomLicense#Element(org.spdx.library.model.v3.expandedlicensing.CustomLicense.CustomLicenseBuilder)}. */ public void testCustomLicenseCustomLicenseBuilder() throws InvalidSPDXAnalysisException { builderForCustomLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSetTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/DisjunctiveLicenseSetTest.java similarity index 88% rename from src/test/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSetTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/DisjunctiveLicenseSetTest.java index 90f6e2a32..621632cbd 100644 --- a/src/test/java/org/spdx/library/model/v3/expandedlicense/DisjunctiveLicenseSetTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/DisjunctiveLicenseSetTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.expandedlicense; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder; +import org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -65,7 +65,7 @@ public static DisjunctiveLicenseSetBuilder builderForDisjunctiveLicenseSetTests( } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -76,15 +76,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("ExpandedLicense.DisjunctiveLicenseSet", testDisjunctiveLicenseSet.getType()); + assertEquals("ExpandedLicensing.DisjunctiveLicenseSet", testDisjunctiveLicenseSet.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -92,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#Element(org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet#Element(org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet.DisjunctiveLicenseSetBuilder)}. */ public void testDisjunctiveLicenseSetDisjunctiveLicenseSetBuilder() throws InvalidSPDXAnalysisException { builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -107,7 +107,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.expandedlicense.DisjunctiveLicenseSet#getMember}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.DisjunctiveLicenseSet#getMember}. */ public void testDisjunctiveLicenseSetgetMembers() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet testDisjunctiveLicenseSet = builderForDisjunctiveLicenseSetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/ExtendableLicenseTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ExtendableLicenseTest.java similarity index 81% rename from src/test/java/org/spdx/library/model/v3/licensing/ExtendableLicenseTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/ExtendableLicenseTest.java index 146dc77e5..0a6ed033a 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/ExtendableLicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ExtendableLicenseTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.ExtendableLicense.ExtendableLicenseBuilder; +import org.spdx.library.model.v3.expandedlicensing.ExtendableLicense.ExtendableLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static ExtendableLicenseBuilder builderForExtendableLicenseTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ExtendableLicense#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,15 +75,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ExtendableLicense#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.ExtendableLicense", testExtendableLicense.getType()); + assertEquals("ExpandedLicensing.ExtendableLicense", testExtendableLicense.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ExtendableLicense#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ExtendableLicense testExtendableLicense = builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ExtendableLicense#Element(org.spdx.library.model.v3.licensing.ExtendableLicense.ExtendableLicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ExtendableLicense#Element(org.spdx.library.model.v3.expandedlicensing.ExtendableLicense.ExtendableLicenseBuilder)}. */ public void testExtendableLicenseExtendableLicenseBuilder() throws InvalidSPDXAnalysisException { builderForExtendableLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/LicenseAdditionTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/LicenseAdditionTest.java similarity index 75% rename from src/test/java/org/spdx/library/model/v3/licensing/LicenseAdditionTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/LicenseAdditionTest.java index 101774520..36822a6e1 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/LicenseAdditionTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/LicenseAdditionTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.LicenseAddition.LicenseAdditionBuilder; +import org.spdx.library.model.v3.expandedlicensing.LicenseAddition.LicenseAdditionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,8 +42,9 @@ public class LicenseAdditionTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String OBSOLETED_BY_TEST_VALUE = "test obsoletedBy"; static final String STANDARD_ADDITION_TEMPLATE_TEST_VALUE = "test standardAdditionTemplate"; + static final String OBSOLETED_BY_TEST_VALUE = "test obsoletedBy"; + static final String LICENSE_XML_TEST_VALUE = "test licenseXml"; static final String ADDITION_TEXT_TEST_VALUE = "test additionText"; protected void setUp() throws Exception { @@ -60,8 +61,9 @@ public static LicenseAdditionBuilder builderForLicenseAdditionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { LicenseAdditionBuilder retval = new LicenseAdditionBuilder(modelStore, objectUri, copyManager) .setIsDeprecatedAdditionId(true) - .setObsoletedBy(OBSOLETED_BY_TEST_VALUE) .setStandardAdditionTemplate(STANDARD_ADDITION_TEMPLATE_TEST_VALUE) + .setObsoletedBy(OBSOLETED_BY_TEST_VALUE) + .setLicenseXml(LICENSE_XML_TEST_VALUE) .setAdditionText(ADDITION_TEXT_TEST_VALUE) //TODO: Add in test values /******************** @@ -71,7 +73,7 @@ public static LicenseAdditionBuilder builderForLicenseAdditionTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -82,15 +84,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.LicenseAddition", testLicenseAddition.getType()); + assertEquals("ExpandedLicensing.LicenseAddition", testLicenseAddition.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -98,7 +100,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#Element(org.spdx.library.model.v3.licensing.LicenseAddition.LicenseAdditionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#Element(org.spdx.library.model.v3.expandedlicensing.LicenseAddition.LicenseAdditionBuilder)}. */ public void testLicenseAdditionLicenseAdditionBuilder() throws InvalidSPDXAnalysisException { builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -113,7 +115,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setIsDeprecatedAdditionId}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#setIsDeprecatedAdditionId}. */ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -123,7 +125,17 @@ public void testLicenseAdditionsetIsDeprecatedAdditionId() throws InvalidSPDXAna } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setObsoletedBy}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#setStandardAdditionTemplate}. + */ + public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXAnalysisException { + LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(STANDARD_ADDITION_TEMPLATE_TEST_VALUE), testLicenseAddition.getStandardAdditionTemplate()); + testLicenseAddition.setStandardAdditionTemplate("new standardAdditionTemplate value"); + assertEquals(Optional.of("new standardAdditionTemplate value"), testLicenseAddition.getStandardAdditionTemplate()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#setObsoletedBy}. */ public void testLicenseAdditionsetObsoletedBy() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -133,17 +145,17 @@ public void testLicenseAdditionsetObsoletedBy() throws InvalidSPDXAnalysisExcept } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setStandardAdditionTemplate}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#setLicenseXml}. */ - public void testLicenseAdditionsetStandardAdditionTemplate() throws InvalidSPDXAnalysisException { + public void testLicenseAdditionsetLicenseXml() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(STANDARD_ADDITION_TEMPLATE_TEST_VALUE), testLicenseAddition.getStandardAdditionTemplate()); - testLicenseAddition.setStandardAdditionTemplate("new standardAdditionTemplate value"); - assertEquals(Optional.of("new standardAdditionTemplate value"), testLicenseAddition.getStandardAdditionTemplate()); + assertEquals(Optional.of(LICENSE_XML_TEST_VALUE), testLicenseAddition.getLicenseXml()); + testLicenseAddition.setLicenseXml("new licenseXml value"); + assertEquals(Optional.of("new licenseXml value"), testLicenseAddition.getLicenseXml()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseAddition#setAdditionText}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.LicenseAddition#setAdditionText}. */ public void testLicenseAdditionsetAdditionText() throws InvalidSPDXAnalysisException { LicenseAddition testLicenseAddition = builderForLicenseAdditionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/LicenseTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/LicenseTest.java similarity index 77% rename from src/test/java/org/spdx/library/model/v3/licensing/LicenseTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/LicenseTest.java index 55f8327bd..f2ffa90d4 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/LicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/LicenseTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.License.LicenseBuilder; +import org.spdx.library.model.v3.expandedlicensing.License.LicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,10 +42,11 @@ public class LicenseTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String STANDARD_LICENSE_TEMPLATE_TEST_VALUE = "test standardLicenseTemplate"; static final String OBSOLETED_BY_TEST_VALUE = "test obsoletedBy"; static final String STANDARD_LICENSE_HEADER_TEST_VALUE = "test standardLicenseHeader"; static final String LICENSE_TEXT_TEST_VALUE = "test licenseText"; + static final String LICENSE_XML_TEST_VALUE = "test licenseXml"; + static final String STANDARD_LICENSE_TEMPLATE_TEST_VALUE = "test standardLicenseTemplate"; protected void setUp() throws Exception { super.setUp(); @@ -61,12 +62,13 @@ public static LicenseBuilder builderForLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { LicenseBuilder retval = new LicenseBuilder(modelStore, objectUri, copyManager) .setIsFsfLibre(true) - .setIsOsiApproved(true) .setIsDeprecatedLicenseId(true) - .setStandardLicenseTemplate(STANDARD_LICENSE_TEMPLATE_TEST_VALUE) + .setIsOsiApproved(true) .setObsoletedBy(OBSOLETED_BY_TEST_VALUE) .setStandardLicenseHeader(STANDARD_LICENSE_HEADER_TEST_VALUE) .setLicenseText(LICENSE_TEXT_TEST_VALUE) + .setLicenseXml(LICENSE_XML_TEST_VALUE) + .setStandardLicenseTemplate(STANDARD_LICENSE_TEMPLATE_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -75,7 +77,7 @@ public static LicenseBuilder builderForLicenseTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -86,15 +88,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.License", testLicense.getType()); + assertEquals("ExpandedLicensing.License", testLicense.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -102,7 +104,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#Element(org.spdx.library.model.v3.licensing.License.LicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#Element(org.spdx.library.model.v3.expandedlicensing.License.LicenseBuilder)}. */ public void testLicenseLicenseBuilder() throws InvalidSPDXAnalysisException { builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -117,7 +119,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setIsFsfLibre}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setIsFsfLibre}. */ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -127,17 +129,7 @@ public void testLicensesetIsFsfLibre() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setIsOsiApproved}. - */ - public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { - License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(new Boolean(true)), testLicense.getIsOsiApproved()); - testLicense.setIsOsiApproved(false); - assertEquals(Optional.of(new Boolean(false)), testLicense.getIsOsiApproved()); - } - - /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setIsDeprecatedLicenseId}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setIsDeprecatedLicenseId}. */ public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -147,17 +139,17 @@ public void testLicensesetIsDeprecatedLicenseId() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setStandardLicenseTemplate}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setIsOsiApproved}. */ - public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisException { + public void testLicensesetIsOsiApproved() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(STANDARD_LICENSE_TEMPLATE_TEST_VALUE), testLicense.getStandardLicenseTemplate()); - testLicense.setStandardLicenseTemplate("new standardLicenseTemplate value"); - assertEquals(Optional.of("new standardLicenseTemplate value"), testLicense.getStandardLicenseTemplate()); + assertEquals(Optional.of(new Boolean(true)), testLicense.getIsOsiApproved()); + testLicense.setIsOsiApproved(false); + assertEquals(Optional.of(new Boolean(false)), testLicense.getIsOsiApproved()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setObsoletedBy}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setObsoletedBy}. */ public void testLicensesetObsoletedBy() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -167,7 +159,7 @@ public void testLicensesetObsoletedBy() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setStandardLicenseHeader}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setStandardLicenseHeader}. */ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -177,7 +169,7 @@ public void testLicensesetStandardLicenseHeader() throws InvalidSPDXAnalysisExce } /** - * Test method for {@link org.spdx.library.model.v3.licensing.License#setLicenseText}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setLicenseText}. */ public void testLicensesetLicenseText() throws InvalidSPDXAnalysisException { License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -185,4 +177,24 @@ public void testLicensesetLicenseText() throws InvalidSPDXAnalysisException { testLicense.setLicenseText("new licenseText value"); assertEquals("new licenseText value", testLicense.getLicenseText()); } + + /** + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setLicenseXml}. + */ + public void testLicensesetLicenseXml() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(LICENSE_XML_TEST_VALUE), testLicense.getLicenseXml()); + testLicense.setLicenseXml("new licenseXml value"); + assertEquals(Optional.of("new licenseXml value"), testLicense.getLicenseXml()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.License#setStandardLicenseTemplate}. + */ + public void testLicensesetStandardLicenseTemplate() throws InvalidSPDXAnalysisException { + License testLicense = builderForLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(STANDARD_LICENSE_TEMPLATE_TEST_VALUE), testLicense.getStandardLicenseTemplate()); + testLicense.setStandardLicenseTemplate("new standardLicenseTemplate value"); + assertEquals(Optional.of("new standardLicenseTemplate value"), testLicense.getStandardLicenseTemplate()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseExceptionTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseExceptionTest.java similarity index 82% rename from src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseExceptionTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseExceptionTest.java index 1d73685e6..f3df0ae27 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseExceptionTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseExceptionTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.ListedLicenseException.ListedLicenseExceptionBuilder; +import org.spdx.library.model.v3.expandedlicensing.ListedLicenseException.ListedLicenseExceptionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -68,7 +68,7 @@ public static ListedLicenseExceptionBuilder builderForListedLicenseExceptionTest } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicenseException#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -79,15 +79,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicenseException#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.ListedLicenseException", testListedLicenseException.getType()); + assertEquals("ExpandedLicensing.ListedLicenseException", testListedLicenseException.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicenseException#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -95,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#Element(org.spdx.library.model.v3.licensing.ListedLicenseException.ListedLicenseExceptionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicenseException#Element(org.spdx.library.model.v3.expandedlicensing.ListedLicenseException.ListedLicenseExceptionBuilder)}. */ public void testListedLicenseExceptionListedLicenseExceptionBuilder() throws InvalidSPDXAnalysisException { builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -110,7 +110,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#setDeprecatedVersion}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicenseException#setDeprecatedVersion}. */ public void testListedLicenseExceptionsetDeprecatedVersion() throws InvalidSPDXAnalysisException { ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -120,7 +120,7 @@ public void testListedLicenseExceptionsetDeprecatedVersion() throws InvalidSPDXA } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicenseException#setListVersionAdded}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicenseException#setListVersionAdded}. */ public void testListedLicenseExceptionsetListVersionAdded() throws InvalidSPDXAnalysisException { ListedLicenseException testListedLicenseException = builderForListedLicenseExceptionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseTest.java similarity index 82% rename from src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseTest.java index 9aa2fdf0e..d1534bb09 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/ListedLicenseTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/ListedLicenseTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.ListedLicense.ListedLicenseBuilder; +import org.spdx.library.model.v3.expandedlicensing.ListedLicense.ListedLicenseBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -42,8 +42,8 @@ public class ListedLicenseTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String DEPRECATED_VERSION_TEST_VALUE = "test deprecatedVersion"; static final String LIST_VERSION_ADDED_TEST_VALUE = "test listVersionAdded"; + static final String DEPRECATED_VERSION_TEST_VALUE = "test deprecatedVersion"; protected void setUp() throws Exception { super.setUp(); @@ -58,8 +58,8 @@ protected void tearDown() throws Exception { public static ListedLicenseBuilder builderForListedLicenseTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { ListedLicenseBuilder retval = new ListedLicenseBuilder(modelStore, objectUri, copyManager) - .setDeprecatedVersion(DEPRECATED_VERSION_TEST_VALUE) .setListVersionAdded(LIST_VERSION_ADDED_TEST_VALUE) + .setDeprecatedVersion(DEPRECATED_VERSION_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -68,7 +68,7 @@ public static ListedLicenseBuilder builderForListedLicenseTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicense#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -79,15 +79,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicense#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.ListedLicense", testListedLicense.getType()); + assertEquals("ExpandedLicensing.ListedLicense", testListedLicense.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicense#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -95,7 +95,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#Element(org.spdx.library.model.v3.licensing.ListedLicense.ListedLicenseBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicense#Element(org.spdx.library.model.v3.expandedlicensing.ListedLicense.ListedLicenseBuilder)}. */ public void testListedLicenseListedLicenseBuilder() throws InvalidSPDXAnalysisException { builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -110,22 +110,22 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#setDeprecatedVersion}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicense#setListVersionAdded}. */ - public void testListedLicensesetDeprecatedVersion() throws InvalidSPDXAnalysisException { + public void testListedLicensesetListVersionAdded() throws InvalidSPDXAnalysisException { ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DEPRECATED_VERSION_TEST_VALUE), testListedLicense.getDeprecatedVersion()); - testListedLicense.setDeprecatedVersion("new deprecatedVersion value"); - assertEquals(Optional.of("new deprecatedVersion value"), testListedLicense.getDeprecatedVersion()); + assertEquals(Optional.of(LIST_VERSION_ADDED_TEST_VALUE), testListedLicense.getListVersionAdded()); + testListedLicense.setListVersionAdded("new listVersionAdded value"); + assertEquals(Optional.of("new listVersionAdded value"), testListedLicense.getListVersionAdded()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.ListedLicense#setListVersionAdded}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.ListedLicense#setDeprecatedVersion}. */ - public void testListedLicensesetListVersionAdded() throws InvalidSPDXAnalysisException { + public void testListedLicensesetDeprecatedVersion() throws InvalidSPDXAnalysisException { ListedLicense testListedLicense = builderForListedLicenseTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(LIST_VERSION_ADDED_TEST_VALUE), testListedLicense.getListVersionAdded()); - testListedLicense.setListVersionAdded("new listVersionAdded value"); - assertEquals(Optional.of("new listVersionAdded value"), testListedLicense.getListVersionAdded()); + assertEquals(Optional.of(DEPRECATED_VERSION_TEST_VALUE), testListedLicense.getDeprecatedVersion()); + testListedLicense.setDeprecatedVersion("new deprecatedVersion value"); + assertEquals(Optional.of("new deprecatedVersion value"), testListedLicense.getDeprecatedVersion()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/licensing/OrLaterOperatorTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/OrLaterOperatorTest.java similarity index 82% rename from src/test/java/org/spdx/library/model/v3/licensing/OrLaterOperatorTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/OrLaterOperatorTest.java index 44643fcfb..36f54e9bd 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/OrLaterOperatorTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/OrLaterOperatorTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.OrLaterOperator.OrLaterOperatorBuilder; +import org.spdx.library.model.v3.expandedlicensing.OrLaterOperator.OrLaterOperatorBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -65,7 +65,7 @@ public static OrLaterOperatorBuilder builderForOrLaterOperatorTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.OrLaterOperator#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -76,15 +76,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.OrLaterOperator#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.OrLaterOperator", testOrLaterOperator.getType()); + assertEquals("ExpandedLicensing.OrLaterOperator", testOrLaterOperator.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.OrLaterOperator#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -92,7 +92,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#Element(org.spdx.library.model.v3.licensing.OrLaterOperator.OrLaterOperatorBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.OrLaterOperator#Element(org.spdx.library.model.v3.expandedlicensing.OrLaterOperator.OrLaterOperatorBuilder)}. */ public void testOrLaterOperatorOrLaterOperatorBuilder() throws InvalidSPDXAnalysisException { builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -107,7 +107,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.OrLaterOperator#setSubjectLicense}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.OrLaterOperator#setSubjectLicense}. */ public void testOrLaterOperatorsetSubjectLicense() throws InvalidSPDXAnalysisException { OrLaterOperator testOrLaterOperator = builderForOrLaterOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/WithAdditionOperatorTest.java b/src/test/java/org/spdx/library/model/v3/expandedlicensing/WithAdditionOperatorTest.java similarity index 81% rename from src/test/java/org/spdx/library/model/v3/licensing/WithAdditionOperatorTest.java rename to src/test/java/org/spdx/library/model/v3/expandedlicensing/WithAdditionOperatorTest.java index ceb959468..3d812303f 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/WithAdditionOperatorTest.java +++ b/src/test/java/org/spdx/library/model/v3/expandedlicensing/WithAdditionOperatorTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.expandedlicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.WithAdditionOperator.WithAdditionOperatorBuilder; +import org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator.WithAdditionOperatorBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -66,7 +66,7 @@ public static WithAdditionOperatorBuilder builderForWithAdditionOperatorTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#verify()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,15 +77,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#getType()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.WithAdditionOperator", testWithAdditionOperator.getType()); + assertEquals("ExpandedLicensing.WithAdditionOperator", testWithAdditionOperator.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#toString()}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +93,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#Element(org.spdx.library.model.v3.licensing.WithAdditionOperator.WithAdditionOperatorBuilder)}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator#Element(org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator.WithAdditionOperatorBuilder)}. */ public void testWithAdditionOperatorWithAdditionOperatorBuilder() throws InvalidSPDXAnalysisException { builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +108,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#setSubjectAddition}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator#setSubjectAddition}. */ public void testWithAdditionOperatorsetSubjectAddition() throws InvalidSPDXAnalysisException { WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -119,7 +119,7 @@ public void testWithAdditionOperatorsetSubjectAddition() throws InvalidSPDXAnaly } /** - * Test method for {@link org.spdx.library.model.v3.licensing.WithAdditionOperator#setSubjectLicense}. + * Test method for {@link org.spdx.library.model.v3.expandedlicensing.WithAdditionOperator#setSubjectLicense}. */ public void testWithAdditionOperatorsetSubjectLicense() throws InvalidSPDXAnalysisException { WithAdditionOperator testWithAdditionOperator = builderForWithAdditionOperatorTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java index e30f1ba08..34dc44581 100644 --- a/src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/CvssV2VulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -43,8 +43,8 @@ public class CvssV2VulnAssessmentRelationshipTest extends TestCase { ModelCopyManager copyManager; static final Integer SCORE_TEST_VALUE = 55; - static final String SEVERITY_TEST_VALUE = "test severity"; static final String VECTOR_TEST_VALUE = "test vector"; + static final String SEVERITY_TEST_VALUE = "test severity"; protected void setUp() throws Exception { super.setUp(); @@ -60,8 +60,8 @@ public static CvssV2VulnAssessmentRelationshipBuilder builderForCvssV2VulnAssess IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { CvssV2VulnAssessmentRelationshipBuilder retval = new CvssV2VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) .setScore(SCORE_TEST_VALUE) - .setSeverity(SEVERITY_TEST_VALUE) .setVector(VECTOR_TEST_VALUE) + .setSeverity(SEVERITY_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -121,16 +121,6 @@ public void testCvssV2VulnAssessmentRelationshipsetScore() throws InvalidSPDXAna assertEquals(new Integer(653), testCvssV2VulnAssessmentRelationship.getScore()); } - /** - * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#setSeverity}. - */ - public void testCvssV2VulnAssessmentRelationshipsetSeverity() throws InvalidSPDXAnalysisException { - CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SEVERITY_TEST_VALUE), testCvssV2VulnAssessmentRelationship.getSeverity()); - testCvssV2VulnAssessmentRelationship.setSeverity("new severity value"); - assertEquals(Optional.of("new severity value"), testCvssV2VulnAssessmentRelationship.getSeverity()); - } - /** * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#setVector}. */ @@ -140,4 +130,14 @@ public void testCvssV2VulnAssessmentRelationshipsetVector() throws InvalidSPDXAn testCvssV2VulnAssessmentRelationship.setVector("new vector value"); assertEquals(Optional.of("new vector value"), testCvssV2VulnAssessmentRelationship.getVector()); } + + /** + * Test method for {@link org.spdx.library.model.v3.security.CvssV2VulnAssessmentRelationship#setSeverity}. + */ + public void testCvssV2VulnAssessmentRelationshipsetSeverity() throws InvalidSPDXAnalysisException { + CvssV2VulnAssessmentRelationship testCvssV2VulnAssessmentRelationship = builderForCvssV2VulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(SEVERITY_TEST_VALUE), testCvssV2VulnAssessmentRelationship.getSeverity()); + testCvssV2VulnAssessmentRelationship.setSeverity("new severity value"); + assertEquals(Optional.of("new severity value"), testCvssV2VulnAssessmentRelationship.getSeverity()); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java index e5e83b67a..c0b01a902 100644 --- a/src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/CvssV3VulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java index 80ddcb3b8..e7d884e0d 100644 --- a/src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/EpssVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java index 658060c29..3ced41ef2 100644 --- a/src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/ExploitCatalogVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java index d5885758d..489ebb7eb 100644 --- a/src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/SsvcVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java index 93a52c51a..c5b5e1be8 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexAffectedVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -43,6 +43,11 @@ public class VexAffectedVulnAssessmentRelationshipTest extends TestCase { ModelCopyManager copyManager; static final String ACTION_STATEMENT_TEST_VALUE = "test actionStatement"; + static final String ACTION_STATEMENT_TIME_TEST_VALUE1 = "test 1 actionStatementTime"; + static final String ACTION_STATEMENT_TIME_TEST_VALUE2 = "test 2 actionStatementTime"; + static final String ACTION_STATEMENT_TIME_TEST_VALUE3 = "test 3 actionStatementTime"; + static final List ACTION_STATEMENT_TIME_TEST_LIST1 = Arrays.asList(new String[] { ACTION_STATEMENT_TIME_TEST_VALUE1, ACTION_STATEMENT_TIME_TEST_VALUE2 }); + static final List ACTION_STATEMENT_TIME_TEST_LIST2 = Arrays.asList(new String[] { ACTION_STATEMENT_TIME_TEST_VALUE3 }); protected void setUp() throws Exception { super.setUp(); @@ -58,9 +63,10 @@ public static VexAffectedVulnAssessmentRelationshipBuilder builderForVexAffected IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationshipBuilder retval = new VexAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) .setActionStatement(ACTION_STATEMENT_TEST_VALUE) + .addActionStatementTime(ACTION_STATEMENT_TIME_TEST_VALUE1) + .addActionStatementTime(ACTION_STATEMENT_TIME_TEST_VALUE2) //TODO: Add in test values /******************** - .addActionStatementTime(DateTime) ***************/ ; return retval; @@ -119,14 +125,13 @@ public void testVexAffectedVulnAssessmentRelationshipsetActionStatement() throws } /** - * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#getActionStatementTime}. + * Test method for {@link org.spdx.library.model.v3.security.VexAffectedVulnAssessmentRelationship#getActionStatementTimes}. */ public void testVexAffectedVulnAssessmentRelationshipgetActionStatementTimes() throws InvalidSPDXAnalysisException { VexAffectedVulnAssessmentRelationship testVexAffectedVulnAssessmentRelationship = builderForVexAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); -// testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().clear(); -// testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().addAll(NEW_TEST_VALUE); -// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); - fail("Not yet implemented"); + assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST1, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); + testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().clear(); + testVexAffectedVulnAssessmentRelationship.getActionStatementTimes().addAll(ACTION_STATEMENT_TIME_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(ACTION_STATEMENT_TIME_TEST_LIST2, new ArrayList<>(testVexAffectedVulnAssessmentRelationship.getActionStatementTimes()))); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java index 67733a3b0..4468d3b91 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexFixedVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java index fca827fab..02a945c6c 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexNotAffectedVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,6 +42,7 @@ public class VexNotAffectedVulnAssessmentRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String IMPACT_STATEMENT_TIME_TEST_VALUE = "test impactStatementTime"; static final String IMPACT_STATEMENT_TEST_VALUE = "test impactStatement"; static final VexJustificationType JUSTIFICATION_TYPE_TEST_VALUE1 = VexJustificationType.values()[0]; static final VexJustificationType JUSTIFICATION_TYPE_TEST_VALUE2 = VexJustificationType.values()[1]; @@ -59,11 +60,11 @@ protected void tearDown() throws Exception { public static VexNotAffectedVulnAssessmentRelationshipBuilder builderForVexNotAffectedVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { VexNotAffectedVulnAssessmentRelationshipBuilder retval = new VexNotAffectedVulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setImpactStatementTime(IMPACT_STATEMENT_TIME_TEST_VALUE) .setImpactStatement(IMPACT_STATEMENT_TEST_VALUE) .setJustificationType(JUSTIFICATION_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** - .setImpactStatementTime(new DateTime()) ***************/ ; return retval; @@ -111,17 +112,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatementTime}. - */ - public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { - VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); -// testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); - fail("Not yet implemented"); - } - /** * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setJustificationType}. */ @@ -132,6 +122,16 @@ public void testVexNotAffectedVulnAssessmentRelationshipsetJustificationType() t assertEquals(Optional.of(JUSTIFICATION_TYPE_TEST_VALUE2), testVexNotAffectedVulnAssessmentRelationship.getJustificationType()); } + /** + * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatementTime}. + */ + public void testVexNotAffectedVulnAssessmentRelationshipsetImpactStatementTime() throws InvalidSPDXAnalysisException { + VexNotAffectedVulnAssessmentRelationship testVexNotAffectedVulnAssessmentRelationship = builderForVexNotAffectedVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(IMPACT_STATEMENT_TIME_TEST_VALUE), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + testVexNotAffectedVulnAssessmentRelationship.setImpactStatementTime("new impactStatementTime value"); + assertEquals(Optional.of("new impactStatementTime value"), testVexNotAffectedVulnAssessmentRelationship.getImpactStatementTime()); + } + /** * Test method for {@link org.spdx.library.model.v3.security.VexNotAffectedVulnAssessmentRelationship#setImpactStatement}. */ diff --git a/src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java index 268aeaea7..69b266037 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexUnderInvestigationVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java index 9d5628919..ad23aaabc 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VexVulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java index a477c6bea..f6316fbdd 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VulnAssessmentRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,6 +42,9 @@ public class VulnAssessmentRelationshipTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String WITHDRAWN_TIME_TEST_VALUE = "test withdrawnTime"; + static final String PUBLISHED_TIME_TEST_VALUE = "test publishedTime"; + static final String MODIFIED_TIME_TEST_VALUE = "test modifiedTime"; protected void setUp() throws Exception { super.setUp(); @@ -56,13 +59,13 @@ protected void tearDown() throws Exception { public static VulnAssessmentRelationshipBuilder builderForVulnAssessmentRelationshipTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { VulnAssessmentRelationshipBuilder retval = new VulnAssessmentRelationshipBuilder(modelStore, objectUri, copyManager) + .setWithdrawnTime(WITHDRAWN_TIME_TEST_VALUE) + .setPublishedTime(PUBLISHED_TIME_TEST_VALUE) + .setModifiedTime(MODIFIED_TIME_TEST_VALUE) //TODO: Add in test values /******************** .setSuppliedBy(new Agent()) - .setPublishedTime(new DateTime()) - .setWithdrawnTime(new DateTime()) .setAssessedElement(new Element()) - .setModifiedTime(new DateTime()) ***************/ ; return retval; @@ -122,13 +125,13 @@ public void testVulnAssessmentRelationshipsetSuppliedBy() throws InvalidSPDXAnal } /** - * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setPublishedTime}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setAssessedElement}. */ - public void testVulnAssessmentRelationshipsetPublishedTime() throws InvalidSPDXAnalysisException { + public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getPublishedTime()); -// testVulnAssessmentRelationship.setPublishedTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getPublishedTime()); +// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getAssessedElement()); +// testVulnAssessmentRelationship.setAssessedElement(NEW_TEST_VALUE); +// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getAssessedElement()); fail("Not yet implemented"); } @@ -137,21 +140,19 @@ public void testVulnAssessmentRelationshipsetPublishedTime() throws InvalidSPDXA */ public void testVulnAssessmentRelationshipsetWithdrawnTime() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getWithdrawnTime()); -// testVulnAssessmentRelationship.setWithdrawnTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getWithdrawnTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(WITHDRAWN_TIME_TEST_VALUE), testVulnAssessmentRelationship.getWithdrawnTime()); + testVulnAssessmentRelationship.setWithdrawnTime("new withdrawnTime value"); + assertEquals(Optional.of("new withdrawnTime value"), testVulnAssessmentRelationship.getWithdrawnTime()); } /** - * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setAssessedElement}. + * Test method for {@link org.spdx.library.model.v3.security.VulnAssessmentRelationship#setPublishedTime}. */ - public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPDXAnalysisException { + public void testVulnAssessmentRelationshipsetPublishedTime() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getAssessedElement()); -// testVulnAssessmentRelationship.setAssessedElement(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getAssessedElement()); - fail("Not yet implemented"); + assertEquals(Optional.of(PUBLISHED_TIME_TEST_VALUE), testVulnAssessmentRelationship.getPublishedTime()); + testVulnAssessmentRelationship.setPublishedTime("new publishedTime value"); + assertEquals(Optional.of("new publishedTime value"), testVulnAssessmentRelationship.getPublishedTime()); } /** @@ -159,9 +160,8 @@ public void testVulnAssessmentRelationshipsetAssessedElement() throws InvalidSPD */ public void testVulnAssessmentRelationshipsetModifiedTime() throws InvalidSPDXAnalysisException { VulnAssessmentRelationship testVulnAssessmentRelationship = builderForVulnAssessmentRelationshipTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnAssessmentRelationship.getModifiedTime()); -// testVulnAssessmentRelationship.setModifiedTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnAssessmentRelationship.getModifiedTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(MODIFIED_TIME_TEST_VALUE), testVulnAssessmentRelationship.getModifiedTime()); + testVulnAssessmentRelationship.setModifiedTime("new modifiedTime value"); + assertEquals(Optional.of("new modifiedTime value"), testVulnAssessmentRelationship.getModifiedTime()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java b/src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java index 37e1ae327..83952280c 100644 --- a/src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java +++ b/src/test/java/org/spdx/library/model/v3/security/VulnerabilityTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,6 +42,9 @@ public class VulnerabilityTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String WITHDRAWN_TIME_TEST_VALUE = "test withdrawnTime"; + static final String MODIFIED_TIME_TEST_VALUE = "test modifiedTime"; + static final String PUBLISHED_TIME_TEST_VALUE = "test publishedTime"; protected void setUp() throws Exception { super.setUp(); @@ -56,11 +59,11 @@ protected void tearDown() throws Exception { public static VulnerabilityBuilder builderForVulnerabilityTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { VulnerabilityBuilder retval = new VulnerabilityBuilder(modelStore, objectUri, copyManager) + .setWithdrawnTime(WITHDRAWN_TIME_TEST_VALUE) + .setModifiedTime(MODIFIED_TIME_TEST_VALUE) + .setPublishedTime(PUBLISHED_TIME_TEST_VALUE) //TODO: Add in test values /******************** - .setModifiedTime(new DateTime()) - .setWithdrawnTime(new DateTime()) - .setPublishedTime(new DateTime()) ***************/ ; return retval; @@ -109,25 +112,23 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setModifiedTime}. + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setWithdrawnTime}. */ - public void testVulnerabilitysetModifiedTime() throws InvalidSPDXAnalysisException { + public void testVulnerabilitysetWithdrawnTime() throws InvalidSPDXAnalysisException { Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnerability.getModifiedTime()); -// testVulnerability.setModifiedTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnerability.getModifiedTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(WITHDRAWN_TIME_TEST_VALUE), testVulnerability.getWithdrawnTime()); + testVulnerability.setWithdrawnTime("new withdrawnTime value"); + assertEquals(Optional.of("new withdrawnTime value"), testVulnerability.getWithdrawnTime()); } /** - * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setWithdrawnTime}. + * Test method for {@link org.spdx.library.model.v3.security.Vulnerability#setModifiedTime}. */ - public void testVulnerabilitysetWithdrawnTime() throws InvalidSPDXAnalysisException { + public void testVulnerabilitysetModifiedTime() throws InvalidSPDXAnalysisException { Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnerability.getWithdrawnTime()); -// testVulnerability.setWithdrawnTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnerability.getWithdrawnTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(MODIFIED_TIME_TEST_VALUE), testVulnerability.getModifiedTime()); + testVulnerability.setModifiedTime("new modifiedTime value"); + assertEquals(Optional.of("new modifiedTime value"), testVulnerability.getModifiedTime()); } /** @@ -135,9 +136,8 @@ public void testVulnerabilitysetWithdrawnTime() throws InvalidSPDXAnalysisExcept */ public void testVulnerabilitysetPublishedTime() throws InvalidSPDXAnalysisException { Vulnerability testVulnerability = builderForVulnerabilityTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testVulnerability.getPublishedTime()); -// testVulnerability.setPublishedTime(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testVulnerability.getPublishedTime()); - fail("Not yet implemented"); + assertEquals(Optional.of(PUBLISHED_TIME_TEST_VALUE), testVulnerability.getPublishedTime()); + testVulnerability.setPublishedTime("new publishedTime value"); + assertEquals(Optional.of("new publishedTime value"), testVulnerability.getPublishedTime()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/licensing/AnyLicenseInfoTest.java b/src/test/java/org/spdx/library/model/v3/simplelicensing/AnyLicenseInfoTest.java similarity index 82% rename from src/test/java/org/spdx/library/model/v3/licensing/AnyLicenseInfoTest.java rename to src/test/java/org/spdx/library/model/v3/simplelicensing/AnyLicenseInfoTest.java index 02d84135b..888b88b50 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/AnyLicenseInfoTest.java +++ b/src/test/java/org/spdx/library/model/v3/simplelicensing/AnyLicenseInfoTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.simplelicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder; +import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo.AnyLicenseInfoBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -64,7 +64,7 @@ public static AnyLicenseInfoBuilder builderForAnyLicenseInfoTests( } /** - * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#verify()}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -75,15 +75,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#getType()}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.AnyLicenseInfo", testAnyLicenseInfo.getType()); + assertEquals("SimpleLicensing.AnyLicenseInfo", testAnyLicenseInfo.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#toString()}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { AnyLicenseInfo testAnyLicenseInfo = builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -91,7 +91,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.AnyLicenseInfo#Element(org.spdx.library.model.v3.licensing.AnyLicenseInfo.AnyLicenseInfoBuilder)}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo#Element(org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo.AnyLicenseInfoBuilder)}. */ public void testAnyLicenseInfoAnyLicenseInfoBuilder() throws InvalidSPDXAnalysisException { builderForAnyLicenseInfoTests(modelStore, TEST_OBJECT_URI, copyManager).build(); diff --git a/src/test/java/org/spdx/library/model/v3/licensing/LicenseExpressionTest.java b/src/test/java/org/spdx/library/model/v3/simplelicensing/LicenseExpressionTest.java similarity index 62% rename from src/test/java/org/spdx/library/model/v3/licensing/LicenseExpressionTest.java rename to src/test/java/org/spdx/library/model/v3/simplelicensing/LicenseExpressionTest.java index 4650600da..a2501639d 100644 --- a/src/test/java/org/spdx/library/model/v3/licensing/LicenseExpressionTest.java +++ b/src/test/java/org/spdx/library/model/v3/simplelicensing/LicenseExpressionTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.spdx.library.model.v3.licensing; +package org.spdx.library.model.v3.simplelicensing; import javax.annotation.Nullable; @@ -27,7 +27,7 @@ import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.licensing.LicenseExpression.LicenseExpressionBuilder; +import org.spdx.library.model.v3.simplelicensing.LicenseExpression.LicenseExpressionBuilder; import org.spdx.storage.IModelStore; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -43,6 +43,7 @@ public class LicenseExpressionTest extends TestCase { ModelCopyManager copyManager; static final String LICENSE_EXPRESSION_TEST_VALUE = "test licenseExpression"; + static final String LICENSE_LIST_VERSION_TEST_VALUE = "test licenseListVersion"; protected void setUp() throws Exception { super.setUp(); @@ -58,15 +59,17 @@ public static LicenseExpressionBuilder builderForLicenseExpressionTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { LicenseExpressionBuilder retval = new LicenseExpressionBuilder(modelStore, objectUri, copyManager) .setLicenseExpression(LICENSE_EXPRESSION_TEST_VALUE) + .setLicenseListVersion(LICENSE_LIST_VERSION_TEST_VALUE) //TODO: Add in test values /******************** + .addCustomIdToUri(DictionaryEntry) ***************/ ; return retval; } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#verify()}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#verify()}. * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { @@ -77,15 +80,15 @@ public void testVerify() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#getType()}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("Licensing.LicenseExpression", testLicenseExpression.getType()); + assertEquals("SimpleLicensing.LicenseExpression", testLicenseExpression.getType()); } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#toString()}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -93,7 +96,7 @@ public void testToString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#Element(org.spdx.library.model.v3.licensing.LicenseExpression.LicenseExpressionBuilder)}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#Element(org.spdx.library.model.v3.simplelicensing.LicenseExpression.LicenseExpressionBuilder)}. */ public void testLicenseExpressionLicenseExpressionBuilder() throws InvalidSPDXAnalysisException { builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -108,7 +111,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.licensing.LicenseExpression#setLicenseExpression}. + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#setLicenseExpression}. */ public void testLicenseExpressionsetLicenseExpression() throws InvalidSPDXAnalysisException { LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); @@ -116,4 +119,26 @@ public void testLicenseExpressionsetLicenseExpression() throws InvalidSPDXAnalys testLicenseExpression.setLicenseExpression("new licenseExpression value"); assertEquals("new licenseExpression value", testLicenseExpression.getLicenseExpression()); } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#setLicenseListVersion}. + */ + public void testLicenseExpressionsetLicenseListVersion() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(LICENSE_LIST_VERSION_TEST_VALUE), testLicenseExpression.getLicenseListVersion()); + testLicenseExpression.setLicenseListVersion("new licenseListVersion value"); + assertEquals(Optional.of("new licenseListVersion value"), testLicenseExpression.getLicenseListVersion()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.LicenseExpression#getCustomIdToUri}. + */ + public void testLicenseExpressiongetCustomIdToUris() throws InvalidSPDXAnalysisException { + LicenseExpression testLicenseExpression = builderForLicenseExpressionTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testLicenseExpression.getCustomIdToUris()))); +// testLicenseExpression.getCustomIdToUris().clear(); +// testLicenseExpression.getCustomIdToUris().addAll(NEW_TEST_VALUE); +// assertTrue(UnitTestHelper.isListsEquivalent(NEW_TEST_VALUE, new ArrayList<>(testLicenseExpression.getCustomIdToUris()))); + fail("Not yet implemented"); + } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingTextTest.java b/src/test/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingTextTest.java new file mode 100644 index 000000000..76b3e61e3 --- /dev/null +++ b/src/test/java/org/spdx/library/model/v3/simplelicensing/SimpleLicensingTextTest.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.library.model.v3.simplelicensing; + +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v3.simplelicensing.SimpleLicensingText.SimpleLicensingTextBuilder; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; +import org.spdx.utility.compare.UnitTestHelper; + +import junit.framework.TestCase; + +public class SimpleLicensingTextTest extends TestCase { + + static final String TEST_OBJECT_URI = "https://test.uri/testuri"; + + + IModelStore modelStore; + ModelCopyManager copyManager; + + static final String LICENSE_TEXT_TEST_VALUE = "test licenseText"; + + protected void setUp() throws Exception { + super.setUp(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static SimpleLicensingTextBuilder builderForSimpleLicensingTextTests( + IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + SimpleLicensingTextBuilder retval = new SimpleLicensingTextBuilder(modelStore, objectUri, copyManager) + .setLicenseText(LICENSE_TEXT_TEST_VALUE) + //TODO: Add in test values + /******************** + ***************/ + ; + return retval; + } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.SimpleLicensingText#verify()}. + * @throws InvalidSPDXAnalysisException on errors + */ + public void testVerify() throws InvalidSPDXAnalysisException { + SimpleLicensingText testSimpleLicensingText = builderForSimpleLicensingTextTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + List result = testSimpleLicensingText.verify(); + assertTrue(result.isEmpty()); + // TODO - add negative tests + } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.SimpleLicensingText#getType()}. + */ + public void testGetType() throws InvalidSPDXAnalysisException { + SimpleLicensingText testSimpleLicensingText = builderForSimpleLicensingTextTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SimpleLicensing.SimpleLicensingText", testSimpleLicensingText.getType()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.SimpleLicensingText#toString()}. + */ + public void testToString() throws InvalidSPDXAnalysisException { + SimpleLicensingText testSimpleLicensingText = builderForSimpleLicensingTextTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("SimpleLicensingText: "+TEST_OBJECT_URI, testSimpleLicensingText.toString()); + } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.SimpleLicensingText#Element(org.spdx.library.model.v3.simplelicensing.SimpleLicensingText.SimpleLicensingTextBuilder)}. + */ + public void testSimpleLicensingTextSimpleLicensingTextBuilder() throws InvalidSPDXAnalysisException { + builderForSimpleLicensingTextTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + } + + public void testEquivalent() throws InvalidSPDXAnalysisException { + SimpleLicensingText testSimpleLicensingText = builderForSimpleLicensingTextTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + SimpleLicensingText test2SimpleLicensingText = builderForSimpleLicensingTextTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + assertTrue(testSimpleLicensingText.equivalent(test2SimpleLicensingText)); + assertTrue(test2SimpleLicensingText.equivalent(testSimpleLicensingText)); + // TODO change some parameters for negative tests + } + + /** + * Test method for {@link org.spdx.library.model.v3.simplelicensing.SimpleLicensingText#setLicenseText}. + */ + public void testSimpleLicensingTextsetLicenseText() throws InvalidSPDXAnalysisException { + SimpleLicensingText testSimpleLicensingText = builderForSimpleLicensingTextTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(LICENSE_TEXT_TEST_VALUE, testSimpleLicensingText.getLicenseText()); + testSimpleLicensingText.setLicenseText("new licenseText value"); + assertEquals("new licenseText value", testSimpleLicensingText.getLicenseText()); + } +} \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/software/SbomTest.java b/src/test/java/org/spdx/library/model/v3/software/SbomTest.java index ed815211b..f7a89c059 100644 --- a/src/test/java/org/spdx/library/model/v3/software/SbomTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SbomTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/software/SnippetTest.java b/src/test/java/org/spdx/library/model/v3/software/SnippetTest.java index a1b6946db..c8c87c58c 100644 --- a/src/test/java/org/spdx/library/model/v3/software/SnippetTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SnippetTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -59,6 +59,7 @@ public static SnippetBuilder builderForSnippetTests( //TODO: Add in test values /******************** .setLineRange(new PositiveIntegerRange()) + .setSnippetFromFile(new SpdxFile()) .setByteRange(new PositiveIntegerRange()) ***************/ ; @@ -118,6 +119,17 @@ public void testSnippetsetLineRange() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } + /** + * Test method for {@link org.spdx.library.model.v3.software.Snippet#setSnippetFromFile}. + */ + public void testSnippetsetSnippetFromFile() throws InvalidSPDXAnalysisException { + Snippet testSnippet = builderForSnippetTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(TEST_VALUE, testSnippet.getSnippetFromFile()); +// testSnippet.setSnippetFromFile(NEW_TEST_VALUE); +// assertEquals(NEW_TEST_VALUE, testSnippet.getSnippetFromFile()); + fail("Not yet implemented"); + } + /** * Test method for {@link org.spdx.library.model.v3.software.Snippet#setByteRange}. */ diff --git a/src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java b/src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java index 65d5f3530..606772945 100644 --- a/src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SoftwareArtifactTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,11 +42,15 @@ public class SoftwareArtifactTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String ATTRIBUTION_TEXT_TEST_VALUE = "test attributionText"; static final String CONTENT_IDENTIFIER_TEST_VALUE = "test contentIdentifier"; static final String COPYRIGHT_TEXT_TEST_VALUE = "test copyrightText"; static final SoftwarePurpose PRIMARY_PURPOSE_TEST_VALUE1 = SoftwarePurpose.values()[0]; static final SoftwarePurpose PRIMARY_PURPOSE_TEST_VALUE2 = SoftwarePurpose.values()[1]; + static final String ATTRIBUTION_TEXT_TEST_VALUE1 = "test 1 attributionText"; + static final String ATTRIBUTION_TEXT_TEST_VALUE2 = "test 2 attributionText"; + static final String ATTRIBUTION_TEXT_TEST_VALUE3 = "test 3 attributionText"; + static final List ATTRIBUTION_TEXT_TEST_LIST1 = Arrays.asList(new String[] { ATTRIBUTION_TEXT_TEST_VALUE1, ATTRIBUTION_TEXT_TEST_VALUE2 }); + static final List ATTRIBUTION_TEXT_TEST_LIST2 = Arrays.asList(new String[] { ATTRIBUTION_TEXT_TEST_VALUE3 }); static final SoftwarePurpose ADDITIONAL_PURPOSE_TEST_VALUE1 = SoftwarePurpose.values()[0]; static final SoftwarePurpose ADDITIONAL_PURPOSE_TEST_VALUE2 = SoftwarePurpose.values()[1]; static final List ADDITIONAL_PURPOSE_TEST_LIST1 = Arrays.asList(new SoftwarePurpose[] { ADDITIONAL_PURPOSE_TEST_VALUE1, ADDITIONAL_PURPOSE_TEST_VALUE2 }); @@ -65,16 +69,15 @@ protected void tearDown() throws Exception { public static SoftwareArtifactBuilder builderForSoftwareArtifactTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SoftwareArtifactBuilder retval = new SoftwareArtifactBuilder(modelStore, objectUri, copyManager) - .setAttributionText(ATTRIBUTION_TEXT_TEST_VALUE) .setContentIdentifier(CONTENT_IDENTIFIER_TEST_VALUE) .setCopyrightText(COPYRIGHT_TEXT_TEST_VALUE) + .addAttributionText(ATTRIBUTION_TEXT_TEST_VALUE1) + .addAttributionText(ATTRIBUTION_TEXT_TEST_VALUE2) .setPrimaryPurpose(PRIMARY_PURPOSE_TEST_VALUE1) .addAdditionalPurpose(ADDITIONAL_PURPOSE_TEST_VALUE1) .addAdditionalPurpose(ADDITIONAL_PURPOSE_TEST_VALUE2) //TODO: Add in test values /******************** - .setConcludedLicense(new AnyLicenseInfo()) - .setDeclaredLicense(new AnyLicenseInfo()) ***************/ ; return retval; @@ -122,28 +125,6 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { // TODO change some parameters for negative tests } - /** - * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setConcludedLicense}. - */ - public void testSoftwareArtifactsetConcludedLicense() throws InvalidSPDXAnalysisException { - SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); -// testSoftwareArtifact.setConcludedLicense(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getConcludedLicense()); - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setDeclaredLicense}. - */ - public void testSoftwareArtifactsetDeclaredLicense() throws InvalidSPDXAnalysisException { - SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); -// testSoftwareArtifact.setDeclaredLicense(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSoftwareArtifact.getDeclaredLicense()); - fail("Not yet implemented"); - } - /** * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setPrimaryPurpose}. */ @@ -154,16 +135,6 @@ public void testSoftwareArtifactsetPrimaryPurpose() throws InvalidSPDXAnalysisEx assertEquals(Optional.of(PRIMARY_PURPOSE_TEST_VALUE2), testSoftwareArtifact.getPrimaryPurpose()); } - /** - * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setAttributionText}. - */ - public void testSoftwareArtifactsetAttributionText() throws InvalidSPDXAnalysisException { - SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(ATTRIBUTION_TEXT_TEST_VALUE), testSoftwareArtifact.getAttributionText()); - testSoftwareArtifact.setAttributionText("new attributionText value"); - assertEquals(Optional.of("new attributionText value"), testSoftwareArtifact.getAttributionText()); - } - /** * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#setContentIdentifier}. */ @@ -184,6 +155,17 @@ public void testSoftwareArtifactsetCopyrightText() throws InvalidSPDXAnalysisExc assertEquals(Optional.of("new copyrightText value"), testSoftwareArtifact.getCopyrightText()); } + /** + * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#getAttributionTexts}. + */ + public void testSoftwareArtifactgetAttributionTexts() throws InvalidSPDXAnalysisException { + SoftwareArtifact testSoftwareArtifact = builderForSoftwareArtifactTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(ATTRIBUTION_TEXT_TEST_LIST1, new ArrayList<>(testSoftwareArtifact.getAttributionTexts()))); + testSoftwareArtifact.getAttributionTexts().clear(); + testSoftwareArtifact.getAttributionTexts().addAll(ATTRIBUTION_TEXT_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(ATTRIBUTION_TEXT_TEST_LIST2, new ArrayList<>(testSoftwareArtifact.getAttributionTexts()))); + } + /** * Test method for {@link org.spdx.library.model.v3.software.SoftwareArtifact#getAdditionalPurpose}. */ diff --git a/src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java b/src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java index bc9c15dc1..06a99e1e5 100644 --- a/src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SoftwareDependencyRelationshipTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * diff --git a/src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java b/src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java index 81132984a..3fd5f9cb9 100644 --- a/src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SpdxFileTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,6 +42,7 @@ public class SpdxFileTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; + static final String CONTENT_TYPE_TEST_VALUE = "test contentType"; protected void setUp() throws Exception { super.setUp(); @@ -56,9 +57,9 @@ protected void tearDown() throws Exception { public static SpdxFileBuilder builderForSpdxFileTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SpdxFileBuilder retval = new SpdxFileBuilder(modelStore, objectUri, copyManager) + .setContentType(CONTENT_TYPE_TEST_VALUE) //TODO: Add in test values /******************** - .setContentType(new MediaType()) ***************/ ; return retval; @@ -111,9 +112,8 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { */ public void testSpdxFilesetContentType() throws InvalidSPDXAnalysisException { SpdxFile testSpdxFile = builderForSpdxFileTests(modelStore, TEST_OBJECT_URI, copyManager).build(); -// assertEquals(Optional.of(TEST_VALUE), testSpdxFile.getContentType()); -// testSpdxFile.setContentType(NEW_TEST_VALUE); -// assertEquals(Optional.of(NEW_TEST_VALUE), testSpdxFile.getContentType()); - fail("Not yet implemented"); + assertEquals(Optional.of(CONTENT_TYPE_TEST_VALUE), testSpdxFile.getContentType()); + testSpdxFile.setContentType("new contentType value"); + assertEquals(Optional.of("new contentType value"), testSpdxFile.getContentType()); } } \ No newline at end of file diff --git a/src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java b/src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java index eb89f3d0a..47ea96228 100644 --- a/src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java +++ b/src/test/java/org/spdx/library/model/v3/software/SpdxPackageTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2023 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -42,11 +42,11 @@ public class SpdxPackageTest extends TestCase { IModelStore modelStore; ModelCopyManager copyManager; - static final String SOURCE_INFO_TEST_VALUE = "test sourceInfo"; - static final String HOME_PAGE_TEST_VALUE = "test homePage"; - static final String PACKAGE_VERSION_TEST_VALUE = "test packageVersion"; static final String PACKAGE_URL_TEST_VALUE = "test packageUrl"; + static final String HOME_PAGE_TEST_VALUE = "test homePage"; static final String DOWNLOAD_LOCATION_TEST_VALUE = "test downloadLocation"; + static final String PACKAGE_VERSION_TEST_VALUE = "test packageVersion"; + static final String SOURCE_INFO_TEST_VALUE = "test sourceInfo"; protected void setUp() throws Exception { super.setUp(); @@ -61,11 +61,11 @@ protected void tearDown() throws Exception { public static SpdxPackageBuilder builderForSpdxPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { SpdxPackageBuilder retval = new SpdxPackageBuilder(modelStore, objectUri, copyManager) - .setSourceInfo(SOURCE_INFO_TEST_VALUE) - .setHomePage(HOME_PAGE_TEST_VALUE) - .setPackageVersion(PACKAGE_VERSION_TEST_VALUE) .setPackageUrl(PACKAGE_URL_TEST_VALUE) + .setHomePage(HOME_PAGE_TEST_VALUE) .setDownloadLocation(DOWNLOAD_LOCATION_TEST_VALUE) + .setPackageVersion(PACKAGE_VERSION_TEST_VALUE) + .setSourceInfo(SOURCE_INFO_TEST_VALUE) //TODO: Add in test values /******************** ***************/ @@ -116,13 +116,13 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setSourceInfo}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setPackageUrl}. */ - public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SOURCE_INFO_TEST_VALUE), testSpdxPackage.getSourceInfo()); - testSpdxPackage.setSourceInfo("new sourceInfo value"); - assertEquals(Optional.of("new sourceInfo value"), testSpdxPackage.getSourceInfo()); + assertEquals(Optional.of(PACKAGE_URL_TEST_VALUE), testSpdxPackage.getPackageUrl()); + testSpdxPackage.setPackageUrl("new packageUrl value"); + assertEquals(Optional.of("new packageUrl value"), testSpdxPackage.getPackageUrl()); } /** @@ -136,32 +136,32 @@ public void testSpdxPackagesetHomePage() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setPackageVersion}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setDownloadLocation}. */ - public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(PACKAGE_VERSION_TEST_VALUE), testSpdxPackage.getPackageVersion()); - testSpdxPackage.setPackageVersion("new packageVersion value"); - assertEquals(Optional.of("new packageVersion value"), testSpdxPackage.getPackageVersion()); + assertEquals(Optional.of(DOWNLOAD_LOCATION_TEST_VALUE), testSpdxPackage.getDownloadLocation()); + testSpdxPackage.setDownloadLocation("new downloadLocation value"); + assertEquals(Optional.of("new downloadLocation value"), testSpdxPackage.getDownloadLocation()); } /** - * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setPackageUrl}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setPackageVersion}. */ - public void testSpdxPackagesetPackageUrl() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetPackageVersion() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(PACKAGE_URL_TEST_VALUE), testSpdxPackage.getPackageUrl()); - testSpdxPackage.setPackageUrl("new packageUrl value"); - assertEquals(Optional.of("new packageUrl value"), testSpdxPackage.getPackageUrl()); + assertEquals(Optional.of(PACKAGE_VERSION_TEST_VALUE), testSpdxPackage.getPackageVersion()); + testSpdxPackage.setPackageVersion("new packageVersion value"); + assertEquals(Optional.of("new packageVersion value"), testSpdxPackage.getPackageVersion()); } /** - * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setDownloadLocation}. + * Test method for {@link org.spdx.library.model.v3.software.SpdxPackage#setSourceInfo}. */ - public void testSpdxPackagesetDownloadLocation() throws InvalidSPDXAnalysisException { + public void testSpdxPackagesetSourceInfo() throws InvalidSPDXAnalysisException { SpdxPackage testSpdxPackage = builderForSpdxPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(DOWNLOAD_LOCATION_TEST_VALUE), testSpdxPackage.getDownloadLocation()); - testSpdxPackage.setDownloadLocation("new downloadLocation value"); - assertEquals(Optional.of("new downloadLocation value"), testSpdxPackage.getDownloadLocation()); + assertEquals(Optional.of(SOURCE_INFO_TEST_VALUE), testSpdxPackage.getSourceInfo()); + testSpdxPackage.setSourceInfo("new sourceInfo value"); + assertEquals(Optional.of("new sourceInfo value"), testSpdxPackage.getSourceInfo()); } } \ No newline at end of file From 1f9fe7a316c34e45e9bb04580075eb641fad8b77 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Tue, 30 Apr 2024 17:23:41 -0700 Subject: [PATCH 24/62] Intermediate checkin for major refactoring Signed-off-by: Gary O'Neall --- pom.xml | 10 + .../org/spdx/library/DefaultModelStore.java | 108 -- .../library/DuplicateSpdxIdException.java | 69 - .../org/spdx/library/IndividualUriValue.java | 33 - .../library/InvalidSPDXAnalysisException.java | 71 - .../library/InvalidSpdxPropertyException.java | 72 - .../org/spdx/library/ModelCopyManager.java | 10 +- .../java/org/spdx/library/ModelManager.java | 52 + .../org/spdx/library/NotEquivalentReason.java | 74 - .../java/org/spdx/library/SimpleUriValue.java | 173 -- .../spdx/library/SpdxConstantsCompatV2.java | 413 ----- .../spdx/library/SpdxIdInUseException.java | 71 - .../spdx/library/SpdxIdNotFoundException.java | 72 - .../spdx/library/SpdxInvalidIdException.java | 73 - .../library/SpdxInvalidTypeException.java | 71 - .../org/spdx/library/SpdxModelFactory.java | 451 ------ .../SpdxObjectNotInStoreException.java | 71 - .../spdx/library/SpdxVerificationHelper.java | 308 ---- .../java/org/spdx/library/TypedValue.java | 79 - src/main/java/org/spdx/library/Version.java | 3 +- .../spdx/library/model/ExternalElement.java | 156 -- .../spdx/library/model/ModelCollection.java | 301 ---- .../org/spdx/library/model/ModelObject.java | 1009 ------------ .../spdx/library/model/ModelObjectHelper.java | 313 ---- .../java/org/spdx/library/model/ModelSet.java | 103 -- .../library/model/compat/v2/Annotation.java | 302 ---- .../library/model/compat/v2/Checksum.java | 274 ---- .../model/compat/v2/ExternalDocumentRef.java | 372 ----- .../library/model/compat/v2/ExternalRef.java | 382 ----- .../model/compat/v2/ExternalSpdxElement.java | 349 ---- .../model/compat/v2/GenericModelObject.java | 85 - .../model/compat/v2/GenericSpdxElement.java | 73 - .../model/compat/v2/GenericSpdxItem.java | 68 - .../model/compat/v2/ModelCollectionV2.java | 316 ---- .../library/model/compat/v2/ModelObject.java | 1432 ----------------- .../library/model/compat/v2/ModelSet.java | 100 -- .../compat/v2/ModelStorageClassConverter.java | 185 --- .../spdx/library/model/compat/v2/Read.java | 169 -- .../model/compat/v2/ReferenceType.java | 54 - .../compat/v2/RelatedElementCollection.java | 400 ----- .../library/model/compat/v2/Relationship.java | 271 ---- .../model/compat/v2/SpdxConstantElement.java | 130 -- .../compat/v2/SpdxCreatorInformation.java | 268 --- .../library/model/compat/v2/SpdxDocument.java | 348 ---- .../library/model/compat/v2/SpdxElement.java | 288 ---- .../library/model/compat/v2/SpdxFile.java | 544 ------- .../library/model/compat/v2/SpdxItem.java | 206 --- .../compat/v2/SpdxNoAssertionElement.java | 78 - .../model/compat/v2/SpdxNoneElement.java | 79 - .../library/model/compat/v2/SpdxPackage.java | 1221 -------------- .../v2/SpdxPackageVerificationCode.java | 135 -- .../library/model/compat/v2/SpdxSnippet.java | 619 ------- .../spdx/library/model/compat/v2/Write.java | 107 -- .../v2/enumerations/AnnotationType.java | 53 - .../v2/enumerations/ChecksumAlgorithm.java | 68 - .../compat/v2/enumerations/FileType.java | 62 - .../model/compat/v2/enumerations/Purpose.java | 62 - .../v2/enumerations/ReferenceCategory.java | 54 - .../v2/enumerations/RelationshipType.java | 96 -- .../enumerations/SpdxEnumFactoryCompatV2.java | 62 - .../compat/v2/enumerations/package-info.java | 27 - .../license/AbstractExtractedLicenseInfo.java | 110 -- .../compat/v2/license/AnyLicenseInfo.java | 76 - .../v2/license/ConjunctiveLicenseSet.java | 216 --- .../model/compat/v2/license/CrossRef.java | 435 ----- .../v2/license/DisjunctiveLicenseSet.java | 210 --- .../license/ExternalExtractedLicenseInfo.java | 317 ---- .../v2/license/ExtractedLicenseInfo.java | 154 -- .../InvalidLicenseStringException.java | 13 - .../model/compat/v2/license/License.java | 329 ---- .../compat/v2/license/LicenseException.java | 323 ---- .../v2/license/LicenseExpressionParser.java | 376 ----- .../compat/v2/license/LicenseInfoFactory.java | 171 -- .../v2/license/LicenseParserException.java | 22 - .../model/compat/v2/license/LicenseSet.java | 127 -- .../v2/license/ListedLicenseException.java | 138 -- .../compat/v2/license/ListedLicenses.java | 249 --- .../compat/v2/license/OrLaterOperator.java | 156 -- .../v2/license/SimpleLicensingInfo.java | 140 -- .../compat/v2/license/SpdxListedLicense.java | 369 ----- .../license/SpdxListedLicenseException.java | 71 - .../v2/license/SpdxNoAssertionLicense.java | 86 - .../compat/v2/license/SpdxNoneLicense.java | 86 - .../v2/license/WithExceptionOperator.java | 240 --- .../model/compat/v2/license/package-info.java | 24 - .../library/model/compat/v2/package-info.java | 25 - .../compat/v2/pointer/ByteOffsetPointer.java | 161 -- .../compat/v2/pointer/CompoundPointer.java | 125 -- .../compat/v2/pointer/LineCharPointer.java | 166 -- .../compat/v2/pointer/SinglePointer.java | 169 -- .../compat/v2/pointer/StartEndPointer.java | 222 --- .../model/compat/v2/pointer/package-info.java | 33 - .../compat/v2/ListedReferenceTypes.java | 203 --- .../compat/v2/listedreferencetypes.properties | 4 - .../referencetype/compat/v2/package-info.java | 24 - .../java/org/spdx/storage/IModelStore.java | 250 --- .../spdx/storage/ISerializableModelStore.java | 51 - .../org/spdx/storage/PropertyDescriptor.java | 90 -- .../v2/CompatibleModelStoreWrapper.java | 420 ----- .../java/org/spdx/storage/package-info.java | 25 - .../storage/simple/ExtendedSpdxStore.java | 33 +- .../spdx/storage/simple/InMemSpdxStore.java | 117 +- .../spdx/storage/simple/StoredTypedItem.java | 70 +- .../library/model/ModelObjectForTesting.java | 4 +- .../model/compat/v2/SpdxElementTest.java | 16 +- 105 files changed, 203 insertions(+), 19948 deletions(-) delete mode 100644 src/main/java/org/spdx/library/DefaultModelStore.java delete mode 100644 src/main/java/org/spdx/library/DuplicateSpdxIdException.java delete mode 100644 src/main/java/org/spdx/library/IndividualUriValue.java delete mode 100644 src/main/java/org/spdx/library/InvalidSPDXAnalysisException.java delete mode 100644 src/main/java/org/spdx/library/InvalidSpdxPropertyException.java create mode 100644 src/main/java/org/spdx/library/ModelManager.java delete mode 100644 src/main/java/org/spdx/library/NotEquivalentReason.java delete mode 100644 src/main/java/org/spdx/library/SimpleUriValue.java delete mode 100644 src/main/java/org/spdx/library/SpdxConstantsCompatV2.java delete mode 100644 src/main/java/org/spdx/library/SpdxIdInUseException.java delete mode 100644 src/main/java/org/spdx/library/SpdxIdNotFoundException.java delete mode 100644 src/main/java/org/spdx/library/SpdxInvalidIdException.java delete mode 100644 src/main/java/org/spdx/library/SpdxInvalidTypeException.java delete mode 100644 src/main/java/org/spdx/library/SpdxModelFactory.java delete mode 100644 src/main/java/org/spdx/library/SpdxObjectNotInStoreException.java delete mode 100644 src/main/java/org/spdx/library/SpdxVerificationHelper.java delete mode 100644 src/main/java/org/spdx/library/TypedValue.java delete mode 100644 src/main/java/org/spdx/library/model/ExternalElement.java delete mode 100644 src/main/java/org/spdx/library/model/ModelCollection.java delete mode 100644 src/main/java/org/spdx/library/model/ModelObject.java delete mode 100644 src/main/java/org/spdx/library/model/ModelObjectHelper.java delete mode 100644 src/main/java/org/spdx/library/model/ModelSet.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/Annotation.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/Checksum.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ModelObject.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ModelSet.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/Read.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/Relationship.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/Write.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/License.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/license/package-info.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/package-info.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java delete mode 100644 src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java delete mode 100644 src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java delete mode 100644 src/main/java/org/spdx/library/referencetype/compat/v2/listedreferencetypes.properties delete mode 100644 src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java delete mode 100644 src/main/java/org/spdx/storage/IModelStore.java delete mode 100644 src/main/java/org/spdx/storage/ISerializableModelStore.java delete mode 100644 src/main/java/org/spdx/storage/PropertyDescriptor.java delete mode 100644 src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java delete mode 100644 src/main/java/org/spdx/storage/package-info.java diff --git a/pom.xml b/pom.xml index 3f4f870ab..7a764ae25 100644 --- a/pom.xml +++ b/pom.xml @@ -160,6 +160,16 @@ jsr305 3.0.2 + + org.spdx + spdx-java-model-2_X + 0.0.1-SNAPSHOT + + + org.spdx + spdx-java-core + 0.0.1-SNAPSHOT + diff --git a/src/main/java/org/spdx/library/DefaultModelStore.java b/src/main/java/org/spdx/library/DefaultModelStore.java deleted file mode 100644 index 0b55997b4..000000000 --- a/src/main/java/org/spdx/library/DefaultModelStore.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import java.util.Objects; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.storage.IModelStore; -import org.spdx.storage.simple.InMemSpdxStore; - -/** - * @author Gary O'Neall - * - * Singleton class to hold a default model store used when no model store is provided - * - * WARNING: The model store is in memory and will continue to grow as it is utilized. There is NO garbage collection. - * - */ -public class DefaultModelStore { - - static IModelStore defaultModelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_3); - static String defaultDocumentUri = "http://www.spdx.org/documents/default_doc_uri_for_SPDX_tools"; - static ModelCopyManager defaultCopyManager = new ModelCopyManager(); - private static final ReadWriteLock lock = new ReentrantReadWriteLock(); - - private DefaultModelStore() { - // prevent instantiating class - } - - public static IModelStore getDefaultModelStore() { - lock.readLock().lock(); - try { - return defaultModelStore; - } finally { - lock.readLock().unlock(); - } - } - - public static String getDefaultDocumentUri() { - lock.readLock().lock(); - try { - return defaultDocumentUri; - } finally { - lock.readLock().unlock(); - } - } - - /** - * Clears the default model store by replacing the default model store with a new one - */ - public static final void reset(SpdxMajorVersion spdxSpecVersion) { - lock.writeLock().lock(); - try { - if (Objects.nonNull(defaultModelStore)) { - try { - defaultModelStore.close(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - defaultModelStore = new InMemSpdxStore(spdxSpecVersion); - defaultCopyManager = new ModelCopyManager(); - } finally { - lock.writeLock().unlock(); - } - } - - public static final void reset(IModelStore newModelStore, String newDefaultDocumentUri, ModelCopyManager newDefaultCopyManager) { - Objects.requireNonNull(newModelStore, "Model store can not be null"); - Objects.requireNonNull(newDefaultDocumentUri, "Document URI can not be null"); - Objects.requireNonNull(newDefaultCopyManager, "Copy manager can not be null"); - lock.writeLock().lock(); - try { - defaultModelStore = newModelStore; - defaultDocumentUri = newDefaultDocumentUri; - defaultCopyManager = newDefaultCopyManager; - } finally { - lock.writeLock().unlock(); - } - } - - public static ModelCopyManager getDefaultCopyManager() { - lock.readLock().lock(); - try { - return defaultCopyManager; - } finally { - lock.readLock().unlock(); - } - } - -} diff --git a/src/main/java/org/spdx/library/DuplicateSpdxIdException.java b/src/main/java/org/spdx/library/DuplicateSpdxIdException.java deleted file mode 100644 index 8e1de22b3..000000000 --- a/src/main/java/org/spdx/library/DuplicateSpdxIdException.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * @author gary - * - */ -public class DuplicateSpdxIdException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public DuplicateSpdxIdException() { - } - - /** - * @param arg0 - */ - public DuplicateSpdxIdException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public DuplicateSpdxIdException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public DuplicateSpdxIdException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public DuplicateSpdxIdException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/IndividualUriValue.java b/src/main/java/org/spdx/library/IndividualUriValue.java deleted file mode 100644 index 810621e51..000000000 --- a/src/main/java/org/spdx/library/IndividualUriValue.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * Classes which implement the IndividuallUriValue interface will be stored as a single value. Theses classes - * must NOT implement any properties themselves. Any such properties will be lost during storage and retrieval. - * - * @author Gary O'Neall - * - */ -public interface IndividualUriValue { - - /** - * @return a unique identifier for this value. Typically the namespace + the long name - */ - public String getIndividualURI(); -} diff --git a/src/main/java/org/spdx/library/InvalidSPDXAnalysisException.java b/src/main/java/org/spdx/library/InvalidSPDXAnalysisException.java deleted file mode 100644 index 282f6d448..000000000 --- a/src/main/java/org/spdx/library/InvalidSPDXAnalysisException.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * @author Gary O'Neall - * - * Exception for invalid SPDX Documents - * - */ -public class InvalidSPDXAnalysisException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public InvalidSPDXAnalysisException() { - } - - /** - * @param arg0 - */ - public InvalidSPDXAnalysisException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public InvalidSPDXAnalysisException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public InvalidSPDXAnalysisException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public InvalidSPDXAnalysisException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/InvalidSpdxPropertyException.java b/src/main/java/org/spdx/library/InvalidSpdxPropertyException.java deleted file mode 100644 index 9d8492e7b..000000000 --- a/src/main/java/org/spdx/library/InvalidSpdxPropertyException.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * @author Gary O'Neall - * - * Invalid property name or value for an SPDX item - * - */ -public class InvalidSpdxPropertyException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public InvalidSpdxPropertyException() { - super(); - } - - /** - * @param arg0 - */ - public InvalidSpdxPropertyException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public InvalidSpdxPropertyException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public InvalidSpdxPropertyException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public InvalidSpdxPropertyException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index 403537d3d..36d5ea41b 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -27,7 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; +import org.spdx.core.IModelCopyManager; +import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -44,7 +45,7 @@ * @author Gary O'Neall * */ -public class ModelCopyManager { +public class ModelCopyManager implements IModelCopyManager { static final Logger logger = LoggerFactory.getLogger(ModelCopyManager.class); @@ -145,6 +146,7 @@ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, * @param fromDocumentUri Document URI for the source item * @param fromId ID source ID * @param type Type to copy + * @param toSpecVersion version of the spec the to value should comply with * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses * @param fromNamespace optional namespace of the from property * @param toNamespace optional namespace of the to property @@ -154,7 +156,7 @@ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, */ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri, - String type, boolean excludeLicenseDetails, + String type, boolean excludeLicenseDetails, String toSpecVersion, @Nullable String fromNamespace, @Nullable String toNamespace, @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { @@ -167,7 +169,7 @@ public void copy(IModelStore toStore, String toObjectUri, return; // trying to copy the same thing! } if (!toStore.exists(toObjectUri)) { - toStore.create(toObjectUri, type); + toStore.create(toObjectUri, type, toSpecVersion); } putCopiedId(fromStore, fromObjectUri, toStore, toObjectUri, toNamespace); if (!(excludeLicenseDetails && diff --git a/src/main/java/org/spdx/library/ModelManager.java b/src/main/java/org/spdx/library/ModelManager.java new file mode 100644 index 000000000..0e9ec2d3a --- /dev/null +++ b/src/main/java/org/spdx/library/ModelManager.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import org.spdx.core.ModelRegistry; +import org.spdx.library.model.v2.SpdxModelInfoV2_X; + +/** + * Main entrypoint for the SPDX Java Library + * + * This is a static class used to manage the different versions of the SPDX spec by + * creating different model classes based on the version of the spec. + * + * Since the release of the SPDX spec version 3.0, the Java classes were generated. + * + * Each generated set of classes generated for a specific version are in a separate library / Jar file. + * + * These generated classes are registered in the Core model registry + * + * @author Gary O'Neall + * + */ +public class ModelManager { + + static { + // register the supported spec version models + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV2_X()); + } + + /** + * Static class private constructor + */ + private ModelManager() { + // Static class + } + +} diff --git a/src/main/java/org/spdx/library/NotEquivalentReason.java b/src/main/java/org/spdx/library/NotEquivalentReason.java deleted file mode 100644 index edaf564a5..000000000 --- a/src/main/java/org/spdx/library/NotEquivalentReason.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import org.spdx.storage.PropertyDescriptor; - -/** - * @author Gary O'Neall - * - * Primarily used for debugging. Records details when two model objects are compared and are determined to not - * be equivalent - * - */ -public class NotEquivalentReason { - - public enum NotEquivalent { - DIFFERENT_CLASS, MISSING_PROPERTY, PROPERTY_NOT_EQUIVALENT, COMPARE_PROPERTY_MISSING}; - - NotEquivalent reason; - PropertyDescriptor property = null; - - public NotEquivalentReason(NotEquivalent reason) { - this.reason = reason; - } - - public NotEquivalentReason(NotEquivalent reason, PropertyDescriptor property) { - this(reason); - this.property = property; - } - - /** - * @return the reason - */ - public NotEquivalent getReason() { - return reason; - } - - /** - * @param reason the reason to set - */ - public void setReason(NotEquivalent reason) { - this.reason = reason; - } - - /** - * @return the property - */ - public PropertyDescriptor getProperty() { - return property; - } - - /** - * @param property the property to set - */ - public void setProperty(PropertyDescriptor property) { - this.property = property; - } - -} diff --git a/src/main/java/org/spdx/library/SimpleUriValue.java b/src/main/java/org/spdx/library/SimpleUriValue.java deleted file mode 100644 index 3bbec28f5..000000000 --- a/src/main/java/org/spdx/library/SimpleUriValue.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.ExternalElement; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.storage.IModelStore; - -/** - * Simple class to just store a URI value. The method toModelObject will convert / inflate the value back to - * either an Enum (if the URI matches), an ExternalSpdxElement if it matches the pattern of an external SPDX element - * or returns itself otherwise - * - * @author Gary O'Neall - * - */ -public class SimpleUriValue implements IndividualUriValue { - - static final Logger logger = LoggerFactory.getLogger(SimpleUriValue.class); - - private String uri; - - /** - * returns hash based on URI of the IndividualUriValue - * @param individualUri IndividualUriValue to obtain a hash from - * @return hash based on URI of the IndividualUriValue - */ - public static int getIndividualUriValueHash(IndividualUriValue individualUri) { - return 11 ^ individualUri.getIndividualURI().hashCode(); - } - - /** - * Compares an object to an individual URI and returns true if the URI values are equal - * @param individualUri IndividualUriValue to compare - * @param comp Object to compare - * @return true if the individualUri has the same URI as comp and comp is of type IndividualUriValue - */ - public static boolean isIndividualUriValueEquals(IndividualUriValue individualUri, Object comp) { - if (!(comp instanceof IndividualUriValue)) { - return false; - } - return Objects.equals(individualUri.getIndividualURI(), ((IndividualUriValue)comp).getIndividualURI()); - } - - public SimpleUriValue(IndividualUriValue fromIndividualValue) throws InvalidSPDXAnalysisException { - this(fromIndividualValue.getIndividualURI()); - } - - public SimpleUriValue(String uri) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(uri, "URI can not be null"); - this.uri = uri; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.IndividualValue#getIndividualURI() - */ - @Override - public String getIndividualURI() { - return uri; - } - - /** - * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if the uri is found in the - * externalMap or if it matches the pattern of a V2 compatible external SPDX element, an Individual object, or returns itself otherwise - * @param store store to use for the inflated object - * @param copyManager if non-null, implicitly copy any referenced properties from other model stores - * @param defaultNamespace optional document namespace when creating V2 compatible external document references - * @param externalMap map of URI's to ExternalMaps for any external elements - * @return Enum, ExternalSpdxElement or itself depending on the pattern - * @throws InvalidSPDXAnalysisException on any store or parsing error - */ - public Object toModelObject(IModelStore store, ModelCopyManager copyManager, @Nullable String defaultNamespace, - @Nullable Map externalMap) throws InvalidSPDXAnalysisException { - if (store.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) < 0) { - if (Objects.isNull(defaultNamespace)) { - logger.error("Default namespace can not be null for SPDX 2 model stores"); - throw new InvalidSPDXAnalysisException("Default namespace can not be null for SPDX 2 model stores"); - } - return toModelObjectV2Compat(store, defaultNamespace, copyManager); - } else { - return toModelObject(store, copyManager, Objects.isNull(externalMap) ? new HashMap<>() : externalMap); - } - } - - /** - * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if the uri is found in the - * externalMap, an Individual object, or returns itself otherwise - * @param store store to use for the inflated object - * @param copyManager if non-null, implicitly copy any referenced properties from other model stores - * @param externalMap map of URI's to ExternalMaps for any external elements - * @return Enum, ExternalSpdxElement, individual or itself depending on the pattern - * @throws InvalidSPDXAnalysisException on any store or parsing error - */ - private Object toModelObject(IModelStore store, ModelCopyManager copyManager, Map externalMap) throws InvalidSPDXAnalysisException { - Object retval = SpdxEnumFactory.uriToEnum.get(uri); - if (Objects.nonNull(retval)) { - return retval; - } else if (externalMap.containsKey(uri)) { - return new ExternalElement(store, uri, copyManager, externalMap.get(uri)); - } else if (SpdxIndividualFactory.uriToIndividual.containsKey(uri)) { - return SpdxIndividualFactory.uriToIndividual.get(uri); - } else { - logger.warn("URI "+uri+" does not match any model object or enumeration"); - return this; - } - } - - /** - * inflate the value back to either an Enum (if the URI matches), an ExternalSpdxElement if it matches the pattern of an external SPDX element - * or returns itself otherwise - * @param store store to store the inflated object - * @param documentUri document URI to use if creating an external document reference - * @param copyManager if non-null, implicitly copy any referenced properties from other model stores - * @return Enum, ExternalSpdxElement or itself depending on the pattern - * @throws InvalidSPDXAnalysisException on any store or parsing error - */ - private Object toModelObjectV2Compat(IModelStore store, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Object retval = SpdxEnumFactoryCompatV2.uriToEnum.get(uri); - if (Objects.nonNull(retval)) { - return retval; - } else if (SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri).matches()) { - return org.spdx.library.model.compat.v2.ExternalSpdxElement.uriToExternalSpdxElement(uri, store, documentUri, copyManager); - } else if (SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri).matches()) { - return org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.uriToExternalExtractedLicense(uri, store, documentUri, copyManager); - } else if (SpdxConstantsCompatV2.REFERENCE_TYPE_URI_PATTERN.matcher(uri).matches()) { - return new org.spdx.library.model.compat.v2.ReferenceType(this); - } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { - // Default value is a license, although it can also be a string or an SpdxElement - // the caller should override the type based on the type expected - return new org.spdx.library.model.compat.v2.license.SpdxNoneLicense(store, documentUri); - } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - return new org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense(store, documentUri); - } else { - logger.warn("URI "+uri+" does not match any model object or enumeration"); - return this; - } - } - - @Override - public boolean equals(Object comp) { - return isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return getIndividualUriValueHash(this); - } -} diff --git a/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java b/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java deleted file mode 100644 index bf05d211a..000000000 --- a/src/main/java/org/spdx/library/SpdxConstantsCompatV2.java +++ /dev/null @@ -1,413 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.spdx.library; - -import java.util.regex.Pattern; - -import org.spdx.storage.PropertyDescriptor; - - -/** - * Constants which map to the SPDX specifications for versions prior to SPDX Spec version 3.0 - * @author Gary O'Neall - * - */ -public class SpdxConstantsCompatV2 { - - public static final String SPDX_VERSION_2 = "2"; - - // Namespaces - public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; - public static final String RDFS_NAMESPACE = "http://www.w3.org/2000/01/rdf-schema#"; - public static final String SPDX_NAMESPACE = "http://spdx.org/rdf/terms#"; - public static final String DOAP_NAMESPACE = "http://usefulinc.com/ns/doap#"; - public static final String OWL_NAMESPACE = "http://www.w3.org/2002/07/owl#"; - public static final String RDF_POINTER_NAMESPACE = "http://www.w3.org/2009/pointers#"; - public static final String XML_SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema#"; - - // RDF Properties - within the RDF_NAMESPACE - public static final PropertyDescriptor RDF_PROP_TYPE = new PropertyDescriptor("type", RDF_NAMESPACE); - public static final PropertyDescriptor RDF_PROP_RESOURCE = new PropertyDescriptor("resource", RDF_NAMESPACE); - public static final String[] RDF_PROPERTIES = new String[] {RDF_PROP_TYPE.getName(), RDF_PROP_RESOURCE.getName()}; - - - // OWL Properties - within the OWL_NAMESPACE - public static final PropertyDescriptor PROP_OWL_SAME_AS = new PropertyDescriptor("sameAs", OWL_NAMESPACE); - public static final String[] OWL_PROPERTIES = new String[] {PROP_OWL_SAME_AS.getName()}; - - // RDFS Properties - within the RDFS_NAMESPACE - public static final PropertyDescriptor RDFS_PROP_COMMENT = new PropertyDescriptor("comment", RDFS_NAMESPACE); - public static final PropertyDescriptor RDFS_PROP_LABEL = new PropertyDescriptor("label", RDFS_NAMESPACE); - public static final PropertyDescriptor RDFS_PROP_SEE_ALSO = new PropertyDescriptor("seeAlso", RDFS_NAMESPACE); - public static final String[] RDFS_PROPERTIES = new String[] {RDFS_PROP_COMMENT.getName(), - RDFS_PROP_LABEL.getName(), RDFS_PROP_SEE_ALSO.getName()}; - - // DOAP Class Names - within the DOAP_NAMESPACE - public static final String CLASS_DOAP_PROJECT = "Project"; - public static final String[] DOAP_CLASSES = {CLASS_DOAP_PROJECT}; - - // DOAP Project Property Names - within the DOAP_NAMESPACE - public static final PropertyDescriptor PROP_PROJECT_HOMEPAGE = new PropertyDescriptor("homepage", DOAP_NAMESPACE); - public static final String[] DOAP_PROPERTIES = new String[] {PROP_PROJECT_HOMEPAGE.getName()}; - - // Pointer Class Names - with in the RDF_POINTER_NAMESPACE - public static final String CLASS_POINTER_START_END_POINTER = "StartEndPointer"; - public static final String CLASS_POINTER_BYTE_OFFSET_POINTER = "ByteOffsetPointer"; - public static final String CLASS_POINTER_LINE_CHAR_POINTER = "LineCharPointer"; - public static final String CLASS_POINTER_COMPOUNT_POINTER = "CompoundPointer"; - public static final String CLASS_SINGLE_POINTER = "SinglePointer"; - public static final String[] POINTER_CLASSES = new String[] { - CLASS_POINTER_START_END_POINTER, CLASS_POINTER_BYTE_OFFSET_POINTER, - CLASS_POINTER_LINE_CHAR_POINTER, CLASS_POINTER_COMPOUNT_POINTER, CLASS_SINGLE_POINTER - }; - - // Pointer Properties - with in the RDF_POINTER_NAMESPACE - public static final PropertyDescriptor PROP_POINTER_START_POINTER = new PropertyDescriptor("startPointer", RDF_POINTER_NAMESPACE); - public static final PropertyDescriptor PROP_POINTER_END_POINTER = new PropertyDescriptor("endPointer", RDF_POINTER_NAMESPACE); - public static final PropertyDescriptor PROP_POINTER_REFERENCE = new PropertyDescriptor("reference", RDF_POINTER_NAMESPACE); - public static final PropertyDescriptor PROP_POINTER_OFFSET = new PropertyDescriptor("offset", RDF_POINTER_NAMESPACE); - public static final PropertyDescriptor PROP_POINTER_LINE_NUMBER = new PropertyDescriptor("lineNumber", RDF_POINTER_NAMESPACE); - public static final String[] POINTER_PROPERTIES = new String[] { - PROP_POINTER_START_POINTER.getName(), PROP_POINTER_END_POINTER.getName(), - PROP_POINTER_REFERENCE.getName(), PROP_POINTER_OFFSET.getName(), - PROP_POINTER_LINE_NUMBER.getName() - }; - - // SPDX Class Names - public static final String CLASS_SPDX_DOCUMENT = "SpdxDocument"; - public static final String CLASS_SPDX_PACKAGE = "Package"; - public static final String CLASS_SPDX_CREATION_INFO = "CreationInfo"; - public static final String CLASS_SPDX_CHECKSUM = "Checksum"; - public static final String CLASS_SPDX_ANY_LICENSE_INFO = "AnyLicenseInfo"; - public static final String CLASS_SPDX_SIMPLE_LICENSE_INFO = "SimpleLicensingInfo"; - public static final String CLASS_SPDX_CONJUNCTIVE_LICENSE_SET = "ConjunctiveLicenseSet"; - public static final String CLASS_SPDX_DISJUNCTIVE_LICENSE_SET = "DisjunctiveLicenseSet"; - public static final String CLASS_SPDX_EXTRACTED_LICENSING_INFO = "ExtractedLicensingInfo"; - public static final String CLASS_SPDX_LICENSE = "License"; - public static final String CLASS_SPDX_LISTED_LICENSE = "ListedLicense"; - public static final String CLASS_SPDX_LICENSE_EXCEPTION = "LicenseException"; - public static final String CLASS_SPDX_LISTED_LICENSE_EXCEPTION = "ListedLicenseException"; - public static final String CLASS_OR_LATER_OPERATOR = "OrLaterOperator"; - public static final String CLASS_WITH_EXCEPTION_OPERATOR = "WithExceptionOperator"; - public static final String CLASS_SPDX_FILE = "File"; - public static final String CLASS_SPDX_REVIEW = "Review"; - public static final String CLASS_SPDX_VERIFICATIONCODE = "PackageVerificationCode"; - public static final String CLASS_ANNOTATION = "Annotation"; - public static final String CLASS_RELATIONSHIP = "Relationship"; - public static final String CLASS_SPDX_ITEM = "SpdxItem"; - public static final String CLASS_SPDX_ELEMENT = "SpdxElement"; - public static final String CLASS_SPDX_NONE_ELEMENT = "SpdxNoneElement"; - public static final String CLASS_SPDX_NOASSERTION_ELEMENT = "SpdxNoAssertionElement"; - public static final String CLASS_EXTERNAL_DOC_REF = "ExternalDocumentRef"; - public static final String CLASS_SPDX_EXTERNAL_REFERENCE = "ExternalRef"; - public static final String CLASS_SPDX_REFERENCE_TYPE = "ReferenceType"; - public static final String CLASS_SPDX_SNIPPET = "Snippet"; - public static final String CLASS_NONE_LICENSE = "SpdxNoneLicense"; - public static final String CLASS_NOASSERTION_LICENSE = "SpdxNoAssertionLicense"; - public static final String CLASS_EXTERNAL_SPDX_ELEMENT = "ExternalSpdxElement"; - public static final String CLASS_EXTERNAL_EXTRACTED_LICENSE = "ExternalExtractedLicenseInfo"; - public static final String CLASS_CROSS_REF = "CrossRef"; - - // all classes used including classes in non-SPDX namespaces - public static final String[] ALL_SPDX_CLASSES = {CLASS_SPDX_DOCUMENT, CLASS_SPDX_PACKAGE, - CLASS_SPDX_CREATION_INFO, CLASS_SPDX_CHECKSUM, CLASS_SPDX_ANY_LICENSE_INFO, - CLASS_SPDX_SIMPLE_LICENSE_INFO, CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, - CLASS_SPDX_EXTRACTED_LICENSING_INFO, CLASS_SPDX_LICENSE, CLASS_SPDX_LISTED_LICENSE, - CLASS_SPDX_LICENSE_EXCEPTION, CLASS_SPDX_LISTED_LICENSE_EXCEPTION, CLASS_OR_LATER_OPERATOR, CLASS_WITH_EXCEPTION_OPERATOR, - CLASS_SPDX_FILE, CLASS_SPDX_REVIEW, CLASS_SPDX_VERIFICATIONCODE, CLASS_ANNOTATION, - CLASS_RELATIONSHIP, CLASS_SPDX_ITEM, CLASS_SPDX_ELEMENT, - CLASS_SPDX_NONE_ELEMENT, CLASS_SPDX_NOASSERTION_ELEMENT, CLASS_EXTERNAL_DOC_REF, - CLASS_SPDX_EXTERNAL_REFERENCE, CLASS_SPDX_REFERENCE_TYPE, CLASS_SPDX_SNIPPET, - CLASS_NONE_LICENSE, CLASS_NOASSERTION_LICENSE, CLASS_EXTERNAL_SPDX_ELEMENT, - CLASS_EXTERNAL_EXTRACTED_LICENSE, CLASS_CROSS_REF, - // DOAP Namespace - CLASS_DOAP_PROJECT, - // RDF Pointer Namespace - CLASS_POINTER_START_END_POINTER, CLASS_POINTER_BYTE_OFFSET_POINTER, - CLASS_POINTER_COMPOUNT_POINTER, CLASS_POINTER_LINE_CHAR_POINTER, CLASS_SINGLE_POINTER}; - - // classes that use the listed license URI for their namespace - public static final String[] LISTED_LICENSE_URI_CLASSES = {CLASS_SPDX_LISTED_LICENSE, CLASS_SPDX_LISTED_LICENSE_EXCEPTION}; - - // Enumeration class names - public static final String ENUM_FILE_TYPE = "FileType"; - public static final String ENUM_ANNOTATION_TYPE = "AnnotationType"; - public static final String ENUM_CHECKSUM_ALGORITHM_TYPE = "ChecksumAlgorithm"; - public static final String ENUM_REFERENCE_CATEGORY_TYPE = "ReferenceCategory"; - public static final String ENUM_REFERENCE_RELATIONSHIP_TYPE = "RelationshipType"; - public static final String ENUM_PURPOSE = "Purpose"; - // General SPDX Properties - public static final PropertyDescriptor PROP_VALUE_NONE = new PropertyDescriptor("none", SPDX_NAMESPACE); - public static final String URI_VALUE_NONE = PROP_VALUE_NONE.toString(); - public static final PropertyDescriptor PROP_VALUE_NOASSERTION = new PropertyDescriptor("noassertion", SPDX_NAMESPACE); - public static final String URI_VALUE_NOASSERTION = PROP_VALUE_NOASSERTION.toString(); - public static final String SPDX_IDENTIFIER = "SPDXID"; - public static final String EXTERNAL_DOCUMENT_REF_IDENTIFIER = "externalDocumentId"; - - // SPDX Document Properties - // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - public static final PropertyDescriptor PROP_SPDX_REVIEWED_BY = new PropertyDescriptor("reviewed", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_EXTRACTED_LICENSES = new PropertyDescriptor("hasExtractedLicensingInfo", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_VERSION = new PropertyDescriptor("specVersion", SPDX_NAMESPACE); // TODO: Migrate this to PROP_SPDX_SPEC_VERSION in 3.0. See issue - public static final PropertyDescriptor PROP_SPDX_SPEC_VERSION = new PropertyDescriptor("spdxVersion", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_CREATION_INFO = new PropertyDescriptor("creationInfo", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_PACKAGE = new PropertyDescriptor("describesPackage", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_DATA_LICENSE = new PropertyDescriptor("dataLicense", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_EXTERNAL_DOC_REF = new PropertyDescriptor("externalDocumentRef", SPDX_NAMESPACE); - public static final String SPDX_DOCUMENT_ID = "SPDXRef-DOCUMENT"; - public static final PropertyDescriptor PROP_DOCUMENT_NAMESPACE = new PropertyDescriptor("documentNamespace", SPDX_NAMESPACE); - - // SPDX Document properties for JSON and YAML files - public static final PropertyDescriptor PROP_DOCUMENT_DESCRIBES = new PropertyDescriptor("documentDescribes", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # - public static final PropertyDescriptor PROP_DOCUMENT_FILES = new PropertyDescriptor("files", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # - public static final PropertyDescriptor PROP_DOCUMENT_PACKAGES = new PropertyDescriptor("packages", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # - public static final PropertyDescriptor PROP_DOCUMENT_SNIPPETS = new PropertyDescriptor("snippets", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # - public static final PropertyDescriptor PROP_DOCUMENT_RELATIONSHIPS = new PropertyDescriptor("relationships", SPDX_NAMESPACE); //TODO: This is not yet approved in the spec - see issue # - - // SPDX CreationInfo Properties - // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - public static final PropertyDescriptor PROP_CREATION_CREATOR = new PropertyDescriptor("creator", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CREATION_CREATED = new PropertyDescriptor("created", SPDX_NAMESPACE); // creation timestamp - public static final PropertyDescriptor PROP_LICENSE_LIST_VERSION = new PropertyDescriptor("licenseListVersion", SPDX_NAMESPACE); - public static final String CREATOR_PREFIX_PERSON = "Person:"; - public static final String CREATOR_PREFIX_ORGANIZATION = "Organization:"; - public static final String CREATOR_PREFIX_TOOL = "Tool:"; - - // SPDX Checksum Properties - public static final PropertyDescriptor PROP_CHECKSUM_ALGORITHM = new PropertyDescriptor("algorithm", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CHECKSUM_VALUE = new PropertyDescriptor("checksumValue", SPDX_NAMESPACE); - public static final String ALGORITHM_SHA1 = "SHA1"; - public static final String PROP_CHECKSUM_ALGORITHM_SHA1 = "checksumAlgorithm_sha1"; - - // SPDX PackageVerificationCode Properties - public static final PropertyDescriptor PROP_VERIFICATIONCODE_IGNORED_FILES = new PropertyDescriptor("packageVerificationCodeExcludedFile", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_VERIFICATIONCODE_VALUE = new PropertyDescriptor("packageVerificationCodeValue", SPDX_NAMESPACE); - - // SPDX Element Properties - public static final PropertyDescriptor PROP_ANNOTATION = new PropertyDescriptor("annotation", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_RELATIONSHIP = new PropertyDescriptor("relationship", SPDX_NAMESPACE); - - // SPDX Item Properties - public static final PropertyDescriptor PROP_LICENSE_CONCLUDED = new PropertyDescriptor("licenseConcluded", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_COPYRIGHT_TEXT = new PropertyDescriptor("copyrightText", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LIC_COMMENTS = new PropertyDescriptor("licenseComments", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_DECLARED = new PropertyDescriptor("licenseDeclared", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_ATTRIBUTION_TEXT = new PropertyDescriptor("attributionText", SPDX_NAMESPACE); - - // SPDX Package Properties - public static final PropertyDescriptor PROP_PACKAGE_DECLARED_NAME = new PropertyDescriptor("name", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_FILE_NAME = new PropertyDescriptor("packageFileName", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_CHECKSUM = new PropertyDescriptor("checksum", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_DOWNLOAD_URL = new PropertyDescriptor("downloadLocation", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_SOURCE_INFO = new PropertyDescriptor("sourceInfo", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_DECLARED_LICENSE = new PropertyDescriptor("licenseDeclared", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_CONCLUDED_LICENSE = PROP_LICENSE_CONCLUDED; - public static final PropertyDescriptor PROP_PACKAGE_DECLARED_COPYRIGHT = PROP_COPYRIGHT_TEXT; - public static final PropertyDescriptor PROP_PACKAGE_SHORT_DESC = new PropertyDescriptor("summary", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_DESCRIPTION = new PropertyDescriptor("description", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_FILE = new PropertyDescriptor("hasFile", SPDX_NAMESPACE);; - public static final PropertyDescriptor PROP_PACKAGE_VERIFICATION_CODE = new PropertyDescriptor("packageVerificationCode", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_LICENSE_INFO_FROM_FILES = new PropertyDescriptor("licenseInfoFromFiles", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_LICENSE_COMMENT = new PropertyDescriptor("licenseComments", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_VERSION_INFO = new PropertyDescriptor("versionInfo", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_ORIGINATOR = new PropertyDescriptor("originator", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_SUPPLIER = new PropertyDescriptor("supplier", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PACKAGE_FILES_ANALYZED = new PropertyDescriptor("filesAnalyzed", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXTERNAL_REF = new PropertyDescriptor("externalRef", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_PRIMARY_PACKAGE_PURPOSE = new PropertyDescriptor("primaryPackagePurpose", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_BUILT_DATE = new PropertyDescriptor("builtDate", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_RELEASE_DATE = new PropertyDescriptor("releaseDate", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_VALID_UNTIL_DATE = new PropertyDescriptor("validUntilDate", SPDX_NAMESPACE); - public static final Pattern REFERENCE_TYPE_URI_PATTERN = Pattern.compile("https?://spdx.org/rdf/references/.+"); - - // SPDX License Properties - // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - // the seeAlso property is in the RDFS_PROP_SEE_ALSO property in the rdfs namespace - public static final PropertyDescriptor PROP_LICENSE_ID = new PropertyDescriptor("licenseId", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_TEXT = new PropertyDescriptor("licenseText", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_TEXT_HTML = new PropertyDescriptor("licenseTextHtml", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXTRACTED_TEXT = new PropertyDescriptor("extractedText", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_NAME = new PropertyDescriptor("licenseName", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_NAME_VERSION_1 = new PropertyDescriptor("licenseName", SPDX_NAMESPACE); // old property name (pre 1.1 spec) - public static final PropertyDescriptor PROP_STD_LICENSE_NAME = new PropertyDescriptor("name", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_URL_VERSION_1 = new PropertyDescriptor("licenseSourceUrl", SPDX_NAMESPACE); // This has been replaced with the rdfs:seeAlso property - public static final PropertyDescriptor PROP_STD_LICENSE_NOTES_VERSION_1 = new PropertyDescriptor("licenseNotes", SPDX_NAMESPACE); // old property name (pre 1.1 spec) - public static final PropertyDescriptor PROP_STD_LICENSE_HEADER_VERSION_1 = new PropertyDescriptor("licenseHeader", SPDX_NAMESPACE); // old property name (pre 1.1 spec) - public static final PropertyDescriptor PROP_STD_LICENSE_NOTICE = new PropertyDescriptor("standardLicenseHeader", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_HEADER_TEMPLATE = new PropertyDescriptor("standardLicenseHeaderTemplate", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_HEADER_HTML = new PropertyDescriptor("standardLicenseHeaderHtml", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_TEMPLATE_VERSION_1 = new PropertyDescriptor("licenseTemplate", SPDX_NAMESPACE); // old property name (pre 1.2 spec) - public static final PropertyDescriptor PROP_STD_LICENSE_TEMPLATE = new PropertyDescriptor("standardLicenseTemplate", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_OSI_APPROVED = new PropertyDescriptor("isOsiApproved", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_FSF_LIBRE = new PropertyDescriptor("isFsfLibre", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_STD_LICENSE_OSI_APPROVED_VERSION_1 = new PropertyDescriptor("licenseOsiApproved", SPDX_NAMESPACE); // old property name (pre 1.1 spec) - public static final PropertyDescriptor PROP_LICENSE_SET_MEMEBER = new PropertyDescriptor("member", SPDX_NAMESPACE); - public static final String TERM_LICENSE_NOASSERTION = PROP_VALUE_NOASSERTION.getName(); - public static final String TERM_LICENSE_NONE = PROP_VALUE_NONE.getName(); - public static final PropertyDescriptor PROP_LICENSE_EXCEPTION_ID = new PropertyDescriptor("licenseExceptionId", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXAMPLE = new PropertyDescriptor("example", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXCEPTION_TEXT = new PropertyDescriptor("licenseExceptionText", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXCEPTION_TEXT_HTML = new PropertyDescriptor("exceptionTextHtml", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXCEPTION_TEMPLATE = new PropertyDescriptor("licenseExceptionTemplate", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_EXCEPTION = new PropertyDescriptor("licenseException", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LIC_ID_DEPRECATED = new PropertyDescriptor("isDeprecatedLicenseId", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LIC_DEPRECATED_VERSION = new PropertyDescriptor("deprecatedVersion", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF = new PropertyDescriptor("crossRef", SPDX_NAMESPACE); - - // SPDX Listed License constants - public static final String LISTED_LICENSE_URL = "https://spdx.org/licenses/"; - // http rather than https since RDF depends on the exact string, - // we were not able to update the namespace variable to match the URL's. - public static final String LISTED_LICENSE_NAMESPACE_PREFIX = "http://spdx.org/licenses/"; - - // crossrefs details (crossRef) properties - public static final PropertyDescriptor PROP_CROSS_REF_IS_VALID = new PropertyDescriptor("isValid", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF_WAYBACK_LINK = new PropertyDescriptor("isWayBackLink", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF_MATCH = new PropertyDescriptor("match", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF_URL = new PropertyDescriptor("url", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF_IS_LIVE = new PropertyDescriptor("isLive", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF_TIMESTAMP = new PropertyDescriptor("timestamp", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_CROSS_REF_ORDER = new PropertyDescriptor("order", SPDX_NAMESPACE); - - // SpdxElement Properties - public static final PropertyDescriptor PROP_NAME = new PropertyDescriptor("name", SPDX_NAMESPACE); - - // SPDX File Properties - // The comment property is the RDFS_PROP_COMMENT property in the rdfs namespace - public static final PropertyDescriptor PROP_FILE_NAME = new PropertyDescriptor("fileName", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_TYPE = new PropertyDescriptor("fileType", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_LICENSE = PROP_LICENSE_CONCLUDED; - public static final PropertyDescriptor PROP_FILE_COPYRIGHT = PROP_COPYRIGHT_TEXT; - public static final PropertyDescriptor PROP_FILE_CHECKSUM = new PropertyDescriptor("checksum", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_SEEN_LICENSE = new PropertyDescriptor("licenseInfoInFile", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_LIC_COMMENTS = PROP_LIC_COMMENTS; - public static final PropertyDescriptor PROP_FILE_ARTIFACTOF = new PropertyDescriptor("artifactOf", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_FILE_DEPENDENCY = new PropertyDescriptor("fileDependency", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_CONTRIBUTOR = new PropertyDescriptor("fileContributor", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_FILE_NOTICE = new PropertyDescriptor("noticeText", SPDX_NAMESPACE); - - // SPDX Snippet Properties - public static final PropertyDescriptor PROP_SNIPPET_FROM_FILE = new PropertyDescriptor("snippetFromFile", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SNIPPET_RANGE = new PropertyDescriptor("range", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_LICENSE_INFO_FROM_SNIPPETS = new PropertyDescriptor("licenseInfoInSnippet", SPDX_NAMESPACE); - - // SPDX File Type Properties - public static final String PROP_FILE_TYPE_SOURCE = "fileType_source"; - public static final String PROP_FILE_TYPE_ARCHIVE = "fileType_archive"; - public static final String PROP_FILE_TYPE_BINARY = "fileType_binary"; - public static final String PROP_FILE_TYPE_OTHER = "fileType_other"; - - public static final String FILE_TYPE_SOURCE = "SOURCE"; - public static final String FILE_TYPE_ARCHIVE = "ARCHIVE"; - public static final String FILE_TYPE_BINARY = "BINARY"; - public static final String FILE_TYPE_OTHER = "OTHER"; - - // SPDX Annotation Properties - public static final PropertyDescriptor PROP_ANNOTATOR = new PropertyDescriptor("annotator", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_ANNOTATION_DATE = new PropertyDescriptor("annotationDate", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_ANNOTATION_TYPE = new PropertyDescriptor("annotationType", SPDX_NAMESPACE); - - // SPDX Relationship Properties - public static final PropertyDescriptor PROP_RELATED_SPDX_ELEMENT = new PropertyDescriptor("relatedSpdxElement", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_RELATIONSHIP_TYPE = new PropertyDescriptor("relationshipType", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_SPDX_ELEMENTID = new PropertyDescriptor("spdxElementId", SPDX_NAMESPACE); - - // ExternalDocumentRef properties - public static final PropertyDescriptor PROP_EXTERNAL_DOC_CHECKSUM = new PropertyDescriptor("checksum", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXTERNAL_SPDX_DOCUMENT = new PropertyDescriptor("spdxDocument", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_EXTERNAL_DOCUMENT_ID = new PropertyDescriptor("externalDocumentId", SPDX_NAMESPACE); - - // External Reference properties - public static final PropertyDescriptor PROP_REFERENCE_CATEGORY = new PropertyDescriptor("referenceCategory", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_REFERENCE_TYPE = new PropertyDescriptor("referenceType", SPDX_NAMESPACE); - public static final PropertyDescriptor PROP_REFERENCE_LOCATOR = new PropertyDescriptor("referenceLocator", SPDX_NAMESPACE); - - // Date format - NOTE: This format does not handle milliseconds. Use Instant.parse for full ISO 8601 parsing - public static final String SPDX_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - - // license ID format - public static String NON_STD_LICENSE_ID_PRENUM = "LicenseRef-"; - public static Pattern LICENSE_ID_PATTERN_NUMERIC = - Pattern.compile(NON_STD_LICENSE_ID_PRENUM+"(\\d+)$"); // Pattern for numeric only license IDs - public static Pattern LICENSE_ID_PATTERN = Pattern.compile(NON_STD_LICENSE_ID_PRENUM+"([0-9a-zA-Z\\.\\-\\_]+)\\+?$"); - - // SPDX Element Reference format - public static String SPDX_ELEMENT_REF_PRENUM = "SPDXRef-"; - public static Pattern SPDX_ELEMENT_REF_PATTERN = Pattern.compile(SPDX_ELEMENT_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$"); - - // External Document ID format - public static String EXTERNAL_DOC_REF_PRENUM = "DocumentRef-"; - public static Pattern EXTERNAL_DOC_REF_PATTERN = Pattern.compile(EXTERNAL_DOC_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$"); - public static Pattern EXTERNAL_ELEMENT_REF_PATTERN = Pattern.compile("(.+[0-9a-zA-Z\\.\\-\\+]+):("+SPDX_ELEMENT_REF_PRENUM+"[0-9a-zA-Z\\.\\-\\+]+)$"); - public static Pattern EXTERNAL_SPDX_ELEMENT_URI_PATTERN = Pattern.compile("(.+)#("+SPDX_ELEMENT_REF_PRENUM+"[0-9a-zA-Z\\.\\-\\+]+)$"); - public static Pattern EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN = Pattern.compile("(.+)#("+NON_STD_LICENSE_ID_PRENUM+"[0-9a-zA-Z\\.\\-\\+]+)$"); - public static Pattern EXTERNAL_EXTRACTED_LICENSE_PATTERN = Pattern.compile("(.+[0-9a-zA-Z\\.\\-\\+]+):("+NON_STD_LICENSE_ID_PRENUM+"[0-9a-zA-Z\\.\\-\\+]+)$"); - - // SPDX version format - public static Pattern SPDX_VERSION_PATTERN = Pattern.compile("^SPDX-(\\d+)\\.(\\d+)$"); - - // Download Location Format - private static final String SUPPORTED_DOWNLOAD_REPOS = "(git|hg|svn|bzr)"; - private static final String URL_PATTERN = "(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/|ssh:\\/\\/|git:\\/\\/|svn:\\/\\/|sftp:\\/\\/|ftp:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+){0,100}\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?"; - private static final String GIT_PATTERN = "(git\\+git@[a-zA-Z0-9\\.\\-]+:[a-zA-Z0-9/\\\\.@\\-]+)"; - private static final String BAZAAR_PATTERN = "(bzr\\+lp:[a-zA-Z0-9\\.\\-]+)"; - public static final Pattern DOWNLOAD_LOCATION_PATTERN = Pattern.compile("^(NONE|NOASSERTION|(("+SUPPORTED_DOWNLOAD_REPOS+"\\+)?"+URL_PATTERN+")|"+GIT_PATTERN+"|"+BAZAAR_PATTERN+")$", Pattern.CASE_INSENSITIVE); - - // License list version Format - - public static final Pattern LICENSE_LIST_VERSION_PATTERN = Pattern.compile("^[a-zA-Z0-9]+\\.[a-zA-Z0-9]+"); - // Standard value strings - public static String NONE_VALUE = "NONE"; - public static String NOASSERTION_VALUE = "NOASSERTION"; - public static final String[] LITERAL_VALUES = new String[]{NONE_VALUE, NOASSERTION_VALUE}; - - // data license ID - public static final String SPDX_DATA_LICENSE_ID_VERSION_1_0 = "PDDL-1.0"; - public static final String SPDX_DATA_LICENSE_ID = "CC0-1.0"; - - public static final String SPDX_LISTED_REFERENCE_TYPES_PREFIX = "http://spdx.org/rdf/references/"; - - // License XML constants - public static final String LICENSEXML_URI = "http://www.spdx.org/license"; - public static final String LICENSEXML_ELEMENT_LICENSE_COLLECTION = "SPDXLicenseCollection"; - public static final String LICENSEXML_ELEMENT_LICENSE = "license"; - public static final String LICENSEXML_ELEMENT_EXCEPTION = "exception"; - public static final String LICENSEXML_ATTRIBUTE_ID = "licenseId"; - public static final String LICENSEXML_ATTRIBUTE_DEPRECATED = "isDeprecated"; - public static final String LICENSEXML_ATTRIBUTE_DEPRECATED_VERSION = "deprecatedVersion"; - public static final String LICENSEXML_ATTRIBUTE_OSI_APPROVED = "isOsiApproved"; - public static final String LICENSEXML_ATTRIBUTE_FSF_LIBRE = "isFsfLibre"; - public static final String LICENSEXML_ATTRIBUTE_NAME = "name"; - public static final String LICENSEXML_ATTRIBUTE_LIST_VERSION_ADDED = "listVersionAdded"; - public static final String LICENSEXML_ELEMENT_CROSS_REFS = "crossRefs"; - public static final String LICENSEXML_ELEMENT_CROSS_REF = "crossRef"; - public static final String LICENSEXML_ELEMENT_NOTES = "notes"; - public static final String LICENSEXML_ELEMENT_STANDARD_LICENSE_HEADER = "standardLicenseHeader"; - public static final String LICENSEXML_ELEMENT_TITLE_TEXT = "titleText"; - public static final String LICENSEXML_ELEMENT_COPYRIGHT_TEXT = "copyrightText"; - public static final String LICENSEXML_ELEMENT_BULLET = "bullet"; - public static final String LICENSEXML_ELEMENT_LIST = "list"; - public static final String LICENSEXML_ELEMENT_ITEM = "item"; - public static final String LICENSEXML_ELEMENT_PARAGRAPH = "p"; - public static final String LICENSEXML_ELEMENT_OPTIONAL = "optional"; - public static final String LICENSEXML_ELEMENT_ALT = "alt"; - public static final String LICENSEXML_ATTRIBUTE_ALT_NAME = "name"; - public static final String LICENSEXML_ATTRIBUTE_ALT_MATCH = "match"; - public static final String LICENSEXML_ELEMENT_BREAK = "br"; - public static final String LICENSEXML_ELEMENT_TEXT = "text"; - -} \ No newline at end of file diff --git a/src/main/java/org/spdx/library/SpdxIdInUseException.java b/src/main/java/org/spdx/library/SpdxIdInUseException.java deleted file mode 100644 index aeb9d4687..000000000 --- a/src/main/java/org/spdx/library/SpdxIdInUseException.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * Exception when an SPDX element is in use (e.g. exception thrown when attempting to delete) - * @author Gary O'Neall - * - */ -public class SpdxIdInUseException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public SpdxIdInUseException() { - super(); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public SpdxIdInUseException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - - /** - * @param arg0 - * @param arg1 - */ - public SpdxIdInUseException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - */ - public SpdxIdInUseException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public SpdxIdInUseException(Throwable arg0) { - super(arg0); - } - -} diff --git a/src/main/java/org/spdx/library/SpdxIdNotFoundException.java b/src/main/java/org/spdx/library/SpdxIdNotFoundException.java deleted file mode 100644 index 93f860a45..000000000 --- a/src/main/java/org/spdx/library/SpdxIdNotFoundException.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * @author Gary O'Neall - * - * Exception for no SPDX identifier found - * - */ -public class SpdxIdNotFoundException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - - /** - * - */ - public SpdxIdNotFoundException() { - } - - /** - * @param arg0 - */ - public SpdxIdNotFoundException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public SpdxIdNotFoundException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public SpdxIdNotFoundException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public SpdxIdNotFoundException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/SpdxInvalidIdException.java b/src/main/java/org/spdx/library/SpdxInvalidIdException.java deleted file mode 100644 index 7f295834f..000000000 --- a/src/main/java/org/spdx/library/SpdxInvalidIdException.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * @author Gary O'Neall - * - * Ivalid SPDX identifier - * - */ -public class SpdxInvalidIdException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public SpdxInvalidIdException() { - super(); - } - - /** - * @param message - */ - public SpdxInvalidIdException(String message) { - super(message); - } - - /** - * @param cause - */ - public SpdxInvalidIdException(Throwable cause) { - super(cause); - } - - /** - * @param message - * @param cause - */ - public SpdxInvalidIdException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param message - * @param cause - * @param enableSuppression - * @param writableStackTrace - */ - public SpdxInvalidIdException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } - -} diff --git a/src/main/java/org/spdx/library/SpdxInvalidTypeException.java b/src/main/java/org/spdx/library/SpdxInvalidTypeException.java deleted file mode 100644 index c6c390340..000000000 --- a/src/main/java/org/spdx/library/SpdxInvalidTypeException.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * @author Gary O'Neall - * - * Invalid type for an SPDX property - * - */ -public class SpdxInvalidTypeException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public SpdxInvalidTypeException() { - } - - /** - * @param arg0 - */ - public SpdxInvalidTypeException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public SpdxInvalidTypeException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public SpdxInvalidTypeException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public SpdxInvalidTypeException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java deleted file mode 100644 index b2045d187..000000000 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ /dev/null @@ -1,451 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.ModelObject; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Factory class to create ModelObjects based on the type and SPDX Spec Version - * Types are defined classes in the SpdxConstantsCompatV2 class and map to the standard SPDX model - * - * @author Gary O'Neall - * - */ -public class SpdxModelFactory { - - static final Logger logger = LoggerFactory.getLogger(SpdxModelFactory.class); - - public static Map> SPDX_TYPE_TO_CLASS_V2; - public static Map> SPDX_TYPE_TO_CLASS_V3; - public static Map, String> SPDX_CLASS_TO_TYPE; - static { - Map> typeToClassV2 = new HashMap<>(); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, org.spdx.library.model.compat.v2.SpdxDocument.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE, org.spdx.library.model.compat.v2.SpdxPackage.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO, org.spdx.library.model.compat.v2.SpdxCreatorInformation.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, org.spdx.library.model.compat.v2.Checksum.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_ANY_LICENSE_INFO, org.spdx.library.model.compat.v2.license.AnyLicenseInfo.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_SIMPLE_LICENSE_INFO, org.spdx.library.model.compat.v2.license.SimpleLicensingInfo.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET, org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE, org.spdx.library.model.compat.v2.license.License.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, org.spdx.library.model.compat.v2.license.SpdxListedLicense.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.LicenseException.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, org.spdx.library.model.compat.v2.license.ListedLicenseException.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR, org.spdx.library.model.compat.v2.license.OrLaterOperator.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR, org.spdx.library.model.compat.v2.license.WithExceptionOperator.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_FILE, org.spdx.library.model.compat.v2.SpdxFile.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE, org.spdx.library.model.compat.v2.SpdxPackageVerificationCode.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_ANNOTATION, org.spdx.library.model.compat.v2.Annotation.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_RELATIONSHIP, org.spdx.library.model.compat.v2.Relationship.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_ITEM, org.spdx.library.model.compat.v2.SpdxItem.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_ELEMENT, org.spdx.library.model.compat.v2.SpdxElement.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoneElement.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_NOASSERTION_ELEMENT, org.spdx.library.model.compat.v2.SpdxNoAssertionElement.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, org.spdx.library.model.compat.v2.ExternalDocumentRef.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE, org.spdx.library.model.compat.v2.ExternalRef.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE, org.spdx.library.model.compat.v2.ReferenceType.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET, org.spdx.library.model.compat.v2.SpdxSnippet.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_NONE_LICENSE, org.spdx.library.model.compat.v2.license.SpdxNoneLicense.class); - typeToClassV2.put(org.spdx.library.model.compat.v2.GenericModelObject.GENERIC_MODEL_OBJECT_TYPE, org.spdx.library.model.compat.v2.GenericModelObject.class); - typeToClassV2.put(org.spdx.library.model.compat.v2.GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE, org.spdx.library.model.compat.v2.GenericSpdxElement.class); - typeToClassV2.put(org.spdx.library.model.compat.v2.GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE, org.spdx.library.model.compat.v2.GenericSpdxItem.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT, org.spdx.library.model.compat.v2.ExternalSpdxElement.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER, org.spdx.library.model.compat.v2.pointer.StartEndPointer.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER, org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER, org.spdx.library.model.compat.v2.pointer.LineCharPointer.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER, org.spdx.library.model.compat.v2.pointer.CompoundPointer.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_SINGLE_POINTER, org.spdx.library.model.compat.v2.pointer.SinglePointer.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_CROSS_REF, org.spdx.library.model.compat.v2.license.CrossRef.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_FILE_TYPE, org.spdx.library.model.compat.v2.enumerations.FileType.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_ANNOTATION_TYPE, org.spdx.library.model.compat.v2.enumerations.AnnotationType.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_CHECKSUM_ALGORITHM_TYPE, org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_CATEGORY_TYPE, org.spdx.library.model.compat.v2.enumerations.ReferenceCategory.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_REFERENCE_RELATIONSHIP_TYPE, org.spdx.library.model.compat.v2.enumerations.RelationshipType.class); - typeToClassV2.put(SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE, org.spdx.library.model.compat.v2.license.ExternalExtractedLicenseInfo.class); - typeToClassV2.put(SpdxConstantsCompatV2.ENUM_PURPOSE, org.spdx.library.model.compat.v2.enumerations.Purpose.class); - SPDX_TYPE_TO_CLASS_V2 = Collections.unmodifiableMap(typeToClassV2); - Map> typeToClassV3 = new HashMap<>(); - //TODO Add V3 class strings - SPDX_TYPE_TO_CLASS_V3 = Collections.unmodifiableMap(typeToClassV3); - Map, String> classToType = new HashMap<>(); - for (Entry> entry:typeToClassV2.entrySet()) { - classToType.put(entry.getValue(), entry.getKey()); - } - for (Entry> entry:typeToClassV3.entrySet()) { - classToType.put(entry.getValue(), entry.getKey()); - } - - SPDX_CLASS_TO_TYPE = Collections.unmodifiableMap(classToType); - } - - /** - * Create an SPDX spec version 3 model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param objectUri Object URI or anonymous ID - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @param create if true, create the model object if it does not already exist - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static ModelObject getModelObject(IModelStore modelStore, String objectUri, - String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(objectUri, "An object URI or anonymous ID must be supplied for all SPDX version 2 model objects"); - - Class clazz = SPDX_TYPE_TO_CLASS_V3.get(type); - if (Objects.isNull(clazz)) { - throw new InvalidSPDXAnalysisException("Unknown SPDX version 3 type: "+type); - } - if (Modifier.isAbstract(clazz.getModifiers())) { - throw new InvalidSPDXAnalysisException("Can not instantiate an abstract class for the SPDX version 3 type: "+type); - } - try { - Constructor con = clazz.getDeclaredConstructor(IModelStore.class, String.class, ModelCopyManager.class, boolean.class); - return (ModelObject)con.newInstance(modelStore, objectUri, copyManager, create); - } catch (NoSuchMethodException e) { - throw new InvalidSPDXAnalysisException("Could not create the model object SPDX version 3 type: "+type); - } catch (SecurityException e) { - throw new InvalidSPDXAnalysisException("Unexpected security exception for SPDX version 3 type: "+type, e); - } catch (InstantiationException e) { - throw new InvalidSPDXAnalysisException("Unexpected instantiation exception for SPDX version 3 type: "+type, e); - } catch (IllegalAccessException e) { - throw new InvalidSPDXAnalysisException("Unexpected illegal access exception for SPDX version 3 type: "+type, e); - } catch (IllegalArgumentException e) { - throw new InvalidSPDXAnalysisException("Unexpected illegal argument exception for SPDX version 2 type: "+type, e); - } catch (InvocationTargetException e) { - if (e.getTargetException() instanceof InvalidSPDXAnalysisException) { - throw (InvalidSPDXAnalysisException)e.getTargetException(); - } else { - throw new InvalidSPDXAnalysisException("Unexpected invocation target exception for SPDX version 3 type: "+type, e); - } - } - } - - - - /** - * Create an SPDX version 2.X document with default values for creator, created, licenseListVersion, data license and specVersion - * @param modelStore Where to store the SPDX Document - * @param documentUri unique URI for the SPDX document - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @return - * @throws InvalidSPDXAnalysisException - */ - public static org.spdx.library.model.compat.v2.SpdxDocument createSpdxDocumentV2(IModelStore modelStore, String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - org.spdx.library.model.compat.v2.SpdxDocument retval = new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, true); - String date = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); - org.spdx.library.model.compat.v2.SpdxCreatorInformation creationInfo = new org.spdx.library.model.compat.v2.SpdxCreatorInformation( - modelStore, documentUri, modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - creationInfo.getCreators().add("Tool: SPDX Tools"); - creationInfo.setCreated(date); - creationInfo.setLicenseListVersion(org.spdx.library.model.compat.v2.license.ListedLicenses.getListedLicenses().getLicenseListVersion()); - retval.setCreationInfo(creationInfo); - retval.setDataLicense(org.spdx.library.model.compat.v2.license.ListedLicenses.getListedLicenses().getListedLicenseById(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)); - retval.setSpecVersion(Version.CURRENT_SPDX_VERSION); - return retval; - } - - /** - * Create an SPDX version 2 model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param documentUri document URI for the stored item - * @param id for the item - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static org.spdx.library.model.compat.v2.ModelObject createModelObjectV2(IModelStore modelStore, String documentUri, String id, - String type, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); - Objects.requireNonNull(id, "ID must not be null"); - return getModelObjectV2(modelStore, documentUri, id, type, copyManager, true); - } - - /** - * Create an SPDX spec version 2.X model object in a model store given the document URI, ID and type - * @param modelStore model store where the object is to be created - * @param documentUri document URI for the stored item - * @param id ID for the item - * @param type SPDX class or type - * @param copyManager if non-null, allows for copying of properties from other model stores or document URI's when referenced - * @param create if true, create the model object if it does not already exist - * @return a ModelObject of type type - * @throws InvalidSPDXAnalysisException - */ - public static org.spdx.library.model.compat.v2.ModelObject getModelObjectV2(IModelStore modelStore, String documentUri, String id, - String type, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); - if (SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT.equals(type)) { - // Special case since document does not have the same constructor method signature - the ID is ignored - return new org.spdx.library.model.compat.v2.SpdxDocument(modelStore, documentUri, copyManager, create); - } - if (SpdxConstantsCompatV2.CLASS_SPDX_REFERENCE_TYPE.equals(type)) { - throw new InvalidSPDXAnalysisException("Reference type can only be created with a type supplied."); - } - if (SpdxConstantsCompatV2.CLASS_SPDX_REVIEW.equals(type)) { - throw new InvalidSPDXAnalysisException("Review class is no longer supported"); - } - Objects.requireNonNull(id, "ID must not be null"); - Class clazz = SPDX_TYPE_TO_CLASS_V2.get(type); - if (Objects.isNull(clazz)) { - throw new InvalidSPDXAnalysisException("Unknown SPDX version 2 type: "+type); - } - if (Modifier.isAbstract(clazz.getModifiers())) { - throw new InvalidSPDXAnalysisException("Can not instantiate an abstract class for the SPDX version 2 type: "+type); - } - try { - Constructor con = clazz.getDeclaredConstructor(IModelStore.class, String.class, String.class, ModelCopyManager.class, boolean.class); - return (org.spdx.library.model.compat.v2.ModelObject)con.newInstance(modelStore, documentUri, id, copyManager, create); - } catch (NoSuchMethodException e) { - throw new InvalidSPDXAnalysisException("Could not create the model object SPDX version 2 type: "+type); - } catch (SecurityException e) { - throw new InvalidSPDXAnalysisException("Unexpected security exception for SPDX version 2 type: "+type, e); - } catch (InstantiationException e) { - throw new InvalidSPDXAnalysisException("Unexpected instantiation exception for SPDX version 2 type: "+type, e); - } catch (IllegalAccessException e) { - throw new InvalidSPDXAnalysisException("Unexpected illegal access exception for SPDX version 2 type: "+type, e); - } catch (IllegalArgumentException e) { - throw new InvalidSPDXAnalysisException("Unexpected illegal argument exception for SPDX version 2 type: "+type, e); - } catch (InvocationTargetException e) { - if (e.getTargetException() instanceof InvalidSPDXAnalysisException) { - throw (InvalidSPDXAnalysisException)e.getTargetException(); - } else { - throw new InvalidSPDXAnalysisException("Unexpected invocation target exception for SPDX version 2 type: "+type, e); - } - } - } - - /** - * @param type SPDX Type - * @param specVersion Version of the SPDX Spec - * @return class associated with the type - * @throws InvalidSPDXAnalysisException - */ - public static Class typeToClass(String type, SpdxMajorVersion specVersion) throws InvalidSPDXAnalysisException { - Class retval; - if (specVersion.compareTo(SpdxMajorVersion.VERSION_3) < 0) { - retval = SPDX_TYPE_TO_CLASS_V2.get(type); - } else { - retval = SPDX_TYPE_TO_CLASS_V3.get(type); - } - if (Objects.isNull(retval)) { - throw new InvalidSPDXAnalysisException("Unknown SPDX type: "+type); - } - return retval; - } - - /** - * @param type SPDX Type - * @return class associated with the type for the latest spec version - * @throws InvalidSPDXAnalysisException - */ - public static Class typeToClass(String type) throws InvalidSPDXAnalysisException { - return typeToClass(type, SpdxMajorVersion.latestVersion()); - } - - /** - * @param store model store - * @param documentUri Document URI for the elements to fetch - * @param copyManager optional copy manager - * @param type SPDX V2 type to filter on - * @return stream of elements of the compatible version 2 types - * @throws InvalidSPDXAnalysisException - */ - public static Stream getElementsV2(IModelStore store, String documentUri, @Nullable ModelCopyManager copyManager, - String type) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(type, "type must not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null for SPDX V2 elements"); - if (!SPDX_TYPE_TO_CLASS_V2.containsKey(type)) { - logger.error("Can not get elements for a non-SPDX version 2 type: "+type); - throw new InvalidSPDXAnalysisException("Can not get elements for a non-SPDX version 2 type: "+type); - } - return store.getAllItems(CompatibleModelStoreWrapper.documentUriToNamespace(documentUri, false), type).map(tv -> { - //TODO: Change this a null namespace and filtering on anonomous or startswith document URI - this will catch the anon. types - try { - boolean anon = store.getIdType(tv.getObjectUri()) == IdType.Anonymous; - return createModelObjectV2(store, documentUri, - CompatibleModelStoreWrapper.objectUriToId(anon, tv.getObjectUri(), documentUri), - tv.getType(), copyManager); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error creating model object",e); - throw new RuntimeException(e); - } - }); - } - - /** - * @param store model store - * @param nameSpace optional namespace to filter elements on - * @param copyManager optional copy manager - * @param type SPDX V2 type to filter on - * @return SPDX spec version 3 elements matching the namespace and class - * @throws InvalidSPDXAnalysisException - */ - public static Stream getElementsV3(IModelStore store, @Nullable String nameSpace, @Nullable ModelCopyManager copyManager, - String type) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(type, "type must not be null"); - if (!SPDX_TYPE_TO_CLASS_V3.containsKey(type)) { - logger.error("Can not get elements for a non-SPDX version 3 type: "+type); - throw new InvalidSPDXAnalysisException("Can not get elements for a non-SPDX version 3 type: "+type); - } - return store.getAllItems(nameSpace, type).map(tv -> { - try { - return createModelObjectV2(store, nameSpace, - CompatibleModelStoreWrapper.objectUriToId(store.getIdType(tv.getObjectUri()) == IdType.Anonymous, tv.getObjectUri(), nameSpace), - tv.getType(), copyManager); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error creating model object",e); - throw new RuntimeException(e); - } - }); - } - - /** - * @param store model store - * @param nameSpace optional namespace to filter elements on - * @param copyManager optional copy manager - * @param spdxClass class to filter elements on - * @return a stream of elements matching the namespace and class - * @throws InvalidSPDXAnalysisException - */ - public static Stream getElements(IModelStore store, @Nullable String nameSpace, @Nullable ModelCopyManager copyManager, - Class spdxClass) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(store, "Store must not be null"); - Objects.requireNonNull(spdxClass, "spdxClass must not be null"); - String type = SPDX_CLASS_TO_TYPE.get(spdxClass); - if (Objects.isNull(type)) { - logger.error("Unknow SPDX class: "+spdxClass.toString()); - throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); - } - if (SPDX_TYPE_TO_CLASS_V3.containsKey(type)) { - return getElementsV3(store, nameSpace, copyManager, type); - } else if (SPDX_TYPE_TO_CLASS_V2.containsKey(type)) { - return getElementsV2(store, nameSpace.endsWith("#") ? nameSpace.substring(0, nameSpace.length()-1) : nameSpace, - copyManager, type); - } else { - logger.error("Unknow SPDX class: "+spdxClass.toString()); - throw new InvalidSPDXAnalysisException("Unknow SPDX class: "+spdxClass.toString()); - } - } - - - - /** - * @param classUri URI for the class type - * @param specVersion Version of the SPDX Spec - * @return class represented by the URI - * @throws InvalidSPDXAnalysisException - */ - public static Class classUriToClass(String classUri, SpdxMajorVersion specVersion) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(classUri, "Missing required class URI"); - int indexOfPound = classUri.lastIndexOf('#'); - if (indexOfPound < 1) { - throw new InvalidSPDXAnalysisException("Invalid class URI: "+classUri); - } - String type = classUri.substring(indexOfPound+1); - return typeToClass(type, specVersion); - } - - /** - * @param classUri URI for the class type - * @return class represented by the URI for the more recent spec version - * @throws InvalidSPDXAnalysisException - */ - public static Class classUriToClass(String classUri) throws InvalidSPDXAnalysisException { - return classUriToClass(classUri, SpdxMajorVersion.latestVersion()); - } - - /** - * @param modelStore Store for the SPDX Spec version 2 model - * @param documentUri Document URI for for the ID - * @param copyManager Optional copy manager for copying any properties from other model - * @param objectUri ID for the model object - * @return SPDX Version 2 compatible ModelObject with the ID in the model store - * @throws InvalidSPDXAnalysisException - */ - public static Optional getModelObjectV2(IModelStore modelStore, String documentUri, - String id, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "A document URI or namespace must be supplied for all SPDX version 2 model objects"); - Objects.requireNonNull(id, "ID must not be null"); - if (id.contains(":")) { - // External document ref - try { - return Optional.of(new org.spdx.library.model.compat.v2.ExternalSpdxElement(modelStore, documentUri, id, copyManager, true)); - } catch(InvalidSPDXAnalysisException ex) { - logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty"); - return Optional.empty(); - } - } - Optional tv = modelStore.getTypedValue( - CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore.getIdType(id).equals(IdType.Anonymous))); - if (tv.isPresent()) { - String type = tv.get().getType(); - try { - return Optional.of(getModelObjectV2(modelStore, documentUri, id, type, copyManager, false)); - } catch(SpdxIdNotFoundException ex) { - return Optional.empty(); // There is a window where the ID disappears between getTypedValue and getModelObject - } - } else { - if (SpdxConstantsCompatV2.NOASSERTION_VALUE.equals(id)) { - return Optional.of(new org.spdx.library.model.compat.v2.SpdxNoAssertionElement()); - } else if (SpdxConstantsCompatV2.NONE_VALUE.equals(id)) { - return Optional.of(new org.spdx.library.model.compat.v2.SpdxNoneElement()); - } else { - return Optional.empty(); - } - } - } - - public static ModelObject createModelObject(IModelStore stModelStore, - String objectUri, String type, ModelCopyManager copyManager) { - // TODO Auto-generated method stub - return null; - } -} diff --git a/src/main/java/org/spdx/library/SpdxObjectNotInStoreException.java b/src/main/java/org/spdx/library/SpdxObjectNotInStoreException.java deleted file mode 100644 index 4cdf23a84..000000000 --- a/src/main/java/org/spdx/library/SpdxObjectNotInStoreException.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -/** - * Exception when an SDPX ID or object was not found in a model store - * @author Gary O'Neall - * - */ -public class SpdxObjectNotInStoreException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public SpdxObjectNotInStoreException() { - super(); - } - - /** - * @param arg0 - */ - public SpdxObjectNotInStoreException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public SpdxObjectNotInStoreException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public SpdxObjectNotInStoreException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public SpdxObjectNotInStoreException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/SpdxVerificationHelper.java b/src/main/java/org/spdx/library/SpdxVerificationHelper.java deleted file mode 100644 index 1e68206a7..000000000 --- a/src/main/java/org/spdx/library/SpdxVerificationHelper.java +++ /dev/null @@ -1,308 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library; - -import java.net.URI; -import java.time.Instant; -import java.time.format.DateTimeParseException; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Pattern; - -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; - -/** - * Holds static methods used for verify various property values - * @author Gary O'Neall - * - */ -public class SpdxVerificationHelper { - - static final Map CHECKSUM_VALUE_LENGTH; - static { - Map map = new HashMap<>(); - map.put(ChecksumAlgorithm.ADLER32, 8); - map.put(ChecksumAlgorithm.BLAKE2b_256, 256 / 4); - map.put(ChecksumAlgorithm.BLAKE2b_384, 384 / 4); - map.put(ChecksumAlgorithm.BLAKE2b_512, 512 / 4); - map.put(ChecksumAlgorithm.BLAKE3, 256 / 4); // Assuming this is the default output size - map.put(ChecksumAlgorithm.MD2, 128 / 4); - map.put(ChecksumAlgorithm.MD4, 128 / 4); - map.put(ChecksumAlgorithm.MD5, 128 / 4); - map.put(ChecksumAlgorithm.MD6, null); // variable 0 to 128 bits - map.put(ChecksumAlgorithm.SHA1, 40); - map.put(ChecksumAlgorithm.SHA224, 224 / 4); - map.put(ChecksumAlgorithm.SHA256, 64); - map.put(ChecksumAlgorithm.SHA384, 384 / 4); - map.put(ChecksumAlgorithm.SHA3_256, 256 / 4); - map.put(ChecksumAlgorithm.SHA3_384, 384 / 4); - map.put(ChecksumAlgorithm.SHA3_512, 512 / 4); - map.put(ChecksumAlgorithm.SHA512, 512 / 4); - CHECKSUM_VALUE_LENGTH = Collections.unmodifiableMap(map); - } - static final Set CHECKSUM_ALGORITHMS_ADDED_23; - static { - Set set = new HashSet<>(); - set.add(ChecksumAlgorithm.SHA3_256); - set.add(ChecksumAlgorithm.SHA3_384); - set.add(ChecksumAlgorithm.SHA3_512); - set.add(ChecksumAlgorithm.BLAKE2b_256); - set.add(ChecksumAlgorithm.BLAKE2b_384); - set.add(ChecksumAlgorithm.BLAKE2b_512); - set.add(ChecksumAlgorithm.BLAKE3); - set.add(ChecksumAlgorithm.ADLER32); - CHECKSUM_ALGORITHMS_ADDED_23 = Collections.unmodifiableSet(set); - } - - static final String[] VALID_CREATOR_PREFIXES = new String[] {SpdxConstantsCompatV2.CREATOR_PREFIX_PERSON, - SpdxConstantsCompatV2.CREATOR_PREFIX_ORGANIZATION, SpdxConstantsCompatV2.CREATOR_PREFIX_TOOL}; - static final String[] VALID_ORIGINATOR_SUPPLIER_PREFIXES = new String[] {SpdxConstantsCompatV2.NOASSERTION_VALUE, "Person:", "Organization:"}; - static final Pattern SPDX_ELEMENT_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$"); - static final Pattern LICENSE_ID_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"([0-9a-zA-Z\\.\\-\\_]+)\\+?$"); - static final Pattern EXTERNAL_DOC_REF_PATTERN = Pattern.compile(".*" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"([0-9a-zA-Z\\.\\-\\+]+)$");; - - public static String verifyNonStdLicenseid(String licenseUri) { - if (LICENSE_ID_PATTERN.matcher(licenseUri).matches()) { - return null; - } else { - return "Invalid license objectUri '"+licenseUri+"'. Must start with 'LicenseRef-' " + - "and made up of the characters from the set 'a'-'z', 'A'-'Z', '0'-'9', '+', '_', '.', and '-'."; - } - } - - /** - * Verifies a creator string value - * @param creator - * @return - */ - public static String verifyCreator(String creator) { - boolean ok = false; - for (int i = 0; i < VALID_CREATOR_PREFIXES.length; i++) { - if (creator.startsWith(VALID_CREATOR_PREFIXES[i])) { - ok = true; - break; - } - } - if (!ok) { - StringBuilder sb = new StringBuilder("Creator does not start with one of "); - sb.append(VALID_CREATOR_PREFIXES[0]); - for (int i = 1; i < VALID_CREATOR_PREFIXES.length; i++) { - sb.append(", "); - sb.append(VALID_CREATOR_PREFIXES[i]); - } - return sb.toString(); - } else { - return null; - } - } - - /** - * Verifies the originator string - * @param originator - * @return - */ - public static String verifyOriginator(String originator) { - return verifyOriginatorOrSupplier(originator); - } - - /** - * Verifies the supplier String - * @param supplier - * @return - */ - public static String verifySupplier(String supplier) { - return verifyOriginatorOrSupplier(supplier); - } - - /** - * Verifies a the originator or supplier - * @param creator - * @return - */ - private static String verifyOriginatorOrSupplier(String originatorOrSupplier) { - boolean ok = false; - for (int i = 0; i < VALID_ORIGINATOR_SUPPLIER_PREFIXES.length; i++) { - if (originatorOrSupplier.startsWith(VALID_ORIGINATOR_SUPPLIER_PREFIXES[i])) { - ok = true; - break; - } - } - if (!ok) { - StringBuilder sb = new StringBuilder("Value must start with one of "); - sb.append(VALID_ORIGINATOR_SUPPLIER_PREFIXES[0]); - for (int i = 1; i < VALID_ORIGINATOR_SUPPLIER_PREFIXES.length; i++) { - sb.append(", "); - sb.append(VALID_ORIGINATOR_SUPPLIER_PREFIXES[i]); - } - return sb.toString(); - } else { - return null; - } - } - - /** - * @param creationDate - * @return error message or null if no error - */ - public static String verifyDate(String creationDate) { - try { - Instant.parse(creationDate); - } catch (DateTimeParseException e) { - return("Invalid date format: "+e.getMessage()); - } - return null; - } - - /** - * @param reviewer - * @return - */ - public static String verifyReviewer(String reviewer) { - if (!reviewer.startsWith("Person:") && !reviewer.startsWith("Tool:") && - !reviewer.startsWith("Organization:")) { - return "Reviewer does not start with Person:, Organization:, or Tool:"; - } else { - return null; - } - } - - /** - * Returns true if s1 equals s2 taking into account the possibility of null values - * @param s1 - * @param s2 - * @return - */ - public static boolean equalsWithNull(Object s1, Object s2) { - if (s1 == null) { - return (s2 == null); - } - if (s2 == null) { - return false; - } - return s1.equals(s2); - } - - /** - * Returns true if the array s1 contains the same objects as s2 independent of order - * and allowing for null values - * @param s1 - * @param s2 - * @return - */ - public static boolean equivalentArray(Object[] s1, Object[] s2) { - if (s1 == null) { - return (s2 == null); - } - if (s2 == null) { - return false; - } - if (s1.length != s2.length) { - return false; - } - for (int i = 0; i < s1.length; i++) { - boolean found = false; - for (int j = 0; j < s2.length; j++) { - if (equalsWithNull(s1[i], s2[j])) { - found = true; - break; - } - } - if (!found) { - return false; - } - } - return true; - } - - /** - * @param annotator - * @return - */ - public static String verifyAnnotator(String annotator) { - if (!annotator.startsWith("Person:") && !annotator.startsWith("Tool:") && - !annotator.startsWith("Organization:")) { - return "Annotator does not start with Person:, Organization:, or Tool"; - } else { - return null; - } - } - - /** - * @param externalDocumentId - * @return - */ - public static boolean isValidExternalDocRef(String externalDocumentId) { - return EXTERNAL_DOC_REF_PATTERN.matcher(externalDocumentId).matches(); - } - - public static boolean isValidUri(String uri) { - try { - URI.create(uri); - } catch (Exception e) { - return false; - } - return true; - } - - public static String verifyChecksumString(String checksum, ChecksumAlgorithm algorithm, String specVersion) { - for (int i = 0; i < checksum.length(); i++) { - char c = checksum.charAt(i); - if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - return "Invalid checksum string character at position "+String.valueOf(i); - } - } - - Integer valueSize = CHECKSUM_VALUE_LENGTH.get(algorithm); - if (Objects.nonNull(valueSize) && checksum.length() != valueSize) { - return "Invalid number of characters for checksum"; - } - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - if (CHECKSUM_ALGORITHMS_ADDED_23.contains(algorithm)) { - return "This algorithm is not supported in SPDX specification versions less than 2.3"; - } - } - return null; // if we got here, all OK - } - - /** - * Verify a download location per section 3.7.5 of the spec - * @param downloadLocation - * @return null if a valid string otherwise a description of the error - */ - public static String verifyDownloadLocation(String downloadLocation) { - if (Objects.isNull(downloadLocation)) { - return "Download location is null"; - } else if (SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.matcher(downloadLocation).matches()) { - return null; - } else { - return "Invalid download location "+downloadLocation+". Must match the pattern "+ - SpdxConstantsCompatV2.DOWNLOAD_LOCATION_PATTERN.pattern(); - } - } - - /** - * @param objectUri - * @return true if the ID is a valid SPDX ID reference - */ - public static boolean verifySpdxId(String objectUri) { - return SPDX_ELEMENT_ID_PATTERN.matcher(objectUri).matches(); - } -} diff --git a/src/main/java/org/spdx/library/TypedValue.java b/src/main/java/org/spdx/library/TypedValue.java deleted file mode 100644 index 0417f4b87..000000000 --- a/src/main/java/org/spdx/library/TypedValue.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.spdx.library; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.spdx.library.model.compat.v2.GenericModelObject; -import org.spdx.library.model.compat.v2.GenericSpdxElement; -import org.spdx.library.model.compat.v2.GenericSpdxItem; - - -/** - * Value which is a stored typed item - */ -public class TypedValue { - - static Set SPDX_CLASSES; - - static { - Set spdxClasses = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); - spdxClasses.addAll(Arrays.asList(SpdxConstants.ALL_SPDX_CLASSES)); - SPDX_CLASSES = Collections.unmodifiableSet(spdxClasses); - } - - - String objectUri; - String type; - - public TypedValue(String objectUri, String type) throws SpdxInvalidIdException, SpdxInvalidTypeException { - if (objectUri == null) { - throw new SpdxInvalidIdException("Null value Id"); - } - // TODO: can add some additional checks for different string formats based on the type - if (type == null) { - throw new SpdxInvalidTypeException("Null type"); - } - if (!SPDX_CLASSES.contains(type) && !GenericModelObject.GENERIC_MODEL_OBJECT_TYPE.equals(type) - &&!"ModelObjectForTesting".equals(type) - &&!"ElementForTest".equals(type) - &&!GenericSpdxElement.GENERIC_SPDX_ELEMENT_TYPE.equals(type) - &&!GenericSpdxItem.GENERIC_SPDX_ITEM_TYPE.equals(type)) { - throw new SpdxInvalidTypeException(type + " is not a valid SPDX class"); - } - this.objectUri = objectUri; - this.type = type; - } - - /** - * @return the objectUri - */ - public String getObjectUri() { - return objectUri; - } - - /** - * @return the type - */ - public String getType() { - return type; - } - - @Override - public boolean equals(Object o) { - if (o == null) { - return false; - } - if (!(o instanceof TypedValue)) { - return false; - } - TypedValue tv = (TypedValue)o; - return tv.getObjectUri().equals(this.objectUri) && tv.getType().equals(this.type); - } - - @Override - public int hashCode() { - return 181 ^ this.objectUri.hashCode() ^ this.type.hashCode(); - } -} \ No newline at end of file diff --git a/src/main/java/org/spdx/library/Version.java b/src/main/java/org/spdx/library/Version.java index b1c5704b6..f3461243f 100644 --- a/src/main/java/org/spdx/library/Version.java +++ b/src/main/java/org/spdx/library/Version.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.regex.Matcher; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; + /** * Static class to manage the SPDX versions and the version of the implementation classes * @author Gary O'Neall @@ -30,7 +32,6 @@ */ public class Version { - public static final String POINT_EIGHT_SPDX_VERSION = "SPDX-0.8"; public static final String POINT_NINE_SPDX_VERSION = "SPDX-0.9"; public static final String ONE_DOT_ZERO_SPDX_VERSION = "SPDX-1.0"; diff --git a/src/main/java/org/spdx/library/model/ExternalElement.java b/src/main/java/org/spdx/library/model/ExternalElement.java deleted file mode 100644 index c9395fbaf..000000000 --- a/src/main/java/org/spdx/library/model/ExternalElement.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.core.CreationInfo; -import org.spdx.library.model.v3.core.Element; -import org.spdx.library.model.v3.core.ExternalIdentifier; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.library.model.v3.core.ExternalRef; -import org.spdx.library.model.v3.core.ProfileIdentifierType; -import org.spdx.storage.IModelStore; - -/** - * This class represents an SPDX element which is not present in the model store - * - * The external property provides optional information on where the external element may be located and verified - * - * @author Gary O'Neall - * - */ -public class ExternalElement extends Element implements IndividualUriValue { - - ExternalMap external; - - /** - * @param store store to use for the inflated object - * @param copyManager if non-null, implicitly copy any referenced properties from other model stores - * @param objectUri URI or anonymous ID for the Element - * @param external Information about the external map - * @throws InvalidSPDXAnalysisException - */ - public ExternalElement(IModelStore store, String objectUri, ModelCopyManager copyManager, - ExternalMap external) throws InvalidSPDXAnalysisException { - super(store, objectUri, copyManager, true); - this.external = external; - } - - /* (non-Javadoc) - * @see org.spdx.library.IndividualUriValue#getIndividualURI() - */ - @Override - public String getIndividualURI() { - return getObjectUri(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() - */ - @Override - public String getType() { - return "Core.ExternalElement"; - } - - // Getters and Setters - - /** - * @return the externalMap - */ - public ExternalMap getExternal() { - return this.external; - } - - - - /** - * @return the creationInfo - */ - @Override - public CreationInfo getCreationInfo() throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); - } - - @Override - public Collection getExternalRefs() { - throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); - } - @Override - public Collection getExternalIdentifiers() { - throw new RuntimeException(new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store.")); - } - - - /** - * @return the description - */ - public Optional getDescription() throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); - } - /** - * @param description the description to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - @Override - public Element setDescription(@Nullable String description) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); - } - - /** - * @return the summary - */ - @Override - public Optional getSummary() throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); - } - /** - * @param summary the summary to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - @Override - public Element setSummary(@Nullable String summary) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException(getObjectUri() + " is external to this object store."); - } - - - @Override - public String toString() { - return "External Element: "+getObjectUri(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.List) - */ - @Override - public List _verify(Set verifiedIds, String specVersion, List profiles) { - return new ArrayList<>(); - } - -} diff --git a/src/main/java/org/spdx/library/model/ModelCollection.java b/src/main/java/org/spdx/library/model/ModelCollection.java deleted file mode 100644 index efcb6e82c..000000000 --- a/src/main/java/org/spdx/library/model/ModelCollection.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import javax.annotation.Nullable; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxObjectNotInStoreException; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; - -/** - * Collection of elements stored in a ModelStore - * - * @author Gary O'Neall - * - */ -public class ModelCollection implements Collection { - - private IModelStore modelStore; - private String objectUri; - private PropertyDescriptor propertyDescriptor; - private ModelCopyManager copyManager; - /** - * Map of URI's of elements referenced but not present in the store - */ - protected Map externalMap; - private Class type; -// private boolean licensePrimitiveAssignable; // If true, NONE and NOASSERTION should be converted to NoneLicense and NoAssertionLicense - - class ModelCollectionIterator implements Iterator { - - private Iterator storageIterator; - - public ModelCollectionIterator(Iterator storageIterator) { - this.storageIterator = storageIterator; - } - - @Override - public boolean hasNext() { - return storageIterator.hasNext(); - } - - @Override - public Object next() { - return checkConvertTypedValue(storageIterator.next()); - } - - } - - /** - * @param modelStore Storage for the model collection - * @param objectUri Object URI or anonymous ID - * @param propertyDescriptor descriptor for the property use for the model collections - * @param copyManager if non-null, use this to copy properties when referenced outside this model store - * @param type The class of the elements to be stored in the collection if none, null if not known - * @param externalMap Map of URI's of elements referenced but not present in the store - * @throws InvalidSPDXAnalysisException on parsing or store errors - */ - public ModelCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, - @Nullable ModelCopyManager copyManager, - @Nullable Class type, Map externalMap) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - this.modelStore = modelStore; - Objects.requireNonNull(objectUri, "Object URI or anonymous ID can not be null"); - this.objectUri = objectUri; - Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); - this.propertyDescriptor = propertyDescriptor; - this.copyManager = copyManager; - if (!modelStore.exists(objectUri)) { - throw new SpdxIdNotFoundException(objectUri+" does not exist."); - } - if (Objects.nonNull(type)) { - this.type = type; -// licensePrimitiveAssignable = type.isAssignableFrom(SpdxNoneLicense.class) || type.isAssignableFrom(SpdxNoAssertionLicense.class); - if (!modelStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, type)) { - throw new SpdxInvalidTypeException("Incompatible type for property "+propertyDescriptor+": "+type.toString()); - } -// } else { -// licensePrimitiveAssignable = false; - } - } - - @Override - public int size() { - try { - return this.modelStore.collectionSize(objectUri, this.propertyDescriptor); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean isEmpty() { - try { - return this.modelStore.collectionSize(objectUri, this.propertyDescriptor) == 0; - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean contains(Object o) { - try { - Object storedObject = null; - try { - storedObject = ModelObjectHelper.modelObjectToStoredObject(o, modelStore, copyManager); - } catch (SpdxObjectNotInStoreException e1) { - return false; // The exception is due to the model object not being in the store - } - return this.modelStore.collectionContains( - objectUri, this.propertyDescriptor, storedObject); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - private Object checkConvertTypedValue(Object value) { - try { - Object retval = ModelObjectHelper.storedObjectToModelObject(value, modelStore, copyManager, externalMap); -// if (licensePrimitiveAssignable && retval instanceof IndividualUriValue) { -// String uri = ((IndividualUriValue)retval).getIndividualURI(); -// if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { -// retval = new SpdxNoAssertionLicense(); -// } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { -// retval = new SpdxNoneLicense(); -// } -// } - if (Objects.nonNull(this.type) && !this.type.isAssignableFrom(retval.getClass())) { - if (retval instanceof IndividualUriValue) { - throw new SpdxInvalidTypeException("No enumeration was found for URI "+((IndividualUriValue)retval).getIndividualURI()+ - " for type "+type.toString()); - } else { - throw new SpdxInvalidTypeException("A collection element of type "+retval.getClass().toString()+ - " was found in a collection of type "+type.toString()); - } - } - return retval; - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - /** - * Converts any typed or individual value objects to a ModelObject - */ - private Function checkConvertTypedValue = value -> { - return checkConvertTypedValue(value); - }; - - public List toImmutableList() { - return (List) Collections.unmodifiableList(StreamSupport.stream( - Spliterators.spliteratorUnknownSize(this.iterator(), Spliterator.ORDERED), false).map(checkConvertTypedValue) - .collect(Collectors.toList())); - } - - @Override - public Iterator iterator() { - try { - return new ModelCollectionIterator( - modelStore.listValues(objectUri, propertyDescriptor)); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public Object[] toArray() { - return toImmutableList().toArray(); - } - - @Override - public AT[] toArray(AT[] a) { - return toImmutableList().toArray(a); - } - - @Override - public boolean add(Object element) { - try { - return modelStore.addValueToCollection( - objectUri, propertyDescriptor, - ModelObjectHelper.modelObjectToStoredObject(element, modelStore, copyManager)); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean remove(Object element) { - try { - return modelStore.removeValueFromCollection(objectUri, propertyDescriptor, - ModelObjectHelper.modelObjectToStoredObject(element, modelStore, null)); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean containsAll(Collection c) { - return toImmutableList().containsAll(c); - } - - @Override - public boolean addAll(Collection c) { - boolean retval = false; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - if (add(iter.next())) { - retval = true; - } - } - return retval; - } - - @Override - public boolean removeAll(Collection c) { - boolean retval = false; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - if (remove(iter.next())) { - retval = true; - } - } - return retval; - } - - @Override - public boolean retainAll(Collection c) { - List values = toImmutableList(); - boolean retval = false; - for (Object value:values) { - if (!c.contains(value)) { - if (remove(value)) { - retval = true; - } - } - } - return retval; - } - - @Override - public void clear() { - try { - modelStore.clearValueCollection(objectUri, propertyDescriptor); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - /** - * @return the modelStore - */ - public IModelStore getModelStore() { - return modelStore; - } - - /** - * @return the objectUri - */ - public String getObjectUri() { - return objectUri; - } - - /** - * @return the propertyDescriptor - */ - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } -} diff --git a/src/main/java/org/spdx/library/model/ModelObject.java b/src/main/java/org/spdx/library/model/ModelObject.java deleted file mode 100644 index 74cd1a824..000000000 --- a/src/main/java/org/spdx/library/model/ModelObject.java +++ /dev/null @@ -1,1009 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.NotEquivalentReason; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.TypedValue; -import org.spdx.library.Version; -import org.spdx.library.NotEquivalentReason.NotEquivalent; -import org.spdx.library.SpdxConstants; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; -import org.spdx.library.model.v3.core.CreationInfo; -import org.spdx.library.model.v3.core.Element; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.library.model.v3.core.ProfileIdentifierType; -import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.IModelStore.ModelUpdate; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * @author Gary O'Neall - * - * Superclass for all SPDX model objects - * - * Provides the primary interface to the storage class that access and stores the data for - * the model objects. - * - * This class includes several helper methods to manage the storage and retrieval of properties. - * - * Each model object is in itself stateless. All state is maintained in the Model Store. - * - * The concrete classes are expected to implements getters for the model class properties which translate - * into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property descriptor - * is passed as a parameter. - * - * There are 2 methods of setting values: - * - call the setPropertyValue, clearValueCollection or addValueToCollection methods - this will call the modelStore and store the - * value immediately - * - Gather a list of updates by calling the updatePropertyValue, updateClearValueList, or updateAddPropertyValue - * methods. These methods return a ModelUpdate which can be applied later by calling the apply() method. - * A convenience method Write.applyUpdatesInOneTransaction will perform all updates within - * a single transaction. This method may result in higher performance updates for some Model Store implementations. - * Note that none of the updates will be applied until the storage manager update method is invoked. - * - * Property values are restricted to the following types: - * - String - Java Strings - * - Booolean - Java Boolean or primitive boolean types - * - ModelObject - A concrete subclass of this type - * - {@literal Collection} - A Collection of type T where T is one of the supported non-collection types - * - * This class also handles the conversion of a ModelObject to and from a TypeValue for storage in the ModelStore. - * - */ -public abstract class ModelObject { - - static final Logger logger = LoggerFactory.getLogger(ModelObject.class); - private IModelStore modelStore; - private String objectUri; - - /** - * If non null, a reference made to a model object stored in a different modelStore and/or - * document will be copied to this modelStore and documentUri - */ - private ModelCopyManager copyManager = null; - /** - * if true, checks input values for setters to verify valid SPDX inputs - */ - protected boolean strict = true; - - NotEquivalentReason lastNotEquivalentReason = null; - - /** - * Map of URI's of elements referenced but not present in the store - */ - protected Map externalMap = new HashMap<>(); - - /** - * Create a new Model Object using an Anonymous ID with the defualt store and default document URI - * @throws InvalidSPDXAnalysisException - */ - public ModelObject() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); - } - - /** - * Open or create a model object with the default store - * @param objectUri Anonymous ID or URI for the model object - * @throws InvalidSPDXAnalysisException - */ - public ModelObject(String objectUri) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), objectUri, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * Creates a new model object - * @param modelStore Storage for the model objects - Must support model V3 classes - * @param objectUri Anonymous ID or URI for the model object - * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - public ModelObject(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model Store can not be null"); - Objects.requireNonNull(objectUri, "Object URI can not be null"); - - if (!SpdxMajorVersion.VERSION_3.equals(modelStore.getSpdxVersion())) { - logger.error("Trying to create an SPDX version 3 model object in an SPDX version 2 model store"); - throw new InvalidSPDXAnalysisException("Trying to create an SPDX version 3 model object in an SPDX version 2 model store"); - } - this.modelStore = modelStore; - this.copyManager = copyManager; - this.objectUri = objectUri; - Optional existing = modelStore.getTypedValue(objectUri); - if (existing.isPresent()) { - if (create && !existing.get().getType().equals(getType())) { - logger.error("Can not create "+objectUri+". It is already in use with type "+existing.get().getType()+" which is incompatible with type "+getType()); - throw new SpdxIdInUseException("Can not create "+objectUri+". It is already in use with type "+existing.get().getType()+" which is incompatible with type "+getType()); - } - } else { - if (create) { - IModelStoreLock lock = enterCriticalSection(false); - // re-check since previous check was done outside of the lock - try { - if (!modelStore.exists(objectUri)) { - modelStore.create(objectUri, getType()); - } - } finally { - lock.unlock(); - } - } else { - logger.error(objectUri+" does not exist"); - throw new SpdxIdNotFoundException(objectUri+" does not exist"); - } - } - } - - /** - * @param builder base builder to create the ModelObject from - * @throws InvalidSPDXAnalysisException - */ - public ModelObject(ModelObjectBuilder builder) throws InvalidSPDXAnalysisException { - this(builder.modelStore, builder.objectUri, builder.copyManager, true); - this.strict = builder.strict; - this.externalMap = builder.externalMap; - } - - // Abstract methods that must be implemented in the subclasses - /** - * @return The class name for this object. Class names are defined in the constants file - */ - public abstract String getType(); - - /** - * Implementation of the specific verifications for this model object - * @param specVersion Version of the SPDX spec to verify against - * @param verifiedElementIds list of all Element Id's which have already been verified - prevents infinite recursion - * @param profiles list of profile identifiers to validate against - * @return Any verification errors or warnings associated with this object - */ - protected abstract List _verify(Set verifiedElementIds, String specVersion, List profiles); - - /** - * Enter a critical section. leaveCriticialSection must be called. - * @param readLockRequested true implies a read lock, false implies write lock. - * @throws InvalidSPDXAnalysisException - */ - public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { - return modelStore.enterCriticalSection(readLockRequested); - } - - /** - * Leave a critical section. Releases the lock form the matching enterCriticalSection - */ - public void leaveCriticalSection(IModelStoreLock lock) { - modelStore.leaveCriticalSection(lock); - } - - /** - * @param specVersion Version of the SPDX spec to verify against - * @param verifiedElementUris list of all element object URIs which have already been verified - prevents infinite recursion - * @param profiles list of profile identifiers to validate against - * @return Any verification errors or warnings associated with this object - */ - public List verify(Set verifiedElementUris, String specVersion, List profiles) { - if (verifiedElementUris.contains(this.objectUri)) { - return new ArrayList<>(); - } else { - // The verifiedElementId is added in the SpdxElement._verify method - return _verify(verifiedElementUris, specVersion, profiles); - } - } - - /** - * @param specVersion Version of the SPDX spec to verify against - * @param verifiedElementUris list of all element object URIs which have already been verified - prevents infinite recursion - * @return Any verification errors or warnings associated with this object - */ - public List verify(Set verifiedElementUris, String specVersion) { - List profiles = new ArrayList<>(); - if (this instanceof Element) { - CreationInfo creationInfo; - try { - creationInfo = ((Element)this).getCreationInfo(); - if (Objects.nonNull(creationInfo)) { - profiles = new ArrayList<>(creationInfo.getProfiles()); - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting element profile for verification", e); - } - } - return verify(verifiedElementUris, specVersion, profiles); - } - - /** - * Verifies against the more recent supported specification version - * @return Any verification errors or warnings associated with this object - */ - public List verify() { - return verify(Version.CURRENT_SPDX_VERSION); - } - - /** - * @param specVersion Version of the SPDX spec to verify against - * @param profiles list of profile identifiers to validate against - * @return Any verification errors or warnings associated with this object - */ - public List verify(String specVersion, List profiles) { - return verify(new HashSet(), specVersion, profiles); - } - - /** - * @param specVersion Version of the SPDX spec to verify against - * @return Any verification errors or warnings associated with this object - */ - public List verify(String specVersion) { - return verify(new HashSet(), specVersion); - } - - /** - * @return the Object URI or anonymous ID - */ - public String getObjectUri() { - return this.objectUri; - } - - /** - * @return the model store for this object - */ - public IModelStore getModelStore() { - return this.modelStore; - } - - /** - * @return if strict input checking is enabled - */ - public boolean isStrict() { - return strict; - } - - /** - * @param strict if true, inputs will be validated against the SPDX spec - */ - public void setStrict(boolean strict) { - this.strict = strict; - } - - /** - * @return the externalMap - */ - public Map getExternalMap() { - return externalMap; - } - - /** - * @param externalMap the externalMap to set - */ - public void setExternalMap(Map externalMap) { - this.externalMap = externalMap; - } - - //The following methods are to manage the properties associated with the model object - /** - * @return all names of property descriptors currently associated with this object - * @throws InvalidSPDXAnalysisException - */ - public List getPropertyValueDescriptors() throws InvalidSPDXAnalysisException { - return modelStore.getPropertyValueDescriptors(this.objectUri); - } - - /** - * Get an object value for a property - * @param propertyDescriptor Descriptor for the property - * @return value associated with a property - */ - protected Optional getObjectPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional retval = ModelObjectHelper.getObjectPropertyValue(modelStore, objectUri, propertyDescriptor, copyManager, externalMap); - if (retval.isPresent() && retval.get() instanceof ModelObject && !strict) { - ((ModelObject)retval.get()).setStrict(strict); - } - return retval; - } - - /** - * Set a property value for a property descriptor, creating the property if necessary - * @param propertyDescriptor Descriptor for the property associated with this object - * @param value Value to associate with the property - * @throws InvalidSPDXAnalysisException - */ - protected void setPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Object value) throws InvalidSPDXAnalysisException { - if (this instanceof IndividualUriValue) { - throw new InvalidSPDXAnalysisException("Can not set a property for the literal value "+((IndividualUriValue)this).getIndividualURI()); - } - ModelObjectHelper.setPropertyValue(this.modelStore, objectUri, propertyDescriptor, value, copyManager); - } - - /** - * Create an update when, when applied by the ModelStore, sets a property value for a property descriptor, creating the property if necessary - * @param propertyDescriptor Descriptor for the property associated with this object - * @param value Value to associate with the property - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updatePropertyValue(PropertyDescriptor propertyDescriptor, Object value) { - return () ->{ - ModelObjectHelper.setPropertyValue(this.modelStore, objectUri, propertyDescriptor, value, copyManager); - }; - } - - /** - * @param propertyDescriptor Descriptor for a property - * @return the Optional String value associated with a property, null if no value is present - * @throws SpdxInvalidTypeException - */ - protected Optional getStringPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (result.isPresent()) { - if (result.get() instanceof String) { - return Optional.of((String)result.get()); - } else { - logger.error("Property "+propertyDescriptor+" is not of type String"); - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type String"); - } - } else { - return Optional.empty(); - } - } - - /** - * @param propertyDescriptor Descriptor for a property - * @return the Optional Integer value associated with a property, null if no value is present - * @throws InvalidSPDXAnalysisException - */ - protected Optional getIntegerPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - Optional retval; - if (result.isPresent()) { - if (!(result.get() instanceof Integer)) { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Integer"); - } - retval = Optional.of((Integer)result.get()); - } else { - retval = Optional.empty(); - } - return retval; - } - - /** - * @param propertyDescriptor descriptor for the property - * @return an enumeration value for the property - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - protected Optional> getEnumPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (!result.isPresent()) { - return Optional.empty(); - } - if (result.get() instanceof Enum) { - return (Optional>)(Optional)result; - } - if (!(result.get() instanceof IndividualUriValue)) { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Individual Value or enum"); - } - Enum retval = SpdxEnumFactoryCompatV2.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); - if (Objects.isNull(retval)) { - logger.error("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); - throw new InvalidSPDXAnalysisException("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); - } else { - return Optional.of(retval); - } - } - - /** - * @param propertyDescriptor Descriptor for the property - * @return the Optional Boolean value for a property - * @throws SpdxInvalidTypeException - */ - protected Optional getBooleanPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (result.isPresent()) { - if (result.get() instanceof Boolean) { - return Optional.of((Boolean)result.get()); - } else if (result.get() instanceof String) { - // try to convert - String sResult = ((String)result.get()).toLowerCase(); - if ("true".equals(sResult)) { - return Optional.of(Boolean.valueOf(true)); - } else if ("false".equals(sResult)) { - return Optional.of(Boolean.valueOf(false)); - } else { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); - } - } else { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); - } - } else { - return Optional.empty(); - } - } - - /** - * Converts property values to an AnyLicenseInfo if possible - if NONE or NOASSERTION URI value, convert to the appropriate license - * @param propertyDescriptor descriptor for the property - * @return AnyLicenseInfo license info for the property - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - protected Optional getAnyLicenseInfoPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (!result.isPresent()) { - return Optional.empty(); - } else if (result.get() instanceof AnyLicenseInfo) { - return (Optional)(Optional)result; - } else if (result.get() instanceof SimpleUriValue) { - Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null, externalMap); - if (val instanceof AnyLicenseInfo) { - return Optional.of((AnyLicenseInfo)val); - } else { - logger.error("Invalid type for AnyLicenseInfo property: "+val.getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for AnyLicenseInfo property: "+val.getClass().toString()); - } - } else { - logger.error("Invalid type for AnyLicenseInfo property: "+result.get().getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for AnyLicenseInfo property: "+result.get().getClass().toString()); - } - } - - /** - * Converts property values to an SpdxElement if possible - if individual value, convert to the appropriate SpdxElement - * @param propertyDescriptor Descriptor for the property - * @return SpdxElement stored - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - protected Optional getElementPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (!result.isPresent()) { - return Optional.empty(); - } else if (result.get() instanceof Element) { - return (Optional)(Optional)result; - } else if (result.get() instanceof SimpleUriValue) { - Object val = ((SimpleUriValue)(result.get())).toModelObject(modelStore, copyManager, null, externalMap); - if (val instanceof Element) { - return Optional.of((Element)val); - } else { - logger.error("Invalid type for Element property: "+val.getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for Element property: "+val.getClass().toString()); - } - } else { - logger.error("Invalid type for SpdxElement property: "+result.get().getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for SpdxElement property: "+result.get().getClass().toString()); - } - } - - /** - * Removes a property and its value from the model store if it exists - * @param propertyDescriptor Descriptor for the property associated with this object to be removed - * @throws InvalidSPDXAnalysisException - */ - protected void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - ModelObjectHelper.removeProperty(modelStore, objectUri, propertyDescriptor); - } - - /** - * Create an update when, when applied by the ModelStore, removes a property and its value from the model store if it exists - * @param propertyDescriptor Descriptor for the property associated with this object to be removed - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor) { - return () -> { - ModelObjectHelper.removeProperty(modelStore, objectUri, propertyDescriptor); - }; - } - - /** - * Clears a collection of values associated with a property - * @param propertyDescriptor Descriptor for the property - */ - protected void clearValueCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - ModelObjectHelper.clearValueCollection(modelStore, objectUri, propertyDescriptor); - } - - /** - * Create an update when, when applied by the ModelStore, clears a collection of values associated with a property - * @param propertyDescriptor Descriptor for the property - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDescriptor) { - return () ->{ - ModelObjectHelper.clearValueCollection(modelStore, objectUri, propertyDescriptor); - }; - } - - /** - * Add a value to a collection of values associated with a property. If a value is a ModelObject and does not - * belong to the document, it will be copied into the object store - * @param propertyDescriptor Descriptor for the property - * @param value to add - * @throws InvalidSPDXAnalysisException - */ - protected void addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - ModelObjectHelper.addValueToCollection(modelStore, objectUri, propertyDescriptor, value, copyManager); - } - - /** - * Create an update when, when applied, adds a value to a collection of values associated with a property. If a value is a ModelObject and does not - * belong to the document, it will be copied into the object store - * @param propertyDescriptor Descriptor for the property - * @param value to add - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateAddPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) { - return () ->{ - ModelObjectHelper.addValueToCollection(modelStore, objectUri, propertyDescriptor, value, copyManager); - }; - } - - /** - * Remove a property value from a collection - * @param propertyDescriptor Descriptor for the property - * @param value Value to be removed - * @throws InvalidSPDXAnalysisException - */ - protected void removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - ModelObjectHelper.removePropertyValueFromCollection(modelStore, objectUri, propertyDescriptor, value); - } - - /** - * Create an update when, when applied, removes a property value from a collection - * @param propertyDescriptor descriptor for the property - * @param value Value to be removed - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateRemovePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) { - return () -> { - ModelObjectHelper.removePropertyValueFromCollection(modelStore, objectUri, propertyDescriptor, value); - }; - } - - /** - * @param propertyDescriptor Descriptor for the property - * @return Set of values associated with a property - */ - protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelSet(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type, externalMap); - } - - /** - * @param propertyDescriptor Descriptor for the property - * @return Collection of values associated with a property - */ - protected ModelCollection getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelCollection(this.modelStore, this.objectUri, propertyDescriptor, this.copyManager, type, externalMap); - } - - /** - * @param propertyDescriptor Descriptor for property - * @return Collection of Strings associated with the property - * @throws SpdxInvalidTypeException - */ - @SuppressWarnings("unchecked") - protected Collection getStringCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!isCollectionMembersAssignableTo(propertyDescriptor, String.class)) { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" does not contain a collection of Strings"); - } - return (Collection)(Collection)getObjectPropertyValueSet(propertyDescriptor, String.class); - } - - protected boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return modelStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, - ModelObjectHelper.modelClassToStoredClass(clazz)); - } - - /** - * @param compare - * @return true if all the properties have the same or equivalent values - */ - public boolean equivalent(ModelObject compare) throws InvalidSPDXAnalysisException { - return equivalent(compare, false); - } - - /** - * @param compare - * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion - * @return true if all the properties have the same or equivalent values - */ - public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (!this.getClass().equals(compare.getClass())) { - lastNotEquivalentReason = new NotEquivalentReason(NotEquivalent.DIFFERENT_CLASS); - return false; - } - List propertyValueDescriptors = getPropertyValueDescriptors(); - List comparePropertyValueDescriptors = new ArrayList(compare.getPropertyValueDescriptors()); // create a copy since we're going to modify it - for (PropertyDescriptor propertyDescriptor:propertyValueDescriptors) { - if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { - continue; - } - if (comparePropertyValueDescriptors.contains(propertyDescriptor)) { - if (!propertyValuesEquivalent(propertyDescriptor, this.getObjectPropertyValue(propertyDescriptor), - compare.getObjectPropertyValue(propertyDescriptor), ignoreRelatedElements)) { - lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.PROPERTY_NOT_EQUIVALENT, propertyDescriptor); - return false; - } - comparePropertyValueDescriptors.remove(propertyDescriptor); - } else { - // No property value - Optional propertyValueOptional = this.getObjectPropertyValue(propertyDescriptor); - if (propertyValueOptional.isPresent()) { - Object propertyValue = propertyValueOptional.get(); - if (isEquivalentToNull(propertyValue, propertyDescriptor)) { - continue; - } - lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.COMPARE_PROPERTY_MISSING, propertyDescriptor); - return false; - } - } - } - for (PropertyDescriptor propertyDescriptor:comparePropertyValueDescriptors) { // check any remaining property values - if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { - continue; - } - Optional comparePropertyValueOptional = compare.getObjectPropertyValue(propertyDescriptor); - if (!comparePropertyValueOptional.isPresent()) { - continue; - } - Object comparePropertyValue = comparePropertyValueOptional.get(); - if (isEquivalentToNull(comparePropertyValue, propertyDescriptor)) { - continue; - } - lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.MISSING_PROPERTY, propertyDescriptor); - return false; - } - return true; - } - - // Some values are treated like null in comparisons - in particular empty model collections and - // "no assertion" values and a filesAnalyzed filed with a value of true - private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor propertyDescriptor) { - if (propertyValue instanceof ModelCollection) { - return isEmptyModelCollection(propertyValue); - } else if (isNoAssertion(propertyValue)) { - return true; - } else { - return false; - } - } - - /** - * @param propertyDescriptor property descriptor for the object in question - * @return true if the object is "to" part of a relationships - */ - private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { - return SpdxConstants.CORE_PROP_TO.equals(propertyDescriptor); - } - - /** - * @param value value to test against an empty model collection - * @return true if the value is a model collection and it is empty - */ - private boolean isEmptyModelCollection(Object value) { - return (value instanceof ModelCollection) - && (((ModelCollection) value).size() == 0); - } - - private boolean isNoAssertion(Object propertyValue) { - return false; - //TODO: Implement - } - - /** - * @param propertyDescriptor Descriptor for the property - * @param valueA value to compare - * @param valueB value to compare - * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion - * @return true if the property values are equivalent - * @throws InvalidSPDXAnalysisException - */ - private boolean propertyValuesEquivalent(PropertyDescriptor propertyDescriptor, Optional valueA, - Optional valueB, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (!valueA.isPresent()) { - if (valueB.isPresent()) { - return isEmptyModelCollection(valueB.get()); - } - } else if (!valueB.isPresent()) { - return isEmptyModelCollection(valueA.get()); - } else if (valueA.get() instanceof ModelCollection && valueB.get() instanceof ModelCollection) { - List myList = ((ModelCollection)valueA.get()).toImmutableList(); - List compareList = ((ModelCollection)valueB.get()).toImmutableList(); - if (!areEquivalent(myList, compareList, ignoreRelatedElements)) { - return false; - } - } else if (valueA.get() instanceof List && valueB.get() instanceof List) { - if (!areEquivalent((List)valueA.get(), (List)valueB.get(), ignoreRelatedElements)) { - return false; - } - } else if (valueA.get() instanceof IndividualUriValue && valueB.get() instanceof IndividualUriValue) { - if (!Objects.equals(((IndividualUriValue)valueA.get()).getIndividualURI(), ((IndividualUriValue)valueB.get()).getIndividualURI())) { - return false; - } - // Note: we must check the IndividualValue before the ModelObject types since the IndividualValue takes precedence - } else if (valueA.get() instanceof ModelObject && valueB.get() instanceof ModelObject) { - if (!((ModelObject)valueA.get()).equivalent(((ModelObject)valueB.get()), - isRelatedElement(propertyDescriptor) ? true : ignoreRelatedElements)) { - return false; - } - - } else if (!optionalObjectsEquivalent(valueA, valueB)) { // Present, not a list, and not a TypedValue - return false; - } - return true; - } - - /** - * Compares 2 simple optional objects considering NONE and NOASSERTION values which are equivalent to their strings - * @param valueA - * @param valueB - * @return - */ - private boolean optionalObjectsEquivalent(Optional valueA, Optional valueB) { - if (Objects.equals(valueA, valueB)) { - return true; - } - if (!valueA.isPresent()) { - return false; - } - if (!valueB.isPresent()) { - return false; - } - if (valueA.get() instanceof IndividualUriValue) { - if (!(valueB.get() instanceof IndividualUriValue)) { - return false; - } - - return ((IndividualUriValue)(valueA.get())).getIndividualURI().equals(((IndividualUriValue)(valueB.get())).getIndividualURI()); - } - if (valueA.get() instanceof String && valueB.get() instanceof String) { - return normalizeString((String)valueA.get()).equals(normalizeString((String)valueB.get())); - } - return false; - } - - /** - * Normalize a string for dos and linux linefeeds - * @param s - * @return DOS style only linefeeds - */ - private Object normalizeString(String s) { - return s.replaceAll("\r\n", "\n").trim(); - } - - /** - * Checks if for each item on either list, there is an item in the other list that is equivalent. - * @param ignoreRelatedElements Whether related elements should be ignored in the comparison - */ - private boolean areEquivalent(List firstList, List secondList, - boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (firstList.size() != secondList.size()) { - return false; - } - for (Object item : firstList) { - if (!containsEqualOrEquivalentItem(secondList, item, ignoreRelatedElements)) { - return false; - } - } - for (Object item : secondList) { - if (!containsEqualOrEquivalentItem(firstList, item, ignoreRelatedElements)) { - return false; - } - } - return true; - } - - /** - * Searches a list for an equal or equivalent item - * @param list list to search - * @param itemToFind the item we're looking for - * @param ignoreRelatedElements if true, don't follow the to parts of relationships - * @return true if the list contains an equal or equivalent item - * @throws InvalidSPDXAnalysisException - */ - private boolean containsEqualOrEquivalentItem(List list, Object itemToFind, - boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (list.contains(itemToFind)) { - return true; - } else if (itemToFind instanceof IndividualUriValue && list.contains(new SimpleUriValue((IndividualUriValue) itemToFind))) { - // Two IndividualUriValues are considered equal if their URI coincides - return true; - } - - if (!(itemToFind instanceof ModelObject)) { - return false; - } - - ModelObject objectToFind = (ModelObject) itemToFind; - for (Object objectToCompare : list) { - if (!(objectToCompare instanceof ModelObject)) { - continue; - } - if (objectToFind.equivalent((ModelObject) objectToCompare, ignoreRelatedElements)) { - return true; - } - } - return false; - } - - @Override - public int hashCode() { - if (modelStore.getIdType(objectUri) == IdType.Anonymous) { - return 11 ^ modelStore.hashCode() ^ objectUri.hashCode(); - } else { - return this.objectUri.hashCode(); - } - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof ModelObject)) { - // covers o == null, as null is not an instance of anything - return false; - } - ModelObject comp = (ModelObject)o; - if (getModelStore().getIdType(objectUri).equals(IdType.Anonymous)) { - return Objects.equals(modelStore, comp.getModelStore()) && Objects.equals(objectUri, comp.getObjectUri()); - } else { - return Objects.equals(objectUri, comp.getObjectUri()); - } - } - - - /** - * Clone a new object using a different model store - * @param modelStore - * @return - */ - public ModelObject clone(IModelStore modelStore) { - if (Objects.isNull(this.copyManager)) { - throw new IllegalStateException("A copy manager must be provided to clone"); - } - if (this.modelStore.equals(modelStore)) { - throw new IllegalStateException("Can not clone to the same model store"); - } - Objects.requireNonNull(modelStore, "Model store for clone must not be null"); - if (modelStore.exists(objectUri)) { - throw new IllegalStateException("Can not clone - "+objectUri+" already exists."); - } - try { - ModelObject retval = SpdxModelFactory.createModelObject(modelStore, objectUri, this.getType(), this.copyManager); - retval.copyFrom(this); - return retval; - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - /** - * Copy all the properties from the source object - * @param source - * @throws InvalidSPDXAnalysisException - */ - public void copyFrom(ModelObject source) throws InvalidSPDXAnalysisException { - if (Objects.isNull(copyManager)) { - throw new InvalidSPDXAnalysisException("Copying is not enabled for "+objectUri); - } - copyManager.copy(this.modelStore, objectUri, - source.getModelStore(), source.getObjectUri(), this.getType(), null, null, null, null); - } - - - /** - * Copy all the properties from the source SPDX version 2 model object - * @param source - * @throws InvalidSPDXAnalysisException - */ - public void copyFromV2(org.spdx.library.model.compat.v2.ModelObject source) throws InvalidSPDXAnalysisException { - if (Objects.isNull(copyManager)) { - throw new InvalidSPDXAnalysisException("Copying is not enabled for "+objectUri); - } - copyManager.copy(this.modelStore, objectUri, - source.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(source.getDocumentUri(), source.getId(), source.getModelStore()), - this.getType(), CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), source.getModelStore().getIdType(source.getId()) == IdType.Anonymous), - null, - CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), false), - null); - } - - /** - * Set the copy manager - * @param copyManager copy manager to set - */ - public void setCopyManager(ModelCopyManager copyManager) { - this.copyManager = copyManager; - } - - /** - * @return the copy manager - value may be null if copies are not allowd - */ - public ModelCopyManager getCopyManager() { - return this.copyManager; - } - - /** - * @return a typed value representation of this object suitable for storage in the model store - * @throws InvalidSPDXAnalysisException - */ - protected TypedValue toTypedValue() throws InvalidSPDXAnalysisException { - return new TypedValue(objectUri, getType()); - } - - @Override - public String toString() { - return this.getType() + ":" + objectUri; - } - - /** - * Base builder class for all model objects - * - */ - public static class ModelObjectBuilder { - - public IModelStore modelStore; - public String objectUri; - public ModelCopyManager copyManager; - public boolean strict = true; - public Map externalMap = new HashMap<>(); - - public ModelObjectBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { - this.modelStore = modelStore; - this.objectUri = objectUri; - this.copyManager = copyManager; - } - - public void setStrict(boolean strict) { - this.strict = strict; - } - - public void setExternalMap(Map externalMap) { - this.externalMap = externalMap; - } - } -} diff --git a/src/main/java/org/spdx/library/model/ModelObjectHelper.java b/src/main/java/org/spdx/library/model/ModelObjectHelper.java deleted file mode 100644 index e86d244a6..000000000 --- a/src/main/java/org/spdx/library/model/ModelObjectHelper.java +++ /dev/null @@ -1,313 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.SpdxObjectNotInStoreException; -import org.spdx.library.TypedValue; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; -import org.spdx.storage.IModelStore.IModelStoreLock; - -/** - * A set of static methods to help with common ModelObject functions - * - * @author Gary O'Neall - * - */ -public class ModelObjectHelper { - - private ModelObjectHelper() { - // this is only a static helper class - } - - /** - * Get an object value for a property - * @param modelStore Model store for the object - * @param objectUri the Object URI or anonymous ID - * @param propertyDescriptor property descriptor for the property - * @param copyManager if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available - * @param externalMap map of URI's to ExternalMaps for any external elements - * @return value associated with a property - * @throws InvalidSPDXAnalysisException - */ - public static Optional getObjectPropertyValue(IModelStore modelStore, String objectUri, - PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager, - @Nullable Map externalMap) throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - // NOTE: we use a write lock since the ModelStorageClassConverter may end up creating objects in the store - try { - if (!modelStore.exists(objectUri)) { - return Optional.empty(); - } else if (modelStore.isCollectionProperty(objectUri, propertyDescriptor)) { - return Optional.of(new ModelCollection<>(modelStore, objectUri, propertyDescriptor, copyManager, null, externalMap)); - } else { - return optionalStoredObjectToModelObject(modelStore.getValue(objectUri, - propertyDescriptor), modelStore, copyManager, externalMap); - } - } finally { - lock.unlock(); - } - } - - /** - * Set a property value for a property descriptor, creating the property if necessary - * @param modelStore Model store for the properties - * @param objectUri URI or anonymous ID for the object - * @param propertyDescriptor Descriptor for the property associated with this object - * @param value Value to associate with the property - * @param copyManager if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available - * @throws InvalidSPDXAnalysisException - */ - protected static void setPropertyValue(IModelStore modelStore, String objectUri, - PropertyDescriptor propertyDescriptor, @Nullable Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model Store can not be null"); - Objects.requireNonNull(objectUri, "Object Uri or anonymous ID can not be null"); - Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); - if (value == null) { - // we just remove the value - removeProperty(modelStore, objectUri, propertyDescriptor); - } else if (value instanceof Collection) { - replacePropertyValueCollection(modelStore, objectUri, propertyDescriptor, (Collection)value, copyManager); - } else { - modelStore.setValue(objectUri, propertyDescriptor, modelObjectToStoredObject(value, modelStore, copyManager)); - } - } - - /** - * Removes a property and its value from the model store if it exists - * @param modelStore Model store for the properties - * @param objectUri URI or anonymous ID for the object - * @param propertyDescriptor Descriptor for the property associated with this object to be removed - * @throws InvalidSPDXAnalysisException - */ - protected static void removeProperty(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - modelStore.removeProperty(objectUri, propertyDescriptor); - } - - /** - * Clears a collection of values associated with a property creating the property if it does not exist - * @param modelStore Model store for the properties - * @param objectUri URI or anonymous ID for the object - * @param propertyDescriptor Descriptor for the property - * @throws InvalidSPDXAnalysisException - */ - protected static void clearValueCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - modelStore.clearValueCollection(objectUri, propertyDescriptor); - } - - /** - * Add a value to a collection of values associated with a property. If a value - * is a ModelObject and does not belong to the document, it will be copied into - * the object store - * - * @param modelStore Model store for the properties - * @param objectUri URI or anonymous ID for the object - * @param propertyDescriptor Descriptor for the property - * @param value to add - * @param copyManager - * @throws InvalidSPDXAnalysisException - */ - protected static void addValueToCollection(IModelStore modelStore, String objectUri, - PropertyDescriptor propertyDescriptor, Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(value, "Value can not be null"); - modelStore.addValueToCollection(objectUri, propertyDescriptor, - modelObjectToStoredObject(value, modelStore, copyManager)); - } - - /** - * Replace the entire value collection for a property. If a value is a ModelObject and does not - * belong to the document, it will be copied into the object store - * @param modelStore Model store for the properties - * @param objectUri URI or anonymous ID for the object - * @param propertyDescriptor Descriptor for the property - * @param values collection of new properties - * @param copyManager if non-null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available - * @throws InvalidSPDXAnalysisException - */ - protected static void replacePropertyValueCollection(IModelStore modelStore, String objectUri, - PropertyDescriptor propertyDescriptor, Collection values, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - clearValueCollection(modelStore, objectUri, propertyDescriptor); - for (Object value:values) { - addValueToCollection(modelStore, objectUri, propertyDescriptor, value, copyManager); - } - } - - /** - * Remove a property value from a collection - * @param modelStore Model store for the properties - * @param objectUri URI or anonymous ID for the object - * @param propertyDescriptor descriptor for the property - * @param value Value to be removed - * @throws InvalidSPDXAnalysisException - */ - protected static void removePropertyValueFromCollection(IModelStore modelStore, String objectUri, - PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - modelStore.removeValueFromCollection(objectUri, propertyDescriptor, modelObjectToStoredObject(value, modelStore, null)); - } - - /** - * Converts any typed value or IndividualValue objects to a ModelObject, - * returning an existing ModelObject if it exists or creates a new ModelObject - * - * @param value Value which may be a TypedValue - * @param modelStore ModelStore to use in fetching or creating - * @param copyManager if not null, copy any referenced ID's outside of this - * document/model store - * @param externalMap map of URI's to ExternalMaps for any external elements - * @return the object itself unless it is a TypedValue, in which case a - * ModelObject is returned - * @throws InvalidSPDXAnalysisException - */ - public static Optional optionalStoredObjectToModelObject(Optional value, - IModelStore modelStore, ModelCopyManager copyManager, @Nullable Map externalMap) throws InvalidSPDXAnalysisException { - if (value.isPresent() && value.get() instanceof IndividualUriValue) { - return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()).toModelObject(modelStore, copyManager, - null, externalMap)); - } else if (value.isPresent() && value.get() instanceof TypedValue) { - TypedValue tv = (TypedValue)value.get(); - return Optional.of(SpdxModelFactory.createModelObject(modelStore, - tv.getObjectUri(), tv.getType(), copyManager)); - } else { - return value; - } - } - - /** - * Converts a stored object to it's appropriate model object type - * @param value - * @param modelStore - * @param copyManager if not null, copy any referenced ID's outside of this document/model store - * @return Model Object appropriate type - * @throws InvalidSPDXAnalysisException - */ - public static Object modelObjectToStoredObject(Object value, IModelStore modelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (value instanceof IndividualUriValue) { - // Convert to a simple URI value to save storage - return new SimpleUriValue((IndividualUriValue)value); - } else if (value instanceof ModelObject) { - ModelObject mValue = (ModelObject)value; - if (!mValue.getModelStore().equals(modelStore)) { - if (Objects.nonNull(copyManager)) { - return copyManager.copy(modelStore, mValue.getModelStore(), mValue.getObjectUri(), mValue.getType(), null, null, null, null); - } else { - throw new SpdxObjectNotInStoreException("Can not set a property value to a Model Object stored in a different model store"); - } - } else { - return mValue.toTypedValue(); - } - } else if (value instanceof Integer || value instanceof String || value instanceof Boolean || value instanceof IndividualUriValue) { - return value; - } else if (Objects.isNull(value)) { - throw new SpdxInvalidTypeException("Property value is null"); - } else { - throw new SpdxInvalidTypeException("Property value type not supported: "+value.getClass().getName()); - } - } - - /** - * Converts any typed value or individual value objects to a ModelObject, - * returning an existing ModelObject if it exists or creates a new ModelObject - * - * @param value Value which may be a TypedValue - * @param modelStore ModelStore to use in fetching or creating - * @param copyManager if not null, copy any referenced ID's outside of this - * document/model store - * @param externalMap map of URI's to ExternalMaps for any external elements - * @return the object itself unless it is a TypedValue, in which case a - * ModelObject is returned - * @throws InvalidSPDXAnalysisException - */ - public static Object storedObjectToModelObject(Object value, IModelStore modelStore, - ModelCopyManager copyManager, @Nullable Map externalMap) throws InvalidSPDXAnalysisException { - if (value instanceof IndividualUriValue) { // Note: this must be before the check for TypedValue - SimpleUriValue suv = new SimpleUriValue((IndividualUriValue)value); - return suv.toModelObject(modelStore, copyManager, null, externalMap); - } else if (value instanceof TypedValue) { - TypedValue tv = (TypedValue)value; - return SpdxModelFactory.getModelObject(modelStore, tv.getObjectUri(), tv.getType(), copyManager, true); - } else { - return value; - } - }; - - /** - * Convert the class to the appropriate stored class - * @param clazz Model class - * @return class compatible with stored classes - */ - public static Class modelClassToStoredClass(Class clazz) { - if (ModelObject.class.isAssignableFrom(clazz)) { - return TypedValue.class; - } else if (implementsIndividualUriValue(clazz)) { - return SimpleUriValue.class; - } else { - return clazz; - } - } - - /** - * @param clazz - * @return true if the clazz implements the IndividualUriValue interface - */ - public static boolean implementsIndividualUriValue(Class clazz) { - for (Class intefaceClass:clazz.getInterfaces()) { - if (intefaceClass.equals(IndividualUriValue.class)) { - return true; - } - } - return false; - } - - /** - * Verifies all elements in a collection - * @param specVersion version of the SPDX specification to verify against - * @param collection collection to be verifies - * @param verifiedIds verifiedIds list of all Id's which have already been verifieds - prevents infinite recursion - * @param warningPrefix String to prefix any warning messages - */ - public static List verifyCollection(Collection collection, String warningPrefix, Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - for (ModelObject mo:collection) { - for (String warning:mo.verify(verifiedIds, specVersion)) { - if (Objects.nonNull(warningPrefix)) { - retval.add(warningPrefix + warning); - } else { - retval.add(warning); - } - } - } - return retval; - } -} diff --git a/src/main/java/org/spdx/library/model/ModelSet.java b/src/main/java/org/spdx/library/model/ModelSet.java deleted file mode 100644 index 9689d990a..000000000 --- a/src/main/java/org/spdx/library/model/ModelSet.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.PropertyDescriptor; - -/** - * A ModelCollection implemented as a set where all items in the collection are unique based - * on equality (not based on equivalence). - * - * @author Gary O'Neall - * - */ -public class ModelSet extends ModelCollection { - - static final Logger logger = LoggerFactory.getLogger(ModelSet.class); - - /** - * @param modelStore Storage for the model collection - * @param objectUri Object URI or anonymous ID - * @param propertyDescriptor descriptor for the property use for the model collections - * @param copyManager if non-null, use this to copy properties when referenced outside this model store - * @param type The class of the elements to be stored in the collection if none, null if not known - * @param externalMap Map of URI's of elements referenced but not present in the store - * @throws InvalidSPDXAnalysisException on parsing or store errors - */ - public ModelSet(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, - @Nullable ModelCopyManager copyManager, @Nullable Class type, - Map externalMap) throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, propertyDescriptor, copyManager, type, externalMap); - } - - @Override - public boolean add(Object element) { - IModelStoreLock lock; - try { - lock = this.getModelStore().enterCriticalSection(false); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - try { - if (!super.contains(element)) { - return super.add(element); - } else { - return false; - } - } finally { - this.getModelStore().leaveCriticalSection(lock); - } - } - - @Override - public boolean addAll(Collection c) { - IModelStoreLock lock; - try { - lock = this.getModelStore().enterCriticalSection(false); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - try { - boolean retval = false; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - Object item = iter.next(); - if (!super.contains(item) && super.add(item)) { - retval = true; - } - } - return retval; - } finally { - this.getModelStore().leaveCriticalSection(lock); - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java b/src/main/java/org/spdx/library/model/compat/v2/Annotation.java deleted file mode 100644 index 2b0aa737f..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/Annotation.java +++ /dev/null @@ -1,302 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.storage.IModelStore; - -/** - * An Annotation is a comment on an SpdxItem by an agent. - * @author Gary O'Neall - * - */ -public class Annotation extends ModelObject implements Comparable { - - /** - * @throws InvalidSPDXAnalysisException - */ - public Annotation() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public Annotation(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public Annotation(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_ANNOTATION; - } - - /** - * @return annotation type - * @throws InvalidSPDXAnalysisException - */ - public AnnotationType getAnnotationType() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_TYPE); - if (retval.isPresent() && !(retval.get() instanceof AnnotationType)) { - throw new SpdxInvalidTypeException("Invalid enum type for "+retval.get().toString()); - } - if (retval.isPresent()) { - if (!(retval.get() instanceof AnnotationType)) { - throw new SpdxInvalidTypeException("Invalid enum type for "+retval.get().toString()); - } - return (AnnotationType)retval.get(); - } else { - logger.warn("Missing required annotation type, returning type missing for "+getId()); - return AnnotationType.MISSING; - } - } - - /** - * @param type - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Annotation setAnnotationType(AnnotationType type) throws InvalidSPDXAnalysisException { - if (strict) { - if (type == null) { - throw new InvalidSPDXAnalysisException("Annotation type is required - null value for type is not accepted"); - } - } - if (AnnotationType.MISSING.equals(type)) { - throw new InvalidSPDXAnalysisException("Can not set value to MISSING for annotation type. This is reserved for when the value is not present in the store."); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_TYPE, type); - return this; - } - - /** - * @return the annotator - * @throws InvalidSPDXAnalysisException - */ - public String getAnnotator() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATOR); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("Missing required annotator for "+getId()); - return ""; - } - } - - /** - * @param annotator - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Annotation setAnnotator(String annotator) throws InvalidSPDXAnalysisException { - if (strict) { - if (annotator == null || annotator.isEmpty()) { - throw new InvalidSPDXAnalysisException("Annotator is required - can not be null or empty"); - } - String verify = SpdxVerificationHelper.verifyAnnotator(annotator); - if (verify != null && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATOR, annotator); - return this; - } - - /** - * @return the comment - */ - public String getComment() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("Missing required comment for "+getId()); - return ""; - } - } - - /** - * Set the comment - * @param comment - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Annotation setComment(String comment) throws InvalidSPDXAnalysisException { - if (strict) { - if (comment == null || comment.isEmpty()) { - throw new InvalidSPDXAnalysisException("Comment is required - can not be null or empty"); - } - } - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - return this; - } - - /** - * @return the date - */ - public String getAnnotationDate() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_DATE); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("Missing required annotation date for "+getId()); - return ""; - } - } - - /** - * Set the annotation date - * @param date - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Annotation setAnnotationDate(String date) throws InvalidSPDXAnalysisException { - if (strict) { - if (date == null || date.isEmpty()) { - throw new InvalidSPDXAnalysisException("Date is required - can not be null or empty"); - } - String dateVerify = SpdxVerificationHelper.verifyDate(date); - if (dateVerify != null && !dateVerify.isEmpty()) { - throw new InvalidSPDXAnalysisException(dateVerify); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_ANNOTATION_DATE, date); - return this; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - public List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList(); - try { - if (AnnotationType.MISSING.equals(getAnnotationType())) { - retval.add("Missing annotationtype for Annotation"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting annotationtype for Annotation: "+e.getMessage()); - } - try { - String annotator = getAnnotator(); - String v = SpdxVerificationHelper.verifyAnnotator(annotator); - if (v != null && !v.isEmpty()) { - retval.add(v + ":" + annotator); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting annotator for Annotation: "+e.getMessage()); - } - try { - if (getComment().isEmpty()) { - retval.add("Missing required comment for Annotation"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting comment for Annotation: "+e.getMessage()); - } - try { - String date = getAnnotationDate(); - if (date.isEmpty()) { - retval.add("Missing required date for Annotation"); - } else { - String dateVerify = SpdxVerificationHelper.verifyDate(date); - if (dateVerify != null && !dateVerify.isEmpty()) { - retval.add(dateVerify); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting date for Annotation: "+e.getMessage()); - } - - return retval; - } - - @Override - public int compareTo(Annotation o) { - try { - if (o == null) { - return 1; - } - if (o.getAnnotationDate() == null) { - if (this.getAnnotationDate() != null) { - return 1; - } - } - if (this.getAnnotationDate() == null) { - return -1; - } - int retval = this.getAnnotationDate().compareTo(o.getAnnotationDate()); - if (retval != 0) { - return retval; - } - if (o.getAnnotator() == null) { - if (this.getAnnotator() != null) { - return 1; - } - } - if (this.getAnnotator() == null) { - return -1; - } - retval = this.getAnnotator().compareToIgnoreCase(o.getAnnotator()); - if (retval != 0) { - return retval; - } - if (o.getAnnotationType() == null) { - if (this.getAnnotationType() != null) { - return 1; - } - } - if (this.getAnnotationType() == null) { - return -1; - } - return this.getAnnotationType().compareTo(o.getAnnotationType()); - } catch(InvalidSPDXAnalysisException ex) { - logger.warn("Error when comparing",ex); - return -1; - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java b/src/main/java/org/spdx/library/model/compat/v2/Checksum.java deleted file mode 100644 index e033bc270..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/Checksum.java +++ /dev/null @@ -1,274 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - -/** - * A Checksum is value that allows the contents of a file to be authenticated. - * Even small changes to the content of the file will change its checksum. - * This class allows the results of a variety of checksum and cryptographic - * message digest algorithms to be represented. - * - * @author Gary O'Neall - */ -public class Checksum extends ModelObject implements Comparable { - - /** - * @throws InvalidSPDXAnalysisException - */ - public Checksum() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public Checksum(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public Checksum(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * Create a checksum with an anonymous ID - * @param modelStore - * @param documentUri - * @param algorithm - * @param value - * @return - * @throws InvalidSPDXAnalysisException - */ - public static Checksum create(IModelStore modelStore, String documentUri, - ChecksumAlgorithm algorithm, String value) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Missing required model store"); - Objects.requireNonNull(documentUri, "Missing required document URI"); - Objects.requireNonNull(algorithm, "Missing required algorithm"); - Objects.requireNonNull(value, "Missing required value"); - Checksum retval = new Checksum(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), null, true); - retval.setAlgorithm(algorithm); - retval.setValue(value); - return retval; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - ChecksumAlgorithm algorithm; - try { - algorithm = getAlgorithm(); - if (ChecksumAlgorithm.MISSING.equals(algorithm)) { - retval.add("Missing required algorithm"); - } else { - try { - String checksumValue = getValue(); - if (checksumValue.isEmpty()) { - retval.add("Missing required checksum value"); - } else { - String verify = SpdxVerificationHelper.verifyChecksumString(checksumValue, - algorithm, specVersion); - if (verify != null) { - retval.add(verify); - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting checksum value",e); - retval.add("Error getting checksum value: "+e.getMessage()); - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting algorithm",e); - retval.add("Error getting checksum algorithm: "+e.getMessage()); - } - return retval; - } - - /** - * @return the ChecksumAlgorithm MISSING denotes that there was no algorithm stored - * @throws InvalidSPDXAnalysisException - */ - public ChecksumAlgorithm getAlgorithm() throws InvalidSPDXAnalysisException { - Optional retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_ALGORITHM); - if (retval.isPresent()) { - if (!(retval.get() instanceof ChecksumAlgorithm)) { - logger.error("Invalid type for checksum algorithm: "+retval.get().getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for checksum algorithm: "+retval.get().getClass().toString()); - } - return (ChecksumAlgorithm)retval.get(); - } else { - return ChecksumAlgorithm.MISSING; - } - } - - - /** - * Set the checksum algorithm. This should only be called by factory classes since they should not be - * modified once created and stored. - * @param algorithm - * @throws InvalidSPDXAnalysisException - */ - protected void setAlgorithm(ChecksumAlgorithm algorithm) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(algorithm)) { - throw new InvalidSPDXAnalysisException("Can not set required checksum algorithm to null"); - } - } - if (ChecksumAlgorithm.MISSING.equals(algorithm)) { - throw new InvalidSPDXAnalysisException("Can not set required checksum algorithm to MISSING. This is only used when no algorithm value was found."); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_ALGORITHM, algorithm); - } - - /** - * @return the checksum algorithm or an empty string if no algorithm value was stored - * @throws InvalidSPDXAnalysisException - */ - public String getValue() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_VALUE); - if (retval.isPresent()) { - return retval.get(); - } else { - return ""; - } - } - - /** - * Set the value - this should only be called by factory methods - * @param value - * @throws InvalidSPDXAnalysisException - */ - protected void setValue(String value) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(value)) { - throw new InvalidSPDXAnalysisException("Can not set required checksum value to null"); - } - ChecksumAlgorithm algorithm = getAlgorithm(); - if (!ChecksumAlgorithm.MISSING.equals(algorithm)) { - String verify = SpdxVerificationHelper.verifyChecksumString(value, algorithm, Version.CURRENT_SPDX_VERSION); - if (verify != null && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_CHECKSUM_VALUE, value); - } - - @Override - public String toString() { - ChecksumAlgorithm algorithm; - try { - algorithm = getAlgorithm(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting algorithm",e); - algorithm = ChecksumAlgorithm.MISSING; - } - String checksumValue; - try { - checksumValue = getValue(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting value",e); - checksumValue = ""; - } - if (ChecksumAlgorithm.MISSING.equals(algorithm) || checksumValue.isEmpty()) { - return "[EMPTY-CHECKSUM]"; - } else { - return (algorithm.toString()+" "+checksumValue); - } - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(Checksum compare) { - ChecksumAlgorithm algorithm; - try { - algorithm = getAlgorithm(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting algorithm",e); - algorithm = ChecksumAlgorithm.MISSING; - } - String checksumValue; - try { - checksumValue = getValue(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting value",e); - checksumValue = ""; - } - ChecksumAlgorithm compareAlgorithm; - try { - compareAlgorithm = compare.getAlgorithm(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare algorithm",e); - compareAlgorithm = ChecksumAlgorithm.MISSING; - } - String compareChecksumValue; - try { - compareChecksumValue = compare.getValue(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare value",e); - compareChecksumValue = ""; - } - int retval = algorithm.toString().compareTo(compareAlgorithm.toString()); - if (retval == 0) { - retval = checksumValue.compareTo(compareChecksumValue); - } - return retval; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java deleted file mode 100644 index 25dd03cc1..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalDocumentRef.java +++ /dev/null @@ -1,372 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * Information about an external SPDX document reference including the checksum. - * This allows for verification of the external references. - * - * @author Gary O'Neall - */ -public class ExternalDocumentRef extends ModelObject implements Comparable { - - /** - * Obtain an ExternalDocumentRef which maps to the document URI for the external SPDX document. - * @param stModelStore Model Store for the document referring to the external SPDX document - * @param stDocumentUri Document URI for the document referring to the external SPDX document - * @param externalDocUri Document URI for the external document (a.k.a. eternalDocumentNamespace) - * @param copyManager if non-null, create the external Doc ref if it is not a property of the SPDX Document - * @return - */ - public static Optional getExternalDocRefByDocNamespace(IModelStore stModelStore, - String stDocumentUri, String externalDocUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(stModelStore, "Model store can not be null"); - Objects.requireNonNull(stDocumentUri, "Document URI can not be null"); - Objects.requireNonNull(externalDocUri, "External document URI can not be null"); - IModelStoreLock lock = stModelStore.enterCriticalSection(false); - try { - ModelCollectionV2 existingExternalRefs = new ModelCollectionV2(stModelStore,stDocumentUri, - SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, copyManager, ExternalDocumentRef.class); - for (Object externalRef:existingExternalRefs) { - if (!(externalRef instanceof ExternalDocumentRef)) { - logger.warn("Incorrect type for an external document ref: "+externalRef.getClass().toString()); - } else { - String externalRefNamespace = ((ExternalDocumentRef)externalRef).getSpdxDocumentNamespace(); - if (externalRefNamespace.isEmpty()) { - logger.warn("Namespace missing for external doc ref "+((ExternalDocumentRef)externalRef).getId()); - } - if (externalDocUri.equals(externalRefNamespace)) { - return Optional.of((ExternalDocumentRef)externalRef); - } - } - } - // if we got here, we didn't find an existing one, need to create one - if (Objects.nonNull(copyManager)) { - ExternalDocumentRef retval = new ExternalDocumentRef(stModelStore, stDocumentUri, - stModelStore.getNextId(IdType.DocumentRef, stDocumentUri + "#"), copyManager, true); - retval.setSpdxDocumentNamespace(externalDocUri); - ModelObject.addValueToCollection(stModelStore, stDocumentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, - SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, retval, copyManager); - return Optional.of(retval); - } else { - return Optional.empty(); - } - } finally { - stModelStore.leaveCriticalSection(lock); - } - } - - /** - * Default model store, copy manager, and document URI - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.DocumentRef, DefaultModelStore.getDefaultDocumentUri())); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef(String id) throws InvalidSPDXAnalysisException { - super(id); - if (!SpdxVerificationHelper.isValidExternalDocRef(id)) { - logger.warn("Invalid external document reference ID "+id+ - ". Must be of the format "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.pattern()); - } - } - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param objectUri URI for the object - must be unique within the SPDX store - * @param copyManager - if supplied, model objects will be implicitly copied into this model store and document URI when referenced by setting methods - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef(IModelStore modelStore, String documentUri, String objectUri, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, objectUri, copyManager, create); - if (!SpdxVerificationHelper.isValidExternalDocRef(objectUri)) { - logger.warn("Invalid external document reference ID "+objectUri+ - ". Must be of the format "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.pattern()); - } - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF; - } - - /** - * Gets the absolute URI representing the document - * @param document - * @return - */ - private String documentToDocumentUri(SpdxDocument document) { - Objects.requireNonNull(document, "Document can not be null"); - String retval = document.getDocumentUri(); - if (retval.endsWith("#")) { - retval = retval.substring(0, retval.length()-1); - } - return retval; - } - - /** - * @return the checksum - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public Optional getChecksum() throws InvalidSPDXAnalysisException { - return (Optional)(Optional)getObjectPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_DOC_CHECKSUM); - } - - /** - * @param checksum the checksum to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef setChecksum(Checksum checksum) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(checksum)) { - throw new InvalidSPDXAnalysisException("Null value for a required checksum"); - } - List verify = checksum.verify(new HashSet(), Version.CURRENT_SPDX_VERSION); - if (verify.size() > 0) { - throw new InvalidSPDXAnalysisException("Invalid checksum: "+verify.get(0)); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_DOC_CHECKSUM, checksum); - return this; - } - - /** - * @return the spdxDocumentNamespace or empty string if no namespace - */ - public String getSpdxDocumentNamespace() throws InvalidSPDXAnalysisException { - Optional docNamespace = getModelStore().getValue( - CompatibleModelStoreWrapper.documentUriIdToUri(getDocumentUri(), getId(), getModelStore().getIdType(getId()) == IdType.Anonymous), - SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); - if (!docNamespace.isPresent()) { - logger.warn("SPDX document namespace not found"); - return ""; - } - if (docNamespace.get() instanceof IndividualUriValue) { - String docUri = ((IndividualUriValue)docNamespace.get()).getIndividualURI(); - if (Objects.isNull(docUri)) { - logger.warn("Missing individual URI in doc namespace"); - return ""; - } - return docUri; - } else if (docNamespace.get() instanceof String) { - logger.warn("Spdx Document Namespace is of type literal string. Reccomended type is IndividualValue"); - return (String)docNamespace.get(); - } else { - logger.error("SPDX document namespace is not of type IndividualValue or String. Type="+docNamespace.get().getClass().toString()); - throw new SpdxInvalidTypeException("SPDX document namespace is not of type IndividualValue or String"); - } - } - - /** - * Set the document namespace - * @param documentNamespace - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef setSpdxDocumentNamespace(String documentNamespace) throws InvalidSPDXAnalysisException { - if (Objects.isNull(documentNamespace)) { - if (strict) { - throw new InvalidSPDXAnalysisException("Null value for a required docment namespace"); - } else { - setPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT, null); - } - } else { - if (strict && !SpdxVerificationHelper.isValidUri(documentNamespace)) { - throw new InvalidSPDXAnalysisException("Invalid document namespace. Must be a valid URI."); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT, - new IndividualUriValue() { - @Override - public String getIndividualURI() { - return documentNamespace; - } - - @Override - public boolean equals(Object comp) { - return SimpleUriValue.isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return SimpleUriValue.getIndividualUriValueHash(this); - } - }); - } - return this; - } - - /** - * Returns the SPDX document if it exists within the same model store, otherwise it returns Optional.empty - * @return the spdxDocument - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public Optional getSpdxDocument() throws InvalidSPDXAnalysisException { - String docNamespace = getSpdxDocumentNamespace(); - if (docNamespace.isEmpty()) { - return Optional.empty(); - } - if (this.getModelStore().exists( - CompatibleModelStoreWrapper.documentUriIdToUri(docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false))) { - return (Optional)(Optional)Optional.of(SpdxModelFactory.createModelObjectV2( - getModelStore(), docNamespace, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, - SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT, getCopyManager())); - } else { - return Optional.empty(); - } - } - - /** - * @param spdxDocument the spdxDocument to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef setSpdxDocument(SpdxDocument spdxDocument) throws InvalidSPDXAnalysisException { - setSpdxDocumentNamespace(documentToDocumentUri(spdxDocument)); - return this; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - if (!getId().startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { - retval.add("Invalid external ref ID: "+getId()+". Must start with "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"."); - } - String spdxDocumentNamespace = "UNKNOWN"; - try { - spdxDocumentNamespace = getSpdxDocumentNamespace(); - if (spdxDocumentNamespace.isEmpty()) { - retval.add("Missing required external document URI"); - } else { - if (!SpdxVerificationHelper.isValidUri(spdxDocumentNamespace)) { - retval.add("Invalid URI for external Spdx Document URI: "+spdxDocumentNamespace); - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("error getting document namespace",e); - retval.add("Error getting document namespace"); - } - - Optional checksum; - try { - checksum = getChecksum(); - if (!checksum.isPresent()) { - retval.add("Missing checksum for external document "+getId()); - } else { - retval.addAll(checksum.get().verify(verifiedIds, Version.CURRENT_SPDX_VERSION)); - if (checksum.get().getAlgorithm() != ChecksumAlgorithm.SHA1) { - retval.add("Checksum algorithm is not SHA1 for external reference "+getId()); - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("error getting checksum",e); - retval.add("Error getting checksum for "+getId()); - } - return retval; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(ExternalDocumentRef o) { - String myDocumentNamespace; - try { - myDocumentNamespace = getSpdxDocumentNamespace(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting document namepsace",e); - myDocumentNamespace = ""; - } - String compareDocumentNamespace; - try { - compareDocumentNamespace = o.getSpdxDocumentNamespace(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare document namepsace",e); - compareDocumentNamespace = ""; - } - int retval = myDocumentNamespace.compareTo(compareDocumentNamespace); - if (retval != 0) { - return retval; - } - Optional myChecksum; - try { - myChecksum = getChecksum(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting checksum",e); - myChecksum = Optional.empty(); - } - Optional comparechecksum; - try { - comparechecksum = o.getChecksum(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare checksum",e); - comparechecksum = Optional.empty(); - } - if (!comparechecksum.isPresent()) { - if (myChecksum.isPresent()) { - return 1; - } - } else if (!myChecksum.isPresent()) { - return -1; - } else { - retval = myChecksum.get().compareTo(comparechecksum.get()); - } - return retval; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java deleted file mode 100644 index 354dcccc9..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalRef.java +++ /dev/null @@ -1,382 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; -import org.spdx.storage.IModelStore; - -/** - * An External Reference allows a Package to reference an external source of - * additional information, metadata, enumerations, asset identifiers, or downloadable content believed to - * be relevant to the Package. - * - * @author Gary O'Neall - */ -public class ExternalRef extends ModelObject implements Comparable { - - /** - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param create - * @param copyManager - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_EXTERNAL_REFERENCE; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - try { - ReferenceCategory referenceCategory = getReferenceCategory(); - if (ReferenceCategory.MISSING.equals(referenceCategory)) { - retval.add("Missing or invalid reference category"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting reference category: "+e.getMessage()); - } - try { - ReferenceType referenceType = getReferenceType(); - if (ReferenceType.MISSING_REFERENCE_TYPE_URI.equals(referenceType.getIndividualURI())) { - retval.add("Missing or invalid reference type"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting reference type: "+e.getMessage()); - } - try { - String referenceLocator = getReferenceLocator(); - if (referenceLocator.isEmpty()) { - retval.add("Missing or invalid reference locator"); - }else if (referenceLocator.contains(" ")) { - retval.add("Reference locator contains spaces"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting reference locator: "+e.getMessage()); - } - return retval; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(ExternalRef o) { - String myReferenceType; - int retval = 0; - try { - myReferenceType = this.getReferenceType().getIndividualURI(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid reference type during compare",e); - myReferenceType = ReferenceType.MISSING_REFERENCE_TYPE_URI; - } - String compRefType; - try { - compRefType = o.getReferenceType().getIndividualURI(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid reference type during compare",e); - compRefType = ReferenceType.MISSING_REFERENCE_TYPE_URI; - } - retval = myReferenceType.compareTo(compRefType); - if (retval == 0) { - String myReferenceLocator = ""; - String compareReferenceLocator = ""; - try { - myReferenceLocator = this.getReferenceLocator(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid reference locator during compare",e); - } - try { - compareReferenceLocator = o.getReferenceLocator(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid compare reference locator during compare",e); - } - retval = myReferenceLocator.compareTo(compareReferenceLocator); - } - if (retval == 0) { - ReferenceCategory referenceCategory = ReferenceCategory.MISSING; - ReferenceCategory compareReferenceCategory = ReferenceCategory.MISSING; - try { - referenceCategory = getReferenceCategory(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid reference category during compare",e); - } - try { - compareReferenceCategory = o.getReferenceCategory(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid compare reference category during compare",e); - } - retval = referenceCategory.toString().compareTo(compareReferenceCategory.toString()); - } - if (retval == 0) { - Optional myComment = Optional.empty(); - Optional compareComment = Optional.empty(); - try { - myComment = getComment(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid comment during compare",e); - } - try { - compareComment = o.getComment(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Invalid compare comment during compare",e); - } - if (!myComment.isPresent()) { - if (compareComment.isPresent()) { - retval = 1; - } - } else if (!compareComment.isPresent()) { - retval = -1; - } else { - retval = myComment.get().compareTo(compareComment.get()); - } - } - return retval; - } - - /** - * @return the comment - * @throws InvalidSPDXAnalysisException - */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - } - - /** - * @param comment comment to set - * @return this to build additional setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - return this; - } - - /** - * @return the referenceCategory - */ - public ReferenceCategory getReferenceCategory() throws InvalidSPDXAnalysisException { - Optional retval = this.getEnumPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_CATEGORY); - if (retval.isPresent()) { - if (!(retval.get() instanceof ReferenceCategory)) { - throw new InvalidSPDXAnalysisException("Invalid type for reference category: "+retval.get().getClass().toString()); - } - return (ReferenceCategory)retval.get(); - } else { - return ReferenceCategory.MISSING; - } - } - - /** - * Set the reference category - * @param referenceCategory - * @return this to build additional setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef setReferenceCategory(ReferenceCategory referenceCategory) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(referenceCategory)) { - throw new InvalidSPDXAnalysisException("Can not set required referenceCategory to null"); - } - } - if (ReferenceCategory.MISSING.equals(referenceCategory)) { - throw new InvalidSPDXAnalysisException("Can not set required referenceCategory to MISSING"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_CATEGORY, referenceCategory); - return this; - } - - /** - * @return the referenceType. If the refrenceType is not in the modelStore, the constant ReferenceType.MISSING is returned - * @throws InvalidSPDXAnalysisException - */ - public ReferenceType getReferenceType() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE); - if (!retval.isPresent()) { - return ReferenceType.getMissingReferenceType(); - } - if (retval.get() instanceof ReferenceType) { - return (ReferenceType)retval.get(); - } else if (retval.get() instanceof SimpleUriValue) { - return new ReferenceType((SimpleUriValue)retval.get()); - } else { - throw new InvalidSPDXAnalysisException("Invalid type returned for reference type: "+retval.get().getClass().toString()); - } - } - - /** - * Set the reference type - * @param referenceType - * @return this to build additional setters - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef setReferenceType(ReferenceType referenceType) throws InvalidSPDXAnalysisException { - if (Objects.isNull(referenceType)) { - if (strict) { - throw new InvalidSPDXAnalysisException("Can not set required referenceType to null"); - } else { - setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE, null); - } - } else { - if (ReferenceType.MISSING_REFERENCE_TYPE_URI.equals(referenceType.getIndividualURI())) { - throw new InvalidSPDXAnalysisException("Can not set referenceType to MISSING"); - } - if (strict && !SpdxVerificationHelper.isValidUri(referenceType.getIndividualURI())) { - throw new InvalidSPDXAnalysisException("Invalid URI for referenceType"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_TYPE, referenceType); - } - return this; - } - - /** - * @return the referenceLocator. If not found, a blank string is returned - */ - public String getReferenceLocator() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_LOCATOR); - if (retval.isPresent()) { - return retval.get(); - } else { - return ""; - } - } - - /** - * Set the reference locator - * @param referenceLocator - * @return this to build additional setter - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef setReferenceLocator(String referenceLocator) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(referenceLocator)) { - throw new InvalidSPDXAnalysisException("Can not set required reference locator to null"); - } - if (referenceLocator.isEmpty()) { - throw new InvalidSPDXAnalysisException("Can not set required reference locator to an empty string"); - } - if (referenceLocator.contains(" ")) { - throw new InvalidSPDXAnalysisException("Reference locator contains spaces"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_REFERENCE_LOCATOR, referenceLocator); - return this; - } - - @Override public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (!(compare instanceof ExternalRef)) { - return false; - } - ExternalRef compareEf = (ExternalRef)compare; - return Objects.equals(this.getReferenceLocator(), compareEf.getReferenceLocator()) && - Objects.equals(getComment(), compareEf.getComment()) && - Objects.equals(getReferenceCategory(), compareEf.getReferenceCategory()); - // we ignore the reference type since it may be local to the document and a different URI - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - try { - ReferenceCategory referenceCategory = getReferenceCategory(); - if (ReferenceCategory.MISSING.equals(referenceCategory)) { - sb.append("[NONE] "); - } else { - sb.append(referenceCategory.toString()); - sb.append(' '); - } - } catch (InvalidSPDXAnalysisException e) { - sb.append("[ERROR] "); - } - try { - ReferenceType referenceType = getReferenceType(); - if (!ReferenceType.MISSING_REFERENCE_TYPE_URI.equals(referenceType.getIndividualURI())) { - sb.append(referenceType.getIndividualURI()); - sb.append(' '); - } else { - sb.append("[NONE] "); - } - } catch (InvalidSPDXAnalysisException e) { - sb.append("[ERROR] "); - } - try { - String referenceLocator = getReferenceLocator(); - if (!referenceLocator.isEmpty()) { - sb.append(referenceLocator); - sb.append(' '); - } else { - sb.append("[NONE]"); - } - } catch (InvalidSPDXAnalysisException e) { - sb.append("[ERROR] "); - } - try { - Optional comment = getComment(); - if (comment.isPresent()) { - sb.append('('); - sb.append(comment.get()); - sb.append(')'); - } - } catch (InvalidSPDXAnalysisException e) { - sb.append("([ERROR])"); - } - return sb.toString(); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java deleted file mode 100644 index 66d46c81e..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ExternalSpdxElement.java +++ /dev/null @@ -1,349 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Matcher; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - - -/** - * This is an SPDX element which is in an external document. The ID must be in the form SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern() - * - * @author Gary O'Neall - */ -public class ExternalSpdxElement extends SpdxElement implements IndividualUriValue { - - // Note: the default empty constructor is not allowed since the element ID must follow a specific pattern - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public ExternalSpdxElement(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param create - * @throws InvalidSPDXAnalysisException - */ - public ExternalSpdxElement(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - if (!SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id).matches()) { - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); - } - getExternalSpdxElementURI(); //this will check to make sure the external document reference is available - } - - /** - * @return external document ID for the external reference - * @throws InvalidSPDXAnalysisException - */ - public String getExternalDocumentId() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); - if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); - } - return matcher.group(1); - } - - /** - * @return element ID used in the external document - * @throws InvalidSPDXAnalysisException - */ - public String getExternalElementId() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(this.getId()); - if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); - } - return matcher.group(2); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_EXTERNAL_SPDX_ELEMENT; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - // we don't want to call super.verify since we really don't require those fields - List retval = new ArrayList<>(); - String id = this.getId(); - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(id); - if (!matcher.matches()) { - retval.add("Invalid objectUri format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); - } else { - try { - externalDocumentIdToNamespace(matcher.group(1), getModelStore(), getDocumentUri(), getCopyManager()); - } catch (InvalidSPDXAnalysisException e) { - retval.add(e.getMessage()); - } - } - return retval; - } - - /** - * @return the External URI associated with this external SPDX element - * @throws InvalidSPDXAnalysisException - */ - public String getExternalSpdxElementURI() throws InvalidSPDXAnalysisException { - return externalSpdxElementIdToURI(getId(), getModelStore(), getDocumentUri(), getCopyManager()); - } - - /** - * @param externalSpdxElementId - * @param stModelStore - * @param stDocumentUri - * @param copyManager - * @return The URI associated with the external SPDX element with the ID externalSpdxElementId - * @throws InvalidSPDXAnalysisException - */ - public static String externalSpdxElementIdToURI(String externalSpdxElementId, - IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.matcher(externalSpdxElementId); - if (!matcher.matches()) { - logger.error("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:SPDXID"); - } - String externalDocumentUri; - externalDocumentUri = externalDocumentIdToNamespace(matcher.group(1), stModelStore, stDocumentUri, copyManager); - if (externalDocumentUri.endsWith("#")) { - return externalDocumentUri + matcher.group(2); - } else { - return externalDocumentUri + "#" + matcher.group(2); - } - } - - /** - * Convert a URI to an ID for an External SPDX Element - * @param uri URI with the external document namespace and the external SPDX ref in the form namespace#SPDXRef-[NUM] - * @param stModelStore - * @param stDocumentUri - * @param copyManager if true, create the external doc ref if it is not already in the ModelStore - * @return external SPDX element ID in the form DocumentRef-XX:SPDXRef-YY - * @throws InvalidSPDXAnalysisException - */ - public static String uriToExternalSpdxElementId(String uri, - IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(uri, "URI can not be null"); - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_SPDX_ELEMENT_URI_PATTERN.matcher(uri); - if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid URI format: "+uri+". Expects namespace#SPDXRef-XXX"); - } - Optional externalDocRef = ExternalDocumentRef.getExternalDocRefByDocNamespace(stModelStore, stDocumentUri, - matcher.group(1), copyManager); - if (!externalDocRef.isPresent()) { - logger.error("Could not find or create the external document reference for document namespace "+ matcher.group(1)); - throw new InvalidSPDXAnalysisException("Could not find or create the external document reference for document namespace "+ matcher.group(1)); - } - return externalDocRef.get().getId() + ":" + matcher.group(2); - } - - /** - * Create an ExternalSpdxElement based on a URI of the form externaldocumentnamespace#SPDXRef-[NUM] - * @param uri RI of the form externaldocumentnamespace#SPDXRef-[NUM] - * @param stModelStore - * @param stDocumentUri - * @return ExternalSpdxRef - * @param copyManager if non-null, create the external doc ref if it is not already in the ModelStore - * @throws InvalidSPDXAnalysisException - */ - public static ExternalSpdxElement uriToExternalSpdxElement(String uri, - IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - return new ExternalSpdxElement(stModelStore, stDocumentUri, uriToExternalSpdxElementId( - uri, stModelStore, stDocumentUri, copyManager), copyManager, true); - } - - public static String externalDocumentIdToNamespace(String externalDocumentId, - IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Optional retval = stModelStore.getValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, externalDocumentId, false), - SpdxConstantsCompatV2.PROP_EXTERNAL_SPDX_DOCUMENT); - if (!retval.isPresent()) { - throw new InvalidSPDXAnalysisException("No external document reference exists for document ID "+externalDocumentId); - } - if (!(retval.get() instanceof IndividualUriValue)) { - logger.error("Invalid type returned for external document. Expected IndividualValue, actual "+retval.get().getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type returned for external document."); - } - return ((IndividualUriValue)retval.get()).getIndividualURI(); - } - - @Override - public boolean equivalent(ModelObject compare) { - if (!(compare instanceof ExternalSpdxElement)) { - return false; - } - return getId().equals(compare.getId()); - } - - @Override - public String getIndividualURI() { - try { - return getExternalSpdxElementURI(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting external SPDX element URI",e); - throw new RuntimeException(e); - } - } - - @Override - public boolean addAnnotation(Annotation annotation) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not add annotations to an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - @Override - public boolean addRelationship(Relationship relationship) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not add relationshps to an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - @Override - public void setComment(String comment) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set comment on an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - @Override - public ExternalSpdxElement setName(String name) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set the name on an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - /** - * @return Annotations - * @throws InvalidSPDXAnalysisException - */ - @Override - public Collection getAnnotations() throws InvalidSPDXAnalysisException { - return new ArrayList(); - } - - /** - * Clears and resets the annotations collection to the parameter - * @param annotations - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - @Override - public SpdxElement setAnnotations(Collection annotations) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set annotations to an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - - /** - * Remove an annotation - * @param annotation - * @return - * @throws InvalidSPDXAnalysisException - */ - @Override - public boolean removeAnnotation(Annotation annotation) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can remove set annotations to an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - /** - * @return Relationships - * @throws InvalidSPDXAnalysisException - */ - @Override - public Collection getRelationships() throws InvalidSPDXAnalysisException { - return new ArrayList(); - } - - /** - * clear and reset the relationships to the paramater relationship - * @param relationships - * @return this to chain sets - * @throws InvalidSPDXAnalysisException - */ - @Override - public SpdxElement setRelationships(Collection relationships) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set relationships on an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - /** - * Remove a relationship - * @param relationship - * @return - * @throws InvalidSPDXAnalysisException - */ - @Override - public boolean removeRelationship(Relationship relationship) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not remove relationships on an ExternalSpdxElement. " - + "These changes must be done to the local SPDX element in the document which defines the SPDX element."); - } - - /** - * @return the comment - * @throws InvalidSPDXAnalysisException - */ - @Override - public Optional getComment() throws InvalidSPDXAnalysisException { - return Optional.empty(); - } - - /** - * @return the name - */ - @Override - public Optional getName() throws InvalidSPDXAnalysisException { - return Optional.empty(); - } - - @Override - public boolean equals(Object comp) { - return SimpleUriValue.isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return SimpleUriValue.getIndividualUriValueHash(this); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java deleted file mode 100644 index 17225e013..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericModelObject.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; - -/** - * Primarily used for testing, this model object does not implement any unique getters and setters nor - * does it implement any verification. - * - * @author Gary O'Neall - * - */ -public class GenericModelObject extends ModelObject { - - public static final String GENERIC_MODEL_OBJECT_TYPE = "GenericModelObject"; - - /** - * @throws InvalidSPDXAnalysisException - */ - public GenericModelObject() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param id - * @throws InvalidSPDXAnalysisException - */ - public GenericModelObject(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param id - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public GenericModelObject(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return GENERIC_MODEL_OBJECT_TYPE; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - return new ArrayList<>(); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java deleted file mode 100644 index 77146c696..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxElement.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; - -/** - * Generic SPDX element - primarily used for testing - * - * @author Gary O'Neall - * - */ -public class GenericSpdxElement extends SpdxElement { - - public static final String GENERIC_SPDX_ELEMENT_TYPE = "GenericSpdxElement"; - - /** - * @throws InvalidSPDXAnalysisException - */ - public GenericSpdxElement() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public GenericSpdxElement(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public GenericSpdxElement(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return GENERIC_SPDX_ELEMENT_TYPE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java b/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java deleted file mode 100644 index b2af9825b..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/GenericSpdxItem.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; - -/** - * Generic SPDX item - primarily used for testing - * @author Gary O'Neall - * - */ -public class GenericSpdxItem extends SpdxItem { - - public static final String GENERIC_SPDX_ITEM_TYPE = "GenericSpdxItem"; - /** - * @throws InvalidSPDXAnalysisException - */ - public GenericSpdxItem() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public GenericSpdxItem(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public GenericSpdxItem(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return GENERIC_SPDX_ITEM_TYPE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java b/src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java deleted file mode 100644 index e5f117bbc..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelCollectionV2.java +++ /dev/null @@ -1,316 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import javax.annotation.Nullable; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxObjectNotInStoreException; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * Collection of elements stored in an SPDX version 2 ModelStore - * - * @author Gary O'Neall - * - */ -public class ModelCollectionV2 implements Collection { - - private IModelStore modelStore; - private String documentUri; - private String id; - private PropertyDescriptor propertyDescriptor; - private ModelCopyManager copyManager; - private Class type; - private boolean licensePrimitiveAssignable; // If true, NONE and NOASSERTION should be converted to NoneLicense and NoAssertionLicense - - class ModelCollectionIterator implements Iterator { - - private Iterator storageIterator; - - public ModelCollectionIterator(Iterator storageIterator) { - this.storageIterator = storageIterator; - } - - @Override - public boolean hasNext() { - return storageIterator.hasNext(); - } - - @Override - public Object next() { - return checkConvertTypedValue(storageIterator.next()); - } - - } - - /** - * @param modelStore Storage for the model collection - * @param documentUri SPDX Document URI for a document associated with this model collection - * @param id ID for this collection - must be unique within the SPDX document - * @param propertyDescriptor descriptor for the property use for the model collections - * @param copyManager if non-null, use this to copy properties when referenced outside this model store - * @param type The class of the elements to be stored in the collection if none, null if not known - * @throws InvalidSPDXAnalysisException - */ - public ModelCollectionV2(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, - @Nullable ModelCopyManager copyManager, - @Nullable Class type) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - this.modelStore = modelStore; - Objects.requireNonNull(documentUri, "Document URI can not be null"); - this.documentUri = documentUri; - Objects.requireNonNull(id, "ID can not be null"); - this.id = id; - Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); - this.propertyDescriptor = propertyDescriptor; - this.copyManager = copyManager; - if (!modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore))) { - throw new SpdxIdNotFoundException(id+" does not exist in document "+documentUri); - } - if (Objects.nonNull(type)) { - this.type = type; - licensePrimitiveAssignable = type.isAssignableFrom(SpdxNoneLicense.class); - if (!modelStore.isCollectionMembersAssignableTo(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), - propertyDescriptor, type)) { - throw new SpdxInvalidTypeException("Incompatible type for property "+propertyDescriptor+": "+type.toString()); - } - } else { - licensePrimitiveAssignable = false; - } - } - - @Override - public int size() { - try { - return this.modelStore.collectionSize( - CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), - this.propertyDescriptor); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean isEmpty() { - try { - return this.modelStore.collectionSize( - CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), - this.propertyDescriptor) == 0; - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean contains(Object o) { - try { - Object storedObject = null; - try { - storedObject = ModelStorageClassConverter.modelObjectToStoredObject(o, documentUri, modelStore, copyManager); - } catch (SpdxObjectNotInStoreException e1) { - return false; // The exception is due to the model object not being in the store - } - return this.modelStore.collectionContains( - CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), - this.propertyDescriptor, storedObject); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - private Object checkConvertTypedValue(Object value) { - try { - Object retval = ModelStorageClassConverter.storedObjectToModelObject(value, documentUri, modelStore, copyManager); - if (licensePrimitiveAssignable && retval instanceof IndividualUriValue) { - String uri = ((IndividualUriValue)retval).getIndividualURI(); - if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - retval = new SpdxNoAssertionLicense(); - } else if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { - retval = new SpdxNoneLicense(); - } - } - if (Objects.nonNull(this.type) && !this.type.isAssignableFrom(retval.getClass())) { - if (retval instanceof IndividualUriValue) { - throw new SpdxInvalidTypeException("No enumeration was found for URI "+((IndividualUriValue)retval).getIndividualURI()+ - " for type "+type.toString()); - } else { - throw new SpdxInvalidTypeException("A collection element of type "+retval.getClass().toString()+ - " was found in a collection of type "+type.toString()); - } - } - return retval; - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - /** - * Converts any typed or individual value objects to a ModelObject - */ - private Function checkConvertTypedValue = value -> { - return checkConvertTypedValue(value); - }; - - public List toImmutableList() { - return (List) Collections.unmodifiableList(StreamSupport.stream( - Spliterators.spliteratorUnknownSize(this.iterator(), Spliterator.ORDERED), false).map(checkConvertTypedValue) - .collect(Collectors.toList())); - } - - @Override - public Iterator iterator() { - try { - return new ModelCollectionIterator( - modelStore.listValues(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), - propertyDescriptor)); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public Object[] toArray() { - return toImmutableList().toArray(); - } - - @Override - public AT[] toArray(AT[] a) { - return toImmutableList().toArray(a); - } - - @Override - public boolean add(Object element) { - try { - return modelStore.addValueToCollection( - CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), propertyDescriptor, - ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, copyManager)); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean remove(Object element) { - try { - return modelStore.removeValueFromCollection(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), - propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject(element, documentUri, modelStore, null)); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean containsAll(Collection c) { - return toImmutableList().containsAll(c); - } - - @Override - public boolean addAll(Collection c) { - boolean retval = false; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - if (add(iter.next())) { - retval = true; - } - } - return retval; - } - - @Override - public boolean removeAll(Collection c) { - boolean retval = false; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - if (remove(iter.next())) { - retval = true; - } - } - return retval; - } - - @Override - public boolean retainAll(Collection c) { - List values = toImmutableList(); - boolean retval = false; - for (Object value:values) { - if (!c.contains(value)) { - if (remove(value)) { - retval = true; - } - } - } - return retval; - } - - @Override - public void clear() { - try { - modelStore.clearValueCollection(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), propertyDescriptor); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - /** - * @return the modelStore - */ - public IModelStore getModelStore() { - return modelStore; - } - - /** - * @return the documentUri - */ - public String getDocumentUri() { - return documentUri; - } - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @return the propertyDescriptor - */ - public PropertyDescriptor getPropertyDescriptor() { - return propertyDescriptor; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java b/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java deleted file mode 100644 index 74c2f6d2c..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelObject.java +++ /dev/null @@ -1,1432 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.NotEquivalentReason; -import org.spdx.library.NotEquivalentReason.NotEquivalent; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.TypedValue; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; -import org.spdx.library.model.compat.v2.license.ListedLicenses; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.library.model.compat.v2.license.CrossRef.CrossRefBuilder; -import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; -import org.spdx.library.model.compat.v2.pointer.LineCharPointer; -import org.spdx.library.model.compat.v2.pointer.SinglePointer; -import org.spdx.library.model.compat.v2.pointer.StartEndPointer; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.IModelStore.ModelUpdate; -import org.spdx.storage.PropertyDescriptor; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * @author Gary O'Neall - * - * Superclass for all SPDX spec version 2 model objects - * - * Provides the primary interface to the storage class that access and stores the data for - * the model objects. - * - * This class includes several helper methods to manage the storage and retrieval of properties. - * - * Each model object is in itself stateless. All state is maintained in the Model Store. - * The Document URI uniquely identifies the document containing the model object. - * - * The concrete classes are expected to implements getters for the model class properties which translate - * into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property descriptor - * is passed as a parameter. - * - * There are 2 methods of setting values: - * - call the setPropertyValue, clearValueCollection or addValueToCollection methods - this will call the modelStore and store the - * value immediately - * - Gather a list of updates by calling the updatePropertyValue, updateClearValueList, or updateAddPropertyValue - * methods. These methods return a ModelUpdate which can be applied later by calling the apply() method. - * A convenience method Write.applyUpdatesInOneTransaction will perform all updates within - * a single transaction. This method may result in higher performance updates for some Model Store implementations. - * Note that none of the updates will be applied until the storage manager update method is invoked. - * - * Property values are restricted to the following types: - * - String - Java Strings - * - Booolean - Java Boolean or primitive boolean types - * - ModelObject - A concrete subclass of this type - * - {@literal Collection} - A Collection of type T where T is one of the supported non-collection types - * - * This class also handles the conversion of a ModelObject to and from a TypeValue for storage in the ModelStore. - * - */ -public abstract class ModelObject { - - static final Logger logger = LoggerFactory.getLogger(ModelObject.class); - - private IModelStore modelStore; - private String documentUri; - private String id; - - /** - * If non null, a reference made to a model object stored in a different modelStore and/or - * document will be copied to this modelStore and documentUri - */ - private ModelCopyManager copyManager = null; - - /** - * if true, checks input values for setters to verify valid SPDX inputs - */ - protected boolean strict = true; - - NotEquivalentReason lastNotEquivalentReason = null; - - - /** - * Create a new Model Object using an Anonymous ID with the defualt store and default document URI - * @throws InvalidSPDXAnalysisException - */ - public ModelObject() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); - } - - /** - * Open or create a model object with the default store and default document URI - * @param id ID for this object - must be unique within the SPDX document - * @throws InvalidSPDXAnalysisException - */ - public ModelObject(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param identifier ID for this object - must be unique within the SPDX document - * @param copyManager - if supplied, model objects will be implictly copied into this model store and document URI when referenced by setting methods - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - public ModelObject(IModelStore modelStore, String documentUri, String identifier, @Nullable ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(modelStore, "Model Store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(identifier, "ID can not be null"); - if (!SpdxMajorVersion.VERSION_2.equals(modelStore.getSpdxVersion())) { - logger.error("Trying to create an SPDX version 2 model object in an SPDX version 3 model store"); - throw new InvalidSPDXAnalysisException("Trying to create an SPDX version 2 model object in an SPDX version 3 model store"); - } - if (identifier.startsWith(documentUri)) { - logger.warn("document URI was passed in as an ID: "+identifier); - this.id = identifier.substring(documentUri.length()); - if (this.id.startsWith("#")) { - this.id = this.id.substring(1); - } - } else { - this.id = identifier; - } - if ((LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) && - !SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri)) { - logger.warn("Listed license document URI changed to listed license URL for documentUri "+documentUri); - this.documentUri = SpdxConstantsCompatV2.LISTED_LICENSE_URL; - } else { - this.documentUri = documentUri; - } - this.modelStore = modelStore; - this.copyManager = copyManager; - Optional existing = modelStore.getTypedValue(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore)); - if (existing.isPresent()) { - if (create && !existing.get().getType().equals(getType())) { - throw new SpdxIdInUseException("Can not create "+id+". It is already in use with type "+existing.get().getType()+" which is incompatible with type "+getType()); - } - } else { - if (create) { - IModelStoreLock lock = enterCriticalSection(false); - // re-check since previous check was done outside of the lock - try { - if (!modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore))) { - modelStore.create(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore), getType()); - } - } finally { - lock.unlock(); - } - } else { - throw new SpdxIdNotFoundException(id+" does not exist in document "+documentUri); - } - } - } - - // Abstract methods that must be implemented in the subclasses - /** - * @return The class name for this object. Class names are defined in the constants file - */ - public abstract String getType(); - - /** - * Implementation of the specific verifications for this model object - * @param specVersion Version of the SPDX spec to verify against - * @param verifiedElementIds list of all Element Id's which have already been verified - prevents infinite recursion - * @return Any verification errors or warnings associated with this object - */ - protected abstract List _verify(Set verifiedElementIds, String specVersion); - - /** - * @param specVersion Version of the SPDX spec to verify against - * @param verifiedIElementds list of all element Id's which have already been verified - prevents infinite recursion - * @return Any verification errors or warnings associated with this object - */ - public List verify(Set verifiedIElementds, String specVersion) { - if (verifiedIElementds.contains(this.id)) { - return new ArrayList<>(); - } else { - // The verifiedElementId is added in the SpdxElement._verify method - return _verify(verifiedIElementds, specVersion); - } - } - - /** - * Verifies against the more recent supported specification version - * @return Any verification errors or warnings associated with this object - */ - public List verify() { - return verify(Version.CURRENT_SPDX_VERSION); - } - - /** - * @param specVersion Version of the SPDX spec to verify against - * @return Any verification errors or warnings associated with this object - */ - public List verify(String specVersion) { - return verify(new HashSet(), specVersion); - } - - /** - * @return the Document URI for this object - */ - public String getDocumentUri() { - return this.documentUri; - } - - /** - * @return ID for the object - */ - public String getId() { - return id; - } - - /** - * @return the Object URI or anonymous ID - */ - public String getObjectUri() { - return modelStore.getIdType(id) == IdType.Anonymous ? id : - SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri) ? documentUri + id : - documentUri + "#" + id; - } - - /** - * @return the model store for this object - */ - public IModelStore getModelStore() { - return this.modelStore; - } - - /** - * @return if strict input checking is enabled - */ - public boolean isStrict() { - return strict; - } - - /** - * @param strict if true, inputs will be validated against the SPDX spec - */ - public void setStrict(boolean strict) { - this.strict = strict; - } - - /** - * Enter a critical section. leaveCriticialSection must be called. - * @param readLockRequested true implies a read lock, false implies write lock. - * @throws InvalidSPDXAnalysisException - */ - public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { - return modelStore.enterCriticalSection(readLockRequested); - } - - /** - * Leave a critical section. Releases the lock form the matching enterCriticalSection - */ - public void leaveCriticalSection(IModelStoreLock lock) { - this.getModelStore().leaveCriticalSection(lock); - } - - - //The following methods are to manage the properties associated with the model object - /** - * @return all names of property descriptors currently associated with this object - * @throws InvalidSPDXAnalysisException - */ - public List getPropertyValueDescriptors() throws InvalidSPDXAnalysisException { - return modelStore.getPropertyValueDescriptors(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, id, modelStore)); - } - - /** - * Get an object value for a property - * @param propertyDescriptor Descriptor for the property - * @return value associated with a property - */ - protected Optional getObjectPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(modelStore, documentUri, id, propertyDescriptor, copyManager); - if (retval.isPresent() && retval.get() instanceof ModelObject && !strict) { - ((ModelObject)retval.get()).setStrict(strict); - } - return retval; - } - - /** - * Get an object value for a property - * @param stModelStore - * @param stDocumentUri - * @param stId - * @param propertyDescriptor - * @param copyManager if non null, any ModelObject property value not stored in the stModelStore under the stDocumentUri will be copied to make it available - * @return value associated with a property - * @throws InvalidSPDXAnalysisException - */ - protected static Optional getObjectPropertyValue(IModelStore stModelStore, String stDocumentUri, - String stId, PropertyDescriptor propertyDescriptor, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - IModelStoreLock lock = stModelStore.enterCriticalSection(false); - // NOTE: we use a write lock since the ModelStorageClassConverter may end up creating objects in the store - try { - if (!stModelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore))) { - return Optional.empty(); - } else if (stModelStore.isCollectionProperty(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor)) { - return Optional.of(new ModelCollectionV2<>(stModelStore, stDocumentUri, stId, propertyDescriptor, copyManager, null)); - } else { - return ModelStorageClassConverter.optionalStoredObjectToModelObject(stModelStore.getValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), - propertyDescriptor), - stDocumentUri, stModelStore, copyManager); - } - } finally { - lock.unlock(); - } - } - - /** - * Set a property value for a property descriptor, creating the property if necessary - * @param stModelStore Model store for the properties - * @param stDocumentUri Unique document URI - * @param stId ID of the item to associate the property with - * @param propertyDescriptor Descriptor for the property associated with this object - * @param value Value to associate with the property - * @param copyManager if non null, any ModelObject property value not stored in the stModelStore under the stDocumentUri will be copied to make it available - * @throws InvalidSPDXAnalysisException - */ - protected static void setPropertyValue(IModelStore stModelStore, String stDocumentUri, - String stId, PropertyDescriptor propertyDescriptor, @Nullable Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(stModelStore, "Model Store can not be null"); - Objects.requireNonNull(stDocumentUri, "Document Uri can not be null"); - Objects.requireNonNull(stId, "ID can not be null"); - Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); - if (value == null) { - // we just remove the value - removeProperty(stModelStore, stDocumentUri, stId, propertyDescriptor); - } else if (value instanceof Collection) { - replacePropertyValueCollection(stModelStore, stDocumentUri, stId, propertyDescriptor, (Collection)value, copyManager); - } else { - stModelStore.setValue(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor, ModelStorageClassConverter.modelObjectToStoredObject( - value, stDocumentUri, stModelStore, copyManager)); - } - } - - /** - * Set a property value for a property descriptor, creating the property if necessary - * @param propertyDescriptor Descriptor for the property associated with this object - * @param value Value to associate with the property - * @throws InvalidSPDXAnalysisException - */ - protected void setPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Object value) throws InvalidSPDXAnalysisException { - if (this instanceof IndividualUriValue) { - throw new InvalidSPDXAnalysisException("Can not set a property for the literal value "+((IndividualUriValue)this).getIndividualURI()); - } - setPropertyValue(this.modelStore, this.documentUri, this.id, propertyDescriptor, value, copyManager); - } - - /** - * Create an update when, when applied by the ModelStore, sets a property value for a property descriptor, creating the property if necessary - * @param propertyDescriptor Descriptor for the property associated with this object - * @param value Value to associate with the property - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updatePropertyValue(PropertyDescriptor propertyDescriptor, Object value) { - return () ->{ - setPropertyValue(this.modelStore, this.documentUri, this.id, propertyDescriptor, value, copyManager); - }; - } - - /** - * @param propertyDescriptor Descriptor for a property - * @return the Optional String value associated with a property, null if no value is present - * @throws SpdxInvalidTypeException - */ - protected Optional getStringPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (result.isPresent()) { - if (result.get() instanceof String) { - return Optional.of((String)result.get()); - } else if (result.get() instanceof IndividualUriValue) { - String uri = ((IndividualUriValue)result.get()).getIndividualURI(); - if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { - return Optional.of(SpdxConstantsCompatV2.NONE_VALUE); - } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - return Optional.of(SpdxConstantsCompatV2.NOASSERTION_VALUE); - } else { - logger.error("Can not convert a URI value to String: "+uri); - throw new SpdxInvalidTypeException("Can not convert a URI value to String: "+uri); - } - } else { - logger.error("Property "+propertyDescriptor+" is not of type String"); - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type String"); - } - } else { - return Optional.empty(); - } - } - - /** - * @param propertyDescriptor Descriptor for a property - * @return the Optional Integer value associated with a property, null if no value is present - * @throws InvalidSPDXAnalysisException - */ - protected Optional getIntegerPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - Optional retval; - if (result.isPresent()) { - if (!(result.get() instanceof Integer)) { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Integer"); - } - retval = Optional.of((Integer)result.get()); - } else { - retval = Optional.empty(); - } - return retval; - } - - /** - * @param propertyDescriptor descriptor for the property - * @return an enumeration value for the property - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - protected Optional> getEnumPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (!result.isPresent()) { - return Optional.empty(); - } - if (result.get() instanceof Enum) { - return (Optional>)(Optional)result; - } - if (!(result.get() instanceof IndividualUriValue)) { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Individual Value or enum"); - } - Enum retval = SpdxEnumFactoryCompatV2.uriToEnum.get(((IndividualUriValue)result.get()).getIndividualURI()); - if (Objects.isNull(retval)) { - logger.error("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); - throw new InvalidSPDXAnalysisException("Unknown individual value for enum: "+((IndividualUriValue)result.get()).getIndividualURI()); - } else { - return Optional.of(retval); - } - } - - /** - * @param propertyDescriptor Descriptor for the property - * @return the Optional Boolean value for a property - * @throws SpdxInvalidTypeException - */ - protected Optional getBooleanPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (result.isPresent()) { - if (result.get() instanceof Boolean) { - return Optional.of((Boolean)result.get()); - } else if (result.get() instanceof String) { - // try to convert - String sResult = ((String)result.get()).toLowerCase(); - if ("true".equals(sResult)) { - return Optional.of(Boolean.valueOf(true)); - } else if ("false".equals(sResult)) { - return Optional.of(Boolean.valueOf(false)); - } else { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); - } - } else { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" is not of type Boolean"); - } - } else { - return Optional.empty(); - } - } - - /** - * Converts property values to an AnyLicenseInfo if possible - if NONE or NOASSERTION URI value, convert to the appropriate license - * @param propertyDescriptor descriptor for the property - * @return AnyLicenseInfo license info for the property - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - protected Optional getAnyLicenseInfoPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (!result.isPresent()) { - return Optional.empty(); - } else if (result.get() instanceof AnyLicenseInfo) { - return (Optional)(Optional)result; - } else if (result.get() instanceof IndividualUriValue) { - String uri = ((IndividualUriValue)result.get()).getIndividualURI(); - if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { - return Optional.of(new SpdxNoneLicense()); - } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - return Optional.of(new SpdxNoAssertionLicense()); - } else { - logger.error("Can not convert a URI value to a license: "+uri); - throw new SpdxInvalidTypeException("Can not convert a URI value to a license: "+uri); - } - } else { - logger.error("Invalid type for AnyLicenseInfo property: "+result.get().getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for AnyLicenseInfo property: "+result.get().getClass().toString()); - } - } - - /** - * Converts property values to an SpdxElement if possible - if NONE or NOASSERTION URI value, convert to the appropriate SpdxElement - * @param propertyDescriptor Descriptor for the property - * @return SpdxElement stored - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - protected Optional getElementPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - Optional result = getObjectPropertyValue(propertyDescriptor); - if (!result.isPresent()) { - return Optional.empty(); - } else if (result.get() instanceof SpdxElement) { - return (Optional)(Optional)result; - } else if (result.get() instanceof IndividualUriValue) { - String uri = ((IndividualUriValue)result.get()).getIndividualURI(); - if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { - return Optional.of(new SpdxNoneElement()); - } else if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - return Optional.of(new SpdxNoAssertionElement()); - } else { - logger.error("Can not convert a URI value to an SPDX element: "+uri); - throw new SpdxInvalidTypeException("Can not convert a URI value to an SPDX element: "+uri); - } - } else { - logger.error("Invalid type for SpdxElement property: "+result.get().getClass().toString()); - throw new SpdxInvalidTypeException("Invalid type for SpdxElement property: "+result.get().getClass().toString()); - } - } - - /** - * Removes a property and its value from the model store if it exists - * @param stModelStore Model store for the properties - * @param stDocumentUri Unique document URI - * @param stId ID of the item to associate the property with - * @param propertyDescriptor Descriptor for the property associated with this object to be removed - * @throws InvalidSPDXAnalysisException - */ - protected static void removeProperty(IModelStore stModelStore, String stDocumentUri, - String stId, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - stModelStore.removeProperty(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor); - } - - /** - * Removes a property and its value from the model store if it exists - * @param propertyDescriptor Descriptor for the property associated with this object to be removed - * @throws InvalidSPDXAnalysisException - */ - protected void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - removeProperty(modelStore, documentUri, id, propertyDescriptor); - } - - /** - * Create an update when, when applied by the ModelStore, removes a property and its value from the model store if it exists - * @param propertyDescriptor Descriptor for the property associated with this object to be removed - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor) { - return () -> { - removeProperty(modelStore, documentUri, id, propertyDescriptor); - }; - } - - // The following methods manage collections of values associated with a property - /** - * Clears a collection of values associated with a property creating the property if it does not exist - * @param stModelStore Model store for the properties - * @param stDocumentUri Unique document URI - * @param stId ID of the item to associate the property with - * @param propertyDescriptor Descriptor for the property - * @throws InvalidSPDXAnalysisException - */ - protected static void clearValueCollection(IModelStore stModelStore, String stDocumentUri, - String stId, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - stModelStore.clearValueCollection(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor); - } - - /** - * Clears a collection of values associated with a property - * @param propertyDescriptor Descriptor for the property - */ - protected void clearValueCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - clearValueCollection(modelStore, documentUri, id, propertyDescriptor); - } - - /** - * Create an update when, when applied by the ModelStore, clears a collection of values associated with a property - * @param propertyDescriptor Descriptor for the property - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDescriptor) { - return () ->{ - clearValueCollection(modelStore, documentUri, id, propertyDescriptor); - }; - } - - /** - * Add a value to a collection of values associated with a property. If a value - * is a ModelObject and does not belong to the document, it will be copied into - * the object store - * - * @param stModelStore Model store for the properties - * @param stDocumentUri Unique document URI - * @param stId ID of the item to associate the property with - * @param propertyDescriptor Descriptor for the property - * @param value to add - * @param copyManager - * @throws InvalidSPDXAnalysisException - */ - protected static void addValueToCollection(IModelStore stModelStore, String stDocumentUri, String stId, - PropertyDescriptor propertyDescriptor, Object value, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(value, "Value can not be null"); - stModelStore.addValueToCollection(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor, - ModelStorageClassConverter.modelObjectToStoredObject(value, stDocumentUri, stModelStore, copyManager)); - } - - /** - * Add a value to a collection of values associated with a property. If a value is a ModelObject and does not - * belong to the document, it will be copied into the object store - * @param propertyDescriptor Descriptor for the property - * @param value to add - * @throws InvalidSPDXAnalysisException - */ - protected void addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - addValueToCollection(modelStore, documentUri, id, propertyDescriptor, value, copyManager); - } - - /** - * Create an update when, when applied, adds a value to a collection of values associated with a property. If a value is a ModelObject and does not - * belong to the document, it will be copied into the object store - * @param propertyDescriptor Descriptor for the property - * @param value to add - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateAddPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) { - return () ->{ - addValueToCollection(modelStore, documentUri, id, propertyDescriptor, value, copyManager); - }; - } - - /** - * Replace the entire value collection for a property. If a value is a ModelObject and does not - * belong to the document, it will be copied into the object store - * @param stModelStore Model store for the properties - * @param stDocumentUri Unique document URI - * @param stId ID of the item to associate the property with - * @param propertyDescriptor Descriptor for the property - * @param values collection of new properties - * @param copyManager if non-null, any ModelObject property value not stored in the stModelStore under the stDocumentUri will be copied to make it available - * @throws InvalidSPDXAnalysisException - */ - protected static void replacePropertyValueCollection(IModelStore stModelStore, String stDocumentUri, String stId, - PropertyDescriptor propertyDescriptor, Collection values, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - clearValueCollection(stModelStore, stDocumentUri, stId, propertyDescriptor); - for (Object value:values) { - addValueToCollection(stModelStore, stDocumentUri, stId, propertyDescriptor, value, copyManager); - } - } - - /** - * Remove a property value from a collection - * @param stModelStore Model store for the properties - * @param stDocumentUri Unique document URI - * @param stId ID of the item to associate the property with - * @param propertyDescriptor descriptor for the property - * @param value Value to be removed - * @throws InvalidSPDXAnalysisException - */ - protected static void removePropertyValueFromCollection(IModelStore stModelStore, String stDocumentUri, String stId, - PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - stModelStore.removeValueFromCollection(CompatibleModelStoreWrapper.documentUriIdToUri(stDocumentUri, stId, stModelStore), propertyDescriptor, - ModelStorageClassConverter.modelObjectToStoredObject(value, stDocumentUri, stModelStore, null)); - } - - /** - * Remove a property value from a collection - * @param propertyDescriptor Descriptor for the property - * @param value Value to be removed - * @throws InvalidSPDXAnalysisException - */ - protected void removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - removePropertyValueFromCollection(modelStore, documentUri, id, propertyDescriptor, value); - } - - /** - * Create an update when, when applied, removes a property value from a collection - * @param propertyDescriptor descriptor for the property - * @param value Value to be removed - * @return an update which can be applied by invoking the apply method - */ - protected ModelUpdate updateRemovePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) { - return () -> { - removePropertyValueFromCollection(modelStore, documentUri, id, propertyDescriptor, value); - }; - } - - /** - * @param propertyDescriptor Descriptor for the property - * @return Set of values associated with a property - */ - protected ModelSet getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelSet(this.modelStore, this.documentUri, this.id, propertyDescriptor, this.copyManager, type); - } - - /** - * @param propertyDescriptor Descriptor for the property - * @return Collection of values associated with a property - */ - protected ModelCollectionV2 getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class type) throws InvalidSPDXAnalysisException { - return new ModelCollectionV2(this.modelStore, this.documentUri, this.id, propertyDescriptor, this.copyManager, type); - } - - /** - * @param propertyDescriptor Descriptor for property - * @return Collection of Strings associated with the property - * @throws SpdxInvalidTypeException - */ - @SuppressWarnings("unchecked") - protected Collection getStringCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - if (!isCollectionMembersAssignableTo(propertyDescriptor, String.class)) { - throw new SpdxInvalidTypeException("Property "+propertyDescriptor+" does not contain a collection of Strings"); - } - return (Collection)(Collection)getObjectPropertyValueSet(propertyDescriptor, String.class); - } - - protected boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return modelStore.isCollectionMembersAssignableTo(CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore), propertyDescriptor, - ModelStorageClassConverter.modelClassToStoredClass(clazz)); - } - - /** - * @param compare - * @return true if all the properties have the same or equivalent values - */ - public boolean equivalent(ModelObject compare) throws InvalidSPDXAnalysisException { - return equivalent(compare, false); - } - - /** - * @param compare - * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion - * @return true if all the properties have the same or equivalent values - */ - public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (!this.getClass().equals(compare.getClass())) { - lastNotEquivalentReason = new NotEquivalentReason(NotEquivalent.DIFFERENT_CLASS); - return false; - } - List propertyValueDescriptors = getPropertyValueDescriptors(); - List comparePropertyValueDescriptors = new ArrayList(compare.getPropertyValueDescriptors()); // create a copy since we're going to modify it - for (PropertyDescriptor propertyDescriptor:propertyValueDescriptors) { - if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { - continue; - } - if (comparePropertyValueDescriptors.contains(propertyDescriptor)) { - if (!propertyValuesEquivalent(propertyDescriptor, this.getObjectPropertyValue(propertyDescriptor), - compare.getObjectPropertyValue(propertyDescriptor), ignoreRelatedElements)) { - lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.PROPERTY_NOT_EQUIVALENT, propertyDescriptor); - return false; - } - comparePropertyValueDescriptors.remove(propertyDescriptor); - } else { - // No property value - Optional propertyValueOptional = this.getObjectPropertyValue(propertyDescriptor); - if (propertyValueOptional.isPresent()) { - Object propertyValue = propertyValueOptional.get(); - if (isEquivalentToNull(propertyValue, propertyDescriptor)) { - continue; - } - lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.COMPARE_PROPERTY_MISSING, propertyDescriptor); - return false; - } - } - } - for (PropertyDescriptor propertyDescriptor:comparePropertyValueDescriptors) { // check any remaining property values - if (ignoreRelatedElements && isRelatedElement(propertyDescriptor)) { - continue; - } - Optional comparePropertyValueOptional = compare.getObjectPropertyValue(propertyDescriptor); - if (!comparePropertyValueOptional.isPresent()) { - continue; - } - Object comparePropertyValue = comparePropertyValueOptional.get(); - if (isEquivalentToNull(comparePropertyValue, propertyDescriptor)) { - continue; - } - lastNotEquivalentReason = new NotEquivalentReason( - NotEquivalent.MISSING_PROPERTY, propertyDescriptor); - return false; - } - return true; - } - - // Some values are treated like null in comparisons - in particular empty model collections and - // "no assertion" values and a filesAnalyzed filed with a value of true - private boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor propertyDescriptor) { - if (propertyValue instanceof ModelCollectionV2) { - return ((ModelCollectionV2) propertyValue).size() == 0; - } else if (isNoAssertion(propertyValue)) { - return true; - } else if (SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED.equals(propertyDescriptor.getName())) { - return propertyValue instanceof Boolean && (Boolean)(propertyValue); - } else { - return false; - } - } - - private boolean isRelatedElement(PropertyDescriptor propertyDescriptor) { - return SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT.equals(propertyDescriptor.getName()); - } - - private boolean isEmptyModelCollection(Object value) { - return (value instanceof ModelCollectionV2) - && (((ModelCollectionV2) value).size() == 0); - } - - private boolean isNoAssertion(Object propertyValue) { - return propertyValue instanceof SpdxNoAssertionLicense || - propertyValue.equals(SpdxConstantsCompatV2.NOASSERTION_VALUE); - } - - /** - * @param propertyDescriptor Descriptor for the property - * @param valueA value to compare - * @param valueB value to compare - * @param ignoreRelatedElements if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion - * @return true if the property values are equivalent - * @throws InvalidSPDXAnalysisException - */ - private boolean propertyValuesEquivalent(PropertyDescriptor propertyDescriptor, Optional valueA, - Optional valueB, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (!valueA.isPresent()) { - if (valueB.isPresent()) { - return isEmptyModelCollection(valueB.get()); - } - } else if (!valueB.isPresent()) { - return isEmptyModelCollection(valueA.get()); - } else if (valueA.get() instanceof ModelCollectionV2 && valueB.get() instanceof ModelCollectionV2) { - List myList = ((ModelCollectionV2)valueA.get()).toImmutableList(); - List compareList = ((ModelCollectionV2)valueB.get()).toImmutableList(); - if (!areEquivalent(myList, compareList, ignoreRelatedElements)) { - return false; - } - } else if (valueA.get() instanceof List && valueB.get() instanceof List) { - if (!areEquivalent((List)valueA.get(), (List)valueB.get(), ignoreRelatedElements)) { - return false; - } - } else if (valueA.get() instanceof IndividualUriValue && valueB.get() instanceof IndividualUriValue) { - if (!Objects.equals(((IndividualUriValue)valueA.get()).getIndividualURI(), ((IndividualUriValue)valueB.get()).getIndividualURI())) { - return false; - } - // Note: we must check the IndividualValue before the ModelObject types since the IndividualValue takes precedence - } else if (valueA.get() instanceof ModelObject && valueB.get() instanceof ModelObject) { - if (!((ModelObject)valueA.get()).equivalent(((ModelObject)valueB.get()), - isRelatedElement(propertyDescriptor) ? true : ignoreRelatedElements)) { - return false; - } - - } else if (!OptionalObjectsEquivalent(valueA, valueB)) { // Present, not a list, and not a TypedValue - return false; - } - return true; - } - - /** - * Compares 2 simple optional objects considering NONE and NOASSERTION values which are equivalent to their strings - * @param valueA - * @param valueB - * @return - */ - private boolean OptionalObjectsEquivalent(Optional valueA, Optional valueB) { - if (Objects.equals(valueA, valueB)) { - return true; - } - if (!valueA.isPresent()) { - return false; - } - if (!valueB.isPresent()) { - return false; - } - if (valueA.get() instanceof IndividualUriValue) { - if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(((IndividualUriValue)valueA.get()).getIndividualURI()) && SpdxConstantsCompatV2.NONE_VALUE.equals(valueB.get())) { - return true; - } - if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(((IndividualUriValue)valueA.get()).getIndividualURI()) && SpdxConstantsCompatV2.NOASSERTION_VALUE.equals(valueB.get())) { - return true; - } - } - if (valueB.get() instanceof IndividualUriValue) { - if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(((IndividualUriValue)valueB.get()).getIndividualURI()) && SpdxConstantsCompatV2.NONE_VALUE.equals(valueA.get())) { - return true; - } - if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(((IndividualUriValue)valueB.get()).getIndividualURI()) && SpdxConstantsCompatV2.NOASSERTION_VALUE.equals(valueA.get())) { - return true; - } - } - if (valueA.get() instanceof String && valueB.get() instanceof String) { - return normalizeString((String)valueA.get()).equals(normalizeString((String)valueB.get())); - } - return false; - } - - /** - * Normalize a string for dos and linux linefeeds - * @param s - * @return linux style only linefeeds - */ - private Object normalizeString(String s) { - return s.replaceAll("\r\n", "\n").trim(); - } - - /** - * Checks if for each item on either list, there is an item in the other list that is equivalent. - * @param ignoreRelatedElements Whether related elements should be ignored in the comparison - */ - private boolean areEquivalent(List firstList, List secondList, - boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (firstList.size() != secondList.size()) { - return false; - } - for (Object item : firstList) { - if (!containsEqualOrEquivalentItem(secondList, item, ignoreRelatedElements)) { - return false; - } - } - for (Object item : secondList) { - if (!containsEqualOrEquivalentItem(firstList, item, ignoreRelatedElements)) { - return false; - } - } - return true; - } - - private boolean containsEqualOrEquivalentItem(List list, Object itemToFind, - boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (list.contains(itemToFind)) { - return true; - } else if (itemToFind instanceof IndividualUriValue && list.contains(new SimpleUriValue((IndividualUriValue) itemToFind))) { - // Two IndividualUriValues are considered equal if their URI coincides - return true; - } - - if (!(itemToFind instanceof ModelObject)) { - return false; - } - - ModelObject objectToFind = (ModelObject) itemToFind; - for (Object objectToCompare : list) { - if (!(objectToCompare instanceof ModelObject)) { - continue; - } - if (objectToFind.equivalent((ModelObject) objectToCompare, ignoreRelatedElements)) { - return true; - } - } - return false; - } - - @Override - public int hashCode() { - if (this.id != null) { - return this.id.toLowerCase().hashCode() ^ this.documentUri.hashCode(); - } else { - return 0; - } - } - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof ModelObject)) { - // covers o == null, as null is not an instance of anything - return false; - } - ModelObject comp = (ModelObject)o; - if (getModelStore().getIdType(id).equals(IdType.Anonymous)) { - return Objects.equals(modelStore, comp.getModelStore()) && Objects.equals(id, comp.getId()) && Objects.equals(documentUri, comp.getDocumentUri()); - } else { - return Objects.equals(id, comp.getId()) && Objects.equals(documentUri, comp.getDocumentUri()); - } - } - - /** - * Clone a new object using a different model store - * @param modelStore - * @return - */ - public ModelObject clone(IModelStore modelStore) { - if (Objects.isNull(this.copyManager)) { - throw new IllegalStateException("A copy manager must be provided to clone"); - } - if (this.modelStore.equals(modelStore)) { - throw new IllegalStateException("Can not clone to the same model store"); - } - Objects.requireNonNull(modelStore, "Model store for clone must not be null"); - if (modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, modelStore))) { - throw new IllegalStateException("Can not clone - "+this.id+" already exists."); - } - try { - ModelObject retval = SpdxModelFactory.createModelObjectV2(modelStore, this.documentUri, this.id, this.getType(), this.copyManager); - retval.copyFrom(this); - return retval; - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - /** - * Copy all the properties from the source object - * @param source - * @throws InvalidSPDXAnalysisException - */ - public void copyFrom(ModelObject source) throws InvalidSPDXAnalysisException { - if (Objects.isNull(copyManager)) { - throw new InvalidSPDXAnalysisException("Copying is not enabled for "+id); - } - copyManager.copy(this.modelStore, CompatibleModelStoreWrapper.documentUriIdToUri(this.documentUri, this.id, this.modelStore), - source.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(source.getDocumentUri(), source.getId(), source.getModelStore()), - this.getType(), CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), source.getModelStore().getIdType(source.getId()) == IdType.Anonymous), - CompatibleModelStoreWrapper.documentUriToNamespace(this.documentUri, modelStore.getIdType(id) == IdType.Anonymous), - CompatibleModelStoreWrapper.documentUriToNamespace(source.getDocumentUri(), false), - CompatibleModelStoreWrapper.documentUriToNamespace(this.documentUri, false)); - } - - public void setCopyManager(ModelCopyManager copyManager) { - this.copyManager = copyManager; - } - - /** - * @return the copy manager - value may be null if copies are not allowd - */ - public ModelCopyManager getCopyManager() { - return this.copyManager; - } - - /** - * @param id String for the object - * @return type of the ID - */ - protected IdType idToIdType(String id) { - if (id.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { - return IdType.LicenseRef; - } else if (id.startsWith(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { - return IdType.SpdxId; - } else if (id.startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { - return IdType.DocumentRef; - } else if (ListedLicenses.getListedLicenses().isSpdxListedLicenseId(id)) { - return IdType.ListedLicense; - } else if ("none".equalsIgnoreCase(id) || "noassertion".equalsIgnoreCase(id)) { - return IdType.Literal; - } else { - return IdType.Anonymous; - } - } - - protected TypedValue toTypedValue() throws InvalidSPDXAnalysisException { - return CompatibleModelStoreWrapper.typedValueFromDocUri(this.documentUri, this.id, modelStore.getIdType(id).equals(IdType.Anonymous), this.getType()); - } - - /** - * Verifies all elements in a collection - * @param specVersion version of the SPDX specification to verify against - * @param collection collection to be verifies - * @param verifiedIds verifiedIds list of all Id's which have already been verifieds - prevents infinite recursion - * @param warningPrefix String to prefix any warning messages - */ - protected List verifyCollection(Collection collection, String warningPrefix, Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - for (ModelObject mo:collection) { - for (String warning:mo.verify(verifiedIds, specVersion)) { - if (Objects.nonNull(warningPrefix)) { - retval.add(warningPrefix + warning); - } else { - retval.add(warning); - } - } - } - return retval; - } - - // The following methods are helper methods to create Model Object subclasses using the same model store and document as this Model Object - - /** - * @param annotator This field identifies the person, organization or tool that has commented on a file, package, or the entire document. - * @param annotationType This field describes the type of annotation. Annotations are usually created when someone reviews the file, and if this is the case the annotation type should be REVIEW. If the author wants to store extra information about one of the elements during creation, it is recommended to use the type of OTHER. - * @param date Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard. - * @param comment - * @return - * @throws InvalidSPDXAnalysisException - */ - public Annotation createAnnotation(String annotator, AnnotationType annotationType, String date, - String comment) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(annotator, "Annotator can not be null"); - Objects.requireNonNull(annotationType, "AnnotationType can not be null"); - Objects.requireNonNull(date, "Date can not be null"); - Objects.requireNonNull(comment, "Comment can not be null"); - Annotation retval = new Annotation(this.modelStore, this.documentUri, - this.modelStore.getNextId(IdType.Anonymous, this.documentUri), copyManager, true); - retval.setAnnotationDate(date); - retval.setAnnotationType(annotationType); - retval.setAnnotator(annotator); - retval.setComment(comment); - return retval; - } - - /** - * @param relatedElement The SPDX Element that is related - * @param relationshipType Type of relationship - See the specification for a - * description of the types - * @param comment optional comment for the relationship - * @return - * @throws InvalidSPDXAnalysisException - */ - public Relationship createRelationship(SpdxElement relatedElement, - RelationshipType relationshipType, @Nullable String comment) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(relatedElement, "Related Element can not be null"); - Objects.requireNonNull(relationshipType, "Relationship type can not be null"); - Relationship retval = new Relationship(this.modelStore, this.documentUri, - this.modelStore.getNextId(IdType.Anonymous, this.documentUri), this.copyManager, true); - retval.setRelatedSpdxElement(relatedElement); - retval.setRelationshipType(relationshipType); - if (Objects.nonNull(comment)) { - retval.setComment(comment); - } - return retval; - } - - /** - * @param algorithm Checksum algorithm - * @param value Checksum value - * @return Checksum using the same model store and document URI as this Model Object - * @throws InvalidSPDXAnalysisException - */ - public Checksum createChecksum(ChecksumAlgorithm algorithm, String value) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(algorithm, "Algorithm can not be null"); - Objects.requireNonNull(value, "Value can not be null"); - Checksum retval = new Checksum(this.modelStore, this.documentUri, - this.modelStore.getNextId(IdType.Anonymous, this.documentUri), this.copyManager, true); - retval.setAlgorithm(algorithm); - retval.setValue(value); - return retval; - } - - /** - * @param value Verification code calculated value - * @param excludedFileNames file names of files excluded from the verification code calculation - * @return Package verification code using the same model store and document URI as this Model Object - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackageVerificationCode createPackageVerificationCode(String value, Collection excludedFileNames) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(value, "Value can not be null"); - Objects.requireNonNull(excludedFileNames, "Excluded Files can not be null"); - SpdxPackageVerificationCode retval = new SpdxPackageVerificationCode(this.modelStore, this.documentUri, - this.modelStore.getNextId(IdType.Anonymous, this.documentUri), this.copyManager, true); - retval.setValue(value); - retval.getExcludedFileNames().addAll(excludedFileNames); - return retval; - } - - /** - * @param externalDocumentUri Document URI for the external document - * @param checksum Checksum of the external Document - * @param externalDocumentId ID to be used internally within this SPDX document - * @return ExternalDocumentRef using the same model store and document URI as this Model Object - * @throws InvalidSPDXAnalysisException - */ - public ExternalDocumentRef createExternalDocumentRef(String externalDocumentId, String externalDocumentUri, - Checksum checksum) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(externalDocumentUri, "External document URI can not be null"); - Objects.requireNonNull(checksum, "Checksum can not be null"); - Objects.requireNonNull(externalDocumentId, "External document ID can not be null"); - if (!SpdxVerificationHelper.isValidExternalDocRef(externalDocumentId)) { - throw new InvalidSPDXAnalysisException("Invalid external document reference ID "+externalDocumentId+ - ". Must be of the format "+SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PATTERN.pattern()); - } - if (!SpdxVerificationHelper.isValidUri(externalDocumentUri)) { - throw new InvalidSPDXAnalysisException("Invalid external document URI: "+externalDocumentUri); - } - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - if (modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(getDocumentUri(), externalDocumentId, modelStore))) { - return new ExternalDocumentRef(getModelStore(), getDocumentUri(), - externalDocumentId, this.copyManager, false); - } else { - ExternalDocumentRef retval = new ExternalDocumentRef(getModelStore(), getDocumentUri(), - externalDocumentId, this.copyManager, true); - retval.setChecksum(checksum); - retval.setSpdxDocumentNamespace(externalDocumentUri); - // Need to add this to the list of document URI's - ModelObject.addValueToCollection(getModelStore(), getDocumentUri(), - SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, - SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, - retval, copyManager); - return retval; - } - } finally { - getModelStore().leaveCriticalSection(lock); - } - } - - /** - * @param creators Creators Identify who (or what, in the case of a tool) created the SPDX file. If the SPDX file was created by an individual, indicate the person's name. - * @param date When the SPDX file was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard. - * @return creationInfo using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation createCreationInfo(List creators, String date) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(creators, "Creators can not be null"); - Objects.requireNonNull(date, "Date can not be null"); - SpdxCreatorInformation retval = new SpdxCreatorInformation(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.getCreators().addAll(creators); - retval.setCreated(date); - return retval; - } - - /** - * @param category Reference category - * @param referenceType Reference type - * @param locator Reference locator - * @param comment Optional comment - * @return ExternalRef using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public ExternalRef createExternalRef(ReferenceCategory category, ReferenceType referenceType, - String locator, @Nullable String comment) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(category, "Category can not be null"); - Objects.requireNonNull(referenceType, "Reference type can not be null"); - Objects.requireNonNull(locator, "Locator can not be null"); - ExternalRef retval = new ExternalRef(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.setReferenceCategory(category); - retval.setReferenceType(referenceType); - retval.setReferenceLocator(locator); - retval.setComment(comment); - return retval; - } - - /** - * Create an SpdxFileBuilder with all of the required properties - the build() method will build the file - * @param id - ID - must be an SPDX ID type - * @param name - File name - * @param concludedLicense license concluded - * @param seenLicense collection of seen licenses - * @param copyrightText Copyright text - * @param sha1 Sha1 checksum - * @return SPDX file using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public SpdxFile.SpdxFileBuilder createSpdxFile(String id, String name, AnyLicenseInfo concludedLicense, - Collection seenLicense, String copyrightText, Checksum sha1) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(name, "Name can not be null"); - Objects.requireNonNull(sha1, "Sha1 can not be null"); - return new SpdxFile.SpdxFileBuilder(modelStore, documentUri, id, copyManager, - name, concludedLicense, seenLicense, copyrightText, sha1); - } - - /** - * Create an SpdxPackageBuilder with all required fields for a filesAnalyzed=false using this objects model store and document URI - * @param id - ID - must be an SPDX ID type - * @param name - File name - * @param concludedLicense license concluded - * @param copyrightText Copyright text - * @param licenseDeclared Declared license for the package - * @return SpdxPackageBuilder with all required fields for a filesAnalyzed=false - */ - public SpdxPackage.SpdxPackageBuilder createPackage(String id, String name, - AnyLicenseInfo concludedLicense, - String copyrightText, AnyLicenseInfo licenseDeclared) { - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(name, "Name can not be null"); - return new SpdxPackage.SpdxPackageBuilder(modelStore, documentUri, id, copyManager, - name, concludedLicense, copyrightText, licenseDeclared); - } - - /** - * @param referencedElement - * @param offset - * @return ByteOffsetPointer using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public ByteOffsetPointer createByteOffsetPointer(SpdxElement referencedElement, int offset) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(referencedElement, "Referenced element can not be null"); - ByteOffsetPointer retval = new ByteOffsetPointer(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.setReference(referencedElement); - retval.setOffset(offset); - return retval; - } - - /** - * @param referencedElement - * @param lineNumber - * @return LineCharPointer using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public LineCharPointer createLineCharPointer(SpdxElement referencedElement, int lineNumber) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(referencedElement, "Referenced element can not be null"); - LineCharPointer retval = new LineCharPointer(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.setReference(referencedElement); - retval.setLineNumber(lineNumber); - return retval; - } - - /** - * @param startPointer - * @param endPointer - * @return StartEndPointer using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public StartEndPointer createStartEndPointer(SinglePointer startPointer, SinglePointer endPointer) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(startPointer, "Start pointer can not be null"); - Objects.requireNonNull(endPointer, "End pointer can not be null"); - StartEndPointer retval = new StartEndPointer(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.setStartPointer(startPointer); - retval.setEndPointer(endPointer); - return retval; - } - - /** - * Create an SpdxSnippetBuilder with all of the required properties - the build() method will build the file - * @param id - ID - must be an SPDX ID type - * @param name - File name - * @param concludedLicense license concluded - * @param seenLicense collection of seen licenses - * @param copyrightText Copyright text - * @param snippetFromFile File where the snippet is located - * @param startByte first byte of the snippet in the file - * @param endByte last byte of the snippet in the file - * @return SPDX snippet using the same modelStore and documentUri as this object - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet.SpdxSnippetBuilder createSpdxSnippet(String id, String name, AnyLicenseInfo concludedLicense, - Collection seenLicense, String copyrightText, - SpdxFile snippetFromFile, int startByte, int endByte) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(name, "Name can not be null"); - return new SpdxSnippet.SpdxSnippetBuilder(modelStore, documentUri, id, copyManager, - name, concludedLicense, seenLicense, copyrightText, snippetFromFile, startByte, endByte); - } - - /** - * @param members - * @return ConjunctiveLicenseSet with default model store and document URI initialized with members - * @throws InvalidSPDXAnalysisException - */ - public ConjunctiveLicenseSet createConjunctiveLicenseSet(Collection members) throws InvalidSPDXAnalysisException { - ConjunctiveLicenseSet retval = new ConjunctiveLicenseSet(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.setMembers(members); - return retval; - } - - /** - * @param members - * @return DisjunctiveLicenseSet with default model store and document URI initialized with members - * @throws InvalidSPDXAnalysisException - */ - public DisjunctiveLicenseSet createDisjunctiveLicenseSet(Collection members) throws InvalidSPDXAnalysisException { - DisjunctiveLicenseSet retval = new DisjunctiveLicenseSet(modelStore, documentUri, - modelStore.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.setMembers(members); - return retval; - } - - /** - * Create a CrossRef Builder with an Anonymous ID type using the same model store and document URI - * @param url URL for the cross reference - * @return a CrossRefBuilder which you can call build() on to build the CrossRef - * @throws InvalidSPDXAnalysisException - */ - public CrossRefBuilder createCrossRef(String url) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(url, "URL can not be null"); - return new CrossRefBuilder(this.modelStore, this.documentUri, - this.modelStore.getNextId(IdType.Anonymous, this.documentUri), this.copyManager, url); - } - - @Override - public String toString() { - return this.getType() + " " + this.id; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java b/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java deleted file mode 100644 index d954aefca..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelSet.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.Collection; -import java.util.Iterator; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.PropertyDescriptor; - -/** - * A ModelCollection implemented as a set where all items in the collection are unique based - * on equality (not based on equivalence). - * - * @author Gary O'Neall - * - */ -public class ModelSet extends ModelCollectionV2 { - - static final Logger logger = LoggerFactory.getLogger(ModelSet.class); - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param propertyDescriptor - * @param copyManager - * @param type - * @throws InvalidSPDXAnalysisException - */ - public ModelSet(IModelStore modelStore, String documentUri, String id, PropertyDescriptor propertyDescriptor, - @Nullable ModelCopyManager copyManager, @Nullable Class type) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, propertyDescriptor, copyManager, type); - } - - @Override - public boolean add(Object element) { - IModelStoreLock lock; - try { - lock = this.getModelStore().enterCriticalSection(false); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - try { - if (!super.contains(element)) { - return super.add(element); - } else { - return false; - } - } finally { - this.getModelStore().leaveCriticalSection(lock); - } - } - - @Override - public boolean addAll(Collection c) { - IModelStoreLock lock; - try { - lock = this.getModelStore().enterCriticalSection(false); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - try { - boolean retval = false; - Iterator iter = c.iterator(); - while (iter.hasNext()) { - Object item = iter.next(); - if (!super.contains(item) && super.add(item)) { - retval = true; - } - } - return retval; - } finally { - this.getModelStore().leaveCriticalSection(lock); - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java b/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java deleted file mode 100644 index a1b13e5c7..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ModelStorageClassConverter.java +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.Objects; -import java.util.Optional; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.SpdxObjectNotInStoreException; -import org.spdx.library.TypedValue; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * This static helper class converts objects used in the model to and from objects used by the SPI / storage class. - * - * The storage SPI supports the following types: - * - * String - * Boolean - * TypedValue - this class is used to store most (if not all) of the ModelStore classes - * IndividualUriValue - this interface type represents a value which can be stored as a unique - * value. It is used to represent Enum types in the model and the ExternalSpdxElement model object. Note that - * IndividualUriValues can not have any properties associated with them. - * - * @author Gary O'Neall - * - */ -public class ModelStorageClassConverter { - - static final Logger logger = LoggerFactory.getLogger(ModelStorageClassConverter.class); - - /** - * Converts any typed value or individual value objects to a ModelObject, - * returning an existing ModelObject if it exists or creates a new ModelObject - * - * @param value Value which may be a TypedValue - * @param documentUri Document URI to use when converting a typedValue - * @param modelStore ModelStore to use in fetching or creating - * @param copyManager if not null, copy any referenced ID's outside of this - * document/model store - * @return the object itself unless it is a TypedValue, in which case a - * ModelObject is returned - * @throws InvalidSPDXAnalysisException - */ - public static Object storedObjectToModelObject(Object value, String documentUri, IModelStore modelStore, - ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (value instanceof IndividualUriValue) { // Note: this must be before the check for TypedValue - SimpleUriValue suv = new SimpleUriValue((IndividualUriValue)value); - return suv.toModelObject(modelStore, null, documentUri, null); - } else if (value instanceof TypedValue) { - TypedValue tv = (TypedValue)value; - String id = tv.getObjectUri().startsWith(documentUri) ? tv.getObjectUri().substring(documentUri.length() + 1) : - tv.getObjectUri(); - if (id.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { - return SpdxModelFactory.getModelObjectV2(modelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, - id.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()), tv.getType(), copyManager, true); - } else { - return SpdxModelFactory.getModelObjectV2(modelStore, documentUri, id, tv.getType(), copyManager, true); - } - } else { - return value; - } - }; - - /** - * Converts any typed value or IndividualValue objects to a ModelObject, - * returning an existing ModelObject if it exists or creates a new ModelObject - * - * @param value Value which may be a TypedValue - * @param stDocumentUri Document URI to use when converting a typedValue - * @param stModelStore ModelStore to use in fetching or creating - * @param copyManager if not null, copy any referenced ID's outside of this - * document/model store - * @return the object itself unless it is a TypedValue, in which case a - * ModelObject is returned - * @throws InvalidSPDXAnalysisException - */ - public static Optional optionalStoredObjectToModelObject(Optional value, - String stDocumentUri, IModelStore stModelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (value.isPresent() && value.get() instanceof IndividualUriValue) { - return Optional.of(new SimpleUriValue((IndividualUriValue)value.get()) - .toModelObject(stModelStore, copyManager, stDocumentUri, null)); - } else if (value.isPresent() && value.get() instanceof TypedValue) { - TypedValue tv = (TypedValue)value.get(); - return Optional.of(SpdxModelFactory.createModelObjectV2(stModelStore, stDocumentUri, - CompatibleModelStoreWrapper.objectUriToId(stModelStore.getIdType(tv.getObjectUri()) == IdType.Anonymous, tv.getObjectUri(), stDocumentUri), - tv.getType(), copyManager)); - } else { - return value; - } - } - - /** - * Converts a stored object to it's appropriate model object type - * @param value - * @param stDocumentUri - * @param stModelStore - * @param copyManager if not null, copy any referenced ID's outside of this document/model store - * @return Model Object appropriate type - * @throws InvalidSPDXAnalysisException - */ - public static Object modelObjectToStoredObject(Object value, String stDocumentUri, - IModelStore stModelStore, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (value instanceof IndividualUriValue) { - // Convert to a simple URI value to save storage - return new SimpleUriValue((IndividualUriValue)value); - } else if (value instanceof ModelObject) { - ModelObject mValue = (ModelObject)value; - String toDocumentUri = SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(mValue.getType()) || - SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION.equals(mValue.getType()) || - SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(mValue.getType()) ? - SpdxConstantsCompatV2.LISTED_LICENSE_URL : stDocumentUri; - if (!mValue.getModelStore().equals(stModelStore) || !mValue.getDocumentUri().equals(toDocumentUri)) { - if (Objects.nonNull(copyManager)) { - boolean anon = mValue.getModelStore().getIdType(mValue.getId()) == IdType.Anonymous; - return copyManager.copy(stModelStore, mValue.getModelStore(), - CompatibleModelStoreWrapper.documentUriIdToUri(mValue.getDocumentUri(), mValue.getId(), anon), - mValue.getType(), CompatibleModelStoreWrapper.documentUriToNamespace(mValue.getDocumentUri(), anon), - CompatibleModelStoreWrapper.documentUriToNamespace(toDocumentUri, anon), - CompatibleModelStoreWrapper.documentUriToNamespace(mValue.getDocumentUri(), false), - CompatibleModelStoreWrapper.documentUriToNamespace(toDocumentUri, false)); - } else { - throw new SpdxObjectNotInStoreException("Can not set a property value to a Model Object stored in a different model store"); - } - } else { - return mValue.toTypedValue(); - } - } else if (value instanceof Integer || value instanceof String || value instanceof Boolean || value instanceof IndividualUriValue) { - return value; - } else if (Objects.isNull(value)) { - throw new SpdxInvalidTypeException("Property value is null"); - } else { - throw new SpdxInvalidTypeException("Property value type not supported: "+value.getClass().getName()); - } - } - - /** - * Convert the class to the approrpriate stored class - * @param clazz Model class - * @return class compatible with stored classes - */ - public static Class modelClassToStoredClass(Class clazz) { - if (ModelObject.class.isAssignableFrom(clazz)) { - return TypedValue.class; - } else if (implementsIndividualUriValue(clazz)) { - return SimpleUriValue.class; - } else { - return clazz; - } - } - - private static boolean implementsIndividualUriValue(Class clazz) { - for (Class intefaceClass:clazz.getInterfaces()) { - if (intefaceClass.equals(IndividualUriValue.class)) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/Read.java b/src/main/java/org/spdx/library/model/compat/v2/Read.java deleted file mode 100644 index f54a80902..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/Read.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Stream; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.TypedValue; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.ISerializableModelStore; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * Supports reading SPDX documents from an existing ModelStore - * - * Some design and some implementation borrowed from Yevster's spdxtra project under the Apache 2.0 license - * http://yevster.github.io/spdxtra/ - * - * - * @author Gary O'Neall - * - */ -public class Read { - - public static class Document { - /** - * Obtains the SPDX Documents described in the provided model store. A document store - * may contain multiple SPDX documents identified by their unique document URI's - * - * @param modelStore Storage for the model objects - * @return List of SPDX documents contained in the modelStore - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static List get(IModelStore modelStore) throws InvalidSPDXAnalysisException, IOException { - List retval = new ArrayList(); - SpdxModelFactory.getElements(modelStore, null, null, SpdxDocument.class).forEach( - spdxDoc -> retval.add((SpdxDocument)spdxDoc)); - return retval; - } - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @return the SPDX document - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static SpdxDocument get(IModelStore modelStore, String documentUri) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(true); - try { - return new SpdxDocument(modelStore, documentUri, null, false); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @return true if the document exists in the model store - */ - public static boolean documentExists(IModelStore modelStore, String documentUri) { - return modelStore.exists(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, - SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, false)); - } - } - - /** - * Serializes an SPDX document stored in the modelStore. The specific format of - * the serialization will depend on the modelStore. - * - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this - * model - * @param stream Output stream for serialization - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static void serialize(ISerializableModelStore modelStore, String documentUri, OutputStream stream) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(true); - try { - modelStore.serialize(documentUri, stream); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - - /** - * Write the SPDX document stored in the modelStore to a file - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param filePath File path to output the file - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static void writeToFile(ISerializableModelStore modelStore, String documentUri, Path filePath) throws InvalidSPDXAnalysisException, IOException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(filePath, "File path can not be null"); - Files.createFile(filePath); - try (FileOutputStream fos = new FileOutputStream(filePath.toFile())) { - modelStore.serialize(documentUri, fos); - } - } - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this - * model - * @param typeFilter Optional parameter to specify the type of objects to be - * retrieved - * @return Stream of all items store within the document - * @throws InvalidSPDXAnalysisException - */ - public static Stream getAllItems(IModelStore modelStore, String documentUri, - String typeFilter) throws InvalidSPDXAnalysisException { - return modelStore.getAllItems(documentUri, typeFilter).map((TypedValue tv) -> { - try { - return SpdxModelFactory.createModelObjectV2(modelStore, documentUri, tv.getObjectUri(), tv.getType(), null); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - }); - } - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @return All packages stored for the document in the model store - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public static Stream getAllPackages(IModelStore modelStore, String documentUri) throws InvalidSPDXAnalysisException { - return (Stream)(getAllItems(modelStore, documentUri, SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE)); - } - - /** The following can be achieve by fetching the list of relationships from the element - public static Stream getRelationships(Dataset dataset, SpdxElement element, Relationship.Type relationshipType) { - - } - **/ -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java b/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java deleted file mode 100644 index 4c8504d45..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/ReferenceType.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SimpleUriValue; - -/** - * Type of external reference - * Note that there are very few required fields for this class in that - * the external reference type does not need to be provided in the SPDX - * document for the document to be valid. - * - * @author Gary O'Neall - */ -public class ReferenceType extends SimpleUriValue implements Comparable { - - public static final String MISSING_REFERENCE_TYPE_URI = "http://spdx.org/rdf/refeferences/MISSING"; - - public static ReferenceType getMissingReferenceType() throws InvalidSPDXAnalysisException { - return new ReferenceType(MISSING_REFERENCE_TYPE_URI); - } - - public ReferenceType(IndividualUriValue uri) throws InvalidSPDXAnalysisException { - super(uri); - } - - public ReferenceType(String uriValue) throws InvalidSPDXAnalysisException { - super(uriValue); - } - - @Override - public int compareTo(ReferenceType compare) { - return this.getIndividualURI().compareTo(compare.getIndividualURI()); - } - - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java b/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java deleted file mode 100644 index dd4419b1b..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/RelatedElementCollection.java +++ /dev/null @@ -1,400 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; - -/** - * Collection of SPDX elements related to an SpdxElement - * - * @author Gary O'Neall - * - */ -/** - * @author gary - * - */ -public class RelatedElementCollection implements Collection { - - static final Logger logger = LoggerFactory.getLogger(RelatedElementCollection.class); - - ModelCollectionV2 relationshipCollection; - private RelationshipType relationshipTypeFilter; - private String relatedElementTypeFilter; - /** - * Keeps track of any created relationships so we can delete them when removed - */ - private Set createdRelationshipIds = new HashSet<>(); - - private SpdxElement owningElement; - - /** - * @param owningElement - * @param relationshipTypeFilter relationship type to filter the results - * collection on - if null, do not filter - * @throws InvalidSPDXAnalysisException - */ - public RelatedElementCollection(SpdxElement owningElement, - @Nullable RelationshipType relationshipTypeFilter) throws InvalidSPDXAnalysisException { - this(owningElement, relationshipTypeFilter, null); - } - - /** - * @param owningElement - * @param relationshipTypeFilter relationship type to filter the results - * collection on - if null, do not filter - * @param relatedElementTypeFilter filter for only related element types - if null, do not filter - * @throws InvalidSPDXAnalysisException - */ - public RelatedElementCollection(SpdxElement owningElement, - @Nullable RelationshipType relationshipTypeFilter, - @Nullable String relatedElementTypeFilter) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(owningElement, "Owning element can not be null"); - this.owningElement = owningElement; - this.relationshipCollection = new ModelCollectionV2(owningElement.getModelStore(), - owningElement.getDocumentUri(), owningElement.getId(), SpdxConstantsCompatV2.PROP_RELATIONSHIP, - owningElement.getCopyManager(), Relationship.class); - this.relationshipTypeFilter = relationshipTypeFilter; - this.relatedElementTypeFilter = relatedElementTypeFilter; - } - - public List toImmutableList() { - List retval = new ArrayList<>(); - for (Object item:relationshipCollection.toImmutableList()) { - if (item instanceof Relationship) { - Relationship relationship = (Relationship)item; - try { - RelationshipType relationshipType = relationship.getRelationshipType(); - if (Objects.isNull(this.relationshipTypeFilter) || - (this.relationshipTypeFilter.equals(relationshipType))) { - Optional relatedElement = relationship.getRelatedSpdxElement(); - if (relatedElement.isPresent()) { - if (Objects.isNull(this.relatedElementTypeFilter) || - this.relatedElementTypeFilter.equals(relatedElement.get().getType())) { - retval.add(relatedElement.get()); - } - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("error getting relationship type - skipping relationship",e); - } - } - } - return Collections.unmodifiableList(retval); - } - - /* (non-Javadoc) - * @see java.util.Collection#size() - */ - @Override - public int size() { - return toImmutableList().size(); - } - - /* (non-Javadoc) - * @see java.util.Collection#isEmpty() - */ - @Override - public boolean isEmpty() { - return toImmutableList().isEmpty(); - } - - /* (non-Javadoc) - * @see java.util.Collection#contains(java.lang.Object) - */ - @Override - public boolean contains(Object o) { - if (!(o instanceof SpdxElement)) { - return false; - } - String elementId = ((SpdxElement)o).getId(); - Iterator iter = relationshipCollection.iterator(); - while (iter.hasNext()) { - Object item = iter.next(); - if (item instanceof Relationship) { - Relationship relationship = (Relationship)item; - try { - RelationshipType relationshipType = relationship.getRelationshipType(); - if (Objects.isNull(this.relationshipTypeFilter) || - (this.relationshipTypeFilter.equals(relationshipType))) { - Optional relatedElement = relationship.getRelatedSpdxElement(); - if (relatedElement.isPresent()) { - if (elementId.equals(relatedElement.get().getId())) { - return true; - } - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("error getting relationship type - skipping relationship",e); - } - } - } - return false; - } - - /* (non-Javadoc) - * @see java.util.Collection#iterator() - */ - @Override - public Iterator iterator() { - return toImmutableList().iterator(); - } - - /* (non-Javadoc) - * @see java.util.Collection#toArray() - */ - @Override - public SpdxElement[] toArray() { - List list = toImmutableList(); - return list.toArray(new SpdxElement[list.size()]); - } - - /* (non-Javadoc) - * @see java.util.Collection#toArray(java.lang.Object[]) - */ - @Override - public T[] toArray(T[] a) { - return toImmutableList().toArray(a); - } - - /* (non-Javadoc) - * @see java.util.Collection#add(java.lang.Object) - */ - @Override - public boolean add(SpdxElement e) { - if (Objects.isNull(this.relationshipTypeFilter)) { - logger.error("Ambiguous relationship type - can not add element"); - throw new RuntimeException("Can not add element to RelatedElementCollection due to ambiguous relationship type. Add a relationshipTypeFilter to resolve."); - } - if (Objects.isNull(e) || contains(e)) { - return false; - } - try { - IModelStoreLock lock = owningElement.getModelStore() - .enterCriticalSection(false); - try { - Relationship relationship = owningElement.createRelationship(e, relationshipTypeFilter, null); - createdRelationshipIds.add(relationship.getId()); - return owningElement.addRelationship(relationship); - } finally { - owningElement.getModelStore().leaveCriticalSection(lock); - } - } catch (InvalidSPDXAnalysisException e1) { - logger.error("Error adding relationship",e1); - throw new RuntimeException(e1); - } - } - - /* (non-Javadoc) - * @see java.util.Collection#remove(java.lang.Object) - */ - @Override - public boolean remove(Object o) { - if (o instanceof Relationship) { - return this.relationshipCollection.remove(o); - } else if (o instanceof SpdxElement) { - if (Objects.isNull(this.relationshipTypeFilter)) { - logger.error("Ambiguous relationship type - can not add element"); - throw new RuntimeException("Can not remove element from RelatedElementCollection due to ambiguous relationship type. Add a relationshipTypeFilter to resolve."); - } - List relationships = this.relationshipCollection.toImmutableList(); - for (Object rel:relationships) { - if (rel instanceof Relationship) { - Relationship relationship = (Relationship)rel; - try { - Optional relatedElement = relationship.getRelatedSpdxElement(); - if (relatedElement.isPresent() && - relatedElement.get().equals(o) && - relationship.getRelationshipType().equals(relationshipTypeFilter)) { - IModelStore modelStore = relationship.getModelStore(); - String documentUri = relationship.getDocumentUri(); - final IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - if (relationshipCollection.remove(relationship)) { - try { - if (createdRelationshipIds.contains(relationship.getId())) { - createdRelationshipIds.remove(relationship.getId()); - modelStore.delete(CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, relationship.getId(), modelStore)); - } - } catch (SpdxIdInUseException ex) { - // This is possible if the relationship is in use - // outside of the RelatedElementCollection - just ignore - // the exception - } - return true; - } else { - return false; - } - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting relationship properties - skipping removal of element",e); - } - } - } - } - return false; - } - - /* (non-Javadoc) - * @see java.util.Collection#containsAll(java.util.Collection) - */ - @Override - public boolean containsAll(Collection c) { - return toImmutableList().containsAll(c); - } - - /* (non-Javadoc) - * @see java.util.Collection#addAll(java.util.Collection) - */ - @Override - public boolean addAll(Collection c) { - boolean modified = false; - for (SpdxElement element:c) { - if (add(element)) { - modified = true; - } - } - return modified; - } - - /* (non-Javadoc) - * @see java.util.Collection#removeAll(java.util.Collection) - */ - @Override - public boolean removeAll(Collection c) { - boolean modified = false; - for (Object element:c) { - if (remove(element)) { - modified = true; - } - } - return modified; - } - - /* (non-Javadoc) - * @see java.util.Collection#retainAll(java.util.Collection) - */ - @Override - public boolean retainAll(Collection c) { - List existingElements = toImmutableList(); - boolean modified = false; - for (SpdxElement existingElement:existingElements) { - if (!c.contains(existingElement)) { - if (remove(existingElement)) { - modified = true; - } - } - } - return modified; - } - - /* (non-Javadoc) - * @see java.util.Collection#clear() - */ - @Override - public void clear() { - if (Objects.isNull(relationshipTypeFilter) && Objects.isNull(relatedElementTypeFilter)) { - relationshipCollection.clear(); - } else { - List existingElements = toImmutableList(); - for (SpdxElement existingElement:existingElements) { - remove(existingElement); - } - } - } - - /* (non-Javadoc) - * @see java.util.Collection#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof RelatedElementCollection)) { - return false; - } - RelatedElementCollection compare = (RelatedElementCollection)o; - return Objects.equals(this.owningElement, compare.getOwningElement()) && - Objects.equals(relationshipTypeFilter, compare.getRelationshipTypeFilter()) && - Objects.equals(relatedElementTypeFilter, compare.getRelatedElementTypeFilter()); - } - - /* (non-Javadoc) - * @see java.util.Collection#hashCode() - */ - @Override - public int hashCode() { - int retval = 33 ^ this.owningElement.hashCode(); - if (Objects.nonNull(relationshipTypeFilter)) { - retval = retval ^ this.relationshipTypeFilter.hashCode(); - } - if (Objects.nonNull(relatedElementTypeFilter)) { - retval = retval ^ this.relatedElementTypeFilter.hashCode(); - } - return retval; - } - - /** - * @return the relationshipCollection - */ - public ModelCollectionV2 getRelationshipCollection() { - return relationshipCollection; - } - - /** - * @return the relationshipTypeFilter - */ - public RelationshipType getRelationshipTypeFilter() { - return relationshipTypeFilter; - } - - /** - * @return the relatedElementTypeFilter - */ - public String getRelatedElementTypeFilter() { - return relatedElementTypeFilter; - } - - /** - * @return the owningElement - */ - public SpdxElement getOwningElement() { - return owningElement; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java b/src/main/java/org/spdx/library/model/compat/v2/Relationship.java deleted file mode 100644 index 9e40dfaf4..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/Relationship.java +++ /dev/null @@ -1,271 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.storage.IModelStore; - -/** - * A Relationship represents a relationship between two SpdxElements. - * - * @author Gary O'Neall - * - */ -public class Relationship extends ModelObject implements Comparable { - - /** - * @throws InvalidSPDXAnalysisException - */ - public Relationship() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public Relationship(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public Relationship(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_RELATIONSHIP; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - Optional relatedSpdxElement; - try { - relatedSpdxElement = getRelatedSpdxElement(); - if (!relatedSpdxElement.isPresent()) { - retval.add("Missing related SPDX element"); - } else { - retval.addAll(relatedSpdxElement.get().verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting related SPDX element for relationship: "+e.getMessage()); - } - try { - RelationshipType relationshipType = getRelationshipType(); - if (RelationshipType.MISSING.equals(relationshipType)) { - retval.add("Missing relationship type"); - } - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION) && - (RelationshipType.REQUIREMENT_DESCRIPTION_FOR.equals(relationshipType) || - RelationshipType.SPECIFICATION_FOR.equals(relationshipType))) { - retval.add(relationshipType.toString()+ - " is not supported in SPDX spec versions less than "+ - Version.TWO_POINT_THREE_VERSION); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting relationship type: "+e.getMessage()); - } - return retval; - } - - /** - * @return the relationshipType - * @throws InvalidSPDXAnalysisException - */ - public RelationshipType getRelationshipType() throws InvalidSPDXAnalysisException { - Optional retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE); - if (retval.isPresent()) { - if (!(retval.get() instanceof RelationshipType)) { - throw new SpdxInvalidTypeException("Invalid type for relationship type individual value: "+retval.get().toString()); - } - return (RelationshipType)retval.get(); - } else { - return RelationshipType.MISSING; - } - } - - /** - * Set the relationship type - * @param type - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Relationship setRelationshipType(RelationshipType type) throws InvalidSPDXAnalysisException { - if (RelationshipType.MISSING.equals(type)) { - throw new InvalidSPDXAnalysisException("Can not set required relationshipType to MISSING"); - } - if (strict && type == null) { - throw new InvalidSPDXAnalysisException("Can not set required relationshipType to null"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_RELATIONSHIP_TYPE, type); - return this; - } - - /** - * @return the comment - */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - } - - /** - * @param comment the comment to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Relationship setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - return this; - } - - /** - * @return the relatedSpdxElement - */ - public Optional getRelatedSpdxElement() throws InvalidSPDXAnalysisException { - return getElementPropertyValue(SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT); - } - - /** - * @param relatedSpdxElement the relatedSpdxElement to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public Relationship setRelatedSpdxElement(SpdxElement relatedSpdxElement) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_RELATED_SPDX_ELEMENT, relatedSpdxElement); - return this; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(Relationship o) { - RelationshipType myRelationshipType; - try { - myRelationshipType = getRelationshipType(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting my relationship type",e); - myRelationshipType = RelationshipType.MISSING; - } - RelationshipType oRelationshipType; - try { - oRelationshipType = o.getRelationshipType(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare relationship type",e); - oRelationshipType = RelationshipType.MISSING; - } - int retval = myRelationshipType.toString().compareTo(oRelationshipType.toString()); - if (retval != 0) { - return retval; - } - Optional compareRelatedElement; - try { - compareRelatedElement = o.getRelatedSpdxElement(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare related element",e); - compareRelatedElement = Optional.empty(); - } - Optional myRelatedElement; - try { - myRelatedElement = getRelatedSpdxElement(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare related element",e); - myRelatedElement = Optional.empty(); - } - if (!compareRelatedElement.isPresent()) { - if (myRelatedElement.isPresent()) { - return 1; - } - } - if (!myRelatedElement.isPresent()) { - return -1; - } - retval = myRelatedElement.get().getId().compareTo(compareRelatedElement.get().getId()); - if (retval != 0) { - return retval; - } - Optional compComment; - try { - compComment = o.getComment(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting my comment",e); - compComment = Optional.empty(); - } - Optional myComment; - try { - myComment = getComment(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare comment",e); - myComment = Optional.empty(); - } - if (!compComment.isPresent()) { - if (myComment.isPresent()) { - return 1; - } - } - if (!myComment.isPresent()) { - return -1; - } - return myComment.get().compareTo(compComment.get()); - } - - @Override - public String toString() { - try { - Optional relatedElement = getRelatedSpdxElement(); - StringBuilder sb = new StringBuilder(); - sb.append(getRelationshipType().toString()); - sb.append(" "); - if (relatedElement.isPresent()) { - sb.append(relatedElement.get().toString()); - } else { - sb.append("[Missing related element]"); - } - return sb.toString(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error in toString: ",e); - return "Error: "+e.getMessage(); - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java deleted file mode 100644 index aac1bbb73..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxConstantElement.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * Type of SpdxElement which is a constant unmodifiable element - * - * @author Gary O'Neall - * - */ -public abstract class SpdxConstantElement extends SpdxElement implements IndividualUriValue { - - private Collection annotations = Collections.unmodifiableCollection(new ArrayList<>()); - private Collection relationships = Collections.unmodifiableCollection(new ArrayList<>()); - - public SpdxConstantElement(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore where the model is stored - * @param documentUri Unique document URI - * @param objectUri ID for the constant element - * @throws InvalidSPDXAnalysisException - */ - public SpdxConstantElement(IModelStore modelStore, String documentUri, String id) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, null, true); - } - - @Override - protected List _verify(Set verifiedIds, String specVersion) { - return new ArrayList<>(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_NONE_ELEMENT; - } - - @Override - public Collection getAnnotations() throws InvalidSPDXAnalysisException { - return annotations; - } - - @Override - public SpdxElement setAnnotations(Collection annotations) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not set annotations for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public boolean addAnnotation(Annotation annotation) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not add annotations for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public boolean removeAnnotation(Annotation annotation) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not remove annotations for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public Collection getRelationships() throws InvalidSPDXAnalysisException { - return relationships; - } - - @Override - public SpdxElement setRelationships(Collection relationships) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not set relationships for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public boolean addRelationship(Relationship relationship) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not add relationships for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public boolean removeRelationship(Relationship relationship) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not remove relationships for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public void setComment(String comment) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not set comment for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public SpdxElement setName(String name) throws InvalidSPDXAnalysisException { - throw new RuntimeException("Can not set name for NONE and NOASSERTION SPDX Elements"); - } - - @Override - public boolean equals(Object comp) { - return SimpleUriValue.isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return SimpleUriValue.getIndividualUriValueHash(this); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java deleted file mode 100644 index ca7a44f61..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxCreatorInformation.java +++ /dev/null @@ -1,268 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.storage.IModelStore; - -/** - * @author gary - * - */ -public class SpdxCreatorInformation extends ModelObject { - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param create - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @return Creators Identify who (or what, in the case of a tool) created the SPDX file. If the SPDX file was created by an individual, indicate the person's name. - * @throws InvalidSPDXAnalysisException - */ - public Collection getCreators() throws InvalidSPDXAnalysisException { - return this.getStringCollection(SpdxConstantsCompatV2.PROP_CREATION_CREATOR); - } - - /** - * @return An optional field for creators of the SPDX file to provide the version of the SPDX License List used when the SPDX file was created. - * @throws InvalidSPDXAnalysisException - */ - public Optional getLicenseListVersion() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_LIST_VERSION); - } - - /** - * @param licenseListVersion An optional field for creators of the SPDX file to provide the version of the SPDX License List used when the SPDX file was created. - * @return this for building more optons - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation setLicenseListVersion(String licenseListVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_LIST_VERSION, licenseListVersion); - return this; - } - - - /** - * @return the comment - */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - } - - /** - * @param comment - * @return this for building more optons - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - return this; - } - - /** - * @return When the SPDX file was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard. - * @throws InvalidSPDXAnalysisException - */ - public String getCreated() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CREATION_CREATED); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("Missing created date"); - return ""; - } - } - - /** - * @param created When the SPDX file was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard. - * @return this for building more optons - * @throws InvalidSPDXAnalysisException - */ - public SpdxCreatorInformation setCreated(String created) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(created)) { - throw new InvalidSPDXAnalysisException("Can not set required created date to null"); - } - String verify = SpdxVerificationHelper.verifyDate(created); - if (Objects.nonNull(verify) && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_CREATION_CREATED, created); - return this; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_CREATION_INFO; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - boolean first = true; - try { - for (String creator:getCreators()) { - if (!first) { - sb.append(", "); - } - sb.append(creator); - first = false; - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting creators",e); - } - String created; - try { - created = getCreated(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting created",e); - created = ""; - } - sb.append("; Created on "); - sb.append(created); - Optional licenseListVerion; - try { - licenseListVerion = getLicenseListVersion(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting licenseListVerion",e); - licenseListVerion = Optional.empty(); - } - if (licenseListVerion.isPresent()) { - sb.append("; License List Version="); - sb.append(licenseListVerion.get()); - } - Optional comment; - try { - comment = getComment(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting comment",e); - comment = Optional.empty(); - } - if (comment.isPresent()) { - sb.append("; Comment: "); - sb.append(comment.get()); - } - return sb.toString(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - try { - int numCreators = 0; - for (String creator:getCreators()) { - String verify = SpdxVerificationHelper.verifyCreator(creator); - if (verify != null) { - retval.add(verify); - } - numCreators++; - } - if (numCreators == 0) { - retval.add("Missing required creators"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting creators: "+e.getMessage()); - } - try { - String creationDate = this.getCreated(); - if (creationDate.isEmpty()) { - retval.add("Missing required created date"); - } else { - String verify = SpdxVerificationHelper.verifyDate(creationDate); - if (verify != null) { - retval.add(verify); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting creation date: "+e.getMessage()); - } - // ListList Verions - try { - Optional licenseListVersion = this.getLicenseListVersion(); - if (licenseListVersion.isPresent()) { - String verify = verifyLicenseListVersion(licenseListVersion.get()); - if (verify != null) { - retval.add(verify); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting license list version: "+e.getMessage()); - } - return retval; - } - - /** - * @param version - * @return - */ - private @Nullable String verifyLicenseListVersion(String version) { - // Currently, there is no rules for the format of a version - if (Objects.isNull(version)) { - return null; - } else { - if (SpdxConstantsCompatV2.LICENSE_LIST_VERSION_PATTERN.matcher(version).matches()) { - return null; - } else { - return "License list version does not match the pattern M.N"; - } - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java deleted file mode 100644 index b6522c897..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxDocument.java +++ /dev/null @@ -1,348 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; - -/** - * An SpdxDocument is a summary of the contents, provenance, ownership and licensing - * analysis of a specific software package. - * This is, effectively, the top level of SPDX information. - * - * @author Gary O'Neall - */ -public class SpdxDocument extends SpdxElement { - - Collection documentDescribes; - Collection externalDocumentRefs; - Collection extractedLicenseInfos; - - /** - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for the document associated with this model - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create - if true, the object will be created in the store if it is not already present - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public SpdxDocument(IModelStore modelStore, String documentUri, ModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, SpdxConstantsCompatV2.SPDX_DOCUMENT_ID, copyManager, create); - documentDescribes = new RelatedElementCollection(this, RelationshipType.DESCRIBES, null); - externalDocumentRefs = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_SPDX_EXTERNAL_DOC_REF, ExternalDocumentRef.class); - extractedLicenseInfos = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_SPDX_EXTRACTED_LICENSES, ExtractedLicenseInfo.class); - } - - /** - * Obtains or creates an SPDX document using the default document store - * @param documentUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxDocument(String documentUri) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), documentUri, DefaultModelStore.getDefaultCopyManager(), true); - } - - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_DOCUMENT; - } - - @Override - protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstantsCompatV2.PROP_NAME; - } - - - /** - * @return collection of items described by this SPDX document - * @throws InvalidSPDXAnalysisException - */ - public Collection getDocumentDescribes() throws InvalidSPDXAnalysisException { - return documentDescribes; - } - - - /** - * clear and reset document describes to the paramater collection - * @param documentDescribes collection of items described by this SPDX document - * @return this to chain setters - */ - public SpdxDocument setDocumentDescribes(List documentDescribes) { - Objects.requireNonNull(documentDescribes, "Document describes can not be null"); - this.documentDescribes.clear(); - this.documentDescribes.addAll(documentDescribes); - return this; - } - - /** - * @return the creationInfo, null if no creationInfo in the SPDX document - * @throws InvalidSPDXAnalysisException - */ - public @Nullable SpdxCreatorInformation getCreationInfo() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_CREATION_INFO); - if (retval.isPresent()) { - if (!(retval.get() instanceof SpdxCreatorInformation)) { - throw new SpdxInvalidTypeException("Invalid tpe for CreationInfo: "+retval.get().getClass().toString()); - } - return (SpdxCreatorInformation)retval.get(); - } else { - logger.warn("No creation info for document "+getName()); - return null; - } - } - - /** - * @param creationInfo the creationInfo to set - */ - public void setCreationInfo(SpdxCreatorInformation creationInfo) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(creationInfo)) { - throw new InvalidSPDXAnalysisException("Can not set required creation info to null"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_CREATION_INFO, creationInfo); - } - - /** - * @return the dataLicense - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo getDataLicense() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_DATA_LICENSE); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("No data license for "+getName()); - return new SpdxNoneLicense(); - } - } - - /** - * @param dataLicense the dataLicense to set - * @throws InvalidSPDXAnalysisException - */ - public void setDataLicense(AnyLicenseInfo dataLicense) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(dataLicense)) { - throw new InvalidSPDXAnalysisException("Can not set required data license to null"); - } - if (!(dataLicense instanceof SpdxListedLicense)) { - throw new InvalidSPDXAnalysisException("Invalid license type for data license - must be an SPDX Listed license"); - } else if (!((SpdxListedLicense)dataLicense).getLicenseId().equals(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)) { - throw new InvalidSPDXAnalysisException("Incorrect data license. Must be "+SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_DATA_LICENSE, dataLicense); - } - - /** - * @return the externalDocumentRefs - * @throws InvalidSPDXAnalysisException - */ - public Collection getExternalDocumentRefs() throws InvalidSPDXAnalysisException { - return externalDocumentRefs; - } - - /** - * @return the extractedLicenseInfos - * @throws InvalidSPDXAnalysisException - */ - public Collection getExtractedLicenseInfos() throws InvalidSPDXAnalysisException { - return this.extractedLicenseInfos; - } - - /** - * Add a license info to the collection of extracted license infos - * @param licenseInfo - * @return - */ - public boolean addExtractedLicenseInfos(ExtractedLicenseInfo licenseInfo) { - Objects.requireNonNull(licenseInfo, "License info can not be null"); - return this.extractedLicenseInfos.add(licenseInfo); - } - - /** - * Clear the extractedLicenseInfos and add all elements from extractedLicenseInfos - * @param extractedLicenseInfos - * @return this to enable chaining of sets - */ - public SpdxDocument setExtractedLicenseInfos(List extractedLicenseInfos) { - Objects.requireNonNull(extractedLicenseInfos, "Extracted license infos can not be null"); - this.extractedLicenseInfos.clear(); - this.extractedLicenseInfos.addAll(extractedLicenseInfos); - return this; - } - - /** - * @return the specVersion - */ - public String getSpecVersion() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_SPEC_VERSION); - if (retval.isPresent()) { - return retval.get(); - } else { - return ""; - } - } - - /** - * @param specVersion the specVersion to set - */ - public void setSpecVersion(String specVersion) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(specVersion)) { - throw new InvalidSPDXAnalysisException("Can not set required spec version to null"); - } - String verify = Version.verifySpdxVersion(specVersion); - if (Objects.nonNull(verify) && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_SPDX_SPEC_VERSION, specVersion); - } - - - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String verifySpecVersion) { - List retval = new ArrayList<>(); - String specVersion; - try { - specVersion = getSpecVersion(); - if (specVersion.isEmpty()) { - retval.add("Missing required SPDX version"); - specVersion = verifySpecVersion; - } else { - String verify = Version.verifySpdxVersion(specVersion); - if (verify != null) { - retval.add(verify); - specVersion = verifySpecVersion; - } - } - } catch (InvalidSPDXAnalysisException e2) { - retval.add("Error getting spec version"); - specVersion = verifySpecVersion; - } - retval.addAll(super._verify(verifiedIds, specVersion)); - - // name - try { - Optional name = getName(); - if (!name.isPresent() || name.get().isEmpty()) { - retval.add("Missing required document name"); - } - } catch (InvalidSPDXAnalysisException e1) { - retval.add("Error getting document name"); - } - - // creationInfo - try { - SpdxCreatorInformation creator = this.getCreationInfo(); - if (Objects.isNull(creator)) { - retval.add("Missing required Creator"); - } else { - retval.addAll(creator.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting creator information: "+e.getMessage()); - } - // Extracted licensine infos - try { - for (ExtractedLicenseInfo licInfo:getExtractedLicenseInfos()) { - retval.addAll(licInfo.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting extracted licensing info: "+e.getMessage()); - } - // data license - try { - AnyLicenseInfo dataLicense = this.getDataLicense(); - if (dataLicense.toString().equals("NONE")) { - retval.add("Missing required data license"); - } else if (!(dataLicense instanceof SpdxListedLicense)) { - retval.add("Invalid license type for data license - must be an SPDX Listed license"); - } else if (!((SpdxListedLicense)dataLicense).getLicenseId().equals(SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID)) { - retval.add("Incorrect data license for SPDX version 1.0 document - found "+ - ((SpdxListedLicense)dataLicense).getLicenseId()+", expected "+ - SpdxConstantsCompatV2.SPDX_DATA_LICENSE_ID); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting data license: "+e.getMessage()); - } - // External document references - try { - for (ExternalDocumentRef externalRef:getExternalDocumentRefs()) { - retval.addAll(externalRef.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting external document references: "+e.getMessage()); - } - // documentDescribes relationships - try { - if (getDocumentDescribes().size() == 0) { - retval.add("Document must have at least one relationship of type DOCUMENT_DESCRIBES"); - // Note - relationships are verified in the superclass. This should also recursively - // verify any other important objects. - } else { - for (SpdxElement element:getDocumentDescribes()) { - retval.addAll(element.verify(verifiedIds, specVersion)); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting document describes: "+e.getMessage()); - } - //TODO: Figure out what to do with checking any "dangling items" not linked to the describes by - return retval; - } - - /** - * Clear the externalDocumentRefs and add all elements from externalDocumentRefs - * @param externalDocumentRefs - * @return this to enable chaining of sets - */ - public SpdxDocument setExternalDocumentRefs(Collection externalDocumentRefs) { - Objects.requireNonNull(externalDocumentRefs, "External document refs can not be null"); - this.externalDocumentRefs.clear(); - this.externalDocumentRefs.addAll(externalDocumentRefs); - return this; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java deleted file mode 100644 index 8b628119a..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxElement.java +++ /dev/null @@ -1,288 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.PropertyDescriptor; - -/** - * An SpdxElement is any thing described in SPDX, either a document or an SpdxItem. - * SpdxElements can be related to other SpdxElements. - * - * If a subproperty is used for the name property name, getNamePropertyName should be overridden. - * - * @author Gary O'Neall - */ -public abstract class SpdxElement extends ModelObject { - - static final Logger logger = LoggerFactory.getLogger(SpdxElement.class); - - private Collection annotations = null; - private Collection relationships = null; - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxElement() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); - - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxElement(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param create - * @throws InvalidSPDXAnalysisException - */ - public SpdxElement(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - // we can not create the annotations and relationships until referenced since ExternalSpdxElement can not create them - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedElementIds, String specVersion) { - List retval = new ArrayList<>(); - if (verifiedElementIds.contains(this.getId())) { - return retval; - } - verifiedElementIds.add(this.getId()); - // verify ID format - IdType idType = this.getModelStore().getIdType(this.getId()); - if (IdType.SpdxId.equals(idType)) { - if (!SpdxVerificationHelper.verifySpdxId(this.getId())) { - retval.add("Invalid SPDX ID: "+this.getId()+". Must match the pattern "+SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PATTERN); - } - } else if (!IdType.Anonymous.equals(idType)) { - retval.add("Invalid ID for SPDX Element: "+this.getId()+". Must be either a valid SPDX ID or Anonymous."); - } - try { - retval.addAll(verifyCollection(getAnnotations(), "Annotation Error: ", verifiedElementIds, specVersion)); - } catch (InvalidSPDXAnalysisException e1) { - retval.add("Error getting annotation: "+e1.getMessage()); - } - try { - retval.addAll(verifyCollection(getRelationships(), "Relationship error: ", verifiedElementIds, specVersion)); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting relationships: "+e.getMessage()); - } - addNameToWarnings(retval); - return retval; - } - - @SuppressWarnings("unchecked") - private synchronized void checkCreateAnnotations() throws InvalidSPDXAnalysisException { - if (Objects.isNull(this.annotations)) { - this.annotations = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_ANNOTATION, Annotation.class); - } - } - - @SuppressWarnings("unchecked") - private synchronized void checkCreateRelationships() throws InvalidSPDXAnalysisException { - if (Objects.isNull(this.relationships)) { - this.relationships = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_RELATIONSHIP, Relationship.class); - } - } - - /** - * Add the name of the element to all strings in the list - * @return the same last after being modified (Note: a new list is not created - this modifies the warnings list) - * @param warnings - */ - protected List addNameToWarnings(List warnings) { - if (warnings == null) { - return new ArrayList<>(); - } - if (warnings.isEmpty()) { - return warnings; - } - String localName = "[UNKNOWN]"; - try { - Optional name = getName(); - if (name.isPresent()) { - localName = name.get(); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting name",e); - } - for (int i = 0; i < warnings.size(); i++) { - warnings.set(i, warnings.get(i)+" in "+localName); - } - return warnings; - } - - /** - * @return Annotations - * @throws InvalidSPDXAnalysisException - */ - public Collection getAnnotations() throws InvalidSPDXAnalysisException { - checkCreateAnnotations(); - return annotations; - } - - /** - * Clears and resets the annotations collection to the parameter - * @param annotations - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxElement setAnnotations(Collection annotations) throws InvalidSPDXAnalysisException { - checkCreateAnnotations(); - Objects.requireNonNull(annotations, "Annotations can not be null"); - this.annotations.clear(); - this.annotations.addAll(annotations); - return this; - } - - /** - * Add an annotation - * @param annotation - * @return - * @throws InvalidSPDXAnalysisException - */ - public boolean addAnnotation(Annotation annotation) throws InvalidSPDXAnalysisException { - checkCreateAnnotations(); - return annotations.add(annotation); - } - - /** - * Remove an annotation - * @param annotation - * @return - * @throws InvalidSPDXAnalysisException - */ - public boolean removeAnnotation(Annotation annotation) throws InvalidSPDXAnalysisException { - checkCreateAnnotations(); - return annotations.remove(annotation); - } - - /** - * @return Relationships - * @throws InvalidSPDXAnalysisException - */ - public Collection getRelationships() throws InvalidSPDXAnalysisException { - checkCreateRelationships(); - return relationships; - } - - /** - * clear and reset the relationships to the paramater relationship - * @param relationships - * @return this to chain sets - * @throws InvalidSPDXAnalysisException - */ - public SpdxElement setRelationships(Collection relationships) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(relationships, "Relationships can not be null"); - checkCreateRelationships(); - this.relationships.clear(); - this.relationships.addAll(relationships); - return this; - } - - /** - * Add a relationship - * @param relationship - * @return - * @throws InvalidSPDXAnalysisException - */ - public boolean addRelationship(Relationship relationship) throws InvalidSPDXAnalysisException { - checkCreateRelationships(); - return relationships.add(relationship); - } - - /** - * Remove a relationship - * @param relationship - * @return - * @throws InvalidSPDXAnalysisException - */ - public boolean removeRelationship(Relationship relationship) throws InvalidSPDXAnalysisException { - checkCreateRelationships(); - return relationships.remove(relationship); - } - - /** - * @return the comment - * @throws InvalidSPDXAnalysisException - */ - public Optional getComment() throws InvalidSPDXAnalysisException { - return this.getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - } - - /** - * Sets the comment - * @param comment - * @throws InvalidSPDXAnalysisException - */ - public void setComment(String comment) throws InvalidSPDXAnalysisException { - this.setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - } - - - /** - * @return the property name used for the Name property. Override this function if using a subproperty of SPDX Name - */ - protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstantsCompatV2.PROP_NAME; - } - - /** - * @return the name - */ - public Optional getName() throws InvalidSPDXAnalysisException { - return this.getStringPropertyValue(getNamePropertyDescriptor()); - } - - /** - * Set the name - * @param name - * @return this so that you can chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxElement setName(String name) throws InvalidSPDXAnalysisException { - this.setPropertyValue(getNamePropertyDescriptor(), name); - return this; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java deleted file mode 100644 index fdda006aa..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxFile.java +++ /dev/null @@ -1,544 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.PropertyDescriptor; - -/** - * A File represents a named sequence of information - * that is contained in a software package. - * @author Gary O'Neall - */ -public class SpdxFile extends SpdxItem implements Comparable { - - Collection fileTypes; - Collection checksums; - private Collection fileContributors; - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxFile() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxFile(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param create - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public SpdxFile(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - fileTypes = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_FILE_TYPE, FileType.class); - checksums = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_FILE_CHECKSUM, Checksum.class); - fileContributors = this.getStringCollection(SpdxConstantsCompatV2.PROP_FILE_CONTRIBUTOR); - } - - protected SpdxFile(SpdxFileBuilder spdxFileBuilder) throws InvalidSPDXAnalysisException { - this(spdxFileBuilder.modelStore, spdxFileBuilder.documentUri, spdxFileBuilder.id, - spdxFileBuilder.copyManager, true); - setCopyrightText(spdxFileBuilder.copyrightText); - setName(spdxFileBuilder.name); - setLicenseConcluded(spdxFileBuilder.concludedLicense); - addChecksum(spdxFileBuilder.sha1); - - // optional parameters - SpdxElement - getAnnotations().addAll(spdxFileBuilder.annotations); - getRelationships().addAll(spdxFileBuilder.relationships); - setComment(spdxFileBuilder.comment); - - // optional parameters - SpdxItem - setLicenseComments(spdxFileBuilder.licenseComments); - getAttributionText().addAll(spdxFileBuilder.attributionText); - if (Objects.nonNull(spdxFileBuilder.licenseInfosFromFile)) { - getLicenseInfoFromFiles().addAll(spdxFileBuilder.licenseInfosFromFile); - } - // optional parameters - SpdxFile - Iterator iter = spdxFileBuilder.checksums.iterator(); - while (iter.hasNext()) { - Checksum cksum = iter.next(); - if (!cksum.equals(spdxFileBuilder.sha1)) { - getChecksums().add(cksum); - } - } - getFileContributors().addAll(spdxFileBuilder.fileContributors); - getFileTypes().addAll(spdxFileBuilder.fileTypes); - setNoticeText(spdxFileBuilder.noticeText); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_FILE; - } - - /** - * @return the Sha1 checksum value for this file, or a blank string if no - * sha1 checksum has been set - */ - public String getSha1() throws InvalidSPDXAnalysisException { - for (Checksum checksum:checksums) { - if (checksum.getAlgorithm().equals(ChecksumAlgorithm.SHA1)) { - if (!checksum.getValue().isEmpty()) { - return checksum.getValue(); - } - } - } - return ""; - } - - @Override - public SpdxFile setCopyrightText(@Nullable String copyrightText) throws InvalidSPDXAnalysisException { - super.setCopyrightText(copyrightText); - return this; - } - - @Override - public SpdxFile setName(@Nullable String name) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(name) || name.isEmpty()) { - throw new InvalidSPDXAnalysisException("Can not set required name to null or empty"); - } - } - super.setName(name); - return this; - } - - @Override - public SpdxFile setLicenseConcluded(@Nullable AnyLicenseInfo license) throws InvalidSPDXAnalysisException { - super.setLicenseConcluded(license); - return this; - } - - @Override - public SpdxFile setLicenseComments(String licenseComments) throws InvalidSPDXAnalysisException { - super.setLicenseComments(licenseComments); - return this; - } - - @Override - protected PropertyDescriptor getLicenseInfoFromFilesPropertyName() { - return SpdxConstantsCompatV2.PROP_FILE_SEEN_LICENSE; - } - - @Override - protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstantsCompatV2.PROP_FILE_NAME; - } - - /** - * @return File types for the file - * @throws InvalidSPDXAnalysisException - */ - public Collection getFileTypes() throws InvalidSPDXAnalysisException { - return fileTypes; - } - - /** - * Add a file type to this file - * @param fileType - * @return true if the list was modified - * @throws InvalidSPDXAnalysisException - */ - public boolean addFileType(FileType fileType) throws InvalidSPDXAnalysisException { - return fileTypes.add(fileType); - } - - /** - * @return the checksums - */ - public Collection getChecksums() { - return checksums; - } - - /** - * Add a checksum - * @param checksum - * @return true if the list was modified - * @throws InvalidSPDXAnalysisException - */ - public boolean addChecksum(Checksum checksum) throws InvalidSPDXAnalysisException { - return checksums.add(checksum); - } - - /** - * @return the fileContributors - */ - public Collection getFileContributors() { - return fileContributors; - } - - /** - * Add a file contributor to the file contributors collection - * @param contributor - * @return - */ - public boolean addFileContributor(String contributor) { - if (Objects.nonNull(contributor)) { - return fileContributors.add(contributor); - } else { - return false; - } - } - - /** - * @return the noticeText - */ - public Optional getNoticeText() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_FILE_NOTICE); - } - - /** - * @param noticeText the noticeText to set - * @return this so you can chain setters - */ - public SpdxFile setNoticeText(@Nullable String noticeText) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_FILE_NOTICE, noticeText); - return this; - } - - /** - * @return file dependencies - note: this is deprecated, use relationships between files rather than this field - * @throws InvalidSPDXAnalysisException - */ - @Deprecated - @SuppressWarnings("unchecked") - public Collection getFileDependency() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_FILE_FILE_DEPENDENCY, SpdxFile.class); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - String fileName = "UNKNOWN"; - try { - Optional myName = this.getName(); - if (myName.isPresent()) { - fileName = myName.get(); - } else { - retval.add("Missing required file name"); - } - } catch(InvalidSPDXAnalysisException e) { - retval.add("Error getting file name"); - } - for (Checksum checksum:checksums) { - retval.addAll(addNameToWarnings(checksum.verify(verifiedIds, specVersion))); - } - String sha1; - try { - sha1 = getSha1(); - if (sha1 == null || sha1.isEmpty()) { - retval.add("Missing required SHA1 hashcode value for "+fileName); - } else { - String warning = SpdxVerificationHelper.verifyChecksumString(sha1, ChecksumAlgorithm.SHA1, specVersion); - if (warning != null) { - retval.add(warning + " for file "+fileName); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting sha1"); - } - return retval; - } - - @Override - public int compareTo(SpdxFile o) { - String name = ""; - try { - Optional myName = getName(); - if (myName.isPresent()) { - name = myName.get(); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting my name on compare"); - } - String compName = ""; - try { - Optional compareName = o.getName(); - if (compareName.isPresent()) { - compName = compareName.get(); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare name on compare"); - } - return name.compareTo(compName); - } - - public static class SpdxFileBuilder { - // required fields - Model Object - IModelStore modelStore; - String documentUri; - String id; - ModelCopyManager copyManager; - - // required fields - SpdxElement - String name; - - // required fields - SpdxItem - AnyLicenseInfo concludedLicense; - String copyrightText; - - // required fields - SpdxFile - Checksum sha1; - - // optional fields - SpdxElement - Collection annotations = new ArrayList(); - Collection relationships = new ArrayList(); - String comment = null; - - // optional fields - SpdxItem - String licenseComments = null; - Collection attributionText = new ArrayList(); - Collection licenseInfosFromFile; - - // optional fields - SpdxFile - Collection checksums = new ArrayList(); - Collection fileContributors = new ArrayList(); - Collection fileTypes = new ArrayList(); - String noticeText = null; - - /** - * Build a file with the required parameters - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param objectUri ID for this object - must be unique within the SPDX document - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param name - File name - * @param concludedLicense license concluded - * @param licenseInfosFromFile collection of seen licenses - * @param copyrightText Copyright text - * @param sha1 - Sha1 checksum value - */ - public SpdxFileBuilder(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, String name, - AnyLicenseInfo concludedLicense, - @Nullable Collection licenseInfosFromFile, - String copyrightText, Checksum sha1) { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(name, "Name can not be null"); - Objects.requireNonNull(sha1, "SHA1 can not be null"); - this.modelStore = modelStore; - this.documentUri = documentUri; - this.id = id; - this.name = name; - this.concludedLicense = concludedLicense; - this.licenseInfosFromFile = licenseInfosFromFile; - this.copyrightText = copyrightText; - this.sha1 = sha1; - this.copyManager = copyManager; - } - - /** - * @param annotations Annotations - * @return this to continue the build - */ - public SpdxFileBuilder setAnnotations(Collection annotations) { - Objects.requireNonNull(annotations, "Annotations can not be null"); - this.annotations = annotations; - return this; - } - - /** - * @param annotation Annotation to add - * @return this to continue the build - */ - public SpdxFileBuilder addAnnotation(Annotation annotation) { - Objects.requireNonNull(annotation, "Annotations can not be null"); - this.annotations.add(annotation); - return this; - } - - /** - * @param relationships Relationships - * @return this to continue the build - */ - public SpdxFileBuilder setRelationship(Collection relationships) { - Objects.requireNonNull(relationships, "Relationships can not be null"); - this.relationships = relationships; - return this; - } - - /** - * @param relationship Relationship to add - * @return this to continue the build - */ - public SpdxFileBuilder addRelationship(Relationship relationship) { - Objects.requireNonNull(relationship, "Relationships can not be null"); - this.relationships.add(relationship); - return this; - } - - /** - * @param comment Comment - * @return this to continue the build - */ - public SpdxFileBuilder setComment(@Nullable String comment) { - this.comment = comment; - return this; - } - /** - * @param licenseComments - * @return this to continue the build - */ - public SpdxFileBuilder setLicenseComments(@Nullable String licenseComments) { - this.licenseComments = licenseComments; - return this; - } - - /** - * @param checksums Checksum - * @return this to continue the build - */ - public SpdxFileBuilder setChecksums(Collection checksums) { - Objects.requireNonNull(checksums, "Checksums can not be null"); - this.checksums = checksums; - return this; - } - - /** - * @param checksum Checksum to add - * @return this to continue the build - */ - public SpdxFileBuilder addChecksum(Checksum checksum) { - Objects.requireNonNull(checksum, "Checksum can not be null"); - this.checksums.add(checksum); - return this; - } - - /** - * @param fileContributors Contributors to the file - * @return this to continue the build - */ - public SpdxFileBuilder setFileContributors(Collection fileContributors) { - Objects.requireNonNull(fileContributors, "File contributors can not be null"); - this.fileContributors = fileContributors; - return this; - } - - /** - * @param fileContributor File contributor to add - * @return this to continue the build - */ - public SpdxFileBuilder addFileContributor(String fileContributor) { - Objects.requireNonNull(fileContributor, "File contributor can not be null"); - this.fileContributors.add(fileContributor); - return this; - } - - /** - * @param fileTypes file types - * @return this to continue the build - */ - public SpdxFileBuilder setFileTypes(Collection fileTypes) { - Objects.requireNonNull(fileTypes, "File types can not be null"); - this.fileTypes = fileTypes; - return this; - } - - /** - * @param fileType file type to add - * @return this to continue the build - */ - public SpdxFileBuilder addFileType(FileType fileType) { - Objects.requireNonNull(fileType, "file type can not be null"); - this.fileTypes.add(fileType); - return this; - } - - /** - * @param noticeText Notice text found in the file - * @return this to continue the build - */ - public SpdxFileBuilder setNoticeText(@Nullable String noticeText) { - this.noticeText = noticeText; - return this; - } - - /** - * @param attributionText Attribution text for the file - * @return this to continue the build - */ - public SpdxFileBuilder setAttributionText(Collection attributionText) { - Objects.requireNonNull(attributionText, "Attribution text collection can not be null"); - this.attributionText = attributionText; - return this; - } - - /** - * Add attribution to the attribution text collection - * @param attribution - * @return - */ - public SpdxFileBuilder addAttributionText(String attribution) { - Objects.requireNonNull(attribution, "Attribution text can not be null"); - this.attributionText.add(attribution); - return this; - } - - public SpdxFile build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new SpdxFile(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java deleted file mode 100644 index bfc3a18e4..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxItem.java +++ /dev/null @@ -1,206 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; - -/** - * An SpdxItem is a potentially copyrightable work. - * @author Gary O'Neall - */ -public abstract class SpdxItem extends SpdxElement { - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxItem() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxItem(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public SpdxItem(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @return Property name for licenseInfoFromFiles. Override if using a subproperty of "licenseDeclared". - */ - protected PropertyDescriptor getLicenseInfoFromFilesPropertyName() { - return SpdxConstantsCompatV2.PROP_PACKAGE_LICENSE_INFO_FROM_FILES; - } - - /** - * @return the licenseConcluded - */ - public AnyLicenseInfo getLicenseConcluded() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_CONCLUDED); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("No license concluded stored, returning NOASSERTION"); - return new SpdxNoAssertionLicense(getModelStore(), getDocumentUri()); - } - } - - /** - * Set the licenseConcluded - * @param license - * @return this so you can chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxItem setLicenseConcluded(@Nullable AnyLicenseInfo license) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_CONCLUDED, license); - return this; - } - - @SuppressWarnings("unchecked") - public Collection getLicenseInfoFromFiles() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(getLicenseInfoFromFilesPropertyName(), AnyLicenseInfo.class); - } - - /** - * @return the copyrightText, empty string if no copyright was set - */ - public String getCopyrightText() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_COPYRIGHT_TEXT); - if (retval.isPresent()) { - return retval.get(); - } else { - return ""; - } - } - - /** - * @param copyrightText the copyrightText to set - * @return myself - so you can chain setters - */ - public SpdxItem setCopyrightText(@Nullable String copyrightText) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_COPYRIGHT_TEXT, copyrightText); - return this; - } - - /** - * @return attribution text collection - * @throws InvalidSPDXAnalysisException - */ - public Collection getAttributionText() throws InvalidSPDXAnalysisException { - return getStringCollection(SpdxConstantsCompatV2.PROP_ATTRIBUTION_TEXT); - } - - @Override - public SpdxItem setName(String name) throws InvalidSPDXAnalysisException { - super.setName(name); - return this; - } - - /** - * @return the licenseComment - */ - public Optional getLicenseComments() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_LIC_COMMENTS); - } - - /** - * @param licenseComments the licenseComment to set - * @return this so you chan chain setters - */ - public SpdxItem setLicenseComments(String licenseComments) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_COMMENTS, licenseComments); - return this; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - String name = "UNKNOWN"; - Optional myName; - try { - myName = this.getName(); - if (myName.isPresent()) { - name = myName.get(); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting name: "+e.getMessage()); - } - - Optional concluded; - try { - concluded = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_CONCLUDED); - if (!concluded.isPresent()) { - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Missing required concluded license for "+name); - } - } else { - retval.addAll(concluded.get().verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting license concluded: "+e.getMessage()); - } - String copyrightText; - try { - copyrightText = getCopyrightText(); - if (copyrightText.isEmpty() && Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Missing required copyright text for "+name); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting comment: "+e.getMessage()); - } - - try { - this.verifyCollection(getLicenseInfoFromFiles(), "SPDX Item "+name+" ", verifiedIds, specVersion); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting license information from files: "+e.getMessage()); - } - addNameToWarnings(retval); - return retval; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java deleted file mode 100644 index 9f00dddc8..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxNoAssertionElement.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * This SPDX element represents no assertion as to an actual SPDX element. - * - * This element should only be used on the right hand side of relationships to represent no assertion - * as to what element the subject is actually related to. - * - * This element has no properties and a fixed ID of "NOASSERTION". - * - * @author Gary O'Neall - * - */ -public class SpdxNoAssertionElement extends SpdxConstantElement { - - public static final String NOASSERTION_ELEMENT_ID = "NOASSERTION"; - - /** - * Create a None element with default model store and document URI - * @throws InvalidSPDXAnalysisException - */ - public SpdxNoAssertionElement() throws InvalidSPDXAnalysisException { - super(NOASSERTION_ELEMENT_ID); - } - - /** - * @param modelStore where the model is stored - * @param documentUri Unique document URI - * @throws InvalidSPDXAnalysisException - */ - public SpdxNoAssertionElement(IModelStore modelStore, String documentUri) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, NOASSERTION_ELEMENT_ID); - } - - @Override - public String toString() { - return SpdxConstantsCompatV2.NOASSERTION_VALUE; - } - - @Override - public Optional getName() throws InvalidSPDXAnalysisException { - return Optional.of(NOASSERTION_ELEMENT_ID); - } - - @Override - public Optional getComment() throws InvalidSPDXAnalysisException { - return Optional.of("This is a NOASSERTION element which indicate no assertion is made whether an element is related to this element"); - } - - @Override - public String getIndividualURI() { - return SpdxConstantsCompatV2.URI_VALUE_NOASSERTION; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java deleted file mode 100644 index cb9536b59..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxNoneElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * This SPDX element represents no SPDX element at all. - * - * This element should only be used on the right hand side of relationships to represent no SPDX element - * is related to the subject. - * - * This element has no properties and a fixed ID of "NONE". - * - * @author Gary O'Neall - * - */ -public class SpdxNoneElement extends SpdxConstantElement { - - public static final String NONE_ELEMENT_ID = "NONE"; - - /** - * Create a None element with default model store and document URI - * @throws InvalidSPDXAnalysisException - */ - public SpdxNoneElement() throws InvalidSPDXAnalysisException { - super(NONE_ELEMENT_ID); - } - - /** - * @param modelStore where the model is stored - * @param documentUri Unique document URI - * @throws InvalidSPDXAnalysisException - */ - public SpdxNoneElement(IModelStore modelStore, String documentUri) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, NONE_ELEMENT_ID); - } - - @Override - public String toString() { - return SpdxConstantsCompatV2.NONE_VALUE; - } - - @Override - public Optional getName() throws InvalidSPDXAnalysisException { - return Optional.of("NONE"); - } - - @Override - public Optional getComment() throws InvalidSPDXAnalysisException { - return Optional.of("This is a NONE element which represents that NO element is related"); - } - - @Override - public String getIndividualURI() { - return SpdxConstantsCompatV2.URI_VALUE_NONE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java deleted file mode 100644 index 1e73523fa..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackage.java +++ /dev/null @@ -1,1221 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.Version; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.Purpose; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.OrLaterOperator; -import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; -import org.spdx.library.model.compat.v2.license.WithExceptionOperator; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.PropertyDescriptor; - -/** - * A Package represents a collection of software files that are - * delivered as a single functional component. - * @author Gary O'Neall - * - */ -public class SpdxPackage extends SpdxItem implements Comparable { - Collection files; - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage() throws InvalidSPDXAnalysisException { - super(); - files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstantsCompatV2.CLASS_SPDX_FILE); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstantsCompatV2.CLASS_SPDX_FILE); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage(String id) throws InvalidSPDXAnalysisException { - super(id); - files = new RelatedElementCollection(this, RelationshipType.CONTAINS, SpdxConstantsCompatV2.CLASS_SPDX_FILE); - } - - protected SpdxPackage(SpdxPackageBuilder spdxPackageBuilder) throws InvalidSPDXAnalysisException { - this(spdxPackageBuilder.modelStore, spdxPackageBuilder.documentUri, spdxPackageBuilder.id, - spdxPackageBuilder.copyManager, true); - setFilesAnalyzed(spdxPackageBuilder.filesAnalyzed); // this must be done first since it impact validation - setCopyrightText(spdxPackageBuilder.copyrightText); - setName(spdxPackageBuilder.name); - setLicenseConcluded(spdxPackageBuilder.concludedLicense); - setLicenseDeclared(spdxPackageBuilder.licenseDeclared); - - // optional parameters - SpdxElement - getAnnotations().addAll(spdxPackageBuilder.annotations); - getRelationships().addAll(spdxPackageBuilder.relationships); - setComment(spdxPackageBuilder.comment); - - // optional parameters - SpdxItem - setLicenseComments(spdxPackageBuilder.licenseComments); - getLicenseInfoFromFiles().addAll(spdxPackageBuilder.licenseInfosFromFile); - getAttributionText().addAll(spdxPackageBuilder.attributionText); - - // optional parameters - SpdxPackage - getChecksums().addAll(spdxPackageBuilder.checksums); - setDescription(spdxPackageBuilder.description); - setDownloadLocation(spdxPackageBuilder.downloadLocation); - getExternalRefs().addAll(spdxPackageBuilder.externalRefs); - getFiles().addAll(spdxPackageBuilder.files); - setHomepage(spdxPackageBuilder.homepage); - setOriginator(spdxPackageBuilder.originator); - setPackageFileName(spdxPackageBuilder.pacakgeFileName); - setPackageVerificationCode(spdxPackageBuilder.packageVerificationCode); - setSourceInfo(spdxPackageBuilder.sourceInfo); - setSummary(spdxPackageBuilder.summary); - setSupplier(spdxPackageBuilder.supplier); - setVersionInfo(spdxPackageBuilder.versionInfo); - setPrimaryPurpose(spdxPackageBuilder.primaryPurpose); - setBuiltDate(spdxPackageBuilder.builtDate); - setValidUntilDate(spdxPackageBuilder.validUntilDate); - setReleaseDate(spdxPackageBuilder.releaseDate); - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_PACKAGE; - } - - @Override - protected PropertyDescriptor getNamePropertyDescriptor() { - return SpdxConstantsCompatV2.PROP_NAME; - } - - /** - * @return true unless the filesAnalyzed property is present and set to false (default is true) - * @throws InvalidSPDXAnalysisException - */ - public boolean isFilesAnalyzed() throws InvalidSPDXAnalysisException { - Optional filesAnalyzed = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED); - if (!filesAnalyzed.isPresent()) { - return true; - } else { - return filesAnalyzed.get(); - } - } - - /** - * Set files Analyzed for the package - * @param filesAnalyzed - * @return this to build additional options - */ - public SpdxPackage setFilesAnalyzed(@Nullable Boolean filesAnalyzed) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILES_ANALYZED, filesAnalyzed); - return this; - } - - /** - * @return This field provides a place for recording the actual date the package was built. - * @throws InvalidSPDXAnalysisException - */ - public Optional getBuiltDate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_BUILT_DATE); - } - - /** - * @param builtDate This field provides a place for recording the actual date the package was built. - * @throws InvalidSPDXAnalysisException - */ - public void setBuiltDate(String builtDate) throws InvalidSPDXAnalysisException { - if (strict && Objects.nonNull(builtDate) && Objects.nonNull(SpdxVerificationHelper.verifyDate(builtDate))) { - throw new InvalidSPDXAnalysisException("Invalid built date"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_BUILT_DATE, builtDate); - } - - /** - * @return This field provides a place for recording the date the package was released. - * @throws InvalidSPDXAnalysisException - */ - public Optional getReleaseDate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_RELEASE_DATE); - } - - /** - * @param releaseDate This field provides a place for recording the date the package was released. - * @throws InvalidSPDXAnalysisException - */ - public void setReleaseDate(String releaseDate) throws InvalidSPDXAnalysisException { - if (strict && Objects.nonNull(releaseDate) && Objects.nonNull(SpdxVerificationHelper.verifyDate(releaseDate))) { - throw new InvalidSPDXAnalysisException("Invalid release date"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_RELEASE_DATE, releaseDate); - } - - /** - * @return This field provides a place for recording the end of the support period for a package from the supplier. - * @throws InvalidSPDXAnalysisException - */ - public Optional getValidUntilDate() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_VALID_UNTIL_DATE); - } - - /** - * @param validUntilDate This field provides a place for recording the end of the support period for a package from the supplier. - * @throws InvalidSPDXAnalysisException - */ - public void setValidUntilDate(String validUntilDate) throws InvalidSPDXAnalysisException { - if (strict && Objects.nonNull(validUntilDate) && Objects.nonNull(SpdxVerificationHelper.verifyDate(validUntilDate))) { - throw new InvalidSPDXAnalysisException("Invalid valid until date"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_VALID_UNTIL_DATE, validUntilDate); - } - - - /** - * @return the licenseDeclared or NOASSERTION if no license declared is found - * @throws InvalidSPDXAnalysisException - */ - public @Nullable AnyLicenseInfo getLicenseDeclared() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DECLARED_LICENSE); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("No declared license provided - returning NoAssertion"); - return new SpdxNoAssertionLicense(); - } - } - - /** - * Set the licenseDeclared - * @param licenseDeclared - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setLicenseDeclared(@Nullable AnyLicenseInfo licenseDeclared) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DECLARED_LICENSE, licenseDeclared); - return this; - } - - /** - * @return collection of checksums - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public Collection getChecksums() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_PACKAGE_CHECKSUM, Checksum.class); - } - - /** - * Add a checksum to the collection of checksums for this package - * @param checksum - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage addChecksum(Checksum checksum) throws InvalidSPDXAnalysisException { - getChecksums().add(checksum); - return this; - } - - /** - * @return the description - */ - public Optional getDescription() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DESCRIPTION); - } - - /** - * @param description - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setDescription(String description) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DESCRIPTION, description); - return this; - } - - /** - * @return the downloadLocation - */ - public Optional getDownloadLocation() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DOWNLOAD_URL); - } - - /** - * @param downloadLocation the download location - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setDownloadLocation(String downloadLocation) throws InvalidSPDXAnalysisException { - if (strict && Objects.nonNull(downloadLocation)) { - String verify = SpdxVerificationHelper.verifyDownloadLocation(downloadLocation); - if (Objects.nonNull(verify) && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DOWNLOAD_URL, downloadLocation); - return this; - } - - /** - * @return the homepage - */ - public Optional getHomepage() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PROJECT_HOMEPAGE); - } - - /** - * @param homepage the package homepage - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setHomepage(String homepage) throws InvalidSPDXAnalysisException { - if (strict && Objects.nonNull(homepage)) { - if (!SpdxVerificationHelper.isValidUri(homepage)) { - throw new InvalidSPDXAnalysisException(homepage + " is not a valid URI"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_PROJECT_HOMEPAGE, homepage); - return this; - } - - /** - * @return the originator - */ - public Optional getOriginator() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_ORIGINATOR); - } - - /** - * @param originator the package originator - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setOriginator(String originator) throws InvalidSPDXAnalysisException { - if (strict && Objects.nonNull(originator)) { - String verify = SpdxVerificationHelper.verifyOriginator(originator); - if (Objects.nonNull(verify) && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - - } - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_ORIGINATOR, originator); - return this; - } - - /** - * @return the packageFileName - */ - public Optional getPackageFileName() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILE_NAME); - } - - /** - * @param packageFileName the package filename to set - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setPackageFileName(String packageFileName) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_FILE_NAME, packageFileName); - return this; - } - - /** - * @return the packageVerificationCode, null if not present - * @throws InvalidSPDXAnalysisException - */ - public Optional getPackageVerificationCode() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERIFICATION_CODE); - if (!retval.isPresent()) { - return Optional.empty(); - } - if (!(retval.get() instanceof SpdxPackageVerificationCode)) { - throw new InvalidSPDXAnalysisException("Invalid type - expecting SpdxVerificationCode, type was "+retval.get().getClass().toString()); - } - return Optional.of((SpdxPackageVerificationCode)retval.get()); - } - - /** - * @param verificationCode the package verification code to set - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setPackageVerificationCode(SpdxPackageVerificationCode verificationCode) throws InvalidSPDXAnalysisException { - if (strict && Objects.isNull(verificationCode) && isFilesAnalyzed()) { - throw new InvalidSPDXAnalysisException("Can not set required verificationCode to null"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERIFICATION_CODE, verificationCode); - return this; - } - - /** - * @return the sourceInfo - */ - public Optional getSourceInfo() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SOURCE_INFO); - } - - /** - * @param sourceInfo package source info - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setSourceInfo(String sourceInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SOURCE_INFO, sourceInfo); - return this; - } - - /** - * @return the summary - */ - public Optional getSummary() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SHORT_DESC); - } - - /** - * @param summary package summary - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setSummary(String summary) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SHORT_DESC, summary); - return this; - } - - /** - * @return the supplier - */ - public Optional getSupplier() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SUPPLIER); - } - - /** - * @param supplier the package supplier to set - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setSupplier(String supplier) throws InvalidSPDXAnalysisException { - if (Objects.nonNull(supplier) && strict) { - String verify = SpdxVerificationHelper.verifySupplier(supplier); - if (Objects.nonNull(verify) && !verify.isEmpty()) { - throw new InvalidSPDXAnalysisException(verify); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_SUPPLIER, supplier); - return this; - } - - /** - * @return the versionInfo - */ - public Optional getVersionInfo() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERSION_INFO); - } - - /** - * @param versionInfo - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage setVersionInfo(String versionInfo) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_VERSION_INFO, versionInfo); - return this; - } - - /** - * @return the externalRefs - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public Collection getExternalRefs() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_EXTERNAL_REF, ExternalRef.class); - } - - /** - * @param externalRef - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage addExternalRef(ExternalRef externalRef) throws InvalidSPDXAnalysisException { - getExternalRefs().add(externalRef); - return this; - } - - /** - * @return the files - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public Collection getFiles() throws InvalidSPDXAnalysisException { - return (Collection)(Collection)files; - } - - /** - * Add a file to the collection of files attached to this package - * @param file - * @return this to build additional options - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage addFile(SpdxFile file) throws InvalidSPDXAnalysisException { - if (Objects.isNull(file)) { - throw new InvalidSPDXAnalysisException("Can not add null file to a package"); - } - getFiles().add(file); - return this; - } - - /** - * @return provides information about the primary purpose of the package. Package Purpose is intrinsic to how the package is being used rather than the content of the package. - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public Optional getPrimaryPurpose() throws InvalidSPDXAnalysisException { - Optional> retval = getEnumPropertyValue(SpdxConstantsCompatV2.PROP_PRIMARY_PACKAGE_PURPOSE); - if (retval.isPresent() && !(retval.get() instanceof Purpose)) { - throw new SpdxInvalidTypeException("Invalid enum type for "+retval.get().toString()); - } - return (Optional)(Optional)retval; - } - - /** - * @param purpose provides information about the primary purpose of the package. Package Purpose is intrinsic to how the package is being used rather than the content of the package. - * @throws InvalidSPDXAnalysisException - */ - public void setPrimaryPurpose(Purpose purpose) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_PRIMARY_PACKAGE_PURPOSE, purpose); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.SpdxItem#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - String pkgName = "UNKNOWN PACKAGE"; - try { - Optional name = getName(); - if (name.isPresent()) { - pkgName = name.get(); - } else { - pkgName = "UNKNOWN PACKAGE"; - } - } catch (InvalidSPDXAnalysisException e1) { - retval.add("Unable to get package name: "+e1.getMessage()); - } - - boolean filesAnalyzed = true; - try { - filesAnalyzed = isFilesAnalyzed(); - } catch (InvalidSPDXAnalysisException e1) { - retval.add("Unable to get filesAnalyzed: "+e1.getMessage()); - } - - // summary - nothing really to check - - // description - nothing really to check - - // download location - try { - Optional downloadLocation = this.getDownloadLocation(); - if (!downloadLocation.isPresent() || downloadLocation.get().isEmpty()) { - retval.add("Missing required download location for package "+pkgName); - } else { - String warning = SpdxVerificationHelper.verifyDownloadLocation(downloadLocation.get()); - if (Objects.nonNull(warning)) { - retval.add(warning); - } - } - } catch (InvalidSPDXAnalysisException e1) { - retval.add("Unable to get download location: "+e1.getMessage()); - } - - // checksum - try { - for (Checksum checksum:getChecksums()) { - List checksumVerify = checksum.verify(verifiedIds, specVersion); - addNameToWarnings(checksumVerify); - retval.addAll(checksumVerify); - } - } catch (InvalidSPDXAnalysisException e1) { - retval.add("Unable to get checksums: "+e1.getMessage()); - } - - // sourceinfo - nothing really to check - - // license declared - try { - Optional declaredLicense = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_PACKAGE_DECLARED_LICENSE); - if (!declaredLicense.isPresent()) { - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Missing required declared license for package "+pkgName); - } - } else { - List verify = declaredLicense.get().verify(verifiedIds, specVersion); - addNameToWarnings(verify); - retval.addAll(verify); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid package declared license: "+e.getMessage()); - } - try { - verifyLicenseInfosInFiles(getLicenseInfoFromFiles(), filesAnalyzed, pkgName, verifiedIds, retval, specVersion); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid license infos from file: "+e.getMessage()); - } - - // files depends on if the filesAnalyzed flag - try { - if (getFiles().size() == 0) { - if (filesAnalyzed) { - retval.add("Missing required package files for "+pkgName); - } - } else { - if (!filesAnalyzed) { - retval.add("Warning: Found analyzed files for package "+pkgName+" when analyzedFiles is set to false."); - } - for (SpdxFile file:getFiles()) { - List verify = file.verify(verifiedIds, specVersion); - addNameToWarnings(verify); - retval.addAll(verify); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid package files: "+e.getMessage()); - } - - // verification code - try { - Optional verificationCode = this.getPackageVerificationCode(); - if (!verificationCode.isPresent() && filesAnalyzed) { - retval.add("Missing required package verification code for package " + pkgName); - } else if (verificationCode.isPresent() && !verificationCode.get().getValue().isEmpty() && !filesAnalyzed) { - retval.add("Verification code must not be included when files not analyzed."); - } else if (filesAnalyzed) { - List verify = verificationCode.get().verify(verifiedIds, specVersion); - addNameToWarnings(verify); - retval.addAll(verify); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid package verification code: " + e.getMessage()); - } - - // supplier - try { - Optional supplier = this.getSupplier(); - if (supplier.isPresent() && !supplier.get().isEmpty()) { - String error = SpdxVerificationHelper.verifySupplier(supplier.get()); - if (error != null && !error.isEmpty()) { - retval.add("Supplier error - "+error+ " for package "+pkgName); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid supplier: " + e.getMessage()); - } - // originator - try { - Optional originator = this.getOriginator(); - if (originator.isPresent() && !originator.get().isEmpty()) { - String error = SpdxVerificationHelper.verifyOriginator(originator.get()); - if (error != null && !error.isEmpty()) { - retval.add("Originator error - "+error+ " for package "+pkgName); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid originator: " + e.getMessage()); - } - // External refs - try { - for (ExternalRef externalRef:getExternalRefs()) { - retval.addAll(externalRef.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid external refs: " + e.getMessage()); - } - // built date - try { - Optional date = getBuiltDate(); - if (date.isPresent()) { - String err = SpdxVerificationHelper.verifyDate(date.get()); - if (Objects.nonNull(err)) { - retval.add("Invalid built date: "+err); - } - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Built date is not supported prior to release "+Version.TWO_POINT_THREE_VERSION); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting built date"); - } - // release date - try { - Optional date = getReleaseDate(); - if (date.isPresent()) { - String err = SpdxVerificationHelper.verifyDate(date.get()); - if (Objects.nonNull(err)) { - retval.add("Invalid releaes date: "+err); - } - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Release date is not supported prior to release "+Version.TWO_POINT_THREE_VERSION); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting release date"); - } - // valid until date - try { - Optional date = getValidUntilDate(); - if (date.isPresent()) { - String err = SpdxVerificationHelper.verifyDate(date.get()); - if (Objects.nonNull(err)) { - retval.add("Invalid valid until date: "+err); - } - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Valid until date is not supported prior to release "+Version.TWO_POINT_THREE_VERSION); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting valid until date"); - } - // Primary purpose - try { - Optional purpose = getPrimaryPurpose(); - if (purpose.isPresent() && Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Primary purpose is not supported prior to release "+Version.TWO_POINT_THREE_VERSION); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting primary purpose"); - } - return retval; - } - - private void verifyLicenseInfosInFiles(Collection licenseInfoFromFiles, - boolean filesAnalyzed, String pkgName, Set verifiedIds, List retval, String specVersion) { - if (licenseInfoFromFiles.size() == 0 && filesAnalyzed) { - if (Version.versionLessThan(specVersion, Version.TWO_POINT_THREE_VERSION)) { - retval.add("Missing required license information from files for "+pkgName); - } - } else { - boolean foundNonSimpleLic = false; - for (AnyLicenseInfo lic:licenseInfoFromFiles) { - List verify = lic.verify(verifiedIds, specVersion); - addNameToWarnings(verify); - retval.addAll(verify); - if (!(lic instanceof SimpleLicensingInfo || - lic instanceof SpdxNoAssertionLicense || - lic instanceof SpdxNoneLicense || - lic instanceof OrLaterOperator || - lic instanceof WithExceptionOperator)) { - foundNonSimpleLic = true; - } - } - if (foundNonSimpleLic) { - retval.add("license info from files contains complex licenses for "+pkgName); - } - } - } - - @Override - public int compareTo(SpdxPackage pkg) { - // sort order is determined by the name and the version - - String myNameVersion = ""; - String compNameVersion = ""; - try { - Optional myName = this.getName(); - if (myName.isPresent()) { - myNameVersion = myName.get(); - } else { - myNameVersion = ""; - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting my name",e); - } - try { - Optional compName = pkg.getName(); - if (compName.isPresent()) { - compNameVersion = compName.get(); - } else { - compNameVersion = ""; - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare name",e); - } - try { - Optional myVersion = this.getVersionInfo(); - if (myVersion.isPresent()) { - myNameVersion = myNameVersion + myVersion.get(); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting my version",e); - } - try { - Optional compVersion = pkg.getVersionInfo(); - if (compVersion.isPresent()) { - compNameVersion = compNameVersion + compVersion.get(); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare version",e); - } - return myNameVersion.compareToIgnoreCase(compNameVersion); - } - - /** - * @return the Sha1 checksum value for this package, or a blank string if no - * sha1 checksum has been set - * @throws InvalidSPDXAnalysisException - */ - public String getSha1() throws InvalidSPDXAnalysisException { - for (Checksum checksum:getChecksums()) { - if (checksum.getAlgorithm().equals(ChecksumAlgorithm.SHA1)) { - String value = checksum.getValue(); - if (!value.isEmpty()) { - return value; - } - } - } - // No sha1 found, return an empty string - return ""; - } - - public static class SpdxPackageBuilder { - // required fields - Model Object - IModelStore modelStore; - String documentUri; - String id; - ModelCopyManager copyManager; - - // required fields - SpdxElement - String name; - - AnyLicenseInfo concludedLicense; - String copyrightText; - - // required fields - SpdxPackage - AnyLicenseInfo licenseDeclared; - - // optional fields - SpdxElement - Collection annotations = new ArrayList(); - Collection relationships = new ArrayList(); - String comment = null; - - // optional fields - SpdxItem - Collection licenseInfosFromFile = new ArrayList<>(); // required if isFilesAnalyzed is true - String licenseComments = null; - Collection attributionText = new ArrayList(); - - // optional fields - SpdxPackage - Collection checksums = new ArrayList(); - String description = null; - String downloadLocation = null; - Collection externalRefs = new ArrayList(); - Collection files = new ArrayList(); // required if isFilesAnalyzed is true - String homepage = null; - String originator = null; - String pacakgeFileName = null; - SpdxPackageVerificationCode packageVerificationCode = null; // required if isFilesAnalyzed is true - String sourceInfo = null; - String summary = null; - String supplier = null; - String versionInfo = null; - boolean filesAnalyzed = true; - Purpose primaryPurpose = null; - String builtDate = null; - String releaseDate = null; - String validUntilDate = null; - - /** - * Build an SpdxPackage with the required parameters if isFilesAnalyzed is false - * - note isFilesAnalyzed must be explicitly set to false - * - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this - * model - * @param objectUri ID for this object - must be unique within the SPDX - * document - * @param name File name - * @param copyManager - * @param concludedLicense - * @param copyrightText Copyright text - * @param licenseDeclared Declared license for the package - */ - public SpdxPackageBuilder(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, String name,AnyLicenseInfo concludedLicense, - String copyrightText, AnyLicenseInfo licenseDeclared) { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(name, "Name can not be null"); - this.modelStore = modelStore; - this.documentUri = documentUri; - this.id = id; - this.name = name; - this.concludedLicense = concludedLicense; - this.copyrightText = copyrightText; - this.licenseDeclared = licenseDeclared; - this.copyManager = copyManager; - } - - /** - * @param annotations Annotations - * @return this to continue the build - */ - public SpdxPackageBuilder setAnnotations(Collection annotations) { - Objects.requireNonNull(annotations, "Annotations can not be null"); - this.annotations = annotations; - return this; - } - - /** - * @param annotation Annotation to add - * @return this to continue the build - */ - public SpdxPackageBuilder addAnnotation(Annotation annotation) { - Objects.requireNonNull(annotation, "Annotation can not be null"); - this.annotations.add(annotation); - return this; - } - - /** - * @param relationships Relationships - * @return this to continue the build - */ - public SpdxPackageBuilder setRelationships(Collection relationships) { - Objects.requireNonNull(relationships, "Relationships can not be null"); - this.relationships = relationships; - return this; - } - - /** - * @param relationship Relationship to add - * @return this to continue the build - */ - public SpdxPackageBuilder addRelationship(Relationship relationship) { - Objects.requireNonNull(relationship, "Relationship can not be null"); - this.relationships.add(relationship); - return this; - } - - /** - * @param comment Comment - * @return this to continue the build - */ - public SpdxPackageBuilder setComment(@Nullable String comment) { - this.comment = comment; - return this; - } - - /** - * @param licenseInfosFromFile License information from all files in the package - * @return this to continue the build - */ - public SpdxPackageBuilder setLicenseInfosFromFile(Collection licenseInfosFromFile) { - this.licenseInfosFromFile = licenseInfosFromFile; - return this; - } - - /** - * @param licenseInfo license info for a file to be added to the collection of license infos - * @return this to continue the build - */ - public SpdxPackageBuilder addLicenseInfosFromFile(AnyLicenseInfo licenseInfo) { - this.licenseInfosFromFile.add(licenseInfo); - return this; - } - - /** - * @param licenseComments license comments - * @return this to continue the build - */ - public SpdxPackageBuilder setLicenseComments(@Nullable String licenseComments) { - this.licenseComments = licenseComments; - return this; - } - - /** - * @param checksums Checksum - * @return this to continue the build - */ - public SpdxPackageBuilder setChecksums(Collection checksums) { - Objects.requireNonNull(checksums, "Checksums can not be null"); - this.checksums = checksums; - return this; - } - - /** - * @param checksum Checksum to add - * @return this to continue the build - */ - public SpdxPackageBuilder addChecksum(Checksum checksum) { - Objects.requireNonNull(checksum, "Checksum can not be null"); - this.checksums.add(checksum); - return this; - } - - /** - * @param description long description - * @return this to continue the build - */ - public SpdxPackageBuilder setDescription(String description) { - Objects.requireNonNull(description, "Description can not be null"); - this.description = description; - return this; - } - - /** - * @param externalRefs external references to this package - * @return this to continue the build - */ - public SpdxPackageBuilder setExternalRefs(Collection externalRefs) { - Objects.requireNonNull(externalRefs, "External Refs can not be null"); - this.externalRefs = externalRefs; - return this; - } - - /** - * @param externalRef external reference to this package - * @return this to continue the build - */ - public SpdxPackageBuilder addExternalRef(ExternalRef externalRef) { - Objects.requireNonNull(externalRef, "External ref can not be null"); - this.externalRefs.add(externalRef); - return this; - } - - /** - * @param files files contained in the package - * @return this to continue the build - */ - public SpdxPackageBuilder setFiles(Collection files) { - Objects.requireNonNull(files, "Files can not be null"); - this.files = files; - return this; - } - - /** - * @param file file to be added to the collection of files - * @return this to continue the build - */ - public SpdxPackageBuilder addFile(SpdxFile file) { - Objects.requireNonNull(file, "File can not be null"); - this.files.add(file); - return this; - } - - /** - * @param homepage package home page - * @return this to continue the build - */ - public SpdxPackageBuilder setHomepage(String homepage) { - Objects.requireNonNull(homepage, "Homepage can not be null"); - this.homepage = homepage; - return this; - } - - /** - * @param originator originator of the package - * @return this to continue the build - */ - public SpdxPackageBuilder setOriginator(String originator) { - Objects.requireNonNull(originator, "Orinator can not be null"); - this.originator = originator; - return this; - } - - /** - * @param packageFileName file name of the archive containing the package - * @return this to continue the build - */ - public SpdxPackageBuilder setPackageFileName(String packageFileName) { - Objects.requireNonNull(packageFileName, "Package file name can not be null"); - this.pacakgeFileName = packageFileName; - return this; - } - - /** - * @param packageVerificationCode Package verification code calculated from the files - * @return this to continue the build - */ - public SpdxPackageBuilder setPackageVerificationCode(SpdxPackageVerificationCode packageVerificationCode) { - Objects.requireNonNull(packageVerificationCode, "Package verification code can not be null"); - this.packageVerificationCode = packageVerificationCode; - return this; - } - - /** - * @param sourceInfo Information on the source of the package - * @return this to continue the build - */ - public SpdxPackageBuilder setSourceInfo(String sourceInfo) { - Objects.requireNonNull(sourceInfo, "Source info can not be null"); - this.sourceInfo = sourceInfo; - return this; - } - - /** - * @param summary Short description - * @return this to continue the build - */ - public SpdxPackageBuilder setSummary(String summary) { - Objects.requireNonNull(summary, "Summary can not be null"); - this.summary = summary; - return this; - } - - /** - * @param supplier Package supplier - * @return this to continue the build - */ - public SpdxPackageBuilder setSupplier(String supplier) { - Objects.requireNonNull(supplier, "Supplier can not be null"); - this.supplier = supplier; - return this; - } - - /** - * @param versionInfo Package version - * @return this to continue the build - */ - public SpdxPackageBuilder setVersionInfo(String versionInfo) { - Objects.requireNonNull(versionInfo, "Version can not be null"); - this.versionInfo = versionInfo; - return this; - } - - /** - * @param filesAnalyzed if true, files were analyzed for this package - add additional required parameters files, verificationCode and licenseInfosFromFile - * @return this to continue the build - */ - public SpdxPackageBuilder setFilesAnalyzed(boolean filesAnalyzed) { - this.filesAnalyzed = filesAnalyzed; - return this; - } - - /** - * @param downloadLocation download location for the package - * @return this to continue the build - */ - public SpdxPackageBuilder setDownloadLocation(String downloadLocation) { - Objects.requireNonNull(downloadLocation, "Download location can not be null"); - this.downloadLocation = downloadLocation; - return this; - } - - /** - * @param attributionText Attribution text for the package - * @return this to continue the build - */ - public SpdxPackageBuilder setAttributionText(Collection attributionText) { - Objects.requireNonNull(attributionText, "Attribution text collection can not be null"); - this.attributionText = attributionText; - return this; - } - - /** - * @param attribution attribution to add to the attribution text - * @return this to continue the build - */ - public SpdxPackageBuilder addAttributionText(String attribution) { - Objects.requireNonNull(attributionText, "Attribution text can not be null"); - this.attributionText.add(attribution); - return this; - } - - /** - * @param purpose Package Purpose is intrinsic to how the package is being used rather than the content of the package. - * @return this to continue the build - */ - public SpdxPackageBuilder setPrimaryPurpose(Purpose purpose) { - Objects.requireNonNull(purpose, "Purpose can not be null"); - this.primaryPurpose = purpose; - return this; - } - - /** - * @param builtDate This field provides a place for recording the actual date the package was built. - * @return this to continue the build - */ - public SpdxPackageBuilder setBuiltDate(String builtDate) { - Objects.requireNonNull(builtDate, "Built date can not be null"); - this.builtDate = builtDate; - return this; - } - - /** - * @param validUntilDate This field provides a place for recording the end of the support period for a package from the supplier. - * @return this to continue the build - */ - public SpdxPackageBuilder setValidUntilDate(String validUntilDate) { - Objects.requireNonNull(validUntilDate, "Valid until date can not be null"); - this.validUntilDate = validUntilDate; - return this; - } - - /** - * @param releaseDate This field provides a place for recording the date the package was released. - * @return this to continue the build - */ - public SpdxPackageBuilder setReleaseDate(String releaseDate) { - Objects.requireNonNull(releaseDate, "Release date can not be null"); - this.releaseDate = releaseDate; - return this; - } - - /** - * @return the SPDX package - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackage build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new SpdxPackage(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java deleted file mode 100644 index b7afc3f0f..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxPackageVerificationCode.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.storage.IModelStore; - -/** - * @author gary - * - */ -public class SpdxPackageVerificationCode extends ModelObject { - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackageVerificationCode() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackageVerificationCode(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public SpdxPackageVerificationCode(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_VERIFICATIONCODE; - } - - - /** - * @return the value of the verification code - * @throws InvalidSPDXAnalysisException - */ - public String getValue() throws InvalidSPDXAnalysisException { - Optional retval = getStringPropertyValue(SpdxConstantsCompatV2.PROP_VERIFICATIONCODE_VALUE); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("No value found - returning empty string"); - return ""; - } - } - - /** - * Set the value for the verification code - * @param value verification code value - * @throws InvalidSPDXAnalysisException - */ - public void setValue(String value) throws InvalidSPDXAnalysisException { - if (strict && (Objects.isNull(value) || value.isEmpty())) { - throw new InvalidSPDXAnalysisException("Can not set required verification code value to null or empty string"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_VERIFICATIONCODE_VALUE, value); - } - - /** - * @return Collection containing files which have been excluded from the verification code calculation - * @throws InvalidSPDXAnalysisException - */ - public Collection getExcludedFileNames() throws InvalidSPDXAnalysisException { - return this.getStringCollection(SpdxConstantsCompatV2.PROP_VERIFICATIONCODE_IGNORED_FILES); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - try { - String value = this.getValue(); - if (value.isEmpty()) { - retval.add("Missing required verification code value"); - } else { - String verify = SpdxVerificationHelper.verifyChecksumString(value, ChecksumAlgorithm.SHA1, specVersion); - if (verify != null) { - retval.add(verify); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting verification code value: "+e.getMessage()); - } - return retval; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java b/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java deleted file mode 100644 index 9afbc50bc..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/SpdxSnippet.java +++ /dev/null @@ -1,619 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.pointer.ByteOffsetPointer; -import org.spdx.library.model.compat.v2.pointer.LineCharPointer; -import org.spdx.library.model.compat.v2.pointer.SinglePointer; -import org.spdx.library.model.compat.v2.pointer.StartEndPointer; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.PropertyDescriptor; - -/** - * Snippets can optionally be used when a file is known to have some content that has been included from another original source. - * They are useful for denoting when part of a file may have been originally created under another license. - * Each instance of Snippet Information needs to be associated with a specific File in an SPDX Document. - * - * @author Gary O'Neall - * - */ -public class SpdxSnippet extends SpdxItem implements Comparable { - - private Collection allRanges; - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), - id, DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public SpdxSnippet(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - allRanges = new ModelCollectionV2(modelStore, documentUri, id, SpdxConstantsCompatV2.PROP_SNIPPET_RANGE, copyManager, StartEndPointer.class); - } - - /** - * @param spdxSnippetBuilder - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet(SpdxSnippetBuilder spdxSnippetBuilder) throws InvalidSPDXAnalysisException { - this(spdxSnippetBuilder.modelStore, spdxSnippetBuilder.documentUri, spdxSnippetBuilder.id, - spdxSnippetBuilder.copyManager, true); - setCopyrightText(spdxSnippetBuilder.copyrightText); - setName(spdxSnippetBuilder.name); - setLicenseConcluded(spdxSnippetBuilder.concludedLicense); - getLicenseInfoFromFiles().addAll(spdxSnippetBuilder.licenseInfosFromFile); - setSnippetFromFile(spdxSnippetBuilder.snippetFromFile); // Note: this should be before the byterange so that the file in the byte range is properly set - setByteRange(spdxSnippetBuilder.startByte, spdxSnippetBuilder.endByte); - - // optional parameters - SpdxElement - getAnnotations().addAll(spdxSnippetBuilder.annotations); - getRelationships().addAll(spdxSnippetBuilder.relationships); - setComment(spdxSnippetBuilder.comment); - - // optional parameters - SpdxItem - setLicenseComments(spdxSnippetBuilder.licenseComments); - getAttributionText().addAll(spdxSnippetBuilder.attributionText); - - // optional parameters - SpdxSnippet - if (spdxSnippetBuilder.startLine > 0) { - setLineRange(spdxSnippetBuilder.startLine, spdxSnippetBuilder.endLine); - } - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_SNIPPET; - } - - @Override - public PropertyDescriptor getLicenseInfoFromFilesPropertyName() { - return SpdxConstantsCompatV2.PROP_LICENSE_INFO_FROM_SNIPPETS; - } - - - /** - * @return the snippetFromFile, null if the file is not present in the model - * @throws InvalidSPDXAnalysisException - */ - public @Nullable SpdxFile getSnippetFromFile() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_SNIPPET_FROM_FILE); - if (!retval.isPresent()) { - return null; - } - if (!(retval.get() instanceof SpdxFile)) { - throw new SpdxInvalidTypeException("Invalid type returned for getSnippetFromFile. Expected SpdxFile, returned type "+retval.get().getClass().toString()); - } - return (SpdxFile)retval.get(); - } - - /** - * @param snippetFromFile the snippetFromFile to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet setSnippetFromFile(SpdxFile snippetFromFile) throws InvalidSPDXAnalysisException { - if (strict && Objects.isNull(snippetFromFile)) { - throw new InvalidSPDXAnalysisException("Can not set required snippetFromFile to null"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_SNIPPET_FROM_FILE, snippetFromFile); - // Update the references in the ranges - StartEndPointer byteRange = getByteRange(); - if (byteRange != null) { - if (!strict) { - byteRange.setStrict(strict); - } - if (byteRange.getStartPointer() != null) { - byteRange.getStartPointer().setReference(snippetFromFile); - } - if (byteRange.getEndPointer() != null) { - byteRange.getEndPointer().setReference(snippetFromFile); - } - } - Optional lineRange = getLineRange(); - if (lineRange.isPresent()) { - if (!strict) { - lineRange.get().setStrict(strict); - } - if (lineRange.get().getStartPointer() != null) { - lineRange.get().getStartPointer().setReference(snippetFromFile); - } - if (lineRange.get().getEndPointer() != null) { - lineRange.get().getEndPointer().setReference(snippetFromFile); - } - } - return this; - } - - /** - * @return the byteRange or null if no byte range is present - * @throws InvalidSPDXAnalysisException - */ - public StartEndPointer getByteRange() throws InvalidSPDXAnalysisException { - for (StartEndPointer range:allRanges) { - if (range.getStartPointer() instanceof ByteOffsetPointer) { - if (!(range.getEndPointer() instanceof ByteOffsetPointer)) { - logger.error("Incompatable start and end pointer types - must both be offset or line types"); - throw new InvalidSPDXAnalysisException("Incompatable start and end snippet specification - mixing byte and line ranges"); - } - return range; - } - } - return null; - } - - /** - * @param startByte first byte of the range - * @param endByte end byte of the range - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet setByteRange(int startByte, int endByte) throws InvalidSPDXAnalysisException { - SpdxFile snippetFromFile = getSnippetFromFile(); - if (strict) { - if (endByte <= startByte) { - throw new InvalidSPDXAnalysisException("Ending byte of a range must be greater than the starting byte"); - } - if (Objects.isNull(snippetFromFile)) { - throw new InvalidSPDXAnalysisException("Snippets from file must be set prior to setting byte range"); - } - } - ByteOffsetPointer startPointer = createByteOffsetPointer(snippetFromFile, startByte); - ByteOffsetPointer endPointer = createByteOffsetPointer(snippetFromFile, endByte); - StartEndPointer byteRange = createStartEndPointer(startPointer, endPointer); - List existing = new ArrayList(); - for (StartEndPointer range:allRanges) { - if (range.getStartPointer() instanceof ByteOffsetPointer) { - existing.add(range); - } - } - allRanges.removeAll(existing); - allRanges.add(byteRange); - return this; - } - - /** - * @return the lineRange - * @throws InvalidSPDXAnalysisException - */ - public Optional getLineRange() throws InvalidSPDXAnalysisException { - for (StartEndPointer range:allRanges) { - if (range.getStartPointer() instanceof LineCharPointer) { - if (!(range.getEndPointer() instanceof LineCharPointer)) { - logger.error("Incompatable start and end pointer types - must both be offset or line types"); - throw new InvalidSPDXAnalysisException("Incompatable start and end snippet specification - mixing byte and line ranges"); - } - return Optional.of(range); - } - } - return Optional.empty(); - } - - /** - * @param startLine the start position of lineRange to set, inclusive - * @param endLine the end position of lineRange to set, exclusive - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public SpdxSnippet setLineRange(int startLine, int endLine) throws InvalidSPDXAnalysisException { - SpdxFile snippetFromFile = getSnippetFromFile(); - if (strict) { - if (endLine <= startLine) { - throw new InvalidSPDXAnalysisException("Ending line of a range must be greater than the starting line"); - } - if (Objects.isNull(snippetFromFile)) { - throw new InvalidSPDXAnalysisException("Snippets from file must be set prior to setting line range"); - } - } - LineCharPointer startPointer = createLineCharPointer(snippetFromFile, startLine); - LineCharPointer endPointer = createLineCharPointer(snippetFromFile, endLine); - StartEndPointer lineRange = createStartEndPointer(startPointer, endPointer); - List existing = new ArrayList(); - for (StartEndPointer range:allRanges) { - if (range.getStartPointer() instanceof LineCharPointer) { - existing.add(range); - } - } - allRanges.removeAll(existing); - if (Objects.nonNull(lineRange)) { - setPointerReferences(lineRange); - allRanges.add(lineRange); - } - return this; - } - - - /** - * Set the reference for the pointers to the snippetFromFile - * @param pointer - * @throws InvalidSPDXAnalysisException - */ - private void setPointerReferences(@Nullable StartEndPointer pointer) throws InvalidSPDXAnalysisException { - if (Objects.isNull(pointer)) { - return; - } - SpdxFile fromFile = getSnippetFromFile(); - if (Objects.nonNull(fromFile)) { - SinglePointer startPointer = pointer.getStartPointer(); - if (Objects.nonNull(startPointer)) { - startPointer.setReference(fromFile); - } - SinglePointer endPointer = pointer.getEndPointer(); - if (Objects.nonNull(endPointer)) { - endPointer.setReference(fromFile); - } - } - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.SpdxItem#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - - String snippetName = "[Unnamed Snippet]"; - Optional name; - try { - name = getName(); - if (name.isPresent()) { - snippetName = name.get(); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting name: "+e.getMessage()); - } - SpdxFile snippetFromFile; - try { - snippetFromFile = getSnippetFromFile(); - if (snippetFromFile == null) { - retval.add("Missing snippet from file in Snippet "+snippetName); - } else { - retval.addAll(snippetFromFile.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting snippetFromFile: "+e.getMessage()); - } - StartEndPointer byteRange; - try { - byteRange = getByteRange(); - if (byteRange == null) { - retval.add("Missing snippet byte range from Snippet "+snippetName); - } else { - retval.addAll(byteRange.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting byteRange: "+e.getMessage()); - } - Optional lineRange; - try { - lineRange = getLineRange(); - if (lineRange.isPresent()) { - retval.addAll(lineRange.get().verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting lineRange: "+e.getMessage()); - } - return retval; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(SpdxSnippet o) { - try { - if (o == null) { - return 1; - } - int retval = 0; - Optional name = getName(); - Optional compName = o.getName(); - if (name.isPresent()) { - if (compName.isPresent()) { - retval = name.get().compareTo(compName.get()); - } else { - return 1; - } - } - SpdxFile snippetFromFile = getSnippetFromFile(); - SpdxFile compSnippetFromFile = o.getSnippetFromFile(); - if (retval == 0 && snippetFromFile != null) { - retval = snippetFromFile.compareTo(compSnippetFromFile); - } - if (retval == 0) { - StartEndPointer byteRange = getByteRange(); - StartEndPointer compByteRange = o.getByteRange(); - if (byteRange != null) { - return byteRange.compareTo(compByteRange); - } else { - if (o.getByteRange() == null) { - return 0; - } else { - return 1; - } - } - } - return retval; - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting compare for snippet",e); - return -1; - } - } - - @Override - public String toString() { - Optional name; - try { - name = getName(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting name",e); - name = Optional.empty(); - } - if (name.isPresent() && !name.get().isEmpty()) { - return name.get(); - } - StringBuilder sb = new StringBuilder(); - SpdxFile snippetFromFile; - try { - snippetFromFile = getSnippetFromFile(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting snippetFromFile",e); - snippetFromFile = null; - } - if (snippetFromFile != null) { - Optional fileName; - try { - fileName = snippetFromFile.getName(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting snippetFromFile fileName",e); - fileName = Optional.empty(); - } - if (fileName.isPresent() && !fileName.get().isEmpty()) { - sb.append(fileName); - } else { - sb.append("FileID "); - sb.append(snippetFromFile.getId()); - } - sb.append(": "); - } - StartEndPointer byteRange; - try { - byteRange = getByteRange(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting byteRange",e); - byteRange = null; - } - if (byteRange != null) { - sb.append(byteRange.toString()); - } else { - sb.append("[No byte range set]"); - } - return sb.toString(); - } - - public static class SpdxSnippetBuilder { - // required fields - Model Object - IModelStore modelStore; - String documentUri; - String id; - ModelCopyManager copyManager; - - // required fields - SpdxElement - String name; - - // required fields - SpdxItem - AnyLicenseInfo concludedLicense; - Collection licenseInfosFromFile; - String copyrightText; - - // required fields - SpdxSnippet - SpdxFile snippetFromFile; - int startByte; - int endByte; - - // optional fields - SpdxElement - Collection annotations = new ArrayList(); - Collection relationships = new ArrayList(); - String comment = null; - - // optional fields - SpdxItem - String licenseComments = null; - Collection attributionText = new ArrayList(); - - // optional fields - SpdxSnippet - int startLine = -1; - int endLine = -1; - - /** - * Build a snippet with the required parameters - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param objectUri ID for this object - must be unique within the SPDX document - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param name - File name - * @param concludedLicense license concluded - * @param licenseInfosFromFile collection of seen licenses - * @param copyrightText Copyright text - * @param snippetFromFile File where the snippet is located - * @param startByte first byte of the snippet in the file - * @param endByte end byte of the snippet in the file - */ - public SpdxSnippetBuilder(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, String name, - AnyLicenseInfo concludedLicense, Collection licenseInfosFromFile, - String copyrightText, SpdxFile snippetFromFile, int startByte, int endByte) { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(name, "Name can not be null"); - Objects.requireNonNull(snippetFromFile, "Snippet from file can not be null"); - this.modelStore = modelStore; - this.documentUri = documentUri; - this.id = id; - this.name = name; - this.concludedLicense = concludedLicense; - this.licenseInfosFromFile = licenseInfosFromFile; - this.copyrightText = copyrightText; - this.startByte = startByte; - this.endByte = endByte; - this.snippetFromFile = snippetFromFile; - this.copyManager = copyManager; - } - - /** - * @param annotations Annotations - * @return this to continue the build - */ - public SpdxSnippetBuilder setAnnotations(Collection annotations) { - Objects.requireNonNull(annotations, "Annotations can not be null"); - this.annotations = annotations; - return this; - } - - /** - * @param annotation Annotation to add - * @return this to continue the build - */ - public SpdxSnippetBuilder addAnnotation(Annotation annotation) { - Objects.requireNonNull(annotation, "Annotation can not be null"); - this.annotations.add(annotation); - return this; - } - - /** - * @param relationships Relationships - * @return this to continue the build - */ - public SpdxSnippetBuilder setRelationship(Collection relationships) { - Objects.requireNonNull(relationships, "Relationships can not be null"); - this.relationships = relationships; - return this; - } - - /** - * @param relationship Relationship to add - * @return this to continue the build - */ - public SpdxSnippetBuilder addRelationship(Relationship relationship) { - Objects.requireNonNull(relationship, "Relationship can not be null"); - this.relationships.add(relationship); - return this; - } - - /** - * @param comment Comment - * @return this to continue the build - */ - public SpdxSnippetBuilder setComment(@Nullable String comment) { - this.comment = comment; - return this; - } - - /** - * @param licenseComments - * @return this to continue the build - */ - public SpdxSnippetBuilder setLicenseComments(@Nullable String licenseComments) { - this.licenseComments = licenseComments; - return this; - } - - /** - * Set the attribution test - * @param attributionText Attribution text for the file - * @return this to continue the build - */ - public SpdxSnippetBuilder setAttributionText(Collection attributionText) { - Objects.requireNonNull(attributionText, "Attribution text collection can not be null"); - this.attributionText = attributionText; - return this; - } - - /** - * Add attribution to the attribution text collection - * @param attribution - * @return this to continue the build - */ - public SpdxSnippetBuilder addAttributionText(String attribution) { - Objects.requireNonNull(attribution, "Attribution text can not be null"); - this.attributionText.add(attribution); - return this; - } - - /** - * @param startLine first line of the snippet - * @param endLine end line of the snippet - * @return this to continue the build - */ - public SpdxSnippetBuilder setLineRange(int startLine, int endLine) { - this.startLine = startLine; - this.endLine = endLine; - return this; - } - - public SpdxSnippet build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new SpdxSnippet(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/Write.java b/src/main/java/org/spdx/library/model/compat/v2/Write.java deleted file mode 100644 index 864fbfc81..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/Write.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Objects; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.storage.IModelStore; -import org.spdx.storage.ISerializableModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.ModelUpdate; - -/** - * Static class to provide write operations to the model. - * - * Some design and some implementation borrowed from Yevster's spdxtra project under the Apache 2.0 license - * http://yevster.github.io/spdxtra/ - * - * @author Gary O'Neall - * - */ -public class Write { - - /** - * Convenience method for applying a small set of updates. - * @param modelStore Storage for the model objects - * @param updates Updates to be applied in a single transaction - * @throws IOException - * @throws InvalidSPDXAnalysisException - */ - public static void applyUpdatesInOneTransaction(String documentUri, IModelStore modelStore, ModelUpdate... updates) throws InvalidSPDXAnalysisException, IOException { - applyUpdatesInOneTransaction(documentUri, modelStore, Arrays.asList(updates)); - } - - /** - * Apply a set of model updates in a single transaction. Updates can be gather from the SpdxModelFactory or the model objects themselves from the update methods - * @param modelStore Storage for the model objects - * @param updates Updates to be applied in a single transaction - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static void applyUpdatesInOneTransaction(String documentUri, IModelStore modelStore, Iterable updates) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - for (ModelUpdate update : updates) { - update.apply(); - } - } finally { - modelStore.leaveCriticalSection(lock); - } - } - - /** - * Deserialize a model store from an input stream. The format of the input stream dependes on the Model Store implementation - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param stream Input stream to deserialize the data - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static void deSerialize(ISerializableModelStore modelStore, String documentUri, InputStream stream) throws InvalidSPDXAnalysisException, IOException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - modelStore.deSerialize(stream, false); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - - /** - * Reads a file into a model store - * @param modelStore - * @param documentUri - * @param filePath - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public static void readFile(ISerializableModelStore modelStore, String documentUri, Path filePath) throws InvalidSPDXAnalysisException, IOException { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(filePath, "File path can not be null"); - try (InputStream is = Files.newInputStream(filePath)) { - deSerialize(modelStore, documentUri, is); - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java deleted file mode 100644 index 8786b163f..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/AnnotationType.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * Annotation types for the Annotation Class - * - * @author Gary O'Neall - * - */ -public enum AnnotationType implements IndividualUriValue { - - OTHER("annotationType_other"), - REVIEW("annotationType_review"), - MISSING("not_allowed"); - - private String longName; - - private AnnotationType(String longName) { - this.longName = longName; - } - @Override - public String getIndividualURI() { - return getNameSpace() + getLongName(); - } - - public String getLongName() { - return longName; - } - - public String getNameSpace() { - return SpdxConstantsCompatV2.SPDX_NAMESPACE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java deleted file mode 100644 index 1d2482e0e..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ChecksumAlgorithm.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * Enum constants for Checksum Algorithms - * - * @author Gary O'Neall - * - */ -public enum ChecksumAlgorithm implements IndividualUriValue { - SHA1("checksumAlgorithm_sha1"), - MD5("checksumAlgorithm_md5"), - SHA256("checksumAlgorithm_sha256"), - MISSING("InvalidMissingChecksum"), - SHA224("checksumAlgorithm_sha224"), - SHA384("checksumAlgorithm_sha384"), - SHA512("checksumAlgorithm_sha512"), - MD2("checksumAlgorithm_md2"), - MD4("checksumAlgorithm_md4"), - MD6("checksumAlgorithm_md6"), - SHA3_256("checksumAlgorithm_sha3_256"), - SHA3_384("checksumAlgorithm_sha3_384"), - SHA3_512("checksumAlgorithm_sha3_512"), - BLAKE2b_256("checksumAlgorithm_blake2b256"), - BLAKE2b_384("checksumAlgorithm_blake2b384"), - BLAKE2b_512("checksumAlgorithm_blake2b512"), - BLAKE3("checksumAlgorithm_blake3"), - ADLER32("checksumAlgorithm_adler32"), - ; - - private final String longName; - - private ChecksumAlgorithm(String longName) { - this.longName = longName; - } - @Override - public String getIndividualURI() { - return getNameSpace() + getLongName(); - } - - public String getLongName() { - return longName; - } - - public String getNameSpace() { - return SpdxConstantsCompatV2.SPDX_NAMESPACE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java deleted file mode 100644 index e95f0406f..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/FileType.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * File Type is intrinsic to the file, independent of how the file is being used. - * A file may have more than one file type assigned to it. - * - * @author Gary O'Neall - * - */ -public enum FileType implements IndividualUriValue { - APPLICATION("fileType_application"), - ARCHIVE("fileType_archive"), - AUDIO("fileType_audio"), - BINARY("fileType_binary"), - DOCUMENTATION("fileType_documentation"), - IMAGE("fileType_image"), - OTHER("fileType_other"), - SOURCE("fileType_source"), - SPDX("fileType_spdx"), - TEXT("fileType_text"), - VIDEO("fileType_video") - ; - - private String longName; - - private FileType(String longName) { - this.longName = longName; - } - @Override - public String getIndividualURI() { - return getNameSpace() + getLongName(); - } - - public String getLongName() { - return longName; - } - - public String getNameSpace() { - return SpdxConstantsCompatV2.SPDX_NAMESPACE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java deleted file mode 100644 index c193c1604..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/Purpose.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2022 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * Package Purpose is intrinsic to how the package is being used rather than the content of the package. - * - * @author Gary O'Neall - * - */ -public enum Purpose implements IndividualUriValue { - - APPLICATION("purpose_application"), - FRAMEWORK("purpose_framework"), - LIBRARY("purpose_library"), - OPERATING_SYSTEM("purpose_operatingSystem"), - DEVICE("purpose_device"), - FIRMWARE("purpose_firmware"), - SOURCE("purpose_source"), - FILE("purpose_file"), - INSTALL("purpose_install"), - ARCHIVE("purpose_archive"), - CONTAINER("purpose_container"), - OTHER("purpose_other"); - -private String longName; - - private Purpose(String longName) { - this.longName = longName; - } - @Override - public String getIndividualURI() { - return getNameSpace() + getLongName(); - } - - public String getLongName() { - return longName; - } - - public String getNameSpace() { - return SpdxConstantsCompatV2.SPDX_NAMESPACE; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java deleted file mode 100644 index f787f53ba..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/ReferenceCategory.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * Reference category for external refs - * - * @author Gary O'Neall - * - */ -public enum ReferenceCategory implements IndividualUriValue { - PACKAGE_MANAGER("referenceCategory_packageManager"), - SECURITY("referenceCategory_security"), - OTHER("referenceCategory_other"), - PERSISTENT_ID("referenceCategory_persistentId"), - MISSING("invalid_missing") - ; - -private String longName; - - private ReferenceCategory(String longName) { - this.longName = longName; - } - @Override - public String getIndividualURI() { - return getNameSpace() + getLongName(); - } - - public String getLongName() { - return longName; - } - - public String getNameSpace() { - return SpdxConstantsCompatV2.SPDX_NAMESPACE; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java deleted file mode 100644 index 762f32fd8..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/RelationshipType.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * Relationship types - * - * @author Gary O'Neall - * - */ -public enum RelationshipType implements IndividualUriValue { - - DESCRIBES("relationshipType_describes"), - DESCRIBED_BY("relationshipType_describedBy"), - ANCESTOR_OF("relationshipType_ancestorOf"), - BUILD_TOOL_OF("relationshipType_buildToolOf"), - CONTAINED_BY("relationshipType_containedBy"), - CONTAINS("relationshipType_contains"), - COPY_OF("relationshipType_copyOf"), - DATA_FILE_OF("relationshipType_dataFile"), - DESCENDANT_OF("relationshipType_descendantOf"), - DISTRIBUTION_ARTIFACT("relationshipType_distributionArtifact"), - DOCUMENTATION_OF("relationshipType_documentation"), - DYNAMIC_LINK("relationshipType_dynamicLink"), - EXPANDED_FROM_ARCHIVE("relationshipType_expandedFromArchive"), - FILE_ADDED("relationshipType_fileAdded"), - FILE_DELETED("relationshipType_fileDeleted"), - FILE_MODIFIED("relationshipType_fileModified"), - GENERATED_FROM("relationshipType_generatedFrom"), - GENERATES("relationshipType_generates"), - METAFILE_OF("relationshipType_metafileOf"), - OPTIONAL_COMPONENT_OF("relationshipType_optionalComponentOf"), - OTHER("relationshipType_other"), - PACKAGE_OF("relationshipType_packageOf"), - PATCH_APPLIED("relationshipType_patchApplied"), - PATCH_FOR("relationshipType_patchFor"), - AMENDS("relationshipType_amendment"), - STATIC_LINK("relationshipType_staticLink"), - TEST_CASE_OF("relationshipType_testcaseOf"), - PREREQUISITE_FOR("relationshipType_prerequisiteFor"), - HAS_PREREQUISITE("relationshipType_hasPrerequisite"), - VARIANT_OF("relationshipType_variantOf"), - MISSING("relationshipType_INVALID_MISSING"), - BUILD_DEPENDENCY_OF("relationshipType_buildDependencyOf"), - DEPENDENCY_MANIFEST_OF("relationshipType_dependencyManifestOf"), - DEPENDENCY_OF("relationshipType_dependencyOf"), - DEPENDS_ON("relationshipType_dependsOn"), - DEV_DEPENDENCY_OF("relationshipType_devDependencyOf"), - DEV_TOOL_OF("relationshipType_devToolOf"), - EXAMPLE_OF("relationshipType_exampleOf"), - OPTIONAL_DEPENDENCY_OF("relationshipType_optionalDependencyOf"), - PROVIDED_DEPENDENCY_OF("relationshipType_providedDependencyOf"), - RUNTIME_DEPENDENCY_OF("relationshipType_runtimeDependencyOf"), - TEST_DEPENDENCY_OF("relationshipType_testDependencyOf"), - TEST_OF("relationshipType_testOf"), - TEST_TOOL_OF("relationshipType_testToolOf"), - REQUIREMENT_DESCRIPTION_FOR("relationshipType_requirementDescriptionFor"), - SPECIFICATION_FOR("relationshipType_specificationFor"); - - private String longName; - - private RelationshipType(String longName) { - this.longName = longName; - } - @Override - public String getIndividualURI() { - return getNameSpace() + getLongName(); - } - - - public String getLongName() { - return longName; - } - - public String getNameSpace() { - return SpdxConstantsCompatV2.SPDX_NAMESPACE; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java deleted file mode 100644 index 0880efec2..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/SpdxEnumFactoryCompatV2.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.enumerations; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * @author gary - * - */ -public class SpdxEnumFactoryCompatV2 { - - /** - * Map of enum URI's to their Enum values - */ - public static Map> uriToEnum; - - static { - Map> map = new HashMap<>(); - for (AnnotationType annotationType:AnnotationType.values()) { - map.put(annotationType.getIndividualURI(), annotationType); - } - for (RelationshipType relationshipType:RelationshipType.values()) { - map.put(relationshipType.getIndividualURI(), relationshipType); - } - for (ChecksumAlgorithm algorithm:ChecksumAlgorithm.values()) { - map.put(algorithm.getIndividualURI(), algorithm); - } - for (ReferenceCategory referenceCategory:ReferenceCategory.values()) { - map.put(referenceCategory.getIndividualURI(), referenceCategory); - } - for (FileType fileType:FileType.values()) { - map.put(fileType.getIndividualURI(), fileType); - } - for (Purpose purpose:Purpose.values()) { - map.put(purpose.getIndividualURI(), purpose); - } - uriToEnum = Collections.unmodifiableMap(map); - } - - private SpdxEnumFactoryCompatV2() { - // this is only a static class - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java deleted file mode 100644 index ab50116e2..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/enumerations/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * This package contains all the enumerations used in the SPDX model. - * - * For the enumerations to be stored properly, they must implement the IndividualUriValue interface. - * - * The enumerations also must be added to the static map uriToEnum in the SpdxEnumFactoryCompatV2 classes. - * - * @author Gary O'Neall - */ -package org.spdx.library.model.compat.v2.enumerations; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java deleted file mode 100644 index 4fe8f034d..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/AbstractExtractedLicenseInfo.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright (c) 2022 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.storage.IModelStore; - -/** - * ExtractedLicenseInfo which can be represented as a concrete ExtractedLicenseInfo within - * the same SPDX document with all properties accessible, or as an ExternalExtractedLicenseInfo - * which represents a license not included within the SPDX document. - * - * @author Gary O'Neall - * - */ -public abstract class AbstractExtractedLicenseInfo extends SimpleLicensingInfo -implements Comparable { - - /** - * Create a new ExtractedLicenseInfo using the ID - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public AbstractExtractedLicenseInfo(String id) - throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * Create a new ExtractedLicenseInfo object - * @param modelStore container which includes the license - * @param documentUri URI for the SPDX document containing the license - * @param objectUri identifier for the license - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license if it does not exist - * @throws InvalidSPDXAnalysisException - */ - public AbstractExtractedLicenseInfo(IModelStore modelStore, - String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#toString() - */ - @Override - public String toString() { - // must be only the ID if we are to use this to create - // parseable license strings - return this.getLicenseId(); - } - - /** - * @return the text - * @throws SpdxInvalidTypeException - */ - public abstract String getExtractedText() throws InvalidSPDXAnalysisException; - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(AbstractExtractedLicenseInfo o) { - try { - if (this.getLicenseId() == null) { - if (o.getLicenseId() == null) { - if (this.getExtractedText() == null) { - if (o.getExtractedText() == null) { - return 0; - } else { - return 1; - } - }else if (o.getExtractedText() == null) { - return -1; - } else { - return this.getExtractedText().compareToIgnoreCase(o.getExtractedText()); - } - } else { - return 1; - } - } else { - if (o.getLicenseId() == null) { - return -1; - } else { - return this.getLicenseId().compareToIgnoreCase(o.getLicenseId()); - } - } - } catch (InvalidSPDXAnalysisException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java deleted file mode 100644 index 5e62677f4..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/AnyLicenseInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * This abstract class represents several ways of describing licensing information. - * License info can be described as a set of conjunctive licenses (where all licenses - * terms must apply), a set of disjunctive licenses (where there is a choice of one - * license among the set described) or a specific license. The specific licenses - * are of a SimpleLicensingInfoType - * @author Gary O'Neall - * - */ -public abstract class AnyLicenseInfo extends ModelObject { - - static final Logger logger = LoggerFactory.getLogger(AnyLicenseInfo.class.getName()); - - /** - * Create a new Model Object using an Anonymous ID with the defualt store and default document URI - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * Open or create a model object with the default store and default document URI - * @param objectUri ID for this object - must be unique within the SPDX document - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * Create a new LicenseInfo object - * @param modelStore container which includes the license - * @param documentUri URI for the SPDX document containing the license - * @param objectUri identifier for the license - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license if it does not exist - * @throws InvalidSPDXAnalysisException - */ - AnyLicenseInfo(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - // force subclasses to implement toString - @Override - public abstract String toString(); -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java deleted file mode 100644 index 23d6334c5..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ConjunctiveLicenseSet.java +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * A set of licenses where all of the licenses apply - * @author Gary O'Neall - * - */ -public class ConjunctiveLicenseSet extends LicenseSet { - - public ConjunctiveLicenseSet() throws InvalidSPDXAnalysisException { - super(); - } - - public ConjunctiveLicenseSet(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public ConjunctiveLicenseSet(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#toString() - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder("("); - boolean moreThanOne = false; - Iterator iter; - try { - iter = this.getMembers().iterator(); - while (iter.hasNext()) { - if (moreThanOne) { - sb.append(" AND "); - } - moreThanOne = true; - sb.append(iter.next().toString()); - } - sb.append(')'); - return sb.toString(); - } catch (InvalidSPDXAnalysisException e) { - return "ERROR RETRIEVING LICENSE SET MEMBERS"; - } - } - - - /** - * Conjunctive license sets can contain other conjunctive license sets as members. Logically, - * the members of these "sub-conjunctive license sets" could be direct members and have the same - * meaning. - * @return all members "flattening out" conjunctive license sets which are members of this set - * @throws SpdxInvalidTypeException - */ - public List getFlattenedMembers() throws InvalidSPDXAnalysisException { - HashSet retval = new HashSet<>(); // Use a set since any duplicated elements would be still considered equal - Iterator iter = this.getMembers().iterator(); - while (iter.hasNext()) { - AnyLicenseInfo li = iter.next(); - if (li instanceof ConjunctiveLicenseSet) { - // we need to flatten this out - List members = ((ConjunctiveLicenseSet)li).getFlattenedMembers(); - for (int i = 0; i < members.size(); i++) { - retval.add(members.get(i)); - } - } else { - retval.add(li); - } - } - List retvallist = new ArrayList<>(); - retvallist.addAll(retval); - return retvallist; - } - - @Override - public int hashCode() { - // We override equals and hashcode to take into account flattening of the license set - // Calculate a hashcode by XOR'ing all of the hashcodes of the license set - int retval = 41; // Prime number - List allMembers; - try { - allMembers = this.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting license set members",e); - } - for (AnyLicenseInfo licenseInfo:allMembers) { - retval = retval ^ licenseInfo.hashCode(); - } - return retval; - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - // We override equals and hashcode to take into account flattening of the license set - if (o == this) { - return true; - } - if (!(o instanceof ConjunctiveLicenseSet)) { - // covers o == null, as null is not an instance of anything - return false; - } - ConjunctiveLicenseSet comp = (ConjunctiveLicenseSet)o; - List compInfos; - try { - compInfos = comp.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting compare license set members",e); - } - List myInfos; - try { - myInfos = this.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting license set members",e); - } - if (compInfos.size() != myInfos.size()) { - return false; - } - for (AnyLicenseInfo myInfo:myInfos) { - if (!compInfos.contains(myInfo)) { - return false; - } - } - return true; - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.model.IRdfModel#equivalent(org.spdx.rdfparser.model.IRdfModel) - */ - @Override - public boolean equivalent(ModelObject compare) throws InvalidSPDXAnalysisException { - if (!(compare instanceof ConjunctiveLicenseSet)) { - return false; - } - return setsEquivalent((ConjunctiveLicenseSet)compare); - } - - protected boolean setsEquivalent(ConjunctiveLicenseSet compare) throws InvalidSPDXAnalysisException { - List compInfos; - try { - compInfos = compare.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting compare license set members",e); - } - List myInfos; - try { - myInfos = this.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting license set members",e); - } - if (compInfos.size() != myInfos.size()) { - return false; - } - for (AnyLicenseInfo myInfo:myInfos) { - if (!compInfos.contains(myInfo)) { - boolean found = false; - for (AnyLicenseInfo compInfo:compInfos) { - if (myInfo.equivalent(compInfo)) { - found = true; - break; - } - } - if (!found) { - return false; - } - } - } - return true; - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_CONJUNCTIVE_LICENSE_SET; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java b/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java deleted file mode 100644 index a143159b3..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/CrossRef.java +++ /dev/null @@ -1,435 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IModelStoreLock; - -/** - * Cross reference details for the a URL reference - * - * @author Gary O'Neall - * - */ -public class CrossRef extends ModelObject { - - /** - * @throws InvalidSPDXAnalysisException - */ - public CrossRef() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public CrossRef(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public CrossRef(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @param builder Builder to build the file - * @throws InvalidSPDXAnalysisException - */ - protected CrossRef(CrossRefBuilder builder) throws InvalidSPDXAnalysisException { - this(builder.modelStore, builder.documentUri, builder.id, builder.copyManager, true); - setLive(builder.live); - setMatch(builder.match); - setOrder(builder.order); - setTimestamp(builder.timestamp); - setUrl(builder.url); - setValid(builder.valid); - setIsWayBackLink(builder.wayBackLink); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_CROSS_REF; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - Optional url; - try { - url = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL); - if (!url.isPresent()) { - retval.add("Missing required URL"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting URL property value: "+e.getMessage()); - } - return retval; - } - - /** - * @return the match - * @throws InvalidSPDXAnalysisException - */ - public Optional getMatch() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH); - } - - /** - * @param match the match to set - * @throws InvalidSPDXAnalysisException - */ - public void setMatch(@Nullable String match) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH, match); - } - - /** - * @return the url - * @throws InvalidSPDXAnalysisException - */ - public Optional getUrl() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL); - } - - /** - * @param url the url to set - * @throws InvalidSPDXAnalysisException - */ - public void setUrl(String url) throws InvalidSPDXAnalysisException { - if (strict) { - Objects.requireNonNull(url, "URL must not be null"); - } - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL, url); - } - - /** - * @return the isValid - * @throws InvalidSPDXAnalysisException - */ - public Optional getValid() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID); - } - - /** - * @param isValid the isValid to set - * @throws InvalidSPDXAnalysisException - */ - public void setValid(@Nullable Boolean isValid) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID, isValid); - } - - /** - * @return the isLive - * @throws InvalidSPDXAnalysisException - */ - public Optional getLive() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE); - } - - /** - * @param isLive the isLive to set - * @throws InvalidSPDXAnalysisException - */ - public void setLive(Boolean isLive) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE, isLive); - } - - /** - * @return the timestamp - * @throws InvalidSPDXAnalysisException - */ - public Optional getTimestamp() throws InvalidSPDXAnalysisException { - return getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP); - } - - /** - * @param timestamp the timestamp to set - * @throws InvalidSPDXAnalysisException - */ - public void setTimestamp(String timestamp) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP, timestamp); - } - - /** - * @return the isWayBackLink - * @throws InvalidSPDXAnalysisException - */ - public Optional getIsWayBackLink() throws InvalidSPDXAnalysisException { - return getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK); - } - - /** - * @param isWayBackLink the isWayBackLink to set - * @throws InvalidSPDXAnalysisException - */ - public void setIsWayBackLink(Boolean isWayBackLink) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK, isWayBackLink); - } - - /** - * @return the order - * @throws InvalidSPDXAnalysisException - */ - public Optional getOrder() throws InvalidSPDXAnalysisException { - return getIntegerPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER); - } - - /** - * @param order the order to set - * @throws InvalidSPDXAnalysisException - */ - public void setOrder(Integer order) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER, order); - } - - /** - * Convenience method for setting details related to the URL checking - * @param isValid - * @param isLive - * @param isWayBackLink - * @param match - * @param timestamp - * @throws InvalidSPDXAnalysisException - */ - public void setDetails(@Nullable Boolean isValid, @Nullable Boolean isLive, @Nullable Boolean isWayBackLink, - @Nullable String match, @Nullable String timestamp) throws InvalidSPDXAnalysisException { - setValid(isValid); - setLive(isLive); - setIsWayBackLink(isWayBackLink); - setMatch(match); - setTimestamp(timestamp); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString(){ - String url; - try { - Optional oUrl = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_URL); - if (oUrl.isPresent()) { - url = oUrl.get(); - } else { - url = "N/A"; - } - } catch (InvalidSPDXAnalysisException e) { - url = "N/A"; - } - - String isValid; - try { - Optional oIsValid = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID); - if (oIsValid.isPresent()) { - isValid = oIsValid.get().toString(); - } else { - isValid = "N/A"; - } - } catch (InvalidSPDXAnalysisException e) { - isValid = "N/A"; - } - String isLive; - try { - Optional oIsLive = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE); - - if (oIsLive.isPresent()) { - isLive = oIsLive.get().toString(); - } else { - isLive = "N/A"; - } - } catch (InvalidSPDXAnalysisException e) { - isLive = "N/A"; - } - String isWayBackLink; - try { - Optional oWayback = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK); - if (oWayback.isPresent()) { - isWayBackLink = oWayback.get().toString(); - } else { - isWayBackLink = "N/A"; - } - } catch (InvalidSPDXAnalysisException e) { - isWayBackLink = "N/A"; - } - String match; - try { - Optional oMatch = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH); - - if (oMatch.isPresent()) { - match = oMatch.get(); - } else { - match = "N/A"; - } - } catch (InvalidSPDXAnalysisException e) { - match = "N/A"; - } - String timestamp; - try { - Optional oTimestamp = getStringPropertyValue(SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP); - if (oTimestamp.isPresent()) { - timestamp = oTimestamp.get(); - } else { - timestamp = "N/A"; - } - } catch (InvalidSPDXAnalysisException e) { - timestamp = "N/A"; - } - String crossRefDetails = String.format("{%s: %s,%s: %s,%s: %s,%s: %s,%s: %s,%s: %s}", - SpdxConstantsCompatV2.PROP_CROSS_REF_URL, url, - SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID, isValid, - SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE, isLive, - SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK, isWayBackLink, - SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH, match, - SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP, timestamp); - return crossRefDetails; - } - - public static class CrossRefBuilder { - // required fields - Model Object - IModelStore modelStore; - String documentUri; - String id; - ModelCopyManager copyManager; - - // required fields - String url; - - // optional fields - String match; - Boolean valid; - Boolean live; - String timestamp; - Boolean wayBackLink; - Integer order; - - /** - * Create a CrossRef with the required parameters - * @param modelStore Storage for the model objects - * @param documentUri SPDX Document URI for a document associated with this model - * @param objectUri ID for this object - must be unique within the SPDX document - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param url URL for the CrossRef - */ - public CrossRefBuilder(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, String url) { - Objects.requireNonNull(modelStore, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - Objects.requireNonNull(id, "ID can not be null"); - Objects.requireNonNull(url, "URL can not be null"); - this.modelStore = modelStore; - this.documentUri = documentUri; - this.id = id; - this.url = url; - this.copyManager = copyManager; - } - - public CrossRefBuilder setMatch(@Nullable String match) { - this.match = match; - return this; - } - - /** - * @param url the url to set - */ - public CrossRefBuilder setUrl(String url) { - Objects.requireNonNull(url, "URL must not be null"); - this.url = url; - return this; - } - - /** - * @param valid the valid to set - */ - public CrossRefBuilder setValid(@Nullable Boolean valid) { - this.valid = valid; - return this; - } - - /** - * @param live the live to set - */ - public CrossRefBuilder setLive(@Nullable Boolean live) { - this.live = live; - return this; - } - - /** - * @param timestamp the timestamp to set - */ - public CrossRefBuilder setTimestamp(@Nullable String timestamp) { - this.timestamp = timestamp; - return this; - } - - /** - * @param wayBackLink the wayBackLink to set - */ - public CrossRefBuilder setWayBackLink(@Nullable Boolean wayBackLink) { - this.wayBackLink = wayBackLink; - return this; - } - - /** - * @param order the order to set - */ - public CrossRefBuilder setOrder(@Nullable Integer order) { - this.order = order; - return this; - } - - /** - * @return CrossRef built from the supplied parameters - * @throws InvalidSPDXAnalysisException - */ - public CrossRef build() throws InvalidSPDXAnalysisException { - IModelStoreLock lock = modelStore.enterCriticalSection(false); - try { - return new CrossRef(this); - } finally { - modelStore.leaveCriticalSection(lock); - } - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java deleted file mode 100644 index 2abb833e8..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/DisjunctiveLicenseSet.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * A set of licenses where there is a choice of one of the licenses in the set - * @author Gary O'Neall - * - */ -public class DisjunctiveLicenseSet extends LicenseSet { - - public DisjunctiveLicenseSet() throws InvalidSPDXAnalysisException { - super(); - } - - public DisjunctiveLicenseSet(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public DisjunctiveLicenseSet(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#toString() - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder("("); - boolean moreThanOne = false; - Iterator iter; - try { - iter = this.getMembers().iterator(); - while (iter.hasNext()) { - if (moreThanOne) { - sb.append(" OR "); - } - moreThanOne = true; - sb.append(iter.next().toString()); - } - sb.append(')'); - return sb.toString(); - } catch (InvalidSPDXAnalysisException e) { - return "ERROR RETRIEVING LICENSE SET MEMBERS"; - } - - } - - @Override - public int hashCode() { - int retval = 41; // Prime number - List allMembers; - try { - allMembers = this.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - for (AnyLicenseInfo member:allMembers) { - retval = retval ^ member.hashCode(); - } - return retval; - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof DisjunctiveLicenseSet)) { - // covers o == null, as null is not an instance of anything - return false; - } - DisjunctiveLicenseSet comp = (DisjunctiveLicenseSet)o; - List compInfos; - try { - compInfos = comp.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - List myInfos; - try { - myInfos = this.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - if (compInfos.size() != myInfos.size()) { - return false; - } - for (AnyLicenseInfo myInfo:myInfos) { - if (!compInfos.contains(myInfo)) { - return false; - } - } - return true; - } - - /** - * Disjunctive license sets can contain other conjunctive license sets as members. Logically, - * the members of these "sub-disjunctive license sets" could be direct members and have the same - * meaning. - * @return all members "flattening out" disjunctive license sets which are members of this set - * @throws SpdxInvalidTypeException - */ - protected List getFlattenedMembers() throws InvalidSPDXAnalysisException { - HashSet retval = new HashSet<>(); // Use a set since any duplicated elements would be still considered equal - Iterator iter = this.getMembers().iterator(); - while (iter.hasNext()) { - AnyLicenseInfo li = iter.next(); - if (li instanceof DisjunctiveLicenseSet) { - // we need to flatten this out - retval.addAll(((DisjunctiveLicenseSet)li).getFlattenedMembers()); - } else { - retval.add(li); - } - } - ArrayList retvallist = new ArrayList<>(); - retvallist.addAll(retval); - return retvallist; - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.model.IRdfModel#equivalent(org.spdx.rdfparser.model.IRdfModel) - */ - @Override - public boolean equivalent(ModelObject compare) throws InvalidSPDXAnalysisException { - if (!(compare instanceof DisjunctiveLicenseSet)) { - return false; - } - return setsEquivalent((DisjunctiveLicenseSet)compare); - } - - private boolean setsEquivalent(DisjunctiveLicenseSet compare) throws InvalidSPDXAnalysisException { - List compInfos; - try { - compInfos = compare.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting compare license set members",e); - } - List myInfos; - try { - myInfos = this.getFlattenedMembers(); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException("Error getting license set members",e); - } - if (compInfos.size() != myInfos.size()) { - return false; - } - for (AnyLicenseInfo myInfo:myInfos) { - if (!compInfos.contains(myInfo)) { - boolean found = false; - for (AnyLicenseInfo compInfo:compInfos) { - if (myInfo.equivalent(compInfo)) { - found = true; - break; - } - } - if (!found) { - return false; - } - } - } - return true; - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_DISJUNCTIVE_LICENSE_SET; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java deleted file mode 100644 index 4862a95fb..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ExternalExtractedLicenseInfo.java +++ /dev/null @@ -1,317 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Matcher; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ExternalDocumentRef; -import org.spdx.library.model.compat.v2.ExternalSpdxElement; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * @author Gary O'Neall - * - * This class represents an ExtractedLicenseInfo which is stored in an external SPDX document. - * - * Note that the actual properties for this ExtractedLicenseInfo is in an external document so - * it is not accessible through this class. - * - * The set methods will cause an exception. - * - * The getExtractedText() will return text that indicates the actual license text - * is in an external document. - * - * The ID must be in the form SpdxConstantsCompatV2.EXTERNAL_LICENSE_REF_PATTERN.pattern() - * - */ -public class ExternalExtractedLicenseInfo extends AbstractExtractedLicenseInfo implements IndividualUriValue { - - // Note: the default empty constructor is not allowed since the license ID must follow a specific pattern - - public ExternalExtractedLicenseInfo(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public ExternalExtractedLicenseInfo(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - if (!SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id).matches()) { - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); - } - getExternalExtractedLicenseURI(); //this will check to make sure the external document reference is available - } - - /** - * @return external document ID for the external reference - * @throws InvalidSPDXAnalysisException - */ - public String getExternalDocumentId() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); - if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); - } - return matcher.group(1); - } - - /** - * @return element ID used in the external document - * @throws InvalidSPDXAnalysisException - */ - public String getExternalLicenseRef() throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(this.getId()); - if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); - } - return matcher.group(2); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_EXTERNAL_EXTRACTED_LICENSE; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.SpdxElement#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - // we don't want to call super.verify since we really don't require those fields - List retval = new ArrayList<>(); - String id = this.getId(); - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(id); - if (!matcher.matches()) { - retval.add("Invalid objectUri format for an external document reference. Must be of the form "+SpdxConstantsCompatV2.EXTERNAL_ELEMENT_REF_PATTERN.pattern()); - } else { - try { - ExternalSpdxElement.externalDocumentIdToNamespace(matcher.group(1), getModelStore(), getDocumentUri(), getCopyManager()); - } catch (InvalidSPDXAnalysisException e) { - retval.add(e.getMessage()); - } - } - return retval; - } - - /** - * @return the URI associated with this external SPDX Extracted License - * @throws InvalidSPDXAnalysisException - */ - public String getExternalExtractedLicenseURI() throws InvalidSPDXAnalysisException { - return externalExtractedLicenseIdToURI(getId(), getModelStore(), getDocumentUri(), getCopyManager()); - } - - /** - * @param externalExtractedLicenseId - * @param stModelStore - * @param stDocumentUri - * @param copyManager - * @return The URI associated with the external LicenseRef with the ID externalLicenseRefId - * @throws InvalidSPDXAnalysisException - */ - public static String externalExtractedLicenseIdToURI(String externalExtractedLicenseId, - IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_PATTERN.matcher(externalExtractedLicenseId); - if (!matcher.matches()) { - logger.error("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); - throw new InvalidSPDXAnalysisException("Invalid objectUri format for an external document reference. Must be of the form ExternalSPDXRef:LicenseRef-XXX"); - } - String externalDocumentUri; - externalDocumentUri = ExternalSpdxElement.externalDocumentIdToNamespace(matcher.group(1), stModelStore, stDocumentUri, copyManager); - if (externalDocumentUri.endsWith("#")) { - return externalDocumentUri + matcher.group(2); - } else { - return externalDocumentUri + "#" + matcher.group(2); - } - } - - /** - * @param externalLicenseUri URI of the form - * externaldocumentnamespace#LicenseRef-XXXXX - * @param stModelStore - * @param stDocumentUri - * @return ExternalSpdxRef an ExternalLicenseRef based on a URI of the form - * externaldocumentnamespace#LicenseRef-XXXXX - * @param copyManager if non-null, create the external doc ref if it is not - * already in the ModelStore - * @throws InvalidSPDXAnalysisException - */ - public static ExternalExtractedLicenseInfo uriToExternalExtractedLicense(String externalLicenseUri, IModelStore stModelStore, - String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - return new ExternalExtractedLicenseInfo(stModelStore, stDocumentUri, uriToExternalExtractedLicenseId( - externalLicenseUri, stModelStore, stDocumentUri, copyManager), copyManager, true); - } - - /** - * Convert a URI to an ID for an External Extracted License - * @param uri URI with the external document namespace and the external Extracted License in the form namespace#LicenseRef-XXXX - * @param stModelStore - * @param stDocumentUri - * @param copyManager if non-null, create the external doc ref if it is not already in the ModelStore - * @return external SPDX element ID in the form DocumentRef-XX:LicenseRef-XXXX - * @throws InvalidSPDXAnalysisException - */ - public static String uriToExternalExtractedLicenseId(String uri, - IModelStore stModelStore, String stDocumentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(uri, "URI can not be null"); - Matcher matcher = SpdxConstantsCompatV2.EXTERNAL_EXTRACTED_LICENSE_URI_PATTERN.matcher(uri); - if (!matcher.matches()) { - throw new InvalidSPDXAnalysisException("Invalid URI format: "+uri+". Expects namespace#LicenseRef-XXXX"); - } - Optional externalDocRef = ExternalDocumentRef.getExternalDocRefByDocNamespace(stModelStore, stDocumentUri, - matcher.group(1), copyManager); - if (!externalDocRef.isPresent()) { - logger.error("Could not find or create the external document reference for document namespace "+ matcher.group(1)); - throw new InvalidSPDXAnalysisException("Could not find or create the external document reference for document namespace "+ matcher.group(1)); - } - return externalDocRef.get().getId() + ":" + matcher.group(2); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject) - */ - @Override - public boolean equivalent(ModelObject compare) { - if (!(compare instanceof ExternalExtractedLicenseInfo)) { - return false; - } - return getId().equals(compare.getId()); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject, boolean) - */ - @Override - public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - return equivalent(compare); - } - - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.IndividualUriValue#getIndividualURI() - */ - @Override - public String getIndividualURI() { - try { - return getExternalExtractedLicenseURI(); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting external LicenseRef URI",e); - throw new RuntimeException(e); - } - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.license.AbstractExtractedLicenseInfo#getExtractedText() - */ - @Override - public String getExtractedText() throws InvalidSPDXAnalysisException { - return "The text for this license can be found in the external document " - + getExternalDocumentId() - + " license Ref " - + getExternalLicenseRef() - + "."; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getComment() - */ - @Override - public String getComment() throws InvalidSPDXAnalysisException { - return "This is an external LicenseRef - see the document containing the license for any comments"; - } - - /** - * @param comment the comment to set - * @throws InvalidSPDXAnalysisException - */ - @Override - public void setComment(String comment) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set comment for an external LicenseRef. " - + "Changes to the license need to be made within the document containing the license."); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getSeeAlso() - */ - @Override - public Collection getSeeAlso() throws InvalidSPDXAnalysisException { - return new ArrayList<>(); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#setSeeAlso(java.util.Collection) - */ - @Override - public void setSeeAlso(Collection seeAlsoUrl) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set seeAlso for an external LicenseRef. " - + "Changes to the license need to be made within the document containing the license."); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#getName() - */ - @Override - public String getName() throws InvalidSPDXAnalysisException { - return ""; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.license.SimpleLicensingInfo#setName(java.lang.String) - */ - @Override - public void setName(String name) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Can not set name for an external LicenseRef. " - + "Changes to the license need to be made within the document containing the license."); - } - - @Override - public boolean equals(Object comp) { - return SimpleUriValue.isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return SimpleUriValue.getIndividualUriValueHash(this); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java deleted file mode 100644 index 67b20c84d..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ExtractedLicenseInfo.java +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright (c) 2011, 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxVerificationHelper; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.utility.compare.LicenseCompareHelper; - -/** - * An ExtractedLicensingInfo represents a license or licensing notice that was found in the package. - * Any license text that is recognized as a license may be represented as a License - * rather than an ExtractedLicensingInfo. - * @author Gary O'Neall - * - */ -public class ExtractedLicenseInfo extends AbstractExtractedLicenseInfo { - - public ExtractedLicenseInfo() throws InvalidSPDXAnalysisException { - super(DefaultModelStore.getDefaultModelStore().getNextId(IdType.LicenseRef, DefaultModelStore.getDefaultDocumentUri())); - } - - public ExtractedLicenseInfo(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * Create a new ExtractedLicenseInfo object - * @param modelStore container which includes the license - * @param documentUri URI for the SPDX document containing the license - * @param objectUri identifier for the license - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license if it does not exist - * @throws InvalidSPDXAnalysisException - */ - public ExtractedLicenseInfo(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * Create a new ExtractedLicenseInfo using the ID and text - * @param objectUri - * @param text - * @throws InvalidSPDXAnalysisException - */ - public ExtractedLicenseInfo(String id, String text) throws InvalidSPDXAnalysisException { - super(id); - this.setExtractedText(text); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO; - } - - /** - * @return the text - * @throws SpdxInvalidTypeException - */ - public String getExtractedText() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXTRACTED_TEXT); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param text the text to set - * @throws InvalidSPDXAnalysisException - */ - public void setExtractedText(String text) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_EXTRACTED_TEXT, text); - } - - /** - * @return - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - String id = this.getLicenseId(); - if (id == null || id.isEmpty()) { - retval.add("Missing required license ID"); - } else { - String idError = SpdxVerificationHelper.verifyNonStdLicenseid(id); - if (idError != null && !idError.isEmpty()) { - retval.add(idError); - } - } - try { - String licenseText = this.getExtractedText(); - if (licenseText == null || licenseText.isEmpty()) { - retval.add("Missing required license text for " + id); - } - if (LicenseExpressionParser.UNINITIALIZED_LICENSE_TEXT.equals(licenseText)) { - retval.add("License not found for " + id); - } - } catch (InvalidSPDXAnalysisException ex) { - retval.add("Unable to fetch license text: "+ex.getMessage()); - } - return retval; - } - - @Override - public boolean equivalent(ModelObject compare) throws InvalidSPDXAnalysisException { - if (compare instanceof ExtractedLicenseInfo) { - // Only test for the text - other fields do not need to equal to be considered equivalent - return LicenseCompareHelper.isLicenseTextEquivalent(this.getExtractedText(), ((ExtractedLicenseInfo)compare).getExtractedText()); - } else { - return false; - } - } - - @Override - public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - return equivalent(compare); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java b/src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java deleted file mode 100644 index ec24787ee..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/InvalidLicenseStringException.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.spdx.library.model.compat.v2.license; - -import org.spdx.library.InvalidSPDXAnalysisException; - -public class InvalidLicenseStringException extends InvalidSPDXAnalysisException { - private static final long serialVersionUID = -1688466911486933160L; - public InvalidLicenseStringException(String message) { - super(message); - } - public InvalidLicenseStringException(String message, Throwable inner) { - super(message, inner); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/License.java b/src/main/java/org/spdx/library/model/compat/v2/license/License.java deleted file mode 100644 index 4f7641ada..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/License.java +++ /dev/null @@ -1,329 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringEscapeUtils; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.ModelUpdate; -import org.spdx.utility.compare.LicenseCompareHelper; - -/** - * Describes a license - * - * All licenses have an ID. - * Subclasses should extend this class to add additional properties. - * - * @author Gary O'Neall - * - */ -public abstract class License extends SimpleLicensingInfo { - - static final String XML_LITERAL = "^^http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"; - - /** - * True if the template in the model uses HTML tags. If this flag is true, the text will - * be converted on import from the model. - */ - private boolean templateInHtml = false; - - - /** - * Open or create a model object with the default store and default document URI - * @param objectUri ID for this object - must be unique within the SPDX document - * @throws InvalidSPDXAnalysisException - */ - public License(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * Create a new License object - * @param modelStore container which includes the license - * @param documentUri URI for the SPDX document containing the license - * @param objectUri identifier for the license - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license if it does not exist - * @throws InvalidSPDXAnalysisException - */ - License(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @return the text of the license - * @throws SpdxInvalidTypeException - */ - public String getLicenseText() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param text the license text to set - * @throws InvalidSPDXAnalysisException - */ - public void setLicenseText(String text) throws InvalidSPDXAnalysisException { - this.setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT, text); - } - - /** - * @return the standardLicenseHeader - * @throws SpdxInvalidTypeException - */ - public String getStandardLicenseHeader() throws InvalidSPDXAnalysisException { - Optional standardLicenseHeader = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE); - if (standardLicenseHeader.isPresent()) { - return StringEscapeUtils.unescapeHtml4(standardLicenseHeader.get()); - } else { - return ""; - } - } - - /** - * @return standard license header template - * @throws SpdxInvalidTypeException - */ - public String getStandardLicenseHeaderTemplate() throws InvalidSPDXAnalysisException { - Optional standardLicenseHeaderTemplate = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE); - if (standardLicenseHeaderTemplate.isPresent()) { - return StringEscapeUtils.unescapeHtml4(standardLicenseHeaderTemplate.get()); - } else { - return ""; - } - } - - /** - * @param standardLicenseHeaderTemplate - * @throws InvalidSPDXAnalysisException - */ - public void setStandardLicenseHeaderTemplate(String standardLicenseHeaderTemplate) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE, standardLicenseHeaderTemplate); - } - - /** - * @param standardLicenseHeader the standardLicenseHeader to set - * @throws InvalidSPDXAnalysisException - */ - public void setStandardLicenseHeader(String standardLicenseHeader) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE, standardLicenseHeader); - } - /** - * @return the template - * @throws SpdxInvalidTypeException - */ - public String getStandardLicenseTemplate() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE); - if (!o.isPresent()) { - return ""; - } - String standardLicenseTemplate = o.get(); - if (standardLicenseTemplate != null && standardLicenseTemplate.endsWith(XML_LITERAL)) { - standardLicenseTemplate = standardLicenseTemplate.substring(0, standardLicenseTemplate.length()-XML_LITERAL.length()); - } - if (standardLicenseTemplate != null && this.templateInHtml) { - standardLicenseTemplate = SpdxLicenseTemplateHelper.htmlToText(standardLicenseTemplate); - } - return standardLicenseTemplate; - } - /** - * @param template the template to set - * @throws InvalidSPDXAnalysisException - */ - public void setStandardLicenseTemplate(String template) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE, template); - } - - @Override - public String toString() { - // must be only the ID if we want to reuse the - // toString for creating parseable license info strings - if (this.getId() == null) { - return "NULL LICENSE"; - } else { - return this.getId(); - } - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - String id = this.getLicenseId(); - if (id == null || id.isEmpty()) { - retval.add("Missing required license ID"); - } - String name; - try { - name = this.getName(); - if (name == null || name.isEmpty()) { - retval.add("Missing required license name"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for name"); - } - try { - this.getComment(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for comment"); - } - try { - this.getSeeAlso(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for seeAlso"); - } - try { - this.getStandardLicenseHeader(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for standard license header"); - } - try { - this.getStandardLicenseTemplate(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for standard license template"); - } - //TODO Add test for template - try { - this.getStandardLicenseHeaderTemplate(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for standard license header template"); - } - //TODO add test for license header template - String licenseText; - try { - licenseText = this.getLicenseText(); - if (licenseText == null || licenseText.isEmpty()) { - retval.add("Missing required license text for " + id); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for license text"); - } - return retval; - } - - /** - * @return true if FSF describes the license as free / libre, false if FSF describes the license as not free / libre or if FSF does not reference the license - * @throws SpdxInvalidTypeException - * @throws InvalidSPDXAnalysisException - */ - public boolean isFsfLibre() throws InvalidSPDXAnalysisException { - Optional libre = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); - if (!libre.isPresent()) { - return false; - } - return libre.get(); - } - - /** - * @return true if FSF specified this license as not free/libre, false if it has been specified by the FSF as free / libre or if it has not been specified - * @throws SpdxInvalidTypeException - */ - public boolean isNotFsfLibre() throws InvalidSPDXAnalysisException { - Optional fsfLibre = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); - return fsfLibre.isPresent() && !fsfLibre.get(); - } - - /** - * @return true if FSF describes the license as free / libre, false if FSF describes the license as not free / libre, null if FSF does not reference the license - * @throws SpdxInvalidTypeException - */ - public Boolean getFsfLibre() throws InvalidSPDXAnalysisException { - Optional libre = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); - if (libre.isPresent()) { - return libre.get(); - } else { - return null; - } - } - - - /** - * @return true if the license is listed as an approved license on the OSI website - * @throws SpdxInvalidTypeException - */ - public boolean isOsiApproved() throws InvalidSPDXAnalysisException { - Optional osiApproved = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED); - return osiApproved.isPresent() && osiApproved.get(); - } - - /** - * @return true if this license is marked as being deprecated - * @throws SpdxInvalidTypeException - */ - public boolean isDeprecated() throws InvalidSPDXAnalysisException { - Optional deprecated = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED); - return deprecated.isPresent() && deprecated.get(); - } - - public void setOsiApproved(Boolean osiApproved) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED, osiApproved); - } - - /** - * @param fsfLibre true if FSF describes the license as free / libre, false if FSF describes the license as not free / libre, null if FSF does not reference the license - * @throws InvalidSPDXAnalysisException - */ - public void setFsfLibre(Boolean fsfLibre) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE, fsfLibre); - } - - /** - * @param deprecated true if this license is deprecated - * @throws InvalidSPDXAnalysisException - */ - public void setDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, deprecated); - } - - /** - * @param deprecated - * @return a ModelUpdate that can be applied through the ModelObject - * @throws InvalidSPDXAnalysisException - */ - public ModelUpdate updateSetDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisException { - return updatePropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, deprecated); - } - - @Override - public boolean equivalent(ModelObject compare, boolean ignoreExternalReferences) throws InvalidSPDXAnalysisException { - if (compare instanceof License) { - return LicenseCompareHelper.isLicenseTextEquivalent(this.getLicenseText(), ((License)compare).getLicenseText()); - } else { - return super.equivalent(compare, ignoreExternalReferences); - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java deleted file mode 100644 index ef5c1ae14..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseException.java +++ /dev/null @@ -1,323 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * - * Represents an SPDX license exception as defined in the License Expression Language - * Used with the "with" unary expression. - * - * @author Gary O'Neall - * - */ -public class LicenseException extends ModelObject { - - /** - * Create a new LicenseException object - * @param modelStore container which includes the license exception - * @param documentUri URI for the SPDX document containing the license exception - * @param objectUri identifier for the license exception - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license exception if it does not exist - * @throws InvalidSPDXAnalysisException - */ - public LicenseException(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, copyManager, create); - if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec - } - } - - public LicenseException(String id, String name, String text, - Collection seeAlso, String comment) throws InvalidSPDXAnalysisException { - this(id, name, text); - setSeeAlso(seeAlso); - setComment(comment); - } - - public LicenseException(String id, String name, String text, - String template, Collection seeAlso, String comment) throws InvalidSPDXAnalysisException { - this(id, name, text, seeAlso, comment); - setLicenseExceptionTemplate(template); - } - - public LicenseException(String id, String name, String text) throws InvalidSPDXAnalysisException { - super(DefaultModelStore.getDefaultModelStore(), SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, - DefaultModelStore.getDefaultCopyManager(), true); - setName(name); - setLicenseExceptionText(text); - if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, id); // Set a property with the exception ID per the spec - } - } - - /** - * @return Comment associated with the License Exception - * @throws InvalidSPDXAnalysisException - */ - public String getComment() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param comment the comment to set - * @throws InvalidSPDXAnalysisException - */ - public void setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - } - - /** - * Deprecated since SPDX spec 2.0 - * @return example text - * @throws InvalidSPDXAnalysisException - */ - @Deprecated - public String getExample() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXAMPLE); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * Deprecated since SPDX spec 2.0 - * @param example - * @throws InvalidSPDXAnalysisException - */ - @Deprecated - public void setExample(String example) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_EXAMPLE, example); - } - - /** - * @return the objectUri - */ - public String getLicenseExceptionId() { - return getId(); - } - - /** - * @return the template - * @throws InvalidSPDXAnalysisException - */ - public String getLicenseExceptionTemplate() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * Set the template text for the exception - * @param template template - * @throws InvalidSPDXAnalysisException - */ - public void setLicenseExceptionTemplate(String template) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE, template); - } - - /** - * @return the text - * @throws InvalidSPDXAnalysisException - */ - public String getLicenseExceptionText() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * Sets the text for the exception - * @param text text - * @throws InvalidSPDXAnalysisException - */ - public void setLicenseExceptionText(String text) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, text); - } - - - /** - * @return the name - * @throws SpdxInvalidTypeException - */ - public String getName() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param name the name to set - * @throws InvalidSPDXAnalysisException - */ - public void setName(String name) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME, name); - } - - /** - * @return the urls which reference the same license information - * @throws SpdxInvalidTypeException - */ - public Collection getSeeAlso() throws InvalidSPDXAnalysisException { - return getStringCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); - } - /** - * @param seeAlso the urls which are references to the same license to set - * @throws InvalidSPDXAnalysisException - */ - public void setSeeAlso(Collection seeAlso) throws InvalidSPDXAnalysisException { - if (seeAlso == null) { - clearValueCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); - } else { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso); - } - } - - /** - * @return true if this license is marked as being deprecated - * @throws SpdxInvalidTypeException - */ - public boolean isDeprecated() throws InvalidSPDXAnalysisException { - Optional deprecated = getBooleanPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED); - return deprecated.isPresent() && deprecated.get(); - } - - /** - * @param deprecated true if this license is deprecated - * @throws InvalidSPDXAnalysisException - */ - public void setDeprecated(Boolean deprecated) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, deprecated); - } - - /** - * @return the deprecatedVersion - * @throws SpdxInvalidTypeException - */ - public String getDeprecatedVersion() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param deprecatedVersion the deprecatedVersion to set - * @throws InvalidSPDXAnalysisException - */ - public void setDeprecatedVersion(String deprecatedVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, deprecatedVersion); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_LICENSE_EXCEPTION; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - String id = this.getLicenseExceptionId(); - if (id == null || id.isEmpty()) { - retval.add("Missing required exception ID"); - } - String name; - try { - name = this.getName(); - if (name == null || name.isEmpty()) { - retval.add("Missing required exception name"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for name"); - } - try { - this.getComment(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for comment"); - } - try { - this.getSeeAlso(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for seeAlso"); - } - try { - this.getLicenseExceptionTemplate(); - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for exception template"); - } - String exceptionText; - try { - exceptionText = this.getLicenseExceptionText(); - if (exceptionText == null || exceptionText.trim().isEmpty()) { - retval.add("Missing required exception text for " + id); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for exception text"); - } - return retval; - } - - @Override - public String toString() { - return this.getId(); - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java deleted file mode 100644 index 2256904a8..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParser.java +++ /dev/null @@ -1,376 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EmptyStackException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Stack; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.ModelStorageClassConverter; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - -/** - * A parser for the SPDX License Expressions as documented in the SPDX appendix. - * - * This is a static help class. The primary method is parseLicenseExpression which - * returns an AnyLicenseInfo. - * @author Gary O'Neall - * - */ -public class LicenseExpressionParser { - - enum Operator { - OR_LATER, WITH, AND, OR //NOTE: These must be in precedence order - }; - static final String LEFT_PAREN = "("; - static final String RIGHT_PAREN = ")"; - static final Map OPERATOR_MAP = new HashMap<>(); - public static final String UNINITIALIZED_LICENSE_TEXT = "[Initialized with license Parser. The actual license text is not available]"; - - static { - OPERATOR_MAP.put("+", Operator.OR_LATER); - OPERATOR_MAP.put("AND", Operator.AND); - OPERATOR_MAP.put("OR", Operator.OR); - OPERATOR_MAP.put("WITH", Operator.WITH); - OPERATOR_MAP.put("and", Operator.AND); - OPERATOR_MAP.put("or", Operator.OR); - OPERATOR_MAP.put("with", Operator.WITH); - } - /** - * Parses a license expression into an license for use in the Model - * @param expression Expression to be parsed - * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If - * none exist for an ID, they will be added. If null, the default model store will be used. - * @param documentUri Document URI for the document containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If - * none exist for an ID, they will be added. If null, the default model document URI will be used. - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @return the parsed license expression - * @throws InvalidSPDXAnalysisException - */ - static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore store, - String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (expression == null || expression.trim().isEmpty()) { - throw new LicenseParserException("Empty license expression"); - } - Objects.requireNonNull(store, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - String[] tokens = tokenizeExpression(expression); - if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) { - return new SpdxNoAssertionLicense(); - } else if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NONE_VALUE)) { - return new SpdxNoneLicense(); - } else { - try { - return parseLicenseExpression(tokens, store, documentUri, copyManager); - } catch (LicenseParserException ex) { - // Add the expression to the error message to provide additional information to the user - throw new LicenseParserException(ex.getMessage()+" License expression: '"+expression+"'", ex); - } catch (EmptyStackException ex) { - throw new LicenseParserException("Invalid license expression: '"+expression+"' - check that every operator (e.g. AND and OR) has operators and that parenthesis are matched"); - } - } - } - - /** - * A custom tokenizer since there is not white space between parents and pluses - * @param expression - * @return - */ - private static String[] tokenizeExpression(String expression) { - String[] startTokens = expression.split("\\s"); - List endTokens = new ArrayList<>(); - for (String token : startTokens) { - processPreToken(token, endTokens); - } - return endTokens.toArray(new String[endTokens.size()]); - } - - /** - * @param preToken - * @param tokenList - */ - private static void processPreToken(String preToken, - List tokenList) { - if (preToken.isEmpty()) { - return; - } else if (preToken.startsWith("(")) { - tokenList.add("("); - processPreToken(preToken.substring(1), tokenList); - } else if (preToken.endsWith(")")) { - processPreToken(preToken.substring(0, preToken.length()-1), tokenList); - tokenList.add(")"); - } else if (preToken.endsWith("+")) { - processPreToken(preToken.substring(0, preToken.length()-1), tokenList); - tokenList.add("+"); - } else { - tokenList.add(preToken); - } - } - - /** - * Parses a tokenized license expression into a license for use in the RDF Parser - * @param tokens - * @param store - * @param documentUri - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @return - * @throws InvalidSPDXAnalysisException - */ - private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStore store, - String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (tokens == null || tokens.length == 0) { - throw new LicenseParserException("Expected license expression"); - } - Stack operandStack = new Stack(); - Stack operatorStack = new Stack(); - int tokenIndex = 0; - String token; - while (tokenIndex < tokens.length) { - token = tokens[tokenIndex++]; - // left operand - if (LEFT_PAREN.equals(token)) { - int rightParenIndex = findMatchingParen(tokens, tokenIndex); - if (rightParenIndex < 0) { - throw new LicenseParserException("Missing right parenthesis"); - } - String[] nestedTokens = Arrays.copyOfRange(tokens, tokenIndex, rightParenIndex); - operandStack.push(parseLicenseExpression(nestedTokens, store, documentUri, copyManager)); - tokenIndex = rightParenIndex + 1; - } else if (OPERATOR_MAP.get(token) == null) { // assumed to be a simple licensing type - operandStack.push(parseSimpleLicenseToken(token, store, documentUri, copyManager)); - } else { - Operator operator = OPERATOR_MAP.get(token); - if (operator == Operator.WITH) { - // special processing here since With must be with an exception, not a licenseInfo - if (!operatorStack.isEmpty() && Operator.OR_LATER.equals(operatorStack.peek())) { - Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); - } - if (tokenIndex >= tokens.length) { - throw new LicenseParserException("Missing exception clause"); - } - token = tokens[tokenIndex++]; - LicenseException licenseException = null; - Optional exceptionId = Optional.empty(); - if (LicenseInfoFactory.isSpdxListedExceptionId(token)) { - exceptionId = LicenseInfoFactory.listedExceptionIdCaseSensitive(token); - } - if (exceptionId.isPresent()) { - licenseException = LicenseInfoFactory.getListedExceptionById(exceptionId.get()); - } else if (token.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { - throw new LicenseParserException("WITH must be followed by a license exception. "+token+" is a Listed License type."); - } else { - licenseException = (ListedLicenseException) SpdxModelFactory.createModelObjectV2(store, - documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, copyManager); - } - AnyLicenseInfo operand = operandStack.pop(); - if (operand == null) { - throw new LicenseParserException("Missing license for with clause"); - } - if (!((operand instanceof SimpleLicensingInfo) || (operand instanceof OrLaterOperator))) { - throw new LicenseParserException("License with exception is not of type SimpleLicensingInfo or OrLaterOperator"); - } - WithExceptionOperator weo = new WithExceptionOperator(store, documentUri, store.getNextId(IdType.Anonymous, documentUri), copyManager, true); - weo.setLicense(operand); - weo.setException(licenseException); - operandStack.push(weo); - } else { - // process in order of precedence using the shunting yard algorithm - while (!operatorStack.isEmpty() && - operatorStack.peek().ordinal() <= operator.ordinal()) { - Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); - } - operatorStack.push(operator); - } - } - } - // go through the rest of the stack - while (!operatorStack.isEmpty()) { - Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); - } - AnyLicenseInfo retval = operandStack.pop(); - if (!operandStack.isEmpty()) { - throw new LicenseParserException("Invalid license expression. Expecting more operands."); - } - return retval; - } - - /** - * Returns the index of the rightmost parenthesis or -1 if not found - * @param tokens - * @return - */ - private static int findMatchingParen(String[] tokens, int startToken) { - if (tokens == null) { - return -1; - } - int nestCount = 0; - for (int i = startToken; i < tokens.length; i++) { - if (LEFT_PAREN.equals(tokens[i])) { - nestCount++; - } else if (RIGHT_PAREN.equals(tokens[i])) { - if (nestCount == 0) { - return i; - } else { - nestCount--; - } - } - } - return -1; - } - - /** - * Converts a string token into its equivalent license - * checking for a listed license - * @param token - * @param baseStore - * @param documentUri - * @param copyManager - * @return - * @throws InvalidSPDXAnalysisException - */ - private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String documentUri, - ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(token, "Token can not be null"); - Objects.requireNonNull(store, "Model store can not be null"); - Objects.requireNonNull(documentUri, "Document URI can not be null"); - if (token.contains(":")) { - // External License Ref - return new ExternalExtractedLicenseInfo(store, documentUri, token, copyManager, true); - } - Optional licenseId = Optional.empty(); - if (LicenseInfoFactory.isSpdxListedLicenseId(token)) { - // listed license - licenseId = LicenseInfoFactory.listedLicenseIdCaseSensitive(token); - } - if (licenseId.isPresent()) { - if (!store.exists(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId.get())) { - SpdxListedLicense listedLicense = LicenseInfoFactory.getListedLicenseById(licenseId.get()); - if (Objects.nonNull(copyManager)) { - // copy to the local store - copyManager.copy(store, listedLicense.getObjectUri(), listedLicense.getModelStore(), - listedLicense.getObjectUri(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, - listedLicense.getDocumentUri(), listedLicense.getDocumentUri(), - listedLicense.getDocumentUri(), listedLicense.getDocumentUri()); - } - } - return (AnyLicenseInfo) ModelStorageClassConverter.storedObjectToModelObject( - new TypedValue(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId.get(), - SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE), - documentUri, store, copyManager); - } else { - // LicenseRef - Optional caseSensitiveId = store.getCaseSensisitiveId(documentUri, token); - ExtractedLicenseInfo localLicense = null; - if (caseSensitiveId.isPresent()) { - localLicense = new ExtractedLicenseInfo(store, documentUri, caseSensitiveId.get(), copyManager, false); - - } else { - localLicense = (ExtractedLicenseInfo) SpdxModelFactory.createModelObjectV2( - store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); - localLicense.setExtractedText(UNINITIALIZED_LICENSE_TEXT); - } - return localLicense; - } - } - - /** - * Evaluate the given operator using paramaeters in the parameter stack - * @param operator - * @param operandStack - * @param copyManager - * @throws InvalidSPDXAnalysisException - */ - private static void evaluateExpression(Operator operator, - Stack operandStack, IModelStore store, - String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (operator == Operator.OR_LATER) { - // unary operator - AnyLicenseInfo license = operandStack.pop(); - if (!(license instanceof SimpleLicensingInfo)) { - throw new LicenseParserException("Missing license for the '+' or later operator"); - } - OrLaterOperator olo = new OrLaterOperator(store, documentUri, store.getNextId(IdType.Anonymous, documentUri), copyManager, true); - olo.setLicense((SimpleLicensingInfo)license); - operandStack.push(olo); - } else { - // binary operator - AnyLicenseInfo operand2 = operandStack.pop(); - AnyLicenseInfo operand1 = operandStack.pop(); - if (operand1 == null || operand2 == null) { - throw new LicenseParserException("Missing operands for the "+operator.toString()+" operator"); - } - operandStack.push(evaluateBinary(operator, operand1, operand2, store, documentUri, copyManager)); - } - } - - /** - * Evaluates a binary expression and merges conjuctive and disjunctive licenses - * @param tosOperator - * @param operand1 - * @param operand2 - * @param copyManager - * @return - * @throws InvalidSPDXAnalysisException - */ - private static AnyLicenseInfo evaluateBinary(Operator tosOperator, - AnyLicenseInfo operand1, AnyLicenseInfo operand2, IModelStore store, - String documentUri, ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - if (tosOperator == Operator.AND) { - if (operand1 instanceof ConjunctiveLicenseSet) { - // just merge into operand1 - ((ConjunctiveLicenseSet) operand1).addMember(operand2); - return operand1; - } else { - ConjunctiveLicenseSet retval = new ConjunctiveLicenseSet(store, documentUri, - store.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.addMember(operand1); - retval.addMember(operand2); - return retval; - } - } else if (tosOperator == Operator.OR) { - if (operand1 instanceof DisjunctiveLicenseSet) { - // just merge into operand1 - ((DisjunctiveLicenseSet) operand1).addMember(operand2); - return operand1; - } else { - DisjunctiveLicenseSet retval = new DisjunctiveLicenseSet(store, documentUri, - store.getNextId(IdType.Anonymous, documentUri), copyManager, true); - retval.addMember(operand1); - retval.addMember(operand2); - return retval; - } - } else { - throw new LicenseParserException("Unknown operator "+tosOperator.toString()); - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java deleted file mode 100644 index 385dc8299..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseInfoFactory.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.storage.IModelStore; - -/** - * Factory for creating SPDXLicenseInfo objects from a Jena model - * @author Gary O'Neall - */ -public class LicenseInfoFactory { - - static final Logger logger = LoggerFactory.getLogger(LicenseInfoFactory.class.getName()); - - public static final String NOASSERTION_LICENSE_NAME = "NOASSERTION"; - public static final String NONE_LICENSE_NAME = "NONE"; - - /** - * @param licenseId SPDX Listed License ID - * @return SPDX listed license or null if the ID is not in the SPDX license list - * @throws InvalidSPDXAnalysisException - */ - public static SpdxListedLicense getListedLicenseById(String licenseId)throws InvalidSPDXAnalysisException { - return ListedLicenses.getListedLicenses().getListedLicenseById(licenseId); - } - - /** - * Parses a license string and converts it into a SPDXLicenseInfo object - * Syntax - A license set must start and end with a parenthesis "(" - * A conjunctive license set will have and AND after the first - * licenseInfo term - * A disjunctive license set will have an OR after the first - * licenseInfo term - * If there is no And or Or, then it is converted to a simple - * license type - * A space or tab must be used between license ID's and the - * keywords AND and OR - * A licenseID must NOT be "AND" or "OR" - * @param licenseString String conforming to the syntax - * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If - * none exist for an ID, they will be added. If null, the default model store will be used. - * @param documentUri Document URI for the document containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If - * none exist for an ID, they will be added. If null, the default model document URI will be used. - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @return an SPDXLicenseInfo created from the string - * @throws InvalidLicenseStringException - */ - public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, - @Nullable String documentUri, @Nullable ModelCopyManager copyManager) throws InvalidLicenseStringException { - if (Objects.isNull(store)) { - store = DefaultModelStore.getDefaultModelStore(); - } - if (Objects.isNull(documentUri)) { - documentUri = DefaultModelStore.getDefaultDocumentUri(); - } - if (Objects.isNull(copyManager)) { - copyManager = DefaultModelStore.getDefaultCopyManager(); - } - try { - return LicenseExpressionParser.parseLicenseExpression(licenseString, store, documentUri, copyManager); - } catch (LicenseParserException e) { - throw new InvalidLicenseStringException(e.getMessage(),e); - } catch (InvalidSPDXAnalysisException e) { - throw new InvalidLicenseStringException("Unexpected SPDX error parsing license string"); - } - } - - /** - * Parses a license string and converts it into a SPDXLicenseInfo object - * Syntax - A license set must start and end with a parenthesis "(" - * A conjunctive license set will have and AND after the first - * licenseInfo term - * A disjunctive license set will have an OR after the first - * licenseInfo term - * If there is no And or Or, then it is converted to a simple - * license type - * A space or tab must be used between license ID's and the - * keywords AND and OR - * A licenseID must NOT be "AND" or "OR" - * @param licenseString String conforming to the syntax - * @return an SPDXLicenseInfo created from the string - * @throws InvalidLicenseStringException - */ - public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException { - return parseSPDXLicenseString(licenseString, null, null, null); - } - - - - /** - * @param licenseID case insensitive - * @return true if the licenseID belongs to an SPDX listed license - */ - public static boolean isSpdxListedLicenseId(String licenseID) { - return ListedLicenses.getListedLicenses().isSpdxListedLicenseId(licenseID); - } - - /** - * @return Array of all SPDX listed license IDs - */ - public static List getSpdxListedLicenseIds() { - return ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); - } - - /** - * @return Version of the license list being used by the SPDXLicenseInfoFactory - */ - public static String getLicenseListVersion() { - return ListedLicenses.getListedLicenses().getLicenseListVersion(); - } - - /** - * @param objectUri exception ID - * @return true if the exception ID is a supported SPDX listed exception - */ - public static boolean isSpdxListedExceptionId(String id) { - return ListedLicenses.getListedLicenses().isSpdxListedExceptionId(id); - } - - /** - * @param objectUri - * @return the standard SPDX license exception or null if the ID is not in the SPDX license list - * @throws InvalidSPDXAnalysisException - */ - public static ListedLicenseException getListedExceptionById(String id) throws InvalidSPDXAnalysisException { - return ListedLicenses.getListedLicenses().getListedExceptionById(id); - } - - /** - * @param licenseId case insensitive license ID - * @return the case sensitive license ID - */ - public static Optional listedLicenseIdCaseSensitive(String licenseId) { - return ListedLicenses.getListedLicenses().listedLicenseIdCaseSensitive(licenseId); - } - - /** - * @param exceptionId case insensitive exception ID - * @return case sensitive ID - */ - public static Optional listedExceptionIdCaseSensitive(String exceptionId) { - return ListedLicenses.getListedLicenses().listedExceptionIdCaseSensitive(exceptionId); - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java deleted file mode 100644 index e827b0c76..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseParserException.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.spdx.library.model.compat.v2.license; - -import org.spdx.library.InvalidSPDXAnalysisException; - -public class LicenseParserException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * @param msg - */ - public LicenseParserException(String msg) { - super(msg); - } - - public LicenseParserException(String msg, Throwable inner) { - super(msg, inner); - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java b/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java deleted file mode 100644 index dc946c0a7..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/LicenseSet.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import javax.annotation.Nullable; - -/** - * A specific form of license information where there is a set of licenses - * represented - * @author Gary O'Neall - * - */ -public abstract class LicenseSet extends AnyLicenseInfo { - - //TODO: Check for recursive references when adding or setting license ID's - currently, this ends badly in an infinite loop on toString - - Collection members; - - - /** - * @throws InvalidSPDXAnalysisException - */ - public LicenseSet() throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore().getNextId(IdType.Anonymous, DefaultModelStore.getDefaultDocumentUri())); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public LicenseSet(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param create - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - LicenseSet(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - members = (Collection)(Collection)getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, AnyLicenseInfo.class); - } - - /** - * Sets the members of the license set. Clears any previous members - * @param licenseInfos New members for the set - * @throws InvalidSPDXAnalysisException - */ - public void setMembers(Collection licenseInfos) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, licenseInfos); - } - - /** - * @return Members of the license set - * @throws SpdxInvalidTypeException - */ - public Collection getMembers() throws InvalidSPDXAnalysisException { - return members; - } - - /** - * Adds a member to the set - * @param member - * @throws InvalidSPDXAnalysisException - */ - public void addMember(AnyLicenseInfo member) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(member, "Member can not be null"); - members.add(member); - } - - public void removeMember(AnyLicenseInfo member) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(member, "Member can not be null"); - members.remove(member); - } - - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - Iterator iter; - try { - iter = getMembers().iterator(); - while (iter.hasNext()) { - retval.addAll(iter.next().verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Exception getting license set members: "+e.getMessage()); - } - return retval; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java deleted file mode 100644 index 645e8d8b2..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenseException.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.Collection; -import java.util.Optional; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.licenseTemplate.LicenseTemplateRuleException; -import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; -import org.spdx.storage.IModelStore; - -/** - * Represents a License Exception present on the SPDX License List - * - * @author Gary O'Neall - * - */ -public class ListedLicenseException extends LicenseException { - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public ListedLicenseException(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @param objectUri - * @param name - * @param text - * @param seeAlso - * @param comment - * @throws InvalidSPDXAnalysisException - */ - public ListedLicenseException(String id, String name, String text, Collection seeAlso, String comment) - throws InvalidSPDXAnalysisException { - super(id, name, text, seeAlso, comment); - } - - /** - * @param objectUri - * @param name - * @param text - * @param template - * @param seeAlso - * @param comment - * @throws InvalidSPDXAnalysisException - */ - public ListedLicenseException(String id, String name, String text, String template, Collection seeAlso, - String comment) throws InvalidSPDXAnalysisException { - super(id, name, text, template, seeAlso, comment); - } - - /** - * @param objectUri - * @param name - * @param text - * @throws InvalidSPDXAnalysisException - */ - public ListedLicenseException(String id, String name, String text) throws InvalidSPDXAnalysisException { - super(id, name, text); - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION; - } - - /** - * @param exceptionTextHtml - * @throws InvalidSPDXAnalysisException - */ - public void setExceptionTextHtml(String exceptionTextHtml) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML, exceptionTextHtml); - } - - /** - * @return HTML form of the exception text either from a stored property or generated from the template or text - * @throws InvalidSPDXAnalysisException - */ - public String getExceptionTextHtml() throws InvalidSPDXAnalysisException { - Optional exceptionTextHtml = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML); - if (exceptionTextHtml.isPresent()) { - return exceptionTextHtml.get(); - } else { - Optional templateText = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE); - if (templateText.isPresent()) { - try { - return SpdxLicenseTemplateHelper.templateTextToHtml(templateText.get()); - } catch(LicenseTemplateRuleException ex) { - throw new InvalidSPDXAnalysisException("Invalid license rule found in exception text for exception "+getName()+":"+ex.getMessage()); - } - } else { - Optional exceptionText = getStringPropertyValue(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT); - if (exceptionText.isPresent()) { - return SpdxLicenseTemplateHelper.formatEscapeHTML(exceptionText.get()); - } else { - return ""; - } - } - } - } - - @Override - public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (compare instanceof ListedLicenseException) { - return this.getId().equals(((ListedLicenseException)compare).getId()); // for listed license, the license ID is the only thing that matters - } else { - return super.equivalent(compare, ignoreRelatedElements); - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java b/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java deleted file mode 100644 index 5acfcd292..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/ListedLicenses.java +++ /dev/null @@ -1,249 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Properties; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxModelFactory; -import org.spdx.storage.IModelStore; -import org.spdx.storage.listedlicense.IListedLicenseStore; -import org.spdx.storage.listedlicense.SpdxListedLicenseLocalStore; -import org.spdx.storage.listedlicense.SpdxListedLicenseWebStore; - -/** - * Singleton class which holds the listed licenses - * - * @author Gary O'Neall - * - */ -public class ListedLicenses { - - static final Logger logger = LoggerFactory.getLogger(ListedLicenses.class.getName()); - private static final String PROPERTIES_DIR = "resources"; - private static final String LISTED_LICENSE_PROPERTIES_FILENAME = PROPERTIES_DIR + "/" + "licenses.properties"; - - Properties licenseProperties; - boolean onlyUseLocalLicenses; - private IListedLicenseStore licenseModelStore; - private static ListedLicenses listedLicenses = null; - /** - * Lock for any modifications to the underlying licenseModelStore - */ - private static final ReadWriteLock listedLicenseModificationLock = new ReentrantReadWriteLock(); - - /** - * This constructor should only be called by the getListedLicenses method - */ - private ListedLicenses() { - licenseProperties = loadLicenseProperties(); - onlyUseLocalLicenses = Boolean.parseBoolean( - System.getProperty("SPDXParser.OnlyUseLocalLicenses", licenseProperties.getProperty("OnlyUseLocalLicenses", "false"))); - initializeLicenseModelStore(); - } - - /** - * Tries to load properties from LISTED_LICENSE_PROPERTIES_FILENAME, ignoring errors - * encountered during the process (e.g., the properties file doesn't exist, etc.). - * - * @return a (possibly empty) set of properties - */ - private static Properties loadLicenseProperties() { - listedLicenseModificationLock.writeLock().lock(); - try { - Properties licenseProperties = new Properties(); - InputStream in = null; - try { - in = ListedLicenses.class.getResourceAsStream("/" + LISTED_LICENSE_PROPERTIES_FILENAME); - if (in != null) { - licenseProperties.load(in); - } - } catch (IOException e) { - // Ignore it and fall through - logger.warn("IO Exception reading listed license properties file: " + e.getMessage()); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - logger.warn("Unable to close listed license properties file: " + e.getMessage()); - } - } - } - return licenseProperties; - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - private void initializeLicenseModelStore() { - listedLicenseModificationLock.writeLock().lock(); - try { - if (!this.onlyUseLocalLicenses) { - try { - licenseModelStore = new SpdxListedLicenseWebStore(); - } catch(InvalidSPDXAnalysisException ex) { - logger.error("Unable to access the most current listed licenses from https://spdx.org/licenses - using locally cached licenses: "+ex.getMessage()); - licenseModelStore = null; - } - } - if (licenseModelStore == null) { - try { - licenseModelStore = new SpdxListedLicenseLocalStore(); - } catch(InvalidSPDXAnalysisException ex) { - logger.error("Error loading cached SPDX licenses"); - throw new RuntimeException("Unexpected error loading SPDX Listed Licenses"); - } - } - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - - - public static ListedLicenses getListedLicenses() { - - ListedLicenses retval = null; - listedLicenseModificationLock.readLock().lock(); - try { - retval = listedLicenses; - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (Objects.isNull(retval)) { - listedLicenseModificationLock.writeLock().lock(); - try { - if (listedLicenses == null) { - listedLicenses = new ListedLicenses(); - } - retval = listedLicenses; - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - return retval; - } - - /** - * Resets all of the cached license information and reloads the license IDs - * NOTE: This method should be used with caution, it will negatively impact - * performance. - * @return - */ - public static ListedLicenses resetListedLicenses() { - listedLicenseModificationLock.writeLock().lock(); - try { - listedLicenses = new ListedLicenses(); - return listedLicenses; - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - - /** - * @param licenseId case insensitive - * @return true if the licenseId belongs to an SPDX listed license - */ - public boolean isSpdxListedLicenseId(String licenseId) { - return this.licenseModelStore.isSpdxListedLicenseId(SpdxConstantsCompatV2.LISTED_LICENSE_URL, licenseId); - } - - /** - * @param exceptionId case insensitive - * @return true if the exceptionId belongs to an SPDX listed exception - */ - public boolean isSpdxListedExceptionId(String exceptionId) { - return this.licenseModelStore.isSpdxListedExceptionId(SpdxConstantsCompatV2.LISTED_LICENSE_URL, exceptionId); - } - - /** - * @param licenseId SPDX Listed License ID - * @return SPDX listed license or null if the ID is not in the SPDX license list - * @throws InvalidSPDXAnalysisException - */ - public SpdxListedLicense getListedLicenseById(String licenseId) throws InvalidSPDXAnalysisException { - return (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); - } - - public ListedLicenseException getListedExceptionById(String exceptionId) throws InvalidSPDXAnalysisException { - return (ListedLicenseException)SpdxModelFactory.createModelObjectV2(this.licenseModelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); - } - - /** - * @return List of all SPDX listed license IDs - */ - public List getSpdxListedLicenseIds() { - listedLicenseModificationLock.readLock().lock(); - try { - return this.licenseModelStore.getSpdxListedLicenseIds(); - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - /** - * @return The version of the loaded license list in the form M.N, where M is the major release and N is the minor release. - * If no license list is loaded, returns {@link org.spdx.storage.listedlicense.SpdxListedLicenseModelStore#DEFAULT_LICENSE_LIST_VERSION}. - */ - public String getLicenseListVersion() { - return this.licenseModelStore.getLicenseListVersion(); - } - - /** - * @return list of SPDX exception IDs - */ - public List getSpdxListedExceptionIds() { - return this.licenseModelStore.getSpdxListedExceptionIds(); - } - - /** - * @param licenseId case insensitive license ID - * @return the case sensitive license ID - */ - public Optional listedLicenseIdCaseSensitive(String licenseId) { - return this.licenseModelStore.listedLicenseIdCaseSensitive(licenseId); - } - - /** - * @param exceptionId case insensitive exception ID - * @return case sensitive ID - */ - public Optional listedExceptionIdCaseSensitive(String exceptionId) { - return this.licenseModelStore.listedExceptionIdCaseSensitive(exceptionId); - } - - /** - * @return model store for listed licenses - */ - public IModelStore getLicenseModelStore() { - return this.licenseModelStore; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java b/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java deleted file mode 100644 index 53c78d3ee..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/OrLaterOperator.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Copyright (c) 2015 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - - -/** - * A license that has an or later operator (e.g. GPL-2.0+) - * @author Gary O'Neall - * - */ -public class OrLaterOperator extends AnyLicenseInfo { - - public OrLaterOperator() throws InvalidSPDXAnalysisException { - super(); - } - - public OrLaterOperator(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - public OrLaterOperator(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * Create a new OrLaterOperator applied to license using the same ModelStore and DocumentURI as the license - * @param license License the OrLater applies to - * @throws InvalidSPDXAnalysisException - */ - public OrLaterOperator(SimpleLicensingInfo license) throws InvalidSPDXAnalysisException { - super(license.getModelStore(), license.getDocumentUri(), - license.getModelStore().getNextId(IdType.Anonymous, license.getDocumentUri()), - license.getCopyManager(), true); - setLicense(license); - } - - /** - * @return the license - * @throws SpdxInvalidTypeException - */ - public SimpleLicensingInfo getLicense() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); - if (!retval.isPresent()) { - throw new SpdxInvalidTypeException("Missing required license for OrLater operator"); - } - if (!(retval.get() instanceof SimpleLicensingInfo)) { - throw new SpdxInvalidTypeException("Expecting SimpleLicensingInfo for or operator license type. Found "+retval.getClass().toString()); - } - return (SimpleLicensingInfo)retval.get(); - } - - /** - * @param license the license to set - * @throws InvalidSPDXAnalysisException - */ - public void setLicense(SimpleLicensingInfo license) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, license); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#toString() - */ - @Override - public String toString() { - SimpleLicensingInfo license; - try { - license = getLicense(); - } catch (InvalidSPDXAnalysisException e) { - return "ERROR GETTING ORLATER LICENSE"; - } - if (license == null) { - return "UNDEFINED OR EXCEPTION"; - } - return license.toString() + "+"; - } - - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - SimpleLicensingInfo license; - try { - license = getLicense(); - if (license == null) { - retval.add("Missing required license for a License Or Later operator"); - } else { - retval.addAll(license.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Exception getting license for OrLater: "+e.getMessage()); - } - return retval; - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_OR_LATER_OPERATOR; - } - - @Override - public boolean equals(Object compare) { - if (!(compare instanceof OrLaterOperator)) { - return false; - } - SimpleLicensingInfo cLic; - try { - cLic = ((OrLaterOperator)compare).getLicense(); - return Objects.equals(this.getLicense(), cLic); - } catch (InvalidSPDXAnalysisException e) { - throw new RuntimeException(e); - } - } - - @Override - public int hashCode() { - int licHashCode = 101; - try { - if (this.getLicense() != null) { - licHashCode = this.getLicense().hashCode() ^ 101; - } - } catch (InvalidSPDXAnalysisException e) { - // Ignore - use the null value - } - return licHashCode; - } -} \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java b/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java deleted file mode 100644 index e442c1f76..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SimpleLicensingInfo.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright (c) 2015, 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.Collection; -import java.util.Optional; - -import javax.annotation.Nullable; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.storage.IModelStore; - - -/** - * The SimpleLicenseInfo class includes all resources that represent - * simple, atomic, licensing information. - * - * @author Gary O'Neall - * - */ -public abstract class SimpleLicensingInfo extends AnyLicenseInfo { - - /** - * Open or create a model object with the default store and default document URI - * @param objectUri ID for this object - must be unique within the SPDX document - * @throws InvalidSPDXAnalysisException - */ - SimpleLicensingInfo(String id) throws InvalidSPDXAnalysisException { - super(id); - if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_ID, id); // Needs to be set as a property per spec - } - } - - /** - * Create a new SimpleLicensingInfo object - * @param modelStore container which includes the license - * @param documentUri URI for the SPDX document containing the license - * @param objectUri identifier for the license - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license if it does not exist - * @throws InvalidSPDXAnalysisException - */ - SimpleLicensingInfo(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - if (!(this instanceof IndividualUriValue)) { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_ID, id); // Needs to be set as a property per spec - } - } - - /** - * @return the license ID without the enclosing namespace - */ - public String getLicenseId() { - return this.getId(); - } - - /** - * @return the name - * @throws SpdxInvalidTypeException - */ - public String getName() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param name the name to set - * @throws InvalidSPDXAnalysisException - */ - public void setName(String name) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME, name); - } - - /** - * @return the comments - * @throws SpdxInvalidTypeException - */ - public String getComment() throws InvalidSPDXAnalysisException { - Optional o = getStringPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); - if (o.isPresent()) { - return o.get(); - } else { - return ""; - } - } - - /** - * @param comment the comment to set - * @throws InvalidSPDXAnalysisException - */ - public void setComment(String comment) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, comment); - } - - /** - * @return the urls which reference the same license information - * @throws SpdxInvalidTypeException - */ - public Collection getSeeAlso() throws InvalidSPDXAnalysisException { - return getStringCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); - } - /** - * @param seeAlsoUrl the urls which are references to the same license to set - * @throws InvalidSPDXAnalysisException - */ - public void setSeeAlso(Collection seeAlsoUrl) throws InvalidSPDXAnalysisException { - if (seeAlsoUrl == null) { - clearValueCollection(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); - } else { - setPropertyValue(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlsoUrl); - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java deleted file mode 100644 index a540c0020..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicense.java +++ /dev/null @@ -1,369 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.licenseTemplate.InvalidLicenseTemplateException; -import org.spdx.licenseTemplate.LicenseTemplateRuleException; -import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; -import org.spdx.storage.IModelStore; - -/** - * Listed license for SPDX as listed at spdx.org/licenses - * @author Gary O'Neall - * - */ -public class SpdxListedLicense extends License { - - Collection crossRef; - - /** - * Open or create a model object with the default store and default document URI - * @param objectUri ID for this object - must be unique within the SPDX document - * @throws InvalidSPDXAnalysisException - */ - public SpdxListedLicense(String id) throws InvalidSPDXAnalysisException { - this(DefaultModelStore.getDefaultModelStore(), SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, - DefaultModelStore.getDefaultCopyManager(), true); - } - - /** - * Create a new SPDX Listed License object - * @param modelStore container which includes the license - * @param documentUri URI for the SPDX document containing the license - * @param objectUri identifier for the license - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create if true, create the license if it does not exist - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public SpdxListedLicense(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, SpdxConstantsCompatV2.LISTED_LICENSE_URL, id, copyManager, create); - crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); - } - - /** - * @param name License name - * @param objectUri License ID - * @param text License text - * @param sourceUrl Optional URLs that reference this license - * @param comments Optional comments - * @param standardLicenseHeader Optional license header - * @param template Optional template - * @param osiApproved True if this is an OSI Approved license - * @param fsfLibre true if FSF describes the license as free / libre, false if FSF describes the license as not free / libre, null if FSF does not reference the license - * @param licenseTextHtml HTML version for the license text - * @param isDeprecated True if this license has been designated as deprecated by the SPDX legal team - * @param deprecatedVersion License list version when this license was first deprecated (null if not deprecated) - * @throws InvalidSPDXAnalysisException - */ - @SuppressWarnings("unchecked") - public SpdxListedLicense(String name, String id, String text, Collection sourceUrl, String comments, - String standardLicenseHeader, String template, boolean osiApproved, Boolean fsfLibre, - String licenseTextHtml, boolean isDeprecated, String deprecatedVersion) throws InvalidSPDXAnalysisException { - this(id); - setName(name); - setLicenseText(text); - setSeeAlso(sourceUrl); - setComment(comments); - setStandardLicenseHeader(standardLicenseHeader); - setStandardLicenseTemplate(template); - setOsiApproved(osiApproved); - setFsfLibre(fsfLibre); - setLicenseTextHtml(licenseTextHtml); - setDeprecated(isDeprecated); - setDeprecatedVersion(deprecatedVersion); - crossRef = (Collection)(Collection)this.getObjectPropertyValueSet(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class); - } - - /** - * @param builder Builder configured with desired parameters - * @throws InvalidSPDXAnalysisException - */ - public SpdxListedLicense(SpdxListedLicense.Builder builder) throws InvalidSPDXAnalysisException { - this(builder.name, builder.id, builder.text, builder.sourceUrl, builder.comments, builder.standardLicenseHeader, - builder.template, builder.osiApproved, builder.fsfLibre, builder.licenseTextHtml, builder.isDeprecated, - builder.deprecatedVersion); - this.crossRef.addAll(builder.crossRefs); - } - - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - try { - if (this.isDeprecated()) { - retval.add(this.getLicenseId() + " is deprecated."); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Invalid type for SPDX license isDeprecated"); - } - return retval; - } - - /** - * @return HTML fragment containing the License Text - * @throws InvalidLicenseTemplateException - * @throws SpdxInvalidTypeException - */ - public String getLicenseTextHtml() throws InvalidLicenseTemplateException, InvalidSPDXAnalysisException { - Optional licenseTextHtml = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML); - if (licenseTextHtml.isPresent()) { - return licenseTextHtml.get(); - } else { - // Format the HTML using the text and template - String templateText = this.getStandardLicenseTemplate(); - if (templateText != null && !templateText.trim().isEmpty()) { - try { - return SpdxLicenseTemplateHelper.templateTextToHtml(templateText); - } catch(LicenseTemplateRuleException ex) { - throw new InvalidLicenseTemplateException("Invalid license expression found in license text for license "+getName()+":"+ex.getMessage()); - } - } else { - return SpdxLicenseTemplateHelper.formatEscapeHTML(this.getLicenseText()); - } - } - } - - /** - * Set the licenseTextHtml - * @param licenseTextHtml HTML fragment representing the license text - * @throws InvalidSPDXAnalysisException - */ - public void setLicenseTextHtml(String licenseTextHtml) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML, licenseTextHtml); - } - - /** - * @return HTML fragment containing the License standard header text - * @throws InvalidLicenseTemplateException - * @throws SpdxInvalidTypeException - */ - public String getLicenseHeaderHtml() throws InvalidLicenseTemplateException, InvalidSPDXAnalysisException { - Optional licenseHeaderHtml = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML); - if (licenseHeaderHtml.isPresent()) { - return licenseHeaderHtml.get(); - } else { - // Format the HTML using the text and template - String templateText = this.getStandardLicenseHeaderTemplate(); - if (templateText != null && !templateText.trim().isEmpty()) { - try { - return SpdxLicenseTemplateHelper.templateTextToHtml(templateText); - } catch(LicenseTemplateRuleException ex) { - throw new InvalidLicenseTemplateException("Invalid license expression found in standard license header for license "+getName()+":"+ex.getMessage()); - } - } else { - return SpdxLicenseTemplateHelper.formatEscapeHTML(this.getStandardLicenseHeader()); - } - } - } - - /** - * Set the licenseHeaderTemplateHtml - * @param licenseHeaderHtml HTML fragment representing the license standard header text - * @throws InvalidSPDXAnalysisException - */ - public void setLicenseHeaderHtml(String licenseHeaderHtml) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML, licenseHeaderHtml); - } - - /** - * @return the deprecatedVersion - * @throws SpdxInvalidTypeException - */ - public String getDeprecatedVersion() throws InvalidSPDXAnalysisException { - Optional depVersion = getStringPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION); - if (depVersion.isPresent()) { - return depVersion.get(); - } else { - return ""; - } - } - - /** - * @param deprecatedVersion the deprecatedVersion to set - * @throws InvalidSPDXAnalysisException - */ - public void setDeprecatedVersion(String deprecatedVersion) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, deprecatedVersion); - } - - public Collection getCrossRef() throws InvalidSPDXAnalysisException { - return this.crossRef; - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE; - } - - @Override - public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException { - if (compare instanceof SpdxListedLicense) { - return this.getLicenseId().equals(((SpdxListedLicense)compare).getLicenseId()); // for listed license, the license ID is the only thing that matters - } else { - return super.equivalent(compare, ignoreRelatedElements); - } - } - - @Override - public boolean equals(Object compare) { - if (!(compare instanceof SpdxListedLicense)) { - return false; - } - return Objects.equals(getLicenseId(),((SpdxListedLicense)compare).getLicenseId()); - } - - @Override - public int hashCode() { - String licId = getLicenseId(); - if (Objects.isNull(licId)) { - return 91; - } else { - return 91 ^ licId.hashCode(); - } - } - - public static class Builder { - private String id; - private String name; - private String text; - private Collection sourceUrl; - private String comments; - private String standardLicenseHeader; - private String template; - private boolean osiApproved; - private Boolean fsfLibre; - private String licenseTextHtml; - private boolean isDeprecated; - private String deprecatedVersion; - private List crossRefs = new ArrayList(); - - /** - * @param name License name - * @param objectUri License ID - * @param text License text - */ - public Builder(String id, String name, String text) { - this.id = id; - this.name = name; - this.text = text; - } - - /** - * @param sourceUrl Optional URLs that reference this license - * @return this to continue the build - */ - public Builder setSourceUrl(Collection sourceUrl) { - this.sourceUrl = sourceUrl; - return this; - } - - /** - * @param comments Optional comments - * @return this to continue the build - */ - public Builder setComments(String comments) { - this.comments = comments; - return this; - } - - /** - * @param standardLicenseHeader Optional license header - * @return this to continue the build - */ - public Builder setStandardLicenseHeader(String standardLicenseHeader) { - this.standardLicenseHeader = standardLicenseHeader; - return this; - } - - /** - * @param template Optional template - * @return this to continue the build - */ - public Builder setTemplate(String template) { - this.template = template; - return this; - } - - /** - * @param osiApproved True if this is an OSI Approved license - * @return this to continue the build - */ - public Builder setOsiApproved(boolean osiApproved) { - this.osiApproved = osiApproved; - return this; - } - - /** - * @param fsfLibre true if FSF describes the license as free / libre, false if FSF describes the license - * as not free / libre, null if FSF does not reference the license - * @return this to continue the build - */ - public Builder setFsfLibre(Boolean fsfLibre) { - this.fsfLibre = fsfLibre; - return this; - } - - /** - * @param licenseTextHtml HTML version for the license text - * @return this to continue the build - */ - public Builder setLicenseTextHtml(String licenseTextHtml) { - this.licenseTextHtml = licenseTextHtml; - return this; - } - - /** - * @param isDeprecated True if this license has been designated as deprecated by the SPDX legal team - * @return this to continue the build - */ - public Builder setIsDeprecated(boolean isDeprecated) { - this.isDeprecated = isDeprecated; - return this; - } - - /** - * @param deprecatedVersion License list version when this license was first deprecated (null if not deprecated) - * @return this to continue the build - */ - public Builder setDeprecatedVersion(String deprecatedVersion) { - this.deprecatedVersion = deprecatedVersion; - return this; - } - - public Builder addCrossRefs(CrossRef crossRef) { -; this.crossRefs.add(crossRef); - return this; - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java deleted file mode 100644 index b7d1a42ee..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxListedLicenseException.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import org.spdx.library.InvalidSPDXAnalysisException; - -/** - * @author gary - * - */ -public class SpdxListedLicenseException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public SpdxListedLicenseException() { - } - - /** - * @param arg0 - */ - public SpdxListedLicenseException(String arg0) { - super(arg0); - } - - /** - * @param arg0 - */ - public SpdxListedLicenseException(Throwable arg0) { - super(arg0); - } - - /** - * @param arg0 - * @param arg1 - */ - public SpdxListedLicenseException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - /** - * @param arg0 - * @param arg1 - * @param arg2 - * @param arg3 - */ - public SpdxListedLicenseException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { - super(arg0, arg1, arg2, arg3); - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java deleted file mode 100644 index fd6a9f90f..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoAssertionLicense.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * Special class of license to represent no asserted license license in the file or packages - * @author Gary O'Neall - * - */ -public class SpdxNoAssertionLicense extends AnyLicenseInfo implements IndividualUriValue { - - static final String NOASSERTION_LICENSE_ID = "NOASSERTION_LICENSE_ID"; - - /** - * Create a new No Assertion license with the default store and default document URI - * @throws InvalidSPDXAnalysisException - */ - public SpdxNoAssertionLicense() throws InvalidSPDXAnalysisException { - super(NOASSERTION_LICENSE_ID); - } - - public SpdxNoAssertionLicense(IModelStore modelStore, String documentUri) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, NOASSERTION_LICENSE_ID, null, true); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#toString() - */ - @Override - public String toString() { - return SpdxConstantsCompatV2.NOASSERTION_VALUE; - } - - @Override - public boolean equals(Object comp) { - return SimpleUriValue.isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return SimpleUriValue.getIndividualUriValueHash(this); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#verify() - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - return new ArrayList<>(); - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_NOASSERTION_LICENSE; - } - - @Override - public String getIndividualURI() { - return SpdxConstantsCompatV2.URI_VALUE_NOASSERTION; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java b/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java deleted file mode 100644 index 7daa50421..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/SpdxNoneLicense.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright (c) 2011 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * A special license meaning that no license was found - * @author Gary O'Neall - * - */ -public class SpdxNoneLicense extends AnyLicenseInfo implements IndividualUriValue { - - static final String NONE_LICENSE_ID = "SPDX_NONE_LICENSE"; - - /** - * Create a new NoneLicense with the default store and default document URI - * @throws InvalidSPDXAnalysisException - */ - public SpdxNoneLicense() throws InvalidSPDXAnalysisException { - super(NONE_LICENSE_ID); - } - - public SpdxNoneLicense(IModelStore modelStore, String documentUri) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, NONE_LICENSE_ID, null, true); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#toString() - */ - @Override - public String toString() { - return SpdxConstantsCompatV2.NONE_VALUE; - } - - @Override - public boolean equals(Object comp) { - return SimpleUriValue.isIndividualUriValueEquals(this, comp); - } - - @Override - public int hashCode() { - return SimpleUriValue.getIndividualUriValueHash(this); - } - - /* (non-Javadoc) - * @see org.spdx.rdfparser.license.AnyLicenseInfo#verify() - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - return new ArrayList<>(); - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_NONE_LICENSE; - } - - @Override - public String getIndividualURI() { - return SpdxConstantsCompatV2.URI_VALUE_NONE; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java b/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java deleted file mode 100644 index 2590e8f21..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/WithExceptionOperator.java +++ /dev/null @@ -1,240 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.license; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.storage.IModelStore; - -/** - * A license that has a With exception operator (e.g. GPL-2.0 WITH Autoconf-exception-2.0) - * @author Gary O'Neall - */ -public class WithExceptionOperator extends AnyLicenseInfo { - - /** - * @throws InvalidSPDXAnalysisException - */ - public WithExceptionOperator() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public WithExceptionOperator(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's - * @param create - * @throws InvalidSPDXAnalysisException - */ - public WithExceptionOperator(IModelStore modelStore, String documentUri, String id, - @Nullable ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - public WithExceptionOperator(AnyLicenseInfo license, LicenseException exception) throws InvalidSPDXAnalysisException { - super(); - setLicense(license); - setException(exception); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_WITH_EXCEPTION_OPERATOR; - } - - /** - * @return the license - * @throws InvalidSPDXAnalysisException - */ - public AnyLicenseInfo getLicense() throws InvalidSPDXAnalysisException { - Optional retval = getAnyLicenseInfoPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); - if (!retval.isPresent()) { - throw new InvalidSPDXAnalysisException("Required license for exception is missing"); - } - return retval.get(); - } - - /** - * @param license the license to set - * @throws InvalidSPDXAnalysisException - */ - public void setLicense(AnyLicenseInfo license) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER, license); - } - - /** - * @return the exception - */ - public LicenseException getException() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION); - if (!retval.isPresent()) { - throw new InvalidSPDXAnalysisException("Required exception is missing for with exception operator"); - } - if (!(retval.get() instanceof LicenseException)) { - throw new SpdxInvalidTypeException("Exception is not of type LicenseException"); - } - return (LicenseException)(retval.get()); - } - - /** - * @param exception the exception to set - * @throws InvalidSPDXAnalysisException - */ - public void setException(LicenseException exception) throws InvalidSPDXAnalysisException { - setPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION, exception); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - try { - Optional license = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); - Optional exception = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION); - if (!license.isPresent() || !exception.isPresent()) { - return "UNDEFINED WITH EXCEPTION"; - } - return license.get().toString() +" WITH "+exception.get().toString(); - } catch (Exception ex) { - return "UNDEFINED WITH EXCEPTION"; - } - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = new ArrayList<>(); - try { - Optional license = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_SET_MEMEBER); - if (license.isPresent()) { - if (license.get() instanceof AnyLicenseInfo) { - retval.addAll(((AnyLicenseInfo)(license.get())).verify(verifiedIds, specVersion)); - } else { - retval.add("Invalid type for With Operator license"); - } - } else { - retval.add("Missing required license for With Operator"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting license property of a With operator: "+e.getMessage()); - } - try { - Optional exception = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION); - if (exception.isPresent()) { - if (exception.get() instanceof LicenseException) { - retval.addAll(((LicenseException)(exception.get())).verify(verifiedIds, specVersion)); - } else { - retval.add("Invalid type for With Operator exception"); - } - } else { - retval.add("Missing required exception for With Operator"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting exception property of a With operator: "+e.getMessage()); - } - return retval; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#equals(java.lang.Object) - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof WithExceptionOperator)) { - return false; - } - WithExceptionOperator comp = (WithExceptionOperator)o; - AnyLicenseInfo myLicense = null; - AnyLicenseInfo compLicense = null; - LicenseException myException = null; - LicenseException compException = null; - try { - myLicense = this.getLicense(); - } catch (InvalidSPDXAnalysisException e) { - // Likely caused by missing required field - leave the value as null - } - try { - compLicense = comp.getLicense(); - } catch (InvalidSPDXAnalysisException e) { - // Likely caused by missing required field - leave the value as null - } - try { - myException = this.getException(); - } catch (InvalidSPDXAnalysisException e) { - // Likely caused by missing required field - leave the value as null - } - try { - compException = comp.getException(); - } catch (InvalidSPDXAnalysisException e) { - // Likely caused by missing required field - leave the value as null - } - if (!Objects.equals(myLicense, compLicense)) { - return false; - } - if (!Objects.equals(myException, compException)) { - return false; - } - return true; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#hashCode() - */ - @Override - public int hashCode() { - int licHashCode = 0; - int exceptionHashCode = 0; - try { - licHashCode = this.getLicense().hashCode(); - } catch (InvalidSPDXAnalysisException e) { - // Likely caused by missing required field - leave the value as 0 - } - try { - exceptionHashCode = this.getException().hashCode(); - } catch (InvalidSPDXAnalysisException e) { - // Likely caused by missing required field - leave the value as 0 - } - return 977 ^ licHashCode ^ exceptionHashCode; - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java deleted file mode 100644 index 11887c897..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/license/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Gary O'Neall - * - * Model for the SPDX version 2 license related objects - * - */ -package org.spdx.library.model.compat.v2.license; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/compat/v2/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/package-info.java deleted file mode 100644 index 8e56c0ba9..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. -/** - * @author Gary O'Neall - * - * Package containing the complete object model for SPDX documents, items, elements, etc. - * - * See the SPDX spec model description for a UML diagram of the model - * - */ -package org.spdx.library.model.compat.v2; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java deleted file mode 100644 index 867d22d21..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/ByteOffsetPointer.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.pointer; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * Byte offset pointer per RDF 2.3.2.2 ByteOffsetPointer Class - * @author Gary O'Neall - * - */ -public class ByteOffsetPointer extends SinglePointer { - - /** - * @throws InvalidSPDXAnalysisException - */ - public ByteOffsetPointer() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public ByteOffsetPointer(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public ByteOffsetPointer(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_POINTER_BYTE_OFFSET_POINTER; - } - - /** - * @return the offset, -1 if no offset is stored - */ - public int getOffset() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_OFFSET); - if (!retval.isPresent()) { - return -1; - } - return retval.get(); - } - - /** - * @param offset the offset to set - */ - public void setOffset(Integer offset) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(offset) || offset < 0) { - throw new InvalidSPDXAnalysisException("Can not set required offset to null or less than zero"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_OFFSET, offset); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - int offset; - try { - offset = getOffset(); - if (offset == -1) { - retval.add("Missing byte offset offset value"); - } else if (offset < 0) { - retval.add("Offset most not be negative for a byte pointer: "+Integer.toString(offset)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting offset: "+e.getMessage()); - } - - return retval; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(SinglePointer o) { - if (o == null) { - return 1; - } - int retval = compareReferences(o); - if (retval != 0) { - return retval; - } - if (!(o instanceof ByteOffsetPointer)) { - return 1; - } - - int compByteOffset; - try { - compByteOffset = ((ByteOffsetPointer)o).getOffset(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting compare offset",e); - compByteOffset = -1; - } - Integer myOffset; - try { - myOffset = getOffset(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting offset",e); - myOffset = -1; - } - return myOffset.compareTo(compByteOffset); - } - - @Override - public String toString() { - int offset; - try { - offset = getOffset(); - return "byte offset " +Integer.toString(offset); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting offset",e); - return "Unknown byte offset"; - } - } -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java deleted file mode 100644 index c57839af4..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/CompoundPointer.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.pointer; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.storage.IModelStore; - -/** - * A pointing method made up of a pair of pointers that identify a well defined section within a document delimited by a begin and an end. - * See http://www.w3.org/2009/pointers and https://www.w3.org/WAI/ER/Pointers/WD-Pointers-in-RDF10-20110427 - * This is an abstract class of pointers which must be subclassed - * @author Gary O'Neall - */ -public abstract class CompoundPointer extends ModelObject { - - /** - * @throws InvalidSPDXAnalysisException - */ - public CompoundPointer() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public CompoundPointer(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public CompoundPointer(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @return the startPointer, null if not present - * @throws InvalidSPDXAnalysisException - */ - public @Nullable SinglePointer getStartPointer() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_START_POINTER); - if (!retval.isPresent()) { - return null; - } - if (!(retval.get() instanceof SinglePointer)) { - throw new SpdxInvalidTypeException("Incorrect type for getEndPointer - expected SinglePointer, found "+retval.get().getClass().toString()); - } - return (SinglePointer)retval.get(); - } - - /* - * @param startPointer the startPointer to set - * @return this to chain setters - * @throws InvalidSPDXAnalysisException - */ - public CompoundPointer setStartPointer(SinglePointer startPointer) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(startPointer)) { - throw new InvalidSPDXAnalysisException("Can not set required startPointer to null"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_START_POINTER, startPointer); - return this; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - ArrayList retval = new ArrayList(); - try { - SinglePointer startPointer = getStartPointer(); - if (startPointer == null) { - retval.add("Missing required start pointer"); - } else { - retval.addAll(startPointer.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException ex) { - retval.add("Error getting start pointer: "+ex.getMessage()); - } - return retval; - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_POINTER_COMPOUNT_POINTER; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java deleted file mode 100644 index fda292def..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/LineCharPointer.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.pointer; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.storage.IModelStore; - -/** - * @author Gary O'Neall - * - */ -public class LineCharPointer extends SinglePointer { - - /** - * @throws InvalidSPDXAnalysisException - */ - public LineCharPointer() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public LineCharPointer(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public LineCharPointer(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @return the lineNumber, -1 if no lineNumber is stored - */ - public int getLineNumber() throws InvalidSPDXAnalysisException { - Optional retval = getIntegerPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_LINE_NUMBER); - if (retval.isPresent()) { - return retval.get(); - } else { - logger.warn("Missing line number"); - return -1; - } - } - - /** - * @param lineNumber the lineNumber to set - */ - public void setLineNumber(Integer lineNumber) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(lineNumber)) { - throw new InvalidSPDXAnalysisException("Can not set required lineNumber to null"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_LINE_NUMBER, lineNumber); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - int lineNumber; - try { - lineNumber = getLineNumber(); - if (lineNumber == -1) { - retval.add("Missing line number value"); - } else if (lineNumber < 0) { - retval.add("Line number most not be negative for a line offset pointer: "+Integer.toString(lineNumber)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting line number: "+e.getMessage()); - } - return retval; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(SinglePointer o) { - if (o == null) { - return 1; - } - int retval = compareReferences(o); - if (retval != 0) { - return retval; - } - if (!(o instanceof LineCharPointer)) { - return 1; - } - int compLine; - try { - compLine = ((LineCharPointer)o).getLineNumber(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting comp line",e); - compLine = -1; - } - int line; - try { - line = getLineNumber(); - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting line",e); - line = -1; - } - return Integer.compare(line, compLine); - } - - @Override - public String toString() { - int lineNumber; - try { - lineNumber = getLineNumber(); - if (lineNumber != -1) { - return "line number " + Integer.toString(lineNumber); - } else { - return "Unknown line number"; - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting line number",e); - return "[ERROR]"; - } - - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#getType() - */ - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_POINTER_LINE_CHAR_POINTER; - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java deleted file mode 100644 index 0a99e2b43..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/SinglePointer.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.pointer; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.storage.IModelStore; - -/** - * A pointing method made up of a unique pointer. This is an abstract single pointer that provides the necessary framework, - * but it does not provide any kind of pointer, so more specific subclasses must be used. - * See http://www.w3.org/2009/pointers and https://www.w3.org/WAI/ER/Pointers/WD-Pointers-in-RDF10-20110427 - * - * @author Gary O'Neall - */ -public abstract class SinglePointer extends ModelObject implements Comparable { - - static final Logger logger = LoggerFactory.getLogger(SinglePointer.class); - - /** - * @throws InvalidSPDXAnalysisException - */ - public SinglePointer() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public SinglePointer(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public SinglePointer(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - /** - * @return the reference, null if no reference is stored - * @throws InvalidSPDXAnalysisException - */ - public @Nullable SpdxElement getReference() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_REFERENCE); - if (!retval.isPresent()) { - return null; - } - if (!(retval.get() instanceof SpdxElement)) { - throw new SpdxInvalidTypeException("Invalid type for reference. Expect SdpxElement, found "+retval.get().getClass().toString()); - } - return (SpdxElement)retval.get(); - } - - /** - * @param reference the reference to set - * @throws InvalidSPDXAnalysisException - */ - public void setReference(SpdxElement reference) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(reference)) { - throw new InvalidSPDXAnalysisException("Can not set required reference to null"); - } - } - setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_REFERENCE, reference); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.ModelObject#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - ArrayList retval = new ArrayList(); - SpdxElement reference; - try { - reference = getReference(); - if (Objects.isNull(reference)) { - retval.add("Missing required reference field"); - } else { - retval.addAll(reference.verify(verifiedIds, specVersion)); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting reference: "+e.getMessage()); - } - - return retval; - } - - protected int compareReferences(SinglePointer o) { - if (o == null) { - return 1; - } - SpdxElement compRef = null; - try { - compRef = o.getReference(); - SpdxElement reference = getReference(); - if (reference == null) { - if (compRef == null) { - return 0; - } else { - return -1; - } - } else if (compRef == null) { - return 1; - } else { - String myName = ""; - try { - Optional name = reference.getName(); - if (name.isPresent()) { - myName = name.get(); - } - } catch (InvalidSPDXAnalysisException ex) { - logger.warn("Error getting reference name",ex); - } - String compName = ""; - try { - Optional cName = compRef.getName(); - if (cName.isPresent()) { - compName = cName.get(); - } - } catch (InvalidSPDXAnalysisException ex) { - logger.warn("Error getting compare name",ex); - } - return myName.compareTo(compName); - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting comparison reference element",e); - return -1; - } - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java deleted file mode 100644 index c9a764558..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/StartEndPointer.java +++ /dev/null @@ -1,222 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model.compat.v2.pointer; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.storage.IModelStore; - -/** - * A compound pointer pointing out parts of a document by means of a range delimited by a pair of single pointers that define the start point and the end point. - * See http://www.w3.org/2009/pointers and https://www.w3.org/WAI/ER/Pointers/WD-Pointers-in-RDF10-20110427 - * @author Gary O'Neall - */ -public class StartEndPointer extends CompoundPointer implements Comparable { - - static final Logger logger = LoggerFactory.getLogger(StartEndPointer.class); - - /** - * @throws InvalidSPDXAnalysisException - */ - public StartEndPointer() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public StartEndPointer(String id) throws InvalidSPDXAnalysisException { - super(id); - } - - /** - * @param modelStore - * @param documentUri - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public StartEndPointer(IModelStore modelStore, String documentUri, String id, ModelCopyManager copyManager, - boolean create) throws InvalidSPDXAnalysisException { - super(modelStore, documentUri, id, copyManager, create); - } - - @Override - public String getType() { - return SpdxConstantsCompatV2.CLASS_POINTER_START_END_POINTER; - } - - /** - * @return the endPointer, null if not present - * @throws InvalidSPDXAnalysisException - */ - public @Nullable SinglePointer getEndPointer() throws InvalidSPDXAnalysisException { - Optional retval = getObjectPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_END_POINTER); - if (!retval.isPresent()) { - return null; - } - if (!(retval.get() instanceof SinglePointer)) { - logger.error("Incorrect type for getEndPointer - expected SinglePointer, found "+retval.get().getClass().toString()); - throw new SpdxInvalidTypeException("Incorrect type for getEndPointer - expected SinglePointer, found "+retval.get().getClass().toString()); - } - return (SinglePointer)retval.get(); - } - - /** - * @param endPointer the endPointer to set - * @throws InvalidSPDXAnalysisException - */ - public void setEndPointer(SinglePointer endPointer) throws InvalidSPDXAnalysisException { - if (strict) { - if (Objects.isNull(endPointer)) { - throw new InvalidSPDXAnalysisException("Can not set required endPointer to null"); - } - SinglePointer startPointer = getStartPointer(); - if (Objects.nonNull(startPointer) && !startPointer.getClass().isAssignableFrom(endPointer.getClass())) { - throw new SpdxInvalidTypeException("Incompatable type for endPointer: "+endPointer.getClass().toString() + - ". Must be assignable to "+startPointer.getClass().toString()+"."); - } - //TODO: We could add a check to make sure the endpointer is greater than the startpointer - } - setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_END_POINTER, endPointer); - } - - @Override - public StartEndPointer setStartPointer(SinglePointer startPointer) throws InvalidSPDXAnalysisException { - if (strict) { - SinglePointer endPointer = getEndPointer(); - if (Objects.nonNull(endPointer) && !endPointer.getClass().isAssignableFrom(startPointer.getClass())) { - throw new SpdxInvalidTypeException("Incompatable type for startPointer: "+startPointer.getClass().toString() + - ". Must be assignable to "+endPointer.getClass().toString()+"."); - } - //TODO: We could add a check to make sure the startPointer is less than the endPointer - } - setPropertyValue(SpdxConstantsCompatV2.PROP_POINTER_START_POINTER, startPointer); - return this; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.compat.v2.compat.v2.pointer.CompoundPointer#_verify(java.util.List) - */ - @Override - protected List _verify(Set verifiedIds, String specVersion) { - List retval = super._verify(verifiedIds, specVersion); - SinglePointer endPointer; - try { - endPointer = getEndPointer(); - if (endPointer == null) { - retval.add("Missing required end pointer"); - } else { - retval.addAll(endPointer.verify(verifiedIds, specVersion)); - try { - SinglePointer startPointer = getStartPointer(); - if (startPointer != null && startPointer instanceof ByteOffsetPointer && !(endPointer instanceof ByteOffsetPointer)) { - retval.add("Inconsistent start and end pointer types"); - } - if (startPointer != null && startPointer instanceof LineCharPointer && !(endPointer instanceof LineCharPointer)) { - retval.add("Inconsistent start and end pointer types"); - } - if (startPointer != null && startPointer.compareTo(endPointer) > 0) { - retval.add("End pointer is less than start pointer"); - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting startPointer: "+e.getMessage()); - } - } - } catch (InvalidSPDXAnalysisException e) { - retval.add("Error getting endPointer: "+e.getMessage()); - } - return retval; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(StartEndPointer o) { - if (o == null) { - return 1; - } - try { - SinglePointer startPointer = getStartPointer(); - SinglePointer compareStartPointer = o.getStartPointer(); - if (startPointer == null) { - if (compareStartPointer == null) { - return 0; - } else { - return -1; - } - } - if (compareStartPointer == null) { - return 1; - } else { - return startPointer.compareTo(compareStartPointer); - } - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting comparison for start end pointer",e); - return -1; - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("From: "); - SinglePointer startPointer; - try { - startPointer = getStartPointer(); - if (startPointer != null) { - sb.append(startPointer.toString()); - } else { - sb.append("[UNKNOWN]"); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting start pointer",e); - sb.append("[ERROR]"); - } - - sb.append(" To: "); - SinglePointer endPointer; - try { - endPointer = getEndPointer(); - if (endPointer != null) { - sb.append(endPointer.toString()); - } else { - sb.append("[UNKNOWN]"); - } - } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting end pointer",e); - sb.append("[ERROR]"); - } - - return sb.toString(); - } - -} diff --git a/src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java b/src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java deleted file mode 100644 index a692fde31..000000000 --- a/src/main/java/org/spdx/library/model/compat/v2/pointer/package-info.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * RDF model classes which implement the proposed W3C Pointer classes. - * From the W3C documentation, pointers are entities that permit identifying - * a portion or segment of a piece of content - making use of the - * Resource Description Framework (RDF). It also describes a number of specific - * types of pointers that permit portions of a document to be referred to in - * different ways. When referring to a specific part of, say, a piece of web content, - * it is useful to be able to have a consistent manner by which to refer to a particular - * segment of a web document, to have a variety of ways by which to refer to that - * same segment, and to make the reference robust in the face of changes to that document. - * - * Pointers are used to describe SPDX Snippet ranges. - * - * @author Gary O'Neall - */ -package org.spdx.library.model.compat.v2.pointer; \ No newline at end of file diff --git a/src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java b/src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java deleted file mode 100644 index d370436c9..000000000 --- a/src/main/java/org/spdx/library/referencetype/compat/v2/ListedReferenceTypes.java +++ /dev/null @@ -1,203 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.referencetype.compat.v2; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.ReferenceType; - -/** - * Singleton class that maintains the current SPDX listed reference types. - * The listed reference types are maintained by the SPDX community. - * @author Gary O'Neall - * - */ -public class ListedReferenceTypes { - - static final Logger logger = LoggerFactory.getLogger(ListedReferenceTypes.class); - private static final ReadWriteLock listedReferenceTypesModificationLock = new ReentrantReadWriteLock(); - private static final String LISTED_REFERENCE_TYPE__RDF_LOCAL_DIR = "resources" + "/" + "listedexternaltypes"; - private static final String LISTED_REFERENCE_TYPE_PROPERTIES_FILENAME = LISTED_REFERENCE_TYPE__RDF_LOCAL_DIR + "/" + "listedreferencetypes.properties"; - private static final String LISTED_REFERENCE_TYPE_PROPERTIES_CLASS_PATH = "org/spdx/library/referencetype/listedreferencetypes.properties"; - private static final String PROPERTY_LISTED_REFERENCE_TYPES = "listedReferenceTypes"; - private static ListedReferenceTypes listedReferenceTypes; - private Properties listedReferenceTypeProperties; - List listedReferenceNames = new ArrayList(); - ConcurrentMap listedReferenceTypeCache = new ConcurrentHashMap<>(); - - private ListedReferenceTypes() { - listedReferenceTypeProperties = new Properties(); - InputStream in = null; - try { - try { - in = ListedReferenceTypes.class.getResourceAsStream("/" + LISTED_REFERENCE_TYPE_PROPERTIES_FILENAME); - if (Objects.nonNull(in)) { - listedReferenceTypeProperties.load(in); - } - } catch (IOException e) { - logger.warn("IO Exception reading listed reference type properties file: " - + e.getMessage() + ", loading properties from class properties file."); - } - if (Objects.isNull(in)) { - try { - in = ListedReferenceTypes.class.getClassLoader().getResourceAsStream(LISTED_REFERENCE_TYPE_PROPERTIES_CLASS_PATH); - if (Objects.nonNull(in)) { - listedReferenceTypeProperties.load(in); - } else { - logger.error("Unable to load listed reference type properties"); - } - } catch (IOException ex2) { - logger.error("IO exception reading listed reference type properties from class properties file: "+ex2.getMessage()); - } - } - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - logger.warn("Unable to close listed license properties file: " + e.getMessage()); - } - } - } - loadReferenceTypeNames(); - } - - /** - * - */ - private void loadReferenceTypeNames() { - listedReferenceTypesModificationLock.readLock().lock(); - try { - String referenceTypeNamesStr = this.listedReferenceTypeProperties.getProperty(PROPERTY_LISTED_REFERENCE_TYPES); - String[] referenceTypeNamesAr = referenceTypeNamesStr.split(",", -1); - for (String name:referenceTypeNamesAr) { - this.listedReferenceNames.add(name.trim()); - } - } finally { - listedReferenceTypesModificationLock.readLock().unlock(); - } - } - - /** - * @return the listed reference types as maintained by the SPDX workgroup - */ - public static ListedReferenceTypes getListedReferenceTypes() { - listedReferenceTypesModificationLock.writeLock().lock(); - try { - if (listedReferenceTypes == null) { - listedReferenceTypes = new ListedReferenceTypes(); - } - return listedReferenceTypes; - } finally { - listedReferenceTypesModificationLock.writeLock().unlock(); - } - } - - /** - * Resets all of the listed reference types and reloads the listed reference ID's - * NOTE: This method should be used with caution, it will negatively impact - * performance. - * @return - */ - public static ListedReferenceTypes resetListedReferenceTypes() { - listedReferenceTypesModificationLock.writeLock().lock(); - try { - listedReferenceTypes = new ListedReferenceTypes(); - return listedReferenceTypes; - } finally { - listedReferenceTypesModificationLock.writeLock().unlock(); - } - } - - /** - * Returns true if the URI references a valid SPDX listed reference type - * @param uri - * @return - */ - public boolean isListedReferenceType(URI uri) { - if (uri.toString().startsWith(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX)) { - String referenceTypeName = uri.toString().substring(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX.length()); - return this.listedReferenceNames.contains(referenceTypeName); - } else { - return false; - } - } - - /** - * Get the listed reference URI from a listed reference type name used in the tag/value format - * @param listedReferenceName - * @return - * @throws InvalidSPDXAnalysisException - */ - public URI getListedReferenceUri(String listedReferenceName) throws InvalidSPDXAnalysisException { - URI retval; - try { - retval = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + listedReferenceName); - } catch (URISyntaxException e) { - logger.error("Error forming listed license URI",e); - throw new InvalidSPDXAnalysisException(listedReferenceName + " is not a valid SPDX listed reference type syntax."); - } - if (!isListedReferenceType(retval)) { - throw new InvalidSPDXAnalysisException(listedReferenceName + " is not a valid SPDX listed reference type."); - } - return retval; - } - - public ReferenceType getListedReferenceTypeByName(String listedReferenceName) throws InvalidSPDXAnalysisException { - ReferenceType retval = this.listedReferenceTypeCache.get(listedReferenceName); - if (retval == null) { - URI listedRefUri = getListedReferenceUri(listedReferenceName); - retval = new ReferenceType(listedRefUri.toString()); - ReferenceType oldValue = this.listedReferenceTypeCache.putIfAbsent(listedReferenceName, retval); - if (oldValue != null) { - retval = oldValue; - } - } - return retval; - } - - /** - * Get the listed reference type name from the listed reference URI - * @param uri - * @return SPDX listed reference type name used in the tag/value format - * @throws InvalidSPDXAnalysisException - */ - public String getListedReferenceName(URI uri) throws InvalidSPDXAnalysisException { - if (!this.isListedReferenceType(uri)) { - throw new InvalidSPDXAnalysisException(uri.toString() + " is not a valid URI for an SPDX listed reference type."); - } - return uri.toString().substring(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX.length()); - } - - //TODO: Implement accessing the SPDX reference type pages directly similar to the SpdxListedLicenses class -} diff --git a/src/main/java/org/spdx/library/referencetype/compat/v2/listedreferencetypes.properties b/src/main/java/org/spdx/library/referencetype/compat/v2/listedreferencetypes.properties deleted file mode 100644 index 12c755727..000000000 --- a/src/main/java/org/spdx/library/referencetype/compat/v2/listedreferencetypes.properties +++ /dev/null @@ -1,4 +0,0 @@ -# Properties file for listed reference types as described in the SPDX specification appendix -# -# List of all reference types separated by comma's -listedReferenceTypes=cpe22Type,cpe23Type,maven-central,npm,nuget,bower,debian,advisory,fix,url,gitoid,purl,swh \ No newline at end of file diff --git a/src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java b/src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java deleted file mode 100644 index 4612fc69d..000000000 --- a/src/main/java/org/spdx/library/referencetype/compat/v2/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Classes related to reference types for external references - * - * @author Gary O'Neall - * - */ -package org.spdx.library.referencetype.compat.v2; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/IModelStore.java b/src/main/java/org/spdx/storage/IModelStore.java deleted file mode 100644 index b43e9ac15..000000000 --- a/src/main/java/org/spdx/storage/IModelStore.java +++ /dev/null @@ -1,250 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage; - -import java.util.Iterator; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.TypedValue; - -/** - * Service Provider Interface for storing and retrieving SPDX properties from the underlying store. - * - * The interface uses the URI to identify specific objects stored. - * - * Each object can have property values and property value lists associated with them. - * - * A property value is an object of a primitive type (e.g. String or Boolean) or is another - * object which includes it's own ID and must also have a type described in the SPDX model. - * - * A property list is just a list of values. - * - * @author Gary O'Neall - * - */ -public interface IModelStore extends AutoCloseable { - - public interface IModelStoreLock { - public void unlock(); - } - - @FunctionalInterface - public static interface ModelUpdate { - void apply() throws InvalidSPDXAnalysisException; - } - - /** - * Different types of ID's - */ - public enum IdType { - LicenseRef, // ID's that start with LicenseRef- - DocumentRef, // ID's that start with DocumentRef- - SpdxId, // ID's that start with SpdxRef- - ListedLicense, // ID's associated with listed licenses - Literal, // ID's for pre-defined literals (such as NONE, NOASSERTION) - Anonymous, // ID's for object only referenced internally - Unkown}; // ID's that just don't fit any pattern - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @return true if the objectUri already exists for the document - */ - public boolean exists(String objectUri); - - /** - * Create a new object with objectUri and type - * @param objectUri unique URI within the SPDX model store for the objects - * @param type SPDX model type as defined in the CLASS constants in SpdxConstantsCompatV2 - * @throws InvalidSPDXAnalysisException - */ - public void create(String objectUri, String type) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @return Property descriptors for all properties having a value for a given objectUri within a document - * @throws InvalidSPDXAnalysisException - */ - public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException; - - /** - * Sets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @param value value to set - * @throws InvalidSPDXAnalysisException - */ - public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @return the single value associated with the objectUri, propertyDescriptor and document - * @throws InvalidSPDXAnalysisException - */ - public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; - - /** - * Generate a unique ID within the document store - * @param idType Type of ID - * @param nameSpace the SPDX namespace to use for the ID - * @return next available unique ID for the specific idType as a full URI - * @throws InvalidSPDXAnalysisException - */ - public String getNextId(IdType idType, @Nullable String nameSpace) throws InvalidSPDXAnalysisException; - - /** - * Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyDescriptor does not exist - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @throws InvalidSPDXAnalysisException - */ - public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; - - /** - * @param nameSpace Optional SPDX namespace to filter items by - * @param typeFilter Optional parameter to specify the type of objects to be retrieved - * @return Stream of all items store within the document - * @throws InvalidSPDXAnalysisException - */ - public Stream getAllItems(@Nullable String nameSpace, @Nullable String typeFilter) throws InvalidSPDXAnalysisException; - - /** - * Enter a critical section. leaveCriticialSection must be called. - * @param readLockRequested true implies a read lock, false implies write lock. - * @throws InvalidSPDXAnalysisException - */ - public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException; - - /** - * Leave a critical section. Releases the lock form the matching enterCriticalSection - */ - public void leaveCriticalSection(IModelStoreLock lock); - - /** - * Removes a value from a collection of values associated with a property - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @param value Value to be removed - * @return - */ - public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @return size of a collection associated with a property. 0 if the property does not exist. - */ - public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @param value - * @return true if the collection associated with a property contains the value - */ - public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; - - /** - * Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not exist - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @throws InvalidSPDXAnalysisException - */ - void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; - - /** - * Adds a value to a property collection creating the propertyDescriptor if it does not exist - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @param value value to add - * @return true if the collection was modified - * @throws InvalidSPDXAnalysisException - */ - public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @return Iterator over the list of values associated with the objectUri, propertyDescriptor and document - * @throws InvalidSPDXAnalysisException - */ - public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @param clazz Class to test compatibility with - * @return true if all members of a collection associated with the objectUri and propertyDescriptor can be assigned to the clazz - * @throws InvalidSPDXAnalysisException - */ - public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @param clazz Class to test compatibility with - * @return true if the value associated with the objectUri and propertyDescriptor can be assigned to the clazz - * @throws InvalidSPDXAnalysisException - */ - public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @param propertyDescriptor descriptor for the property - * @return true if the propertyDescriptor represents multiple values - */ - public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException; - - /** - * @param objectUri - * @return The type of ID based on the string format - */ - public IdType getIdType(String objectUri); - - /** - * In SPDX 2.2 license refs are allowed to be matched case insensitive. This function will return - * the case sensitivie ID (e.g. if you have LicenseRef-ABC, calling this function with licenseref-abc will return LicenseRef-ABC - * @param nameSpace the nameSpace used for the ID - the URI is formed by the nameSpace + "#" + caseInsensisitiveId - * @param caseInsensisitiveId - * @return the case sensitive ID if it exists - */ - public Optional getCaseSensisitiveId(String nameSpace, String caseInsensisitiveId); - - /** - * @param objectUri unique URI within the SPDX model store for the objects - * @return type TypedValue containing the type of the ModelObject related to the ID - */ - public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException; - /** - * Deletes an item from the document - * @param objectUri unique URI within the SPDX model store for the objects - * @throws InvalidSPDXAnalysisException - */ - public void delete(String objectUri) throws InvalidSPDXAnalysisException; - - /** - * @return the major SPDX version for the model store (e.g. "2" or "3") - */ - public SpdxMajorVersion getSpdxVersion(); -} diff --git a/src/main/java/org/spdx/storage/ISerializableModelStore.java b/src/main/java/org/spdx/storage/ISerializableModelStore.java deleted file mode 100644 index f596e9e3c..000000000 --- a/src/main/java/org/spdx/storage/ISerializableModelStore.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.spdx.library.InvalidSPDXAnalysisException; - -/** - * A model store that can be serialized and de-serialized to and from a Stream - * @author Gary O'Neall - * - */ -public interface ISerializableModelStore extends IModelStore { - - /** - * Serialize the items stored in the documentUri. The specific format for serialization depends on the document store. - * @param documentUri URI for the document to be serialized - * @param stream output stream to serialize to - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public void serialize(String documentUri, OutputStream stream) throws InvalidSPDXAnalysisException, IOException; - - /** - * Deserialize / read an SPDX document from a stream - * @param stream input stream to deserialize from - * @param overwrite if true, allow any existing documents with the same documentUri to be overwritten - * @return document URI of the document - * @throws InvalidSPDXAnalysisException - * @throws IOException - */ - public String deSerialize(InputStream stream, boolean overwrite) throws InvalidSPDXAnalysisException, IOException; -} diff --git a/src/main/java/org/spdx/storage/PropertyDescriptor.java b/src/main/java/org/spdx/storage/PropertyDescriptor.java deleted file mode 100644 index 06dbf84e5..000000000 --- a/src/main/java/org/spdx/storage/PropertyDescriptor.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage; - -import java.util.Objects; - -/** - * Holds a description of a property including the property name and property - * nameSpace. Includes a helper function to default the namespace. - * @author Gary O'Neall - * - */ -public class PropertyDescriptor { - - private String name; - private String nameSpace; - - /** - * @param name Property name as defined in the SPDX specification - * @param nameSpace Property nameSpace as defined in the SPDX specification - */ - public PropertyDescriptor(String name, String nameSpace) { - Objects.requireNonNull(name); - Objects.requireNonNull(nameSpace); - this.name = name; - this.nameSpace = nameSpace; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - Objects.requireNonNull(name, "Can not set name to null"); - this.name = name; - } - - /** - * @return the nameSpace - */ - public String getNameSpace() { - return nameSpace; - } - - /** - * @param nameSpace the nameSpace to set - */ - public void setNameSpace(String nameSpace) { - Objects.requireNonNull(nameSpace, "Can not set nameSpace to null"); - this.nameSpace = nameSpace; - } - - @Override - public boolean equals(Object compare) { - return compare instanceof PropertyDescriptor && - Objects.equals(this.name, ((PropertyDescriptor)(compare)).name) && - Objects.equals(this.nameSpace, ((PropertyDescriptor)(compare)).nameSpace); - } - - @Override - public int hashCode() { - return 11 ^ this.name.hashCode() ^ this.nameSpace.hashCode(); - } - - @Override - public String toString() { - return this.nameSpace + this.name; - } -} diff --git a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java b/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java deleted file mode 100644 index 57385df14..000000000 --- a/src/main/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapper.java +++ /dev/null @@ -1,420 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.compat.v2; - -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidIdException; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.TypedValue; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; - -/** - * Wraps a model store providing a compatible interface to the 1.X version of the SPDX Java Library - * - * @author Gary O'Neall - * - */ -public class CompatibleModelStoreWrapper implements IModelStore { - - private IModelStore baseStore; - - public CompatibleModelStoreWrapper(IModelStore baseStore) { - Objects.requireNonNull(baseStore, "A base store must be provided for the CompatibileModelStoreWrapper"); - this.baseStore = baseStore; - } - - @Override - public void close() throws Exception { - baseStore.close(); - } - - /** - * @param documentUri a nameSpace for the ID - * @param objectUri unique ID within the SPDX document - * @return true if the objectUri already exists for the documentUri - */ - public boolean exists(String documentUri, String id) { - return exists(documentUriIdToUri(documentUri, id, baseStore)); - } - - /** - * @param documentUri SPDX v2 Document URI - * @param id ID consistent with SPDX v2 spec - * @param store store used for the Document URI - * @return true if the objectUri already exists for the documentUri - */ - public static String documentUriIdToUri(String documentUri, String id, IModelStore store) { - return documentUriIdToUri(documentUri, id, store.getIdType(id).equals(IdType.Anonymous)); - } - - public static String documentUriToNamespace(String documentUri, boolean anonymous) { - if (anonymous) { - return ""; - } else if (documentUri.contains("://spdx.org/licenses/")) { - return documentUri; - } else { - return documentUri + "#"; - } - } - - /** - * @param documentUri SPDX v2 Document URI - * @param id ID consistent with SPDX v2 spec - * @param anonymous true of this is an anonymous ID - * @return a URI based on the document URI and ID - if anonymous is true, the ID is returned - */ - public static String documentUriIdToUri(String documentUri, String id, boolean anonymous) { - return documentUriToNamespace(documentUri, anonymous) + id; - } - - /** - * Convenience method to convert an SPDX 2.X style typed value to the current TypedValue - * @param documentUri SPDX v2 Document URI - * @param id ID consistent with SPDX v2 spec - * @param anonymous true of this is an anonymous ID - * @param type SPDX type - * @return TypedValue with the proper Object URI formed by the documentUri and ID - * @throws SpdxInvalidIdException - * @throws SpdxInvalidTypeException - */ - public static TypedValue typedValueFromDocUri(String documentUri, String id, boolean anonymous, String type) throws SpdxInvalidIdException, SpdxInvalidTypeException { - return new TypedValue(documentUriIdToUri(documentUri, id, anonymous), type); - } - - /** - * @param store Store storing the objet URI - * @param objectUri Object URI - * @param documentUri SPDX 2 document URI for the ID - * @return the SPDX 2 compatible ID - * @throws InvalidSPDXAnalysisException - */ - public static String objectUriToId(IModelStore store, String objectUri, String documentUri) throws InvalidSPDXAnalysisException { - return objectUriToId(store.getIdType(objectUri) == IdType.Anonymous, objectUri, documentUri); - } - - /** - * @param anon true if the ID type is anonymous - * @param objectUri Object URI - * @param documentUri SPDX 2 document URI for the ID - * @return the SPDX 2 compatible ID - * @throws InvalidSPDXAnalysisException - */ - public static String objectUriToId(boolean anon, String objectUri, String documentUri) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(objectUri, "Object URI can not be null"); - if (anon) { - return objectUri; - } - if (objectUri.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { - return objectUri.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()); - } - Objects.requireNonNull(documentUri, "Document URI can not be null"); - String nameSpace = documentUri + "#"; - if (!objectUri.startsWith(nameSpace)) { - throw new InvalidSPDXAnalysisException("Object URI must start with document URI + #. DocumentUri: " + - documentUri + ", Object URI: "+objectUri); - } - return objectUri.substring(nameSpace.length()); - } - - @Override - public boolean exists(String uri) { - return baseStore.exists(uri); - } - - /** - * @param documentUri SPDX v2 spec document URI - * @param objectUri SPDX ID - * @param type type - * @throws InvalidSPDXAnalysisException - */ - public void create(String documentUri, String id, String type) - throws InvalidSPDXAnalysisException { - baseStore.create(documentUriIdToUri(documentUri, id, baseStore), type); - } - - @Override - public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { - baseStore.create(objectUri, type); - } - - @Override - public List getPropertyValueDescriptors( - String objectUri) throws InvalidSPDXAnalysisException { - return baseStore.getPropertyValueDescriptors(objectUri); - } - - public List getPropertyValueDescriptors( - String documentUri, String id) throws InvalidSPDXAnalysisException { - return getPropertyValueDescriptors(documentUriIdToUri(documentUri, id, baseStore)); - } - - @Override - public void setValue(String objectUri, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - baseStore.setValue(objectUri, propertyDescriptor, value); - } - - public void setValue(String documentUri, String id, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - setValue(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); - } - - @Override - public Optional getValue(String objectUri, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return baseStore.getValue(objectUri, propertyDescriptor); - } - - public Optional getValue(String documentUri, String id, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return getValue(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); - } - - @Override - public String getNextId(IdType idType, String documentUri) - throws InvalidSPDXAnalysisException { - Objects.requireNonNull(documentUri, "SPDX V2 requires a namespace for generating next ID's"); - if (documentUri.contains("://spdx.org/licenses")) { - return baseStore.getNextId(idType, documentUri); - } else { - return baseStore.getNextId(idType, documentUri + "#"); - } - } - - @Override - public void removeProperty(String objectUri, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - baseStore.removeProperty(objectUri, propertyDescriptor); - } - - public void removeProperty(String documentUri, String id, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - removeProperty(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); - } - - @Override - public Stream getAllItems(String nameSpace, String typeFilter) - throws InvalidSPDXAnalysisException { - return baseStore.getAllItems(nameSpace, typeFilter); - } - - @Override - public IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException { - return baseStore.enterCriticalSection(readLockRequested); - } - - public IModelStoreLock enterCriticalSection(String documentUri, - boolean readLockRequested) throws InvalidSPDXAnalysisException { - return enterCriticalSection(readLockRequested); - } - - @Override - public void leaveCriticalSection(IModelStoreLock lock) { - baseStore.leaveCriticalSection(lock); - } - - @Override - public boolean removeValueFromCollection(String objectUri, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - return baseStore.removeValueFromCollection(objectUri, propertyDescriptor, value); - } - - public boolean removeValueFromCollection(String documentUri, String id, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - return removeValueFromCollection(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); - } - - @Override - public int collectionSize(String objectUri, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return baseStore.collectionSize(objectUri, propertyDescriptor); - } - - public int collectionSize(String documentUri, String id, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return collectionSize(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); - } - - @Override - public boolean collectionContains(String objectUri, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - return baseStore.collectionContains(objectUri, propertyDescriptor, value); - } - - public boolean collectionContains(String documentUri, String id, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - return collectionContains(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); - } - - @Override - public void clearValueCollection(String objectUri, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - baseStore.clearValueCollection(objectUri, propertyDescriptor); - } - - public void clearValueCollection(String documentUri, String id, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - clearValueCollection(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); - } - - @Override - public boolean addValueToCollection(String objectUri, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - return baseStore.addValueToCollection(objectUri, propertyDescriptor, value); - } - - public boolean addValueToCollection(String documentUri, String id, - PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - return addValueToCollection(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, value); - } - - @Override - public Iterator listValues(String objectUri, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return baseStore.listValues(objectUri, propertyDescriptor); - } - - public Iterator listValues(String documentUri, String id, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return listValues(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); - } - - @Override - public boolean isCollectionMembersAssignableTo(String objectUri, - PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - return baseStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, clazz); - } - - public boolean isCollectionMembersAssignableTo(String documentUri, - String id, PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - return isCollectionMembersAssignableTo(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, clazz); - } - - @Override - public boolean isPropertyValueAssignableTo(String objectUri, - PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz); - } - - public boolean isPropertyValueAssignableTo(String documentUri, String id, - PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - return isPropertyValueAssignableTo(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor, clazz); - } - - @Override - public boolean isCollectionProperty(String objectUri, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return baseStore.isCollectionProperty(objectUri, propertyDescriptor); - } - - public boolean isCollectionProperty(String documentUri, String id, - PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - return isCollectionProperty(documentUriIdToUri(documentUri, id, baseStore), propertyDescriptor); - } - - @Override - public IdType getIdType(String objectUri) { - return baseStore.getIdType(objectUri); - } - - @Override - public Optional getCaseSensisitiveId(String documentUri, - String caseInsensisitiveId) { - return baseStore.getCaseSensisitiveId(documentUri, caseInsensisitiveId); - } - - @Override - public Optional getTypedValue(String objectUri) - throws InvalidSPDXAnalysisException { - return baseStore.getTypedValue(objectUri); - } - - public Optional getTypedValue(String documentUri, String id) - throws InvalidSPDXAnalysisException { - return getTypedValue(documentUriIdToUri(documentUri, id, baseStore)); - } - - @Override - public void delete(String documentUri) - throws InvalidSPDXAnalysisException { - baseStore.delete(documentUri); - } - - public void delete(String documentUri, String id) - throws InvalidSPDXAnalysisException { - delete(documentUriIdToUri(documentUri, id, baseStore)); - } - - @Override - public SpdxMajorVersion getSpdxVersion() { - return SpdxMajorVersion.VERSION_2; - } - - /** - * @return the store this store wraps - */ - public IModelStore getBaseModelStore() { - return this.baseStore; - } - - @Override - public boolean equals(Object comp) { - return super.equals(comp); - // TODO: Return true the base is equal since this contains no properties - } - - @Override - public int hashCode() { - //TODO: Update once equals is updated - return super.hashCode(); - } - -} diff --git a/src/main/java/org/spdx/storage/package-info.java b/src/main/java/org/spdx/storage/package-info.java deleted file mode 100644 index 22094facc..000000000 --- a/src/main/java/org/spdx/storage/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Contains classes that implement the storage interfaces for reading and writing - * SPDX document properties. - * - * @author Gary O'Neall - * - */ -package org.spdx.storage; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java index 1bc72d9e2..c5ed8ddab 100644 --- a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java @@ -19,12 +19,16 @@ import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.TypedValue; +import javax.annotation.Nullable; + +import org.spdx.core.IExternalElementInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -61,8 +65,8 @@ public boolean exists(String objectUri) { * @see org.spdx.storage.IModelStore#create(java.lang.String, java.lang.String, java.lang.String) */ @Override - public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { - baseStore.create(objectUri, type); + public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException { + baseStore.create(typedValue); } /* (non-Javadoc) @@ -198,9 +202,9 @@ public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescrip * @see org.spdx.storage.IModelStore#isPropertyValueAssignableTo(java.lang.String, java.lang.String, java.lang.String, java.lang.Class) */ @Override - public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz); + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, + Class clazz, String specVersion) throws InvalidSPDXAnalysisException { + return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz, specVersion); } /* (non-Javadoc) @@ -264,5 +268,20 @@ public void delete(String objectUri) throws InvalidSPDXAnalysisException { public void close() throws Exception { baseStore.close(); } + + @Override + public synchronized @Nullable IExternalElementInfo getExternalElementInfo(String externalObjectUri, String collectionUri) { + return baseStore.getExternalElementInfo(externalObjectUri, collectionUri); + } + + @Override + public synchronized @Nullable Map getExternalReferenceMap(String externalObjectUri) { + return baseStore.getExternalReferenceMap(externalObjectUri); + } + + @Override + public synchronized @Nullable IExternalElementInfo addExternalReference(String externalObjectUri, String collectionUri, IExternalElementInfo externalElementInfo) { + return baseStore.addExternalReference(externalObjectUri, collectionUri, externalElementInfo); + } } diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index baf2bd487..253be78e6 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -18,16 +18,14 @@ package org.spdx.storage.simple; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Matcher; @@ -38,15 +36,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.DuplicateSpdxIdException; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.ModelCollectionV2; -import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; +import org.spdx.core.DuplicateSpdxIdException; +import org.spdx.core.IExternalElementInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelCollection; +import org.spdx.core.ModelRegistry; +import org.spdx.core.SpdxIdInUseException; +import org.spdx.core.SpdxIdNotFoundException; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.LicenseInfoFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -73,12 +72,16 @@ public class InMemSpdxStore implements IModelStore { static Pattern SPDX_ID_PATTERN_GENERATED = Pattern.compile(".*"+SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+"(\\d+)$"); public static final String ANON_PREFIX = "__anon__"; static Pattern ANON_ID_PATTERN_GENERATED = Pattern.compile(ANON_PREFIX+GENERATED+"(\\d+)$"); - private static final Set LITERAL_VALUE_SET = new HashSet(Arrays.asList(SpdxConstantsCompatV2.LITERAL_VALUES)); /** * Map of property object URI's to typed value items */ protected Map typedValueMap = Collections.synchronizedMap(new LinkedHashMap<>()); + + /** + * Map of an objectUri to a map of documentUri's to external element information + */ + protected Map> objectUriExternalMap = new HashMap<>(); private int nextNextLicenseId = 0; private int nextNextDocumentId = 0; private int nextNextSpdxId = 0; @@ -105,30 +108,62 @@ public void unlock() { }; - private SpdxMajorVersion spdxVersion; public InMemSpdxStore() { - this(SpdxMajorVersion.VERSION_3); + + } + + /** + * Adds an external reference for a given collection + * @param externalObjectUri URI of the external SPDX Element or License + * @param collectionUri URI of the SPDX document or collection + * @param externalElementInfo info about the external element + * @return the previous external mapping for the collection, null if no previous value is present + */ + @Override + public synchronized @Nullable IExternalElementInfo addExternalReference(String externalObjectUri, String collectionUri, IExternalElementInfo externalElementInfo) { + Map externalObjectToCollectionMap = objectUriExternalMap.get(externalObjectUri); + if (Objects.isNull(externalObjectToCollectionMap)) { + externalObjectToCollectionMap = new HashMap<>(); + } + return externalObjectToCollectionMap.put(collectionUri, externalElementInfo); } /** - * @param spdxVersion the major SPDX version for the model store (e.g. "2" or "3") + * @param externalObjectUri object URI for an element external to a collection + * @return a map of collection (or document) URI's mapped to their external element info for the given object URI */ - public InMemSpdxStore(SpdxMajorVersion spdxVersion) { - this.spdxVersion = spdxVersion; + @Override + public synchronized @Nullable Map getExternalReferenceMap(String externalObjectUri) { + return objectUriExternalMap.get(externalObjectUri); } - + + /** + * @param externalObjectUri URI of the external SPDX Element or License + * @param collectionUri URI of the SPDX document or collection + * @return the externalElementInfo associated with the collection for a given external element + */ + @Override + public synchronized @Nullable IExternalElementInfo getExternalElementInfo(String externalObjectUri, String collectionUri) { + Map externalObjectToCollectionMap = objectUriExternalMap.get(externalObjectUri); + if (Objects.isNull(externalObjectToCollectionMap)) { + return null; + } else { + return externalObjectToCollectionMap.get(collectionUri); + } + } + @Override public boolean exists(String objectUri) { return typedValueMap.containsKey(objectUri.toLowerCase()); } @Override - public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { - StoredTypedItem value = new StoredTypedItem(objectUri, type); - updateNextIds(objectUri); - if (Objects.nonNull(this.typedValueMap.putIfAbsent(objectUri.toLowerCase(), value))) { - throw new DuplicateSpdxIdException("Object URI "+objectUri+" already exists."); + public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException { + StoredTypedItem value = new StoredTypedItem(typedValue.getObjectUri(), typedValue.getType(), typedValue.getSpecVersion()); + updateNextIds(typedValue.getObjectUri()); + if (Objects.nonNull(this.typedValueMap.putIfAbsent(typedValue.getObjectUri().toLowerCase(), value))) { + throw new DuplicateSpdxIdException("Object URI "+typedValue.getObjectUri()+" already exists."); } } @@ -297,18 +332,12 @@ public Iterator listValues(String objectUri, PropertyDescriptor property @Override public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { StoredTypedItem item = getItem(objectUri); + Class itemClass = ModelRegistry.getModelRegistry().typeToClass(item.getType(), item.getSpecVersion()); + if (Objects.isNull(itemClass)) { + throw new InvalidSPDXAnalysisException("Unknown type "+item.getType()+" for spec version "+item.getSpecVersion()); + } if (item.isCollectionProperty(propertyDescriptor)) { - if (this.spdxVersion.compareTo(SpdxMajorVersion.VERSION_3) < 0) { - int indexOfPound = item.getObjectUri().lastIndexOf('#'); - if (indexOfPound < 0) { - throw new InvalidSPDXAnalysisException("Object URIs in SPDX 2 compatible stores must contain a '#' to determine the document URI"); - } - String documentUri = item.getObjectUri().substring(0, indexOfPound); - String id = item.getObjectUri().substring(indexOfPound + 1); - return Optional.of(new ModelCollectionV2<>(this, documentUri, id, propertyDescriptor, null ,null)); - } else { - throw new InvalidSPDXAnalysisException("Unimplemented version 3"); - } + return Optional.of(new ModelCollection(this, objectUri, propertyDescriptor, null, itemClass, item.getSpecVersion())); } else { return Optional.ofNullable(item.getValue(propertyDescriptor)); } @@ -322,7 +351,6 @@ public synchronized String getNextId(IdType idType, @Nullable String nameSpace) case DocumentRef: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); case SpdxId: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); case ListedLicense: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Listed License"); - case Literal: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Literal"); default: throw new InvalidSPDXAnalysisException("Unknown ID type for next ID: "+idType.toString()); } } @@ -370,13 +398,13 @@ public boolean collectionContains(String objectUri, PropertyDescriptor propertyD @Override public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - return getItem(objectUri).isCollectionMembersAssignableTo(propertyDescriptor, clazz, spdxVersion); + return getItem(objectUri).isCollectionMembersAssignableTo(propertyDescriptor, clazz); } @Override - public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz, String specVersion) throws InvalidSPDXAnalysisException { - return getItem(objectUri).isPropertyValueAssignableTo(propertyDescriptor, clazz); + return getItem(objectUri).isPropertyValueAssignableTo(propertyDescriptor, clazz, specVersion); } @Override @@ -402,9 +430,6 @@ public IdType getIdType(String id) { id.contains("#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { return IdType.SpdxId; } - if (LITERAL_VALUE_SET.contains(id)) { - return IdType.Literal; - } if (id.contains("://spdx.org/licenses/") || LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) { return IdType.ListedLicense; } else { @@ -505,12 +530,4 @@ public void delete(String objectUri) throws InvalidSPDXAnalysisException { public void close() throws Exception { // Nothing to do for the in-memory store } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#getSpdxVersion() - */ - @Override - public SpdxMajorVersion getSpdxVersion() { - return this.spdxVersion; - } } diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index 21345af7f..f54696e2b 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -1,14 +1,11 @@ package org.spdx.storage.simple; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Objects; -import java.util.Set; import java.util.Map.Entry; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -17,15 +14,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxInvalidTypeException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.enumerations.SpdxEnumFactoryCompatV2; +import org.spdx.core.CoreModelObject; +import org.spdx.core.IndividualUriValue; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistry; +import org.spdx.core.ModelRegistryException; +import org.spdx.core.SpdxCoreConstants.SpdxMajorVersion; +import org.spdx.core.SpdxInvalidTypeException; +import org.spdx.core.TypedValue; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; @@ -41,16 +37,14 @@ public class StoredTypedItem extends TypedValue { private static final String NO_ID_ID = "__NO_ID__"; // ID to use in list has map for non-typed values - static Set SPDX_CLASSES = new HashSet<>(Arrays.asList(SpdxConstantsCompatV2.ALL_SPDX_CLASSES)); - private ConcurrentHashMap properties = new ConcurrentHashMap<>(); private int referenceCount = 0; private final ReadWriteLock countLock = new ReentrantReadWriteLock(); - public StoredTypedItem(String objectUri, String type) throws InvalidSPDXAnalysisException { - super(objectUri, type); + public StoredTypedItem(String objectUri, String type, String specVersion) throws InvalidSPDXAnalysisException { + super(objectUri, type, specVersion); } /** @@ -119,7 +113,7 @@ public int getReferenceCount() throws SpdxInvalidTypeException { public void setValue(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(value, "Value can not be null"); - if (value instanceof ModelObject) { + if (value instanceof CoreModelObject) { throw new SpdxInvalidTypeException("Can not store Model Object in store. Convert to TypedValue first"); } else if (value instanceof List || value instanceof Collection) { throw new SpdxInvalidTypeException("Can not store list values directly. Use addValueToCollection."); @@ -162,7 +156,7 @@ public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws public boolean addValueToList(PropertyDescriptor propertyDescriptor, Object value) throws SpdxInvalidTypeException { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(value, "Value can not be null"); - if (value instanceof ModelObject) { + if (value instanceof CoreModelObject) { throw new SpdxInvalidTypeException("Can not store Model Object in store. Convert to TypedValue first"); } else if (!value.getClass().isPrimitive() && !value.getClass().isAssignableFrom(String.class) && @@ -403,8 +397,9 @@ public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object * @param propertyDescriptor descriptor for the property * @param clazz class to test against * @return true if the property with the propertyDescriptor can be assigned to clazz for the latest SPDX version + * @throws ModelRegistryException */ - public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws ModelRegistryException { return isCollectionMembersAssignableTo(propertyDescriptor, clazz, SpdxMajorVersion.latestVersion()); } @@ -413,8 +408,9 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri * @param clazz class to test against * @param specVersion Version of the SPDX Spec * @return true if the property with the propertyDescriptor can be assigned to clazz + * @throws ModelRegistryException */ - public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, SpdxMajorVersion specVersion) { + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, SpdxMajorVersion specVersion) throws ModelRegistryException { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); Object map = properties.get(propertyDescriptor); @@ -431,18 +427,19 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri if (!clazz.isAssignableFrom(value.getClass())) { if (value instanceof IndividualUriValue) { String uri = ((IndividualUriValue)value).getIndividualURI(); - Enum spdxEnum = SpdxEnumFactoryCompatV2.uriToEnum.get(uri); + Enum spdxEnum = ModelRegistry.getModelRegistry().uriToEnum(uri, specVersion); if (Objects.nonNull(spdxEnum)) { if (!clazz.isAssignableFrom(spdxEnum.getClass())) { return false; } - } else if (!(SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri) || - SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri))) { + } else if (Objects.isNull(ModelRegistry.getModelRegistry().uriToIndividual(uri, specVersion))) { return false; + //TODO: Test for type of individual } } else if (value instanceof TypedValue) { + TypedValue typedValue = (TypedValue)value; try { - if (clazz != TypedValue.class && !clazz.isAssignableFrom(SpdxModelFactory.typeToClass(((TypedValue)value).getType(), specVersion))) { + if (clazz != TypedValue.class && !clazz.isAssignableFrom(ModelRegistry.getModelRegistry().typeToClass(typedValue.getType(), typedValue.getSpecVersion()))) { return false; } } catch (InvalidSPDXAnalysisException e) { @@ -461,19 +458,11 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri /** * @param propertyDescriptor descriptor for the property * @param clazz class to test against + * @param specVersion Version of the spec to test for * @return true if the property can be assigned to type clazz for the latest SPDX spec version + * @throws ModelRegistryException */ - public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { - return isPropertyValueAssignableTo(propertyDescriptor, clazz, SpdxMajorVersion.latestVersion()); - } - - /** - * @param propertyDescriptor descriptor for the property - * @param clazz class to test against - * @param specVersion Version of the SPDX Spec - * @return true if the property can be assigned to type clazz - */ - public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, SpdxMajorVersion specVersion) { + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, String specVersion) throws ModelRegistryException { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); Object value = properties.get(propertyDescriptor); @@ -484,8 +473,9 @@ public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor return true; } if (value instanceof TypedValue) { + TypedValue typedValue = (TypedValue)value; try { - return clazz.isAssignableFrom(SpdxModelFactory.typeToClass(((TypedValue)value).getType(), specVersion)); + return clazz.isAssignableFrom(ModelRegistry.getModelRegistry().typeToClass(typedValue.getType(), typedValue.getSpecVersion())); } catch (InvalidSPDXAnalysisException e) { logger.error("Error converting typed value to class",e); return false; @@ -493,13 +483,11 @@ public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor } if (value instanceof IndividualUriValue) { String uri = ((IndividualUriValue)value).getIndividualURI(); - if (SpdxConstantsCompatV2.URI_VALUE_NOASSERTION.equals(uri)) { - return true; - } - if (SpdxConstantsCompatV2.URI_VALUE_NONE.equals(uri)) { + if (Objects.nonNull(ModelRegistry.getModelRegistry().uriToEnum(uri, specVersion))) { return true; } - Enum spdxEnum = SpdxEnumFactoryCompatV2.uriToEnum.get(uri); + //TODO: Check for individual URI types + Enum spdxEnum = ModelRegistry.getModelRegistry().uriToEnum(uri, specVersion); if (Objects.nonNull(spdxEnum)) { return clazz.isAssignableFrom(spdxEnum.getClass()); } else { diff --git a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java index 7673789a3..13da8ba7b 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java +++ b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java @@ -72,7 +72,7 @@ public ModelObjectForTesting(IModelStore modelStore, String objectUri, * @param builder * @throws InvalidSPDXAnalysisException */ - public ModelObjectForTesting(ModelObjectBuilder builder) + public ModelObjectForTesting(CoreModelObjectBuilder builder) throws InvalidSPDXAnalysisException { super(builder); } @@ -94,7 +94,7 @@ protected List _verify(Set verifiedElementIds, return new ArrayList(); } - public static class ModelObjectForTestingBuilder extends ModelObjectBuilder { + public static class ModelObjectForTestingBuilder extends CoreModelObjectBuilder { /** * Create an ElementBuilder from another model object copying the modelStore and copyManager and using an anonymous ID diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java index 25a65cfa3..a6e233c07 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxElementTest.java @@ -18,18 +18,20 @@ package org.spdx.library.model.compat.v2; +import java.lang.annotation.Annotation; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; import java.util.List; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; +import org.spdx.core.DefaultModelStore; +import org.spdx.core.SpdxCoreConstants.SpdxMajorVersion; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v2.GenericModelObject; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.SpdxElement; import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -57,7 +59,7 @@ public class SpdxElementTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); + DefaultModelStore.initialize(new InMemSpdxStore(SpdxMajorVersion.VERSION_2), "http://default/document", new ModelCopyManager()); gmo = new GenericModelObject(); ANNOTATION1 = gmo.createAnnotation("Person: Annotator1", AnnotationType.OTHER, DATE_NOW, "Comment1"); From 312dae10e86249c972dea82b1dab71e26a5cbbf1 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 1 May 2024 14:46:56 -0700 Subject: [PATCH 25/62] Working version for SPDXv2 annotation test Signed-off-by: Gary O'Neall --- .../org/spdx/library/ModelCopyManager.java | 178 +++++------------- .../spdx/storage/simple/StoredTypedItem.java | 18 +- .../library/model/ModelObjectHelperTest.java | 133 ------------- .../model/compat/v2/AnnotationTest.java | 18 +- 4 files changed, 66 insertions(+), 281 deletions(-) delete mode 100644 src/test/java/org/spdx/library/model/ModelObjectHelperTest.java diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index 36d5ea41b..ae5627738 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -28,7 +28,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.core.IModelCopyManager; +import org.spdx.core.IndividualUriValue; import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.SimpleUriValue; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -53,8 +57,7 @@ public class ModelCopyManager implements IModelCopyManager { * Map of copied ID's fromModelStore, toModelStore, fromObjectUri, toObjectUri * Used to keep track of copied ID's to make sure we don't copy them more than once */ - private ConcurrentHashMap>>> COPIED_IDS = + private ConcurrentHashMap>> COPIED_IDS = new ConcurrentHashMap<>(); /** @@ -68,24 +71,19 @@ public ModelCopyManager() { * @param fromStore Store copied from * @param fromObjectUri Object URI in the from tsotre * @param toStore store copied to - * @param toNamespace Optional nameSpace used for the copied URI - can copy the same object to multiple namespaces in the same toStore * @return the objectId which has already been copied, or null if it has not been copied */ public String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri, - IModelStore toStore, @Nullable String toNamespace) { - ConcurrentHashMap>> fromStoreMap = COPIED_IDS.get(fromStore); + IModelStore toStore) { + ConcurrentHashMap> fromStoreMap = COPIED_IDS.get(fromStore); if (Objects.isNull(fromStoreMap)) { return null; } - ConcurrentHashMap> toStoreMap = fromStoreMap.get(toStore); + ConcurrentHashMap toStoreMap = fromStoreMap.get(toStore); if (Objects.isNull(toStoreMap)) { return null; } - ConcurrentHashMap toNamespaceMap = toStoreMap.get(fromObjectUri); - if (Objects.isNull(toNamespaceMap)) { - return null; - } - return toNamespaceMap.get(toNamespace == null ? "" : toNamespace); + return toStoreMap.get(fromObjectUri); } /** @@ -93,50 +91,25 @@ public String getCopiedObjectUri(IModelStore fromStore, String fromObjectUri, * @param fromStore Store copied from * @param fromObjectUri URI for the from Object * @param toObjectUri URI for the to Object - * @param toNamespace Optional nameSpace used for the copied URI - can copy the same object to multiple namespaces in the same toStore * @return any copied to ID for the same stores, URI's, nameSpace and fromID */ public String putCopiedId(IModelStore fromStore, String fromObjectUri, IModelStore toStore, - String toObjectUri, @Nullable String toNamespace) { - ConcurrentHashMap>> fromStoreMap = COPIED_IDS.get(fromStore); + String toObjectUri) { + ConcurrentHashMap> fromStoreMap = COPIED_IDS.get(fromStore); while (Objects.isNull(fromStoreMap)) { fromStoreMap = COPIED_IDS.putIfAbsent(fromStore, new ConcurrentHashMap<>()); } - ConcurrentHashMap> toStoreMap = fromStoreMap.get(toStore); + ConcurrentHashMap toStoreMap = fromStoreMap.get(toStore); while (Objects.isNull(toStoreMap)) { toStoreMap = fromStoreMap.putIfAbsent(toStore, new ConcurrentHashMap<>()); } - ConcurrentHashMap toNamespaceMap = toStoreMap.get(fromObjectUri); - while (Objects.isNull(toNamespaceMap)) { - toNamespaceMap = toStoreMap.putIfAbsent(fromObjectUri, new ConcurrentHashMap<>()); - } - String ns = toNamespace == null ? "" : toNamespace; - if (toNamespaceMap.containsKey(ns)) { + + if (toStoreMap.containsKey(fromObjectUri)) { logger.warn("Object URI already exists for the originating "+ fromObjectUri); } - return toNamespaceMap.put(ns, toObjectUri); + return toStoreMap.put(fromObjectUri, toObjectUri); } - /** - * Copy an item from one Model Object Store to another - * @param toStore Model Store to copy to - * @param toObjectUri URI for the destination object - * @param fromStore Model Store containing the source item - * @param fromObjectUri Object URI for the source item - * @param type Type to copy - * @param fromNamespace optional namespace of the from property - * @param toNamespace optional namespace of the to property - * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace - * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace - * @throws InvalidSPDXAnalysisException - */ - public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri, String type, - @Nullable String fromNamespace, @Nullable String toNamespace, - @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { - copy(toStore, toObjectUri, fromStore, fromObjectUri, type, false, fromNamespace, toNamespace, - fromCollectionNamespace, toCollectionNamespace); - } - /** * Copy an item from one Model Object Store to another * @param toStore Model Store to copy to @@ -147,44 +120,32 @@ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, * @param fromId ID source ID * @param type Type to copy * @param toSpecVersion version of the spec the to value should comply with - * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses - * @param fromNamespace optional namespace of the from property - * @param toNamespace optional namespace of the to property - * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace - * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace + * @param toNamespace Namespace to use if an ID needs to be generated for the to object * @throws InvalidSPDXAnalysisException */ public void copy(IModelStore toStore, String toObjectUri, IModelStore fromStore, String fromObjectUri, - String type, boolean excludeLicenseDetails, String toSpecVersion, - @Nullable String fromNamespace, @Nullable String toNamespace, - @Nullable String fromCollectionNamespace, - @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { + String type, String toSpecVersion, + @Nullable String toNamespace) throws InvalidSPDXAnalysisException { Objects.requireNonNull(toStore, "ToStore can not be null"); Objects.requireNonNull(toObjectUri, "To Object URI can not be null"); Objects.requireNonNull(fromStore, "FromStore can not be null"); Objects.requireNonNull(fromObjectUri, "From ObjectUri can not be null"); Objects.requireNonNull(type, "Type can not be null"); + Objects.requireNonNull(toSpecVersion, "To spec version can not be null"); if (fromStore.equals(toStore) && fromObjectUri.equals(toObjectUri)) { return; // trying to copy the same thing! } if (!toStore.exists(toObjectUri)) { - toStore.create(toObjectUri, type, toSpecVersion); + toStore.create(new TypedValue(toObjectUri, type, toSpecVersion)); } - putCopiedId(fromStore, fromObjectUri, toStore, toObjectUri, toNamespace); - if (!(excludeLicenseDetails && - (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(type) || - SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)))) { - List propertyDescriptors = fromStore.getPropertyValueDescriptors(fromObjectUri); - for (PropertyDescriptor propDesc:propertyDescriptors) { - if (fromStore.isCollectionProperty(fromObjectUri, propDesc)) { - copyCollectionProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, excludeLicenseDetails, - (fromCollectionNamespace == null ? fromNamespace : fromCollectionNamespace), - (toCollectionNamespace == null ? toNamespace : toCollectionNamespace)); - } else { - copyIndividualProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, excludeLicenseDetails, - fromNamespace, toNamespace); - } + putCopiedId(fromStore, fromObjectUri, toStore, toObjectUri); + List propertyDescriptors = fromStore.getPropertyValueDescriptors(fromObjectUri); + for (PropertyDescriptor propDesc:propertyDescriptors) { + if (fromStore.isCollectionProperty(fromObjectUri, propDesc)) { + copyCollectionProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, toSpecVersion, toNamespace); + } else { + copyIndividualProperty(toStore, toObjectUri, fromStore, fromObjectUri, propDesc, toSpecVersion, toNamespace); } } } @@ -196,14 +157,13 @@ public void copy(IModelStore toStore, String toObjectUri, * @param fromStore Model Store containing the source item * @param fromObjectUri object to copy from * @param propDescriptor Descriptor for the property - * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses - * @param fromNamespace optional namespace of the from property - * @param toNamespace optional namespace of the to property + * @param toSpecVersion Version of the SPDX spec the to value complies with + * @param toNamespace Namespace to use if an ID needs to be generated for the to object * @throws InvalidSPDXAnalysisException */ private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IModelStore fromStore, - String fromObjectUri, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails, - @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + String fromObjectUri, PropertyDescriptor propDescriptor, + String toSpecVersion, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(false); //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection Optional result = Optional.empty(); @@ -220,12 +180,11 @@ private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IMo toStore.setValue(toObjectUri, propDescriptor, new SimpleUriValue((IndividualUriValue)result.get())); } else if (result.get() instanceof TypedValue) { TypedValue tv = (TypedValue)result.get(); - if (fromStore.equals(toStore) && Objects.equals(fromNamespace, toNamespace)) { + if (fromStore.equals(toStore)) { toStore.setValue(toObjectUri, propDescriptor, tv); } else { toStore.setValue(toObjectUri, propDescriptor, - copy(toStore, fromStore, tv.getObjectUri(), tv.getType(), excludeLicenseDetails, - fromNamespace, toNamespace, fromNamespace, toNamespace)); + copy(toStore, fromStore, tv.getObjectUri(), tv.getType(), toSpecVersion, toNamespace)); } } else { toStore.setValue(toObjectUri, propDescriptor, result.get()); @@ -240,14 +199,13 @@ private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IMo * @param fromStore Model Store containing the source item * @param fromDocumentUri Object URI to copy from * @param propDescriptor Descriptor for the property - * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses - * @param fromNamespace optional namespace of the from property - * @param toNamespace optional namespace of the to property + * @param toSpecVersion Version of the SPDX spec the to value complies with + * @param toNamespace Namespace to use if an ID needs to be generated for the to object * @throws InvalidSPDXAnalysisException */ private void copyCollectionProperty(IModelStore toStore, String toObjectUri, IModelStore fromStore, - String fromObjectUri, PropertyDescriptor propDescriptor, boolean excludeLicenseDetails, - @Nullable String fromNamespace, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { + String fromObjectUri, PropertyDescriptor propDescriptor, + String toSpecVersion, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(false); //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection Iterator fromListIter = null; @@ -266,12 +224,11 @@ private void copyCollectionProperty(IModelStore toStore, String toObjectUri, IMo toStoreItem = new SimpleUriValue((IndividualUriValue)listItem); } else if (listItem instanceof TypedValue) { TypedValue listItemTv = (TypedValue)listItem; - if (toStore.equals(fromStore) && Objects.equals(fromNamespace, toNamespace)) { + if (toStore.equals(fromStore)) { toStoreItem = listItemTv; } else { toStoreItem = copy(toStore, fromStore, listItemTv.getObjectUri(), - listItemTv.getType(), excludeLicenseDetails, fromNamespace, toNamespace, - fromNamespace, toNamespace); + listItemTv.getType(), toSpecVersion, toNamespace); } } else { toStoreItem = listItem; @@ -279,26 +236,6 @@ private void copyCollectionProperty(IModelStore toStore, String toObjectUri, IMo toStore.addValueToCollection(toObjectUri, propDescriptor, toStoreItem); } } - - /** - * Copy an item from one Model Object Store to another using the source ID for the target unless it is anonymous - * @param toStore Model Store to copy to - * @param fromStore Model Store containing the source item - * @param sourceObjectUri source object URI - * @param type Type to copy - * @param fromNamespace optional namespace of the from property - * @param toNamespace optional namespace of the to property - * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace - * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace - * @return Object URI for the copied object - * @throws InvalidSPDXAnalysisException - */ - public TypedValue copy(IModelStore toStore, IModelStore fromStore, - String sourceObjectUri, String type, - @Nullable String fromNamespace, @Nullable String toNamespace, - @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { - return copy(toStore, fromStore, sourceObjectUri, type, false, fromNamespace, toNamespace, fromCollectionNamespace, toCollectionNamespace); - } /** * Copy an item from one Model Object Store to another using the source ID for the target unless it is anonymous @@ -306,36 +243,25 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, * @param fromStore Model Store containing the source item * @param sourceUri URI for the Source object * @param type Type to copy - * @param excludeLicenseDetails If true, don't copy over properties of the listed licenses - * @param fromNamespace optional namespace of the from property - * @param toNamespace optional namespace of the to property - * @param fromCollectionNamespace Optional namespace for the from collection to use when creating items for collections. Defaults to toNamespace - * @param toCollectionNamespace Optional namespace for the to collection to use when creating items for collections. Defaults to toNamespace + * @param toSpecVersion Version of the SPDX spec the to value complies with + * @param toNamespace Namespace to use if an ID needs to be generated for the to object * @return Object URI for the copied object * @throws InvalidSPDXAnalysisException */ public TypedValue copy(IModelStore toStore, IModelStore fromStore, - String sourceUri, String type, boolean excludeLicenseDetails, - @Nullable String fromNamespace, @Nullable String toNamespace, - @Nullable String fromCollectionNamespace, @Nullable String toCollectionNamespace) throws InvalidSPDXAnalysisException { + String sourceUri, String type, String toSpecVersion, @Nullable String toNamespace) throws InvalidSPDXAnalysisException { Objects.requireNonNull(toStore, "To Store can not be null"); Objects.requireNonNull(fromStore, "From Store can not be null"); Objects.requireNonNull(sourceUri, "Source URI can not be null"); Objects.requireNonNull(type, "Type can not be null"); - if (fromStore.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) >= 0 && - toStore.getSpdxVersion().compareTo(SpdxMajorVersion.VERSION_3) < 0) { - throw new InvalidSPDXAnalysisException("Can not copy from SPDX spec version 3.0 to SPDX spec version less than 3.0"); - } - String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore, toNamespace); + Objects.requireNonNull(toSpecVersion, "To specVersion can not be null"); + + String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore); if (Objects.isNull(toObjectUri)) { - if (!(fromStore.getIdType(sourceUri) == IdType.Anonymous)) { - if (Objects.nonNull(fromNamespace) && sourceUri.startsWith(fromNamespace) && Objects.nonNull(toNamespace)) { - toObjectUri = toNamespace + sourceUri.substring(fromNamespace.length()); - } else { - toObjectUri = sourceUri; - } - } - if (Objects.isNull(toObjectUri) || toStore.exists(toObjectUri)) { + if (toStore.exists(sourceUri)) { + logger.warn("Copying to an existing object "+sourceUri); + toObjectUri = sourceUri; + } else if (Objects.nonNull(toNamespace)) { if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { toObjectUri = toStore.getNextId(IdType.DocumentRef, toNamespace); } else { @@ -345,7 +271,6 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, case DocumentRef: toObjectUri = toStore.getNextId(IdType.DocumentRef, toNamespace); break; case SpdxId: toObjectUri = toStore.getNextId(IdType.SpdxId, toNamespace); break; case ListedLicense: - case Literal: case Unkown: default: toObjectUri = sourceUri; } @@ -354,9 +279,8 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, if (Objects.isNull(toObjectUri)) { toObjectUri = sourceUri; } - copy(toStore, toObjectUri, fromStore, sourceUri, type, excludeLicenseDetails, fromNamespace, toNamespace, - fromCollectionNamespace, toCollectionNamespace); + copy(toStore, toObjectUri, fromStore, sourceUri, type, toSpecVersion, toNamespace); } - return new TypedValue(toObjectUri, type); + return new TypedValue(toObjectUri, type, toSpecVersion); } } diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index f54696e2b..6d579f9b9 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -19,7 +19,6 @@ import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.core.ModelRegistry; import org.spdx.core.ModelRegistryException; -import org.spdx.core.SpdxCoreConstants.SpdxMajorVersion; import org.spdx.core.SpdxInvalidTypeException; import org.spdx.core.TypedValue; import org.spdx.storage.IModelStore; @@ -392,25 +391,14 @@ public boolean collectionContains(PropertyDescriptor propertyDescriptor, Object throw new SpdxInvalidTypeException("Trying to find contains for non list type for property "+propertyDescriptor); } } - - /** - * @param propertyDescriptor descriptor for the property - * @param clazz class to test against - * @return true if the property with the propertyDescriptor can be assigned to clazz for the latest SPDX version - * @throws ModelRegistryException - */ - public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws ModelRegistryException { - return isCollectionMembersAssignableTo(propertyDescriptor, clazz, SpdxMajorVersion.latestVersion()); - } /** * @param propertyDescriptor descriptor for the property * @param clazz class to test against - * @param specVersion Version of the SPDX Spec * @return true if the property with the propertyDescriptor can be assigned to clazz * @throws ModelRegistryException */ - public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz, SpdxMajorVersion specVersion) throws ModelRegistryException { + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws ModelRegistryException { Objects.requireNonNull(propertyDescriptor, "Property descriptor can not be null"); Objects.requireNonNull(clazz, "Class can not be null"); Object map = properties.get(propertyDescriptor); @@ -427,12 +415,12 @@ public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescri if (!clazz.isAssignableFrom(value.getClass())) { if (value instanceof IndividualUriValue) { String uri = ((IndividualUriValue)value).getIndividualURI(); - Enum spdxEnum = ModelRegistry.getModelRegistry().uriToEnum(uri, specVersion); + Enum spdxEnum = ModelRegistry.getModelRegistry().uriToEnum(uri, getSpecVersion()); if (Objects.nonNull(spdxEnum)) { if (!clazz.isAssignableFrom(spdxEnum.getClass())) { return false; } - } else if (Objects.isNull(ModelRegistry.getModelRegistry().uriToIndividual(uri, specVersion))) { + } else if (Objects.isNull(ModelRegistry.getModelRegistry().uriToIndividual(uri, getSpecVersion()))) { return false; //TODO: Test for type of individual } diff --git a/src/test/java/org/spdx/library/model/ModelObjectHelperTest.java b/src/test/java/org/spdx/library/model/ModelObjectHelperTest.java deleted file mode 100644 index 05ccf38a7..000000000 --- a/src/test/java/org/spdx/library/model/ModelObjectHelperTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import junit.framework.TestCase; - -/** - * @author gary - * - */ -public class ModelObjectHelperTest extends TestCase { - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#getObjectPropertyValue(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, org.spdx.library.ModelCopyManager)}. - */ - public void testGetObjectPropertyValue() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#setPropertyValue(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object, org.spdx.library.ModelCopyManager)}. - */ - public void testSetPropertyValue() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#removeProperty(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor)}. - */ - public void testRemoveProperty() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#clearValueCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor)}. - */ - public void testClearValueCollection() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#addValueToCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object, org.spdx.library.ModelCopyManager)}. - */ - public void testAddValueToCollection() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#replacePropertyValueCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.util.Collection, org.spdx.library.ModelCopyManager)}. - */ - public void testReplacePropertyValueCollection() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#removePropertyValueFromCollection(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testRemovePropertyValueFromCollection() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#optionalStoredObjectToModelObject(java.util.Optional, org.spdx.storage.IModelStore, org.spdx.library.ModelCopyManager)}. - */ - public void testOptionalStoredObjectToModelObject() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#modelObjectToStoredObject(java.lang.Object, org.spdx.storage.IModelStore, org.spdx.library.ModelCopyManager)}. - */ - public void testModelObjectToStoredObject() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#storedObjectToModelObject(java.lang.Object, org.spdx.storage.IModelStore, org.spdx.library.ModelCopyManager)}. - */ - public void testStoredObjectToModelObject() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#modelClassToStoredClass(java.lang.Class)}. - */ - public void testModelClassToStoredClass() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#implementsIndividualUriValue(java.lang.Class)}. - */ - public void testImplementsIndividualUriValue() { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectHelper#verifyCollection(java.util.Collection, java.lang.String, java.util.Set, java.lang.String)}. - */ - public void testVerifyCollection() { - fail("Not yet implemented"); - } - -} diff --git a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java index d166b25bc..6ebf60c5a 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/AnnotationTest.java @@ -21,11 +21,16 @@ import java.text.SimpleDateFormat; import java.util.Date; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.SpdxConstantsCompatV2; +import org.spdx.core.DefaultModelStore; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistry; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.GenericModelObject; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.SpdxModelInfoV2_X; +import org.spdx.library.model.v2.enumerations.AnnotationType; +import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -49,7 +54,8 @@ public class AnnotationTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV2_X()); + DefaultModelStore.initialize(new InMemSpdxStore(), "http://defaultdocument", new ModelCopyManager()); DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); date = format.format(new Date()); oldDate = format.format(new Date(10101)); From 7ac928a7912328fcc1d7d25b48a5413ac2a5c2bd Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 17 May 2024 12:00:29 -0700 Subject: [PATCH 26/62] Working SPDX-3 Signed-off-by: Gary O'Neall --- pom.xml | 5 + .../org/spdx/library/ModelCopyManager.java | 10 +- .../java/org/spdx/library/ModelManager.java | 2 + .../org/spdx/library/model/package-info.java | 2 +- .../storage/listedlicense/CrossRefJson.java | 266 ---- .../storage/listedlicense/ExceptionJson.java | 278 ---- .../listedlicense/ExceptionJsonTOC.java | 232 ---- .../listedlicense/IListedLicenseStore.java | 74 -- .../storage/listedlicense/LicenseJson.java | 387 ------ .../storage/listedlicense/LicenseJsonTOC.java | 263 ---- .../SpdxListedLicenseLocalStore.java | 81 -- .../SpdxListedLicenseModelStore.java | 1163 ----------------- .../SpdxListedLicenseWebStore.java | 103 -- .../storage/listedlicense/package-info.java | 28 - .../storage/simple/ExtendedSpdxStore.java | 4 +- .../spdx/storage/simple/InMemSpdxStore.java | 9 +- .../spdx/utility/compare/SpdxComparer.java | 8 +- .../spdx/library/SpdxModelFactoryTest.java | 18 +- .../library/model/ModelObjectForTesting.java | 8 +- .../spdx/library/model/ModelObjectTest.java | 80 +- .../model/compat/v2/ModelObjectTest.java | 82 +- .../v2/ModelStorageClassConverterTest.java | 4 +- .../model/compat/v2/SpdxDocumentTest.java | 74 +- .../library/model/v3/ai/AIPackageTest.java | 26 +- .../spdx/utility/compare/UnitTestHelper.java | 10 +- 25 files changed, 189 insertions(+), 3028 deletions(-) delete mode 100644 src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/LicenseJson.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java delete mode 100644 src/main/java/org/spdx/storage/listedlicense/package-info.java diff --git a/pom.xml b/pom.xml index 7a764ae25..071b52880 100644 --- a/pom.xml +++ b/pom.xml @@ -170,6 +170,11 @@ spdx-java-core 0.0.1-SNAPSHOT + + spdx + spdx-java-model-3_0 + 0.0.1-SNAPSHOT + diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index ae5627738..e76525e65 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -263,13 +263,13 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, toObjectUri = sourceUri; } else if (Objects.nonNull(toNamespace)) { if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { - toObjectUri = toStore.getNextId(IdType.DocumentRef, toNamespace); + toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); } else { switch (fromStore.getIdType(sourceUri)) { - case Anonymous: toObjectUri = toStore.getNextId(IdType.Anonymous, toNamespace); break; - case LicenseRef: toObjectUri = toStore.getNextId(IdType.LicenseRef, toNamespace); break; - case DocumentRef: toObjectUri = toStore.getNextId(IdType.DocumentRef, toNamespace); break; - case SpdxId: toObjectUri = toStore.getNextId(IdType.SpdxId, toNamespace); break; + case Anonymous: toObjectUri = toStore.getNextId(IdType.Anonymous); break; + case LicenseRef: toObjectUri = toNamespace + toStore.getNextId(IdType.LicenseRef); break; + case DocumentRef: toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); break; + case SpdxId: toObjectUri = toNamespace + toStore.getNextId(IdType.SpdxId); break; case ListedLicense: case Unkown: default: toObjectUri = sourceUri; diff --git a/src/main/java/org/spdx/library/ModelManager.java b/src/main/java/org/spdx/library/ModelManager.java index 0e9ec2d3a..f05a593ea 100644 --- a/src/main/java/org/spdx/library/ModelManager.java +++ b/src/main/java/org/spdx/library/ModelManager.java @@ -19,6 +19,7 @@ import org.spdx.core.ModelRegistry; import org.spdx.library.model.v2.SpdxModelInfoV2_X; +import org.spdx.library.model.v3.SpdxModelInfoV3_0; /** * Main entrypoint for the SPDX Java Library @@ -40,6 +41,7 @@ public class ModelManager { static { // register the supported spec version models ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV2_X()); + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV3_0()); } /** diff --git a/src/main/java/org/spdx/library/model/package-info.java b/src/main/java/org/spdx/library/model/package-info.java index 2c7a4cb64..80265b034 100644 --- a/src/main/java/org/spdx/library/model/package-info.java +++ b/src/main/java/org/spdx/library/model/package-info.java @@ -20,7 +20,7 @@ * * Sub packages are named by profile * - * All model objects inherit the ModelObject abstract class which contains useful helper functions + * All model objects inherit the ModelObjectV2 abstract class which contains useful helper functions * * @author Gary O'Neall * diff --git a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java deleted file mode 100644 index 49a49c99b..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.spdx.storage.listedlicense; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.InvalidSpdxPropertyException; -import org.spdx.library.model.compat.v2.license.CrossRef; - -/** - * JSON Representation of a CrossRef - * - * @author Gary O'Neall - * - */ -class CrossRefJson { - - public String match; - public String url; - public Boolean isValid; - public Boolean isLive; - public String timestamp; - public Boolean isWayBackLink; - public Integer order; - private transient String id; // The ID is always transient and of anonymous type - - public CrossRefJson() { - // empty constructor so GSON will work - } - - /** - * @param crossRef cross ref to copy values from - * @throws InvalidSPDXAnalysisException - */ - public CrossRefJson(CrossRef crossRef) throws InvalidSPDXAnalysisException { - this.id = crossRef.getId(); - Optional fromMatch = crossRef.getMatch(); - if (fromMatch.isPresent()) { - match = fromMatch.get(); - } - Optional fromUrl = crossRef.getUrl(); - if (fromUrl.isPresent()) { - url = fromUrl.get(); - } - Optional fromIsValid = crossRef.getValid(); - if (fromIsValid.isPresent()) { - isValid = fromIsValid.get(); - } - Optional fromIsLive = crossRef.getLive(); - if (fromIsLive.isPresent()) { - isLive = fromIsLive.get(); - } - Optional fromIsWayBackLink = crossRef.getIsWayBackLink(); - if (fromIsWayBackLink.isPresent()) { - isWayBackLink = fromIsWayBackLink.get(); - } - Optional fromTimestamp = crossRef.getTimestamp(); - if (fromTimestamp.isPresent()) { - timestamp = fromTimestamp.get(); - } - Optional fromOrder = crossRef.getOrder(); - if (fromOrder.isPresent()) { - order = fromOrder.get(); - } - } - - /** - * @return all valid property names - */ - public List getPropertyValueNames() { - List retval = new ArrayList(); - if (Objects.nonNull(match)) { - retval.add("match"); - } - if (Objects.nonNull(url)) { - retval.add("url"); - } - if (Objects.nonNull(isValid)) { - retval.add("isValid"); - } - if (Objects.nonNull(isLive)) { - retval.add("isLive"); - } - if (Objects.nonNull(timestamp)) { - retval.add("timestamp"); - } - if (Objects.nonNull(isWayBackLink)) { - retval.add("isWayBackLink"); - } - if (Objects.nonNull(order)) { - retval.add("order"); - } - return retval; - } - - /** - * Sets the value to the property name - * @param propertyName - * @param value - * @throws InvalidSpdxPropertyException - */ - public void setPrimativeValue(String propertyName, Object value) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "match": if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - this.match = (String)value; - break; - case "url": if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - this.url = (String)value; - break; - case "timestamp": if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - this.timestamp = (String)value; - break; - case "isValid": if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected boolean type for "+propertyName); - } - this.isValid = (Boolean)value; - break; - case "isLive": if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected boolean type for "+propertyName); - } - this.isLive = (Boolean)value; - break; - case "isWayBackLink": if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected boolean type for "+propertyName); - } - this.isWayBackLink = (Boolean)value; - break; - case "order": if (!(value instanceof Integer)) { - throw new InvalidSpdxPropertyException("Expected integer type for "+propertyName); - } - this.order = (Integer)value; - break; - default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyName); - } - } - - public void clearPropertyValueList(String propertyName) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException(propertyName + " is not a list type."); - } - - public boolean addPrimitiveValueToList(String propertyName, Object value) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException(propertyName + " is not a list type."); - } - - public boolean removePrimitiveValueToList(String propertyName, Object value) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException(propertyName + " is not a list type."); - } - - public @Nullable String getId() { - return this.id; - } - - public void setId(String crossRefId) { - this.id = crossRefId; - } - - /** - * @param propertyName - * @return the list associated with the property - * @throws InvalidSpdxPropertyException - */ - public List getValueList(String propertyName) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException(propertyName + " is not a list type."); - } - - /** - * @param propertyName - * @return the value associated with the property - null if not assigned or not present - * @throws InvalidSpdxPropertyException - */ - public @Nullable Object getValue(String propertyName) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "match": return this.match; - case "url": return this.url; - case "isValid": return this.isValid; - case "isLive": return this.isLive; - case "timestamp": return this.timestamp; - case "isWayBackLink": return this.isWayBackLink; - case "order": return this.order; - default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyName); - } - } - - /** - * sets the property to null (no way to remove in this store) - * @param propertyName - * @throws InvalidSpdxPropertyException - */ - public void removeProperty(String propertyName) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "match": this.match = null; break; - case "url": this.url = null; break; - case "isValid": this.isValid = null; break; - case "isLive": this.isLive = null; break; - case "timestamp": this.timestamp = null; break; - case "isWayBackLink": this.isWayBackLink = null; break; - case "order": this.order = null; break; - default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyName); - } - } - - /** - * @param propertyName - * @param clazz - * @return true if the members can be assigned from clazz - */ - public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - return false; - } - - /** - * @param propertyName - * @param clazz - * @return true if the property can be assigned from clazz - * @throws InvalidSpdxPropertyException - */ - public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "match": - case "url": - case "timestamp": return String.class.isAssignableFrom(clazz); - case "isValid": - case "isLive": - case "isWayBackLink": return Boolean.class.isAssignableFrom(clazz); - case "order": return Integer.class.isAssignableFrom(clazz); - default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyName); - } - - } - - /** - * @param propertyName - * @return if the property is a colloection - */ - public boolean isCollectionProperty(String propertyName) { - return false; - } -} \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java deleted file mode 100644 index 2443e82b7..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java +++ /dev/null @@ -1,278 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.InvalidSpdxPropertyException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; - -/** - * Simple POJO to hold the license exception data loaded from a JSON file - * - * Licenses in the JSON format can be found at spdx.org/licenses/[exceptionid].json - * - * @author Gary O'Neall - * - */ -public class ExceptionJson { - - static final List PROPERTY_VALUE_NAMES = Collections.unmodifiableList(Arrays.asList( - "licenseExceptionText", "name", "licenseExceptionTemplate", - "example", "isDeprecatedLicenseId", "deprecatedVersion", - "comment", "licenseExceptionId", "seeAlso", "exceptionTextHtml")); //NOTE: This list must be updated if any new properties are added - - Boolean isDeprecatedLicenseId; - String licenseExceptionText; - String name; - String licenseComments; //TODO: This is for legacy JSON files - this should be removed in 3.0. See https://github.com/spdx/spdx-spec/issues/158 - String comment; - List seeAlso = new ArrayList<>(); - String licenseExceptionId; - String licenseExceptionTemplate; - String example; - String deprecatedVersion; - String exceptionTextHtml; - - public ExceptionJson(String id) { - this.licenseExceptionId = id; - } - - public ExceptionJson() { - - } - - public List getPropertyValueNames() { - return PROPERTY_VALUE_NAMES; - } - - public void setTypedProperty(String propertyName, String valueId, String type) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException("Invalid type for Listed License SPDX Property: "+type); - } - - public void setPrimativeValue(String propertyName, Object value) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseExceptionText": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseExceptionText = (String)value; - break; - case "name": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - name = (String)value; - break; - case "seeAlso":throw new InvalidSpdxPropertyException("Expected list type for "+propertyName); - case "licenseExceptionTemplate": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseExceptionTemplate = (String)value; - break; - case "example": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - example = (String)value; - break; - case "isDeprecatedLicenseId": - if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyName); - } - isDeprecatedLicenseId = (Boolean)value; - break; - case "deprecatedVersion": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - deprecatedVersion = (String)value; - break; - case "comment": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseComments = (String)value; - comment = (String)value; - break; - case "licenseExceptionId": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseExceptionId = (String)value; - break; - case "exceptionTextHtml": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - exceptionTextHtml = (String)value; - break; - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - } - - public void clearPropertyValueList(String propertyName) throws InvalidSpdxPropertyException { - if (!"seeAlso".equals(propertyName)) { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - seeAlso.clear(); - } - - public void addValueToList(String propertyName, String valueId, String type) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException("Invalid type for Listed License SPDX Property: "+type); - } - - public boolean addPrimitiveValueToList(String propertyName, Object value) throws InvalidSpdxPropertyException { - if (!"seeAlso".equals(propertyName)) { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - return seeAlso.add((String)value); - } - - public List getValueList(String propertyName) throws InvalidSpdxPropertyException { - if (!"seeAlso".equals(propertyName)) { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - return seeAlso; - } - - public Object getValue(String propertyName) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseExceptionText": return licenseExceptionText; - case "name": return name; - case "seeAlso":return seeAlso; - case "licenseExceptionTemplate": return licenseExceptionTemplate; - case "example": return example; - case "isDeprecatedLicenseId": return isDeprecatedLicenseId; - case "deprecatedVersion": return deprecatedVersion; - case "comment": - if (comment != null) return comment; - return licenseComments; - case "licenseExceptionId": return licenseExceptionId; - case "exceptionTextHtml": return exceptionTextHtml; - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - } - - public void removeProperty(String propertyName) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseExceptionText": licenseExceptionText = null; break; - case "name": name = null; break; - case "seeAlso":seeAlso.clear(); break; - case "licenseExceptionTemplate": licenseExceptionTemplate = null; break; - case "example": example = null; break; - case "isDeprecatedLicenseId": isDeprecatedLicenseId = null; break; - case "deprecatedVersion": deprecatedVersion = null; break; - case "comment": - comment = null; - licenseComments = null; break; - case "licenseExceptionId": licenseExceptionId = null; break; - case "exceptionTextHtml": exceptionTextHtml = null; break; - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - - } - - @SuppressWarnings("deprecation") - public void copyFrom(ListedLicenseException fromException) throws InvalidSPDXAnalysisException { - /* TODO: Uncomment this in in SPDX 3.0 and remove the next couple set for licenseComment and comment - this.licenseComments = null; - this.comment = fromException.getComment(); - if (Objects.nonNull(this.comment) && this.comment.isEmpty()) { - this.comment = null; - } - */ - this.comment = null; - this.licenseComments = fromException.getComment(); - if (Objects.nonNull(this.licenseComments) && this.licenseComments.isEmpty()) { - this.licenseComments = null; - } - this.deprecatedVersion = fromException.getDeprecatedVersion(); - if (Objects.nonNull(this.deprecatedVersion) && this.deprecatedVersion.isEmpty()) { - this.deprecatedVersion = null; - } - this.example = fromException.getExample(); - if (Objects.nonNull(this.example) && this.example.isEmpty()) { - this.example = null; - } - this.isDeprecatedLicenseId = fromException.isDeprecated(); - this.licenseExceptionId = fromException.getId(); - this.licenseExceptionTemplate = fromException.getLicenseExceptionTemplate(); - if (Objects.nonNull(this.licenseExceptionTemplate) && this.licenseExceptionTemplate.isEmpty()) { - this.licenseExceptionTemplate = null; - } - this.licenseExceptionText = fromException.getLicenseExceptionText(); - if (Objects.nonNull(this.licenseExceptionText) && this.licenseExceptionText.isEmpty()) { - this.licenseExceptionText = null; - } - this.name = fromException.getName(); - if (Objects.nonNull(this.name) && this.name.isEmpty()) { - this.name = null; - } - this.seeAlso = new ArrayList(fromException.getSeeAlso()); - this.exceptionTextHtml = fromException.getExceptionTextHtml(); - if (Objects.nonNull(this.exceptionTextHtml) && this.exceptionTextHtml.isEmpty()) { - this.exceptionTextHtml = null; - } - } - - public boolean removePrimitiveValueToList(String propertyName, Object value) throws InvalidSpdxPropertyException { - if (!"seeAlso".equals(propertyName)) { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - return seeAlso.remove(value); - } - - public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseExceptionText": - case "name": - case "licenseExceptionTemplate": - case "example": - case "comment": - case "deprecatedVersion": - case "exceptionTextHtml": - case "licenseExceptionId": return String.class.isAssignableFrom(clazz); - case "seeAlso": return false; - case "isDeprecatedLicenseId": return Boolean.class.isAssignableFrom(clazz); - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - } - - public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - if (!SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { - return false; - } - return String.class.isAssignableFrom(clazz); - } - - public boolean isCollectionProperty(String propertyName) { - return SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName); - } - -} diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java deleted file mode 100644 index 6d485c528..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java +++ /dev/null @@ -1,232 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; - - -/** - * Table of Contents for the listed license list as represented as a JSON index file - * at spdx.org/licenses/licenses.json - * - * @author Gary O'Neall - * - */ -public class ExceptionJsonTOC { - static class ExceptionJson { - private String reference; - private boolean isDeprecatedLicenseId; - private String detailsUrl; - private int referenceNumber; - private String name; - private String licenseExceptionId; - private List seeAlso; - /** - * @return the licenseExceptionId - */ - public String getLicenseExceptionId() { - return licenseExceptionId; - } - /** - * @return the reference - */ - public String getReference() { - return reference; - } - /** - * @return the isDeprecatedLicenseId - */ - public boolean isDeprecatedLicenseId() { - return isDeprecatedLicenseId; - } - /** - * @return the detailsUrl - */ - public String getDetailsUrl() { - return detailsUrl; - } - /** - * @return the referenceNumber - */ - public int getReferenceNumber() { - return referenceNumber; - } - /** - * @return the name - */ - public String getName() { - return name; - } - /** - * @return the seeAlso - */ - public List getSeeAlso() { - return seeAlso; - } - /** - * @param reference the reference to set - */ - public void setReference(String reference) { - this.reference = reference; - } - /** - * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set - */ - public void setDeprecatedLicenseId(boolean isDeprecatedLicenseId) { - this.isDeprecatedLicenseId = isDeprecatedLicenseId; - } - /** - * @param detailsUrl the detailsUrl to set - */ - public void setDetailsUrl(String detailsUrl) { - this.detailsUrl = detailsUrl; - } - /** - * @param referenceNumber the referenceNumber to set - */ - public void setReferenceNumber(int referenceNumber) { - this.referenceNumber = referenceNumber; - } - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - /** - * @param licenseExceptionId the licenseExceptionId to set - */ - public void setLicenseExceptionId(String licenseExceptionId) { - this.licenseExceptionId = licenseExceptionId; - } - /** - * @param seeAlso the seeAlso to set - */ - public void setSeeAlso(List seeAlso) { - this.seeAlso = seeAlso; - } - } - - - private String licenseListVersion; - private List exceptions; - private String releaseDate; - - public ExceptionJsonTOC(String version, String releaseDate) { - this.licenseListVersion = version; - this.releaseDate = releaseDate; - exceptions = new ArrayList<>(); - } - - public ExceptionJsonTOC() { - licenseListVersion = null; - exceptions = new ArrayList<>(); - releaseDate = null; - } - - /** - * @return the licenseListVersion - */ - public @Nullable String getLicenseListVersion() { - return licenseListVersion; - } - - /** - * @return the exceptions - */ - public List getExceptions() { - return exceptions; - } - - /** - * @return map of lower case to correct case exception IDs - */ - public Map getExceptionIds() { - Map retval = new HashMap<>(); - if (exceptions == null) { - return retval; - } - for (ExceptionJson licenseException:exceptions) { - retval.put(licenseException.licenseExceptionId.toLowerCase(), licenseException.licenseExceptionId); - } - return retval; - } - - /** - * @return the releaseDate - */ - public @Nullable String getReleaseDate() { - return releaseDate; - } - - /** - * Add a new exception to the list of exceptions - * @param exception - * @param exceptionHTMLReference - * @param exceptionJSONReference - * @param deprecated - * @throws InvalidSPDXAnalysisException - */ - public void addException(ListedLicenseException exception, String exceptionHTMLReference, - String exceptionJSONReference, boolean deprecated) throws InvalidSPDXAnalysisException { - ExceptionJson ej = new ExceptionJson(); - ej.setLicenseExceptionId(exception.getId()); - ej.setDeprecatedLicenseId(deprecated); - ej.setDetailsUrl(exceptionHTMLReference); - ej.setName(exception.getName()); - ej.setReference(exceptionJSONReference); - int referenceNumber = 0; - for (ExceptionJson existing:this.exceptions) { - if (existing.getReferenceNumber() > referenceNumber) { - referenceNumber = existing.getReferenceNumber(); - } - } - referenceNumber++; - ej.setReferenceNumber(referenceNumber); - List seeAlso = new ArrayList<>(); - for (String sa:exception.getSeeAlso()) { - seeAlso.add(sa); - } - ej.setSeeAlso(seeAlso); - this.exceptions.add(ej); - } - - /** - * @param licenseListVersion the licenseListVersion to set - */ - public void setLicenseListVersion(String licenseListVersion) { - this.licenseListVersion = licenseListVersion; - } - - /** - * @param releaseDate the releaseDate to set - */ - public void setReleaseDate(String releaseDate) { - this.releaseDate = releaseDate; - } - - -} diff --git a/src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java b/src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java deleted file mode 100644 index 27fdb9d44..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.util.List; -import java.util.Optional; - -import org.spdx.storage.IModelStore; - -/** - * @author Gary O'Neall - * - * Extends the model store to include interfaces specific to listed licenses - * - */ -public interface IListedLicenseStore extends IModelStore { - - /** - * @return List of all SPDX listed license IDs - */ - List getSpdxListedLicenseIds(); - - /** - * @return The version of the loaded license list in the form M.N, where M is the major release and N is the minor release. - */ - String getLicenseListVersion(); - - /** - * @param listedLicenseDocumentUri - * @param licenseId - * @return true if the licenseId belongs to an SPDX listed license - */ - boolean isSpdxListedLicenseId(String listedLicenseDocumentUri, String licenseId); - - /** - * @param listedLicenseDocumentUri - * @param exceptionId - * @return true if the exceptionId belongs to an SPDX listed exception - */ - boolean isSpdxListedExceptionId(String listedLicenseDocumentUri, String exceptionId); - - /** - * @return list of SPDX exception IDs - */ - List getSpdxListedExceptionIds(); - - /** - * @param licenseId case insensitive license ID - * @return the case sensitive license ID - */ - Optional listedLicenseIdCaseSensitive(String licenseId); - - /** - * @param exceptionId case insensitive exception ID - * @return case sensitive ID - */ - Optional listedExceptionIdCaseSensitive(String exceptionId); - -} diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java deleted file mode 100644 index 3b199d104..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java +++ /dev/null @@ -1,387 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.InvalidSpdxPropertyException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.license.CrossRef; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; -import org.spdx.licenseTemplate.InvalidLicenseTemplateException; - -/** - * Simple POJO to hold the license data loaded from a JSON file - * - * Licenses in the JSON format can be found at spdx.org/licenses/[licenseid].json - * - * @author Gary O'Neall - * - */ -public class LicenseJson { - - static final List PROPERTY_VALUE_NAMES = Collections.unmodifiableList(Arrays.asList( - "licenseText", "licenseTextHtml", "name", "standardLicenseHeader", - "standardLicenseHeaderTemplate", "standardLicenseHeaderHtml", "standardLicenseTemplate", - "isOsiApproved", "isFsfLibre", "example", "isDeprecatedLicenseId", "deprecatedVersion", - "comment", "licenseId", "seeAlso", "crossRef")); //NOTE: This list must be updated if any new properties are added - - Boolean isDeprecatedLicenseId; - Boolean isFsfLibre; - String licenseText; - String standardLicenseHeaderTemplate; - String standardLicenseTemplate; - String name; - String licenseComments; //TODO: This is for legacy JSON files - this should be removed in 3.0. See https://github.com/spdx/spdx-spec/issues/158 - String comment; - String licenseId; - String standardLicenseHeader; - List crossRef = new ArrayList<>(); - List seeAlso = new ArrayList<>(); - Boolean isOsiApproved; - String licenseTextHtml; - String standardLicenseHeaderHtml; - String example; - String deprecatedVersion; - - public LicenseJson(String id) { - this.licenseId = id; - } - - public LicenseJson() { - - } - - public List getPropertyValueNames() { - return PROPERTY_VALUE_NAMES; - } - - public void setTypedProperty(String propertyName, String valueId, String type) throws InvalidSpdxPropertyException { - throw new InvalidSpdxPropertyException("Invalid type for Listed License SPDX Property: "+type); - } - - public void setPrimativeValue(String propertyName, Object value) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseText": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseText = (String)value; - break; - case "licenseTextHtml": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseTextHtml = (String)value; - break; - case "name": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - name = (String)value; - break; - case "seeAlso": - case "crossRef": throw new InvalidSpdxPropertyException("Expected list type for "+propertyName); - case "standardLicenseHeader": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - standardLicenseHeader = (String)value; - break; - case "standardLicenseHeaderTemplate": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - standardLicenseHeaderTemplate = (String)value; - break; - case "standardLicenseHeaderHtml": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - standardLicenseHeaderHtml = (String)value; - break; - case "standardLicenseTemplate": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - standardLicenseTemplate = (String)value; - break; - case "isOsiApproved": - if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyName); - } - isOsiApproved = (Boolean)value; - break; - case "isFsfLibre": - if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyName); - } - isFsfLibre = (Boolean)value; - break; - case "example": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - example = (String)value; - break; - case "isDeprecatedLicenseId": - if (!(value instanceof Boolean)) { - throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyName); - } - isDeprecatedLicenseId = (Boolean)value; - break; - case "deprecatedVersion": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - deprecatedVersion = (String)value; - break; - case "comment": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseComments = (String)value; - comment = (String)value; - break; - case "licenseId": - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - licenseId = (String)value; - break; - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - } - - public void clearPropertyValueList(String propertyName) throws InvalidSpdxPropertyException { - if ("seeAlso".equals(propertyName)) { - seeAlso.clear(); - } else if ("crossRef".equals(propertyName)) { - crossRef.clear(); - } else { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - - } - - /** - * Add a cross reference to a value list - * @param propertyName - * @param value - * @return true as specified by Collections.add - * @throws InvalidSPDXAnalysisException - */ - public boolean addCrossRefValueToList(String propertyName, CrossRefJson value) throws InvalidSPDXAnalysisException { - if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { - return crossRef.add(value); - } else { - throw new InvalidSpdxPropertyException(propertyName + "is not a crossRef list type"); - } - } - - /** - * Add a primitive value to a value list - * @param propertyName - * @param value - * @return true as specified by Collections.add - * @throws InvalidSPDXAnalysisException - */ - public boolean addPrimitiveValueToList(String propertyName, Object value) throws InvalidSPDXAnalysisException { - if ("seeAlso".equals(propertyName)) { - if (!(value instanceof String)) { - throw new InvalidSpdxPropertyException("Expected string type for "+propertyName); - } - return seeAlso.add((String)value); - } else if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { - if (!(value instanceof CrossRefJson)) { - throw new InvalidSpdxPropertyException("Expected CrossRefJson type for "+propertyName); - } - return crossRef.add((CrossRefJson)value); - } else { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - } - - public boolean removePrimitiveValueToList(String propertyName, Object value) throws InvalidSpdxPropertyException { - if ("seeAlso".equals(propertyName)) { - return seeAlso.remove(value); - } else if ("crossRef".equals(propertyName)) { - return crossRef.remove(value); - } else { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - } - - public List getValueList(String propertyName) throws InvalidSpdxPropertyException { - if ("seeAlso".equals(propertyName)) { - return seeAlso; - } else if ("crossRef".equals(propertyName)) { - return crossRef; - } else { - throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); - } - } - - public Object getValue(String propertyName) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseText": return licenseText; - case "licenseTextHtml": return licenseTextHtml; - case "name": return name; - case "seeAlso": return seeAlso; - case "crossRef": return crossRef; - case "standardLicenseHeader": return standardLicenseHeader; - case "standardLicenseHeaderTemplate": return standardLicenseHeaderTemplate; - case "standardLicenseHeaderHtml": return standardLicenseHeaderHtml; - case "standardLicenseTemplate": return standardLicenseTemplate; - case "isOsiApproved": return isOsiApproved; - case "isFsfLibre": return isFsfLibre; - case "example": return example; - case "isDeprecatedLicenseId": return isDeprecatedLicenseId; - case "deprecatedVersion": return deprecatedVersion; - case "comment": - if (comment != null) return comment; - return licenseComments; - case "licenseId": return licenseId; - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - } - - public void removeProperty(String propertyName) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseText": licenseText = null; break; - case "licenseTextHtml": licenseTextHtml = null; break; - case "name": name = null; break; - case "seeAlso":seeAlso.clear(); break; - case "crossRef":crossRef.clear(); break; - case "standardLicenseHeader": standardLicenseHeader = null; break; - case "standardLicenseHeaderTemplate": standardLicenseHeaderTemplate = null; break; - case "standardLicenseHeaderHtml": standardLicenseHeaderHtml = null; break; - case "standardLicenseTemplate": standardLicenseTemplate = null; break; - case "isOsiApproved": isOsiApproved = null; break; - case "isFsfLibre": isFsfLibre = null; break; - case "example": example = null; break; - case "isDeprecatedLicenseId": isDeprecatedLicenseId = null; break; - case "deprecatedVersion": deprecatedVersion = null; break; - case "comment": - comment = null; - licenseComments = null; break; - case "licenseId": licenseId = null; break; - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - } - - public void copyFrom(SpdxListedLicense fromLicense) throws InvalidLicenseTemplateException, InvalidSPDXAnalysisException { - /* TODO: Uncomment this in 3.0 and remove the following comment setting code in 3.0 - this.licenseComments = null; - this.comment = fromLicense.getComment(); - if (Objects.nonNull(this.comment) && this.comment.isEmpty()) { - this.comment = null; - } - */ - this.comment = null; - this.licenseComments = fromLicense.getComment(); - if (Objects.nonNull(this.licenseComments) && this.licenseComments.isEmpty()) { - this.licenseComments = null; - } - this.deprecatedVersion = fromLicense.getDeprecatedVersion(); - if (Objects.nonNull(this.deprecatedVersion) && this.deprecatedVersion.isEmpty()) { - this.deprecatedVersion = null; - } - this.example = null; - this.isDeprecatedLicenseId = fromLicense.isDeprecated(); - this.isFsfLibre = fromLicense.getFsfLibre(); - this.licenseId = fromLicense.getId(); - this.licenseText = fromLicense.getLicenseText(); - if (Objects.nonNull(this.licenseText) && this.licenseText.isEmpty()) { - this.licenseText = null; - } - this.licenseTextHtml = fromLicense.getLicenseTextHtml(); - if (Objects.nonNull(this.licenseTextHtml) && this.licenseTextHtml.isEmpty()) { - this.licenseTextHtml = null; - } - this.name = fromLicense.getName(); - if (Objects.nonNull(this.name) && this.name.isEmpty()) { - this.name = null; - } - this.isOsiApproved = fromLicense.isOsiApproved(); - this.seeAlso = new ArrayList(fromLicense.getSeeAlso()); - this.standardLicenseHeader = fromLicense.getStandardLicenseHeader(); - if (Objects.nonNull(this.standardLicenseHeader) && this.standardLicenseHeader.isEmpty()) { - this.standardLicenseHeader = null; - } - this.standardLicenseHeaderHtml = fromLicense.getLicenseHeaderHtml(); - if (Objects.nonNull(this.standardLicenseHeaderHtml) && this.standardLicenseHeaderHtml.isEmpty()) { - this.standardLicenseHeaderHtml = null; - } - this.standardLicenseHeaderTemplate = fromLicense.getStandardLicenseHeaderTemplate(); - if (Objects.nonNull(this.standardLicenseHeaderTemplate) && this.standardLicenseHeaderTemplate.isEmpty()) { - this.standardLicenseHeaderTemplate = null; - } - this.standardLicenseTemplate = fromLicense.getStandardLicenseTemplate(); - if (Objects.nonNull(this.standardLicenseTemplate) && this.standardLicenseTemplate.isEmpty()) { - this.standardLicenseTemplate = null; - } - this.crossRef.clear(); - for (CrossRef crossRef:fromLicense.getCrossRef()) { - this.crossRef.add(new CrossRefJson(crossRef)); - } - } - - public boolean isPropertyValueAssignableTo(String propertyName, Class clazz) throws InvalidSpdxPropertyException { - switch (propertyName) { - case "licenseText": - case "licenseTextHtml": - case "name": - case "standardLicenseHeader": - case "standardLicenseHeaderTemplate": - case "standardLicenseHeaderHtml": - case "standardLicenseTemplate": - case "example": - case "deprecatedVersion": - case "comment": - case "licenseId": return String.class.isAssignableFrom(clazz); - case "seeAlso": - case "crossRef": return false; - case "isOsiApproved": - case "isFsfLibre": - case "isDeprecatedLicenseId": return Boolean.class.isAssignableFrom(clazz); - default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); - } - - } - - public boolean isCollectionMembersAssignableTo(String propertyName, Class clazz) { - if (SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { - return String.class.isAssignableFrom(clazz); - } else if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { - return CrossRef.class.isAssignableFrom(clazz); - } else { - return false; - } - } - - public boolean isCollectionProperty(String propertyName) { - return SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName) || - SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName); - } -} diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java deleted file mode 100644 index f106264c0..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java +++ /dev/null @@ -1,263 +0,0 @@ -/** - * Copyright (c) 2018 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; - - -/** - * Table of Contents for the listed license list as represented as a JSON index file - * at spdx.org/licenses/licenses.json - * - * @author Gary O'Neall - * - */ -public class LicenseJsonTOC { - - public static class LicenseJson { - private String reference; - private boolean isDeprecatedLicenseId; - private String detailsUrl; - private int referenceNumber; - private String name; - private String licenseId; - private List seeAlso; - private boolean isOsiApproved; - private Boolean isFsfLibre; - /** - * @return the reference - */ - public String getReference() { - return reference; - } - /** - * @return the isDeprecatedLicenseId - */ - public boolean isDeprecatedLicenseId() { - return isDeprecatedLicenseId; - } - /** - * @return the detailsUrl - */ - public String getDetailsUrl() { - return detailsUrl; - } - /** - * @return the referenceNumber - */ - public int getReferenceNumber() { - return referenceNumber; - } - /** - * @return the name - */ - public String getName() { - return name; - } - /** - * @return the licenseId - */ - public String getLicenseId() { - return licenseId; - } - /** - * @return the seeAlso - */ - public List getSeeAlso() { - return seeAlso; - } - /** - * @return the isOsiApproved - */ - public boolean isOsiApproved() { - return isOsiApproved; - } - /** - * @return fsfLibre - */ - public @Nullable Boolean getFsfLibre() { - return this.isFsfLibre; - } - /** - * @param fsfLibre the fsfLibre flag to set - */ - public void setFsfLibre(@Nullable Boolean fsfLibre) { - this.isFsfLibre = fsfLibre; - } - /** - * @param reference the reference to set - */ - public void setReference(String reference) { - this.reference = reference; - } - /** - * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set - */ - public void setDeprecatedLicenseId(boolean isDeprecatedLicenseId) { - this.isDeprecatedLicenseId = isDeprecatedLicenseId; - } - /** - * @param detailsUrl the detailsUrl to set - */ - public void setDetailsUrl(String detailsUrl) { - this.detailsUrl = detailsUrl; - } - /** - * @param referenceNumber the referenceNumber to set - */ - public void setReferenceNumber(int referenceNumber) { - this.referenceNumber = referenceNumber; - } - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - /** - * @param licenseId the licenseId to set - */ - public void setLicenseId(String licenseId) { - this.licenseId = licenseId; - } - /** - * @param seeAlso the seeAlso to set - */ - public void setSeeAlso(List seeAlso) { - this.seeAlso = seeAlso; - } - /** - * @param isOsiApproved the isOsiApproved to set - */ - public void setOsiApproved(boolean isOsiApproved) { - this.isOsiApproved = isOsiApproved; - } - } - - - private String licenseListVersion; - private List licenses; - private String releaseDate; - - public LicenseJsonTOC(String version, String releaseDate) { - this.licenseListVersion = version; - this.releaseDate = releaseDate; - this.licenses = new ArrayList<>(); - } - - public LicenseJsonTOC() { - this.licenseListVersion = null; - this.releaseDate = null; - this.licenses = new ArrayList<>(); - } - - /** - * @return the licenseListVersion - */ - public String getLicenseListVersion() { - return licenseListVersion; - } - - /** - * @return the licenses - */ - public List getLicenses() { - return licenses; - } - - /** - * @return map of lower case to correct case license IDs - */ - public Map getLicenseIds() { - Map retval = new HashMap<>(); - if (licenses == null) { - return retval; - } - for (LicenseJson license:licenses) { - retval.put(license.licenseId.toLowerCase(), license.licenseId); - } - return retval; - } - - /** - * @return the releaseDate - */ - public String getReleaseDate() { - return releaseDate; - } - - /** - * Add summary information about a specific license to the licenses list - * @param license - * @param licHTMLReference - * @param licJSONReference - * @param deprecated - * @throws InvalidSPDXAnalysisException - */ - public void addLicense(SpdxListedLicense license, String licHTMLReference, String licJSONReference, - boolean deprecated) throws InvalidSPDXAnalysisException { - LicenseJson lj = new LicenseJson(); - lj.setDeprecatedLicenseId(deprecated); - lj.setDetailsUrl(toAbsoluteURL(licJSONReference)); - lj.setLicenseId(license.getId()); - lj.setName(license.getName()); - lj.setOsiApproved(license.isOsiApproved()); - lj.setFsfLibre(license.getFsfLibre()); - lj.setReference(toAbsoluteURL(licHTMLReference)); - int referenceNumber = -1; - for (LicenseJson existing:this.licenses) { - if (existing.getReferenceNumber() > referenceNumber) { - referenceNumber = existing.getReferenceNumber(); - } - } - referenceNumber++; - lj.setReferenceNumber(referenceNumber); - List seeAlso = new ArrayList<>(); - for (String sa:license.getSeeAlso()) { - seeAlso.add(sa); - } - lj.setSeeAlso(seeAlso); - this.licenses.add(lj); - } - - /** - * @param licenseListVersion the licenseListVersion to set - */ - public void setLicenseListVersion(String licenseListVersion) { - this.licenseListVersion = licenseListVersion; - } - - /** - * @param releaseDate the releaseDate to set - */ - public void setReleaseDate(String releaseDate) { - this.releaseDate = releaseDate; - } - - private static String toAbsoluteURL(String relURL) { - String retval = relURL.startsWith("./") ? relURL.substring(2) : relURL; - return SpdxConstantsCompatV2.LISTED_LICENSE_URL + retval; - } -} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java deleted file mode 100644 index c98ecf1d4..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.io.IOException; -import java.io.InputStream; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * @author Gary O'Neall - * - * Model store for listed licenses using the JSON files in the resources/stdlicenses directory. - * Note the resources/stdlicenses must be on the build path. - * - */ -public class SpdxListedLicenseLocalStore extends SpdxListedLicenseModelStore { - - static final String LISTED_LICENSE_JSON_LOCAL_DIR = "resources" + "/" + "stdlicenses"; - - public SpdxListedLicenseLocalStore() throws InvalidSPDXAnalysisException { - super(); - } - - @Override - InputStream getTocInputStream() throws IOException { - String fileName = LISTED_LICENSE_JSON_LOCAL_DIR + "/" + LICENSE_TOC_FILENAME; - InputStream retval = SpdxListedLicenseLocalStore.class.getResourceAsStream("/" + fileName); - if (retval == null) { - throw new IOException("Unable to open local local license table of contents file"); - } - return retval; - } - - @Override - InputStream getLicenseInputStream(String licenseId) throws IOException { - - String fileName = LISTED_LICENSE_JSON_LOCAL_DIR + "/" + licenseId + JSON_SUFFIX; - InputStream retval = SpdxListedLicenseLocalStore.class.getResourceAsStream("/" + fileName); - if (retval == null) { - throw new IOException("Unable to open local local license JSON file for license ID "+licenseId); - } - return retval; - } - - @Override - InputStream getExceptionTocInputStream() throws IOException { - String fileName = LISTED_LICENSE_JSON_LOCAL_DIR + "/" + EXCEPTION_TOC_FILENAME; - InputStream retval = SpdxListedLicenseLocalStore.class.getResourceAsStream("/" + fileName); - if (retval == null) { - throw new IOException("Unable to open local local license table of contents file"); - } - return retval; - } - - @Override - InputStream getExceptionInputStream(String exceptionId) throws IOException { - return getLicenseInputStream(exceptionId); - } - - @Override - public void close() throws Exception { - // Nothing to do for the either the in-memory or the web store - } -} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java deleted file mode 100644 index 05cd5dcc3..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ /dev/null @@ -1,1163 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.stream.Stream; - -import javax.annotation.Nullable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.DuplicateSpdxIdException; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdNotFoundException; -import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; -import org.spdx.library.model.compat.v2.license.SpdxListedLicenseException; -import org.spdx.storage.PropertyDescriptor; - -import com.google.gson.Gson; - -/** - * Read-only model store for the SPDX listed licenses - * - * License and exception ID's can be case insensitive - * - * License information is stored in a LicenseJson file with the ID being Listed License ID - * License Exception information is stored in an ExceptionJson file with the ID being the Listed Exception ID - * CrossRef information is stored within the LicenseJson file. Id's are anonymous and generated. - * - * @author Gary O'Neall - * - */ -public abstract class SpdxListedLicenseModelStore implements IListedLicenseStore { - - static final Logger logger = LoggerFactory.getLogger(SpdxListedLicenseModelStore.class.getName()); - static final String DEFAULT_LICENSE_LIST_VERSION = "3.17"; - static final String LICENSE_TOC_FILENAME = "licenses.json"; - static final String EXCEPTION_TOC_FILENAME = "exceptions.json"; - static final String JSON_SUFFIX = ".json"; - private static final String ANONYMOUS_ID_PREFIX = "SpdxLicenseGeneratedId-"; - - /** - * Map of lower case to correct case license IDs - */ - Map licenseIds = new HashMap<>(); - /** - * Map of lower case to correct case exception IDs - */ - Map exceptionIds = new HashMap<>(); - Map listedLicenseCache = null; - Map listedExceptionCache = null; - Map crossRefs = new HashMap<>(); - String licenseListVersion = DEFAULT_LICENSE_LIST_VERSION; - private int nextId=0; - private final ReadWriteLock listedLicenseModificationLock = new ReentrantReadWriteLock(); - - private final IModelStoreLock readLock = new IModelStoreLock() { - - @Override - public void unlock() { - listedLicenseModificationLock.readLock().unlock(); - } - - }; - - private final IModelStoreLock writeLock = new IModelStoreLock() { - - @Override - public void unlock() { - listedLicenseModificationLock.writeLock().unlock(); - } - - }; - - Gson gson = new Gson(); // we should be able to reuse since all access is within write locks - - public SpdxListedLicenseModelStore() throws InvalidSPDXAnalysisException { - loadIds(); - } - - /** - * @return InputStream for the Table of Contents of the licenses formated in JSON SPDX - * @throws IOException - */ - abstract InputStream getTocInputStream() throws IOException; - - /** - * @return InputStream for the Table of Contents of the exceptions formated in JSON SPDX - * @throws IOException - */ - abstract InputStream getExceptionTocInputStream() throws IOException; - - /** - * @return InputStream for a license formated in SPDX JSON - * @throws IOException - */ - abstract InputStream getLicenseInputStream(String licenseId) throws IOException; - - /** - * @return InputStream for an exception formated in SPDX JSON - * @throws IOException - */ - abstract InputStream getExceptionInputStream(String exceptionId) throws IOException; - - /** - * Loads all license and exception ID's from the appropriate JSON files - * @throws InvalidSPDXAnalysisException - */ - private void loadIds() throws InvalidSPDXAnalysisException { - listedLicenseModificationLock.writeLock().lock(); - try { - listedLicenseCache = new HashMap<>(); // clear the cache - listedExceptionCache = new HashMap<>(); - licenseIds = new HashMap<>(); //Clear the listed license IDs to avoid stale licenses. - //NOTE: This includes deprecated licenses - should this be changed to only return non-deprecated licenses? - InputStream tocStream = null; - BufferedReader reader = null; - try { - // read the license IDs - tocStream = getTocInputStream(); - reader = new BufferedReader(new InputStreamReader(tocStream, "UTF-8")); - StringBuilder tocJsonStr = new StringBuilder(); - String line; - while((line = reader.readLine()) != null) { - tocJsonStr.append(line); - } - LicenseJsonTOC jsonToc = gson.fromJson(tocJsonStr.toString(), LicenseJsonTOC.class); - licenseIds = jsonToc.getLicenseIds(); - this.licenseListVersion = jsonToc.getLicenseListVersion(); - - // read the exception ID's - tocStream = getExceptionTocInputStream(); - reader = new BufferedReader(new InputStreamReader(tocStream, "UTF-8")); - tocJsonStr = new StringBuilder(); - while((line = reader.readLine()) != null) { - tocJsonStr.append(line); - } - ExceptionJsonTOC exceptionToc = gson.fromJson(tocJsonStr.toString(), ExceptionJsonTOC.class); - exceptionIds = exceptionToc.getExceptionIds(); - } catch (MalformedURLException e) { - throw new SpdxListedLicenseException("License TOC URL invalid") ; - } catch (IOException e) { - throw new SpdxListedLicenseException("I/O error reading license TOC"); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - logger.warn("Unable to close JSON TOC reader"); - } - } - } - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#exists(java.lang.String, java.lang.String) - */ - @Override - public boolean exists(String objectUri) { - Objects.requireNonNull(objectUri, "Object URI can not be null"); - String id; - if (objectUri.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { - id = objectUri.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()); - } else if (getIdType(objectUri) == IdType.Anonymous) { - id = objectUri; - } else { - return false; - } - listedLicenseModificationLock.readLock().lock(); - try { - return this.licenseIds.containsKey(id.toLowerCase()) || - this.exceptionIds.containsKey(id.toLowerCase()) || - this.crossRefs.containsKey(id); - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - private String objectUriToId(String objectUri) throws InvalidSPDXAnalysisException { - Objects.requireNonNull(objectUri, "Object URI can not be null"); - String id; - if (objectUri.startsWith(SpdxConstantsCompatV2.LISTED_LICENSE_URL)) { - id = objectUri.substring(SpdxConstantsCompatV2.LISTED_LICENSE_URL.length()); - } else if (getIdType(objectUri) == IdType.Anonymous) { - id = objectUri; - } else { - logger.error("Namespace for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied URI was "+objectUri); - throw new SpdxIdNotFoundException("Namespace for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied URI was "+objectUri); - } - return id; - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#create(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public void create(String objectUri, String type) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - listedLicenseModificationLock.writeLock().lock(); - try { - if (SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(type)) { - CrossRefJson crossRef = new CrossRefJson(); - crossRef.setId(id); - this.crossRefs.put(id, crossRef); - } else if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(type)) { - if (this.licenseIds.containsKey(id.toLowerCase()) || this.exceptionIds.containsKey(id.toLowerCase())) { - logger.error("Duplicate SPDX ID on create: "+id);; - throw new DuplicateSpdxIdException("ID "+id+" already exists."); - } - this.licenseIds.put(id.toLowerCase(), id); - this.listedLicenseCache.put(id, new LicenseJson(id)); - } else if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(type)) { - if (this.licenseIds.containsKey(id.toLowerCase()) || this.exceptionIds.containsKey(id.toLowerCase())) { - logger.error("Duplicate SPDX ID on create: "+id);; - throw new DuplicateSpdxIdException("ID "+id+" already exists."); - } - this.exceptionIds.put(id.toLowerCase(), id); - this.listedExceptionCache.put(id, new ExceptionJson(id)); - } - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#getPropertyValueNames(java.lang.String, java.lang.String) - */ - @Override - public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - List retval = new ArrayList<>(); - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(licenseIds.get(id.toLowerCase())); - license.getPropertyValueNames().spliterator().forEachRemaining( - s -> retval.add(new PropertyDescriptor(s, SpdxConstantsCompatV2.SPDX_NAMESPACE))); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(exceptionIds.get(id.toLowerCase())); - exc.getPropertyValueNames().spliterator().forEachRemaining( - s -> retval.add(new PropertyDescriptor(s, SpdxConstantsCompatV2.SPDX_NAMESPACE))); - } else if (Objects.nonNull(crossRef)) { - crossRef.getPropertyValueNames().spliterator().forEachRemaining( - s -> retval.add(new PropertyDescriptor(s, SpdxConstantsCompatV2.SPDX_NAMESPACE))); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID"); - } - return retval; - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - /** - * @param idCaseInsensitive License ID case insensitive - * @return License JSON for the ID - reading from the input stream if needed - * @throws InvalidSPDXAnalysisException - */ - private LicenseJson fetchLicenseJson(String idCaseInsensitive) throws InvalidSPDXAnalysisException { - String idLowerCase = idCaseInsensitive.toLowerCase(); - String id = null; - listedLicenseModificationLock.readLock().lock(); - try { - id = this.licenseIds.get(idLowerCase); - if (Objects.isNull(id)) { - logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); - throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); - } - if (this.listedLicenseCache.containsKey(id)) { - return this.listedLicenseCache.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - // If we got here, it wasn't in the cache - listedLicenseModificationLock.writeLock().lock(); - try { - // have to retest since we were unlocked - id = this.licenseIds.get(idLowerCase); - if (Objects.isNull(id)) { - logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); - throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); - } - if (!this.listedLicenseCache.containsKey(id)) { - InputStream jsonStream = null; - BufferedReader reader = null; - try { - jsonStream = getLicenseInputStream(id); - reader = new BufferedReader(new InputStreamReader(jsonStream, "UTF-8")); - StringBuilder licenseJsonStr = new StringBuilder(); - String line; - while((line = reader.readLine()) != null) { - licenseJsonStr.append(line); - } - LicenseJson license = gson.fromJson(licenseJsonStr.toString(), LicenseJson.class); - this.listedLicenseCache.put(id, license); - } catch (MalformedURLException e) { - logger.error("Json license invalid for ID "+id); - throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id); - } catch (IOException e) { - logger.error("I/O error opening Json license URL"); - throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - logger.warn("Unable to close JSON TOC reader"); - } - } else if (jsonStream != null) { - try { - jsonStream.close(); - } catch (IOException e) { - logger.warn("Unable to close JSON TOC input stream"); - } - } - } - } - return this.listedLicenseCache.get(id); - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - /** - * @param idCaseInsensitive Exception ID case insensitive - * @return Exception JSON for the ID - reading from the input stream if needed - * @throws InvalidSPDXAnalysisException - */ - private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws InvalidSPDXAnalysisException { - String idLower = idCaseInsensitive.toLowerCase(); - String id = null; // case sensitive ID - listedLicenseModificationLock.readLock().lock(); - try { - id = this.exceptionIds.get(idLower); - if (Objects.isNull(id)) { - logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); - throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); - } - if (this.listedExceptionCache.containsKey(id)) { - return this.listedExceptionCache.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - // If we got here, it wasn't in the cache - listedLicenseModificationLock.writeLock().lock(); - try { - // have to retest since we were unlocked - id = this.exceptionIds.get(idLower); - if (Objects.isNull(id)) { - logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); - throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); - } - if (!this.listedExceptionCache.containsKey(id)) { - InputStream jsonStream = null; - BufferedReader reader = null; - try { - jsonStream = getExceptionInputStream(id); - reader = new BufferedReader(new InputStreamReader(jsonStream, "UTF-8")); - StringBuilder exceptionJsonStr = new StringBuilder(); - String line; - while((line = reader.readLine()) != null) { - exceptionJsonStr.append(line); - } - ExceptionJson exc = gson.fromJson(exceptionJsonStr.toString(), ExceptionJson.class); - this.listedExceptionCache.put(id, exc); - } catch (MalformedURLException e) { - logger.error("Json license invalid for ID "+id); - throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id); - } catch (IOException e) { - logger.error("I/O error opening Json license URL"); - throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - logger.warn("Unable to close JSON TOC reader"); - } - } else if (jsonStream != null) { - try { - jsonStream.close(); - } catch (IOException e) { - logger.warn("Unable to close JSON TOC input stream"); - } - } - } - } - return this.listedExceptionCache.get(id); - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#setPrimitiveValue(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) - */ - @Override - public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - license.setPrimativeValue(propertyDescriptor.getName(), value); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - exc.setPrimativeValue(propertyDescriptor.getName(), value); - } else if (Objects.nonNull(crossRef)) { - crossRef.setPrimativeValue(propertyDescriptor.getName(), value); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#clearPropertyValueList(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - license.clearPropertyValueList(propertyDescriptor.getName()); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - exc.clearPropertyValueList(propertyDescriptor.getName()); - }else if (Objects.nonNull(crossRef)) { - crossRef.clearPropertyValueList(propertyDescriptor.getName()); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#addPrimitiveValueToList(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) - */ - @Override - public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { - if (!(value instanceof TypedValue)) { - logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); - } - TypedValue tv = (TypedValue)value; - if (!SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(tv.getType())) { - logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); - } - CrossRefJson crj = crossRefs.get(tv.getObjectUri()); - if (Objects.isNull(crj)) { - logger.error("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); - throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); - } - return license.addCrossRefValueToList(propertyDescriptor.getName(), crj); - } else { - return license.addPrimitiveValueToList(propertyDescriptor.getName(), value); - } - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return exc.addPrimitiveValueToList(propertyDescriptor.getName(), value); - } else if (Objects.nonNull(crossRef)) { - return crossRef.addPrimitiveValueToList(propertyDescriptor.getName(), value); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - @Override - public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { - if (!(value instanceof TypedValue)) { - logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); - } - TypedValue tv = (TypedValue)value; - if (!SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(tv.getType())) { - logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); - throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); - } - CrossRefJson crj = crossRefs.get(tv.getObjectUri()); - if (Objects.isNull(crj)) { - logger.error("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); - throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); - } - return license.removePrimitiveValueToList(propertyDescriptor.getName(), crj); - } else { - return license.removePrimitiveValueToList(propertyDescriptor.getName(), value); - } - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return exc.removePrimitiveValueToList(propertyDescriptor.getName(), value); - } else if (Objects.nonNull(crossRef)) { - return crossRef.removePrimitiveValueToList(propertyDescriptor.getName(), value); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#getValueList(java.lang.String, java.lang.String, java.lang.String) - */ - @SuppressWarnings("unchecked") - @Override - public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); - if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { - final Iterator crossRefJsonIter = valueList.iterator(); - return new Iterator() { - - @Override - public boolean hasNext() { - return crossRefJsonIter.hasNext(); - } - - @Override - public Object next() { - Object nextVal = crossRefJsonIter.next(); - if (Objects.isNull(nextVal)) { - return null; - } - if (!(nextVal instanceof CrossRefJson)) { - throw new RuntimeException(new InvalidSPDXAnalysisException("Invalid type for "+propertyDescriptor+". Must be of type CrossRefJson")); - } - CrossRefJson nextCrossRef = (CrossRefJson)nextVal; - String crossRefId = nextCrossRef.getId(); - listedLicenseModificationLock.writeLock().lock(); - try { - if (Objects.isNull(crossRefId)) { - // Need to create an ID and store it in the cache - try { - crossRefId = getNextId(IdType.Anonymous, SpdxConstantsCompatV2.LISTED_LICENSE_URL); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error getting next Anonymous ID",e); - throw new RuntimeException(e); - } - nextCrossRef.setId(crossRefId); - crossRefs.put(crossRefId, nextCrossRef); - } - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - try { - return new TypedValue(crossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - } catch (InvalidSPDXAnalysisException e) { - logger.error("Error creating TypedValue for CrossRef",e); - throw new RuntimeException(e); - } - } - }; - } else { - return valueList.iterator(); - } - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return ((List)(List)exc.getValueList(propertyDescriptor.getName())).iterator(); - } else if (Objects.nonNull(crossRef)) { - return ((List)(List)crossRef.getValueList(propertyDescriptor.getName())).iterator(); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#getValue(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - return Optional.ofNullable(license.getValue(propertyDescriptor.getName())); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return Optional.ofNullable(exc.getValue(propertyDescriptor.getName())); - } else if (Objects.nonNull(crossRef)) { - return Optional.ofNullable(crossRef.getValue(propertyDescriptor.getName())); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - /* (non-Javadoc) - * @see org.spdx.storage.IModelStore#getNextId(org.spdx.storage.IModelStore.IdType, java.lang.String) - */ - @Override - public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException { - if (!SpdxConstantsCompatV2.LISTED_LICENSE_URL.equals(documentUri) && !IdType.Anonymous.equals(idType)) { - logger.error("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - throw new SpdxIdNotFoundException("Document URI for SPDX listed licenses is expected to be "+ - SpdxConstantsCompatV2.LISTED_LICENSE_URL + ". Supplied document URI was "+documentUri); - } - this.listedLicenseModificationLock.writeLock().lock(); - try { - if (IdType.Anonymous.equals(idType)) { - return ANONYMOUS_ID_PREFIX + String.valueOf(this.nextId++); - } else { - return "listedLicenseId_" + String.valueOf(this.nextId++); - } - } finally { - this.listedLicenseModificationLock.writeLock().unlock(); - } - } - - @Override - public List getSpdxListedLicenseIds() { - this.listedLicenseModificationLock.readLock().lock(); - try { - List retval = new ArrayList<>(); - retval.addAll(this.licenseIds.values()); - return retval; - } finally { - this.listedLicenseModificationLock.readLock().unlock(); - } - } - - @Override - public String getLicenseListVersion() { - this.listedLicenseModificationLock.readLock().lock(); - try { - return this.licenseListVersion; - } finally { - this.listedLicenseModificationLock.readLock().unlock(); - } - } - - public List getSpdxListedExceptionIds() { - this.listedLicenseModificationLock.readLock().lock(); - try { - List retval = new ArrayList<>(); - retval.addAll(this.exceptionIds.values()); - return retval; - } finally { - this.listedLicenseModificationLock.readLock().unlock(); - } - } - - /** - * @param listedLicenseDocumentUri - * @param licenseId - * @return true if the licenseId belongs to an SPDX listed license - */ - public boolean isSpdxListedLicenseId(String listedLicenseDocumentUri, String licenseId) { - this.listedLicenseModificationLock.readLock().lock(); - try { - return this.licenseIds.containsKey(licenseId.toLowerCase()); - } finally { - this.listedLicenseModificationLock.readLock().unlock(); - } - } - - /** - * @param listedLicenseDocumentUri - * @param exceptionId - * @return true if the exceptionId belongs to an SPDX listed exception - */ - public boolean isSpdxListedExceptionId(String listedLicenseDocumentUri, String exceptionId) { - this.listedLicenseModificationLock.readLock().lock(); - try { - return this.exceptionIds.containsKey(exceptionId.toLowerCase()); - } finally { - this.listedLicenseModificationLock.readLock().unlock(); - } - } - - @Override - public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE)); - } else if (exceptionIds.containsKey(id.toLowerCase())) { - return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION)); - } else if (crossRefs.containsKey(id)) { - return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_CROSS_REF)); - } else { - return Optional.empty(); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - @Override - public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - license.removeProperty(propertyDescriptor.getName()); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - exc.removeProperty(propertyDescriptor.getName()); - } else if (Objects.nonNull(crossRef)) { - crossRef.removeProperty(propertyDescriptor.getName()); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - @Override - public Stream getAllItems(String documentUri, @Nullable String typeFilter) - throws InvalidSPDXAnalysisException { - Objects.requireNonNull(typeFilter, "Type filter can not be null"); - listedLicenseModificationLock.readLock().lock(); - try { - List allItems = new ArrayList(); - if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(typeFilter)) { - for (String licenseId:this.licenseIds.values()) { - allItems.add(new TypedValue(licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE)); - } - } - if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(typeFilter)) { - for (String exceptionId:this.exceptionIds.values()) { - allItems.add(new TypedValue(exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION)); - } - } - if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(typeFilter)) { - for (String crossRefId:crossRefs.keySet()) { - allItems.add(new TypedValue(crossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF)); - } - } - return Collections.unmodifiableList(allItems).stream(); - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - - - @SuppressWarnings("unchecked") - @Override - public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - return ((List)(List)license.getValueList(propertyDescriptor.getName())).size(); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return ((List)(List)exc.getValueList(propertyDescriptor.getName())).size(); - } else if (Objects.nonNull(crossRef)) { - return ((List)(List)crossRef.getValueList(propertyDescriptor.getName())).size(); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - @SuppressWarnings("unchecked") - @Override - public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) - throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - List valueList = (List)(List)license.getValueList(propertyDescriptor.getName()); - if (value instanceof TypedValue && SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(((TypedValue)value).getType())) { - CrossRefJson compareValue = crossRefs.get(((TypedValue)value).getObjectUri()); - if (Objects.isNull(compareValue)) { - return false; - } else { - return valueList.contains(compareValue); - } - } else { - return valueList.contains(value); - } - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return ((List)(List)exc.getValueList(propertyDescriptor.getName())).contains(value); - } else if (Objects.nonNull(crossRef)) { - return ((List)(List)crossRef.getValueList(propertyDescriptor.getName())).contains(value); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - @Override - public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - return license.isCollectionMembersAssignableTo(propertyDescriptor.getName(), clazz); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return exc.isCollectionMembersAssignableTo(propertyDescriptor.getName(), clazz); - } else if (Objects.nonNull(crossRef)) { - return crossRef.isCollectionMembersAssignableTo(propertyDescriptor.getName(), clazz); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - @Override - public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) - throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - return license.isPropertyValueAssignableTo(propertyDescriptor.getName(), clazz); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return exc.isPropertyValueAssignableTo(propertyDescriptor.getName(), clazz); - } else if (Objects.nonNull(crossRef)) { - return crossRef.isPropertyValueAssignableTo(propertyDescriptor.getName(), clazz); - } else { - logger.error("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID"); - } - } - - @Override - public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) - throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - boolean isLicenseId = false; - boolean isExceptionId = false; - CrossRefJson crossRef = null; - listedLicenseModificationLock.readLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - isLicenseId = true; - } else if (exceptionIds.containsKey(id.toLowerCase())) { - isExceptionId = true; - } else if (crossRefs.containsKey(id)) { - crossRef = crossRefs.get(id); - } - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - if (isLicenseId) { - LicenseJson license = fetchLicenseJson(id); - return license.isCollectionProperty(propertyDescriptor.getName()); - } else if (isExceptionId) { - ExceptionJson exc = fetchExceptionJson(id); - return exc.isCollectionProperty(propertyDescriptor.getName()); - } else if (Objects.nonNull(crossRef)) { - return crossRef.isCollectionProperty(propertyDescriptor.getName()); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } - - @Override - public IdType getIdType(String id) { - Objects.requireNonNull(id, "ID must not be null"); - if (LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) { - return IdType.ListedLicense; - } else if (id.startsWith(ANONYMOUS_ID_PREFIX)) { - return IdType.Anonymous; - } else { - return IdType.Unkown; - } - } - - - @Override - public IModelStoreLock enterCriticalSection(boolean readLockRequested) { - if (readLockRequested) { - this.listedLicenseModificationLock.readLock().lock(); - return readLock; - } else { - this.listedLicenseModificationLock.writeLock().lock(); - return writeLock; - } - } - - @Override - public void leaveCriticalSection(IModelStoreLock lock) { - lock.unlock(); - } - - @Override - public Optional listedLicenseIdCaseSensitive(String licenseId) { - listedLicenseModificationLock.readLock().lock(); - try { - return Optional.ofNullable(this.licenseIds.get(licenseId.toLowerCase())); - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - - @Override - public Optional listedExceptionIdCaseSensitive(String exceptionId) { - listedLicenseModificationLock.readLock().lock(); - try { - return Optional.ofNullable(this.exceptionIds.get(exceptionId.toLowerCase())); - } finally { - listedLicenseModificationLock.readLock().unlock(); - } - } - - @Override - public Optional getCaseSensisitiveId(String documentUri, String caseInsensisitiveId) { - Optional retval = listedLicenseIdCaseSensitive(caseInsensisitiveId); - if (retval.isPresent()) { - return retval; - } - return listedExceptionIdCaseSensitive(caseInsensisitiveId); - } - - @Override - public void delete(String objectUri) throws InvalidSPDXAnalysisException { - String id = objectUriToId(objectUri); - listedLicenseModificationLock.writeLock().lock(); - try { - if (licenseIds.containsKey(id.toLowerCase())) { - this.listedLicenseCache.remove(id); - this.licenseIds.remove(id.toLowerCase()); - } else if (exceptionIds.containsKey(id.toLowerCase())) { - this.listedExceptionCache.remove(id); - this.exceptionIds.remove(id.toLowerCase()); - } else if (crossRefs.containsKey(id)) { - this.crossRefs.remove(id); - } else { - logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); - } - } finally { - listedLicenseModificationLock.writeLock().unlock(); - } - } - - @Override - public SpdxMajorVersion getSpdxVersion() { - return SpdxMajorVersion.VERSION_2; - } -} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java deleted file mode 100644 index e776cfa9d..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.storage.listedlicense; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; - -/** - * @author gary - * - */ -public class SpdxListedLicenseWebStore extends SpdxListedLicenseModelStore { - - private static final int READ_TIMEOUT = 5000; - - static final List WHITE_LIST = Collections.unmodifiableList(Arrays.asList( - "spdx.org", "spdx.dev", "spdx.com", "spdx.info")); // Allowed host names for the SPDX listed licenses - - /** - * @throws InvalidSPDXAnalysisException - */ - public SpdxListedLicenseWebStore() throws InvalidSPDXAnalysisException { - super(); - } - - private InputStream getUrlInputStream(URL url) throws IOException { - HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - connection.setReadTimeout(READ_TIMEOUT); - int status = connection.getResponseCode(); - if (status != HttpURLConnection.HTTP_OK && - (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM - || status == HttpURLConnection.HTTP_SEE_OTHER)) { - // redirect - String redirectUrlStr = connection.getHeaderField("Location"); - if (Objects.isNull(redirectUrlStr) || redirectUrlStr.isEmpty()) { - throw new IOException("Empty redirect URL response"); - } - URL redirectUrl; - try { - redirectUrl = new URL(redirectUrlStr); - } catch(Exception ex) { - throw new IOException("Invalid redirect URL"); - } - if (!redirectUrl.getProtocol().toLowerCase().startsWith("http")) { - throw new IOException("Invalid redirect protocol"); - } - if (!WHITE_LIST.contains(redirectUrl.getHost())) { - throw new IOException("Invalid redirect host - not on the allowed 'white list'"); - } - connection = (HttpURLConnection)redirectUrl.openConnection(); - } - return connection.getInputStream(); - } - - @Override - InputStream getTocInputStream() throws IOException { - return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + LICENSE_TOC_FILENAME)); - } - - @Override - InputStream getLicenseInputStream(String licenseId) throws IOException { - return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId + JSON_SUFFIX)); - } - - @Override - InputStream getExceptionTocInputStream() throws IOException { - return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + EXCEPTION_TOC_FILENAME)); - } - - @Override - InputStream getExceptionInputStream(String exceptionId) throws IOException { - return getLicenseInputStream(exceptionId); // Same URL using exception ID rather than license ID - } - - @Override - public void close() throws Exception { - // Nothing to do for the either the in-memory or the web store - } -} diff --git a/src/main/java/org/spdx/storage/listedlicense/package-info.java b/src/main/java/org/spdx/storage/listedlicense/package-info.java deleted file mode 100644 index 8490547d8..000000000 --- a/src/main/java/org/spdx/storage/listedlicense/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Gary O'Neall - * - * Storage for SPDX listed licenses. - * - * The SpdxListedLicenseModelStore is the default storage which pull the data from JSON files at spdx.org/licenses - * - * The SpdxListedLicenseLocalModelStore uses a local copy of the licenses stored in the resources/licenses directory - * - */ -package org.spdx.storage.listedlicense; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java index c5ed8ddab..c2d63ea56 100644 --- a/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java @@ -99,8 +99,8 @@ public Optional getValue(String objectUri, PropertyDescriptor propertyDe * @see org.spdx.storage.IModelStore#getNextId(org.spdx.storage.IModelStore.IdType, java.lang.String) */ @Override - public String getNextId(IdType idType, String documentUri) throws InvalidSPDXAnalysisException { - return baseStore.getNextId(idType, documentUri); + public String getNextId(IdType idType) throws InvalidSPDXAnalysisException { + return baseStore.getNextId(idType); } /* (non-Javadoc) diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index 253be78e6..b6f85ea0f 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -344,12 +344,13 @@ public Optional getValue(String objectUri, PropertyDescriptor propertyDe } @Override - public synchronized String getNextId(IdType idType, @Nullable String nameSpace) throws InvalidSPDXAnalysisException { + public synchronized String getNextId(IdType idType) throws InvalidSPDXAnalysisException { switch (idType) { + //TODO: Move the compat constants into it's own constants file case Anonymous: return ANON_PREFIX+GENERATED+String.valueOf(nextAnonId++); - case LicenseRef: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+String.valueOf(nextNextLicenseId++); - case DocumentRef: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); - case SpdxId: return (nameSpace == null ? "" : nameSpace) + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); + case LicenseRef: return SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+GENERATED+String.valueOf(nextNextLicenseId++); + case DocumentRef: return SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+GENERATED+String.valueOf(nextNextDocumentId++); + case SpdxId: return SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+GENERATED+String.valueOf(nextNextSpdxId++); case ListedLicense: throw new InvalidSPDXAnalysisException("Can not generate a license ID for a Listed License"); default: throw new InvalidSPDXAnalysisException("Unknown ID type for next ID: "+idType.toString()); } diff --git a/src/main/java/org/spdx/utility/compare/SpdxComparer.java b/src/main/java/org/spdx/utility/compare/SpdxComparer.java index 2bd4e27a2..ced90031e 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxComparer.java @@ -1157,7 +1157,7 @@ public static boolean objectsEqual(Object o1, Object o2) { * @return true of the elements are present and equivalent * @throws InvalidSPDXAnalysisException */ - public static boolean elementsEquivalent(Optional elementA, Optional elementB) throws InvalidSPDXAnalysisException { + public static boolean elementsEquivalent(Optional elementA, Optional elementB) throws InvalidSPDXAnalysisException { if (elementA.isPresent()) { if (elementB.isPresent()) { return elementA.get().equivalent(elementB.get()); @@ -1175,7 +1175,7 @@ public static boolean elementsEquivalent(Optional element * @throws InvalidSPDXAnalysisException * @return true if the collections all contain equivalent items */ - public static boolean collectionsEquivalent(Collection collectionA, Collection collectionB) throws InvalidSPDXAnalysisException { + public static boolean collectionsEquivalent(Collection collectionA, Collection collectionB) throws InvalidSPDXAnalysisException { if (Objects.isNull(collectionA)) { return Objects.isNull(collectionB); } @@ -1185,12 +1185,12 @@ public static boolean collectionsEquivalent(Collection co if (collectionA.size() != collectionB.size()) { return false; } - for (ModelObject elementA:collectionA) { + for (ModelObjectV2 elementA:collectionA) { if (Objects.isNull(elementA)) { continue; } boolean found = false; - for (ModelObject elementB:collectionB) { + for (ModelObjectV2 elementB:collectionB) { if (Objects.isNull(elementB)) { continue; } diff --git a/src/test/java/org/spdx/library/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/SpdxModelFactoryTest.java index 30eeb69b5..964195e4f 100644 --- a/src/test/java/org/spdx/library/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/SpdxModelFactoryTest.java @@ -69,18 +69,18 @@ public void testCreateSpdxDocumentV2() throws InvalidSPDXAnalysisException { } public void testCreateModelObjectV2() throws InvalidSPDXAnalysisException { - ModelObject result = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, + ModelObjectV2 result = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); } public void testGetModelObjectIModelStoreStringStringStringModelCopyManagerBooleanV2() throws InvalidSPDXAnalysisException { - ModelObject result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, + ModelObjectV2 result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); - ModelObject result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, + ModelObjectV2 result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, false); assertTrue(result2 instanceof Checksum); assertEquals(ID1, result2.getId()); @@ -102,9 +102,9 @@ public void testTypeToClassV2() throws InvalidSPDXAnalysisException { @SuppressWarnings("unchecked") public void testGetElementsV2() throws InvalidSPDXAnalysisException { - ModelObject file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, + ModelObjectV2 file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); - ModelObject file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, + ModelObjectV2 file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); try (Stream elementStream = (Stream)SpdxModelFactory.getElements(modelStore, DOCUMENT_URI, copyManager, SpdxFile.class)) { elementStream.forEach(element -> { @@ -129,9 +129,9 @@ public void testGetElementsV2() throws InvalidSPDXAnalysisException { @SuppressWarnings("unchecked") public void testGetElementsNamespace() throws InvalidSPDXAnalysisException { - ModelObject file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, + ModelObjectV2 file1 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); - ModelObject file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, + ModelObjectV2 file2 = SpdxModelFactory.createModelObjectV2(modelStore, DOCUMENT_URI, ID2, SpdxConstantsCompatV2.CLASS_SPDX_FILE, copyManager); try (Stream elementStream = (Stream)SpdxModelFactory.getElements(modelStore, DOCUMENT_URI + "#", copyManager, SpdxFile.class)) { elementStream.forEach(element -> { @@ -161,11 +161,11 @@ public void testClassUriToClassV2() throws InvalidSPDXAnalysisException { } public void testGetModelObjectIModelStoreStringStringModelCopyManagerV2() throws InvalidSPDXAnalysisException { - ModelObject result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, + ModelObjectV2 result = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, copyManager, true); assertTrue(result instanceof Checksum); assertEquals(ID1, result.getId()); - Optional result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, copyManager); + Optional result2 = SpdxModelFactory.getModelObjectV2(modelStore, DOCUMENT_URI, ID1, copyManager); assertTrue(result2.isPresent()); assertTrue(result2.get() instanceof Checksum); assertEquals(ID1, result2.get().getId()); diff --git a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java index 13da8ba7b..dace448cb 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java +++ b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java @@ -30,12 +30,12 @@ import org.spdx.storage.IModelStore.IdType; /** - * Concrete subclass of ModelObject for testing purposes + * Concrete subclass of ModelObjectV2 for testing purposes * * @author Gary O'Neall * */ -public class ModelObjectForTesting extends ModelObject { +public class ModelObjectForTesting extends ModelObjectV2 { public static final String TYPE = "ModelObjectForTesting"; @@ -101,7 +101,7 @@ public static class ModelObjectForTestingBuilder extends CoreModelObjectBuilder * @param from model object to copy the model store and copyManager from * @throws InvalidSPDXAnalysisException */ - public ModelObjectForTestingBuilder(ModelObject from) throws InvalidSPDXAnalysisException { + public ModelObjectForTestingBuilder(ModelObjectV2 from) throws InvalidSPDXAnalysisException { this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); } @@ -111,7 +111,7 @@ public ModelObjectForTestingBuilder(ModelObject from) throws InvalidSPDXAnalysis * @param objectUri URI for the object * @param objectUri */ - public ModelObjectForTestingBuilder(ModelObject from, String objectUri) { + public ModelObjectForTestingBuilder(ModelObjectV2 from, String objectUri) { this(from.getModelStore(), objectUri, from.getCopyManager()); setStrict(from.isStrict()); setExternalMap(from.externalMap); diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/ModelObjectTest.java index 229c4c21b..6128eb45a 100644 --- a/src/test/java/org/spdx/library/model/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/ModelObjectTest.java @@ -97,7 +97,7 @@ public class ModelObjectTest extends TestCase { new PropertyDescriptor("anylicensListProp2", SpdxConstants.CORE_NAMESPACE), new PropertyDescriptor("anylicenseListProp3", SpdxConstants.CORE_NAMESPACE)}; - ModelObject[] TEST_MODEL_OBJECT_PROP_VALUES; + ModelObjectV2[] TEST_MODEL_OBJECT_PROP_VALUES; List[] TEST_LIST_PROPERTY_VALUES; AnyLicenseInfo[] TEST_ANYLICENSEINFO_PROP_VALUES; List[] TEST_ANYLICENSEINFO_LIST_PROP_VALUES; @@ -138,10 +138,10 @@ protected void setUp() throws Exception { cls.getMembers().add(eli1); TEST_LIST_PROPERTY_VALUES = new List[] {Arrays.asList("ListItem1", "listItem2", "listItem3"), Arrays.asList(true, false, true), - Arrays.asList(new ModelObject[] {lex, eli1}), + Arrays.asList(new ModelObjectV2[] {lex, eli1}), Arrays.asList(new HashAlgorithm[] {HashAlgorithm.SHA256, HashAlgorithm.SHA1}), Arrays.asList(new Integer[] {1, 3, 5})}; - TEST_MODEL_OBJECT_PROP_VALUES = new ModelObject[] {lex, eli1}; + TEST_MODEL_OBJECT_PROP_VALUES = new ModelObjectV2[] {lex, eli1}; // TODO: Changes these back once we have the individuals implemented /* TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true), @@ -205,7 +205,7 @@ protected void tearDown() throws Exception { } /** - * Test method for {@link org.spdx.library.model.ModelObject#ModelObject(org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager, boolean)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#ModelObject(org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager, boolean)}. * @throws InvalidSPDXAnalysisException */ public void testModelObjectIModelStoreStringModelCopyManagerBoolean() throws InvalidSPDXAnalysisException { @@ -223,7 +223,7 @@ public void testModelObjectIModelStoreStringModelCopyManagerBoolean() throws Inv } /** - * Test method for {@link org.spdx.library.model.ModelObject#ModelObject(org.spdx.library.mobdel.ModelObjectBuilder)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#ModelObject(org.spdx.library.mobdel.ModelObjectBuilder)}. */ public void testModelObjectModelObjectBuilder() throws InvalidSPDXAnalysisException { ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); @@ -245,7 +245,7 @@ public void testSetExternalMap() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#verify(java.lang.String)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#verify(java.lang.String)}. */ public void testVerifyString() throws InvalidSPDXAnalysisException { ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); @@ -253,7 +253,7 @@ public void testVerifyString() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getObjectUri()}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectUri()}. */ public void testGetObjectUri() throws InvalidSPDXAnalysisException { ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); @@ -261,7 +261,7 @@ public void testGetObjectUri() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getModelStore()}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getModelStore()}. */ public void testGetModelStore() throws InvalidSPDXAnalysisException { ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); @@ -269,7 +269,7 @@ public void testGetModelStore() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#setStrict(boolean)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#setStrict(boolean)}. */ public void testSetStrict() throws InvalidSPDXAnalysisException { ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); @@ -279,7 +279,7 @@ public void testSetStrict() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.ModelObject#getPropertyValueDescriptors()}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getPropertyValueDescriptors()}. */ public void testGetPropertyValueDescriptors() throws InvalidSPDXAnalysisException { ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); @@ -293,210 +293,210 @@ public void testGetPropertyValueDescriptors() throws InvalidSPDXAnalysisExceptio } } - protected void addTestValues(ModelObject mo) throws InvalidSPDXAnalysisException { + protected void addTestValues(ModelObjectV2 mo) throws InvalidSPDXAnalysisException { for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { mo.setPropertyValue(entry.getKey(), entry.getValue()); } } /** - * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#setPropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#setPropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#updatePropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#updatePropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getStringPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getStringPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetStringPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getIntegerPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getIntegerPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetIntegerPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getEnumPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getEnumPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetEnumPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getBooleanPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getBooleanPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetAnyLicenseInfoPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getElementPropertyValue(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getElementPropertyValue(org.spdx.storage.PropertyDescriptor)}. */ public void testGetElementPropertyValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#removeProperty(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#removeProperty(org.spdx.storage.PropertyDescriptor)}. */ public void testRemoveProperty() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateRemoveProperty(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#updateRemoveProperty(org.spdx.storage.PropertyDescriptor)}. */ public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#clearValueCollection(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#clearValueCollection(org.spdx.storage.PropertyDescriptor)}. */ public void testClearValueCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateClearValueCollection(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#updateClearValueCollection(org.spdx.storage.PropertyDescriptor)}. */ public void testUpdateClearValueCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#addPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#addPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ public void testAddPropertyValueToCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateAddPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#updateAddPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ public void testUpdateAddPropertyValueToCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#removePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#removePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ public void testRemovePropertyValueFromCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#updateRemovePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#updateRemovePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. */ public void testUpdateRemovePropertyValueFromCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValueSet(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectPropertyValueSet(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. */ public void testGetObjectPropertyValueSet() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getObjectPropertyValueCollection(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectPropertyValueCollection(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. */ public void testGetObjectPropertyValueCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getStringCollection(org.spdx.storage.PropertyDescriptor)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getStringCollection(org.spdx.storage.PropertyDescriptor)}. */ public void testGetStringCollection() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. */ public void testIsCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#equivalent(org.spdx.library.model.ModelObject)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#equivalent(org.spdx.library.model.ModelObjectV2)}. */ public void testEquivalentModelObject() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#equals(java.lang.Object)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#equals(java.lang.Object)}. */ public void testEqualsObject() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#clone(org.spdx.storage.IModelStore)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#clone(org.spdx.storage.IModelStore)}. */ public void testCloneIModelStore() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#copyFrom(org.spdx.library.model.ModelObject)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#copyFrom(org.spdx.library.model.ModelObjectV2)}. */ public void testCopyFrom() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#copyFromV2(org.spdx.library.model.compat.v2.ModelObject)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#copyFromV2(org.spdx.library.model.compat.v2.ModelObjectV2)}. */ public void testCopyFromV2() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#setCopyManager(org.spdx.library.ModelCopyManager)}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#setCopyManager(org.spdx.library.ModelCopyManager)}. */ public void testSetCopyManager() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#getCopyManager()}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#getCopyManager()}. */ public void testGetCopyManager() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); } /** - * Test method for {@link org.spdx.library.model.ModelObject#toTypedValue()}. + * Test method for {@link org.spdx.library.model.ModelObjectV2#toTypedValue()}. */ public void testToTypedValue() throws InvalidSPDXAnalysisException { fail("Not yet implemented"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java index ce7e5752b..2894120bd 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelObjectTest.java @@ -104,7 +104,7 @@ public class ModelObjectTest extends TestCase { new PropertyDescriptor("anylicensListProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), new PropertyDescriptor("anylicenseListProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; - ModelObject[] TEST_MODEL_OBJECT_PROP_VALUES; + ModelObjectV2[] TEST_MODEL_OBJECT_PROP_VALUES; List[] TEST_LIST_PROPERTY_VALUES; AnyLicenseInfo[] TEST_ANYLICENSEINFO_PROP_VALUES; List[] TEST_ANYLICENSEINFO_LIST_PROP_VALUES; @@ -131,10 +131,10 @@ protected void setUp() throws Exception { cls.addMember(eli1); TEST_LIST_PROPERTY_VALUES = new List[] {Arrays.asList("ListItem1", "listItem2", "listItem3"), Arrays.asList(true, false, true), - Arrays.asList(new ModelObject[] {lex, eli1}), + Arrays.asList(new ModelObjectV2[] {lex, eli1}), Arrays.asList(new ChecksumAlgorithm[] {ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1}), Arrays.asList(new Integer[] {1, 3, 5})}; - TEST_MODEL_OBJECT_PROP_VALUES = new ModelObject[] {lex, eli1}; + TEST_MODEL_OBJECT_PROP_VALUES = new ModelObjectV2[] {lex, eli1}; TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new SpdxListedLicense("Apache-2.0"), eli1, new SpdxNoneLicense()}; TEST_ANYLICENSEINFO_LIST_PROP_VALUES = new List[] {Arrays.asList(new AnyLicenseInfo[] {new SpdxListedLicense("MIT"), eli1, new SpdxListedLicense("GPL-2.0-only")}), Arrays.asList(new AnyLicenseInfo[] {new SpdxNoAssertionLicense()}), @@ -182,7 +182,7 @@ protected void tearDown() throws Exception { super.tearDown(); } - protected void addTestValues(ModelObject mo) throws InvalidSPDXAnalysisException { + protected void addTestValues(ModelObjectV2 mo) throws InvalidSPDXAnalysisException { for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { mo.setPropertyValue(entry.getKey(), entry.getValue()); } @@ -192,20 +192,20 @@ protected void addTestValues(ModelObject mo) throws InvalidSPDXAnalysisException protected boolean compareLists(Object olist1, Object olist2) throws InvalidSPDXAnalysisException { List list1; if (olist1 instanceof List) { - if (((List)(olist1)).size() > 0 && ((List)(olist1)).get(0) instanceof ModelObject) { + if (((List)(olist1)).size() > 0 && ((List)(olist1)).get(0) instanceof ModelObjectV2) { // convert type TypedValue list1 = new ArrayList(); for (Object o:((List)(olist1))) { - list1.add(((ModelObject)o).toTypedValue()); + list1.add(((ModelObjectV2)o).toTypedValue()); } } else { list1 = (List)(olist1); } } else if (olist1 instanceof Object[]) { - if (((Object[])olist1).length > 0 && ((Object[])olist1)[0] instanceof ModelObject) { + if (((Object[])olist1).length > 0 && ((Object[])olist1)[0] instanceof ModelObjectV2) { list1 = new ArrayList(); for (Object o:((Object[])olist1)) { - list1.add(((ModelObject)o).toTypedValue()); + list1.add(((ModelObjectV2)o).toTypedValue()); } } else { list1 = Arrays.asList(olist1); @@ -215,20 +215,20 @@ protected boolean compareLists(Object olist1, Object olist2) throws InvalidSPDXA } List list2; if (olist2 instanceof List) { - if (((List)(olist2)).size() > 0 && ((List)(olist2)).get(0) instanceof ModelObject) { + if (((List)(olist2)).size() > 0 && ((List)(olist2)).get(0) instanceof ModelObjectV2) { // convert type TypedValue list2 = new ArrayList(); for (Object o:((List)(olist2))) { - list2.add(((ModelObject)o).toTypedValue()); + list2.add(((ModelObjectV2)o).toTypedValue()); } } else { list2 = (List)(olist2); } } else if (olist2 instanceof Object[]) { - if (((Object[])olist2).length > 0 && ((Object[])olist2)[0] instanceof ModelObject) { + if (((Object[])olist2).length > 0 && ((Object[])olist2)[0] instanceof ModelObjectV2) { list2 = new ArrayList(); for (Object o:((Object[])olist2)) { - list2.add(((ModelObject)o).toTypedValue()); + list2.add(((ModelObjectV2)o).toTypedValue()); } } else { list2 = Arrays.asList(olist2); @@ -237,7 +237,7 @@ protected boolean compareLists(Object olist1, Object olist2) throws InvalidSPDXA return false; } assertEquals(list1.size(), list2.size()); - if (list1.size() > 0 && list1.get(0) instanceof ModelObject) { + if (list1.size() > 0 && list1.get(0) instanceof ModelObjectV2) { // convert to type } for (Object list1item:list1) { @@ -263,7 +263,7 @@ public void testModelObjectCreate() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getDocumentUri()}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getDocumentUri()}. * @throws InvalidSPDXAnalysisException */ public void testGetDocumentUri() throws InvalidSPDXAnalysisException { @@ -272,7 +272,7 @@ public void testGetDocumentUri() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getId()}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getId()}. * @throws InvalidSPDXAnalysisException */ public void testGetId() throws InvalidSPDXAnalysisException { @@ -281,7 +281,7 @@ public void testGetId() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getModelStore()}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getModelStore()}. */ public void testGetModelStore() throws InvalidSPDXAnalysisException { InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); @@ -290,7 +290,7 @@ public void testGetModelStore() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getPropertyValueDescriptors()}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getPropertyValueDescriptors()}. */ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -305,7 +305,7 @@ public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getObjectPropertyValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getObjectPropertyValue(java.lang.String)}. */ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -316,7 +316,7 @@ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { assertTrue(result.isPresent()); if (result.get() instanceof List) { assertTrue(compareLists(entry.getValue(), result.get())); - } else if (result.get() instanceof ModelObject) { + } else if (result.get() instanceof ModelObjectV2) { assertEquals(entry.getValue(), result.get()); } else if (result.get() instanceof ModelCollectionV2) { assertTrue(compareLists(entry.getValue(), ((ModelCollectionV2)result.get()).toImmutableList())); @@ -328,7 +328,7 @@ public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#setPropertyValue(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#setPropertyValue(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. */ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -341,7 +341,7 @@ public void testSetPropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updatePropertyValue(java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#updatePropertyValue(java.lang.String, java.lang.Object)}. */ public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -356,7 +356,7 @@ public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getStringPropertyValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getStringPropertyValue(java.lang.String)}. */ public void testGetStringPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -387,7 +387,7 @@ public void testGetIntegerPropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getBooleanPropertyValue(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getBooleanPropertyValue(java.lang.String)}. */ public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -404,7 +404,7 @@ public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#removeProperty(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#removeProperty(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. */ public void testRemovePropertyIModelStoreStringStringString() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -419,7 +419,7 @@ public void testRemovePropertyIModelStoreStringStringString() throws InvalidSPDX } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateRemoveProperty(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#updateRemoveProperty(java.lang.String)}. */ public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -437,7 +437,7 @@ public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#clearValueCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#clearValueCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String)}. */ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -450,7 +450,7 @@ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateClearValueCollection(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#updateClearValueCollection(java.lang.String)}. */ public void testUpdateClearPropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -467,7 +467,7 @@ public void testUpdateClearPropertyValueList() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#addValueToCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#addValueToCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. */ public void testAddPropertyValueToList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -485,7 +485,7 @@ public void testAddPropertyValueToList() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateAddPropertyValueToCollection(java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#updateAddPropertyValueToCollection(java.lang.String, java.lang.Object)}. */ public void testUpdateAddPropertyValueToList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -505,7 +505,7 @@ public void testUpdateAddPropertyValueToList() throws InvalidSPDXAnalysisExcepti } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#replacePropertyValueList(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.util.List)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#replacePropertyValueList(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.util.List)}. */ public void testReplacePropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -522,7 +522,7 @@ public void testReplacePropertyValueList() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateReplacePropertyValueList(java.lang.String, java.util.List)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#updateReplacePropertyValueList(java.lang.String, java.util.List)}. */ public void testUpdateReplacePropertyValueList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -539,7 +539,7 @@ public void testUpdateReplacePropertyValueList() throws InvalidSPDXAnalysisExcep } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#removePropertyValueFromCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#removePropertyValueFromCollection(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)}. */ public void testRemovePropertyValueFromList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -557,7 +557,7 @@ public void testRemovePropertyValueFromList() throws InvalidSPDXAnalysisExceptio } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#updateRemovePropertyValueFromCollection(java.lang.String, java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#updateRemovePropertyValueFromCollection(java.lang.String, java.lang.Object)}. */ public void testUpdateRemovePropertyValueFromList() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -577,7 +577,7 @@ public void testUpdateRemovePropertyValueFromList() throws InvalidSPDXAnalysisEx } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#getStringPropertyValueList(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#getStringPropertyValueList(java.lang.String)}. */ public void testGetStringPropertyValueCollection() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -593,7 +593,7 @@ public void testGetStringPropertyValueCollection() throws InvalidSPDXAnalysisExc } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.compat.v2.ModelObject)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#equivalent(org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject)}. */ public void testEquivalent() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -745,7 +745,7 @@ public void testListEquivalenceIsSymmetric() throws InvalidSPDXAnalysisException } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#equals(java.lang.Object)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#equals(java.lang.Object)}. */ public void testEqualsObject() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -765,13 +765,13 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#clone()}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#clone()}. */ public void testClone() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); addTestValues(gmo); InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); - ModelObject result = gmo.clone(store2); + ModelObjectV2 result = gmo.clone(store2); assertTrue(result instanceof GenericModelObject); assertEquals(result, gmo); assertTrue(result.equivalent(gmo)); @@ -779,7 +779,7 @@ public void testClone() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#copyFrom(org.spdx.library.model.compat.v2.compat.v2.ModelObject)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#copyFrom(org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject)}. */ public void testCopyFrom() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -796,7 +796,7 @@ public void testCopyFrom() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#idToIdType(java.lang.String)}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#idToIdType(java.lang.String)}. */ public void testIdToIdType() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); @@ -810,7 +810,7 @@ public void testIdToIdType() throws InvalidSPDXAnalysisException { } /** - * Test method for {@link org.spdx.library.model.compat.v2.compat.v2.ModelObject#toTypedValue()}. + * Test method for {@link org.spdx.library.model.compat.v2.ModelObjectV2.v2.ModelObject#toTypedValue()}. */ public void testToTypeValue() throws InvalidSPDXAnalysisException { GenericModelObject gmo = new GenericModelObject(store, docUri, TEST_ID, copyManager, true); diff --git a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java index 9c5c5bccb..7e6e543f2 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/ModelStorageClassConverterTest.java @@ -127,7 +127,7 @@ public void testOptionalStoredObjectToModelObject() throws InvalidSPDXAnalysisEx } public void testModelObjectToStoredObject() throws InvalidSPDXAnalysisException { - // ModelObject + // ModelObjectV2 Object result = ModelStorageClassConverter.modelObjectToStoredObject(gmo, gmo.getDocumentUri(), gmo.getModelStore(), gmo.getCopyManager()); assertTrue(result instanceof TypedValue); assertEquals(gmo.getId(), ((TypedValue)result).getObjectUri()); @@ -178,7 +178,7 @@ public void testCopyIModelStoreStringIModelStoreStringStringString() throws Inva } public void testModelClassToStoredClass() { - // ModelObject + // ModelObjectV2 assertEquals(TypedValue.class, ModelStorageClassConverter.modelClassToStoredClass(GenericModelObject.class)); // InvidiualUriValue assertEquals(SimpleUriValue.class, ModelStorageClassConverter.modelClassToStoredClass(ChecksumAlgorithm.MD5.getClass())); diff --git a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java index 70bbfc786..0d4e7eed1 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxDocumentTest.java @@ -24,24 +24,37 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.core.DefaultModelStore; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistry; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxModelFactory; import org.spdx.library.Version; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.AnnotationType; -import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; -import org.spdx.library.model.compat.v2.license.SimpleLicensingInfo; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.Checksum; +import org.spdx.library.model.v2.ExternalDocumentRef; +import org.spdx.library.model.v2.GenericModelObject; +import org.spdx.library.model.v2.GenericSpdxElement; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxCreatorInformation; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.library.model.v2.SpdxElement; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.SpdxItem; +import org.spdx.library.model.v2.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxModelInfoV2_X; +import org.spdx.library.model.v2.SpdxPackage; +import org.spdx.library.model.v2.enumerations.AnnotationType; +import org.spdx.library.model.v2.enumerations.ChecksumAlgorithm; +import org.spdx.library.model.v2.enumerations.FileType; +import org.spdx.library.model.v2.enumerations.RelationshipType; +import org.spdx.library.model.v2.license.AnyLicenseInfo; +import org.spdx.library.model.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.v2.license.LicenseInfoFactory; +import org.spdx.library.model.v2.license.SimpleLicensingInfo; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.storage.CompatibleModelStoreWrapper; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; @@ -103,7 +116,8 @@ public class SpdxDocumentTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); - DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV2_X()); + DefaultModelStore.initialize(new InMemSpdxStore(), "http://default/namespace", new ModelCopyManager()); gmo = new GenericModelObject(); CCO_DATALICENSE = LicenseInfoFactory.getListedLicenseById("CC0-1.0"); LICENSE1 = new ExtractedLicenseInfo("LicenseRef-1", "License Text 1"); @@ -127,7 +141,7 @@ protected void setUp() throws Exception { RelationshipType.CONTAINS, "Relationship Comment1"); RELATIONSHIP2 = gmo.createRelationship(RELATED_ELEMENT2, RelationshipType.DYNAMIC_LINK, "Relationship Comment2"); - FILE1 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + FILE1 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId), "FileName1", LICENSE1, Arrays.asList(new ExtractedLicenseInfo[] {LICENSE2}), "File Copyright1", CHECKSUM1) .setComment("FileComment 1") @@ -137,7 +151,7 @@ protected void setUp() throws Exception { .setNoticeText("File Notice1") .build(); - FILE2 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + FILE2 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId), "FileName2", LICENSE2, Arrays.asList(new ExtractedLicenseInfo[] {LICENSE3}), "File Copyright2", CHECKSUM2) .setComment("FileComment 2") @@ -147,7 +161,7 @@ protected void setUp() throws Exception { .setNoticeText("File Notice2") .build(); - FILE3 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + FILE3 = gmo.createSpdxFile(gmo.getModelStore().getNextId(IdType.SpdxId), "FileName3", LICENSE3, Arrays.asList(new ExtractedLicenseInfo[] {LICENSE1}), "File Copyright2", CHECKSUM1) .setComment("FileComment 3") @@ -157,7 +171,7 @@ protected void setUp() throws Exception { .setNoticeText("File Notice3") .build(); - PACKAGE1 = gmo.createPackage(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + PACKAGE1 = gmo.createPackage(gmo.getModelStore().getNextId(IdType.SpdxId), "Package 1", LICENSE1, "Pkg Copyright1", LICENSE2) .addChecksum(CHECKSUM1) .setLicenseInfosFromFile(Arrays.asList(new SimpleLicensingInfo[] {LICENSE2})) @@ -177,7 +191,7 @@ protected void setUp() throws Exception { .setVersionInfo("version1") .build(); - PACKAGE2 = gmo.createPackage(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + PACKAGE2 = gmo.createPackage(gmo.getModelStore().getNextId(IdType.SpdxId), "Package 2", LICENSE2, "Pkg Copyright2", LICENSE3) .addChecksum(CHECKSUM2) .setLicenseInfosFromFile(Arrays.asList(new SimpleLicensingInfo[] {LICENSE2})) @@ -197,7 +211,7 @@ protected void setUp() throws Exception { .setVersionInfo("version2") .build(); - PACKAGE3 = gmo.createPackage(gmo.getModelStore().getNextId(IdType.SpdxId, gmo.getDocumentUri()), + PACKAGE3 = gmo.createPackage(gmo.getModelStore().getNextId(IdType.SpdxId), "Package 3", LICENSE1, "Pkg Copyright3", LICENSE3) .addChecksum(CHECKSUM1) .setLicenseInfosFromFile(Arrays.asList(new SimpleLicensingInfo[] {LICENSE2})) @@ -293,7 +307,7 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { assertTrue(doc.equivalent(doc)); String doc2Uri = "http://spdx.org/spdx/2ndoc/2342"; - IModelStore model2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + IModelStore model2 = new InMemSpdxStore(); SpdxDocument doc2 = SpdxModelFactory.createSpdxDocumentV2(model2, doc2Uri, gmo.getCopyManager()); doc2.setStrict(false); doc2.setAnnotations(annotations); @@ -367,7 +381,7 @@ public void testVerify() throws InvalidSPDXAnalysisException { doc.setName(DOC_NAME1); doc.setRelationships(relationships); doc.setDocumentDescribes(items); - doc.setSpecVersion(Version.CURRENT_SPDX_VERSION); + doc.setSpecVersion(Version.TWO_POINT_THREE_VERSION); List result = doc.verify(); assertEquals(0, result.size()); // data license @@ -378,10 +392,6 @@ public void testVerify() throws InvalidSPDXAnalysisException { doc.setName(null); result = doc.verify(); assertEquals(2, result.size()); - // SpecVersion - doc.setSpecVersion(null); - result = doc.verify(); - assertEquals(3, result.size()); } /** @@ -416,7 +426,7 @@ public void testGetDocumentDescribes() throws InvalidSPDXAnalysisException { doc.setName(DOC_NAME1); doc.setRelationships(relationships); doc.setDocumentDescribes(items); - doc.setSpecVersion(Version.CURRENT_SPDX_VERSION); + doc.setSpecVersion(Version.TWO_POINT_THREE_VERSION); assertTrue(collectionsSame(items, doc.getDocumentDescribes())); List expected = Arrays.asList(new SpdxItem[] { @@ -651,7 +661,6 @@ public void testSetSpecVersion() throws InvalidSPDXAnalysisException { doc.setName(DOC_NAME1); doc.setRelationships(relationships); doc.setDocumentDescribes(items); - assertTrue(doc.getSpecVersion().isEmpty()); String ver = "SPDX-2.1"; doc.setSpecVersion(ver); assertEquals(ver, doc.getSpecVersion()); @@ -659,16 +668,17 @@ public void testSetSpecVersion() throws InvalidSPDXAnalysisException { // Test for issue 126 - removing a documentDescribes not properly decrementing use counts public void testRemoveDescribes() throws InvalidSPDXAnalysisException { - IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + IModelStore modelStore = new InMemSpdxStore(); String docUri = "https://some.doc.uri"; ModelCopyManager copyManager = new ModelCopyManager(); SpdxDocument doc = new SpdxDocument(modelStore, docUri, copyManager, true); - String describedElementId = "describedElement"; + String describedElementId = "SPDXRef-describedElement"; SpdxElement describedElement = new GenericSpdxElement(modelStore, docUri, describedElementId, copyManager, true); assertEquals(0, doc.getDocumentDescribes().size()); assertEquals(0, doc.getRelationships().size()); doc.getDocumentDescribes().add(describedElement); - assertEquals(1, doc.getDocumentDescribes().size()); + SpdxElement[] describes = doc.getDocumentDescribes().toArray(new SpdxElement[doc.getDocumentDescribes().size()]); + assertEquals(1, describes.length); assertEquals(1, doc.getRelationships().size()); Relationship rel = doc.getRelationships().toArray(new Relationship[1])[0]; assertEquals(describedElement, rel.getRelatedSpdxElement().get()); diff --git a/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java index dc602232e..3d0c3ff6a 100644 --- a/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java +++ b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java @@ -25,11 +25,18 @@ import java.util.List; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistry; import org.spdx.library.ModelCopyManager; +import org.spdx.library.model.v3.SpdxModelInfoV3_0; import org.spdx.library.model.v3.ai.AIPackage.AIPackageBuilder; +import org.spdx.library.model.v3.core.Agent.AgentBuilder; +import org.spdx.library.model.v3.core.CreationInfo; import org.spdx.library.model.v3.core.PresenceType; +import org.spdx.library.model.v3.core.ProfileIdentifierType; +import org.spdx.library.model.v3.core.CreationInfo.CreationInfoBuilder; import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -79,23 +86,32 @@ public class AIPackageTest extends TestCase { static final List MODEL_DATA_PREPROCESSING_TEST_LIST1 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE1, MODEL_DATA_PREPROCESSING_TEST_VALUE2 }); static final List MODEL_DATA_PREPROCESSING_TEST_LIST2 = Arrays.asList(new String[] { MODEL_DATA_PREPROCESSING_TEST_VALUE3 }); + private CreationInfo creationInfo; + protected void setUp() throws Exception { super.setUp(); + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV3_0()); modelStore = new InMemSpdxStore(); copyManager = new ModelCopyManager(); + creationInfo = new CreationInfoBuilder(modelStore, modelStore.getNextId(IdType.Anonymous), copyManager) + .setCreated("2010-01-29T18:30:22Z") + .setSpecVersion("3.0.0").build(); + AgentBuilder agentBuilder = new AgentBuilder(modelStore, "https://unique/id" + modelStore.getNextId(IdType.SpdxId), copyManager); + agentBuilder.setCreationInfo(creationInfo); + agentBuilder.setName("Creator Name"); + creationInfo.getCreatedBys().add(agentBuilder.build()); } protected void tearDown() throws Exception { super.tearDown(); } - public static AIPackageBuilder builderForAIPackageTests( + public AIPackageBuilder builderForAIPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager) .setLimitation(LIMITATION_TEST_VALUE) .setInformationAboutApplication(INFORMATION_ABOUT_APPLICATION_TEST_VALUE) .setInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) - .setEnergyConsumption(ENERGY_CONSUMPTION_TEST_VALUE) .addDomain(DOMAIN_TEST_VALUE1) .addDomain(DOMAIN_TEST_VALUE2) .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) @@ -108,14 +124,16 @@ public static AIPackageBuilder builderForAIPackageTests( .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) .setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE1) .setAutonomyType(AUTONOMY_TYPE_TEST_VALUE1) - .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) //TODO: Add in test values /******************** .addMetric(DictionaryEntry) .addMetricDecisionThreshold(DictionaryEntry) .addHyperparameter(DictionaryEntry) + .setEnergyConsumption(ENERGY_CONSUMPTION_TEST_VALUE) + .setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1) ***************/ ; + retval.setCreationInfo(creationInfo); return retval; } diff --git a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java index 98056cb2a..8e472b622 100644 --- a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java +++ b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java @@ -164,7 +164,7 @@ public static boolean isListsEqual(List expected, List expected, List result) throws InvalidSPDXAnalysisException { + public static boolean isListsEquivalent(List expected, List result) throws InvalidSPDXAnalysisException { if (Objects.isNull(expected)) { return Objects.isNull(result); } @@ -174,9 +174,9 @@ public static boolean isListsEquivalent(List expected, Li if (expected.size() != result.size()) { return false; } - for (ModelObject o1:expected) { + for (ModelObjectV2 o1:expected) { boolean found = false; - for (ModelObject o2:result) { + for (ModelObjectV2 o2:result) { if (o1.equivalent(o2)) { found = true; break; @@ -189,8 +189,8 @@ public static boolean isListsEquivalent(List expected, Li return true; } - public static void copyObjectsToDoc(SpdxDocument doc, Collection modelObjects) throws InvalidSPDXAnalysisException { - for (ModelObject mo:modelObjects) { + public static void copyObjectsToDoc(SpdxDocument doc, Collection modelObjects) throws InvalidSPDXAnalysisException { + for (ModelObjectV2 mo:modelObjects) { doc.getCopyManager().copy(doc.getModelStore(), mo.getModelStore(), CompatibleModelStoreWrapper.documentUriIdToUri(mo.getDocumentUri(), mo.getId(), mo.getModelStore()), mo.getType(), From d7a92cb8683ab4b2f3735c1fb57f8e1e26e4f270 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 17 May 2024 14:43:04 -0700 Subject: [PATCH 27/62] Update unit test with unique V3 naming Signed-off-by: Gary O'Neall --- .../library/model/v3/ai/AIPackageTest.java | 169 +++++++++--------- 1 file changed, 85 insertions(+), 84 deletions(-) diff --git a/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java index 3d0c3ff6a..3471307e8 100644 --- a/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java +++ b/src/test/java/org/spdx/library/model/v3/ai/AIPackageTest.java @@ -29,7 +29,7 @@ import org.spdx.core.ModelRegistry; import org.spdx.library.ModelCopyManager; import org.spdx.library.model.v3.SpdxModelInfoV3_0; -import org.spdx.library.model.v3.ai.AIPackage.AIPackageBuilder; +import org.spdx.library.model.v3.ai.AIAIPackage.AIAIPackageBuilder; import org.spdx.library.model.v3.core.Agent.AgentBuilder; import org.spdx.library.model.v3.core.CreationInfo; import org.spdx.library.model.v3.core.PresenceType; @@ -54,8 +54,8 @@ public class AIPackageTest extends TestCase { static final String INFORMATION_ABOUT_APPLICATION_TEST_VALUE = "test informationAboutApplication"; static final String INFORMATION_ABOUT_TRAINING_TEST_VALUE = "test informationAboutTraining"; static final String ENERGY_CONSUMPTION_TEST_VALUE = "test energyConsumption"; - static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE1 = SafetyRiskAssessmentType.values()[0]; - static final SafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE2 = SafetyRiskAssessmentType.values()[1]; + static final AISafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE1 = AISafetyRiskAssessmentType.values()[0]; + static final AISafetyRiskAssessmentType SAFETY_RISK_ASSESSMENT_TEST_VALUE2 = AISafetyRiskAssessmentType.values()[1]; static final PresenceType AUTONOMY_TYPE_TEST_VALUE1 = PresenceType.values()[0]; static final PresenceType AUTONOMY_TYPE_TEST_VALUE2 = PresenceType.values()[1]; static final PresenceType SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1 = PresenceType.values()[0]; @@ -106,24 +106,24 @@ protected void tearDown() throws Exception { super.tearDown(); } - public AIPackageBuilder builderForAIPackageTests( + public AIAIPackageBuilder builderForAIPackageTests( IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) throws InvalidSPDXAnalysisException { - AIPackageBuilder retval = new AIPackageBuilder(modelStore, objectUri, copyManager) - .setLimitation(LIMITATION_TEST_VALUE) - .setInformationAboutApplication(INFORMATION_ABOUT_APPLICATION_TEST_VALUE) - .setInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) - .addDomain(DOMAIN_TEST_VALUE1) - .addDomain(DOMAIN_TEST_VALUE2) - .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) - .addStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE2) - .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE1) - .addModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE2) - .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE1) - .addTypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) - .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) - .addModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) - .setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE1) - .setAutonomyType(AUTONOMY_TYPE_TEST_VALUE1) + AIAIPackageBuilder retval = new AIAIPackageBuilder(modelStore, objectUri, copyManager) + .setAILimitation(LIMITATION_TEST_VALUE) + .setAIInformationAboutApplication(INFORMATION_ABOUT_APPLICATION_TEST_VALUE) + .setAIInformationAboutTraining(INFORMATION_ABOUT_TRAINING_TEST_VALUE) + .addAIDomain(DOMAIN_TEST_VALUE1) + .addAIDomain(DOMAIN_TEST_VALUE2) + .addAIStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE1) + .addAIStandardCompliance(STANDARD_COMPLIANCE_TEST_VALUE2) + .addAIModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE1) + .addAIModelExplainability(MODEL_EXPLAINABILITY_TEST_VALUE2) + .addAITypeOfModel(TYPE_OF_MODEL_TEST_VALUE1) + .addAITypeOfModel(TYPE_OF_MODEL_TEST_VALUE2) + .addAIModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE1) + .addAIModelDataPreprocessing(MODEL_DATA_PREPROCESSING_TEST_VALUE2) + .setAISafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE1) + .setAIAutonomyType(AUTONOMY_TYPE_TEST_VALUE1) //TODO: Add in test values /******************** .addMetric(DictionaryEntry) @@ -142,7 +142,7 @@ public AIPackageBuilder builderForAIPackageTests( * @throws InvalidSPDXAnalysisException on errors */ public void testVerify() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); List result = testAIPackage.verify(); assertTrue(result.isEmpty()); // TODO - add negative tests @@ -152,28 +152,28 @@ public void testVerify() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getType()}. */ public void testGetType() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("AI.AIPackage", testAIPackage.getType()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("AI.AIAIPackage", testAIPackage.getType()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#toString()}. */ public void testToString() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals("AIPackage: "+TEST_OBJECT_URI, testAIPackage.toString()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals("AIAIPackage: "+TEST_OBJECT_URI, testAIPackage.toString()); } /** - * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#Element(org.spdx.library.model.v3.ai.AIPackage.AIPackageBuilder)}. + * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#Element(org.spdx.library.model.v3.ai.AIAIPackage.AIAIPackageBuilder)}. */ public void testAIPackageAIPackageBuilder() throws InvalidSPDXAnalysisException { builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); } public void testEquivalent() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - AIPackage test2AIPackage = builderForAIPackageTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AIAIPackage test2AIPackage = builderForAIPackageTests(new InMemSpdxStore(), "https://testObject2", copyManager).build(); assertTrue(testAIPackage.equivalent(test2AIPackage)); assertTrue(test2AIPackage.equivalent(testAIPackage)); // TODO change some parameters for negative tests @@ -183,77 +183,78 @@ public void testEquivalent() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSafetyRiskAssessment}. */ public void testAIPackagesetSafetyRiskAssessment() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SAFETY_RISK_ASSESSMENT_TEST_VALUE1), testAIPackage.getSafetyRiskAssessment()); - testAIPackage.setSafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE2); - assertEquals(Optional.of(SAFETY_RISK_ASSESSMENT_TEST_VALUE2), testAIPackage.getSafetyRiskAssessment()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(SAFETY_RISK_ASSESSMENT_TEST_VALUE1), testAIPackage.getAISafetyRiskAssessment()); + testAIPackage.setAISafetyRiskAssessment(SAFETY_RISK_ASSESSMENT_TEST_VALUE2); + assertEquals(Optional.of(SAFETY_RISK_ASSESSMENT_TEST_VALUE2), testAIPackage.getAISafetyRiskAssessment()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setAutonomyType}. */ public void testAIPackagesetAutonomyType() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(AUTONOMY_TYPE_TEST_VALUE1), testAIPackage.getAutonomyType()); - testAIPackage.setAutonomyType(AUTONOMY_TYPE_TEST_VALUE2); - assertEquals(Optional.of(AUTONOMY_TYPE_TEST_VALUE2), testAIPackage.getAutonomyType()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(AUTONOMY_TYPE_TEST_VALUE1), testAIPackage.getAIAutonomyType()); + testAIPackage.setAIAutonomyType(AUTONOMY_TYPE_TEST_VALUE2); + assertEquals(Optional.of(AUTONOMY_TYPE_TEST_VALUE2), testAIPackage.getAIAutonomyType()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setSensitivePersonalInformation}. */ public void testAIPackagesetSensitivePersonalInformation() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1), testAIPackage.getSensitivePersonalInformation()); - testAIPackage.setSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2); - assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2), testAIPackage.getSensitivePersonalInformation()); + fail("unimplemented"); +// AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE1), testAIPackage.getAIUseSensitivePersonalInformation()); +// testAIPackage.setAIUseSensitivePersonalInformation(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2); +// assertEquals(Optional.of(SENSITIVE_PERSONAL_INFORMATION_TEST_VALUE2), testAIPackage.getAIUseSensitivePersonalInformation()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setLimitation}. */ public void testAIPackagesetLimitation() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(LIMITATION_TEST_VALUE), testAIPackage.getLimitation()); - testAIPackage.setLimitation("new limitation value"); - assertEquals(Optional.of("new limitation value"), testAIPackage.getLimitation()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(LIMITATION_TEST_VALUE), testAIPackage.getAILimitation()); + testAIPackage.setAILimitation("new limitation value"); + assertEquals(Optional.of("new limitation value"), testAIPackage.getAILimitation()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setInformationAboutApplication}. */ public void testAIPackagesetInformationAboutApplication() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(INFORMATION_ABOUT_APPLICATION_TEST_VALUE), testAIPackage.getInformationAboutApplication()); - testAIPackage.setInformationAboutApplication("new informationAboutApplication value"); - assertEquals(Optional.of("new informationAboutApplication value"), testAIPackage.getInformationAboutApplication()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(INFORMATION_ABOUT_APPLICATION_TEST_VALUE), testAIPackage.getAIInformationAboutApplication()); + testAIPackage.setAIInformationAboutApplication("new informationAboutApplication value"); + assertEquals(Optional.of("new informationAboutApplication value"), testAIPackage.getAIInformationAboutApplication()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setInformationAboutTraining}. */ public void testAIPackagesetInformationAboutTraining() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(INFORMATION_ABOUT_TRAINING_TEST_VALUE), testAIPackage.getInformationAboutTraining()); - testAIPackage.setInformationAboutTraining("new informationAboutTraining value"); - assertEquals(Optional.of("new informationAboutTraining value"), testAIPackage.getInformationAboutTraining()); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertEquals(Optional.of(INFORMATION_ABOUT_TRAINING_TEST_VALUE), testAIPackage.getAIInformationAboutTraining()); + testAIPackage.setAIInformationAboutTraining("new informationAboutTraining value"); + assertEquals(Optional.of("new informationAboutTraining value"), testAIPackage.getAIInformationAboutTraining()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#setEnergyConsumption}. */ public void testAIPackagesetEnergyConsumption() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertEquals(Optional.of(ENERGY_CONSUMPTION_TEST_VALUE), testAIPackage.getEnergyConsumption()); - testAIPackage.setEnergyConsumption("new energyConsumption value"); - assertEquals(Optional.of("new energyConsumption value"), testAIPackage.getEnergyConsumption()); +// AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); +// assertEquals(Optional.of(ENERGY_CONSUMPTION_TEST_VALUE), testAIPackage.getAIEnergyConsumption()); +// testAIPackage.setAIEnergyConsumption("new energyConsumption value"); +// assertEquals(Optional.of("new energyConsumption value"), testAIPackage.getAIEnergyConsumption()); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getMetric}. */ public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); // assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetrics()))); // testAIPackage.getMetrics().clear(); // testAIPackage.getMetrics().addAll(NEW_TEST_VALUE); @@ -265,7 +266,7 @@ public void testAIPackagegetMetrics() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getMetricDecisionThreshold}. */ public void testAIPackagegetMetricDecisionThresholds() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); // assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getMetricDecisionThresholds()))); // testAIPackage.getMetricDecisionThresholds().clear(); // testAIPackage.getMetricDecisionThresholds().addAll(NEW_TEST_VALUE); @@ -277,7 +278,7 @@ public void testAIPackagegetMetricDecisionThresholds() throws InvalidSPDXAnalysi * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getHyperparameter}. */ public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); // assertTrue(UnitTestHelper.isListsEquivalent(TEST_VALUE, new ArrayList<>(testAIPackage.getHyperparameters()))); // testAIPackage.getHyperparameters().clear(); // testAIPackage.getHyperparameters().addAll(NEW_TEST_VALUE); @@ -289,54 +290,54 @@ public void testAIPackagegetHyperparameters() throws InvalidSPDXAnalysisExceptio * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getDomains}. */ public void testAIPackagegetDomains() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getDomains()))); - testAIPackage.getDomains().clear(); - testAIPackage.getDomains().addAll(DOMAIN_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getDomains()))); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST1, new ArrayList<>(testAIPackage.getAIDomains()))); + testAIPackage.getAIDomains().clear(); + testAIPackage.getAIDomains().addAll(DOMAIN_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(DOMAIN_TEST_LIST2, new ArrayList<>(testAIPackage.getAIDomains()))); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getStandardCompliances}. */ public void testAIPackagegetStandardCompliances() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST1, new ArrayList<>(testAIPackage.getStandardCompliances()))); - testAIPackage.getStandardCompliances().clear(); - testAIPackage.getStandardCompliances().addAll(STANDARD_COMPLIANCE_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST2, new ArrayList<>(testAIPackage.getStandardCompliances()))); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST1, new ArrayList<>(testAIPackage.getAIStandardCompliances()))); + testAIPackage.getAIStandardCompliances().clear(); + testAIPackage.getAIStandardCompliances().addAll(STANDARD_COMPLIANCE_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(STANDARD_COMPLIANCE_TEST_LIST2, new ArrayList<>(testAIPackage.getAIStandardCompliances()))); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getModelExplainabilitys}. */ public void testAIPackagegetModelExplainabilitys() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST1, new ArrayList<>(testAIPackage.getModelExplainabilitys()))); - testAIPackage.getModelExplainabilitys().clear(); - testAIPackage.getModelExplainabilitys().addAll(MODEL_EXPLAINABILITY_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST2, new ArrayList<>(testAIPackage.getModelExplainabilitys()))); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST1, new ArrayList<>(testAIPackage.getAIModelExplainabilitys()))); + testAIPackage.getAIModelExplainabilitys().clear(); + testAIPackage.getAIModelExplainabilitys().addAll(MODEL_EXPLAINABILITY_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(MODEL_EXPLAINABILITY_TEST_LIST2, new ArrayList<>(testAIPackage.getAIModelExplainabilitys()))); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getTypeOfModels}. */ public void testAIPackagegetTypeOfModels() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getTypeOfModels()))); - testAIPackage.getTypeOfModels().clear(); - testAIPackage.getTypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getTypeOfModels()))); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST1, new ArrayList<>(testAIPackage.getAITypeOfModels()))); + testAIPackage.getAITypeOfModels().clear(); + testAIPackage.getAITypeOfModels().addAll(TYPE_OF_MODEL_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(TYPE_OF_MODEL_TEST_LIST2, new ArrayList<>(testAIPackage.getAITypeOfModels()))); } /** * Test method for {@link org.spdx.library.model.v3.ai.AIPackage#getModelDataPreprocessings}. */ public void testAIPackagegetModelDataPreprocessings() throws InvalidSPDXAnalysisException { - AIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); - assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); - testAIPackage.getModelDataPreprocessings().clear(); - testAIPackage.getModelDataPreprocessings().addAll(MODEL_DATA_PREPROCESSING_TEST_LIST2); - assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testAIPackage.getModelDataPreprocessings()))); + AIAIPackage testAIPackage = builderForAIPackageTests(modelStore, TEST_OBJECT_URI, copyManager).build(); + assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST1, new ArrayList<>(testAIPackage.getAIModelDataPreprocessings()))); + testAIPackage.getAIModelDataPreprocessings().clear(); + testAIPackage.getAIModelDataPreprocessings().addAll(MODEL_DATA_PREPROCESSING_TEST_LIST2); + assertTrue(UnitTestHelper.isListsEqual(MODEL_DATA_PREPROCESSING_TEST_LIST2, new ArrayList<>(testAIPackage.getAIModelDataPreprocessings()))); } } \ No newline at end of file From d00efda8bf48bdef133719860436848cfae177da Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Tue, 21 May 2024 16:46:39 -0700 Subject: [PATCH 28/62] Intermediate checkin - unit test for CopyManager Signed-off-by: Gary O'Neall --- README.md | 25 +- .../ModelCopyConverter.java} | 14 +- .../org/spdx/library/ModelCopyManager.java | 32 +- .../java/org/spdx/library/ModelManager.java | 54 ---- .../org/spdx/library/SpdxModelFactory.java | 209 ++++++++++++ src/main/java/org/spdx/library/Version.java | 92 ------ .../HtmlTemplateOutputHandler.java | 212 ------------ .../ILicenseTemplateOutputHandler.java | 58 ---- .../InvalidLicenseTemplateException.java | 60 ---- .../LicenseParserException.java | 43 --- .../licenseTemplate/LicenseTemplateRule.java | 301 ------------------ .../LicenseTemplateRuleException.java | 37 --- .../SpdxLicenseTemplateHelper.java | 276 ---------------- .../TextTemplateOutputHandler.java | 70 ---- .../spdx/storage/simple/InMemSpdxStore.java | 6 +- .../spdx/library/ModelCopyManagerTest.java | 197 ++++++++++++ .../compat/v2}/SpdxModelFactoryTest.java | 3 +- .../v2}/SpdxVerificationHelperTest.java | 3 +- .../TestHtmlTemplateOutputHandler.java | 225 ------------- .../TestLicenseTemplateRule.java | 95 ------ .../TestSpdxLicenseTemplateHelper.java | 224 ------------- .../TestTextTemplateOutputHandler.java | 148 --------- 22 files changed, 455 insertions(+), 1929 deletions(-) rename src/main/java/org/spdx/{licenseTemplate/package-info.java => library/ModelCopyConverter.java} (72%) delete mode 100644 src/main/java/org/spdx/library/ModelManager.java create mode 100644 src/main/java/org/spdx/library/SpdxModelFactory.java delete mode 100644 src/main/java/org/spdx/library/Version.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/HtmlTemplateOutputHandler.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/ILicenseTemplateOutputHandler.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/InvalidLicenseTemplateException.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/LicenseParserException.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/LicenseTemplateRule.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/LicenseTemplateRuleException.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/SpdxLicenseTemplateHelper.java delete mode 100644 src/main/java/org/spdx/licenseTemplate/TextTemplateOutputHandler.java create mode 100644 src/test/java/org/spdx/library/ModelCopyManagerTest.java rename src/test/java/org/spdx/library/{ => model/compat/v2}/SpdxModelFactoryTest.java (98%) rename src/test/java/org/spdx/library/{ => model/compat/v2}/SpdxVerificationHelperTest.java (99%) delete mode 100644 src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java delete mode 100644 src/test/java/org/spdx/licenseTemplate/TestLicenseTemplateRule.java delete mode 100644 src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java delete mode 100644 src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java diff --git a/README.md b/README.md index 30665da72..67bea717b 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,12 @@ Java library which implements the Java object model for SPDX and provides useful ## Library Version Compatibility -Library version 3.0.0 and higher is not compatible with previous versions of the library due to breaking changes introduced in SPDX 3.0. +Library version 2.0.0 and higher is not compatible with previous versions of the library due to breaking changes introduced in SPDX 3.0. + +The library does support the spec versions 2.X and 3.X. + +See the [README-V3-UPGRADE.md](README-V3-UPGRADE.md) file for information on how to upgrade from earlier versions of the library. -See the [README-V3-UPGRADE.md](README-V3-UPGRADE.md) file for information on how to upgrade. ## Storage Interface The Spdx-Java-Library allows for different implementations of SPDX object storage. The storage facility implements the org.spdx.storage.IModelStore interface. This is a low level Service Provider Interface (SPI). The ISerializableModelStore extends the IModelStore and supports serializing and de-serializing the store to an I/O Stream. This interface is currently used to implement JSON, XML, YAML, and RDF/XML formats. The default storage interface is an in-memory Map which should be sufficient for light weight usage of the library. @@ -29,7 +32,7 @@ If you are using Maven, you can add the following dependency in your POM file: org.spdx java-spdx-library - (,1.0] + (,2.0] ``` @@ -37,16 +40,18 @@ If you are using Maven, you can add the following dependency in your POM file: There are a couple of static classes that help common usage scenarios: -- org.spdx.library.SPDXModelFactory supports the creation of specific model objects +- org.spdx.library.SpdxModelFactory supports the creation of specific model objects - org.spdx.library.model.license.LicenseInfoFactory supports the parsing of SPDX license expressions, creation, and comparison of SPDX licenses -## Update for new properties or classes +The first thing that needs to be done in your implementation is call `SpdxModelFactory.init()` - this will load all the supported versions. + +## Update for new versions of the spec To update Spdx-Java-Library, the following is a very brief checklist: - 1. Update the SpdxContants with any new or changed properties and classes - 2. Update the Java code representing the model - 3. Update the SpdxComparer/SpdxFileComparer in the org.spdx.compare package - 4. Update unit tests + 1. Create a Java .jar file for the new version which contains an implementation of `ISpdxModelInfo` - typically named SpdxModelInfoVXXX - where XXX is the version of the spec. + 2. Update the SpdxModelFactory source file to load the model info by adding the line `ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoVXXX());` in the static block at the very beginning of the class. + 3. If there are any conversions that are needed when copying to or from the new model version, add conversion code to the `ModelCopyConverter` class. + 4. Update SpdxModelFactory unit test for the highest version check ## Development Status -Note: This library is mostly stable, but may contain some defects. Reviews, suggestions are welcome. Please enter an issue with any suggestions. +Note: This library is currently unstable, and under development. Reviews, suggestions are welcome. Please enter an issue with any suggestions. diff --git a/src/main/java/org/spdx/licenseTemplate/package-info.java b/src/main/java/org/spdx/library/ModelCopyConverter.java similarity index 72% rename from src/main/java/org/spdx/licenseTemplate/package-info.java rename to src/main/java/org/spdx/library/ModelCopyConverter.java index 517795d07..f6ec18bb9 100644 --- a/src/main/java/org/spdx/licenseTemplate/package-info.java +++ b/src/main/java/org/spdx/library/ModelCopyConverter.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2019 Source Auditor Inc. + * Copyright (c) 2024 Source Auditor Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -15,10 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.spdx.library; + /** * @author Gary O'Neall * - * License template are used for matching licenses. + * Static class which manages the conversion between different versions of the SPDX specification * */ -package org.spdx.licenseTemplate; \ No newline at end of file +public class ModelCopyConverter { + + private ModelCopyConverter() { + // static class + } + +} diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index e76525e65..9137b8403 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -259,24 +259,24 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore); if (Objects.isNull(toObjectUri)) { if (toStore.exists(sourceUri)) { - logger.warn("Copying to an existing object "+sourceUri); - toObjectUri = sourceUri; - } else if (Objects.nonNull(toNamespace)) { - if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { - toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); - } else { - switch (fromStore.getIdType(sourceUri)) { - case Anonymous: toObjectUri = toStore.getNextId(IdType.Anonymous); break; - case LicenseRef: toObjectUri = toNamespace + toStore.getNextId(IdType.LicenseRef); break; - case DocumentRef: toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); break; - case SpdxId: toObjectUri = toNamespace + toStore.getNextId(IdType.SpdxId); break; - case ListedLicense: - case Unkown: - default: toObjectUri = sourceUri; + if (Objects.nonNull(toNamespace)) { + if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { + toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); + } else { + switch (fromStore.getIdType(sourceUri)) { + case Anonymous: toObjectUri = toStore.getNextId(IdType.Anonymous); break; + case LicenseRef: toObjectUri = toNamespace + toStore.getNextId(IdType.LicenseRef); break; + case DocumentRef: toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); break; + case SpdxId: toObjectUri = toNamespace + toStore.getNextId(IdType.SpdxId); break; + case ListedLicense: + case Unkown: + default: toObjectUri = toStore.getNextId(IdType.Anonymous); + } } + } else { + toObjectUri = toStore.getNextId(IdType.Anonymous); } - } - if (Objects.isNull(toObjectUri)) { + } else { toObjectUri = sourceUri; } copy(toStore, toObjectUri, fromStore, sourceUri, type, toSpecVersion, toNamespace); diff --git a/src/main/java/org/spdx/library/ModelManager.java b/src/main/java/org/spdx/library/ModelManager.java deleted file mode 100644 index f05a593ea..000000000 --- a/src/main/java/org/spdx/library/ModelManager.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2024 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import org.spdx.core.ModelRegistry; -import org.spdx.library.model.v2.SpdxModelInfoV2_X; -import org.spdx.library.model.v3.SpdxModelInfoV3_0; - -/** - * Main entrypoint for the SPDX Java Library - * - * This is a static class used to manage the different versions of the SPDX spec by - * creating different model classes based on the version of the spec. - * - * Since the release of the SPDX spec version 3.0, the Java classes were generated. - * - * Each generated set of classes generated for a specific version are in a separate library / Jar file. - * - * These generated classes are registered in the Core model registry - * - * @author Gary O'Neall - * - */ -public class ModelManager { - - static { - // register the supported spec version models - ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV2_X()); - ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV3_0()); - } - - /** - * Static class private constructor - */ - private ModelManager() { - // Static class - } - -} diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java new file mode 100644 index 000000000..9193c204c --- /dev/null +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -0,0 +1,209 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import javax.annotation.Nullable; + +import org.spdx.core.CoreModelObject; +import org.spdx.core.IModelCopyManager; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistry; +import org.spdx.core.ModelRegistryException; +import org.spdx.library.model.v2.SpdxModelInfoV2_X; +import org.spdx.library.model.v3.SpdxModelInfoV3_0; +import org.spdx.storage.IModelStore; + +/** + * Main entrypoint for the SPDX Java Library + * + * This is a static class used to manage the different versions of the SPDX spec by + * creating different model classes based on the version of the spec. + * + * Since the release of the SPDX spec version 3.0, the Java classes were generated. + * + * Each generated set of classes generated for a specific version are in a separate library / Jar file. + * + * These generated classes are registered in the Core model registry + * + * The inflateModelObject methods will create an initial object based on the name of the type + * + * @author Gary O'Neall + * + */ +public class SpdxModelFactory { + + static { + // register the supported spec version models + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV2_X()); + ModelRegistry.getModelRegistry().registerModel(new SpdxModelInfoV3_0()); + } + + static final String IMPLEMENTATION_VERSION = "2.0.0"; + + /** + * Static class private constructor + */ + private SpdxModelFactory() { + // Static class + } + + /** + * @param version version to check + * @return null if valid, otherwise will return a message + */ + static String verifyVersion(String version) { + if (Objects.isNull(version)) { + return "Null version"; + } + if (!ModelRegistry.getModelRegistry().containsSpecVersion(version)) { + return "Spec version is not supported"; + } + return null; + } + + /** + * @return the latest version of the spec supported by the library + */ + static String getLatestSpecVersion() { + List allVersions = ModelRegistry.getModelRegistry().getSupportedVersions(); + List preVersion2Versions = new ArrayList<>(); + List post2Versions = new ArrayList<>(); + for (String version:allVersions) { + if (version.startsWith("SPDX-")) { + preVersion2Versions.add(version); + } else { + post2Versions.add(version); + } + } + if (!post2Versions.isEmpty()) { + Collections.sort(post2Versions); + return post2Versions.get(post2Versions.size()-1); + } else if (!preVersion2Versions.isEmpty()) { + return preVersion2Versions.get(preVersion2Versions.size()-1); + } else { + return ""; + } + } + + /** + * This static method is a convenience to load this class and initialize the supported model versions. + * + * It should be called before using any other functionality from the library + */ + public static void init() { + // doesn't do anything + } + + /** + * If the object exists in the model store, it will be "inflated" back to the Java object. + * If the object does not exist AND the create parameter is true, a new object will be created and + * its inflated form will be returned + * @param modelStore store to use for the inflated object + * @param objectUri URI of the external element + * @param documentUri URI for the SPDX document to store the external element reference - used for compatibility with SPDX 2.X model stores + * @param type Type of the object to create + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param externalMap map of URI's to ExternalMaps for any external elements + * @param specVersion version of the SPDX spec the object complies with + * @param create if true, create the model object ONLY if it does not already exist + * @return model object of type type + * @throws InvalidSPDXAnalysisException + */ + public static CoreModelObject inflateModelObject(IModelStore modelStore, String objectUri, + String type, IModelCopyManager copyManager, + String specVersion, boolean create) throws InvalidSPDXAnalysisException { + return ModelRegistry.getModelRegistry().inflateModelObject(modelStore, objectUri, type, copyManager, specVersion, create); + } + + /** + * For the most recent spec version supported: + * If the object exists in the model store, it will be "inflated" back to the Java object. + * If the object does not exist AND the create parameter is true, a new object will be created and + * its inflated form will be returned + * @param modelStore store to use for the inflated object + * @param objectUri URI of the external element + * @param documentUri URI for the SPDX document to store the external element reference - used for compatibility with SPDX 2.X model stores + * @param type Type of the object to create + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param externalMap map of URI's to ExternalMaps for any external elements + * @param create if true, create the model object ONLY if it does not already exist + * @return model object of type type + * @throws InvalidSPDXAnalysisException + */ + public static CoreModelObject inflateModelObject(IModelStore modelStore, String objectUri, + String type, IModelCopyManager copyManager, boolean create) throws InvalidSPDXAnalysisException { + return inflateModelObject(modelStore, objectUri, type, copyManager, getLatestSpecVersion(), create); + } + + /** + * @param store store to use for the inflated object + * @param uri URI of the external element + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param documentUri URI for the SPDX document to store the external element reference - used for compatibility with SPDX 2.X model stores + * @param externalMap Map of URI's of elements referenced but not present in the store + * @param specVersion version of the SPDX spec the object complies with + * @return a java object representing an SPDX element external to model store, collection or document + * @throws InvalidSPDXAnalysisException + */ + public static Object getExternalElement(IModelStore store, String uri, + @Nullable IModelCopyManager copyManager, + String specVersion) throws InvalidSPDXAnalysisException { + return ModelRegistry.getModelRegistry().getExternalElement(store, uri, copyManager, specVersion); + } + + /** + * @param store store to use for the inflated object + * @param uri URI of the external element + * @param copyManager if non-null, implicitly copy any referenced properties from other model stores + * @param documentUri URI for the SPDX document to store the external element reference - used for compatibility with SPDX 2.X model stores + * @param externalMap Map of URI's of elements referenced but not present in the store + * @return a java object representing an SPDX element external to model store, collection or document for the most recent version of the spec supported + * @throws InvalidSPDXAnalysisException + */ + public static Object getExternalElement(IModelStore store, String uri, + @Nullable IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + return getExternalElement(store, uri, copyManager, getLatestSpecVersion()); + } + + /** + * Converts a URI to enum + * @param uri URI for the Enum individual + * @param specVersion Version of the spec the enum belongs to + * @return the Enum represented by the individualURI if it exists within the spec model + * @throws ModelRegistryException if the spec version does not exist + */ + public static @Nullable Enum uriToEnum(String uri, String specVersion) throws ModelRegistryException { + return ModelRegistry.getModelRegistry().uriToEnum(uri, specVersion); + } + + /** + * Converts a URI to enum for the latest supported version of the spec + * @param uri URI for the Enum individual + * @return the Enum represented by the individualURI if it exists within the spec model + * @throws ModelRegistryException if the spec version does not exist + */ + public static @Nullable Enum uriToEnum(String uri) throws ModelRegistryException { + return uriToEnum(uri, getLatestSpecVersion()); + } + +} diff --git a/src/main/java/org/spdx/library/Version.java b/src/main/java/org/spdx/library/Version.java deleted file mode 100644 index f3461243f..000000000 --- a/src/main/java/org/spdx/library/Version.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.regex.Matcher; - -import org.spdx.library.model.v2.SpdxConstantsCompatV2; - -/** - * Static class to manage the SPDX versions and the version of the implementation classes - * @author Gary O'Neall - * - */ -public class Version { - - public static final String POINT_EIGHT_SPDX_VERSION = "SPDX-0.8"; - public static final String POINT_NINE_SPDX_VERSION = "SPDX-0.9"; - public static final String ONE_DOT_ZERO_SPDX_VERSION = "SPDX-1.0"; - public static final String ONE_DOT_ONE_SPDX_VERSION = "SPDX-1.1"; - public static final String ONE_DOT_TWO_SPDX_VERSION = "SPDX-1.2"; - public static final String TWO_POINT_ZERO_VERSION = "SPDX-2.0"; - public static final String TWO_POINT_ONE_VERSION = "SPDX-2.1"; - public static final String TWO_POINT_TWO_VERSION = "SPDX-2.2"; - public static final String TWO_POINT_THREE_VERSION = "SPDX-2.3"; - public static final String THREE_POINT_ZERO_VERSION = "SPDX-3.0"; - public static final String CURRENT_SPDX_VERSION = THREE_POINT_ZERO_VERSION; - - public static final List SUPPORTED_SPDX_VERSIONS = Collections.unmodifiableList(new ArrayList(Arrays.asList(new String[]{ - ONE_DOT_ZERO_SPDX_VERSION, ONE_DOT_ONE_SPDX_VERSION, ONE_DOT_TWO_SPDX_VERSION, TWO_POINT_ZERO_VERSION, - TWO_POINT_ONE_VERSION, TWO_POINT_TWO_VERSION, TWO_POINT_THREE_VERSION, THREE_POINT_ZERO_VERSION - }))); - - public static final String CURRENT_IMPLEMENTATION_VERSION = "2.0.0"; - - public static String verifySpdxVersion(String spdxVersion) { - if (!spdxVersion.startsWith("SPDX-")) { - return "Invalid spdx version - must start with 'SPDX-'"; - } - Matcher docSpecVersionMatcher = SpdxConstantsCompatV2.SPDX_VERSION_PATTERN.matcher(spdxVersion); - if (!docSpecVersionMatcher.matches()) { - return "Invalid spdx version format - must match 'SPDX-M.N'"; - } - if (!SUPPORTED_SPDX_VERSIONS.contains(spdxVersion)) { - return "Version "+spdxVersion+" is not supported by this version of the rdf parser"; - } - return null; // if we got here, there is no problem - } - - private Version() { - // static class - } - - - /** - * Compares versions of the SPDX spec - * @param specVersion - * @param compareSpecVersion - * @return true if specVersion is less than compareSpecVersion - */ - public static boolean versionLessThan(String specVersion, - String compareSpecVersion) { - int i = SUPPORTED_SPDX_VERSIONS.indexOf(specVersion); - if (i < 0) { - return false; - } - int j = SUPPORTED_SPDX_VERSIONS.indexOf(compareSpecVersion); - if (j < 0) { - return false; - } - return i < j; - } - -} diff --git a/src/main/java/org/spdx/licenseTemplate/HtmlTemplateOutputHandler.java b/src/main/java/org/spdx/licenseTemplate/HtmlTemplateOutputHandler.java deleted file mode 100644 index 79ab9066f..000000000 --- a/src/main/java/org/spdx/licenseTemplate/HtmlTemplateOutputHandler.java +++ /dev/null @@ -1,212 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -/** - * License template output handler for generating an HTML version of a license from a license template. - * Used when parsing a license template. - * @author Gary O'Neall - * - */ -public class HtmlTemplateOutputHandler implements ILicenseTemplateOutputHandler { - - public static final String REPLACEABLE_LICENSE_TEXT_CLASS = "replaceable-license-text"; - public static final String OPTIONAL_LICENSE_TEXT_CLASS = "optional-license-text"; - static final String END_PARAGRAPH_TAG = "

"; - - private static final String STARTS_WITH_LETTER_REGEX = "[A-Za-z].*"; - - StringBuilder htmlString = new StringBuilder(); - - int optionalNestLevel = 0; - boolean movingParagraph = false; // true if we need to move the end of a - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#text(java.lang.String) - */ - @Override - public void text(String text) { - if (optionalNestLevel > 0) { - htmlString.append((SpdxLicenseTemplateHelper.formatEscapeHTML(text, false))); - } else { - htmlString.append(SpdxLicenseTemplateHelper.formatEscapeHTML(text, this.movingParagraph)); - this.movingParagraph = false; - } - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#variableRule(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void variableRule(LicenseTemplateRule rule) { - removeEndParagraphTag(); - htmlString.append(formatReplaceabledHTML(rule.getOriginal(), rule.getName())); - } - - /** - * Adds back an end paragraph tag if it was removed - */ - @SuppressWarnings("unused") - private void addRemovedEndParagraphTag() { - // this is a bit of a hack to deal with the formatting of HTML - // in normal text inserting end paragraphs at the end of the string - // which then creates line breaks. We need to move the end paragraph - // tags to after the rule generated text. - if (this.movingParagraph) { - if (endsInEndParagraph()) { - this.htmlString.append(END_PARAGRAPH_TAG); - } - this.movingParagraph = false; - } - } - - private boolean endsInEndParagraph() { - int lastEndParagraph = this.htmlString.lastIndexOf(END_PARAGRAPH_TAG); - return (lastEndParagraph == this.htmlString.length()-END_PARAGRAPH_TAG.length()) ; - } - /** - * If the current htmlString ends with an HTML end paragraph tag, remove it - * and set the flag so that it can be put back when addRemovedEndParagraphTag - * is called. - */ - private void removeEndParagraphTag() { - if (endsInEndParagraph()) { - this.movingParagraph = true; - this.htmlString.delete(this.htmlString.length()-END_PARAGRAPH_TAG.length(), this.htmlString.length()); - } - } - - /** - * Format HTML for a replaceable string - * @param text text for the optional license string - * @param objectUri ID used for the div - * @return - */ - public static String formatReplaceabledHTML(String text, String id) { - StringBuilder sb = new StringBuilder(); - sb.append("\n"); - sb.append(SpdxLicenseTemplateHelper.formatEscapeHTML(text)); - sb.append("\n"); - return sb.toString(); - } - - - /** - * Escape the ID string to conform to the legal characters for an HTML ID string - * @param objectUri - * @return - */ - public static String escapeIdString(String id) { - String retval = id; - if (!retval.matches(STARTS_WITH_LETTER_REGEX)) { - retval = "X" + retval; - } - for (int i = 0; i < retval.length(); i++) { - char c = retval.charAt(i); - if (!validIdChar(c)) { - // replace with "_" - retval = retval.replace(c, '_'); - } - } - return retval; - } - - /** - * @param c - * @return true if c is a valid character for an ID string - */ - private static boolean validIdChar(char c) { - return ((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - (c == '-')|| - (c == '_') || - (c == '.')); - } - - /** - * @return - */ - public String getHtml() { - return this.htmlString.toString(); - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void beginOptional(LicenseTemplateRule rule) { - if (this.optionalNestLevel == 0) { // We only want to format the top level optional texts - removeEndParagraphTag(); - this.htmlString.append(formatStartOptionalHTML(rule.getName())); - } - this.optionalNestLevel++; - } - - /** - * Format HTML for an optional string - * @param objectUri ID used for the div - * @return - */ - public static String formatStartOptionalHTML(String id) { - StringBuilder sb = new StringBuilder(); - sb.append("\n
\n"); - return sb.toString(); - } - - public static String formatEndOptionalHTML(boolean inParagraph) { - if (inParagraph) { - return "
\n

\n"; - } else { - return "\n"; - } - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#endOptional(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void endOptional(LicenseTemplateRule rule) { - this.optionalNestLevel--; - if (this.optionalNestLevel == 0) { // we are only formatting the top level optional elements - this.htmlString.append(formatEndOptionalHTML(this.movingParagraph)); - this.movingParagraph = false; - } - } - - @Override - public void completeParsing() { - // Nothing needs to be done - everything is processed inline - - } -} \ No newline at end of file diff --git a/src/main/java/org/spdx/licenseTemplate/ILicenseTemplateOutputHandler.java b/src/main/java/org/spdx/licenseTemplate/ILicenseTemplateOutputHandler.java deleted file mode 100644 index c6bc367c0..000000000 --- a/src/main/java/org/spdx/licenseTemplate/ILicenseTemplateOutputHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -/** - * Handles output for parsed license templates. The methods are called during parsing - * to handle the parsed rules and text. - * - * @author Gary O'Neall - * - */ -public interface ILicenseTemplateOutputHandler { - - /** - * Text for processing - * @param text - */ - void text(String text); - - /** - * Variable rule found within the template - * @param rule - */ - void variableRule(LicenseTemplateRule rule); - - /** - * Begin optional rule found - * @param rule - */ - void beginOptional(LicenseTemplateRule rule); - - /** - * End optional rule found - * @param rule - */ - void endOptional(LicenseTemplateRule rule); - - /** - * Signals all text has been added and parsing can be completed. - * @throws LicenseParserException - */ - void completeParsing() throws LicenseParserException; - -} diff --git a/src/main/java/org/spdx/licenseTemplate/InvalidLicenseTemplateException.java b/src/main/java/org/spdx/licenseTemplate/InvalidLicenseTemplateException.java deleted file mode 100644 index 3e89f4b6c..000000000 --- a/src/main/java/org/spdx/licenseTemplate/InvalidLicenseTemplateException.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2016 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -/** - * Exceptions related to invalid license templates - * @author Gary O'Neall - * - */ -public class InvalidLicenseTemplateException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * - */ - public InvalidLicenseTemplateException() { - super(); - } - - /** - * @param message - */ - public InvalidLicenseTemplateException(String message) { - super(message); - } - - /** - * @param cause - */ - public InvalidLicenseTemplateException(Throwable cause) { - super(cause); - } - - /** - * @param message - * @param cause - */ - public InvalidLicenseTemplateException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/src/main/java/org/spdx/licenseTemplate/LicenseParserException.java b/src/main/java/org/spdx/licenseTemplate/LicenseParserException.java deleted file mode 100644 index d71d598e2..000000000 --- a/src/main/java/org/spdx/licenseTemplate/LicenseParserException.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2015 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -import org.spdx.library.InvalidSPDXAnalysisException; - -/** - * Exception caused by an invalid license expression - * @author Gary O'Neall - * - */ -public class LicenseParserException extends InvalidSPDXAnalysisException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * @param msg - */ - public LicenseParserException(String msg) { - super(msg); - } - - public LicenseParserException(String msg, Throwable inner) { - super(msg, inner); - } -} diff --git a/src/main/java/org/spdx/licenseTemplate/LicenseTemplateRule.java b/src/main/java/org/spdx/licenseTemplate/LicenseTemplateRule.java deleted file mode 100644 index e30c00462..000000000 --- a/src/main/java/org/spdx/licenseTemplate/LicenseTemplateRule.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -/** - * Implements a license rule - * @author Gary O'Neall - * - */ -public class LicenseTemplateRule { - - public enum RuleType {VARIABLE, BEGIN_OPTIONAL, END_OPTIONAL}; - - RuleType type; - String original = null; - String name; - String example = null; - String match = null; - - static final Pattern SPLIT_REGEX = Pattern.compile("[^\\\\];"); - private static final String EXAMPLE_KEYWORD = "example"; - private static final String NAME_KEYWORD = "name"; - private static final String ORIGINAL_KEYWORD = "original"; - private static final String MATCH_KEYWORD = "match"; - private static final String VARIABLE_RULE_TYPE_STR = "var"; - private static final String BEGIN_OPTIONAL_TYPE_STR = "beginOptional"; - private static final String END_OPTIONAL_TYPE_STR = "endOptional"; - private static final String VALUE_SEPARATOR = "="; - - /** - * Create a new LicenseTemplateRule - * @param name Name of the rule - must not be null - * @param type - type of rule - * @param original - Original text - must not be null - * @param example - Example text - may be null - * @throws LicenseTemplateRuleException - */ - public LicenseTemplateRule(String name, RuleType type, String original, String match, String example) throws LicenseTemplateRuleException { - this.type = type; - this.original = formatValue(original); - this.name = name; - this.example = formatValue(example); - this.match = match; - validate(); - } - - @Override - public String toString() { - if (RuleType.VARIABLE.equals(this.type)) { - String myName = name; - if (myName == null) { - myName = ""; - } - return "var: "+myName; - } else if (RuleType.BEGIN_OPTIONAL.equals(this.type)) { - return "beginOptional"; - } else if (RuleType.END_OPTIONAL.equals(this.type)) { - return "endOptional"; - } else { - return "Unknown"; - } - } - - /** - * Validates that the LicenseTemplateRule is properly initialized - * @throws LicenseTemplateRuleException - */ - public void validate() throws LicenseTemplateRuleException { - if (this.type == null) { - throw new LicenseTemplateRuleException("Rule type can not be null."); - } - if (this.type == RuleType.VARIABLE && this.name == null) { - throw new LicenseTemplateRuleException("Rule name can not be null for a variable or alt rule."); - } - if (this.type == RuleType.VARIABLE && this.original == null) { - throw new LicenseTemplateRuleException("Rule original text can not be null."); - } - if (this.type == RuleType.VARIABLE && this.match == null) { - throw new LicenseTemplateRuleException("Rule match regular expression can not be null."); - } - } - - /** - * Create a new License Template Rule by parsing a rule string compliant with the SPDX - * License Template text - * @param parseableLicenseTemplateRule - * @throws LicenseTemplateRuleException - */ - public LicenseTemplateRule(String parseableLicenseTemplateRule) throws LicenseTemplateRuleException { - parseLicenseTemplateRule(parseableLicenseTemplateRule); - validate(); - } - - /** - * @param ruleName - * @param ruleType - * @throws LicenseTemplateRuleException - */ - public LicenseTemplateRule(String ruleName, RuleType ruleType) throws LicenseTemplateRuleException { - this.name = ruleName; - this.type = ruleType; - validate(); - } - - /** - * Parse a license template rule string compliant with the SPDX license template text and - * replace all properties with the parsed values - * @param parseableLicenseTemplateRule - * @throws LicenseTemplateRuleException - */ - public void parseLicenseTemplateRule(String parseableLicenseTemplateRule) throws LicenseTemplateRuleException { - //TODO: Check for repeated keywords - this.example = null; - this.name = null; - this.original = null; - this.type = null; - this.match = null; - Matcher rulePartMatcher = SPLIT_REGEX.matcher(parseableLicenseTemplateRule); - int start = 0; - // parse out the first field - should be the rule type - String typeStr = null; - if (rulePartMatcher.find()) { - typeStr = parseableLicenseTemplateRule.substring(start, rulePartMatcher.start()+1).trim(); - start = rulePartMatcher.end(); - } else { - typeStr = parseableLicenseTemplateRule.trim(); - start = parseableLicenseTemplateRule.length(); - } - this.type = typeStringToType(typeStr); - - // parse out remaining fields - while (rulePartMatcher.find()) { - String rulePart = parseableLicenseTemplateRule.substring(start, rulePartMatcher.start()+1); - parseRulePart(rulePart.trim()); - start = rulePartMatcher.end(); - } - String remainingRuleString = parseableLicenseTemplateRule.substring(start).trim(); - if (!remainingRuleString.isEmpty()) { - parseRulePart(remainingRuleString); - } - validate(); - } - - /** - * @param typeStr - * @return - * @throws LicenseTemplateRuleException - */ - private RuleType typeStringToType(String typeStr) throws LicenseTemplateRuleException { - if (typeStr.equals(VARIABLE_RULE_TYPE_STR)) { - return RuleType.VARIABLE; - } else if (typeStr.equals(BEGIN_OPTIONAL_TYPE_STR)) { - return RuleType.BEGIN_OPTIONAL; - } else if (typeStr.equals(END_OPTIONAL_TYPE_STR)) { - return RuleType.END_OPTIONAL; - } else { - throw new LicenseTemplateRuleException("Unknown rule type: "+typeStr); - } - } - - public RuleType getType() { - return type; - } - - /** - * @param type the type to set - */ - public void setType(RuleType type) { - this.type = type; - } - - /** - * @return the original - */ - public String getOriginal() { - return original; - } - - /** - * @param original the original to set - */ - public void setOriginal(String original) { - this.original = original; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the example - */ - public String getExample() { - return example; - } - - /** - * @param example the example to set - */ - public void setExample(String example) { - this.example = example; - } - - /** - * @return the match - */ - public String getMatch() { - return match; - } - - /** - * @param match the match to set - */ - public void setMatch(String match) { - this.match = match; - } - - /** - * Parse the part of a rule and stores the result as a property - * @param rulePart - * @throws LicenseTemplateRuleException - */ - private void parseRulePart(String rulePart) throws LicenseTemplateRuleException { - if (rulePart.startsWith(EXAMPLE_KEYWORD)) { - String value = getValue(rulePart, EXAMPLE_KEYWORD); - this.example = formatValue(value); - } else if (rulePart.startsWith(NAME_KEYWORD)) { - this.name = getValue(rulePart, NAME_KEYWORD); - } else if (rulePart.startsWith(ORIGINAL_KEYWORD)) { - String value = getValue(rulePart, ORIGINAL_KEYWORD); - this.original = formatValue(value); - } else if (rulePart.startsWith(MATCH_KEYWORD)) { - this.match = getValue(rulePart, MATCH_KEYWORD); - } else { - throw new LicenseTemplateRuleException("Unknown rule keyword: "+rulePart); - } - } - - /** - * Formats the string interpreting escape characters - * @param value - * @return - */ - private String formatValue(String value) { - String retval = value.replace("\\n", "\n"); - retval = retval.replace("\\t", "\t"); - return retval; - } - - /** - * Retrieve the value portion of a rule part - * @param rulePart - * @param keyword - * @return - * @throws LicenseTemplateRuleException - */ - private String getValue(String rulePart, String keyword) throws LicenseTemplateRuleException { - String retval = rulePart.substring(keyword.length()); - retval = retval.trim(); - if (!retval.startsWith(VALUE_SEPARATOR)) { - throw new LicenseTemplateRuleException("Missing "+VALUE_SEPARATOR+" for "+keyword); - } - retval = retval.substring(1).trim(); - if (retval.startsWith("\"")) { - retval = retval.substring(1); - } - if (retval.endsWith("\"")) { - retval = retval.substring(0, retval.length()-1); - } - return retval; - } - -} diff --git a/src/main/java/org/spdx/licenseTemplate/LicenseTemplateRuleException.java b/src/main/java/org/spdx/licenseTemplate/LicenseTemplateRuleException.java deleted file mode 100644 index e9b4ec2f0..000000000 --- a/src/main/java/org/spdx/licenseTemplate/LicenseTemplateRuleException.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -/** - * Exception for license template rules - * @author Gary O'Neall - * - */ -public class LicenseTemplateRuleException extends Exception { - /** - * - */ - private static final long serialVersionUID = 1L; - - public LicenseTemplateRuleException(String msg) { - super(msg); - } - - public LicenseTemplateRuleException(String msg, Throwable inner) { - super(msg, inner); - } -} diff --git a/src/main/java/org/spdx/licenseTemplate/SpdxLicenseTemplateHelper.java b/src/main/java/org/spdx/licenseTemplate/SpdxLicenseTemplateHelper.java deleted file mode 100644 index 94743420a..000000000 --- a/src/main/java/org/spdx/licenseTemplate/SpdxLicenseTemplateHelper.java +++ /dev/null @@ -1,276 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.StringEscapeUtils; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; - -/** - * Implements common conversion methods for processing SPDX license templates - * - * @author Gary O'Neall - * - */ -public class SpdxLicenseTemplateHelper { - - static final String START_RULE = "<<"; - static final String END_RULE = ">>"; - public static final Pattern RULE_PATTERN = Pattern.compile(START_RULE + "\\s*(beginOptional|endOptional|var)"); - public static final Pattern END_RULE_PATTERN = Pattern.compile(END_RULE); - private static final int SPACES_PER_TAB = 5; - private static final int MAX_TABS = 4; - private static final int[] PIXELS_PER_TAB = new int[] { 20, 40, 60, 70 }; - - /** - * Parses the license template calling the templateOutputHandler for any text - * and rules found - * - * @param licenseTemplate License template to be parsed - * @param templateOutputHandler Handles the text, optional text, and variable - * rules text found - * @throws LicenseTemplateRuleException - * @throws LicenseParserException - */ - public static void parseTemplate(String licenseTemplate, ILicenseTemplateOutputHandler templateOutputHandler) - throws LicenseTemplateRuleException, LicenseParserException { - Matcher ruleMatcher = RULE_PATTERN.matcher(licenseTemplate); - Matcher endRuleMatcher = END_RULE_PATTERN.matcher(licenseTemplate); - int end = 0; - int optionalNestLevel = 0; - int start = 0; - while (ruleMatcher.find(start)) { - // copy everything up to the start of the find - String upToTheFind = licenseTemplate.substring(end, ruleMatcher.start()); - if (!upToTheFind.trim().isEmpty()) { - templateOutputHandler.text(upToTheFind); - } - if (!endRuleMatcher.find(ruleMatcher.end())) { - throw (new LicenseTemplateRuleException("Missing end of rule '>>' after text '" + upToTheFind + "'")); - } - end = endRuleMatcher.end(); - String ruleString = licenseTemplate.substring(ruleMatcher.start() + START_RULE.length(), end - END_RULE.length()); - start = end; - - LicenseTemplateRule rule = new LicenseTemplateRule(ruleString); - if (rule.getType() == LicenseTemplateRule.RuleType.VARIABLE) { - templateOutputHandler.variableRule(rule); - } else if (rule.getType() == LicenseTemplateRule.RuleType.BEGIN_OPTIONAL) { - templateOutputHandler.beginOptional(rule); - optionalNestLevel++; - } else if (rule.getType() == LicenseTemplateRule.RuleType.END_OPTIONAL) { - optionalNestLevel--; - if (optionalNestLevel < 0) { - throw (new LicenseTemplateRuleException( - "End optional rule found without a matching begin optional rule after text '" + upToTheFind + "'")); - } - templateOutputHandler.endOptional(rule); - } else { - throw (new LicenseTemplateRuleException( - "Unrecognized rule: " + rule.getType().toString() + " after text '" + upToTheFind + "'")); - } - } - if (optionalNestLevel > 0) { - throw (new LicenseTemplateRuleException("Missing EndOptional rule and end of text")); - } - // copy the rest of the template to the end - String restOfTemplate = licenseTemplate.substring(end); - if (!restOfTemplate.isEmpty()) { - templateOutputHandler.text(restOfTemplate); - } - templateOutputHandler.completeParsing(); - } - - /** - * Converts a license template string to formatted HTML which highlights any - * rules or tags - * - * @param licenseTemplate - * @return - * @throws LicenseTemplateRuleException - */ - public static String templateTextToHtml(String licenseTemplate) throws LicenseTemplateRuleException { - HtmlTemplateOutputHandler htmlOutput = new HtmlTemplateOutputHandler(); - try { - parseTemplate(licenseTemplate, htmlOutput); - } catch (LicenseParserException e) { - throw new LicenseTemplateRuleException("Parsing error parsing license template", e); - } - return htmlOutput.getHtml(); - } - - /** - * Converts template text to standard default text using any default parameters - * in the rules - * - * @param template - * @return - * @throws LicenseTemplateRuleException - */ - public static String templateToText(String template) throws LicenseTemplateRuleException { - TextTemplateOutputHandler textOutput = new TextTemplateOutputHandler(); - try { - parseTemplate(template, textOutput); - } catch (LicenseParserException e) { - throw new LicenseTemplateRuleException("Parsing error parsing license template", e); - } - return textOutput.getText(); - } - - /** - * Escapes and formats text - * - * @param text unformatted text - * @return - */ - public static String formatEscapeHTML(String text) { - return formatEscapeHTML(text, false); - } - - /** - * Escapes and formats text - * - * @param text unformatted text - * @param inParagraph true if inside a paragraph tag - * @return - */ - public static String formatEscapeHTML(String text, boolean inParagraph) { - String retval = StringEscapeUtils.escapeXml11(text); - return addHtmlFormatting(retval, inParagraph); - } - - /** - * Adds HTML formatting {@code
- * } and {@code - *

- * } - * - * @param text unformatted text - * @return - */ - public static String addHtmlFormatting(String text) { - return addHtmlFormatting(text, false); - } - - /** - * Adds HTML formatting {@code
- * } and {@code - *

- * } - * - * @param text unformatted text - * @param inParagraph true if inside a paragraph tag - * @return - */ - public static String addHtmlFormatting(String text, boolean inParagraph) { - String[] lines = text.split("\n"); - StringBuilder result = new StringBuilder(); - result.append(lines[0]); - int i = 1; - while (i < lines.length) { - if (lines[i].trim().isEmpty()) { - // paragraph boundary - if (inParagraph) { - result.append("

"); - } - result.append("\n"); - i++; - if (i < lines.length) { - String paragraphTag = getParagraphTagConsideringTags(lines[i]); - result.append(paragraphTag); - result.append(lines[i++]); - } else { - result.append("

"); - } - inParagraph = true; - } else { - // just a line break - result.append("
"); - result.append("\n"); - result.append(lines[i++]); - } - } - if (inParagraph) { - result.append("

"); - } else if (text.endsWith("\n")) { - result.append("
\n"); - } - return result.toString(); - } - - /** - * Creating a paragraph tag and add the correct margin considering the number of - * spaces or tabs - * - * @param string - * @return - */ - private static String getParagraphTagConsideringTags(String line) { - int numSpaces = countLeadingSpaces(line); - StringBuilder result = new StringBuilder(); - if (numSpaces >= SPACES_PER_TAB) { - int numTabs = numSpaces / SPACES_PER_TAB; - if (numTabs > MAX_TABS) { - numTabs = MAX_TABS; - } - - int pixels = PIXELS_PER_TAB[numTabs - 1]; - result.append("

"); - } else { - result.append("

"); - } - return result.toString(); - } - - /** - * Counts the number of leading spaces in a given line - * - * @param string - * @return - */ - private static int countLeadingSpaces(String string) { - char[] charArray = string.toCharArray(); - int retval = 0; - while (retval < charArray.length && charArray[retval] == ' ') { - retval++; - } - return retval; - } - - /** - * Converts an HTML string to text preserving line breaks for {@code
- * } tags - * - * @param html - * @return - */ - public static String htmlToText(String html) { - String newlineString = "NewLineGoesHere"; - String replaceBrs = html.replaceAll("(?i)]*>", newlineString); - String replaceBrsAndPs = replaceBrs.replaceAll("(?i)]*>", newlineString); - Document doc = Jsoup.parse(replaceBrsAndPs); - String retval = doc.text(); - retval = retval.replace(newlineString, "\n"); - return retval; - } - -} diff --git a/src/main/java/org/spdx/licenseTemplate/TextTemplateOutputHandler.java b/src/main/java/org/spdx/licenseTemplate/TextTemplateOutputHandler.java deleted file mode 100644 index 3c1b7d3db..000000000 --- a/src/main/java/org/spdx/licenseTemplate/TextTemplateOutputHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -/** - * License template output handler for generating a text version of a license from a license template. - * Used when parsing a license template. - * @author Gary O'Neall - * - */ -public class TextTemplateOutputHandler implements ILicenseTemplateOutputHandler { - - StringBuilder textString = new StringBuilder(); - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#text(java.lang.String) - */ - @Override - public void text(String text) { - textString.append(text); - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#variableRule(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void variableRule(LicenseTemplateRule rule) { - textString.append(rule.getOriginal()); - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void beginOptional(LicenseTemplateRule rule) { - // ignore - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#endOptional(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void endOptional(LicenseTemplateRule rule) { - // ignore - } - - public String getText() { - return this.textString.toString(); - } - - @Override - public void completeParsing() { - // // Nothing needs to be done - everything is processed inline - - } -} diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index b6f85ea0f..080a11ffa 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -420,15 +420,15 @@ public IdType getIdType(String id) { return IdType.Anonymous; } if (id.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM) | - id.contains("#" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { + id.contains(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { return IdType.LicenseRef; } if (id.startsWith(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM) | - id.contains("#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { + id.contains(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM)) { return IdType.DocumentRef; } if (id.startsWith(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM) | - id.contains("#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { + id.contains(SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM)) { return IdType.SpdxId; } if (id.contains("://spdx.org/licenses/") || LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) { diff --git a/src/test/java/org/spdx/library/ModelCopyManagerTest.java b/src/test/java/org/spdx/library/ModelCopyManagerTest.java new file mode 100644 index 000000000..b00f68cde --- /dev/null +++ b/src/test/java/org/spdx/library/ModelCopyManagerTest.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import static org.junit.Assert.*; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Objects; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.library.model.v3.core.Hash; +import org.spdx.library.model.v3.core.HashAlgorithm; +import org.spdx.library.model.v3.core.Relationship; +import org.spdx.library.model.v3.core.RelationshipType; +import org.spdx.library.model.v3.core.SpdxDocument; +import org.spdx.library.model.v3.software.SpdxFile; +import org.spdx.library.model.v3.software.SpdxPackage; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.simple.InMemSpdxStore; + +/** + * @author Gary O'Neall + * + */ +public class ModelCopyManagerTest { + + private static final String HASH_OBJECT_URI = "http://something#SPDXRef-15"; + private static final String OBJECT_URI2 = "urn:object.uri.two"; + private static final String HASH_TYPE = "Core.Hash"; + private static final String NAMESPACE = "urn:namespace."; + private static final HashAlgorithm HASH_ALGORITHM = HashAlgorithm.MD5; + private static final String HASH_VALUE = "asfd1231"; + private ModelCopyManager modelCopyManager; + private InMemSpdxStore fromStore; + private InMemSpdxStore toStore; + private Hash hash; + String date; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + SpdxModelFactory.init(); + modelCopyManager = new ModelCopyManager(); + fromStore = new InMemSpdxStore(); + toStore = new InMemSpdxStore(); + hash = (Hash)SpdxModelFactory.inflateModelObject(fromStore, HASH_OBJECT_URI, HASH_TYPE, modelCopyManager, "3.0.0", true); + hash.setAlgorithm(HASH_ALGORITHM); + hash.setHashValue(HASH_VALUE); + DateFormat format = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT); + date = format.format(new Date()); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link org.spdx.library.ModelCopyManager#getCopiedObjectUri(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.IModelStore)}. + */ + @Test + public void testGetCopiedObjectUri() { + assertTrue(Objects.isNull(modelCopyManager.getCopiedObjectUri(fromStore, HASH_OBJECT_URI, toStore))); + assertTrue(Objects.isNull(modelCopyManager.putCopiedId(fromStore, HASH_OBJECT_URI, toStore, OBJECT_URI2))); + assertEquals(OBJECT_URI2, (modelCopyManager.getCopiedObjectUri(fromStore, HASH_OBJECT_URI, toStore))); + } + + /** + * Test method for {@link org.spdx.library.ModelCopyManager#copy(org.spdx.storage.IModelStore, org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. + * @throws InvalidSPDXAnalysisException + */ + @Test + public void testCopyIModelStoreIModelStoreStringStringStringString() throws InvalidSPDXAnalysisException { + modelCopyManager.copy(toStore, OBJECT_URI2, fromStore, HASH_OBJECT_URI, HASH_TYPE, "3.0.0", NAMESPACE); + assertEquals(OBJECT_URI2, (modelCopyManager.getCopiedObjectUri(fromStore, HASH_OBJECT_URI, toStore))); + Hash copiedHash = (Hash)SpdxModelFactory.inflateModelObject(toStore, OBJECT_URI2, HASH_TYPE, modelCopyManager, "3.0.0", false); + assertTrue(hash.equivalent(copiedHash)); + assertEquals(HASH_ALGORITHM, copiedHash.getAlgorithm()); + assertEquals(HASH_VALUE, copiedHash.getHashValue()); + } + + @Test + public void testDeepComplexCopy() throws InvalidSPDXAnalysisException { + CreationInfo creationInfo = hash.createCreationInfo(fromStore.getNextId(IdType.Anonymous)) + .setCreated(date) + .setSpecVersion("3.0.0") + .build(); + Agent agent = hash.createAgent(fromStore.getNextId(IdType.SpdxId)) + .setCreationInfo(creationInfo) + .setName("Name") + .build(); + creationInfo.getCreatedBys().add(agent); + agent.setCreationInfo(creationInfo); + SpdxFile spdxFile = agent.createSpdxFile(fromStore.getNextId(IdType.SpdxId)) + .setName("fileName") + .setCopyrightText("copyrightText") + .addVerifiedUsing(hash) + .build(); + SpdxPackage pkg = spdxFile.createSpdxPackage(fromStore.getNextId(IdType.SpdxId)) + .setName("packageName") + .setBuiltTime(date) + .build(); + Relationship rel = pkg.createRelationship(fromStore.getNextId(IdType.SpdxId)) + .setComment("relationship comment") + .setFrom(pkg) + .addTo(spdxFile) + .setRelationshipType(RelationshipType.CONTAINS) + .build(); + SpdxDocument doc = pkg.createSpdxDocument(fromStore.getNextId(IdType.SpdxId)) + .setName("SPDX Document") + .addElement(agent) + .addElement(spdxFile) + .addElement(pkg) + .addElement(rel) + .build(); + TypedValue result = modelCopyManager.copy(toStore, fromStore, doc.getObjectUri(), doc.getType(), "3.0.0", NAMESPACE); + assertEquals(doc.getObjectUri(), result.getObjectUri()); + assertEquals(doc.getType(), result.getType()); + assertEquals("3.0.0", result.getSpecVersion()); + SpdxDocument copiedDoc = (SpdxDocument)SpdxModelFactory.inflateModelObject(toStore, result.getObjectUri(), result.getType(), modelCopyManager, "3.0.0", false); + assertTrue(copiedDoc.equivalent(doc)); + + } + + /** + * Test method for {@link org.spdx.library.ModelCopyManager#copy(org.spdx.storage.IModelStore, java.lang.String, org.spdx.storage.IModelStore, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. + * @throws InvalidSPDXAnalysisException + */ + @Test + public void testCopyIModelStoreStringIModelStoreStringStringStringString() throws InvalidSPDXAnalysisException { + // URI does not exist + TypedValue result = modelCopyManager.copy(toStore, fromStore, HASH_OBJECT_URI, HASH_TYPE, "3.0.0", NAMESPACE); + Hash copiedHash = (Hash)SpdxModelFactory.inflateModelObject(toStore, HASH_OBJECT_URI, HASH_TYPE, modelCopyManager, "3.0.0", false); + assertTrue(hash.equivalent(copiedHash)); + assertEquals(HASH_ALGORITHM, copiedHash.getAlgorithm()); + assertEquals(HASH_VALUE, copiedHash.getHashValue()); + assertEquals(HASH_TYPE, result.getType()); + assertEquals(HASH_OBJECT_URI, result.getObjectUri()); + assertEquals("3.0.0", result.getSpecVersion()); + // Anonymous fromUri + String differentUri = fromStore.getNextId(IdType.Anonymous); + Hash differentHash = (Hash)SpdxModelFactory.inflateModelObject(fromStore, differentUri, HASH_TYPE, modelCopyManager, "3.0.0", true); + differentHash.setAlgorithm(HashAlgorithm.BLAKE2B256); + differentHash.setHashValue("asasdf1309u93u"); + result = modelCopyManager.copy(toStore, fromStore, differentUri, HASH_TYPE, "3.0.0", NAMESPACE); + assertEquals(IdType.Anonymous, toStore.getIdType(result.getObjectUri())); + assertEquals(HASH_TYPE, result.getType()); + assertEquals(HASH_TYPE, result.getType());assertEquals("3.0.0", result.getSpecVersion()); + Hash differentCopiedHash = (Hash)SpdxModelFactory.inflateModelObject(toStore, result.getObjectUri(), HASH_TYPE, modelCopyManager, "3.0.0", true); + assertTrue(differentHash.equivalent(differentCopiedHash)); + } + + @Test + public void testCopyToExistingUri() throws InvalidSPDXAnalysisException { + String differentUri = "http://prefix/something#"+fromStore.getNextId(IdType.SpdxId); + modelCopyManager.copy(toStore, differentUri, fromStore, HASH_OBJECT_URI, HASH_TYPE, "3.0.0", NAMESPACE); + Hash differentHash = (Hash)SpdxModelFactory.inflateModelObject(fromStore, differentUri, HASH_TYPE, modelCopyManager, "3.0.0", true); + differentHash.setAlgorithm(HashAlgorithm.BLAKE2B256); + differentHash.setHashValue("asasdf1309u93u"); + TypedValue result = modelCopyManager.copy(toStore, fromStore, differentUri, HASH_TYPE, "3.0.0", NAMESPACE); + assertEquals(IdType.SpdxId, toStore.getIdType(result.getObjectUri())); + assertTrue(result.getObjectUri().startsWith(NAMESPACE)); + assertEquals(HASH_TYPE, result.getType()); + assertEquals(HASH_TYPE, result.getType());assertEquals("3.0.0", result.getSpecVersion()); + Hash differentCopiedHash = (Hash)SpdxModelFactory.inflateModelObject(toStore, result.getObjectUri(), HASH_TYPE, modelCopyManager, "3.0.0", true); + assertTrue(differentHash.equivalent(differentCopiedHash)); + } + +} diff --git a/src/test/java/org/spdx/library/SpdxModelFactoryTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java similarity index 98% rename from src/test/java/org/spdx/library/SpdxModelFactoryTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java index 964195e4f..da37db37b 100644 --- a/src/test/java/org/spdx/library/SpdxModelFactoryTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxModelFactoryTest.java @@ -1,8 +1,9 @@ -package org.spdx.library; +package org.spdx.library.model.compat.v2; import java.util.Optional; import java.util.stream.Stream; +import org.spdx.library.ModelCopyManager; import org.spdx.library.SpdxConstants.SpdxMajorVersion; import org.spdx.library.model.compat.v2.Annotation; import org.spdx.library.model.compat.v2.Checksum; diff --git a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java b/src/test/java/org/spdx/library/model/compat/v2/SpdxVerificationHelperTest.java similarity index 99% rename from src/test/java/org/spdx/library/SpdxVerificationHelperTest.java rename to src/test/java/org/spdx/library/model/compat/v2/SpdxVerificationHelperTest.java index ff101ff7b..a2c9bcacc 100644 --- a/src/test/java/org/spdx/library/SpdxVerificationHelperTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/SpdxVerificationHelperTest.java @@ -15,13 +15,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.spdx.library; +package org.spdx.library.model.compat.v2; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Objects; +import org.spdx.library.Version; import org.spdx.library.model.compat.v2.enumerations.ChecksumAlgorithm; import junit.framework.TestCase; diff --git a/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java b/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java deleted file mode 100644 index f8b92072c..000000000 --- a/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType; - -/** - * @author Source Auditor - * - */ -public class TestHtmlTemplateOutputHandler { - - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#normalText(java.lang.String)}. - */ - @Test - public void testNormalText() { - String normalText = "normal text\t\nwith spec chars>"; - String escapedNormalText = "normal text\t
\nwith spec chars>"; - HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); - htoh.text(normalText); - assertEquals(escapedNormalText,htoh.getHtml()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#variableRule(org.spdx.licenseTemplate.LicenseTemplateRule)}. - */ - @Test - public void testVariableRule() throws LicenseTemplateRuleException { - String ruleName = "testRule"; - String originalText = "Original \\ntext"; - String compareOriginalText = "Original
\ntext"; - String matchText = "match text"; - String exampleText = "Example \\n text"; - LicenseTemplateRule normalRule = new LicenseTemplateRule(ruleName, RuleType.VARIABLE, - originalText, matchText, exampleText); - String expectedResult = "\n" + compareOriginalText + - "\n"; - HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); - htoh.variableRule(normalRule); - assertEquals(expectedResult, htoh.getHtml()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#formatReplaceabledHTML(java.lang.String, java.lang.String)}. - */ - @Test - public void testFormatReplaceabledHTML() { - String originalText = "Original \ntext"; - String compareOriginalText = "Original
\ntext"; - String ruleName = "testRule"; - String expectedResult = "\n" + compareOriginalText + - "\n"; - String result = HtmlTemplateOutputHandler.formatReplaceabledHTML(originalText, ruleName); - assertEquals(expectedResult, result); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#escapeIdString(java.lang.String)}. - */ - @Test - public void testEscapeIdString() { - // not starting with letter - String testId = "1test"; - assertEquals("X"+testId, HtmlTemplateOutputHandler.escapeIdString(testId)); - // invalid character - String invalidChar = "idWith:Invalid"; - String validChar = "idWith_Invalid"; - assertEquals(validChar, HtmlTemplateOutputHandler.escapeIdString(invalidChar)); - String allValid = "iDwith0-.valid"; - assertEquals(allValid, HtmlTemplateOutputHandler.escapeIdString(allValid)); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#getHtml()}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testGetHtml() throws LicenseTemplateRuleException { - HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); - String beginText = "Begin text\n"; - String escapedBeginText = "Begin text
\n"; - htoh.text(beginText); - - String optRuleName = "optionalRule"; - - LicenseTemplateRule beginRule = new LicenseTemplateRule(optRuleName, RuleType.BEGIN_OPTIONAL); - htoh.beginOptional(beginRule); - String optionalText = "Optional Text"; - htoh.text(optionalText); - String escapedBeginRuleText = "\n

\n"; - String escapedOptionalText = optionalText; - - String varRuleName = "testRule"; - String originalText = "Original \\ntext"; - String compareOriginalText = "Original
\ntext"; - String matchText = "match text"; - String exampleText = "Example \\n text"; - LicenseTemplateRule normalRule = new LicenseTemplateRule(varRuleName, RuleType.VARIABLE, - originalText, matchText, exampleText); - String escapedVariableRuleText = "\n" + compareOriginalText + - "\n"; - htoh.variableRule(normalRule); - LicenseTemplateRule endRule = new LicenseTemplateRule(optRuleName, RuleType.END_OPTIONAL); - htoh.endOptional(endRule); - String escapedEndRuleText = "
\n"; - - String lastLine = "\nLast Line.&"; - htoh.text(lastLine); - String escapedLastLine = "
\nLast Line.&"; - - String expectedValue = escapedBeginText +escapedBeginRuleText+escapedOptionalText+ - escapedVariableRuleText+escapedEndRuleText+escapedLastLine; - - assertEquals(expectedValue, htoh.getHtml()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testBeginOptional() throws LicenseTemplateRuleException { - HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); - String optRuleName = "optionalRule"; - - LicenseTemplateRule beginRule = new LicenseTemplateRule(optRuleName, RuleType.BEGIN_OPTIONAL); - htoh.beginOptional(beginRule); - String escapedBeginRuleText = "\n
\n"; - assertEquals(escapedBeginRuleText, htoh.getHtml()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#formatStartOptionalHTML(java.lang.String)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testFormatStartOptionalHTML() throws LicenseTemplateRuleException { - String optRuleName = "optionalRule"; - String escapedBeginRuleText = "\n
\n"; - assertEquals(escapedBeginRuleText, HtmlTemplateOutputHandler.formatStartOptionalHTML(optRuleName)); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#formatEndOptionalHTML()}. - */ - @Test - public void testFormatEndOptionalHTML() { - String escapedEndRuleText = "
\n"; - assertEquals(escapedEndRuleText, HtmlTemplateOutputHandler.formatEndOptionalHTML(false)); - - } - - /** - * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#endOptional(org.spdx.licenseTemplate.LicenseTemplateRule)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testEndOptional() throws LicenseTemplateRuleException { - HtmlTemplateOutputHandler htoh = new HtmlTemplateOutputHandler(); - String optRuleName = "optionalRule"; - - LicenseTemplateRule beginRule = new LicenseTemplateRule(optRuleName, RuleType.BEGIN_OPTIONAL); - htoh.beginOptional(beginRule); - - LicenseTemplateRule endRule = new LicenseTemplateRule(optRuleName, RuleType.END_OPTIONAL); - htoh.endOptional(endRule); - String escapedEndRuleText = "
\n"; - assertTrue(htoh.getHtml().endsWith(escapedEndRuleText)); - - } - -} diff --git a/src/test/java/org/spdx/licenseTemplate/TestLicenseTemplateRule.java b/src/test/java/org/spdx/licenseTemplate/TestLicenseTemplateRule.java deleted file mode 100644 index 23639d215..000000000 --- a/src/test/java/org/spdx/licenseTemplate/TestLicenseTemplateRule.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType; - -/** - * @author Source Auditor - * - */ -public class TestLicenseTemplateRule { - - static final String PARSEABLE_RULE = "var;original=Copyright (c) \\nAll rights reserved.;match=Copyright \\(c\\) .+All rights reserved.;name=copyright;example=Copyright (C) 2013 John Doe\\nAll rights reserved.\n"; - static final String RULE_NAME = "copyright"; - static final RuleType RULE_TYPE = RuleType.VARIABLE; - static final String RULE_ORIGINAL = "Copyright (c) \nAll rights reserved."; - static final String RULE_MATCH = "Copyright \\(c\\) .+All rights reserved."; - static final String RULE_EXAMPLE = "Copyright (C) 2013 John Doe\nAll rights reserved."; - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - - @Test - public void testparseLicenseTemplateRule() throws LicenseTemplateRuleException { - LicenseTemplateRule rule = new LicenseTemplateRule("Name", RuleType.BEGIN_OPTIONAL, "original", "match", "example"); - rule.parseLicenseTemplateRule(PARSEABLE_RULE); - assertEquals(rule.getExample(), RULE_EXAMPLE); - assertEquals(rule.getName(), RULE_NAME); - assertEquals(rule.getOriginal(), RULE_ORIGINAL); - assertEquals(rule.getType(), RULE_TYPE); - assertEquals(rule.getMatch(), RULE_MATCH); - } - - @Test - public void testBeginOptionalRule() throws LicenseTemplateRuleException { - String ruleName = "optionalName"; - String ruleStr = "beginOptional;name="+ruleName; - LicenseTemplateRule rule = new LicenseTemplateRule(ruleStr); - assertEquals(RuleType.BEGIN_OPTIONAL, rule.getType()); - assertEquals(ruleName, rule.getName()); - } - - @Test - public void testEndOptionalRule() throws LicenseTemplateRuleException { - String ruleStr = "endOptional"; - LicenseTemplateRule rule = new LicenseTemplateRule(ruleStr); - assertEquals(RuleType.END_OPTIONAL, rule.getType()); - } -} diff --git a/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java b/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java deleted file mode 100644 index 5d80ad09f..000000000 --- a/src/test/java/org/spdx/licenseTemplate/TestSpdxLicenseTemplateHelper.java +++ /dev/null @@ -1,224 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType; - -/** - * @author Gary O'Neall - * - */ -public class TestSpdxLicenseTemplateHelper { - - String optionalTextString; - String normalTextString; - LicenseTemplateRule variableRule; - LicenseTemplateRule optionalRule; - LicenseTemplateRule endOptionalRule; - - public class TestLicenseTemplateOutputHandler implements ILicenseTemplateOutputHandler { - - int optionalNestLevel = 0; - - public TestLicenseTemplateOutputHandler() { - optionalTextString = null; - normalTextString = null; - variableRule = null; - optionalRule = null; - endOptionalRule = null; - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#text(java.lang.String) - */ - @Override - public void text(String text) { - if (optionalNestLevel > 0) { - optionalTextString = text; - } else { - normalTextString = text; - } - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#variableRule(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void variableRule(LicenseTemplateRule rule) { - variableRule = rule; - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void beginOptional(LicenseTemplateRule rule) { - optionalRule = rule; - this.optionalNestLevel++; - } - - /* (non-Javadoc) - * @see org.spdx.licenseTemplate.ILicenseTemplateOutputHandler#endOptional(org.spdx.licenseTemplate.LicenseTemplateRule) - */ - @Override - public void endOptional(LicenseTemplateRule rule) { - endOptionalRule = rule; - this.optionalNestLevel--; - } - - @Override - public void completeParsing() { - // // Nothing needs to be done - everything is processed inline - - } - - } - - static final String LINE1 = "This is the start of the license.\n"; - static final String REQUIRED_RULE="< \\nAll rights reserved.;match=Copyright \\(c\\) .+All rights reserved.;name=copyright;example=Copyright (C) 2013 John Doe\\nAll rights reserved.>>"; - static final String LINE2 = "\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met"; - static final String OPTIONAL_RULE="<>Original Text<>"; - static final String LINE3="\nLast line of the license"; - static final String TEMPLATE_TEXT = LINE1+REQUIRED_RULE+LINE2+OPTIONAL_RULE+LINE3; - - static final String HTML_COPYRIGHT="\nCopyright (c) <year> <owner>
\nAll rights reserved.
\n"; - static final String HTML_OPTIONAL_RULE="\n
\nOriginal Text
\n"; - static final String HTML_LICENSE = LINE1.replace("\n", "
\n")+ - HTML_COPYRIGHT+ - LINE2.replace("\n", "
\n")+ - HTML_OPTIONAL_RULE+ - LINE3.replace("\n", "
\n"); - - static final String TEXT_COPYRIGHT = "Copyright (c) \nAll rights reserved."; - static final String TEXT_OPTIONAL_RULE = "Original Text"; - static final String TEXT_LICENSE = LINE1+TEXT_COPYRIGHT+LINE2+TEXT_OPTIONAL_RULE+LINE3; - private static final Object PARSE_OPTIONAL_RULE_NAME = "OptionalRuleName"; - private static final Object PARSE_VARIABLE_RULE_NAME = "VariableRuleName"; - private static final Object PARSE_OPTIONAL_TEXT = "Optional Text"; - private static final Object PARSE_NORMAL_TEXT = "Normal Text"; - private static final String PARSE_TEXT_STRING = PARSE_NORMAL_TEXT + "<>"+ - "<>"+PARSE_OPTIONAL_TEXT+"<>"; - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - - /** - * Test method for {@link org.spdx.licenseTemplate.SpdxLicenseTemplateHelper#templateTextToHtml(java.lang.String)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testTemplateTextToHtml() throws LicenseTemplateRuleException { - String ret = SpdxLicenseTemplateHelper.templateTextToHtml(TEMPLATE_TEXT); - assertEquals(HTML_LICENSE, ret); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.SpdxLicenseTemplateHelper#templateToText(java.lang.String)}. - * @throws LicenseTemplateRuleException - * @throws LicenseParserException - */ - @Test - public void testTemplateToText() throws LicenseTemplateRuleException, LicenseParserException { - String ret = SpdxLicenseTemplateHelper.templateToText(TEMPLATE_TEXT); - assertEquals(TEXT_LICENSE, ret); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.SpdxLicenseTemplateHelper#formatEscapeHTML(java.lang.String)}. - */ - @Test - public void testEscapeHTML() { - String unEscaped = ""; - String escaped = "<abc
\nline2>"; - assertEquals(escaped, SpdxLicenseTemplateHelper.formatEscapeHTML(unEscaped)); - } - - @Test - public void testParseTemplate() throws LicenseTemplateRuleException, LicenseParserException { - String noText = ""; - TestLicenseTemplateOutputHandler handler = new TestLicenseTemplateOutputHandler(); - SpdxLicenseTemplateHelper.parseTemplate(noText, handler); - assertEquals(null, optionalTextString); - assertEquals(null, normalTextString); - assertEquals(null, variableRule); - assertEquals(null, optionalRule); - assertEquals(null, endOptionalRule); - - handler = new TestLicenseTemplateOutputHandler(); - SpdxLicenseTemplateHelper.parseTemplate(PARSE_TEXT_STRING, handler); - assertEquals(PARSE_NORMAL_TEXT, normalTextString); - assertEquals(PARSE_OPTIONAL_TEXT, optionalTextString); - assertEquals(PARSE_VARIABLE_RULE_NAME, variableRule.getName()); - assertEquals(RuleType.VARIABLE, variableRule.getType()); - assertEquals(PARSE_OPTIONAL_RULE_NAME, optionalRule.getName()); - assertEquals(RuleType.BEGIN_OPTIONAL, optionalRule.getType()); - assertEquals(RuleType.END_OPTIONAL, endOptionalRule.getType()); - } - - @Test - public void testAddHtmlFormatting() { - String noParagraphs = "lines1\nline2\nline3"; - String noParagraphsTagged = "lines1
\nline2
\nline3"; - assertEquals(noParagraphsTagged, SpdxLicenseTemplateHelper.addHtmlFormatting(noParagraphs)); - String empty = ""; - assertEquals(empty, SpdxLicenseTemplateHelper.addHtmlFormatting(empty)); - String oneLine = "one line"; - assertEquals(oneLine, SpdxLicenseTemplateHelper.addHtmlFormatting(oneLine)); - String paragraphs = "paragraph1\n\nparagraph2\n\nparagraph3"; - String paragraphsTagged = "paragraph1\n

paragraph2

\n

paragraph3

"; - assertEquals(paragraphsTagged, SpdxLicenseTemplateHelper.addHtmlFormatting(paragraphs)); - String tabbed = "paragraph1\n\n tabbed paragraph\n\nnormal paragraph"; - String tabbedTagged = "paragraph1\n

tabbed paragraph

\n

normal paragraph

"; - assertEquals(tabbedTagged, SpdxLicenseTemplateHelper.addHtmlFormatting(tabbed)); - String quadTabbed = "paragraph1\n\n tabbed paragraph\n\nnormal paragraph"; - String quadTabbedTagged = "paragraph1\n

tabbed paragraph

\n

normal paragraph

"; - assertEquals(quadTabbedTagged, SpdxLicenseTemplateHelper.addHtmlFormatting(quadTabbed)); - } -} diff --git a/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java b/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java deleted file mode 100644 index aa50a67b0..000000000 --- a/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright (c) 2013 Source Auditor Inc. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ -package org.spdx.licenseTemplate; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType; - -/** - * @author Source Auditor - * - */ -public class TestTextTemplateOutputHandler { - - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - - /** - * Test method for {@link org.spdx.licenseTemplate.TextTemplateOutputHandler#normalText(java.lang.String)}. - */ - @Test - public void testNormalText() { - String test = "test normal\n"; - TextTemplateOutputHandler oh = new TextTemplateOutputHandler(); - oh.text(test); - assertEquals(test, oh.getText()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.TextTemplateOutputHandler#variableRule(org.spdx.licenseTemplate.LicenseTemplateRule)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testVariableRule() throws LicenseTemplateRuleException { - String ruleName = "testRule"; - String originalText = "Original \\ntext"; - String compareOriginalText = "Original \ntext"; - String matchText = "match text"; - String exampleText = "Example \\n text"; - LicenseTemplateRule normalRule = new LicenseTemplateRule(ruleName, RuleType.VARIABLE, - originalText, matchText, exampleText); - TextTemplateOutputHandler oh = new TextTemplateOutputHandler(); - oh.variableRule(normalRule); - assertEquals(compareOriginalText, oh.getText()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.TextTemplateOutputHandler#beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testBeginOptional() throws LicenseTemplateRuleException { - String ruleName = "testRule"; - String originalText = "Original \\ntext"; - String matchText = "match text"; - String exampleText = "Example \\n text"; - LicenseTemplateRule normalRule = new LicenseTemplateRule(ruleName, RuleType.BEGIN_OPTIONAL, - originalText, matchText, exampleText); - TextTemplateOutputHandler oh = new TextTemplateOutputHandler(); - oh.beginOptional(normalRule); - assertEquals("", oh.getText()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.TextTemplateOutputHandler#endOptional(org.spdx.licenseTemplate.LicenseTemplateRule)}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testEndOptional() throws LicenseTemplateRuleException { - String ruleName = "testRule"; - String originalText = "Original \\ntext"; - String matchText = "match text"; - String exampleText = "Example \\n text"; - LicenseTemplateRule normalRule = new LicenseTemplateRule(ruleName, RuleType.END_OPTIONAL, - originalText, matchText, exampleText); - TextTemplateOutputHandler oh = new TextTemplateOutputHandler(); - oh.endOptional(normalRule); - assertEquals("", oh.getText()); - } - - /** - * Test method for {@link org.spdx.licenseTemplate.TextTemplateOutputHandler#getText()}. - * @throws LicenseTemplateRuleException - */ - @Test - public void testGetText() throws LicenseTemplateRuleException { - String normalText = "Normal text"; - TextTemplateOutputHandler oh = new TextTemplateOutputHandler(); - assertEquals("", oh.getText()); - String ruleName = "testRule"; - String originalText = "Original \\ntext"; - String matchText = "match text"; - String exampleText = "Example \\n text"; - LicenseTemplateRule beginRule = new LicenseTemplateRule(ruleName, RuleType.BEGIN_OPTIONAL, - originalText, matchText, exampleText); - LicenseTemplateRule endRule = new LicenseTemplateRule(ruleName, RuleType.END_OPTIONAL, - originalText, matchText, exampleText); - oh.beginOptional(beginRule); - oh.text(normalText); - oh.endOptional(endRule); - assertEquals(normalText, oh.getText()); - } - -} From bceae5706bfa123eb461c0afa1ffb8b2fcc7d059 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 22 May 2024 15:12:56 -0700 Subject: [PATCH 29/62] Add convenience methods for SPDX 2.X and SPDX 3.X Signed-off-by: Gary O'Neall --- README.md | 6 ++ .../model/v3/SpdxModelClassFactoryTest.java | 77 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/java/org/spdx/library/model/v3/SpdxModelClassFactoryTest.java diff --git a/README.md b/README.md index 67bea717b..849a2787e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ There are a couple of static classes that help common usage scenarios: The first thing that needs to be done in your implementation is call `SpdxModelFactory.init()` - this will load all the supported versions. +If you are programatically creating SPDX data, you will start by creating a model store. The simplest model store is an in-memory model store which can be created with `store = new InMemSpdxStore()`. A copy manager will be needed if you are working with more than one store (e.g. a serialized format of SPDX data and in memory). If you're not sure, you should just create one. This can be done with `copyManager = new ModelCopyManager()`. + +The first object you create will depend on the major version: +- For SPDX 2.X, you would start by creating an SpdxDocument. The factory method `SpdxDocument document = SpdxModelFactory.createSpdxDocumentV2(IModelStore modelStore, String documentUri, IModelCopyManager copyManager)` will create a new SPDX document. Once created, you can use the setters to set the specific fields. You can then use the convenience create methods on the document to create additional SPDX objects (e.g. `document.createSpdxFile(...)`); +- For SPDX 3.X, you will start with a CreationInfo class. The factory method `CreationInfo creationInfo = SpdxModelClassFactory.createCreationInfo(IModelStore modelStore, String createdByUri,String createdByName, @Nullable IModelCopyManager copyManager)` will create and initialize a CreationInfo with today's date and the Agent information. To create any additional objects, you can use the builder convenience methods from the creationInfo (or any Elements created by the creationInfo) (e.g. `creationInfo.createSoftwareSpdxFile(String spdxFileObjectUri)`. The created objects will copy the creationInfo. + ## Update for new versions of the spec To update Spdx-Java-Library, the following is a very brief checklist: diff --git a/src/test/java/org/spdx/library/model/v3/SpdxModelClassFactoryTest.java b/src/test/java/org/spdx/library/model/v3/SpdxModelClassFactoryTest.java new file mode 100644 index 000000000..1e09c6fe9 --- /dev/null +++ b/src/test/java/org/spdx/library/model/v3/SpdxModelClassFactoryTest.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library.model.v3; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.spdx.core.IModelCopyManager; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; +import org.spdx.storage.simple.InMemSpdxStore; + +/** + * @author gary + * + */ +public class SpdxModelClassFactoryTest { + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + SpdxModelFactory.init(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link org.spdx.library.model.v3.SpdxModelClassFactory#createCreationInfo(org.spdx.storage.IModelStore, java.lang.String, java.lang.String, org.spdx.core.IModelCopyManager)}. + * @throws InvalidSPDXAnalysisException + */ + @Test + public void testCreateCreationInfo() throws InvalidSPDXAnalysisException { + IModelStore modelStore = new InMemSpdxStore(); + IModelCopyManager copyManager = new ModelCopyManager(); + String createdByUri = "urn:some.name"; + String createdByName = "My name"; + CreationInfo result = SpdxModelClassFactory.createCreationInfo(modelStore, createdByUri, createdByName, copyManager); + assertEquals(IdType.Anonymous, modelStore.getIdType(result.getObjectUri())); + assertEquals(1, result.getCreatedBys().size()); + assertEquals(0, result.verify().size()); + Agent agent = result.getCreatedBys().toArray(new Agent[1])[0]; + assertEquals(createdByUri, agent.getObjectUri()); + assertEquals(createdByName, agent.getName().get()); + assertTrue(result.equivalent(agent.getCreationInfo())); + assertEquals(result, agent.getCreationInfo()); + } + +} From 09a78d872c515aa6c3bdf0af1066c970bf774603 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Thu, 23 May 2024 11:35:49 -0700 Subject: [PATCH 30/62] Fix compare compile errors and unit tests for InMemSpdxStore Signed-off-by: Gary O'Neall --- .../spdx/storage/simple/InMemSpdxStore.java | 7 +- .../utility/compare/LicenseCompareHelper.java | 22 +- .../spdx/utility/compare/SpdxComparer.java | 32 +- .../compare/SpdxExternalRefDifference.java | 8 +- .../utility/compare/SpdxFileComparer.java | 16 +- .../utility/compare/SpdxFileDifference.java | 15 +- .../utility/compare/SpdxItemComparer.java | 13 +- .../utility/compare/SpdxItemDifference.java | 10 +- .../compare/SpdxLicenseDifference.java | 4 +- .../utility/compare/SpdxPackageComparer.java | 14 +- .../utility/compare/SpdxSnippetComparer.java | 12 +- .../VerificationCodeGenerator.java | 8 +- .../spdx/library/ModelCopyManagerTest.java | 10 +- .../library/model/ModelCollectionTest.java | 160 ---- .../library/model/ModelObjectForTesting.java | 131 --- .../spdx/library/model/ModelObjectTest.java | 505 ------------ .../library/model/SimpleUriValueTest.java | 114 --- .../ListedReferenceTypesTest.java | 87 -- .../listedreferencetypes.properties | 4 - .../v2/CompatibleModelStoreWrapperTest.java | 749 ------------------ .../storage/simple/InMemSpdxStoreTest.java | 210 +++-- .../storage/simple/StoredTypedItemTest.java | 71 +- 22 files changed, 216 insertions(+), 1986 deletions(-) delete mode 100644 src/test/java/org/spdx/library/model/ModelCollectionTest.java delete mode 100644 src/test/java/org/spdx/library/model/ModelObjectForTesting.java delete mode 100644 src/test/java/org/spdx/library/model/ModelObjectTest.java delete mode 100644 src/test/java/org/spdx/library/model/SimpleUriValueTest.java delete mode 100644 src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java delete mode 100644 src/test/java/org/spdx/library/referencetype/listedreferencetypes.properties delete mode 100644 src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index 080a11ffa..d3f8ebfd4 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -332,12 +332,9 @@ public Iterator listValues(String objectUri, PropertyDescriptor property @Override public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { StoredTypedItem item = getItem(objectUri); - Class itemClass = ModelRegistry.getModelRegistry().typeToClass(item.getType(), item.getSpecVersion()); - if (Objects.isNull(itemClass)) { - throw new InvalidSPDXAnalysisException("Unknown type "+item.getType()+" for spec version "+item.getSpecVersion()); - } if (item.isCollectionProperty(propertyDescriptor)) { - return Optional.of(new ModelCollection(this, objectUri, propertyDescriptor, null, itemClass, item.getSpecVersion())); + logger.warn("Returning a collection for a getValue call for property "+propertyDescriptor.getName()); + return Optional.of(new ModelCollection(this, objectUri, propertyDescriptor, null, null, item.getSpecVersion())); } else { return Optional.ofNullable(item.getValue(propertyDescriptor)); } diff --git a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java index aeb1b7723..296955be9 100644 --- a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java +++ b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java @@ -37,17 +37,17 @@ import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.License; -import org.spdx.library.model.compat.v2.license.LicenseException; -import org.spdx.library.model.compat.v2.license.LicenseSet; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; -import org.spdx.library.model.compat.v2.license.ListedLicenses; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.license.AnyLicenseInfo; +import org.spdx.library.model.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.v2.license.License; +import org.spdx.library.model.v2.license.LicenseException; +import org.spdx.library.model.v2.license.LicenseSet; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.ListedLicenses; +import org.spdx.library.model.v2.license.SpdxListedLicense; import org.spdx.licenseTemplate.LicenseParserException; import org.spdx.licenseTemplate.LicenseTemplateRuleException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; diff --git a/src/main/java/org/spdx/utility/compare/SpdxComparer.java b/src/main/java/org/spdx/utility/compare/SpdxComparer.java index ced90031e..c01757a89 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxComparer.java @@ -33,22 +33,22 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxModelFactory; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalDocumentRef; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxCreatorInformation; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxElement; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxPackage; -import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; -import org.spdx.library.model.compat.v2.SpdxSnippet; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.Checksum; +import org.spdx.library.model.v2.ExternalDocumentRef; +import org.spdx.library.model.v2.ModelObjectV2; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxCreatorInformation; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.library.model.v2.SpdxElement; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxPackage; +import org.spdx.library.model.v2.SpdxPackageVerificationCode; +import org.spdx.library.model.v2.SpdxSnippet; +import org.spdx.library.model.v2.license.AnyLicenseInfo; +import org.spdx.library.model.v2.license.ExtractedLicenseInfo; /** * Performs a comparison between two or more SPDX documents and holds the results of the comparison * The main function to perform the comparison is compare(spdxdoc1, spdxdoc2) diff --git a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java index a4bbc3286..25d107efe 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxExternalRefDifference.java @@ -20,10 +20,10 @@ import java.util.Objects; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.ExternalRef; -import org.spdx.library.model.compat.v2.ReferenceType; -import org.spdx.library.model.compat.v2.enumerations.ReferenceCategory; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.ExternalRef; +import org.spdx.library.model.v2.ReferenceType; +import org.spdx.library.model.v2.enumerations.ReferenceCategory; /** * Contains information on differences between two different External Refs. diff --git a/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java b/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java index 99659c8a0..0f7541b0f 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxFileComparer.java @@ -25,14 +25,14 @@ import java.util.Map; import java.util.Map.Entry; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.Checksum; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.SpdxItem; +import org.spdx.library.model.v2.license.AnyLicenseInfo; /** * Compares two SPDX files. The compare(fileA, fileB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java index 7cf8e12b3..5ea2625f9 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxFileDifference.java @@ -23,13 +23,14 @@ import java.util.Objects; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.enumerations.FileType; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.Checksum; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.enumerations.FileType; +import org.spdx.library.model.v2.license.AnyLicenseInfo; + /** * Contains the results of a comparison between two SPDX files with the same name diff --git a/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java b/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java index 58f0db064..c6501605d 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxItemComparer.java @@ -26,12 +26,13 @@ import java.util.Map.Entry; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.library.model.v2.SpdxItem; +import org.spdx.library.model.v2.license.AnyLicenseInfo; + /** * Compares two SPDX items. The compare(itemA, itemB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java b/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java index 739b29ef8..35452cee8 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxItemDifference.java @@ -20,11 +20,11 @@ import java.util.List; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Annotation; -import org.spdx.library.model.compat.v2.Relationship; -import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.Annotation; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxItem; +import org.spdx.library.model.v2.license.AnyLicenseInfo; /** * Contains the results of a comparison between two SPDX items with the same name diff --git a/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java b/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java index d1ff9efb8..b6305c170 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java +++ b/src/main/java/org/spdx/utility/compare/SpdxLicenseDifference.java @@ -19,8 +19,8 @@ import java.util.Collection; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.license.ExtractedLicenseInfo; /** * Contains the results of a comparison between two SPDX non-standard licenses diff --git a/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java b/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java index 00fe7368d..73107965b 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxPackageComparer.java @@ -29,13 +29,13 @@ import java.util.Objects; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.Checksum; -import org.spdx.library.model.compat.v2.ExternalRef; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.SpdxPackage; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.Checksum; +import org.spdx.library.model.v2.ExternalRef; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.SpdxItem; +import org.spdx.library.model.v2.SpdxPackage; /** * Compares two SPDX package. The compare(pkgA, pkgB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java b/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java index 3600b2a38..fe4521488 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java @@ -24,12 +24,12 @@ import java.util.Objects; import java.util.Optional; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxItem; -import org.spdx.library.model.compat.v2.SpdxSnippet; -import org.spdx.library.model.compat.v2.pointer.StartEndPointer; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.SpdxItem; +import org.spdx.library.model.v2.SpdxSnippet; +import org.spdx.library.model.v2.pointer.StartEndPointer; /** * Compares two SPDX snippets. The compare(snippetA, snippetB) method will perform the comparison and diff --git a/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java b/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java index 2403423c9..01a287bf2 100644 --- a/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java +++ b/src/main/java/org/spdx/utility/verificationcode/VerificationCodeGenerator.java @@ -29,9 +29,9 @@ import java.util.Set; import java.util.TreeSet; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.SpdxFile; -import org.spdx.library.model.compat.v2.SpdxPackageVerificationCode; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.SpdxFile; +import org.spdx.library.model.v2.SpdxPackageVerificationCode; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -140,7 +140,7 @@ protected SpdxPackageVerificationCode generatePackageVerificationCode(List EXTERNAL_MAP = new HashMap<>(); - - //TODO: Change this to a version 3 GMO - Element gmo; - - protected void setUp() throws Exception { - super.setUp(); - DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); - gmo = new Element(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testSize() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), null, EXTERNAL_MAP); - for (String element:ELEMENTS) { - mc.add(element); - } - assertEquals(ELEMENTS.length, mc.size()); - } - - public void testIsEmpty() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - assertTrue(mc.isEmpty()); - for (String element:ELEMENTS) { - mc.add(element); - } - assertFalse(mc.isEmpty()); - } - - public void testContains() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - for (String element:ELEMENTS) { - mc.add(element); - } - for (String element:ELEMENTS) { - assertTrue(mc.contains(element)); - } - assertFalse(mc.contains("not there")); - } - - public void testToImmutableList() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - for (String element:ELEMENTS) { - mc.add(element); - } - List result = mc.toImmutableList(); - assertEquals(ELEMENTS.length, result.size()); - for (String element:ELEMENTS) { - assertTrue(result.contains(element)); - } - } - - public void testAdd() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - assertEquals(0, mc.size()); - mc.add(ELEMENTS[0]); - assertEquals(1, mc.size()); - assertTrue(mc.contains(ELEMENTS[0])); - mc.add(ELEMENTS[1]); - assertEquals(2, mc.size()); - assertTrue(mc.contains(ELEMENTS[0])); - assertTrue(mc.contains(ELEMENTS[1])); - } - - public void testRemove() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - for (String element:ELEMENTS) { - mc.add(element); - } - assertEquals(ELEMENTS.length, mc.size()); - assertTrue(mc.contains(ELEMENTS[0])); - mc.remove(ELEMENTS[0]); - assertEquals(ELEMENTS.length-1, mc.size()); - assertFalse(mc.contains(ELEMENTS[0])); - } - - public void testContainsAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - for (String element:ELEMENTS) { - mc.add(element); - } - List compare = new ArrayList(Arrays.asList(ELEMENTS)); - assertTrue(mc.containsAll(compare)); - compare.add("Another"); - assertFalse(mc.containsAll(compare)); - } - - public void testAddAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - List compare = new ArrayList(Arrays.asList(ELEMENTS)); - mc.addAll(compare); - - assertEquals(ELEMENTS.length, mc.size()); - for (String element:ELEMENTS) { - assertTrue(mc.contains(element)); - } - } - - public void testRemoveAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - List list1 = Arrays.asList(ELEMENTS); - List list2 = new ArrayList(list1); - String addedElement = "added"; - list2.add(addedElement); - mc.addAll(list2); - mc.removeAll(list1); - assertEquals(1, mc.size()); - assertTrue(mc.contains(addedElement)); - } - - public void testRetainAll() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - List list1 = Arrays.asList(ELEMENTS); - List list2 = new ArrayList(list1); - String addedElement = "added"; - list2.add(addedElement); - mc.addAll(list2); - assertEquals(list2.size(), mc.size()); - mc.retainAll(list1); - assertEquals(list1.size(), mc.size()); - for (String s:list1) { - assertTrue(mc.contains(s)); - } - } - - public void testClear() throws InvalidSPDXAnalysisException { - ModelCollection mc = new ModelCollection(gmo.getModelStore(), gmo.getObjectUri(), PROPERTY_NAME, gmo.getCopyManager(), String.class, EXTERNAL_MAP); - for (String element:ELEMENTS) { - mc.add(element); - } - assertEquals(ELEMENTS.length, mc.size()); - mc.clear(); - assertEquals(0, mc.size()); - } - -} diff --git a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java b/src/test/java/org/spdx/library/model/ModelObjectForTesting.java deleted file mode 100644 index dace448cb..000000000 --- a/src/test/java/org/spdx/library/model/ModelObjectForTesting.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.model.v3.core.ProfileIdentifierType; -import org.spdx.storage.IModelStore; -import org.spdx.storage.IModelStore.IdType; - -/** - * Concrete subclass of ModelObjectV2 for testing purposes - * - * @author Gary O'Neall - * - */ -public class ModelObjectForTesting extends ModelObjectV2 { - - public static final String TYPE = "ModelObjectForTesting"; - - /** - * @throws InvalidSPDXAnalysisException - */ - public ModelObjectForTesting() throws InvalidSPDXAnalysisException { - super(); - } - - /** - * @param objectUri - * @throws InvalidSPDXAnalysisException - */ - public ModelObjectForTesting(String objectUri) - throws InvalidSPDXAnalysisException { - super(objectUri); - } - - /** - * @param modelStore - * @param objectUri - * @param copyManager - * @param create - * @throws InvalidSPDXAnalysisException - */ - public ModelObjectForTesting(IModelStore modelStore, String objectUri, - ModelCopyManager copyManager, boolean create) - throws InvalidSPDXAnalysisException { - super(modelStore, objectUri, copyManager, create); - } - - /** - * @param builder - * @throws InvalidSPDXAnalysisException - */ - public ModelObjectForTesting(CoreModelObjectBuilder builder) - throws InvalidSPDXAnalysisException { - super(builder); - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#getType() - */ - @Override - public String getType() { - return TYPE; - } - - /* (non-Javadoc) - * @see org.spdx.library.model.ModelObject#_verify(java.util.Set, java.lang.String, java.util.List) - */ - @Override - protected List _verify(Set verifiedElementIds, - String specVersion, List profiles) { - return new ArrayList(); - } - - public static class ModelObjectForTestingBuilder extends CoreModelObjectBuilder { - - /** - * Create an ElementBuilder from another model object copying the modelStore and copyManager and using an anonymous ID - * @param from model object to copy the model store and copyManager from - * @throws InvalidSPDXAnalysisException - */ - public ModelObjectForTestingBuilder(ModelObjectV2 from) throws InvalidSPDXAnalysisException { - this(from, from.getModelStore().getNextId(IdType.Anonymous, null)); - } - - /** - * Create an ElementBuilder from another model object copying the modelStore and copyManager - * @param from model object to copy the model store and copyManager from - * @param objectUri URI for the object - * @param objectUri - */ - public ModelObjectForTestingBuilder(ModelObjectV2 from, String objectUri) { - this(from.getModelStore(), objectUri, from.getCopyManager()); - setStrict(from.isStrict()); - setExternalMap(from.externalMap); - } - - /** - * Creates a ElementBuilder - * @param modelStore model store for the built Element - * @param objectUri objectUri for the built Element - * @param copyManager optional copyManager for the built Element - */ - public ModelObjectForTestingBuilder(IModelStore modelStore, String objectUri, @Nullable ModelCopyManager copyManager) { - super(modelStore, objectUri, copyManager); - } - } - -} diff --git a/src/test/java/org/spdx/library/model/ModelObjectTest.java b/src/test/java/org/spdx/library/model/ModelObjectTest.java deleted file mode 100644 index 6128eb45a..000000000 --- a/src/test/java/org/spdx/library/model/ModelObjectTest.java +++ /dev/null @@ -1,505 +0,0 @@ -/** - * Copyright (c) 2023 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants; -import org.spdx.library.model.ModelObjectForTesting.ModelObjectForTestingBuilder; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.library.model.v3.core.HashAlgorithm; -import org.spdx.library.model.v3.expandedlicensing.ConjunctiveLicenseSet; -import org.spdx.library.model.v3.expandedlicensing.CustomLicense; -import org.spdx.library.model.v3.expandedlicensing.ListedLicense; -import org.spdx.library.model.v3.expandedlicensing.ListedLicenseException; -import org.spdx.library.model.v3.expandedlicensing.ListedLicenseException.ListedLicenseExceptionBuilder; -import org.spdx.library.model.v3.simplelicensing.AnyLicenseInfo; -import org.spdx.storage.IModelStore; -import org.spdx.storage.PropertyDescriptor; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.simple.InMemSpdxStore; - -import junit.framework.TestCase; - -/** - * @author gary - * - */ -public class ModelObjectTest extends TestCase { - - private static final String TEST_OBJECT_URI = "https://spdx.test/testId"; - private static final String TEST_OBJECT_URI2 = "https://spdx.test/testId2"; - private static final Object TEST_VALUE1 = "value1"; - private static final PropertyDescriptor TEST_PROPERTY1 = new PropertyDescriptor("property1", SpdxConstants.CORE_NAMESPACE); - private static final PropertyDescriptor TEST_PROPERTY2 = new PropertyDescriptor("property2", SpdxConstants.CORE_NAMESPACE); - static final String TEST_TYPE1 = "Core.Element"; - static final String TEST_TYPE2 = "Core.Annotation"; - - static final String EXTERNAL_ID1 = "http://externalMap1"; - static final String EXTERNAL_DEFINING_DOCUMENT1 = "http://externalDoc1"; - static final String EXTERNAL_ID2 = "http://externalMap2"; - static final String EXTERNAL_DEFINING_DOCUMENT2 = "http://externalDoc2"; - - static final PropertyDescriptor[] TEST_STRING_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("valueProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("valueProp2", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("valueProp3", SpdxConstants.CORE_NAMESPACE)}; - static final Object[] TEST_STRING_VALUE_PROPERTY_VALUES = new Object[] {"value1", "value2", "value3"}; - static final PropertyDescriptor[] TEST_INTEGER_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("intProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("intProp2", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("Intprop3", SpdxConstants.CORE_NAMESPACE)}; - static final Object[] TEST_INTEGER_VALUE_PROPERTY_VALUES = new Object[] {Integer.valueOf(3), Integer.valueOf(0), Integer.valueOf(-1)}; - static final PropertyDescriptor[] TEST_BOOLEAN_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("boolProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("boolProp2", SpdxConstants.CORE_NAMESPACE)}; - static final Object[] TEST_BOOLEAN_VALUE_PROPERTY_VALUES = new Object[] {true, false}; - static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("listProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("listProp2", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("listProp3", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("listProp4", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("listProp5", SpdxConstants.CORE_NAMESPACE)}; - static final PropertyDescriptor[] TEST_MODEL_OJBECT_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("typeProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("typeProp2", SpdxConstants.CORE_NAMESPACE)}; - static final PropertyDescriptor[] TEST_ENUM_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("enumProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("enumProp2", SpdxConstants.CORE_NAMESPACE)}; - static final HashAlgorithm[] TEST_ENUM_VALUES = new HashAlgorithm[] {HashAlgorithm.MD5, HashAlgorithm.SHA1}; - static final PropertyDescriptor[] TEST_ANYLICENSEINFO_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("anylicenseProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("anylicenseProp2", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("anylicenseProp3", SpdxConstants.CORE_NAMESPACE)}; - static final PropertyDescriptor[] TEST_ANYLICENSEINFO_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("anylicenseListProp1", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("anylicensListProp2", SpdxConstants.CORE_NAMESPACE), - new PropertyDescriptor("anylicenseListProp3", SpdxConstants.CORE_NAMESPACE)}; - - ModelObjectV2[] TEST_MODEL_OBJECT_PROP_VALUES; - List[] TEST_LIST_PROPERTY_VALUES; - AnyLicenseInfo[] TEST_ANYLICENSEINFO_PROP_VALUES; - List[] TEST_ANYLICENSEINFO_LIST_PROP_VALUES; - Map ALL_PROPERTY_VALUES; - - IModelStore store; - ModelCopyManager copyManager; - Map externalMap; - - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - store = new InMemSpdxStore(); - copyManager = new ModelCopyManager(); - externalMap = new HashMap<>(); - externalMap.put(EXTERNAL_ID1, new ExternalMap.ExternalMapBuilder(store, EXTERNAL_ID1, copyManager) - .setDefiningDocument(EXTERNAL_DEFINING_DOCUMENT1) - .setExternalId(EXTERNAL_ID1) - .build()); - externalMap.put(EXTERNAL_ID2, new ExternalMap.ExternalMapBuilder(store, EXTERNAL_ID2, copyManager) - .setDefiningDocument(EXTERNAL_DEFINING_DOCUMENT2) - .setExternalId(EXTERNAL_ID2) - .build()); - ListedLicenseExceptionBuilder llbldr = new ListedLicenseExceptionBuilder(store, "http://spdx.org/licenses/Autoconf-exception-2.0", copyManager); - llbldr.setAdditionText("Autoconf exception 2.0 text"); - llbldr.setName("Autoconf exception 2.0 name"); - ListedLicenseException lex = llbldr.build(); - - CustomLicense eli1 = new CustomLicense(store.getNextId(IdType.LicenseRef, null)); - eli1.setName("eli1"); - eli1.setLicenseText("eli1 text"); - ConjunctiveLicenseSet cls = new ConjunctiveLicenseSet(store, store.getNextId(IdType.Anonymous, null), copyManager, true); - - cls.getMembers().add(new ListedLicense(store, "Apache-2.0", copyManager, true)); - cls.getMembers().add(eli1); - TEST_LIST_PROPERTY_VALUES = new List[] {Arrays.asList("ListItem1", "listItem2", "listItem3"), - Arrays.asList(true, false, true), - Arrays.asList(new ModelObjectV2[] {lex, eli1}), - Arrays.asList(new HashAlgorithm[] {HashAlgorithm.SHA256, HashAlgorithm.SHA1}), - Arrays.asList(new Integer[] {1, 3, 5})}; - TEST_MODEL_OBJECT_PROP_VALUES = new ModelObjectV2[] {lex, eli1}; - // TODO: Changes these back once we have the individuals implemented - /* - TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true), - eli1, new SpdxNoneLicense()}; - TEST_ANYLICENSEINFO_LIST_PROP_VALUES = new List[] {Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "MIT", copyManager, true), - eli1, new ListedLicense(store, "GPL-2.0-only", copyManager, true)}), - Arrays.asList(new AnyLicenseInfo[] {new SpdxNoAssertionLicense()}), - Arrays.asList(new AnyLicenseInfo[] {cls, eli1}) - }; - */ - - TEST_ANYLICENSEINFO_PROP_VALUES = new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true), - eli1}; - TEST_ANYLICENSEINFO_LIST_PROP_VALUES = new List[] {Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "MIT", copyManager, true), - eli1, new ListedLicense(store, "GPL-2.0-only", copyManager, true)}), - Arrays.asList(new AnyLicenseInfo[] {new ListedLicense(store, "Apache-2.0", copyManager, true)}), - Arrays.asList(new AnyLicenseInfo[] {cls, eli1}) - }; - - - ALL_PROPERTY_VALUES = new HashMap<>(); - for (int i = 0; i < TEST_STRING_VALUE_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_STRING_VALUE_PROPERTIES[i], - TEST_STRING_VALUE_PROPERTY_VALUES[i]); - } - for (int i = 0; i < TEST_BOOLEAN_VALUE_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_BOOLEAN_VALUE_PROPERTIES[i], - TEST_BOOLEAN_VALUE_PROPERTY_VALUES[i]); - } - for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_LIST_PROPERTIES[i], - TEST_LIST_PROPERTY_VALUES[i]); - } - for (int i = 0; i < TEST_MODEL_OJBECT_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_MODEL_OJBECT_PROPERTIES[i], - TEST_MODEL_OBJECT_PROP_VALUES[i]); - } - for (int i = 0; i < TEST_ENUM_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_ENUM_PROPERTIES[i], - TEST_ENUM_VALUES[i]); - } - for (int i = 0; i < TEST_ANYLICENSEINFO_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_PROPERTIES[i], - TEST_ANYLICENSEINFO_PROP_VALUES[i]); - } - for (int i = 0; i < TEST_ANYLICENSEINFO_LIST_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_ANYLICENSEINFO_LIST_PROPERTIES[i], - TEST_ANYLICENSEINFO_LIST_PROP_VALUES[i]); - } - for (int i = 0; i < TEST_INTEGER_VALUE_PROPERTIES.length; i++) { - ALL_PROPERTY_VALUES.put(TEST_INTEGER_VALUE_PROPERTIES[i], - TEST_INTEGER_VALUE_PROPERTY_VALUES[i]); - } - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#ModelObject(org.spdx.storage.IModelStore, java.lang.String, org.spdx.library.ModelCopyManager, boolean)}. - * @throws InvalidSPDXAnalysisException - */ - public void testModelObjectIModelStoreStringModelCopyManagerBoolean() throws InvalidSPDXAnalysisException { - try { - new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, false); - fail("This should not have worked since created is set to false and the ID does not exist"); - } catch (InvalidSPDXAnalysisException ex) { - // expected - } - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - moft.setPropertyValue(TEST_PROPERTY1, TEST_VALUE1); - ModelObjectForTesting moft2 = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, false); - assertTrue(moft2.getStringPropertyValue(TEST_PROPERTY1).isPresent()); - assertEquals(moft2.getStringPropertyValue(TEST_PROPERTY1).get(), TEST_VALUE1); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#ModelObject(org.spdx.library.mobdel.ModelObjectBuilder)}. - */ - public void testModelObjectModelObjectBuilder() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - moft.setPropertyValue(TEST_PROPERTY1, TEST_VALUE1); - moft.setExternalMap(externalMap); - ModelObjectForTestingBuilder moftBuilder = new ModelObjectForTestingBuilder(moft, TEST_OBJECT_URI2); - ModelObjectForTesting moft2 = new ModelObjectForTesting(moftBuilder); - assertEquals(moft.getCopyManager(), moft2.getCopyManager()); - assertEquals(moft.getModelStore(), moft2.getModelStore()); - assertEquals(moft.getExternalMap(), moft2.getExternalMap()); - assertFalse(moft2.getStringPropertyValue(TEST_PROPERTY1).isPresent()); - } - - public void testSetExternalMap() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - assertTrue(moft.getExternalMap().isEmpty()); - moft.setExternalMap(externalMap); - assertEquals(externalMap, moft.getExternalMap()); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#verify(java.lang.String)}. - */ - public void testVerifyString() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - assertTrue(moft.verify().isEmpty()); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectUri()}. - */ - public void testGetObjectUri() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - assertEquals(TEST_OBJECT_URI, moft.getObjectUri()); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getModelStore()}. - */ - public void testGetModelStore() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - assertEquals(store, moft.getModelStore()); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#setStrict(boolean)}. - */ - public void testSetStrict() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - assertFalse(moft.isStrict()); - moft.setStrict(true); - assertTrue(moft.isStrict()); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getPropertyValueDescriptors()}. - */ - public void testGetPropertyValueDescriptors() throws InvalidSPDXAnalysisException { - ModelObjectForTesting moft = new ModelObjectForTesting(store, TEST_OBJECT_URI, copyManager, true); - List result = moft.getPropertyValueDescriptors(); - assertEquals(0, result.size()); - addTestValues(moft); - result =moft.getPropertyValueDescriptors(); - assertEquals(ALL_PROPERTY_VALUES.size(), result.size()); - for (PropertyDescriptor property:ALL_PROPERTY_VALUES.keySet()) { - assertTrue(result.contains(property)); - } - } - - protected void addTestValues(ModelObjectV2 mo) throws InvalidSPDXAnalysisException { - for (Entry entry:ALL_PROPERTY_VALUES.entrySet()) { - mo.setPropertyValue(entry.getKey(), entry.getValue()); - } - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetObjectPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#setPropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testSetPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#updatePropertyValue(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testUpdatePropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getStringPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetStringPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getIntegerPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetIntegerPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getEnumPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetEnumPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getBooleanPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetBooleanPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetAnyLicenseInfoPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getElementPropertyValue(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetElementPropertyValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#removeProperty(org.spdx.storage.PropertyDescriptor)}. - */ - public void testRemoveProperty() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#updateRemoveProperty(org.spdx.storage.PropertyDescriptor)}. - */ - public void testUpdateRemoveProperty() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#clearValueCollection(org.spdx.storage.PropertyDescriptor)}. - */ - public void testClearValueCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#updateClearValueCollection(org.spdx.storage.PropertyDescriptor)}. - */ - public void testUpdateClearValueCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#addPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testAddPropertyValueToCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#updateAddPropertyValueToCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testUpdateAddPropertyValueToCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#removePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testRemovePropertyValueFromCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#updateRemovePropertyValueFromCollection(org.spdx.storage.PropertyDescriptor, java.lang.Object)}. - */ - public void testUpdateRemovePropertyValueFromCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectPropertyValueSet(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. - */ - public void testGetObjectPropertyValueSet() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getObjectPropertyValueCollection(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. - */ - public void testGetObjectPropertyValueCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getStringCollection(org.spdx.storage.PropertyDescriptor)}. - */ - public void testGetStringCollection() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. - */ - public void testIsCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#equivalent(org.spdx.library.model.ModelObjectV2)}. - */ - public void testEquivalentModelObject() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#equals(java.lang.Object)}. - */ - public void testEqualsObject() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#clone(org.spdx.storage.IModelStore)}. - */ - public void testCloneIModelStore() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#copyFrom(org.spdx.library.model.ModelObjectV2)}. - */ - public void testCopyFrom() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#copyFromV2(org.spdx.library.model.compat.v2.ModelObjectV2)}. - */ - public void testCopyFromV2() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#setCopyManager(org.spdx.library.ModelCopyManager)}. - */ - public void testSetCopyManager() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#getCopyManager()}. - */ - public void testGetCopyManager() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - - /** - * Test method for {@link org.spdx.library.model.ModelObjectV2#toTypedValue()}. - */ - public void testToTypedValue() throws InvalidSPDXAnalysisException { - fail("Not yet implemented"); - } - -} diff --git a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java b/src/test/java/org/spdx/library/model/SimpleUriValueTest.java deleted file mode 100644 index a1982c4c8..000000000 --- a/src/test/java/org/spdx/library/model/SimpleUriValueTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.model; - -import java.util.HashMap; -import java.util.Map; - -import org.spdx.library.IndividualUriValue; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SimpleUriValue; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.enumerations.RelationshipType; -import org.spdx.library.model.v3.core.ExternalMap; -import org.spdx.storage.IModelStore; -import org.spdx.storage.simple.InMemSpdxStore; - -import junit.framework.TestCase; - -/** - * @author gary - * - */ -public class SimpleUriValueTest extends TestCase { - - Enum TEST_ENUM = RelationshipType.DESCRIBES; - - static final String ENUM_URI = RelationshipType.DESCRIBES.getIndividualURI(); - static final String EXTERNAL_DOC_NAMSPACE = "https://test/namespace1"; - static final String EXTERNAL_SPDX_ELEMENT_ID = SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM + "TEST"; - static final String EXTERNAL_SPDX_URI = EXTERNAL_DOC_NAMSPACE + "#" + EXTERNAL_SPDX_ELEMENT_ID; - static final String NON_INTERESTING_URI = "https://nothing/to/see/here"; - static final Map EXTERNAL_MAP = new HashMap<>(); - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - - /** - * Test method for {@link org.spdx.library.compat.v2.SimpleUriValue#SimpleUriValue(org.spdx.library.compat.v2.IndividualUriValue)}. - * @throws InvalidSPDXAnalysisException - */ - public void testSimpleUriValueIndividualValue() throws InvalidSPDXAnalysisException { - SimpleUriValue value1 = new SimpleUriValue(NON_INTERESTING_URI); - SimpleUriValue value2 = new SimpleUriValue(new IndividualUriValue() { - - @Override - public String getIndividualURI() { - return NON_INTERESTING_URI; - } - - }); - assertEquals(NON_INTERESTING_URI, value1.getIndividualURI()); - assertEquals(NON_INTERESTING_URI, value2.getIndividualURI()); - assertEquals(value1, value2); - } - - /** - * Test method for {@link org.spdx.library.compat.v2.SimpleUriValue#toModelObject(org.spdx.storage.IModelStore, java.lang.String)}. - * @throws InvalidSPDXAnalysisException - */ - public void testToModelObjectV2() throws InvalidSPDXAnalysisException { - IModelStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); - ModelCopyManager copyManager = new ModelCopyManager(); - org.spdx.library.model.compat.v2.GenericModelObject gmo = - new org.spdx.library.model.compat.v2.GenericModelObject(store, "http://doc", "id", copyManager, true); - new org.spdx.library.model.compat.v2.SpdxDocument(gmo.getModelStore(), gmo.getDocumentUri(), gmo.getCopyManager(), true); - Object result = new SimpleUriValue(EXTERNAL_SPDX_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), - gmo.getDocumentUri(), EXTERNAL_MAP); - assertTrue(result instanceof org.spdx.library.model.compat.v2.ExternalSpdxElement); - org.spdx.library.model.compat.v2.ExternalSpdxElement externalElement = (org.spdx.library.model.compat.v2.ExternalSpdxElement)result; - assertEquals(EXTERNAL_SPDX_ELEMENT_ID, externalElement.getExternalElementId()); - assertEquals(EXTERNAL_SPDX_URI, externalElement.getExternalSpdxElementURI()); - - result = new SimpleUriValue(ENUM_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), - gmo.getDocumentUri(), EXTERNAL_MAP); - assertEquals(TEST_ENUM, result); - - result = new SimpleUriValue(NON_INTERESTING_URI).toModelObject(gmo.getModelStore(), gmo.getCopyManager(), - gmo.getDocumentUri(), EXTERNAL_MAP); - assertTrue(result instanceof SimpleUriValue); - assertEquals(NON_INTERESTING_URI, ((SimpleUriValue)result).getIndividualURI()); - } - - public void testToModelObject() throws InvalidSPDXAnalysisException { - fail("Unimplemented"); - } -} diff --git a/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java b/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java deleted file mode 100644 index 0d2ce87a6..000000000 --- a/src/test/java/org/spdx/library/referencetype/ListedReferenceTypesTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2019 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.spdx.library.referencetype; - - -import java.net.URI; -import java.net.URISyntaxException; - -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.referencetype.compat.v2.ListedReferenceTypes; - -import junit.framework.TestCase; - -/** - * @author gary - * - */ -public class ListedReferenceTypesTest extends TestCase { - - static final String[] LISTED_REFERENCE_TYPE_NAMES = new String[] { - "cpe22Type","cpe23Type","maven-central","npm","nuget","bower","debian","advisory","fix","url","gitoid","swh","purl" - }; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - ListedReferenceTypes.resetListedReferenceTypes(); - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - - /** - * Test method for {@link org.spdx.library.referencetype.compat.v2.ListedReferenceTypes#isListedReferenceType(java.net.URI)}. - */ - public void testIsListedReferenceType() throws URISyntaxException { - for (String refName:LISTED_REFERENCE_TYPE_NAMES) { - URI uri = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + refName); - assertTrue(ListedReferenceTypes.getListedReferenceTypes().isListedReferenceType(uri)); - } - URI wrongNamespace = new URI("http://wrong/"+LISTED_REFERENCE_TYPE_NAMES[0]); - assertFalse(ListedReferenceTypes.getListedReferenceTypes().isListedReferenceType(wrongNamespace)); - URI notValidName = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX+"wrong"); - assertFalse(ListedReferenceTypes.getListedReferenceTypes().isListedReferenceType(notValidName)); - } - - /** - * Test method for {@link org.spdx.library.referencetype.compat.v2.ListedReferenceTypes#getListedReferenceUri(java.lang.String)}. - */ - public void testGetListedReferenceUri() throws InvalidSPDXAnalysisException { - URI result = ListedReferenceTypes.getListedReferenceTypes().getListedReferenceUri(LISTED_REFERENCE_TYPE_NAMES[0]); - assertEquals(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + LISTED_REFERENCE_TYPE_NAMES[0], result.toString()); - } - - /** - * Test method for {@link org.spdx.library.referencetype.compat.v2.ListedReferenceTypes#getListedReferenceName(java.net.URI)}. - */ - public void testGetListedReferenceName() throws URISyntaxException, InvalidSPDXAnalysisException { - for (String refName:LISTED_REFERENCE_TYPE_NAMES) { - URI uri = new URI(SpdxConstantsCompatV2.SPDX_LISTED_REFERENCE_TYPES_PREFIX + refName); - assertEquals(refName, ListedReferenceTypes.getListedReferenceTypes().getListedReferenceName(uri)); - } - } - -} diff --git a/src/test/java/org/spdx/library/referencetype/listedreferencetypes.properties b/src/test/java/org/spdx/library/referencetype/listedreferencetypes.properties deleted file mode 100644 index e62761f08..000000000 --- a/src/test/java/org/spdx/library/referencetype/listedreferencetypes.properties +++ /dev/null @@ -1,4 +0,0 @@ -# Properties file for listed reference types as described in the SPDX specification appendix -# -# List of all reference types separated by comma's -listedReferenceTypes=cpe22Type,cpe23Type,maven-central,npm,nuget,bower,debian,advisory,fix,url,gitoid,swh,purl \ No newline at end of file diff --git a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java b/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java deleted file mode 100644 index 0d12f82c0..000000000 --- a/src/test/java/org/spdx/storage/compat/v2/CompatibleModelStoreWrapperTest.java +++ /dev/null @@ -1,749 +0,0 @@ -package org.spdx.storage.compat.v2; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.concurrent.TimeoutException; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.TypedValue; -import org.spdx.storage.PropertyDescriptor; -import org.spdx.storage.IModelStore.IModelStoreLock; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.simple.InMemSpdxStore; -import org.spdx.storage.simple.InMemSpdxStoreTest; - -import junit.framework.TestCase; -import net.jodah.concurrentunit.Waiter; - -public class CompatibleModelStoreWrapperTest extends TestCase { - -static final Logger logger = LoggerFactory.getLogger(InMemSpdxStoreTest.class); - - static final long TIMEOUT = 10000; - - static final String TEST_DOCUMENT_URI1 = "http://test.document.uri/1"; - static final String TEST_DOCUMENT_URI2 = "http://test.document.uri/2"; - - static final String TEST_ID1 = "id1"; - static final String TEST_ID2 = "id2"; - - static final String TEST_TYPE1 = SpdxConstantsCompatV2.CLASS_ANNOTATION; - static final String TEST_TYPE2 = SpdxConstantsCompatV2.CLASS_RELATIONSHIP; - static final PropertyDescriptor[] TEST_VALUE_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("valueProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new PropertyDescriptor("valueProp4", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; - static final Object[] TEST_VALUE_PROPERTY_VALUES = new Object[] {"value1", true, "value2", null}; - static final PropertyDescriptor[] TEST_LIST_PROPERTIES = new PropertyDescriptor[] { - new PropertyDescriptor("listProp1", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new PropertyDescriptor("listProp2", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new PropertyDescriptor("listProp3", SpdxConstantsCompatV2.SPDX_NAMESPACE)}; - - protected static final int MAX_RETRIES = 10; - TypedValue[] TEST_TYPED_PROP_VALUES; - ArrayList[] TEST_LIST_PROPERTY_VALUES; - - String state; // used to track state in the asynch tests (e.g. testTransaction) - - private synchronized String setTestState(String newState) { - logger.info("Setting state to "+state); - String retval = state; - state = newState; - return retval; - } - - private synchronized String getTestState() { - return state; - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - TEST_LIST_PROPERTY_VALUES = new ArrayList[] {new ArrayList<>(Arrays.asList("ListItem1", "listItem2", "listItem3")), - new ArrayList<>(Arrays.asList(true, false, true)), - new ArrayList<>(Arrays.asList(CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, "typeId1", false, TEST_TYPE1), - CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, "typeId2", false, TEST_TYPE2)))}; - TEST_VALUE_PROPERTY_VALUES[3] = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, "typeId3", false, TEST_TYPE1); - - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testObjectUriToIdIdToUri() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - String documentUri = "http://doc.uri"; - String nameSpace = documentUri + "#"; - String anonId = store.getNextId(IdType.Anonymous, documentUri); - String spdxId = store.getNextId(IdType.SpdxId, documentUri); - - String objectUriId = CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, spdxId, store); - assertEquals(nameSpace + spdxId, objectUriId); - assertEquals(spdxId, CompatibleModelStoreWrapper.objectUriToId(store, objectUriId, documentUri)); - - String anonUriId = CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, anonId, store); - assertEquals(anonId, anonUriId); - assertEquals(anonId, CompatibleModelStoreWrapper.objectUriToId(store, anonUriId, documentUri)); - - } - - public void testUpdateNextIds() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - // License ID's - String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd34", nextId); - - // SPDX ID's - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, "SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE); - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd34", nextId); - - // Anonymous ID's - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM); - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd34", nextId); - - // Document ID's - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - store.create(TEST_DOCUMENT_URI1, SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF); - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); - } - - public void testCreateExists() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - String id1 = "TestId1"; - String id2 = "testId2"; - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - } - - public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); - for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { - if (TEST_VALUE_PROPERTY_VALUES[i] instanceof TypedValue) { - TypedValue tv = (TypedValue)TEST_VALUE_PROPERTY_VALUES[i]; - store.create(tv.getObjectUri(), tv.getType()); - } - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); - } - for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { - for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { - if (value instanceof TypedValue) { - TypedValue tv = (TypedValue)value; - store.create(tv.getObjectUri(), tv.getType()); - } - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[i], value); - } - } - List result = store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID1); - assertEquals(TEST_VALUE_PROPERTIES.length + TEST_LIST_PROPERTIES.length, result.size()); - for (PropertyDescriptor prop:TEST_VALUE_PROPERTIES) { - assertTrue(result.contains(prop)); - } - for (PropertyDescriptor prop:TEST_LIST_PROPERTIES) { - assertTrue(result.contains(prop)); - } - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI2, TEST_ID1).size()); - assertEquals(0, store.getPropertyValueDescriptors(TEST_DOCUMENT_URI1, TEST_ID2).size()); - } - - - public void testGetSetValue() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); - assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[1]); - assertEquals(TEST_VALUE_PROPERTY_VALUES[1], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_VALUE_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_VALUE_PROPERTIES[0]).isPresent()); - } - - public void testGetAddValueList() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - assertTrue(store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); - assertTrue(store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2)); - assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - } - - static List toImmutableList(Iterator listValues) { - return (List) Collections.unmodifiableList(StreamSupport.stream( - Spliterators.spliteratorUnknownSize(listValues, Spliterator.ORDERED), false) - .collect(Collectors.toList())); - } - - public void testGetNextId() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - // License ID's - String nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd0", nextId); - nextId = store.getNextId(IdType.LicenseRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "LicenseRef-gnrtd1", nextId); - - // SPDX ID's - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd0", nextId); - nextId = store.getNextId(IdType.SpdxId, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + "SPDXRef-gnrtd1", nextId); - - // Anonymous ID's - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - nextId = store.getNextId(IdType.Anonymous, TEST_DOCUMENT_URI1); - assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd1", nextId); - - // Document ID's - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - nextId = store.getNextId(IdType.DocumentRef, TEST_DOCUMENT_URI1); - assertEquals(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); - } - - public void testRemoveProperty() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore(SpdxMajorVersion.VERSION_2)); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - - assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).get()); - assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).get()); - assertCollectionsEquals(TEST_LIST_PROPERTY_VALUES[0], store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).get()); - store.removeProperty(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { - try { - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0], e); - } catch (InvalidSPDXAnalysisException e1) { - fail(e1.getMessage()); - } - } - } - - private void assertCollectionsEquals(Object c1, Object c2) { - if (!(c1 instanceof Collection)) { - fail("c1 is not a collection"); - } - if (!(c2 instanceof Collection)) { - fail("c2 is not a collection"); - } - Collection col1 = (Collection)c1; - Collection col2 = (Collection)c2; - assertEquals(col1.size(), col2.size()); - for (Object item:col1) { - assertTrue(col2.contains(item)); - } - } - - public void testClearList() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - store.clearValueCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]); - assertEquals(0, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - } - - public void copyFrom() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); - InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); - ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store2, store, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION, null, null, null, null); - assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_VALUE_PROPERTIES[0])); - assertEquals(2, toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store2.listValues(TEST_DOCUMENT_URI2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - } - - public void testRemoveListItem() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertEquals(2, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertTrue(store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); - assertEquals(1, toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertFalse(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store.listValues(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - assertFalse("Already removed - should return false",store.removeValueFromCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1)); - } - - //TODO: Fix the following test - it is flakey. Times out about 1 out of 5 times. Test problem, not a problem with the code under test - public void testLock() throws InvalidSPDXAnalysisException, IOException, InterruptedException, TimeoutException { - final CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - IModelStoreLock lock = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], value1); - lock.unlock(); - assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - /* Expected program flow - * Step1: thread1 run verifies that the property is still value1 - * thread1 starts a read transaction - * thread1 waits for step2 - * thread2 run verifies that the property is still value1 - * Step2: thread2 wakes up thread 1 - * Step3: thread1 wakes up thread 2 - * thread2 starts a write transaction - * thread2 is expected to block on the write transaction until thread1 finishes the read/verify - * step4: thread2 completes the write transaction, both threads verify value updated - */ - final Waiter waiter = new Waiter(); - @SuppressWarnings("unused") - final Thread thread1 = new Thread(null, null, "Thread1") { - @Override - public void run() { - try { - logger.info("thread1 started"); - logger.info("Waking up main thread"); - waiter.assertEquals("step0", setTestState("step1")); - waiter.resume(); // release the main thread - logger.info("Woke up main thread"); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - IModelStoreLock transactionLock = store.enterCriticalSection(TEST_DOCUMENT_URI1, true); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - int retries = 0; - while (!getTestState().equals("step2") && retries < MAX_RETRIES) { - logger.info("Thread 1 waiting for thread 2"); - waiter.await(TIMEOUT); // wait for thread 2 - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Thread1 awoke from thread 2"); - waiter.assertEquals("step2", setTestState("step3")); - logger.info("Waking up thread2"); - waiter.resume(); // wake thread 2 back up - logger.info("Woke up thread2"); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - transactionLock.unlock(); - retries = 0; - while (!getTestState().equals("step4") && retries < MAX_RETRIES) { - logger.info("Thread 1 waiting for thread 2"); - waiter.await(TIMEOUT); // wait for thread 2 to commit - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Thread1 awoke from thread 2"); - waiter.assertEquals("step4", getTestState()); - waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - } catch (Exception e) { - waiter.fail("Unexpected exception: "+e.getMessage()); - } - } - }; - - @SuppressWarnings("unused") - final Thread thread2 = new Thread(null ,null, "thread2") { - @Override - public void run() { - try { - waiter.assertEquals("step1", getTestState()); - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - waiter.assertEquals("step1",setTestState("step2")); - logger.info("Waking up Thread1"); - waiter.resume(); // wakeup thread1 - logger.info("Woke up Thread1"); - int retries = 0; - while (!getTestState().equals("step3") && retries < MAX_RETRIES) { - logger.info("Thread 2 waiting for thread 1"); - waiter.await(TIMEOUT); // wait for thread 1 - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Thread2 awoke from thread 1"); - waiter.assertEquals("step3", getTestState()); - IModelStoreLock transactionLock2 = store.enterCriticalSection(TEST_DOCUMENT_URI1, false); // this should block waiting for thread1 transaction to complete - waiter.assertEquals(value1, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0], value2); - waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - transactionLock2.unlock(); - waiter.assertEquals("step3",setTestState("step4")); - logger.info("Waking up Thread1"); - waiter.resume(); // wakeup thread1 - logger.info("Woke up Thread1"); - waiter.assertEquals(value2, store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - } catch (Exception e) { - waiter.fail("Unexpected exception: "+e.getMessage()); - } - } - }; - /* - setTestState("step0"); - logger.info("Starting Thread1"); - thread1.start(); - int retries = 0; - while (getTestState().equals("step0")) { - logger.info("Waiting for Thread1"); - waiter.await(TIMEOUT); // wait for thread 1 to get going - } - if (retries >= MAX_RETRIES) { - waiter.fail("State never changed"); - } - logger.info("Starting Thread2"); - thread2.start(); - logger.info("Joining thread1"); - thread1.join(); - logger.info("Joining thread2"); - thread2.join(); - assertEquals("step4", getTestState()); - */ - } - - public void testCollectionSize() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertEquals(2, store.collectionSize(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0])); - assertEquals(0, store.collectionSize(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[1])); - } - - public void testCollectionContains() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI2, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0], value2); - assertTrue(store.collectionContains(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0],value1)); - assertTrue(store.collectionContains(TEST_DOCUMENT_URI1, TEST_ID1, TEST_LIST_PROPERTIES[0],value2)); - assertFalse(store.getValue(TEST_DOCUMENT_URI2, TEST_ID1, TEST_LIST_PROPERTIES[0]).isPresent()); - assertFalse(store.getValue(TEST_DOCUMENT_URI1, TEST_ID2, TEST_LIST_PROPERTIES[0]).isPresent()); - } - - public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { - - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); - // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); - assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); - // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - TypedValue tv = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, TEST_ID2, false, TEST_TYPE2); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, String.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); - assertTrue(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); - // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - assertFalse(store.isPropertyValueAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); - } - - public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 2"); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, String.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, Boolean.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, TypedValue.class)); - // Boolean - PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(true)); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.valueOf(false)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, String.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, Boolean.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, bProperty, TypedValue.class)); - // TypedValue - PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - TypedValue tv = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, TEST_ID2, false, TEST_TYPE2); - store.create(TEST_DOCUMENT_URI1, TEST_ID2, TEST_TYPE2); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, tv); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, String.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, Boolean.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, tvProperty, TypedValue.class)); - // Mixed - PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.valueOf(true)); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, "mixed value"); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, String.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, Boolean.class)); - assertFalse(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, mixedProperty, TypedValue.class)); - // Empty - PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, String.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, Boolean.class)); - assertTrue(store.isCollectionMembersAssignableTo(TEST_DOCUMENT_URI1, TEST_ID1, emptyProperty, TypedValue.class)); - } - - public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - // String - PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.setValue(TEST_DOCUMENT_URI1, TEST_ID1, sProperty, "String 1"); - PropertyDescriptor listProperty = new PropertyDescriptor("listProp", SpdxConstantsCompatV2.SPDX_NAMESPACE); - store.addValueToCollection(TEST_DOCUMENT_URI1, TEST_ID1, listProperty, "testValue"); - assertTrue(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, listProperty)); - assertFalse(store.isCollectionProperty(TEST_DOCUMENT_URI1, TEST_ID1, sProperty)); - } - - public void testIdType() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - assertEquals(IdType.Anonymous, store.getIdType(InMemSpdxStore.ANON_PREFIX+"gnrtd23")); - assertEquals(IdType.DocumentRef, store.getIdType(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM+"gnrtd23")); - assertEquals(IdType.LicenseRef, store.getIdType(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM+"gnrtd23")); - assertEquals(IdType.ListedLicense, store.getIdType("Apache-2.0")); - assertEquals(IdType.ListedLicense, store.getIdType("https://spdx.org/licenses/somelicense")); - assertEquals(IdType.ListedLicense, store.getIdType("LLVM-exception")); - assertEquals(IdType.Literal, store.getIdType("NONE")); - assertEquals(IdType.Literal, store.getIdType("NOASSERTION")); - assertEquals(IdType.SpdxId, store.getIdType(TEST_DOCUMENT_URI1 + "#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); - } - - public void testGetCaseSensisitiveId() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - String expected = "TestIdOne"; - String lower = expected.toLowerCase(); - store.create(TEST_DOCUMENT_URI1, expected, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(expected, store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, lower).get()); - assertFalse(store.getCaseSensisitiveId(TEST_DOCUMENT_URI1, "somethingNotThere").isPresent()); - try { - store.create(TEST_DOCUMENT_URI1, lower, SpdxConstantsCompatV2.CLASS_ANNOTATION); - fail("This should be a duplicate ID failure"); - } catch (InvalidSPDXAnalysisException e) { - // expected - } - } - - public void testGetTypedValue() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - store.create(TEST_DOCUMENT_URI1, TEST_ID1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - assertEquals(SpdxConstantsCompatV2.CLASS_ANNOTATION, store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID1).get().getType()); - assertFalse(store.getTypedValue(TEST_DOCUMENT_URI1, TEST_ID2).isPresent()); - assertFalse(store.getTypedValue(TEST_DOCUMENT_URI2, TEST_ID1).isPresent()); - } - - public void testDelete() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - String id1 = "TestId1"; - String id2 = "testId2"; - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI2, id2)); - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI2, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI2, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - assertTrue(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - - store.delete(TEST_DOCUMENT_URI1, id1); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id1)); - assertTrue(store.exists(TEST_DOCUMENT_URI2, id2)); - } - - public void testDeleteInUse() throws InvalidSPDXAnalysisException { - CompatibleModelStoreWrapper store = new CompatibleModelStoreWrapper(new InMemSpdxStore()); - String id1 = "TestId1"; - String id2 = "testId2"; - String id3 = "testId3"; - String id4 = "testId4"; - store.create(TEST_DOCUMENT_URI1, id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_DOCUMENT_URI1, id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - TypedValue tv3 = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, id3, false, - SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.addValueToCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv3); - TypedValue tv4 = CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, id4, false, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.addValueToCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); - store.setValue(TEST_DOCUMENT_URI1, id3, - new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE), - CompatibleModelStoreWrapper.typedValueFromDocUri(TEST_DOCUMENT_URI1, id1, false, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); - - try { - store.delete(TEST_DOCUMENT_URI1, id3); - fail("id3 is in the listProperty for id2"); - } catch (SpdxIdInUseException ex) { - // expected - id3 is in the listProperty for id2 - } - try { - store.delete(TEST_DOCUMENT_URI1, id4); - fail("id4 is in the listProperty for id2"); - } catch (SpdxIdInUseException ex) { - // expected - id4 is in the listProperty for id2 - } - try { - store.delete(TEST_DOCUMENT_URI1, id1); - fail("id1 is in the property for id3"); - } catch (SpdxIdInUseException ex) { - // expected - id1 is in the property for id3 - } - store.removeValueFromCollection(TEST_DOCUMENT_URI1, id2, - new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); - store.delete(TEST_DOCUMENT_URI1, id4); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id4)); - try { - store.delete(TEST_DOCUMENT_URI1, id3); - fail("id3 is in the listProperty for id2"); - } catch (SpdxIdInUseException ex) { - // expected - id3 is in the listProperty for id2 - } - store.removeProperty(TEST_DOCUMENT_URI1, id3, - new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE)); - store.delete(TEST_DOCUMENT_URI1, id1); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id1)); - store.delete(TEST_DOCUMENT_URI1, id2); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id2)); - store.delete(TEST_DOCUMENT_URI1, id3); - assertFalse(store.exists(TEST_DOCUMENT_URI1, id3)); - } -} diff --git a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java index e2d822b79..14e365fdf 100644 --- a/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java +++ b/src/test/java/org/spdx/storage/simple/InMemSpdxStoreTest.java @@ -30,12 +30,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.SpdxIdInUseException; +import org.spdx.core.TypedValue; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxIdInUseException; -import org.spdx.library.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.IModelStore.IModelStoreLock; import org.spdx.storage.IModelStore.IdType; @@ -96,10 +96,11 @@ private synchronized String getTestState() { * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { + SpdxModelFactory.init(); TEST_LIST_PROPERTY_VALUES = new ArrayList[] {new ArrayList<>(Arrays.asList("ListItem1", "listItem2", "listItem3")), new ArrayList<>(Arrays.asList(true, false, true)), - new ArrayList<>(Arrays.asList(new TypedValue("typeId1", TEST_TYPE1), new TypedValue("typeId2", TEST_TYPE2)))}; - TEST_VALUE_PROPERTY_VALUES[3] = new TypedValue("typeId3", TEST_TYPE1); + new ArrayList<>(Arrays.asList(new TypedValue("typeId1", TEST_TYPE1, "SPDX-2.3"), new TypedValue("typeId2", TEST_TYPE2, "SPDX-2.3")))}; + TEST_VALUE_PROPERTY_VALUES[3] = new TypedValue("typeId3", TEST_TYPE1, "SPDX-2.3"); } @@ -113,32 +114,32 @@ protected void tearDown() throws Exception { public void testUpdateNextIds() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { // License ID's - String nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd0", nextId); - store.create(TEST_NAMESPACE1 + "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd34", nextId); + String nextId = store.getNextId(IdType.LicenseRef); + assertEquals("LicenseRef-gnrtd0", nextId); + store.create(new TypedValue(TEST_NAMESPACE1 + "LicenseRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE, "SPDX-2.3")); + nextId = store.getNextId(IdType.LicenseRef); + assertEquals("LicenseRef-gnrtd34", nextId); // SPDX ID's - nextId = store.getNextId(IdType.SpdxId, null); + nextId = store.getNextId(IdType.SpdxId); assertEquals("SPDXRef-gnrtd0", nextId); - store.create("SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE); - nextId = store.getNextId(IdType.SpdxId, null); + store.create(new TypedValue("SPDXRef-gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_FILE, "SPDX-2.3")); + nextId = store.getNextId(IdType.SpdxId); assertEquals("SPDXRef-gnrtd34", nextId); // Anonymous ID's - nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + nextId = store.getNextId(IdType.Anonymous); assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - store.create(InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM); - nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + store.create(new TypedValue(InMemSpdxStore.ANON_PREFIX + "gnrtd33", SpdxConstantsCompatV2.CLASS_SPDX_CHECKSUM, "SPDX-2.3")); + nextId = store.getNextId(IdType.Anonymous); assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd34", nextId); // Document ID's - nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - store.create(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF); - nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); + nextId = store.getNextId(IdType.DocumentRef); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + store.create(new TypedValue(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd33", SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF, "SPDX-2.3")); + nextId = store.getNextId(IdType.DocumentRef); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd34", nextId); } } @@ -146,10 +147,10 @@ public void testCreateExists() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { assertFalse(store.exists(TEST_OBJECT_URI1)); assertFalse(store.exists(TEST_OBJECT_URI2)); - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); assertTrue(store.exists(TEST_OBJECT_URI1)); assertFalse(store.exists(TEST_OBJECT_URI2)); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); assertTrue(store.exists(TEST_OBJECT_URI1)); assertTrue(store.exists(TEST_OBJECT_URI2)); } @@ -157,12 +158,12 @@ public void testCreateExists() throws Exception { public void testGetPropertyValueNames() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { if (TEST_VALUE_PROPERTY_VALUES[i] instanceof TypedValue) { TypedValue tv = (TypedValue)TEST_VALUE_PROPERTY_VALUES[i]; - store.create(tv.getObjectUri(), tv.getType()); + store.create(tv); } store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); } @@ -170,7 +171,7 @@ public void testGetPropertyValueNames() throws Exception { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { if (value instanceof TypedValue) { TypedValue tv = (TypedValue)value; - store.create(tv.getObjectUri(), tv.getType()); + store.create(tv); } store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[i], value); } @@ -190,8 +191,8 @@ public void testGetPropertyValueNames() throws Exception { public void testGetSetValue() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_VALUE_PROPERTIES[0]).isPresent()); store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); @@ -203,9 +204,9 @@ public void testGetSetValue() throws Exception { } public void testGetAddValueList() throws Exception { - try (InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2)) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); String value1 = "value1"; @@ -229,35 +230,35 @@ static List toImmutableList(Iterator listValues) { public void testGetNextId() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { // License ID's - String nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd0", nextId); - nextId = store.getNextId(IdType.LicenseRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + "LicenseRef-gnrtd1", nextId); + String nextId = store.getNextId(IdType.LicenseRef); + assertEquals("LicenseRef-gnrtd0", nextId); + nextId = store.getNextId(IdType.LicenseRef); + assertEquals("LicenseRef-gnrtd1", nextId); // SPDX ID's - nextId = store.getNextId(IdType.SpdxId, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + "SPDXRef-gnrtd0", nextId); - nextId = store.getNextId(IdType.SpdxId, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + "SPDXRef-gnrtd1", nextId); + nextId = store.getNextId(IdType.SpdxId); + assertEquals("SPDXRef-gnrtd0", nextId); + nextId = store.getNextId(IdType.SpdxId); + assertEquals("SPDXRef-gnrtd1", nextId); // Anonymous ID's - nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + nextId = store.getNextId(IdType.Anonymous); assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd0", nextId); - nextId = store.getNextId(IdType.Anonymous, TEST_NAMESPACE1); + nextId = store.getNextId(IdType.Anonymous); assertEquals(InMemSpdxStore.ANON_PREFIX + "gnrtd1", nextId); // Document ID's - nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); - nextId = store.getNextId(IdType.DocumentRef, TEST_NAMESPACE1); - assertEquals(TEST_NAMESPACE1 + SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); + nextId = store.getNextId(IdType.DocumentRef); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd0", nextId); + nextId = store.getNextId(IdType.DocumentRef); + assertEquals(SpdxConstantsCompatV2.EXTERNAL_DOC_REF_PRENUM + "gnrtd1", nextId); } } public void testRemoveProperty() throws Exception { - try (InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2)) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + try (InMemSpdxStore store = new InMemSpdxStore()) { + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); for (Object e:TEST_LIST_PROPERTY_VALUES[0]) { @@ -293,8 +294,8 @@ private void assertCollectionsEquals(Object c1, Object c2) { public void testClearList() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); String value1 = "value1"; @@ -310,28 +311,9 @@ public void testClearList() throws Exception { } } - public void testCopyFrom() throws Exception { - try (InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2)) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - String value1 = "value1"; - String value2 = "value2"; - store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); - store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value2); - store.setValue(TEST_OBJECT_URI1, TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); - InMemSpdxStore store2 = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); - ModelCopyManager copyManager = new ModelCopyManager(); - copyManager.copy(store2, store, TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, TEST_NAMESPACE1, - TEST_NAMESPACE2, TEST_NAMESPACE1, TEST_NAMESPACE2); - assertEquals(TEST_VALUE_PROPERTY_VALUES[0], store2.getValue(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_VALUE_PROPERTIES[0]).get()); - assertEquals(2, toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).size()); - assertTrue(toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value1)); - assertTrue(toImmutableList(store2.listValues(TEST_NAMESPACE2 + "#" + TEST_ID1, TEST_LIST_PROPERTIES[0])).contains(value2)); - } - } - public void testRemoveListItem() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); String value1 = "value1"; String value2 = "value2"; store.addValueToCollection(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0], value1); @@ -350,7 +332,7 @@ public void testRemoveListItem() throws Exception { //TODO: Fix the following test - it is flakey. Times out about 1 out of 5 times. Test problem, not a problem with the code under test public void testLock() throws Exception { try (final InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); String value1 = "value1"; @SuppressWarnings("unused") String value2 = "value2"; @@ -476,8 +458,8 @@ public void run() { public void testCollectionSize() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); String value1 = "value1"; @@ -492,8 +474,8 @@ public void testCollectionSize() throws Exception { public void testCollectionContains() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertFalse(store.getValue(TEST_OBJECT_URI1, TEST_LIST_PROPERTIES[0]).isPresent()); assertFalse(store.getValue(TEST_OBJECT_URI2, TEST_LIST_PROPERTIES[0]).isPresent()); String value1 = "value1"; @@ -509,36 +491,36 @@ public void testCollectionContains() throws Exception { public void testIsPropertyValueAssignableTo() throws Exception { try(InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.setValue(TEST_OBJECT_URI1, sProperty, "String 1"); - assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, String.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, Boolean.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, TypedValue.class)); + assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, String.class, "SPDX-2.3")); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, Boolean.class, "SPDX-2.3")); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, sProperty, TypedValue.class, "SPDX-2.3")); // Boolean PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.setValue(TEST_OBJECT_URI1, bProperty, Boolean.valueOf(true)); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, String.class)); - assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, Boolean.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, TypedValue.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, String.class, "SPDX-2.3")); + assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, Boolean.class, "SPDX-2.3")); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, bProperty, TypedValue.class, "SPDX-2.3")); // TypedValue PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - TypedValue tv = new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2); - store.create(TEST_OBJECT_URI2, TEST_TYPE2); + TypedValue tv = new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2, "SPDX-2.3"); + store.create(new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2, "SPDX-2.3")); store.setValue(TEST_OBJECT_URI1, tvProperty, tv); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, String.class)); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, Boolean.class)); - assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, TypedValue.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, String.class, "SPDX-2.3")); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, Boolean.class, "SPDX-2.3")); + assertTrue(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, tvProperty, TypedValue.class, "SPDX-2.3")); // Empty PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, emptyProperty, String.class)); + assertFalse(store.isPropertyValueAssignableTo(TEST_OBJECT_URI1, emptyProperty, String.class, "SPDX-2.3")); } } public void testCollectionMembersAssignableTo() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.addValueToCollection(TEST_OBJECT_URI1, sProperty, "String 1"); @@ -555,8 +537,8 @@ public void testCollectionMembersAssignableTo() throws Exception { assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, bProperty, TypedValue.class)); // TypedValue PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - TypedValue tv = new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2); - store.create(TEST_OBJECT_URI2, TEST_TYPE2); + TypedValue tv = new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2, "SPDX-2.3"); + store.create(new TypedValue(TEST_OBJECT_URI2, TEST_TYPE2, "SPDX-2.3")); store.addValueToCollection(TEST_OBJECT_URI1, tvProperty, tv); assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, tvProperty, String.class)); assertFalse(store.isCollectionMembersAssignableTo(TEST_OBJECT_URI1, tvProperty, Boolean.class)); @@ -578,7 +560,7 @@ public void testCollectionMembersAssignableTo() throws Exception { public void testIsCollectionProperty() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); store.setValue(TEST_OBJECT_URI1, sProperty, "String 1"); @@ -597,8 +579,6 @@ public void testIdType() throws Exception { assertEquals(IdType.ListedLicense, store.getIdType("Apache-2.0")); assertEquals(IdType.ListedLicense, store.getIdType("http://spdx.org/licenses/Apache-2.0")); assertEquals(IdType.ListedLicense, store.getIdType("LLVM-exception")); - assertEquals(IdType.Literal, store.getIdType("NONE")); - assertEquals(IdType.Literal, store.getIdType("NOASSERTION")); assertEquals(IdType.SpdxId, store.getIdType(TEST_NAMESPACE1 + "#" + SpdxConstantsCompatV2.SPDX_ELEMENT_REF_PRENUM+"gnrtd123")); } } @@ -607,11 +587,11 @@ public void testGetCaseSensisitiveId() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { String expected = "TestIdOne"; String lower = expected.toLowerCase(); - store.create(TEST_NAMESPACE1 + "#" + expected, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + expected, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertEquals(expected, store.getCaseSensisitiveId(TEST_NAMESPACE1, lower).get()); assertFalse(store.getCaseSensisitiveId(TEST_NAMESPACE1, "somethingNotThere").isPresent()); try { - store.create(TEST_NAMESPACE1 + "#" + lower, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + lower, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); fail("This should be a duplicate ID failure"); } catch (InvalidSPDXAnalysisException e) { // expected @@ -621,7 +601,7 @@ public void testGetCaseSensisitiveId() throws Exception { public void testGetTypedValue() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_ANNOTATION, "SPDX-2.3")); assertEquals(SpdxConstantsCompatV2.CLASS_ANNOTATION, store.getTypedValue(TEST_OBJECT_URI1).get().getType()); assertFalse(store.getTypedValue(TEST_OBJECT_URI2).isPresent()); } @@ -631,8 +611,8 @@ public void testDelete() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { assertFalse(store.exists(TEST_OBJECT_URI1)); assertFalse(store.exists(TEST_OBJECT_URI2)); - store.create(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(new TypedValue(TEST_OBJECT_URI1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); + store.create(new TypedValue(TEST_OBJECT_URI2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); assertTrue(store.exists(TEST_OBJECT_URI1)); assertTrue(store.exists(TEST_OBJECT_URI2)); @@ -648,19 +628,19 @@ public void testDeleteInUse() throws Exception { String id2 = "testId2"; String id3 = "testId3"; String id4 = "testId4"; - store.create(TEST_NAMESPACE1 + "#" + id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_NAMESPACE1 + "#" + id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_NAMESPACE1 + "#" + id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - store.create(TEST_NAMESPACE1 + "#" + id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); - TypedValue tv3 = new TypedValue(TEST_NAMESPACE1 + "#" + id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + id2, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); + TypedValue tv3 = new TypedValue(TEST_NAMESPACE1 + "#" + id3, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3"); store.addValueToCollection(TEST_NAMESPACE1 + "#" + id2, new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv3); - TypedValue tv4 = new TypedValue(TEST_NAMESPACE1 + "#" + id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO); + TypedValue tv4 = new TypedValue(TEST_NAMESPACE1 + "#" + id4, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3"); store.addValueToCollection(TEST_NAMESPACE1 + "#" + id2, new PropertyDescriptor("listProperty", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv4); store.setValue(TEST_NAMESPACE1 + "#" + id3, new PropertyDescriptor("property", SpdxConstantsCompatV2.SPDX_NAMESPACE), - new TypedValue(TEST_NAMESPACE1 + "#" + id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO)); + new TypedValue(TEST_NAMESPACE1 + "#" + id1, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, "SPDX-2.3")); try { store.delete(TEST_NAMESPACE1 + "#" + id3); @@ -703,11 +683,11 @@ public void testDeleteInUse() throws Exception { public void testReferenceCounts() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, TEST_TYPE1); - store.create(TEST_NAMESPACE1 + "#" + TEST_ID2, TEST_TYPE2); + store.create(new TypedValue(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3")); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + TEST_ID2, TEST_TYPE2, "SPDX-2.3")); StoredTypedItem item = store.getItem(TEST_OBJECT_URI1); assertEquals(0, item.getReferenceCount()); - TypedValue tv = new TypedValue(TEST_OBJECT_URI1, TEST_TYPE1); + TypedValue tv = new TypedValue(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); store.addValueToCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); @@ -732,11 +712,11 @@ public void testReferenceCounts() throws Exception { public void testReferenceCountsDelete() throws Exception { try (InMemSpdxStore store = new InMemSpdxStore()) { - store.create(TEST_OBJECT_URI1, TEST_TYPE1); - store.create(TEST_NAMESPACE1 + "#" + TEST_ID2, TEST_TYPE2); + store.create(new TypedValue(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3")); + store.create(new TypedValue(TEST_NAMESPACE1 + "#" + TEST_ID2, TEST_TYPE2, "SPDX-2.3")); StoredTypedItem item = store.getItem(TEST_OBJECT_URI1); assertEquals(0, item.getReferenceCount()); - TypedValue tv = new TypedValue(TEST_NAMESPACE1 + "#" + TEST_ID1, TEST_TYPE1); + TypedValue tv = new TypedValue(TEST_NAMESPACE1 + "#" + TEST_ID1, TEST_TYPE1, "SPDX-2.3"); store.addValueToCollection(TEST_NAMESPACE1 + "#" + TEST_ID2, new PropertyDescriptor("prop1", SpdxConstantsCompatV2.SPDX_NAMESPACE), tv); assertEquals(1, item.getReferenceCount()); diff --git a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java index bf329fe74..907ecaf2d 100644 --- a/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java +++ b/src/test/java/org/spdx/storage/simple/StoredTypedItemTest.java @@ -20,11 +20,11 @@ import java.util.Arrays; import java.util.List; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.Relationship; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.Relationship; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; import org.spdx.storage.PropertyDescriptor; import junit.framework.TestCase; @@ -59,10 +59,11 @@ public class StoredTypedItemTest extends TestCase { * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { + SpdxModelFactory.init(); TEST_LIST_PROPERTY_VALUES = new List[] {Arrays.asList("ListItem1", "listItem2", "listItem3"), Arrays.asList(true, false, true), - Arrays.asList(new TypedValue("typeId1", TEST_TYPE1), new TypedValue("typeId2", TEST_TYPE2))}; - TEST_VALUE_PROPERTY_VALUES[3] = new TypedValue("typeId3", TEST_TYPE1); + Arrays.asList(new TypedValue("typeId1", TEST_TYPE1, "SPDX-2.3"), new TypedValue("typeId2", TEST_TYPE2, "SPDX-2.3"))}; + TEST_VALUE_PROPERTY_VALUES[3] = new TypedValue("typeId3", TEST_TYPE1, "SPDX-2.3"); } /* (non-Javadoc) @@ -76,14 +77,14 @@ protected void tearDown() throws Exception { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#equals(java.lang.Object)}. */ public void testEqualsObject() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); - StoredTypedItem sti2 = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); + StoredTypedItem sti2 = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); assertTrue(sti.equals(sti2)); assertTrue(sti2.equals(sti2)); - StoredTypedItem sti3 = new StoredTypedItem(TEST_OBJECT_URI2, TEST_TYPE1); + StoredTypedItem sti3 = new StoredTypedItem(TEST_OBJECT_URI2, TEST_TYPE1, "SPDX-2.3"); assertFalse(sti.equals(sti3)); assertFalse(sti3.equals(sti)); - StoredTypedItem sti4 = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE2); + StoredTypedItem sti4 = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE2, "SPDX-2.3"); assertFalse(sti.equals(sti4)); assertFalse(sti4.equals(sti)); } @@ -92,7 +93,7 @@ public void testEqualsObject() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#getPropertyValueNames(java.lang.String, java.lang.String)}. */ public void testGetSetPropertyValueNames() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); assertEquals(0, sti.getPropertyValueDescriptors().size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { sti.setValue(TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); @@ -116,7 +117,7 @@ public void testGetSetPropertyValueNames() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#setValue(java.lang.String, java.lang.Object)}. */ public void testGetSetValue() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); Object result = sti.getValue(TEST_VALUE_PROPERTIES[0]); assertTrue(result == null); sti.setValue(TEST_VALUE_PROPERTIES[0], TEST_VALUE_PROPERTY_VALUES[0]); @@ -129,7 +130,7 @@ public void testGetSetValue() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#clearPropertyValueList(java.lang.String)}. */ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -145,7 +146,7 @@ public void testClearPropertyValueList() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#addValueToList(java.lang.String, java.lang.Object)}. */ public void testAddValueToList() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -162,7 +163,7 @@ public void testAddValueToList() throws InvalidSPDXAnalysisException { * Test method for {@link org.spdx.storage.simple.StoredTypedItem#getValueList(java.lang.String)}. */ public void testGetValueList() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -175,7 +176,7 @@ public void testGetValueList() throws InvalidSPDXAnalysisException { } public void testRemove() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); assertEquals(0, sti.getPropertyValueDescriptors().size()); for (int i = 0; i < TEST_VALUE_PROPERTIES.length; i++) { sti.setValue(TEST_VALUE_PROPERTIES[i], TEST_VALUE_PROPERTY_VALUES[i]); @@ -194,7 +195,7 @@ public void testRemove() throws InvalidSPDXAnalysisException { } public void testCollectionSize() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -206,7 +207,7 @@ public void testCollectionSize() throws InvalidSPDXAnalysisException { } public void testCollectionContains() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); for (int i = 0; i < TEST_LIST_PROPERTIES.length; i++) { for (Object value:TEST_LIST_PROPERTY_VALUES[i]) { sti.addValueToList(TEST_LIST_PROPERTIES[i], value); @@ -221,7 +222,7 @@ public void testCollectionContains() throws InvalidSPDXAnalysisException { } public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(sProperty, "String 1"); @@ -238,10 +239,10 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio assertFalse(sti.isCollectionMembersAssignableTo(bProperty, TypedValue.class)); // TypedValue PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - sti.addValueToList(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); + sti.addValueToList(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2, "SPDX-2.3")); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, String.class)); assertFalse(sti.isCollectionMembersAssignableTo(tvProperty, Boolean.class)); - assertTrue(sti.isCollectionMembersAssignableTo(tvProperty, Relationship.class, SpdxMajorVersion.VERSION_2)); + assertTrue(sti.isCollectionMembersAssignableTo(tvProperty, Relationship.class)); // Mixed PropertyDescriptor mixedProperty = new PropertyDescriptor("mixedprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.addValueToList(mixedProperty, Boolean.valueOf(true)); @@ -257,32 +258,32 @@ public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisExceptio } public void testCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); - assertTrue(sti.isPropertyValueAssignableTo(sProperty, String.class)); - assertFalse(sti.isPropertyValueAssignableTo(sProperty, Boolean.class)); - assertFalse(sti.isPropertyValueAssignableTo(sProperty, TypedValue.class)); + assertTrue(sti.isPropertyValueAssignableTo(sProperty, String.class, "SPDX-2.3")); + assertFalse(sti.isPropertyValueAssignableTo(sProperty, Boolean.class, "SPDX-2.3")); + assertFalse(sti.isPropertyValueAssignableTo(sProperty, TypedValue.class, "SPDX-2.3")); // Boolean PropertyDescriptor bProperty = new PropertyDescriptor("boolprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(bProperty, Boolean.valueOf(true)); - assertFalse(sti.isPropertyValueAssignableTo(bProperty, String.class)); - assertTrue(sti.isPropertyValueAssignableTo(bProperty, Boolean.class)); - assertFalse(sti.isPropertyValueAssignableTo(bProperty, TypedValue.class)); + assertFalse(sti.isPropertyValueAssignableTo(bProperty, String.class, "SPDX-2.3")); + assertTrue(sti.isPropertyValueAssignableTo(bProperty, Boolean.class, "SPDX-2.3")); + assertFalse(sti.isPropertyValueAssignableTo(bProperty, TypedValue.class, "SPDX-2.3")); // TypedValue PropertyDescriptor tvProperty = new PropertyDescriptor("tvprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - sti.setValue(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2)); - assertFalse(sti.isPropertyValueAssignableTo(tvProperty, String.class)); - assertFalse(sti.isPropertyValueAssignableTo(tvProperty, Boolean.class)); - assertTrue(sti.isPropertyValueAssignableTo(tvProperty, TypedValue.class)); + sti.setValue(tvProperty, new TypedValue(TEST_ID2, TEST_TYPE2, "SPDX-2.3")); + assertFalse(sti.isPropertyValueAssignableTo(tvProperty, String.class, "SPDX-2.3")); + assertFalse(sti.isPropertyValueAssignableTo(tvProperty, Boolean.class, "SPDX-2.3")); + assertTrue(sti.isPropertyValueAssignableTo(tvProperty, TypedValue.class, "SPDX-2.3")); // Empty PropertyDescriptor emptyProperty = new PropertyDescriptor("emptyprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); - assertFalse(sti.isPropertyValueAssignableTo(emptyProperty, String.class)); + assertFalse(sti.isPropertyValueAssignableTo(emptyProperty, String.class, "SPDX-2.3")); } public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { - StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1); + StoredTypedItem sti = new StoredTypedItem(TEST_OBJECT_URI1, TEST_TYPE1, "SPDX-2.3"); // String PropertyDescriptor sProperty = new PropertyDescriptor("stringprop", SpdxConstantsCompatV2.SPDX_NAMESPACE); sti.setValue(sProperty, "String 1"); From 10605d055cb0d76d51bbb87964724f0e564451ef Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sun, 26 May 2024 19:25:15 -0700 Subject: [PATCH 31/62] Upgraded listed licenses to support v2 and v3 Signed-off-by: Gary O'Neall --- .../org/spdx/library/LicenseInfoFactory.java | 201 +++ .../java/org/spdx/library/ListedLicenses.java | 282 ++++ .../org/spdx/library/ModelCopyManager.java | 2 +- .../storage/listedlicense/CrossRefJson.java | 268 ++++ .../storage/listedlicense/ExceptionJson.java | 411 +++++ .../listedlicense/ExceptionJsonTOC.java | 232 +++ .../listedlicense/IListedLicenseStore.java | 74 + .../listedlicense/LicenseCreationInfo.java | 159 ++ .../listedlicense/LicenseCreatorAgent.java | 141 ++ .../storage/listedlicense/LicenseJson.java | 559 +++++++ .../storage/listedlicense/LicenseJsonTOC.java | 264 ++++ .../SpdxListedLicenseLocalStore.java | 76 + .../SpdxListedLicenseModelStore.java | 1327 +++++++++++++++++ .../SpdxListedLicenseWebStore.java | 98 ++ .../SpdxV2ListedLicenseModelStore.java | 403 +++++ .../SpdxV3ListedLicenseModelStore.java | 409 +++++ .../storage/listedlicense/package-info.java | 28 + .../spdx/storage/simple/InMemSpdxStore.java | 3 +- .../utility/compare/LicenseCompareHelper.java | 357 ++++- .../license/LicenseExpressionParser.java | 385 +++++ .../license/LicenseParserException.java | 22 + .../spdx/utility/license/package-info.java | 24 + ...fJsonTest.java => CrossRefJsonV2Test.java} | 94 +- .../listedlicense/ExceptionJsonTOCTest.java | 7 +- .../listedlicense/ExceptionJsonTest.java | 344 +++-- .../LicenseCreationInfoTest.java | 149 ++ .../LicenseCreatorAgentTest.java | 149 ++ .../listedlicense/LicenseJsonTOCTest.java | 11 +- .../listedlicense/LicenseJsonTest.java | 358 +++-- .../SpdxListedLicenseLocalStoreTest.java | 200 ++- .../SpdxListedLicenseWebStoreTest.java | 196 ++- .../compare/LicenseCompareHelperTest.java | 42 +- .../spdx/utility/compare/UnitTestHelper.java | 15 +- 33 files changed, 6799 insertions(+), 491 deletions(-) create mode 100644 src/main/java/org/spdx/library/LicenseInfoFactory.java create mode 100644 src/main/java/org/spdx/library/ListedLicenses.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/LicenseCreationInfo.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/LicenseCreatorAgent.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/LicenseJson.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxV2ListedLicenseModelStore.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/SpdxV3ListedLicenseModelStore.java create mode 100644 src/main/java/org/spdx/storage/listedlicense/package-info.java create mode 100644 src/main/java/org/spdx/utility/license/LicenseExpressionParser.java create mode 100644 src/main/java/org/spdx/utility/license/LicenseParserException.java create mode 100644 src/main/java/org/spdx/utility/license/package-info.java rename src/test/java/org/spdx/storage/listedlicense/{CrossRefJsonTest.java => CrossRefJsonV2Test.java} (60%) create mode 100644 src/test/java/org/spdx/storage/listedlicense/LicenseCreationInfoTest.java create mode 100644 src/test/java/org/spdx/storage/listedlicense/LicenseCreatorAgentTest.java diff --git a/src/main/java/org/spdx/library/LicenseInfoFactory.java b/src/main/java/org/spdx/library/LicenseInfoFactory.java new file mode 100644 index 000000000..c46890cb5 --- /dev/null +++ b/src/main/java/org/spdx/library/LicenseInfoFactory.java @@ -0,0 +1,201 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.core.DefaultModelStore; +import org.spdx.core.DefaultStoreNotInitialized; +import org.spdx.core.IModelCopyManager; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.license.AnyLicenseInfo; +import org.spdx.library.model.v2.license.InvalidLicenseStringException; +import org.spdx.library.model.v2.license.LicenseParserException; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.storage.IModelStore; +import org.spdx.utility.license.LicenseExpressionParser; + +/** + * Factory for creating SPDXLicenseInfo objects from a Jena model + * @author Gary O'Neall + */ +public class LicenseInfoFactory { + + static final Logger logger = LoggerFactory.getLogger(LicenseInfoFactory.class.getName()); + + public static final String NOASSERTION_LICENSE_NAME = "NOASSERTION"; + public static final String NONE_LICENSE_NAME = "NONE"; + + /** + * @param licenseId SPDX Listed License ID + * @return SPDX listed license or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public static ExpandedLicensingListedLicense getListedLicenseById(String licenseId)throws InvalidSPDXAnalysisException { + return ListedLicenses.getListedLicenses().getListedLicenseById(licenseId); + } + + /** + * @param licenseId SPDX Listed License ID + * @return SPDX listed license in SPDX spec version 2.X format or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public static SpdxListedLicense getListedLicenseV2ByIdCompat(String licenseId)throws InvalidSPDXAnalysisException { + return ListedLicenses.getListedLicenses().getListedLicenseV2ById(licenseId); + } + + /** + * Parses a license string and converts it into a SPDXLicenseInfo object + * Syntax - A license set must start and end with a parenthesis "(" + * A conjunctive license set will have and AND after the first + * licenseInfo term + * A disjunctive license set will have an OR after the first + * licenseInfo term + * If there is no And or Or, then it is converted to a simple + * license type + * A space or tab must be used between license ID's and the + * keywords AND and OR + * A licenseID must NOT be "AND" or "OR" + * @param licenseString String conforming to the syntax + * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model store will be used. + * @param documentUri Document URI for the document containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model document URI will be used. + * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's + * @return an SPDXLicenseInfo created from the string + * @throws InvalidLicenseStringException + * @throws DefaultStoreNotInitialized + */ + public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, + @Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws InvalidLicenseStringException, DefaultStoreNotInitialized { + if (Objects.isNull(store)) { + store = DefaultModelStore.getDefaultModelStore(); + } + if (Objects.isNull(documentUri)) { + documentUri = DefaultModelStore.getDefaultDocumentUri(); + } + if (Objects.isNull(copyManager)) { + copyManager = DefaultModelStore.getDefaultCopyManager(); + } + try { + return LicenseExpressionParser.parseLicenseExpression(licenseString, store, documentUri, + copyManager); + } catch (LicenseParserException e) { + throw new InvalidLicenseStringException(e.getMessage(),e); + } catch (InvalidSPDXAnalysisException e) { + throw new InvalidLicenseStringException("Unexpected SPDX error parsing license string"); + } + } + + /** + * Parses a license string and converts it into a SPDXLicenseInfo object + * Syntax - A license set must start and end with a parenthesis "(" + * A conjunctive license set will have and AND after the first + * licenseInfo term + * A disjunctive license set will have an OR after the first + * licenseInfo term + * If there is no And or Or, then it is converted to a simple + * license type + * A space or tab must be used between license ID's and the + * keywords AND and OR + * A licenseID must NOT be "AND" or "OR" + * @param licenseString String conforming to the syntax + * @return an SPDXLicenseInfo created from the string + * @throws InvalidLicenseStringException + * @throws DefaultStoreNotInitialized + */ + public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitialized { + return parseSPDXLicenseString(licenseString, null, null, null); + } + + + + /** + * @param licenseID case insensitive + * @return true if the licenseID belongs to an SPDX listed license + */ + public static boolean isSpdxListedLicenseId(String licenseID) { + return ListedLicenses.getListedLicenses().isSpdxListedLicenseId(licenseID); + } + + /** + * @return Array of all SPDX listed license IDs + */ + public static List getSpdxListedLicenseIds() { + return ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); + } + + /** + * @return Version of the license list being used by the SPDXLicenseInfoFactory + */ + public static String getLicenseListVersion() { + return ListedLicenses.getListedLicenses().getLicenseListVersion(); + } + + /** + * @param objectUri exception ID + * @return true if the exception ID is a supported SPDX listed exception + */ + public static boolean isSpdxListedExceptionId(String id) { + return ListedLicenses.getListedLicenses().isSpdxListedExceptionId(id); + } + + /** + * @param objectUri + * @return the standard SPDX license exception or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public static ExpandedLicensingListedLicenseException getListedExceptionById(String id) throws InvalidSPDXAnalysisException { + return ListedLicenses.getListedLicenses().getListedExceptionById(id); + } + + /** + * @param objectUri + * @return the standard SPDX license exception in SPDX Spec V2.X format or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public static ListedLicenseException getListedExceptionV2ById(String id) throws InvalidSPDXAnalysisException { + return ListedLicenses.getListedLicenses().getListedExceptionV2ById(id); + } + + /** + * @param licenseId case insensitive license ID + * @return the case sensitive license ID + */ + public static Optional listedLicenseIdCaseSensitive(String licenseId) { + return ListedLicenses.getListedLicenses().listedLicenseIdCaseSensitive(licenseId); + } + + /** + * @param exceptionId case insensitive exception ID + * @return case sensitive ID + */ + public static Optional listedExceptionIdCaseSensitive(String exceptionId) { + return ListedLicenses.getListedLicenses().listedExceptionIdCaseSensitive(exceptionId); + } + +} diff --git a/src/main/java/org/spdx/library/ListedLicenses.java b/src/main/java/org/spdx/library/ListedLicenses.java new file mode 100644 index 000000000..b2447a658 --- /dev/null +++ b/src/main/java/org/spdx/library/ListedLicenses.java @@ -0,0 +1,282 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.library; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Properties; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.SpdxModelFactory; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.storage.IModelStore; +import org.spdx.storage.listedlicense.IListedLicenseStore; +import org.spdx.storage.listedlicense.SpdxListedLicenseLocalStore; +import org.spdx.storage.listedlicense.SpdxListedLicenseModelStore; +import org.spdx.storage.listedlicense.SpdxListedLicenseWebStore; +import org.spdx.storage.listedlicense.SpdxV2ListedLicenseModelStore; +import org.spdx.storage.listedlicense.SpdxV3ListedLicenseModelStore; + +/** + * Singleton class which holds the listed licenses + * + * @author Gary O'Neall + * + */ +public class ListedLicenses { + + static final Logger logger = LoggerFactory.getLogger(ListedLicenses.class.getName()); + private static final String PROPERTIES_DIR = "resources"; + private static final String LISTED_LICENSE_PROPERTIES_FILENAME = PROPERTIES_DIR + "/" + "licenses.properties"; + + Properties licenseProperties; + boolean onlyUseLocalLicenses; + private IListedLicenseStore baseModelStore; + private SpdxV2ListedLicenseModelStore licenseStoreV2; + private SpdxV3ListedLicenseModelStore licenseStoreV3; + private static ListedLicenses listedLicenses = null; + /** + * Lock for any modifications to the underlying licenseModelStore + */ + private static final ReadWriteLock listedLicenseModificationLock = new ReentrantReadWriteLock(); + + /** + * This constructor should only be called by the getListedLicenses method + */ + private ListedLicenses() { + licenseProperties = loadLicenseProperties(); + onlyUseLocalLicenses = Boolean.parseBoolean( + System.getProperty("SPDXParser.OnlyUseLocalLicenses", licenseProperties.getProperty("OnlyUseLocalLicenses", "false"))); + initializeLicenseModelStore(); + } + + /** + * Tries to load properties from LISTED_LICENSE_PROPERTIES_FILENAME, ignoring errors + * encountered during the process (e.g., the properties file doesn't exist, etc.). + * + * @return a (possibly empty) set of properties + */ + private static Properties loadLicenseProperties() { + listedLicenseModificationLock.writeLock().lock(); + try { + Properties licenseProperties = new Properties(); + InputStream in = null; + try { + in = ListedLicenses.class.getResourceAsStream("/" + LISTED_LICENSE_PROPERTIES_FILENAME); + if (in != null) { + licenseProperties.load(in); + } + } catch (IOException e) { + // Ignore it and fall through + logger.warn("IO Exception reading listed license properties file: " + e.getMessage()); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + logger.warn("Unable to close listed license properties file: " + e.getMessage()); + } + } + } + return licenseProperties; + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + private void initializeLicenseModelStore() { + listedLicenseModificationLock.writeLock().lock(); + try { + if (!this.onlyUseLocalLicenses) { + try { + baseModelStore = new SpdxListedLicenseWebStore(); + } catch(InvalidSPDXAnalysisException ex) { + logger.error("Unable to access the most current listed licenses from https://spdx.org/licenses - using locally cached licenses: "+ex.getMessage()); + baseModelStore = null; + } + } + if (baseModelStore == null) { + try { + baseModelStore = new SpdxListedLicenseLocalStore(); + } catch(InvalidSPDXAnalysisException ex) { + logger.error("Error loading cached SPDX licenses"); + throw new RuntimeException("Unexpected error loading SPDX Listed Licenses"); + } + } + licenseStoreV2 = new SpdxV2ListedLicenseModelStore(baseModelStore); + licenseStoreV3 = new SpdxV3ListedLicenseModelStore(baseModelStore); + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + + + public static ListedLicenses getListedLicenses() { + + ListedLicenses retval = null; + listedLicenseModificationLock.readLock().lock(); + try { + retval = listedLicenses; + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (Objects.isNull(retval)) { + listedLicenseModificationLock.writeLock().lock(); + try { + if (listedLicenses == null) { + listedLicenses = new ListedLicenses(); + } + retval = listedLicenses; + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + return retval; + } + + /** + * Resets all of the cached license information and reloads the license IDs + * NOTE: This method should be used with caution, it will negatively impact + * performance. + * @return + */ + public static ListedLicenses resetListedLicenses() { + listedLicenseModificationLock.writeLock().lock(); + try { + listedLicenses = new ListedLicenses(); + return listedLicenses; + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + + /** + * @param licenseId case insensitive + * @return true if the licenseId belongs to an SPDX listed license + */ + public boolean isSpdxListedLicenseId(String licenseId) { + return baseModelStore.isSpdxListedLicenseId(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, licenseId); + } + + /** + * @param exceptionId case insensitive + * @return true if the exceptionId belongs to an SPDX listed exception + */ + public boolean isSpdxListedExceptionId(String exceptionId) { + return this.baseModelStore.isSpdxListedExceptionId(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, exceptionId); + } + + /** + * @param licenseId SPDX Listed License ID + * @return an SPDX spec version 2 SPDX listed license or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public SpdxListedLicense getListedLicenseV2ById(String licenseId) throws InvalidSPDXAnalysisException { + return (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(this.licenseStoreV2, SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); + } + + /** + * @param exceptionId SPDX Listed License Exception ID + * @return an SPDX spec version 2 SPDX listed license exception or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public ListedLicenseException getListedExceptionV2ById(String exceptionId) throws InvalidSPDXAnalysisException { + return (ListedLicenseException)SpdxModelFactory.createModelObjectV2(this.licenseStoreV2, SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + } + + /** + * @param licenseId SPDX Listed License ID + * @return SPDX listed license or null if the ID is not in the SPDX license list + * @throws InvalidSPDXAnalysisException + */ + public ExpandedLicensingListedLicense getListedLicenseById(String licenseId) throws InvalidSPDXAnalysisException { + return new ExpandedLicensingListedLicense(this.licenseStoreV3, SpdxListedLicenseModelStore.licenseOrExceptionIdToObjectUri(licenseId), null, true); + } + + public ExpandedLicensingListedLicenseException getListedExceptionById(String exceptionId) throws InvalidSPDXAnalysisException { + return new ExpandedLicensingListedLicenseException(this.licenseStoreV3, SpdxListedLicenseModelStore.licenseOrExceptionIdToObjectUri(exceptionId), null, true); + } + + /** + * @return List of all SPDX listed license IDs + */ + public List getSpdxListedLicenseIds() { + listedLicenseModificationLock.readLock().lock(); + try { + return this.baseModelStore.getSpdxListedLicenseIds(); + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + /** + * @return The version of the loaded license list in the form M.N, where M is the major release and N is the minor release. + * If no license list is loaded, returns {@link org.spdx.storage.listedlicense.SpdxListedLicenseModelStore#DEFAULT_LICENSE_LIST_VERSION}. + */ + public String getLicenseListVersion() { + return this.baseModelStore.getLicenseListVersion(); + } + + /** + * @return list of SPDX exception IDs + */ + public List getSpdxListedExceptionIds() { + return this.baseModelStore.getSpdxListedExceptionIds(); + } + + /** + * @param licenseId case insensitive license ID + * @return the case sensitive license ID + */ + public Optional listedLicenseIdCaseSensitive(String licenseId) { + return this.baseModelStore.listedLicenseIdCaseSensitive(licenseId); + } + + /** + * @param exceptionId case insensitive exception ID + * @return case sensitive ID + */ + public Optional listedExceptionIdCaseSensitive(String exceptionId) { + return this.baseModelStore.listedExceptionIdCaseSensitive(exceptionId); + } + + /** + * @return model store for listed licenses using the version 3 SPDX model + */ + public IModelStore getLicenseModelStore() { + return this.licenseStoreV3; + } + + public IModelStore getLicenseModelStoreV2() { + return this.licenseStoreV2; + } + +} diff --git a/src/main/java/org/spdx/library/ModelCopyManager.java b/src/main/java/org/spdx/library/ModelCopyManager.java index 9137b8403..ee40f041f 100644 --- a/src/main/java/org/spdx/library/ModelCopyManager.java +++ b/src/main/java/org/spdx/library/ModelCopyManager.java @@ -258,7 +258,7 @@ public TypedValue copy(IModelStore toStore, IModelStore fromStore, String toObjectUri = getCopiedObjectUri(fromStore, sourceUri, toStore); if (Objects.isNull(toObjectUri)) { - if (toStore.exists(sourceUri)) { + if (toStore.exists(sourceUri) || IdType.Anonymous.equals(fromStore.getIdType(sourceUri))) { if (Objects.nonNull(toNamespace)) { if (SpdxConstantsCompatV2.CLASS_EXTERNAL_DOC_REF.equals(type)) { toObjectUri = toNamespace + toStore.getNextId(IdType.DocumentRef); diff --git a/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java new file mode 100644 index 000000000..ed2c924a6 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/CrossRefJson.java @@ -0,0 +1,268 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nullable; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSpdxPropertyException; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.CrossRef; +import org.spdx.storage.PropertyDescriptor; + +/** + * JSON Representation of a CrossRef + * + * @author Gary O'Neall + * + */ +class CrossRefJson { + + public String match; + public String url; + public Boolean isValid; + public Boolean isLive; + public String timestamp; + public Boolean isWayBackLink; + public Integer order; + private transient String id; // The ID is always transient and of anonymous type + + public CrossRefJson() { + // empty constructor so GSON will work + } + + /** + * @param crossRef cross ref to copy values from + * @throws InvalidSPDXAnalysisException + */ + public CrossRefJson(CrossRef crossRef) throws InvalidSPDXAnalysisException { + this.id = crossRef.getId(); + Optional fromMatch = crossRef.getMatch(); + if (fromMatch.isPresent()) { + match = fromMatch.get(); + } + Optional fromUrl = crossRef.getUrl(); + if (fromUrl.isPresent()) { + url = fromUrl.get(); + } + Optional fromIsValid = crossRef.getValid(); + if (fromIsValid.isPresent()) { + isValid = fromIsValid.get(); + } + Optional fromIsLive = crossRef.getLive(); + if (fromIsLive.isPresent()) { + isLive = fromIsLive.get(); + } + Optional fromIsWayBackLink = crossRef.getIsWayBackLink(); + if (fromIsWayBackLink.isPresent()) { + isWayBackLink = fromIsWayBackLink.get(); + } + Optional fromTimestamp = crossRef.getTimestamp(); + if (fromTimestamp.isPresent()) { + timestamp = fromTimestamp.get(); + } + Optional fromOrder = crossRef.getOrder(); + if (fromOrder.isPresent()) { + order = fromOrder.get(); + } + } + + /** + * @return all valid property descriptors + */ + public List getPropertyValueDescriptors() { + List retval = new ArrayList(); + if (Objects.nonNull(match)) { + retval.add(new PropertyDescriptor("match", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + if (Objects.nonNull(url)) { + retval.add(new PropertyDescriptor("url", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + if (Objects.nonNull(isValid)) { + retval.add(new PropertyDescriptor("isValid", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + if (Objects.nonNull(isLive)) { + retval.add(new PropertyDescriptor("isLive", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + if (Objects.nonNull(timestamp)) { + retval.add(new PropertyDescriptor("timestamp", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + if (Objects.nonNull(isWayBackLink)) { + retval.add(new PropertyDescriptor("isWayBackLink", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + if (Objects.nonNull(order)) { + retval.add(new PropertyDescriptor("order", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + return retval; + } + + /** + * Sets the value to the property name + * @param propertyDescriptor + * @param value + * @throws InvalidSpdxPropertyException + */ + public void setPrimativeValue(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + switch (propertyDescriptor.getName()) { + case "match": if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + this.match = (String)value; + break; + case "url": if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + this.url = (String)value; + break; + case "timestamp": if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + this.timestamp = (String)value; + break; + case "isValid": if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected boolean type for "+propertyDescriptor); + } + this.isValid = (Boolean)value; + break; + case "isLive": if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected boolean type for "+propertyDescriptor); + } + this.isLive = (Boolean)value; + break; + case "isWayBackLink": if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected boolean type for "+propertyDescriptor); + } + this.isWayBackLink = (Boolean)value; + break; + case "order": if (!(value instanceof Integer)) { + throw new InvalidSpdxPropertyException("Expected integer type for "+propertyDescriptor); + } + this.order = (Integer)value; + break; + default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyDescriptor); + } + } + + public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException(propertyDescriptor + " is not a list type."); + } + + public boolean addPrimitiveValueToList(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException(propertyDescriptor + " is not a list type."); + } + + public boolean removePrimitiveValueToList(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException(propertyDescriptor + " is not a list type."); + } + + public @Nullable String getId() { + return this.id; + } + + public void setId(String crossRefId) { + this.id = crossRefId; + } + + /** + * @param propertyDescriptor + * @return the list associated with the property + * @throws InvalidSpdxPropertyException + */ + public List getValueList(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException(propertyDescriptor + " is not a list type."); + } + + /** + * @param propertyDescriptor + * @return the value associated with the property - null if not assigned or not present + * @throws InvalidSpdxPropertyException + */ + public @Nullable Object getValue(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + switch (propertyDescriptor.getName()) { + case "match": return this.match; + case "url": return this.url; + case "isValid": return this.isValid; + case "isLive": return this.isLive; + case "timestamp": return this.timestamp; + case "isWayBackLink": return this.isWayBackLink; + case "order": return this.order; + default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyDescriptor); + } + } + + /** + * sets the property to null (no way to remove in this store) + * @param propertyDescriptor + * @throws InvalidSpdxPropertyException + */ + public void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + switch (propertyDescriptor.getName()) { + case "match": this.match = null; break; + case "url": this.url = null; break; + case "isValid": this.isValid = null; break; + case "isLive": this.isLive = null; break; + case "timestamp": this.timestamp = null; break; + case "isWayBackLink": this.isWayBackLink = null; break; + case "order": this.order = null; break; + default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyDescriptor); + } + } + + /** + * @param propertyDescriptor + * @param clazz + * @return true if the members can be assigned from clazz + */ + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + return false; + } + + /** + * @param propertyDescriptor + * @param clazz + * @return true if the property can be assigned from clazz + * @throws InvalidSpdxPropertyException + */ + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSpdxPropertyException { + switch (propertyDescriptor.getName()) { + case "match": + case "url": + case "timestamp": return String.class.isAssignableFrom(clazz); + case "isValid": + case "isLive": + case "isWayBackLink": return Boolean.class.isAssignableFrom(clazz); + case "order": return Integer.class.isAssignableFrom(clazz); + default: throw new InvalidSpdxPropertyException("Invalid property for CrossRef:"+propertyDescriptor); + } + + } + + /** + * @param propertyName + * @return if the property is a colloection + */ + public boolean isCollectionProperty(String propertyName) { + return false; + } +} \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java new file mode 100644 index 000000000..3b3da08cf --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/ExceptionJson.java @@ -0,0 +1,411 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSpdxPropertyException; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.storage.PropertyDescriptor; + + +/** + * Simple POJO to hold the license exception data loaded from a JSON file + * + * Licenses in the JSON format can be found at spdx.org/licenses/[exceptionid].json + * + * @author Gary O'Neall + * + */ +public class ExceptionJson { + + public static final List ALL_PROPERTY_DESCRIPTORS; + public static final Map PROPERTY_DESCRIPTOR_TO_VALUE_NAME; + static final Set COLLECTION_PROPERTIES; + + static { + Map descriptorsToValue = new HashMap<>(); + Set collectionProperties = new HashSet<>(); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_ADDITION_TEXT, "licenseExceptionText"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, "licenseExceptionText"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML, "exceptionTextHtml"); + descriptorsToValue.put(SpdxConstantsV3.PROP_NAME, "name"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_NAME, "name"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, "licenseExceptionId"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_ADDITION_TEMPLATE, "licenseExceptionTemplate"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE, "licenseExceptionTemplate"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_EXAMPLE, "example"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_DEPRECATED_ADDITION_ID, "isDeprecatedLicenseId"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, "isDeprecatedLicenseId"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_DEPRECATED_VERSION, "deprecatedVersion"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, "deprecatedVersion"); + descriptorsToValue.put(SpdxConstantsV3.PROP_COMMENT, "comment"); + descriptorsToValue.put(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, "comment"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, "licenseExceptionId"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, "seeAlso"); + collectionProperties.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + descriptorsToValue.put(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, "seeAlso"); + collectionProperties.add(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LICENSE_XML, "licenseXml"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_OBSOLETED_BY, "obsoletedBy"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LIST_VERSION_ADDED, "listVersionAdded"); + + // The following are not implemented in the JSON - they are added so there is no errors when creating V3 object classes + descriptorsToValue.put(SpdxConstantsV3.PROP_EXTERNAL_REF, "externalRef"); + collectionProperties.add(SpdxConstantsV3.PROP_EXTERNAL_REF); + descriptorsToValue.put(SpdxConstantsV3.PROP_VERIFIED_USING, "verifiedUsing"); + collectionProperties.add(SpdxConstantsV3.PROP_VERIFIED_USING); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXTENSION, "extension"); + collectionProperties.add(SpdxConstantsV3.PROP_EXTENSION); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER, "externalIdentifier"); + collectionProperties.add(SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER); + descriptorsToValue.put(SpdxConstantsV3.PROP_CREATED_USING, "createdUsing"); + collectionProperties.add(SpdxConstantsV3.PROP_CREATED_USING); + descriptorsToValue.put(SpdxConstantsV3.PROP_DESCRIPTION, "description"); + descriptorsToValue.put(SpdxConstantsV3.PROP_SUMMARY, "summary"); + PROPERTY_DESCRIPTOR_TO_VALUE_NAME = Collections.unmodifiableMap(descriptorsToValue); + ALL_PROPERTY_DESCRIPTORS = Collections.unmodifiableList(new ArrayList<>(descriptorsToValue.keySet())); + COLLECTION_PROPERTIES = Collections.unmodifiableSet(collectionProperties); + } + + Boolean isDeprecatedLicenseId; + String licenseExceptionText; + String name; + String licenseComments; //TODO: This is for legacy JSON files - this should be removed in 3.0. See https://github.com/spdx/spdx-spec/issues/158 + String comment; + List seeAlso = new ArrayList<>(); + String licenseExceptionId; + String licenseExceptionTemplate; + String example; + String deprecatedVersion; + String exceptionTextHtml; + String licenseXml; + String obsoletedBy; + String listVersionAdded; + + public ExceptionJson(String id) { + this.licenseExceptionId = id; + } + + public ExceptionJson() { + + } + + public void setTypedProperty(String propertyName, String valueId, String type) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException("Invalid type for Listed License SPDX Property: "+type); + } + + public void setPrimativeValue(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed exception:"+propertyDescriptor.getName()); + } + switch (propertyName) { + case "licenseExceptionText": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseExceptionText = (String)value; + break; + case "name": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + name = (String)value; + break; + case "seeAlso":throw new InvalidSpdxPropertyException("Expected list type for "+propertyDescriptor); + case "licenseExceptionTemplate": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseExceptionTemplate = (String)value; + break; + case "example": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + example = (String)value; + break; + case "isDeprecatedLicenseId": + if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyDescriptor); + } + isDeprecatedLicenseId = (Boolean)value; + break; + case "deprecatedVersion": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + deprecatedVersion = (String)value; + break; + case "comment": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseComments = (String)value; + comment = (String)value; + break; + case "licenseExceptionId": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseExceptionId = (String)value; + break; + case "exceptionTextHtml": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + exceptionTextHtml = (String)value; + break; + case "obsoletedBy": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + obsoletedBy = (String)value; + break; + case "licenseXml": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseXml = (String)value; + break; + case "listVersionAdded": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + listVersionAdded = (String)value; + break; + default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor); + } + } + + public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + if (!"seeAlso".equals(PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor))) { + throw new InvalidSpdxPropertyException(propertyDescriptor + "is not a list type"); + } + seeAlso.clear(); + } + + public void addValueToList(String propertyName, String valueId, String type) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException("Invalid type for Listed License SPDX Property: "+type); + } + + public boolean addPrimitiveValueToList(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + if (!"seeAlso".equals(PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor))) { + throw new InvalidSpdxPropertyException(propertyDescriptor + "is not a list type"); + } + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + return seeAlso.add((String)value); + } + + public List getValueList(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + if ("seeAlso".equals(PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor))) { + return seeAlso; + } else if (COLLECTION_PROPERTIES.contains(propertyDescriptor)) { + return new ArrayList<>(); + } else { + throw new InvalidSpdxPropertyException(propertyDescriptor + "is not a list type"); + } + } + + public Object getValue(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + return null; // unsupported property + } + switch (propertyName) { + case "licenseExceptionText": return licenseExceptionText; + case "name": return name; + case "seeAlso":return seeAlso; + case "licenseExceptionTemplate": return licenseExceptionTemplate; + case "example": return example; + case "isDeprecatedLicenseId": return isDeprecatedLicenseId; + case "deprecatedVersion": return deprecatedVersion; + case "comment": + if (comment != null) return comment; + return licenseComments; + case "licenseExceptionId": return licenseExceptionId; + case "exceptionTextHtml": return exceptionTextHtml; + case "licenseXml": return licenseXml; + case "obsoletedBy": return obsoletedBy; + case "listVersionAdded": return listVersionAdded; + default: return null; // unsupported property + } + } + + public void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed exception:"+propertyDescriptor.getName()); + } + switch (propertyName) { + case "licenseExceptionText": licenseExceptionText = null; break; + case "name": name = null; break; + case "seeAlso":seeAlso.clear(); break; + case "licenseExceptionTemplate": licenseExceptionTemplate = null; break; + case "example": example = null; break; + case "isDeprecatedLicenseId": isDeprecatedLicenseId = null; break; + case "deprecatedVersion": deprecatedVersion = null; break; + case "comment": + comment = null; + licenseComments = null; break; + case "licenseExceptionId": licenseExceptionId = null; break; + case "exceptionTextHtml": exceptionTextHtml = null; break; + case "licenseXml": licenseXml = null; break; + case "obsoletedBy": obsoletedBy = null; break; + case "listVersionAdded": listVersionAdded = null; break; + default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor); + } + + } + + public void copyFrom(ExpandedLicensingListedLicenseException fromException) throws InvalidSPDXAnalysisException { + this.comment = fromException.getComment().orElse(null); + this.deprecatedVersion = fromException.getExpandedLicensingDeprecatedVersion().orElse(null); + this.isDeprecatedLicenseId = fromException.getExpandedLicensingIsDeprecatedAdditionId().orElse(false); + this.licenseExceptionId = SpdxListedLicenseModelStore.objectUriToLicenseOrExceptionId(fromException.getObjectUri()); + this.licenseExceptionTemplate = fromException.getExpandedLicensingStandardAdditionTemplate().orElse(null); + this.licenseExceptionText = fromException.getExpandedLicensingAdditionText(); + this.name = fromException.getName().orElse(null); + this.seeAlso = new ArrayList(fromException.getExpandedLicensingSeeAlsos()); + this.obsoletedBy = fromException.getExpandedLicensingObsoletedBy().orElse(null); + this.listVersionAdded = fromException.getExpandedLicensingListVersionAdded().orElse(null); + this.licenseXml = fromException.getExpandedLicensingLicenseXml().orElse(null); + } + + @SuppressWarnings("deprecation") + public void copyFrom(ListedLicenseException fromException) throws InvalidSPDXAnalysisException { + this.comment = null; + this.licenseComments = fromException.getComment(); + if (Objects.nonNull(this.licenseComments) && this.licenseComments.isEmpty()) { + this.licenseComments = null; + } + this.deprecatedVersion = fromException.getDeprecatedVersion(); + if (Objects.nonNull(this.deprecatedVersion) && this.deprecatedVersion.isEmpty()) { + this.deprecatedVersion = null; + } + this.example = fromException.getExample(); + if (Objects.nonNull(this.example) && this.example.isEmpty()) { + this.example = null; + } + this.isDeprecatedLicenseId = fromException.isDeprecated(); + this.licenseExceptionId = fromException.getId(); + this.licenseExceptionTemplate = fromException.getLicenseExceptionTemplate(); + if (Objects.nonNull(this.licenseExceptionTemplate) && this.licenseExceptionTemplate.isEmpty()) { + this.licenseExceptionTemplate = null; + } + this.licenseExceptionText = fromException.getLicenseExceptionText(); + if (Objects.nonNull(this.licenseExceptionText) && this.licenseExceptionText.isEmpty()) { + this.licenseExceptionText = null; + } + this.name = fromException.getName(); + if (Objects.nonNull(this.name) && this.name.isEmpty()) { + this.name = null; + } + this.seeAlso = new ArrayList(fromException.getSeeAlso()); + this.exceptionTextHtml = fromException.getExceptionTextHtml(); + if (Objects.nonNull(this.exceptionTextHtml) && this.exceptionTextHtml.isEmpty()) { + this.exceptionTextHtml = null; + } + } + + public boolean removePrimitiveValueToList(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + if (!"seeAlso".equals(PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor))) { + throw new InvalidSpdxPropertyException(propertyDescriptor + "is not a list type"); + } + return seeAlso.remove(value); + } + + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed exception:"+propertyDescriptor.getName()); + } + switch (propertyName) { + case "licenseExceptionText": + case "name": + case "licenseExceptionTemplate": + case "example": + case "comment": + case "deprecatedVersion": + case "exceptionTextHtml": + case "obsoletedBy": + case "licenseXml": + case "listVersionAdded": + case "licenseExceptionId": return String.class.isAssignableFrom(clazz); + case "seeAlso": return false; + case "isDeprecatedLicenseId": return Boolean.class.isAssignableFrom(clazz); + default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor); + } + } + + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) { + if (SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.equals(propertyDescriptor) || + SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO.equals(propertyDescriptor)) { + return String.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTERNAL_REF.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalRef.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_VERIFIED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.IntegrityMethod.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTENSION.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.extension.ExtensionExtension.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalIdentifier.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_CREATED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.Tool.class.isAssignableFrom(clazz); + } else { + return false; + } + } + + public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) { + return COLLECTION_PROPERTIES.contains(propertyDescriptor); + } + + /** + * @return all present property descriptors + */ + public List getPropertyValueDescriptors() { + List retval = new ArrayList<>(); + ALL_PROPERTY_DESCRIPTORS.forEach(propDescriptor -> { + try { + if (Objects.nonNull(getValue(propDescriptor))) { + retval.add(propDescriptor); + } + } catch (InvalidSpdxPropertyException e) { + // ignore - assume missing + } + }); + return retval; + } + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java b/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java new file mode 100644 index 000000000..70e0b49b3 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/ExceptionJsonTOC.java @@ -0,0 +1,232 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.license.ListedLicenseException; + + +/** + * Table of Contents for the listed license list as represented as a JSON index file + * at spdx.org/licenses/licenses.json + * + * @author Gary O'Neall + * + */ +public class ExceptionJsonTOC { + static class ExceptionJson { + private String reference; + private boolean isDeprecatedLicenseId; + private String detailsUrl; + private int referenceNumber; + private String name; + private String licenseExceptionId; + private List seeAlso; + /** + * @return the licenseExceptionId + */ + public String getLicenseExceptionId() { + return licenseExceptionId; + } + /** + * @return the reference + */ + public String getReference() { + return reference; + } + /** + * @return the isDeprecatedLicenseId + */ + public boolean isDeprecatedLicenseId() { + return isDeprecatedLicenseId; + } + /** + * @return the detailsUrl + */ + public String getDetailsUrl() { + return detailsUrl; + } + /** + * @return the referenceNumber + */ + public int getReferenceNumber() { + return referenceNumber; + } + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @return the seeAlso + */ + public List getSeeAlso() { + return seeAlso; + } + /** + * @param reference the reference to set + */ + public void setReference(String reference) { + this.reference = reference; + } + /** + * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set + */ + public void setDeprecatedLicenseId(boolean isDeprecatedLicenseId) { + this.isDeprecatedLicenseId = isDeprecatedLicenseId; + } + /** + * @param detailsUrl the detailsUrl to set + */ + public void setDetailsUrl(String detailsUrl) { + this.detailsUrl = detailsUrl; + } + /** + * @param referenceNumber the referenceNumber to set + */ + public void setReferenceNumber(int referenceNumber) { + this.referenceNumber = referenceNumber; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @param licenseExceptionId the licenseExceptionId to set + */ + public void setLicenseExceptionId(String licenseExceptionId) { + this.licenseExceptionId = licenseExceptionId; + } + /** + * @param seeAlso the seeAlso to set + */ + public void setSeeAlso(List seeAlso) { + this.seeAlso = seeAlso; + } + } + + + private String licenseListVersion; + private List exceptions; + private String releaseDate; + + public ExceptionJsonTOC(String version, String releaseDate) { + this.licenseListVersion = version; + this.releaseDate = releaseDate; + exceptions = new ArrayList<>(); + } + + public ExceptionJsonTOC() { + licenseListVersion = null; + exceptions = new ArrayList<>(); + releaseDate = null; + } + + /** + * @return the licenseListVersion + */ + public @Nullable String getLicenseListVersion() { + return licenseListVersion; + } + + /** + * @return the exceptions + */ + public List getExceptions() { + return exceptions; + } + + /** + * @return map of lower case to correct case exception IDs + */ + public Map getExceptionIds() { + Map retval = new HashMap<>(); + if (exceptions == null) { + return retval; + } + for (ExceptionJson licenseException:exceptions) { + retval.put(licenseException.licenseExceptionId.toLowerCase(), licenseException.licenseExceptionId); + } + return retval; + } + + /** + * @return the releaseDate + */ + public @Nullable String getReleaseDate() { + return releaseDate; + } + + /** + * Add a new exception to the list of exceptions + * @param exception + * @param exceptionHTMLReference + * @param exceptionJSONReference + * @param deprecated + * @throws InvalidSPDXAnalysisException + */ + public void addException(ListedLicenseException exception, String exceptionHTMLReference, + String exceptionJSONReference, boolean deprecated) throws InvalidSPDXAnalysisException { + ExceptionJson ej = new ExceptionJson(); + ej.setLicenseExceptionId(exception.getId()); + ej.setDeprecatedLicenseId(deprecated); + ej.setDetailsUrl(exceptionHTMLReference); + ej.setName(exception.getName()); + ej.setReference(exceptionJSONReference); + int referenceNumber = 0; + for (ExceptionJson existing:this.exceptions) { + if (existing.getReferenceNumber() > referenceNumber) { + referenceNumber = existing.getReferenceNumber(); + } + } + referenceNumber++; + ej.setReferenceNumber(referenceNumber); + List seeAlso = new ArrayList<>(); + for (String sa:exception.getSeeAlso()) { + seeAlso.add(sa); + } + ej.setSeeAlso(seeAlso); + this.exceptions.add(ej); + } + + /** + * @param licenseListVersion the licenseListVersion to set + */ + public void setLicenseListVersion(String licenseListVersion) { + this.licenseListVersion = licenseListVersion; + } + + /** + * @param releaseDate the releaseDate to set + */ + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java b/src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java new file mode 100644 index 000000000..27fdb9d44 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/IListedLicenseStore.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.List; +import java.util.Optional; + +import org.spdx.storage.IModelStore; + +/** + * @author Gary O'Neall + * + * Extends the model store to include interfaces specific to listed licenses + * + */ +public interface IListedLicenseStore extends IModelStore { + + /** + * @return List of all SPDX listed license IDs + */ + List getSpdxListedLicenseIds(); + + /** + * @return The version of the loaded license list in the form M.N, where M is the major release and N is the minor release. + */ + String getLicenseListVersion(); + + /** + * @param listedLicenseDocumentUri + * @param licenseId + * @return true if the licenseId belongs to an SPDX listed license + */ + boolean isSpdxListedLicenseId(String listedLicenseDocumentUri, String licenseId); + + /** + * @param listedLicenseDocumentUri + * @param exceptionId + * @return true if the exceptionId belongs to an SPDX listed exception + */ + boolean isSpdxListedExceptionId(String listedLicenseDocumentUri, String exceptionId); + + /** + * @return list of SPDX exception IDs + */ + List getSpdxListedExceptionIds(); + + /** + * @param licenseId case insensitive license ID + * @return the case sensitive license ID + */ + Optional listedLicenseIdCaseSensitive(String licenseId); + + /** + * @param exceptionId case insensitive exception ID + * @return case sensitive ID + */ + Optional listedExceptionIdCaseSensitive(String exceptionId); + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseCreationInfo.java b/src/main/java/org/spdx/storage/listedlicense/LicenseCreationInfo.java new file mode 100644 index 000000000..a193d601f --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseCreationInfo.java @@ -0,0 +1,159 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +import org.spdx.core.ModelRegistryException; +import org.spdx.core.SpdxInvalidIdException; +import org.spdx.core.SpdxInvalidTypeException; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.storage.PropertyDescriptor; + +/** + * @author Gary O'Neall + * + * Creation information for the listed license store + * + */ +public class LicenseCreationInfo { + + static final String CREATION_INFO_URI = "__creation_info"; + + public static final List ALL_PROPERTY_DESCRIPTORS; + public static final Map PROPERTY_TO_STATIC_VALUE; + + static { + Map ptosv = new HashMap<>(); + ptosv.put(SpdxConstantsV3.PROP_COMMENT, "This is a generated SPDX License object from the SPDX license list"); + ptosv.put(SpdxConstantsV3.PROP_CREATED, null); // this needs to be filled in with the creation date of the license list itself + ptosv.put(SpdxConstantsV3.PROP_CREATED_BY, null); // this also needs to be created + ptosv.put(SpdxConstantsV3.PROP_SPEC_VERSION, SpdxConstantsV3.MODEL_SPEC_VERSION); + PROPERTY_TO_STATIC_VALUE = Collections.unmodifiableMap(ptosv); + ALL_PROPERTY_DESCRIPTORS = Collections.unmodifiableList(new ArrayList<>(ptosv.keySet())); + }; + + private static List EMPTY = Collections.unmodifiableList(new ArrayList<>()); + + private String created; + private List creators; + + TypedValue typedValue; + + /** + * @param licenseListCreator + * @param licenseListReleaseDate + * @throws ModelRegistryException + * @throws SpdxInvalidTypeException + * @throws SpdxInvalidIdException + */ + public LicenseCreationInfo(LicenseCreatorAgent licenseListCreator, + String licenseListReleaseDate) throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + this.created = Pattern.matches("^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ$", licenseListReleaseDate) ? + licenseListReleaseDate : new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); + this.creators = Collections.unmodifiableList(Arrays.asList(licenseListCreator.getTypedValue())); + this.typedValue = new TypedValue(LicenseCreationInfo.CREATION_INFO_URI, SpdxConstantsV3.CORE_CREATION_INFO, SpdxConstantsV3.MODEL_SPEC_VERSION); + } + + public TypedValue getTypedValue() { + return this.typedValue; + } + + /** + * @param propertyDescriptor + * @return true if it is a collection property + */ + public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) { + return SpdxConstantsV3.PROP_CREATED_BY.equals(propertyDescriptor); + } + + /** + * @param propertyDescriptor + * @return list of values for a collection + */ + public List getValueList(PropertyDescriptor propertyDescriptor) { + if (SpdxConstantsV3.PROP_CREATED_BY.equals(propertyDescriptor)) { + return creators; + } else { + return EMPTY; + } + } + + /** + * @param propertyDescriptor + * @return value if present, otherwise null + */ + public Object getValue(PropertyDescriptor propertyDescriptor) { + if (SpdxConstantsV3.PROP_CREATED_BY.equals(propertyDescriptor)) { + return creators; + } else if (SpdxConstantsV3.PROP_CREATED.equals(propertyDescriptor)) { + return created; + } else { + return PROPERTY_TO_STATIC_VALUE.get(propertyDescriptor); + } + } + + /** + * @param propertyDescriptor + * @param clazz + * @return + */ + public boolean isCollectionMembersAssignableTo( + PropertyDescriptor propertyDescriptor, Class clazz) { + if (SpdxConstantsV3.PROP_EXTERNAL_REF.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalRef.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_VERIFIED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.IntegrityMethod.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTENSION.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.extension.ExtensionExtension.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalIdentifier.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_CREATED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.Tool.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_CREATED_BY.equals(propertyDescriptor)) { + return (Agent.class.equals(clazz) || LicenseCreatorAgent.class.equals(clazz)); + } else { + return false; + } + } + + /** + * @param propertyDescriptor + * @param clazz + * @return + */ + public boolean isPropertyValueAssignableTo( + PropertyDescriptor propertyDescriptor, Class clazz) { + return String.class.equals(clazz) && + (SpdxConstantsV3.PROP_COMMENT.equals(propertyDescriptor) || + SpdxConstantsV3.PROP_SPEC_VERSION.equals(propertyDescriptor) || + SpdxConstantsV3.PROP_CREATED.equals(propertyDescriptor)); + } + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseCreatorAgent.java b/src/main/java/org/spdx/storage/listedlicense/LicenseCreatorAgent.java new file mode 100644 index 000000000..2f7dd6f85 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseCreatorAgent.java @@ -0,0 +1,141 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistryException; +import org.spdx.core.SpdxInvalidIdException; +import org.spdx.core.SpdxInvalidTypeException; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.storage.PropertyDescriptor; + +/** + * @author Gary O'Neall + * + * Storage for the creator agent of the license list + * + */ +public class LicenseCreatorAgent { + + static final String OBJECT_URI_PREFIX = "https://spdx.org/licenses/creatoragent/"; + public static final List ALL_PROPERTY_DESCRIPTORS = Collections.unmodifiableList(Arrays.asList( + SpdxConstantsV3.PROP_CREATION_INFO, SpdxConstantsV3.PROP_NAME, SpdxConstantsV3.PROP_DESCRIPTION)); + static final List EMPTY = Collections.unmodifiableList(new ArrayList<>()); + static final String NAME = "SPDX Legal Team"; + static final String DESCRIPTION = "This object is created and maintained by the SPDX legal team (https://spdx.dev/engage/participate/legal-team/)"; + private String objectUri; + private TypedValue typedValue; + private TypedValue creationInfoTV; + + public LicenseCreatorAgent(String licenseListVersion) throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + this.objectUri = OBJECT_URI_PREFIX + licenseListVersion.replace('.','_'); + this.typedValue = new TypedValue(objectUri, SpdxConstantsV3.CORE_AGENT, SpdxConstantsV3.MODEL_SPEC_VERSION); + this.creationInfoTV = new TypedValue(LicenseCreationInfo.CREATION_INFO_URI, SpdxConstantsV3.CORE_CREATION_INFO, SpdxConstantsV3.MODEL_SPEC_VERSION); + } + + public String getObjectUri() { + return this.objectUri; + } + + /** + * @return + */ + public TypedValue getTypedValue() { + return this.typedValue; + } + + /** + * @param propertyDescriptor + * @return + */ + public List getValueList(PropertyDescriptor propertyDescriptor) { + return EMPTY; + } + + /** + * @param propertyDescriptor + * @return value if present, otherwise null + * @throws InvalidSPDXAnalysisException + */ + public Object getValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + if (SpdxConstantsV3.PROP_CREATION_INFO.equals(propertyDescriptor)) { + return this.creationInfoTV; + } else if (SpdxConstantsV3.PROP_NAME.equals(propertyDescriptor)) { + return NAME; + } else if (SpdxConstantsV3.PROP_DESCRIPTION.equals(propertyDescriptor)) { + return DESCRIPTION; + } else { + return null; + } + } + + /** + * @param propertyDescriptor + * @param clazz + * @return + */ + public boolean isCollectionMembersAssignableTo( + PropertyDescriptor propertyDescriptor, Class clazz) { + if (SpdxConstantsV3.PROP_EXTERNAL_REF.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalRef.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_VERIFIED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.IntegrityMethod.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTENSION.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.extension.ExtensionExtension.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalIdentifier.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_CREATED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.Tool.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_CREATED_BY.equals(propertyDescriptor)) { + return (Agent.class.equals(clazz) || LicenseCreatorAgent.class.equals(clazz)); + } else { + return false; + } + } + + /** + * @param propertyDescriptor + * @param clazz + * @return + */ + public boolean isPropertyValueAssignableTo( + PropertyDescriptor propertyDescriptor, Class clazz) { + return (String.class.equals(clazz) && + (SpdxConstantsV3.PROP_NAME.equals(propertyDescriptor) || + SpdxConstantsV3.PROP_DESCRIPTION.equals(propertyDescriptor))) || + ((CreationInfo.class.equals(clazz) || LicenseCreationInfo.class.equals(clazz)) + && SpdxConstantsV3.PROP_CREATION_INFO.equals(propertyDescriptor)); + } + + /** + * @param propertyDescriptor + * @return + */ + public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) { + return false; + } + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java new file mode 100644 index 000000000..cc2f85900 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseJson.java @@ -0,0 +1,559 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSpdxPropertyException; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.CrossRef; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.licenseTemplate.InvalidLicenseTemplateException; +import org.spdx.storage.PropertyDescriptor; + +/** + * Simple POJO to hold the license data loaded from a JSON file + * + * Licenses in the JSON format can be found at spdx.org/licenses/[licenseid].json + * + * @author Gary O'Neall + * + */ +public class LicenseJson { + + static final Map PROPERTY_DESCRIPTOR_TO_VALUE_NAME; + static final List ALL_PROPERTY_DESCRIPTORS; + static final Set COLLECTION_PROPERTIES; + + static { + Map descriptorsToValue = new HashMap<>(); + Set collectionProperties = new HashSet<>(); + descriptorsToValue.put(SpdxConstantsV3.PROP_SIMPLE_LICENSING_LICENSE_TEXT, "licenseText"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_TEXT, "licenseText"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML, "licenseTextHtml"); + descriptorsToValue.put(SpdxConstantsV3.PROP_NAME, "name"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_NAME, "name"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_NAME, "name"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_LICENSE_HEADER, "standardLicenseHeader"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE, "standardLicenseHeader"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE, "standardLicenseHeaderTemplate"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML, "standardLicenseHeaderHtml"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_LICENSE_TEMPLATE, "standardLicenseTemplate"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE, "standardLicenseTemplate"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_OSI_APPROVED, "isOsiApproved"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED, "isOsiApproved"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_FSF_LIBRE, "isFsfLibre"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE, "isFsfLibre"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_EXAMPLE, "example"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_DEPRECATED_LICENSE_ID, "isDeprecatedLicenseId"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, "isDeprecatedLicenseId"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_DEPRECATED_VERSION, "deprecatedVersion"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, "deprecatedVersion"); + descriptorsToValue.put(SpdxConstantsV3.PROP_COMMENT, "comment"); + descriptorsToValue.put(SpdxConstantsCompatV2.RDFS_PROP_COMMENT, "comment"); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_LICENSE_ID, "licenseId"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, "seeAlso"); + collectionProperties.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + descriptorsToValue.put(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, "seeAlso"); + collectionProperties.add(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + descriptorsToValue.put(SpdxConstantsCompatV2.PROP_CROSS_REF, "crossRef"); + collectionProperties.add(SpdxConstantsCompatV2.PROP_CROSS_REF); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LICENSE_XML, "licenseXml"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_OBSOLETED_BY, "obsoletedBy"); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LIST_VERSION_ADDED, "listVersionAdded"); + descriptorsToValue.put(SpdxConstantsV3.PROP_CREATION_INFO, "creationInfo"); + + // The following are not implemented in the JSON - they are added so there is no errors when creating V3 object classes + descriptorsToValue.put(SpdxConstantsV3.PROP_EXTERNAL_REF, "externalRef"); + collectionProperties.add(SpdxConstantsV3.PROP_EXTERNAL_REF); + descriptorsToValue.put(SpdxConstantsV3.PROP_VERIFIED_USING, "verifiedUsing"); + collectionProperties.add(SpdxConstantsV3.PROP_VERIFIED_USING); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXTENSION, "extension"); + collectionProperties.add(SpdxConstantsV3.PROP_EXTENSION); + descriptorsToValue.put(SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER, "externalIdentifier"); + collectionProperties.add(SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER); + descriptorsToValue.put(SpdxConstantsV3.PROP_CREATED_USING, "createdUsing"); + collectionProperties.add(SpdxConstantsV3.PROP_CREATED_USING); + descriptorsToValue.put(SpdxConstantsV3.PROP_DESCRIPTION, "description"); + descriptorsToValue.put(SpdxConstantsV3.PROP_SUMMARY, "summary"); + + PROPERTY_DESCRIPTOR_TO_VALUE_NAME = Collections.unmodifiableMap(descriptorsToValue); + ALL_PROPERTY_DESCRIPTORS = Collections.unmodifiableList(new ArrayList<>(descriptorsToValue.keySet())); + COLLECTION_PROPERTIES = Collections.unmodifiableSet(collectionProperties); + } + + Boolean isDeprecatedLicenseId; + Boolean isFsfLibre; + String licenseText; + String standardLicenseHeaderTemplate; + String standardLicenseTemplate; + String name; + String licenseComments; //TODO: This is for legacy JSON files - this should be removed in 3.0. See https://github.com/spdx/spdx-spec/issues/158 + String comment; + String licenseId; + String standardLicenseHeader; + List crossRef = new ArrayList<>(); + List seeAlso = new ArrayList<>(); + Boolean isOsiApproved; + String licenseTextHtml; + String standardLicenseHeaderHtml; + String example; + String deprecatedVersion; + String obsoletedBy; + String licenseXml; + String listVersionAdded; + + public LicenseJson(String id) { + this.licenseId = id; + } + + public LicenseJson() { + + } + + public void setTypedProperty(String propertyName, String valueId, String type) throws InvalidSpdxPropertyException { + throw new InvalidSpdxPropertyException("Invalid type for Listed License SPDX Property: "+type); + } + + public void setPrimativeValue(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + switch (propertyName) { + case "licenseText": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseText = (String)value; + break; + case "licenseTextHtml": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseTextHtml = (String)value; + break; + case "name": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + name = (String)value; + break; + case "seeAlso": + case "crossRef": throw new InvalidSpdxPropertyException("Expected list type for "+propertyDescriptor); + case "standardLicenseHeader": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + standardLicenseHeader = (String)value; + break; + case "standardLicenseHeaderTemplate": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + standardLicenseHeaderTemplate = (String)value; + break; + case "standardLicenseHeaderHtml": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + standardLicenseHeaderHtml = (String)value; + break; + case "standardLicenseTemplate": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + standardLicenseTemplate = (String)value; + break; + case "isOsiApproved": + if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyDescriptor); + } + isOsiApproved = (Boolean)value; + break; + case "isFsfLibre": + if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyDescriptor); + } + isFsfLibre = (Boolean)value; + break; + case "example": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + example = (String)value; + break; + case "isDeprecatedLicenseId": + if (!(value instanceof Boolean)) { + throw new InvalidSpdxPropertyException("Expected Boolean type for "+propertyDescriptor); + } + isDeprecatedLicenseId = (Boolean)value; + break; + case "deprecatedVersion": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + deprecatedVersion = (String)value; + break; + case "comment": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseComments = (String)value; + comment = (String)value; + break; + case "licenseId": + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseId = (String)value; + break; + case "obsoletedBy": if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + obsoletedBy = (String)value; + break; + case "licenseXml": if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + licenseXml = (String)value; + break; + case "listVersionAdded": if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + listVersionAdded = (String)value; + break; + default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); + } + } + + public void clearPropertyValueList(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + if ("seeAlso".equals(propertyName)) { + seeAlso.clear(); + } else if ("crossRef".equals(propertyName)) { + crossRef.clear(); + } else { + throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); + } + + } + + /** + * Add a cross reference to a value list + * @param propertyDescriptor + * @param value + * @return true as specified by Collections.add + * @throws InvalidSPDXAnalysisException + */ + public boolean addCrossRefValueToList(PropertyDescriptor propertyDescriptor, CrossRefJson value) throws InvalidSPDXAnalysisException { + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { + return crossRef.add(value); + } else { + throw new InvalidSpdxPropertyException(propertyDescriptor + "is not a crossRef list type"); + } + } + + /** + * Add a primitive value to a value list + * @param propertyDescriptor + * @param value + * @return true as specified by Collections.add + * @throws InvalidSPDXAnalysisException + */ + public boolean addPrimitiveValueToList(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + if ("seeAlso".equals(propertyName)) { + if (!(value instanceof String)) { + throw new InvalidSpdxPropertyException("Expected string type for "+propertyDescriptor); + } + return seeAlso.add((String)value); + } else if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { + if (!(value instanceof CrossRefJson)) { + throw new InvalidSpdxPropertyException("Expected CrossRefJson type for "+propertyDescriptor); + } + return crossRef.add((CrossRefJson)value); + } else { + throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); + } + } + + public boolean removePrimitiveValueToList(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + if ("seeAlso".equals(propertyName)) { + return seeAlso.remove(value); + } else if ("crossRef".equals(propertyName)) { + return crossRef.remove(value); + } else { + throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); + } + } + + public List getValueList(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + return new ArrayList<>(); // unsupported property + } + if ("seeAlso".equals(propertyName)) { + return seeAlso; + } else if ("crossRef".equals(propertyName)) { + return crossRef; + } else if (COLLECTION_PROPERTIES.contains(propertyDescriptor)) { + return new ArrayList<>(); // not supported in JSON - just return empty + } else { + throw new InvalidSpdxPropertyException(propertyName + "is not a list type"); + } + } + + public Object getValue(PropertyDescriptor descriptor) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(descriptor); + if (Objects.isNull(propertyName)) { + return null; // unsupport property type + } + switch (propertyName) { + case "licenseText": return licenseText; + case "licenseTextHtml": return licenseTextHtml; + case "name": return name; + case "seeAlso": return seeAlso; + case "crossRef": return crossRef; + case "standardLicenseHeader": return standardLicenseHeader; + case "standardLicenseHeaderTemplate": return standardLicenseHeaderTemplate; + case "standardLicenseHeaderHtml": return standardLicenseHeaderHtml; + case "standardLicenseTemplate": return standardLicenseTemplate; + case "isOsiApproved": return isOsiApproved; + case "isFsfLibre": return isFsfLibre; + case "example": return example; + case "isDeprecatedLicenseId": return isDeprecatedLicenseId; + case "deprecatedVersion": return deprecatedVersion; + case "comment": + if (comment != null) return comment; + return licenseComments; + case "licenseId": return licenseId; + case "licenseXml": return licenseXml; + case "listVersionAdded": return listVersionAdded; + case "obsoletedBy": return obsoletedBy; + default: return null; // unsupportd property type + } + } + + public void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + switch (propertyName) { + case "licenseText": licenseText = null; break; + case "licenseTextHtml": licenseTextHtml = null; break; + case "name": name = null; break; + case "seeAlso":seeAlso.clear(); break; + case "crossRef":crossRef.clear(); break; + case "standardLicenseHeader": standardLicenseHeader = null; break; + case "standardLicenseHeaderTemplate": standardLicenseHeaderTemplate = null; break; + case "standardLicenseHeaderHtml": standardLicenseHeaderHtml = null; break; + case "standardLicenseTemplate": standardLicenseTemplate = null; break; + case "isOsiApproved": isOsiApproved = null; break; + case "isFsfLibre": isFsfLibre = null; break; + case "example": example = null; break; + case "isDeprecatedLicenseId": isDeprecatedLicenseId = null; break; + case "deprecatedVersion": deprecatedVersion = null; break; + case "comment": + comment = null; + licenseComments = null; break; + case "licenseId": licenseId = null; break; + case "licenseXml": licenseXml = null; break; + case "listVersionAdded": listVersionAdded = null; break; + case "obsoletedBy": obsoletedBy = null; break; + default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); + } + } + + /** + * @param license + * @throws InvalidSPDXAnalysisException + */ + public void copyFrom(ExpandedLicensingListedLicense fromLicense) throws InvalidSPDXAnalysisException { + this.comment = fromLicense.getComment().orElse(null); + this.deprecatedVersion = fromLicense.getExpandedLicensingDeprecatedVersion().orElse(null); + this.example = null; + this.isDeprecatedLicenseId = fromLicense.getExpandedLicensingIsDeprecatedLicenseId().orElse(false); + this.isFsfLibre = fromLicense.getExpandedLicensingIsFsfLibre().orElse(null); + this.licenseText = fromLicense.getSimpleLicensingLicenseText(); + this.licenseTextHtml = null; + this.name = fromLicense.getName().orElse(null); + this.isOsiApproved = fromLicense.getExpandedLicensingIsOsiApproved().orElse(false); + this.seeAlso = new ArrayList<>(fromLicense.getExpandedLicensingSeeAlsos()); + this.standardLicenseHeader = fromLicense.getExpandedLicensingStandardLicenseHeader().orElse(null); + this.standardLicenseHeaderHtml = null; + this.standardLicenseTemplate = fromLicense.getExpandedLicensingStandardLicenseTemplate().orElse(null); + this.crossRef.clear(); + this.obsoletedBy = fromLicense.getExpandedLicensingObsoletedBy().orElse(null); + this.licenseXml = fromLicense.getExpandedLicensingLicenseXml().orElse(null); + this.listVersionAdded = fromLicense.getExpandedLicensingListVersionAdded().orElse(null); + } + + public void copyFrom(SpdxListedLicense fromLicense) throws InvalidLicenseTemplateException, InvalidSPDXAnalysisException { + this.licenseComments = null; + this.comment = fromLicense.getComment(); + if (Objects.nonNull(this.comment) && this.comment.isEmpty()) { + this.comment = null; + } + this.licenseComments = fromLicense.getComment(); + if (Objects.nonNull(this.licenseComments) && this.licenseComments.isEmpty()) { + this.licenseComments = null; + } + this.deprecatedVersion = fromLicense.getDeprecatedVersion(); + if (Objects.nonNull(this.deprecatedVersion) && this.deprecatedVersion.isEmpty()) { + this.deprecatedVersion = null; + } + this.example = null; + this.isDeprecatedLicenseId = fromLicense.isDeprecated(); + this.isFsfLibre = fromLicense.getFsfLibre(); + this.licenseId = fromLicense.getId(); + this.licenseText = fromLicense.getLicenseText(); + if (Objects.nonNull(this.licenseText) && this.licenseText.isEmpty()) { + this.licenseText = null; + } + this.licenseTextHtml = fromLicense.getLicenseTextHtml(); + if (Objects.nonNull(this.licenseTextHtml) && this.licenseTextHtml.isEmpty()) { + this.licenseTextHtml = null; + } + this.name = fromLicense.getName(); + if (Objects.nonNull(this.name) && this.name.isEmpty()) { + this.name = null; + } + this.isOsiApproved = fromLicense.isOsiApproved(); + this.seeAlso = new ArrayList(fromLicense.getSeeAlso()); + this.standardLicenseHeader = fromLicense.getStandardLicenseHeader(); + if (Objects.nonNull(this.standardLicenseHeader) && this.standardLicenseHeader.isEmpty()) { + this.standardLicenseHeader = null; + } + this.standardLicenseHeaderHtml = fromLicense.getLicenseHeaderHtml(); + if (Objects.nonNull(this.standardLicenseHeaderHtml) && this.standardLicenseHeaderHtml.isEmpty()) { + this.standardLicenseHeaderHtml = null; + } + this.standardLicenseHeaderTemplate = fromLicense.getStandardLicenseHeaderTemplate(); + if (Objects.nonNull(this.standardLicenseHeaderTemplate) && this.standardLicenseHeaderTemplate.isEmpty()) { + this.standardLicenseHeaderTemplate = null; + } + this.standardLicenseTemplate = fromLicense.getStandardLicenseTemplate(); + if (Objects.nonNull(this.standardLicenseTemplate) && this.standardLicenseTemplate.isEmpty()) { + this.standardLicenseTemplate = null; + } + this.crossRef.clear(); + for (CrossRef crossRef:fromLicense.getCrossRef()) { + this.crossRef.add(new CrossRefJson(crossRef)); + } + } + + public boolean isPropertyValueAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + switch (propertyName) { + case "licenseText": + case "licenseTextHtml": + case "name": + case "standardLicenseHeader": + case "standardLicenseHeaderTemplate": + case "standardLicenseHeaderHtml": + case "standardLicenseTemplate": + case "example": + case "deprecatedVersion": + case "comment": + case "licenseXml": + case "listVersionAdded": + case "obsoletedBy": + case "licenseId": return String.class.isAssignableFrom(clazz); + case "seeAlso": + case "crossRef": return false; + case "isOsiApproved": + case "isFsfLibre": + case "isDeprecatedLicenseId": return Boolean.class.isAssignableFrom(clazz); + default: throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyName); + } + + } + + public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSpdxPropertyException { + String propertyName = PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(propertyDescriptor); + if (Objects.isNull(propertyName)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + if (SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName().equals(propertyName)) { + return String.class.isAssignableFrom(clazz); + } else if (SpdxConstantsCompatV2.PROP_CROSS_REF.getName().equals(propertyName)) { + return CrossRef.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTERNAL_REF.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalRef.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_VERIFIED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.IntegrityMethod.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTENSION.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.extension.ExtensionExtension.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.ExternalIdentifier.class.isAssignableFrom(clazz); + } else if (SpdxConstantsV3.PROP_CREATED_USING.equals(propertyDescriptor)) { + return org.spdx.library.model.v3.core.Tool.class.isAssignableFrom(clazz); + } else { + return false; + } + } + + public boolean isCollectionProperty(PropertyDescriptor propertyDescriptor) throws InvalidSpdxPropertyException { + if (!PROPERTY_DESCRIPTOR_TO_VALUE_NAME.containsKey(propertyDescriptor)) { + throw new InvalidSpdxPropertyException("Invalid property for SPDX listed license:"+propertyDescriptor.getName()); + } + return COLLECTION_PROPERTIES.contains(propertyDescriptor); + } + + /** + * @return all present property descriptors + */ + public List getPropertyValueDescriptors() { + List retval = new ArrayList<>(); + ALL_PROPERTY_DESCRIPTORS.forEach(propDescriptor -> { + try { + if (Objects.nonNull(getValue(propDescriptor))) { + retval.add(propDescriptor); + } + } catch (InvalidSpdxPropertyException e) { + // ignore - assume missing + } + }); + return retval; + } +} diff --git a/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java b/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java new file mode 100644 index 000000000..738bbdb7c --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/LicenseJsonTOC.java @@ -0,0 +1,264 @@ +/** + * Copyright (c) 2018 Source Auditor Inc. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.SpdxListedLicense; + + + +/** + * Table of Contents for the listed license list as represented as a JSON index file + * at spdx.org/licenses/licenses.json + * + * @author Gary O'Neall + * + */ +public class LicenseJsonTOC { + + public static class LicenseJson { + private String reference; + private boolean isDeprecatedLicenseId; + private String detailsUrl; + private int referenceNumber; + private String name; + private String licenseId; + private List seeAlso; + private boolean isOsiApproved; + private Boolean isFsfLibre; + /** + * @return the reference + */ + public String getReference() { + return reference; + } + /** + * @return the isDeprecatedLicenseId + */ + public boolean isDeprecatedLicenseId() { + return isDeprecatedLicenseId; + } + /** + * @return the detailsUrl + */ + public String getDetailsUrl() { + return detailsUrl; + } + /** + * @return the referenceNumber + */ + public int getReferenceNumber() { + return referenceNumber; + } + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @return the licenseId + */ + public String getLicenseId() { + return licenseId; + } + /** + * @return the seeAlso + */ + public List getSeeAlso() { + return seeAlso; + } + /** + * @return the isOsiApproved + */ + public boolean isOsiApproved() { + return isOsiApproved; + } + /** + * @return fsfLibre + */ + public @Nullable Boolean getFsfLibre() { + return this.isFsfLibre; + } + /** + * @param fsfLibre the fsfLibre flag to set + */ + public void setFsfLibre(@Nullable Boolean fsfLibre) { + this.isFsfLibre = fsfLibre; + } + /** + * @param reference the reference to set + */ + public void setReference(String reference) { + this.reference = reference; + } + /** + * @param isDeprecatedLicenseId the isDeprecatedLicenseId to set + */ + public void setDeprecatedLicenseId(boolean isDeprecatedLicenseId) { + this.isDeprecatedLicenseId = isDeprecatedLicenseId; + } + /** + * @param detailsUrl the detailsUrl to set + */ + public void setDetailsUrl(String detailsUrl) { + this.detailsUrl = detailsUrl; + } + /** + * @param referenceNumber the referenceNumber to set + */ + public void setReferenceNumber(int referenceNumber) { + this.referenceNumber = referenceNumber; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @param licenseId the licenseId to set + */ + public void setLicenseId(String licenseId) { + this.licenseId = licenseId; + } + /** + * @param seeAlso the seeAlso to set + */ + public void setSeeAlso(List seeAlso) { + this.seeAlso = seeAlso; + } + /** + * @param isOsiApproved the isOsiApproved to set + */ + public void setOsiApproved(boolean isOsiApproved) { + this.isOsiApproved = isOsiApproved; + } + } + + + private String licenseListVersion; + private List licenses; + private String releaseDate; + + public LicenseJsonTOC(String version, String releaseDate) { + this.licenseListVersion = version; + this.releaseDate = releaseDate; + this.licenses = new ArrayList<>(); + } + + public LicenseJsonTOC() { + this.licenseListVersion = null; + this.releaseDate = null; + this.licenses = new ArrayList<>(); + } + + /** + * @return the licenseListVersion + */ + public String getLicenseListVersion() { + return licenseListVersion; + } + + /** + * @return the licenses + */ + public List getLicenses() { + return licenses; + } + + /** + * @return map of lower case to correct case license IDs + */ + public Map getLicenseIds() { + Map retval = new HashMap<>(); + if (licenses == null) { + return retval; + } + for (LicenseJson license:licenses) { + retval.put(license.licenseId.toLowerCase(), license.licenseId); + } + return retval; + } + + /** + * @return the releaseDate + */ + public String getReleaseDate() { + return releaseDate; + } + + /** + * Add summary information about a specific license to the licenses list + * @param license + * @param licHTMLReference + * @param licJSONReference + * @param deprecated + * @throws InvalidSPDXAnalysisException + */ + public void addLicense(SpdxListedLicense license, String licHTMLReference, String licJSONReference, + boolean deprecated) throws InvalidSPDXAnalysisException { + LicenseJson lj = new LicenseJson(); + lj.setDeprecatedLicenseId(deprecated); + lj.setDetailsUrl(toAbsoluteURL(licJSONReference)); + lj.setLicenseId(license.getId()); + lj.setName(license.getName()); + lj.setOsiApproved(license.isOsiApproved()); + lj.setFsfLibre(license.getFsfLibre()); + lj.setReference(toAbsoluteURL(licHTMLReference)); + int referenceNumber = -1; + for (LicenseJson existing:this.licenses) { + if (existing.getReferenceNumber() > referenceNumber) { + referenceNumber = existing.getReferenceNumber(); + } + } + referenceNumber++; + lj.setReferenceNumber(referenceNumber); + List seeAlso = new ArrayList<>(); + for (String sa:license.getSeeAlso()) { + seeAlso.add(sa); + } + lj.setSeeAlso(seeAlso); + this.licenses.add(lj); + } + + /** + * @param licenseListVersion the licenseListVersion to set + */ + public void setLicenseListVersion(String licenseListVersion) { + this.licenseListVersion = licenseListVersion; + } + + /** + * @param releaseDate the releaseDate to set + */ + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + private static String toAbsoluteURL(String relURL) { + String retval = relURL.startsWith("./") ? relURL.substring(2) : relURL; + return SpdxConstantsCompatV2.LISTED_LICENSE_URL + retval; + } +} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java new file mode 100644 index 000000000..aa06f8af2 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.io.IOException; +import java.io.InputStream; + +import org.spdx.core.InvalidSPDXAnalysisException; + + +/** + * @author Gary O'Neall + * + * Model store for listed licenses using the JSON files in the resources/stdlicenses directory. + * Note the resources/stdlicenses must be on the build path. + * + */ +public class SpdxListedLicenseLocalStore extends SpdxListedLicenseModelStore { + + static final String LISTED_LICENSE_JSON_LOCAL_DIR = "resources" + "/" + "stdlicenses"; + + public SpdxListedLicenseLocalStore() throws InvalidSPDXAnalysisException { + super(); + } + + @Override + InputStream getTocInputStream() throws IOException { + String fileName = LISTED_LICENSE_JSON_LOCAL_DIR + "/" + LICENSE_TOC_FILENAME; + InputStream retval = SpdxListedLicenseLocalStore.class.getResourceAsStream("/" + fileName); + if (retval == null) { + throw new IOException("Unable to open local local license table of contents file"); + } + return retval; + } + + @Override + InputStream getLicenseInputStream(String licenseId) throws IOException { + + String fileName = LISTED_LICENSE_JSON_LOCAL_DIR + "/" + licenseId + JSON_SUFFIX; + InputStream retval = SpdxListedLicenseLocalStore.class.getResourceAsStream("/" + fileName); + if (retval == null) { + throw new IOException("Unable to open local local license JSON file for license ID "+licenseId); + } + return retval; + } + + @Override + InputStream getExceptionTocInputStream() throws IOException { + String fileName = LISTED_LICENSE_JSON_LOCAL_DIR + "/" + EXCEPTION_TOC_FILENAME; + InputStream retval = SpdxListedLicenseLocalStore.class.getResourceAsStream("/" + fileName); + if (retval == null) { + throw new IOException("Unable to open local local license table of contents file"); + } + return retval; + } + + @Override + InputStream getExceptionInputStream(String exceptionId) throws IOException { + return getLicenseInputStream(exceptionId); + } +} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java new file mode 100644 index 000000000..0cb0fa1a1 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -0,0 +1,1327 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.stream.Stream; + +import javax.annotation.Nullable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spdx.core.DuplicateSpdxIdException; +import org.spdx.core.IExternalElementInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.SpdxIdNotFoundException; +import org.spdx.core.TypedValue; +import org.spdx.library.LicenseInfoFactory; +import org.spdx.library.model.v2.ModelObjectV2; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.SpdxListedLicenseException; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.storage.PropertyDescriptor; + +import com.google.gson.Gson; + +/** + * Read-only model store for the SPDX listed licenses + * + * License and exception ID's can be case insensitive + * + * License information is stored in a LicenseJson file with the ID being Listed License ID + * License Exception information is stored in an ExceptionJson file with the ID being the Listed Exception ID + * CrossRef information is stored within the LicenseJson file. Id's are anonymous and generated. + * + * @author Gary O'Neall + * + */ +public abstract class SpdxListedLicenseModelStore implements IListedLicenseStore { + + static final Logger logger = LoggerFactory.getLogger(SpdxListedLicenseModelStore.class.getName()); + static final String DEFAULT_LICENSE_LIST_VERSION = "3.24"; + static final String LICENSE_TOC_FILENAME = "licenses.json"; + static final String EXCEPTION_TOC_FILENAME = "exceptions.json"; + static final String JSON_SUFFIX = ".json"; + private static final String ANONYMOUS_ID_PREFIX = "SpdxLicenseGeneratedId-"; + public static final String LISTED_LICENSE_NAMESPACE = SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX; + + /** + * Map of lower case to correct case license IDs + */ + Map licenseIds = new HashMap<>(); + /** + * Map of lower case to correct case exception IDs + */ + Map exceptionIds = new HashMap<>(); + Map listedLicenseCache = null; + Map listedExceptionCache = null; + Map crossRefs = new HashMap<>(); + String licenseListVersion = DEFAULT_LICENSE_LIST_VERSION; + String licenseListReleaseDate = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); + LicenseCreationInfo licenseCreationInfo; + LicenseCreatorAgent licenseCreator; + + private int nextId=0; + private final ReadWriteLock listedLicenseModificationLock = new ReentrantReadWriteLock(); + + private final IModelStoreLock readLock = new IModelStoreLock() { + + @Override + public void unlock() { + listedLicenseModificationLock.readLock().unlock(); + } + + }; + + private final IModelStoreLock writeLock = new IModelStoreLock() { + + @Override + public void unlock() { + listedLicenseModificationLock.writeLock().unlock(); + } + + }; + + Gson gson = new Gson(); // we should be able to reuse since all access is within write locks + + public static String objectUriToLicenseOrExceptionId(String objectUri) { + return objectUri.substring(LISTED_LICENSE_NAMESPACE.length()+1); + } + + public static String licenseOrExceptionIdToObjectUri(String id) { + return LISTED_LICENSE_NAMESPACE + "/" + id; + } + + /** + * @param majorSpecVersion Major spec version - the store will work with either SPDX 3 or SPDX 2 major version of the spec + * @throws InvalidSPDXAnalysisException on error loading ids + */ + public SpdxListedLicenseModelStore() throws InvalidSPDXAnalysisException { + loadIds(); + licenseCreator = new LicenseCreatorAgent(this.getLicenseListVersion()); + licenseCreationInfo = new LicenseCreationInfo(licenseCreator, this.getLicenseListReleaseDate()); + } + + /** + * @return InputStream for the Table of Contents of the licenses formated in JSON SPDX + * @throws IOException + */ + abstract InputStream getTocInputStream() throws IOException; + + /** + * @return InputStream for the Table of Contents of the exceptions formated in JSON SPDX + * @throws IOException + */ + abstract InputStream getExceptionTocInputStream() throws IOException; + + /** + * @return InputStream for a license formated in SPDX JSON + * @throws IOException + */ + abstract InputStream getLicenseInputStream(String licenseId) throws IOException; + + /** + * @return InputStream for an exception formated in SPDX JSON + * @throws IOException + */ + abstract InputStream getExceptionInputStream(String exceptionId) throws IOException; + + /** + * Map of an objectUri to a map of documentUri's to external element information + */ + protected Map> objectUriExternalMap = new HashMap<>(); + + /** + * Loads all license and exception ID's from the appropriate JSON files + * @throws InvalidSPDXAnalysisException + */ + private void loadIds() throws InvalidSPDXAnalysisException { + listedLicenseModificationLock.writeLock().lock(); + try { + listedLicenseCache = new HashMap<>(); // clear the cache + listedExceptionCache = new HashMap<>(); + licenseIds = new HashMap<>(); //Clear the listed license IDs to avoid stale licenses. + //NOTE: This includes deprecated licenses - should this be changed to only return non-deprecated licenses? + InputStream tocStream = null; + BufferedReader reader = null; + try { + // read the license IDs + tocStream = getTocInputStream(); + reader = new BufferedReader(new InputStreamReader(tocStream, "UTF-8")); + StringBuilder tocJsonStr = new StringBuilder(); + String line; + while((line = reader.readLine()) != null) { + tocJsonStr.append(line); + } + LicenseJsonTOC jsonToc = gson.fromJson(tocJsonStr.toString(), LicenseJsonTOC.class); + licenseIds = jsonToc.getLicenseIds(); + this.licenseListVersion = jsonToc.getLicenseListVersion(); + this.licenseListReleaseDate = jsonToc.getReleaseDate(); + + // read the exception ID's + tocStream = getExceptionTocInputStream(); + reader = new BufferedReader(new InputStreamReader(tocStream, "UTF-8")); + tocJsonStr = new StringBuilder(); + while((line = reader.readLine()) != null) { + tocJsonStr.append(line); + } + ExceptionJsonTOC exceptionToc = gson.fromJson(tocJsonStr.toString(), ExceptionJsonTOC.class); + exceptionIds = exceptionToc.getExceptionIds(); + } catch (MalformedURLException e) { + throw new SpdxListedLicenseException("License TOC URL invalid") ; + } catch (IOException e) { + throw new SpdxListedLicenseException("I/O error reading license TOC"); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + logger.warn("Unable to close JSON TOC reader"); + } + } + } + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#exists(java.lang.String, java.lang.String) + */ + @Override + public boolean exists(String objectUri) { + Objects.requireNonNull(objectUri, "Object URI can not be null"); + String id; + if (objectUri.startsWith(LISTED_LICENSE_NAMESPACE)) { + id = objectUri.substring(LISTED_LICENSE_NAMESPACE.length()); + } else if (getIdType(objectUri) == IdType.Anonymous || + LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri) || + this.licenseCreator.getObjectUri().equals(objectUri)) { + id = objectUri; + } else { + return false; + } + listedLicenseModificationLock.readLock().lock(); + try { + return this.licenseIds.containsKey(id.toLowerCase()) || + this.exceptionIds.containsKey(id.toLowerCase()) || + this.crossRefs.containsKey(id) || + LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri) || + this.licenseCreator.getObjectUri().equals(objectUri); + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + private String objectUriToId(String objectUri) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(objectUri, "Object URI can not be null"); + String id; + if (objectUri.startsWith(LISTED_LICENSE_NAMESPACE)) { + id = objectUri.substring(LISTED_LICENSE_NAMESPACE.length()); + } else if (getIdType(objectUri) == IdType.Anonymous || + licenseCreator.getObjectUri().equals(objectUri) || + LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + id = objectUri; + } else { + logger.error("Namespace for SPDX listed licenses is expected to be "+ + LISTED_LICENSE_NAMESPACE + ". Supplied URI was "+objectUri); + throw new SpdxIdNotFoundException("Namespace for SPDX listed licenses is expected to be "+ + LISTED_LICENSE_NAMESPACE + ". Supplied URI was "+objectUri); + } + return id; + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#create(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException { + boolean isSpdx3 = typedValue.getSpecVersion().startsWith("3."); + String id = objectUriToId(typedValue.getObjectUri()); + listedLicenseModificationLock.writeLock().lock(); + try { + if (SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(typedValue.getType())) { + CrossRefJson crossRef = new CrossRefJson(); + crossRef.setId(id); + this.crossRefs.put(id, crossRef); + } else if ((isSpdx3 && SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE.equals(typedValue.getType())) || + (!isSpdx3 && SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(typedValue.getType()))) { + if (this.licenseIds.containsKey(id.toLowerCase()) || this.exceptionIds.containsKey(id.toLowerCase())) { + logger.error("Duplicate SPDX ID on create: "+id); + throw new DuplicateSpdxIdException("ID "+id+" already exists."); + } + this.licenseIds.put(id.toLowerCase(), id); + this.listedLicenseCache.put(id, new LicenseJson(id)); + } else if ((isSpdx3 && SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION.equals(typedValue.getType())) || + (!isSpdx3 && SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(typedValue.getType()))) { + if (this.licenseIds.containsKey(id.toLowerCase()) || this.exceptionIds.containsKey(id.toLowerCase())) { + logger.error("Duplicate SPDX ID on create: "+id); + throw new DuplicateSpdxIdException("ID "+id+" already exists."); + } + this.exceptionIds.put(id.toLowerCase(), id); + this.listedExceptionCache.put(id, new ExceptionJson(id)); + } else if (this.licenseCreationInfo.getTypedValue().equals(typedValue)) { + logger.warn("Ignoring the creation of a creationInfo for the listed license store"); + } else if (this.licenseCreator.getTypedValue().equals(typedValue)) { + logger.warn("Ignoring the creation of the creator for the listed license store"); + } + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getPropertyValueNames(java.lang.String, java.lang.String) + */ + @Override + public List getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + LicenseJson license = fetchLicenseJson(licenseIds.get(id.toLowerCase())); + return license.getPropertyValueDescriptors(); + // NOTE: we're returning both version 2 and version 3 property value descriptors + } else if (exceptionIds.containsKey(id.toLowerCase())) { + ExceptionJson exc = fetchExceptionJson(exceptionIds.get(id.toLowerCase())); + return exc.getPropertyValueDescriptors(); + } else if (crossRefs.containsKey(id)) { + return crossRefs.get(id).getPropertyValueDescriptors(); + // Currently, there is no SPDX 3 support for cross refs + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return LicenseCreationInfo.ALL_PROPERTY_DESCRIPTORS; + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return LicenseCreatorAgent.ALL_PROPERTY_DESCRIPTORS; + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID"); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + /** + * @param idCaseInsensitive License ID case insensitive + * @return License JSON for the ID - reading from the input stream if needed + * @throws InvalidSPDXAnalysisException + */ + private LicenseJson fetchLicenseJson(String idCaseInsensitive) throws InvalidSPDXAnalysisException { + String idLowerCase = idCaseInsensitive.toLowerCase(); + String id = null; + listedLicenseModificationLock.readLock().lock(); + try { + id = this.licenseIds.get(idLowerCase); + if (Objects.isNull(id)) { + logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); + throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); + } + if (this.listedLicenseCache.containsKey(id)) { + return this.listedLicenseCache.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + // If we got here, it wasn't in the cache + listedLicenseModificationLock.writeLock().lock(); + try { + // have to retest since we were unlocked + id = this.licenseIds.get(idLowerCase); + if (Objects.isNull(id)) { + logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); + throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); + } + if (!this.listedLicenseCache.containsKey(id)) { + InputStream jsonStream = null; + BufferedReader reader = null; + try { + jsonStream = getLicenseInputStream(id); + reader = new BufferedReader(new InputStreamReader(jsonStream, "UTF-8")); + StringBuilder licenseJsonStr = new StringBuilder(); + String line; + while((line = reader.readLine()) != null) { + licenseJsonStr.append(line); + } + LicenseJson license = gson.fromJson(licenseJsonStr.toString(), LicenseJson.class); + this.listedLicenseCache.put(id, license); + } catch (MalformedURLException e) { + logger.error("Json license invalid for ID "+id); + throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id); + } catch (IOException e) { + logger.error("I/O error opening Json license URL"); + throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + logger.warn("Unable to close JSON TOC reader"); + } + } else if (jsonStream != null) { + try { + jsonStream.close(); + } catch (IOException e) { + logger.warn("Unable to close JSON TOC input stream"); + } + } + } + } + return this.listedLicenseCache.get(id); + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + /** + * @param idCaseInsensitive Exception ID case insensitive + * @return Exception JSON for the ID - reading from the input stream if needed + * @throws InvalidSPDXAnalysisException + */ + private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws InvalidSPDXAnalysisException { + String idLower = idCaseInsensitive.toLowerCase(); + String id = null; // case sensitive ID + listedLicenseModificationLock.readLock().lock(); + try { + id = this.exceptionIds.get(idLower); + if (Objects.isNull(id)) { + logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); + throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); + } + if (this.listedExceptionCache.containsKey(id)) { + return this.listedExceptionCache.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + // If we got here, it wasn't in the cache + listedLicenseModificationLock.writeLock().lock(); + try { + // have to retest since we were unlocked + id = this.exceptionIds.get(idLower); + if (Objects.isNull(id)) { + logger.error("Attemting to get property values on non-existent ID "+idCaseInsensitive); + throw new SpdxIdNotFoundException("ID "+idCaseInsensitive+" not found."); + } + if (!this.listedExceptionCache.containsKey(id)) { + InputStream jsonStream = null; + BufferedReader reader = null; + try { + jsonStream = getExceptionInputStream(id); + reader = new BufferedReader(new InputStreamReader(jsonStream, "UTF-8")); + StringBuilder exceptionJsonStr = new StringBuilder(); + String line; + while((line = reader.readLine()) != null) { + exceptionJsonStr.append(line); + } + ExceptionJson exc = gson.fromJson(exceptionJsonStr.toString(), ExceptionJson.class); + this.listedExceptionCache.put(id, exc); + } catch (MalformedURLException e) { + logger.error("Json license invalid for ID "+id); + throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id); + } catch (IOException e) { + logger.error("I/O error opening Json license URL"); + throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + logger.warn("Unable to close JSON TOC reader"); + } + } else if (jsonStream != null) { + try { + jsonStream.close(); + } catch (IOException e) { + logger.warn("Unable to close JSON TOC input stream"); + } + } + } + } + return this.listedExceptionCache.get(id); + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#setPrimitiveValue(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) + */ + @Override + public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + license.setPrimativeValue(propertyDescriptor, value); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + exc.setPrimativeValue(propertyDescriptor, value); + } else if (Objects.nonNull(crossRef)) { + crossRef.setPrimativeValue(propertyDescriptor, value); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + logger.warn("Ignoring the setting of "+propertyDescriptor.getName()+" for license list creation info"); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + logger.warn("Ignoring the setting of "+propertyDescriptor.getName()+" for license list creator info"); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#clearPropertyValueList(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + license.clearPropertyValueList(propertyDescriptor); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + exc.clearPropertyValueList(propertyDescriptor); + } else if (Objects.nonNull(crossRef)) { + crossRef.clearPropertyValueList(propertyDescriptor); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + logger.warn("Ignoring the clearing of collection for license list creation info"); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + logger.warn("Ignoring the clearing of collection for license list creator"); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#addPrimitiveValueToList(java.lang.String, java.lang.String, java.lang.String, java.lang.Object) + */ + @Override + public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { + if (!(value instanceof TypedValue)) { + logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); + throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); + } + TypedValue tv = (TypedValue)value; + if (!SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(tv.getType())) { + logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + } + CrossRefJson crj = crossRefs.get(tv.getObjectUri()); + if (Objects.isNull(crj)) { + logger.error("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); + throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); + } + return license.addCrossRefValueToList(propertyDescriptor, crj); + } else { + return license.addPrimitiveValueToList(propertyDescriptor, value); + } + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return exc.addPrimitiveValueToList(propertyDescriptor, value); + } else if (Objects.nonNull(crossRef)) { + return crossRef.addPrimitiveValueToList(propertyDescriptor, value); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + logger.warn("Ignoring the adding to collection for license list creation info"); + return false; + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + logger.warn("Ignoring the adding to collection for license list creator"); + return false; + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + @Override + public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { + if (!(value instanceof TypedValue)) { + logger.error("Invalid class for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); + throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected TypedValue, was supplied type "+value.getClass().toString()); + } + TypedValue tv = (TypedValue)value; + if (!SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(tv.getType())) { + logger.error("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + throw new InvalidSPDXAnalysisException("Invalid type for CrossRef - expected"+SpdxConstantsCompatV2.CLASS_CROSS_REF+", was supplied type "+value.getClass().toString()); + } + CrossRefJson crj = crossRefs.get(tv.getObjectUri()); + if (Objects.isNull(crj)) { + logger.error("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); + throw new InvalidSPDXAnalysisException("CrossRef with ID "+tv.getObjectUri()+" does not exist in the store."); + } + return license.removePrimitiveValueToList(propertyDescriptor, crj); + } else { + return license.removePrimitiveValueToList(propertyDescriptor, value); + } + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return exc.removePrimitiveValueToList(propertyDescriptor, value); + } else if (Objects.nonNull(crossRef)) { + return crossRef.removePrimitiveValueToList(propertyDescriptor, value); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + logger.warn("Ignoring the removing from collection for license list creation info"); + return false; + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + logger.warn("Ignoring the removing from collection for license list creator"); + return false; + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getValueList(java.lang.String, java.lang.String, java.lang.String) + */ + @SuppressWarnings("unchecked") + @Override + public Iterator listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + List valueList = (List)(List)license.getValueList(propertyDescriptor); + if (SpdxConstantsCompatV2.PROP_CROSS_REF.equals(propertyDescriptor)) { + final Iterator crossRefJsonIter = valueList.iterator(); + return new Iterator() { + + @Override + public boolean hasNext() { + return crossRefJsonIter.hasNext(); + } + + @Override + public Object next() { + Object nextVal = crossRefJsonIter.next(); + if (Objects.isNull(nextVal)) { + return null; + } + if (!(nextVal instanceof CrossRefJson)) { + throw new RuntimeException(new InvalidSPDXAnalysisException("Invalid type for "+propertyDescriptor+". Must be of type CrossRefJson")); + } + CrossRefJson nextCrossRef = (CrossRefJson)nextVal; + String crossRefId = nextCrossRef.getId(); + listedLicenseModificationLock.writeLock().lock(); + try { + if (Objects.isNull(crossRefId)) { + // Need to create an ID and store it in the cache + try { + crossRefId = getNextId(IdType.Anonymous); + } catch (InvalidSPDXAnalysisException e) { + logger.error("Error getting next Anonymous ID",e); + throw new RuntimeException(e); + } + nextCrossRef.setId(crossRefId); + crossRefs.put(crossRefId, nextCrossRef); + } + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + try { + return new TypedValue(crossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF, ModelObjectV2.LATEST_SPDX_2_VERSION); + } catch (InvalidSPDXAnalysisException e) { + logger.error("Error creating TypedValue for CrossRef",e); + throw new RuntimeException(e); + } + } + }; + } else { + return valueList.iterator(); + } + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return ((List)(List)exc.getValueList(propertyDescriptor)).iterator(); + } else if (Objects.nonNull(crossRef)) { + return ((List)(List)crossRef.getValueList(propertyDescriptor)).iterator(); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return ((List)(List)licenseCreationInfo.getValueList(propertyDescriptor)).iterator(); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return ((List)(List)licenseCreator.getValueList(propertyDescriptor)).iterator(); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getValue(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public Optional getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (SpdxConstantsV3.PROP_CREATION_INFO.equals(propertyDescriptor) && (isLicenseId || isExceptionId)) { + return Optional.of(licenseCreationInfo.getTypedValue()); + } else if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + return Optional.ofNullable(license.getValue(propertyDescriptor)); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return Optional.ofNullable(exc.getValue(propertyDescriptor)); + } else if (Objects.nonNull(crossRef)) { + return Optional.ofNullable(crossRef.getValue(propertyDescriptor)); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return Optional.ofNullable(licenseCreationInfo.getValue(propertyDescriptor)); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return Optional.ofNullable(licenseCreator.getValue(propertyDescriptor)); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getNextId(org.spdx.storage.IModelStore.IdType, java.lang.String) + */ + @Override + public String getNextId(IdType idType) throws InvalidSPDXAnalysisException { + this.listedLicenseModificationLock.writeLock().lock(); + try { + if (IdType.Anonymous.equals(idType)) { + return ANONYMOUS_ID_PREFIX + String.valueOf(this.nextId++); + } else { + return LISTED_LICENSE_NAMESPACE + "/" + "listedLicenseId_" + String.valueOf(this.nextId++); + } + } finally { + this.listedLicenseModificationLock.writeLock().unlock(); + } + } + + @Override + public List getSpdxListedLicenseIds() { + this.listedLicenseModificationLock.readLock().lock(); + try { + List retval = new ArrayList<>(); + retval.addAll(this.licenseIds.values()); + return retval; + } finally { + this.listedLicenseModificationLock.readLock().unlock(); + } + } + + @Override + public String getLicenseListVersion() { + this.listedLicenseModificationLock.readLock().lock(); + try { + return this.licenseListVersion; + } finally { + this.listedLicenseModificationLock.readLock().unlock(); + } + } + + /** + * @return the release date for the license list + */ + public String getLicenseListReleaseDate() { + this.listedLicenseModificationLock.readLock().lock(); + try { + return this.licenseListReleaseDate; + } finally { + this.listedLicenseModificationLock.readLock().unlock(); + } + } + + @Override + public List getSpdxListedExceptionIds() { + this.listedLicenseModificationLock.readLock().lock(); + try { + List retval = new ArrayList<>(); + retval.addAll(this.exceptionIds.values()); + return retval; + } finally { + this.listedLicenseModificationLock.readLock().unlock(); + } + } + + /** + * @param listedLicenseDocumentUri + * @param licenseId + * @return true if the licenseId belongs to an SPDX listed license + */ + public boolean isSpdxListedLicenseId(String listedLicenseDocumentUri, String licenseId) { + this.listedLicenseModificationLock.readLock().lock(); + try { + return this.licenseIds.containsKey(licenseId.toLowerCase()); + } finally { + this.listedLicenseModificationLock.readLock().unlock(); + } + } + + /** + * @param listedLicenseDocumentUri + * @param exceptionId + * @return true if the exceptionId belongs to an SPDX listed exception + */ + public boolean isSpdxListedExceptionId(String listedLicenseDocumentUri, String exceptionId) { + this.listedLicenseModificationLock.readLock().lock(); + try { + return this.exceptionIds.containsKey(exceptionId.toLowerCase()); + } finally { + this.listedLicenseModificationLock.readLock().unlock(); + } + } + + @Override + public Optional getTypedValue(String objectUri) throws InvalidSPDXAnalysisException { + //NOTE: We only return the SPDX 3.0 version of the typed value, SPDX 2.X versions are also supported + // but there is no API to specify the version of the typedValue + String id = objectUriToId(objectUri); + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + return Optional.of(new TypedValue(id, SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE, SpdxConstantsV3.MODEL_SPEC_VERSION)); + } else if (exceptionIds.containsKey(id.toLowerCase())) { + return Optional.of(new TypedValue(id, SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION, SpdxConstantsV3.MODEL_SPEC_VERSION)); + } else if (crossRefs.containsKey(id)) { + // Cross refs are only supported in SPDX version 2.X + return Optional.of(new TypedValue(id, SpdxConstantsCompatV2.CLASS_CROSS_REF, ModelObjectV2.LATEST_SPDX_2_VERSION)); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return Optional.of(licenseCreationInfo.getTypedValue()); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return Optional.of(licenseCreator.getTypedValue()); + } else { + return Optional.empty(); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + @Override + public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + license.removeProperty(propertyDescriptor); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + exc.removeProperty(propertyDescriptor); + } else if (Objects.nonNull(crossRef)) { + crossRef.removeProperty(propertyDescriptor); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + logger.warn("Ignoring remove property "+propertyDescriptor.getName()+" for license list creation info"); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + logger.warn("Ignoring remove property "+propertyDescriptor.getName()+" for license list creator"); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + @Override + public Stream getAllItems(String documentUri, @Nullable String typeFilter) + throws InvalidSPDXAnalysisException { + Objects.requireNonNull(typeFilter, "Type filter can not be null"); + listedLicenseModificationLock.readLock().lock(); + try { + List allItems = new ArrayList(); + if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(typeFilter)) { + for (String licenseId:this.licenseIds.values()) { + allItems.add(new TypedValue(licenseId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, ModelObjectV2.LATEST_SPDX_2_VERSION)); + } + } + if (Objects.isNull(typeFilter) || SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE.equals(typeFilter)) { + for (String licenseId:this.licenseIds.values()) { + allItems.add(new TypedValue(licenseId, SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE, SpdxConstantsV3.MODEL_SPEC_VERSION)); + } + } + if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(typeFilter)) { + for (String exceptionId:this.exceptionIds.values()) { + allItems.add(new TypedValue(exceptionId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, ModelObjectV2.LATEST_SPDX_2_VERSION)); + } + } + if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(typeFilter)) { + for (String exceptionId:this.exceptionIds.values()) { + allItems.add(new TypedValue(exceptionId, SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION, SpdxConstantsV3.MODEL_SPEC_VERSION)); + } + } + if (Objects.isNull(typeFilter) || SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(typeFilter)) { + for (String crossRefId:crossRefs.keySet()) { + allItems.add(new TypedValue(crossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF, ModelObjectV2.LATEST_SPDX_2_VERSION)); + } + } + if (Objects.isNull(typeFilter) || SpdxConstantsV3.CORE_CREATION_INFO.equals(typeFilter)) { + allItems.add(licenseCreationInfo.typedValue); + } + if (Objects.isNull(typeFilter) || SpdxConstantsV3.CORE_AGENT.equals(typeFilter)) { + allItems.add(licenseCreator.getTypedValue()); + } + return Collections.unmodifiableList(allItems).stream(); + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + + + @SuppressWarnings("unchecked") + @Override + public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + return ((List)(List)license.getValueList(propertyDescriptor)).size(); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return ((List)(List)exc.getValueList(propertyDescriptor)).size(); + } else if (Objects.nonNull(crossRef)) { + return ((List)(List)crossRef.getValueList(propertyDescriptor)).size(); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return ((List)(List)licenseCreationInfo.getValueList(propertyDescriptor)).size(); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return ((List)(List)licenseCreator.getValueList(propertyDescriptor)).size(); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + @SuppressWarnings("unchecked") + @Override + public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + List valueList = (List)(List)license.getValueList(propertyDescriptor); + if (value instanceof TypedValue && SpdxConstantsCompatV2.CLASS_CROSS_REF.equals(((TypedValue)value).getType())) { + CrossRefJson compareValue = crossRefs.get(((TypedValue)value).getObjectUri()); + if (Objects.isNull(compareValue)) { + return false; + } else { + return valueList.contains(compareValue); + } + } else { + return valueList.contains(value); + } + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return ((List)(List)exc.getValueList(propertyDescriptor)).contains(value); + } else if (Objects.nonNull(crossRef)) { + return ((List)(List)crossRef.getValueList(propertyDescriptor)).contains(value); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return ((List)(List)licenseCreationInfo.getValueList(propertyDescriptor)).contains(value); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return ((List)(List)licenseCreator.getValueList(propertyDescriptor)).contains(value); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + @Override + public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + return license.isCollectionMembersAssignableTo(propertyDescriptor, clazz); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return exc.isCollectionMembersAssignableTo(propertyDescriptor, clazz); + } else if (Objects.nonNull(crossRef)) { + return crossRef.isCollectionMembersAssignableTo(propertyDescriptor, clazz); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return licenseCreationInfo.isCollectionMembersAssignableTo(propertyDescriptor, clazz); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return licenseCreator.isCollectionMembersAssignableTo(propertyDescriptor, clazz); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + @Override + public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, + Class clazz, String specVersion) + throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + return license.isPropertyValueAssignableTo(propertyDescriptor, clazz); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return exc.isPropertyValueAssignableTo(propertyDescriptor, clazz); + } else if (Objects.nonNull(crossRef)) { + return crossRef.isPropertyValueAssignableTo(propertyDescriptor, clazz); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return licenseCreationInfo.isPropertyValueAssignableTo(propertyDescriptor, clazz); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return licenseCreator.isPropertyValueAssignableTo(propertyDescriptor, clazz); + } else { + logger.error("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, CrossRef ID nor a listed exception ID"); + } + } + + @Override + public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + boolean isLicenseId = false; + boolean isExceptionId = false; + CrossRefJson crossRef = null; + listedLicenseModificationLock.readLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + isLicenseId = true; + } else if (exceptionIds.containsKey(id.toLowerCase())) { + isExceptionId = true; + } else if (crossRefs.containsKey(id)) { + crossRef = crossRefs.get(id); + } + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + if (isLicenseId) { + LicenseJson license = fetchLicenseJson(id); + return license.isCollectionProperty(propertyDescriptor); + } else if (isExceptionId) { + ExceptionJson exc = fetchExceptionJson(id); + return exc.isCollectionProperty(propertyDescriptor); + } else if (Objects.nonNull(crossRef)) { + return crossRef.isCollectionProperty(propertyDescriptor.getName()); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + return this.licenseCreationInfo.isCollectionProperty(propertyDescriptor); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + return licenseCreator.isCollectionProperty(propertyDescriptor); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } + + @Override + public IdType getIdType(String id) { + Objects.requireNonNull(id, "ID must not be null"); + if (LicenseInfoFactory.isSpdxListedLicenseId(id) || LicenseInfoFactory.isSpdxListedExceptionId(id)) { + return IdType.ListedLicense; + } else if (id.startsWith(ANONYMOUS_ID_PREFIX) || LicenseCreationInfo.CREATION_INFO_URI.equals(id)) { + return IdType.Anonymous; + } else if (id.startsWith(LicenseCreatorAgent.OBJECT_URI_PREFIX)) { + return IdType.SpdxId; + } else { + return IdType.Unkown; + } + } + + + @Override + public IModelStoreLock enterCriticalSection(boolean readLockRequested) { + if (readLockRequested) { + this.listedLicenseModificationLock.readLock().lock(); + return readLock; + } else { + this.listedLicenseModificationLock.writeLock().lock(); + return writeLock; + } + } + + @Override + public void leaveCriticalSection(IModelStoreLock lock) { + lock.unlock(); + } + + @Override + public Optional listedLicenseIdCaseSensitive(String licenseId) { + listedLicenseModificationLock.readLock().lock(); + try { + return Optional.ofNullable(this.licenseIds.get(licenseId.toLowerCase())); + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + + @Override + public Optional listedExceptionIdCaseSensitive(String exceptionId) { + listedLicenseModificationLock.readLock().lock(); + try { + return Optional.ofNullable(this.exceptionIds.get(exceptionId.toLowerCase())); + } finally { + listedLicenseModificationLock.readLock().unlock(); + } + } + + @Override + public Optional getCaseSensisitiveId(String documentUri, String caseInsensisitiveId) { + Optional retval = listedLicenseIdCaseSensitive(caseInsensisitiveId); + if (retval.isPresent()) { + return retval; + } + return listedExceptionIdCaseSensitive(caseInsensisitiveId); + } + + @Override + public void delete(String objectUri) throws InvalidSPDXAnalysisException { + String id = objectUriToId(objectUri); + listedLicenseModificationLock.writeLock().lock(); + try { + if (licenseIds.containsKey(id.toLowerCase())) { + this.listedLicenseCache.remove(id); + this.licenseIds.remove(id.toLowerCase()); + } else if (exceptionIds.containsKey(id.toLowerCase())) { + this.listedExceptionCache.remove(id); + this.exceptionIds.remove(id.toLowerCase()); + } else if (crossRefs.containsKey(id)) { + this.crossRefs.remove(id); + } else if (LicenseCreationInfo.CREATION_INFO_URI.equals(objectUri)) { + logger.warn("Ignoring the removal of the creation info for the license list"); + } else if (licenseCreator.getObjectUri().equals(objectUri)) { + logger.warn("Ignoring the removal of the creator for the license list"); + } else { + logger.error("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID, crossRef ID nor a listed exception ID"); + } + } finally { + listedLicenseModificationLock.writeLock().unlock(); + } + } + + @Override + public void close() throws Exception { + // Nothing to do for the either the in-memory or the web store + } + + /** + * Adds an external reference for a given collection + * @param externalObjectUri URI of the external SPDX Element or License + * @param collectionUri URI of the SPDX document or collection + * @param externalElementInfo info about the external element + * @return the previous external mapping for the collection, null if no previous value is present + */ + @Override + public synchronized @Nullable IExternalElementInfo addExternalReference(String externalObjectUri, String collectionUri, IExternalElementInfo externalElementInfo) { + Map externalObjectToCollectionMap = objectUriExternalMap.get(externalObjectUri); + if (Objects.isNull(externalObjectToCollectionMap)) { + externalObjectToCollectionMap = new HashMap<>(); + } + return externalObjectToCollectionMap.put(collectionUri, externalElementInfo); + } + + /** + * @param externalObjectUri object URI for an element external to a collection + * @return a map of collection (or document) URI's mapped to their external element info for the given object URI + */ + @Override + public synchronized @Nullable Map getExternalReferenceMap(String externalObjectUri) { + return objectUriExternalMap.get(externalObjectUri); + } + + /** + * @param externalObjectUri URI of the external SPDX Element or License + * @param collectionUri URI of the SPDX document or collection + * @return the externalElementInfo associated with the collection for a given external element + */ + @Override + public synchronized @Nullable IExternalElementInfo getExternalElementInfo(String externalObjectUri, String collectionUri) { + Map externalObjectToCollectionMap = objectUriExternalMap.get(externalObjectUri); + if (Objects.isNull(externalObjectToCollectionMap)) { + return null; + } else { + return externalObjectToCollectionMap.get(collectionUri); + } + } +} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java new file mode 100644 index 000000000..0ba858e6c --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; + +/** + * @author gary + * + */ +public class SpdxListedLicenseWebStore extends SpdxListedLicenseModelStore { + + private static final int READ_TIMEOUT = 5000; + + static final List WHITE_LIST = Collections.unmodifiableList(Arrays.asList( + "spdx.org", "spdx.dev", "spdx.com", "spdx.info")); // Allowed host names for the SPDX listed licenses + + /** + * @throws InvalidSPDXAnalysisException + */ + public SpdxListedLicenseWebStore() throws InvalidSPDXAnalysisException { + super(); + } + + private InputStream getUrlInputStream(URL url) throws IOException { + HttpURLConnection connection = (HttpURLConnection)url.openConnection(); + connection.setReadTimeout(READ_TIMEOUT); + int status = connection.getResponseCode(); + if (status != HttpURLConnection.HTTP_OK && + (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM + || status == HttpURLConnection.HTTP_SEE_OTHER)) { + // redirect + String redirectUrlStr = connection.getHeaderField("Location"); + if (Objects.isNull(redirectUrlStr) || redirectUrlStr.isEmpty()) { + throw new IOException("Empty redirect URL response"); + } + URL redirectUrl; + try { + redirectUrl = new URL(redirectUrlStr); + } catch(Exception ex) { + throw new IOException("Invalid redirect URL"); + } + if (!redirectUrl.getProtocol().toLowerCase().startsWith("http")) { + throw new IOException("Invalid redirect protocol"); + } + if (!WHITE_LIST.contains(redirectUrl.getHost())) { + throw new IOException("Invalid redirect host - not on the allowed 'white list'"); + } + connection = (HttpURLConnection)redirectUrl.openConnection(); + } + return connection.getInputStream(); + } + + @Override + InputStream getTocInputStream() throws IOException { + return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + LICENSE_TOC_FILENAME)); + } + + @Override + InputStream getLicenseInputStream(String licenseId) throws IOException { + return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + licenseId + JSON_SUFFIX)); + } + + @Override + InputStream getExceptionTocInputStream() throws IOException { + return getUrlInputStream(new URL(SpdxConstantsCompatV2.LISTED_LICENSE_URL + EXCEPTION_TOC_FILENAME)); + } + + @Override + InputStream getExceptionInputStream(String exceptionId) throws IOException { + return getLicenseInputStream(exceptionId); // Same URL using exception ID rather than license ID + } +} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxV2ListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxV2ListedLicenseModelStore.java new file mode 100644 index 000000000..577151a0e --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxV2ListedLicenseModelStore.java @@ -0,0 +1,403 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Stream; + +import org.spdx.core.IExternalElementInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v2.ModelObjectV2; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; + +/** + * @author Gary O'Neall + * + * Model store for generating SPDX version 2.X listed license and listed exceptions + * + */ +public class SpdxV2ListedLicenseModelStore implements IModelStore { + + static Set SUPPORTED_V2_DESCRIPTORS = new HashSet<>(); + + static { + // Licenses + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_TEXT); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_NAME); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_NAME); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_EXAMPLE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_ID); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_CROSS_REF); + // Exceptions + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_NAME); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_EXAMPLE); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.RDFS_PROP_COMMENT); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID); + SUPPORTED_V2_DESCRIPTORS.add(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + // Crossrefs + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("match", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("url", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("isValid", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("isLive", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("timestamp", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("isWayBackLink", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + SUPPORTED_V2_DESCRIPTORS.add(new PropertyDescriptor("order", SpdxConstantsCompatV2.SPDX_NAMESPACE)); + } + + IListedLicenseStore baseStore; + + /** + * @param baseStore store used for the JSON objects containing the license data + */ + public SpdxV2ListedLicenseModelStore(IListedLicenseStore baseStore) { + Objects.requireNonNull(baseStore, "A base license store must be supplied"); + this.baseStore = baseStore; + } + + /* (non-Javadoc) + * @see java.lang.AutoCloseable#close() + */ + @Override + public void close() throws Exception { + baseStore.close(); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#exists(java.lang.String) + */ + @Override + public boolean exists(String objectUri) { + return baseStore.exists(objectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#create(org.spdx.core.TypedValue) + */ + @Override + public void create(TypedValue typedValue) + throws InvalidSPDXAnalysisException { + if (typedValue.getSpecVersion().startsWith("3.")) { + throw new InvalidSPDXAnalysisException("Can not create an SPDX 3.X version using the SPDX V2 listed license model"); + } + baseStore.create(typedValue); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getPropertyValueDescriptors(java.lang.String) + */ + @Override + public List getPropertyValueDescriptors( + String objectUri) throws InvalidSPDXAnalysisException { + List retval = new ArrayList<>(); + baseStore.getPropertyValueDescriptors(objectUri).forEach(pd -> { + if (SUPPORTED_V2_DESCRIPTORS.contains(pd)) { + retval.add(pd); + } + }); + return retval; + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#setValue(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public void setValue(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + baseStore.setValue(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getValue(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public Optional getValue(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.getValue(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getNextId(org.spdx.storage.IModelStore.IdType) + */ + @Override + public String getNextId(IdType idType) throws InvalidSPDXAnalysisException { + return baseStore.getNextId(idType); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#removeProperty(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public void removeProperty(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + baseStore.removeProperty(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getAllItems(java.lang.String, java.lang.String) + */ + @Override + public Stream getAllItems(String nameSpace, String typeFilter) + throws InvalidSPDXAnalysisException { + return baseStore.getAllItems(nameSpace, typeFilter).filter(tv -> !tv.getSpecVersion().startsWith("3.")); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#enterCriticalSection(boolean) + */ + @Override + public IModelStoreLock enterCriticalSection(boolean readLockRequested) + throws InvalidSPDXAnalysisException { + return baseStore.enterCriticalSection(readLockRequested); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#leaveCriticalSection(org.spdx.storage.IModelStore.IModelStoreLock) + */ + @Override + public void leaveCriticalSection(IModelStoreLock lock) { + baseStore.leaveCriticalSection(lock); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#removeValueFromCollection(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public boolean removeValueFromCollection(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.removeValueFromCollection(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#collectionSize(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public int collectionSize(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.collectionSize(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#collectionContains(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public boolean collectionContains(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.collectionContains(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#clearValueCollection(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public void clearValueCollection(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + baseStore.clearValueCollection(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#addValueToCollection(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public boolean addValueToCollection(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.addValueToCollection(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#listValues(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public Iterator listValues(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.listValues(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#isCollectionMembersAssignableTo(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Class) + */ + @Override + public boolean isCollectionMembersAssignableTo(String objectUri, + PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, clazz); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#isPropertyValueAssignableTo(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Class, java.lang.String) + */ + @Override + public boolean isPropertyValueAssignableTo(String objectUri, + PropertyDescriptor propertyDescriptor, Class clazz, + String specVersion) throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz, specVersion); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#isCollectionProperty(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public boolean isCollectionProperty(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V2_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V2 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.isCollectionProperty(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getIdType(java.lang.String) + */ + @Override + public IdType getIdType(String objectUri) { + return baseStore.getIdType(objectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getCaseSensisitiveId(java.lang.String, java.lang.String) + */ + @Override + public Optional getCaseSensisitiveId(String nameSpace, + String caseInsensisitiveId) { + return baseStore.getCaseSensisitiveId(nameSpace, caseInsensisitiveId); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getTypedValue(java.lang.String) + */ + @Override + public Optional getTypedValue(String objectUri) + throws InvalidSPDXAnalysisException { + Optional baseTypedValue = baseStore.getTypedValue(objectUri); + if (!baseTypedValue.isPresent() || !baseTypedValue.get().getSpecVersion().startsWith("3.")) { + return baseTypedValue; + } + switch (baseTypedValue.get().getType()) { + case SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE: + return Optional.of(new TypedValue(objectUri, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, ModelObjectV2.LATEST_SPDX_2_VERSION)); + case SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION: + return Optional.of(new TypedValue(objectUri, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, ModelObjectV2.LATEST_SPDX_2_VERSION)); + case SpdxConstantsV3.CORE_CREATION_INFO: + case SpdxConstantsV3.CORE_AGENT: + default: throw new InvalidSPDXAnalysisException("Unsupported type for SPDX V2 listed license model store: "+baseTypedValue.get().getType()); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#delete(java.lang.String) + */ + @Override + public void delete(String objectUri) throws InvalidSPDXAnalysisException { + baseStore.delete(objectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#addExternalReference(java.lang.String, java.lang.String, org.spdx.core.IExternalElementInfo) + */ + @Override + public IExternalElementInfo addExternalReference(String externalObjectUri, + String collectionUri, IExternalElementInfo externalElementInfo) { + return baseStore.addExternalReference(externalObjectUri, collectionUri, externalElementInfo); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getExternalReferenceMap(java.lang.String) + */ + @Override + public Map getExternalReferenceMap( + String externalObjectUri) { + return baseStore.getExternalReferenceMap(externalObjectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getExternalElementInfo(java.lang.String, java.lang.String) + */ + @Override + public IExternalElementInfo getExternalElementInfo(String externalObjectUri, + String collectionUri) { + return baseStore.getExternalElementInfo(externalObjectUri, collectionUri); + } + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxV3ListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxV3ListedLicenseModelStore.java new file mode 100644 index 000000000..7c8558885 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxV3ListedLicenseModelStore.java @@ -0,0 +1,409 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Stream; + +import org.spdx.core.IExternalElementInfo; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; + +/** + * @author gary + * + */ +public class SpdxV3ListedLicenseModelStore implements IModelStore { + + + static Set SUPPORTED_V3_DESCRIPTORS = new HashSet<>(); + + static { + // Licenses + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_SIMPLE_LICENSING_LICENSE_TEXT); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_NAME); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_LICENSE_HEADER); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_OSI_APPROVED); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_FSF_LIBRE); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_DEPRECATED_LICENSE_ID); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_DEPRECATED_VERSION); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_COMMENT); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_LICENSE_TEMPLATE); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LICENSE_XML); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_OBSOLETED_BY); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LIST_VERSION_ADDED); + // Exceptions + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_ADDITION_TEXT); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_ADDITION_TEMPLATE); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_DEPRECATED_ADDITION_ID); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_DEPRECATED_VERSION); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_COMMENT); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LICENSE_XML); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_OBSOLETED_BY); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXPANDED_LICENSING_LIST_VERSION_ADDED); + + // CreationInfo + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_COMMENT); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_CREATED); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_CREATED_BY); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_SPEC_VERSION); + + // Agent + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_CREATION_INFO); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_NAME); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_DESCRIPTION); + + // Collections created on initialization + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXTERNAL_REF); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_VERIFIED_USING); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXTENSION); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_EXTERNAL_IDENTIFIER); + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_CREATED_USING); + + // Unused properties used + SUPPORTED_V3_DESCRIPTORS.add(SpdxConstantsV3.PROP_SUMMARY); + } + + IListedLicenseStore baseStore; + + /** + * @param baseStore store used for the JSON objects containing the license data + */ + public SpdxV3ListedLicenseModelStore(IListedLicenseStore baseStore) { + this.baseStore = baseStore; + } + + /* (non-Javadoc) + * @see java.lang.AutoCloseable#close() + */ + @Override + public void close() throws Exception { + baseStore.close(); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#exists(java.lang.String) + */ + @Override + public boolean exists(String objectUri) { + return baseStore.exists(objectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#create(org.spdx.core.TypedValue) + */ + @Override + public void create(TypedValue typedValue) + throws InvalidSPDXAnalysisException { + if (!typedValue.getSpecVersion().startsWith("3.")) { + throw new InvalidSPDXAnalysisException("Can not create an SPDX 2.X version using the SPDX V3 listed license model"); + } + baseStore.create(typedValue); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getPropertyValueDescriptors(java.lang.String) + */ + @Override + public List getPropertyValueDescriptors( + String objectUri) throws InvalidSPDXAnalysisException { + List retval = new ArrayList<>(); + baseStore.getPropertyValueDescriptors(objectUri).forEach(pd -> { + if (SUPPORTED_V3_DESCRIPTORS.contains(pd)) { + retval.add(pd); + } + }); + return retval; + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#setValue(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public void setValue(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + baseStore.setValue(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getValue(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public Optional getValue(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.getValue(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getNextId(org.spdx.storage.IModelStore.IdType) + */ + @Override + public String getNextId(IdType idType) throws InvalidSPDXAnalysisException { + return baseStore.getNextId(idType); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#removeProperty(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public void removeProperty(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + baseStore.removeProperty(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getAllItems(java.lang.String, java.lang.String) + */ + @Override + public Stream getAllItems(String nameSpace, String typeFilter) + throws InvalidSPDXAnalysisException { + return baseStore.getAllItems(nameSpace, typeFilter).filter(tv -> tv.getSpecVersion().startsWith("3.")); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#enterCriticalSection(boolean) + */ + @Override + public IModelStoreLock enterCriticalSection(boolean readLockRequested) + throws InvalidSPDXAnalysisException { + return baseStore.enterCriticalSection(readLockRequested); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#leaveCriticalSection(org.spdx.storage.IModelStore.IModelStoreLock) + */ + @Override + public void leaveCriticalSection(IModelStoreLock lock) { + baseStore.leaveCriticalSection(lock); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#removeValueFromCollection(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public boolean removeValueFromCollection(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.removeValueFromCollection(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#collectionSize(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public int collectionSize(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.collectionSize(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#collectionContains(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public boolean collectionContains(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.collectionContains(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#clearValueCollection(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public void clearValueCollection(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + baseStore.clearValueCollection(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#addValueToCollection(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Object) + */ + @Override + public boolean addValueToCollection(String objectUri, + PropertyDescriptor propertyDescriptor, Object value) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.addValueToCollection(objectUri, propertyDescriptor, value); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#listValues(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public Iterator listValues(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.listValues(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#isCollectionMembersAssignableTo(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Class) + */ + @Override + public boolean isCollectionMembersAssignableTo(String objectUri, + PropertyDescriptor propertyDescriptor, Class clazz) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, clazz); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#isPropertyValueAssignableTo(java.lang.String, org.spdx.storage.PropertyDescriptor, java.lang.Class, java.lang.String) + */ + @Override + public boolean isPropertyValueAssignableTo(String objectUri, + PropertyDescriptor propertyDescriptor, Class clazz, + String specVersion) throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.isPropertyValueAssignableTo(objectUri, propertyDescriptor, clazz, specVersion); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#isCollectionProperty(java.lang.String, org.spdx.storage.PropertyDescriptor) + */ + @Override + public boolean isCollectionProperty(String objectUri, + PropertyDescriptor propertyDescriptor) + throws InvalidSPDXAnalysisException { + if (!SUPPORTED_V3_DESCRIPTORS.contains(propertyDescriptor)) { + throw new InvalidSPDXAnalysisException("Unsupported property for SPDX V3 Listed License or Exception "+propertyDescriptor.getName()); + } + return baseStore.isCollectionProperty(objectUri, propertyDescriptor); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getIdType(java.lang.String) + */ + @Override + public IdType getIdType(String objectUri) { + return baseStore.getIdType(objectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getCaseSensisitiveId(java.lang.String, java.lang.String) + */ + @Override + public Optional getCaseSensisitiveId(String nameSpace, + String caseInsensisitiveId) { + return baseStore.getCaseSensisitiveId(nameSpace, caseInsensisitiveId); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getTypedValue(java.lang.String) + */ + @Override + public Optional getTypedValue(String objectUri) + throws InvalidSPDXAnalysisException { + Optional baseTypedValue = baseStore.getTypedValue(objectUri); + if (!baseTypedValue.isPresent() || baseTypedValue.get().getSpecVersion().startsWith("3.")) { + return baseTypedValue; + } + switch (baseTypedValue.get().getType()) { + case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE: + return Optional.of(new TypedValue(objectUri, SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE, SpdxConstantsV3.MODEL_SPEC_VERSION)); + case SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION: + return Optional.of(new TypedValue(objectUri, SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION, SpdxConstantsV3.MODEL_SPEC_VERSION)); + case SpdxConstantsV3.CORE_CREATION_INFO: + return Optional.of(new TypedValue(objectUri, SpdxConstantsV3.CORE_CREATION_INFO, SpdxConstantsV3.MODEL_SPEC_VERSION)); + case SpdxConstantsV3.CORE_AGENT: + return Optional.of(new TypedValue(objectUri, SpdxConstantsV3.CORE_AGENT, SpdxConstantsV3.MODEL_SPEC_VERSION)); + default: throw new InvalidSPDXAnalysisException("Unsupported type for SPDX V2 listed license model store: "+baseTypedValue.get().getType()); + } + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#delete(java.lang.String) + */ + @Override + public void delete(String objectUri) throws InvalidSPDXAnalysisException { + baseStore.delete(objectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#addExternalReference(java.lang.String, java.lang.String, org.spdx.core.IExternalElementInfo) + */ + @Override + public IExternalElementInfo addExternalReference(String externalObjectUri, + String collectionUri, IExternalElementInfo externalElementInfo) { + return baseStore.addExternalReference(externalObjectUri, collectionUri, externalElementInfo); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getExternalReferenceMap(java.lang.String) + */ + @Override + public Map getExternalReferenceMap( + String externalObjectUri) { + return baseStore.getExternalReferenceMap(externalObjectUri); + } + + /* (non-Javadoc) + * @see org.spdx.storage.IModelStore#getExternalElementInfo(java.lang.String, java.lang.String) + */ + @Override + public IExternalElementInfo getExternalElementInfo(String externalObjectUri, + String collectionUri) { + return baseStore.getExternalElementInfo(externalObjectUri, collectionUri); + } + +} diff --git a/src/main/java/org/spdx/storage/listedlicense/package-info.java b/src/main/java/org/spdx/storage/listedlicense/package-info.java new file mode 100644 index 000000000..8490547d8 --- /dev/null +++ b/src/main/java/org/spdx/storage/listedlicense/package-info.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Gary O'Neall + * + * Storage for SPDX listed licenses. + * + * The SpdxListedLicenseModelStore is the default storage which pull the data from JSON files at spdx.org/licenses + * + * The SpdxListedLicenseLocalModelStore uses a local copy of the licenses stored in the resources/licenses directory + * + */ +package org.spdx.storage.listedlicense; \ No newline at end of file diff --git a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java index d3f8ebfd4..0ce27f999 100644 --- a/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java +++ b/src/main/java/org/spdx/storage/simple/InMemSpdxStore.java @@ -40,12 +40,11 @@ import org.spdx.core.IExternalElementInfo; import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.core.ModelCollection; -import org.spdx.core.ModelRegistry; import org.spdx.core.SpdxIdInUseException; import org.spdx.core.SpdxIdNotFoundException; import org.spdx.core.TypedValue; +import org.spdx.library.LicenseInfoFactory; import org.spdx.library.model.v2.SpdxConstantsCompatV2; -import org.spdx.library.model.v2.license.LicenseInfoFactory; import org.spdx.storage.IModelStore; import org.spdx.storage.PropertyDescriptor; diff --git a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java index 296955be9..bbd1ef977 100644 --- a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java +++ b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java @@ -38,16 +38,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spdx.core.InvalidSPDXAnalysisException; -import org.spdx.library.model.v2.license.AnyLicenseInfo; -import org.spdx.library.model.v2.license.ConjunctiveLicenseSet; -import org.spdx.library.model.v2.license.DisjunctiveLicenseSet; -import org.spdx.library.model.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.v2.license.License; -import org.spdx.library.model.v2.license.LicenseException; -import org.spdx.library.model.v2.license.LicenseSet; -import org.spdx.library.model.v2.license.ListedLicenseException; -import org.spdx.library.model.v2.license.ListedLicenses; -import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.ListedLicenses; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingConjunctiveLicenseSet; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingCustomLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingDisjunctiveLicenseSet; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.library.model.v3.simplelicensing.SimpleLicensingAnyLicenseInfo; import org.spdx.licenseTemplate.LicenseParserException; import org.spdx.licenseTemplate.LicenseTemplateRuleException; import org.spdx.licenseTemplate.SpdxLicenseTemplateHelper; @@ -567,28 +564,28 @@ static boolean canSkip(String token) { * @throws SpdxCompareException * @throws InvalidSPDXAnalysisException */ - public static boolean isLicenseEqual(AnyLicenseInfo license1, - AnyLicenseInfo license2, Map xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisException { - if (license1 instanceof ConjunctiveLicenseSet) { - if (!(license2 instanceof ConjunctiveLicenseSet)) { + public static boolean isLicenseEqual(SimpleLicensingAnyLicenseInfo license1, + SimpleLicensingAnyLicenseInfo license2, Map xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisException { + if (license1 instanceof ExpandedLicensingConjunctiveLicenseSet) { + if (!(license2 instanceof ExpandedLicensingConjunctiveLicenseSet)) { return false; } else { - return isLicenseSetsEqual((ConjunctiveLicenseSet)license1, - (ConjunctiveLicenseSet)license2, xlationMap); + return isLicenseSetsEqual(((ExpandedLicensingConjunctiveLicenseSet)license1).getExpandedLicensingMembers(), + ((ExpandedLicensingConjunctiveLicenseSet)license2).getExpandedLicensingMembers(), xlationMap); } - } else if (license1 instanceof DisjunctiveLicenseSet) { - if (!(license2 instanceof DisjunctiveLicenseSet)) { + } else if (license1 instanceof ExpandedLicensingDisjunctiveLicenseSet) { + if (!(license2 instanceof ExpandedLicensingDisjunctiveLicenseSet)) { return false; } else { - return isLicenseSetsEqual((DisjunctiveLicenseSet)license1, - (DisjunctiveLicenseSet)license2, xlationMap); + return isLicenseSetsEqual(((ExpandedLicensingDisjunctiveLicenseSet)license1).getExpandedLicensingMembers(), + ((ExpandedLicensingDisjunctiveLicenseSet)license2).getExpandedLicensingMembers(), xlationMap); } - } else if (license1 instanceof ExtractedLicenseInfo) { - if (!(license2 instanceof ExtractedLicenseInfo)) { + } else if (license1 instanceof ExpandedLicensingCustomLicense) { + if (!(license2 instanceof ExpandedLicensingCustomLicense)) { return false; } else { - String licenseid1 = ((ExtractedLicenseInfo)license1).getLicenseId(); - String licenseid2 = ((ExtractedLicenseInfo)license2).getLicenseId(); + String licenseid1 = ((ExpandedLicensingCustomLicense)license1).getObjectUri(); + String licenseid2 = ((ExpandedLicensingCustomLicense)license2).getObjectUri(); String xlatedLicenseId = xlationMap.get(licenseid1); if (xlatedLicenseId == null) { return false; // no equivalent license was found @@ -608,10 +605,9 @@ public static boolean isLicenseEqual(AnyLicenseInfo license1, * @throws SpdxCompareException * @throws InvalidSPDXAnalysisException */ - private static boolean isLicenseSetsEqual(LicenseSet license1, LicenseSet license2, Map xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisException { + private static boolean isLicenseSetsEqual(Collection licenseInfos1, + Collection licenseInfos2, Map xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisException { // note - order does not matter - Collection licenseInfos1 = license1.getMembers(); - Collection licenseInfos2 = license2.getMembers(); if (licenseInfos1 == null) { return licenseInfos2 == null; } @@ -621,9 +617,9 @@ private static boolean isLicenseSetsEqual(LicenseSet license1, LicenseSet licens if (licenseInfos1.size() != licenseInfos2.size()) { return false; } - for (AnyLicenseInfo ali1:licenseInfos1) { + for (SimpleLicensingAnyLicenseInfo ali1:licenseInfos1) { boolean found = false; - for (AnyLicenseInfo ali2:licenseInfos2) { + for (SimpleLicensingAnyLicenseInfo ali2:licenseInfos2) { if (isLicenseEqual(ali1, ali2, xlationMap)) { found = true; break; @@ -636,19 +632,6 @@ private static boolean isLicenseSetsEqual(LicenseSet license1, LicenseSet licens return true; } - /** - * Get the text of a license minus any optional text - note: this include the default variable text - * @param licenseTemplate license template containing optional and var tags - * @param includeVarText if true, include the default variable text; if false remove the variable text - * @return list of strings for all non-optional license text. - * @throws SpdxCompareException - */ - @Deprecated - public static List getNonOptionalLicenseText(String licenseTemplate, boolean includeVarText) throws SpdxCompareException { - return getNonOptionalLicenseText(licenseTemplate, - includeVarText ? VarTextHandling.ORIGINAL : VarTextHandling.OMIT); - } - /** * Get the text of a license minus any optional text - note: this include the default variable text * @param licenseTemplate license template containing optional and var tags @@ -984,7 +967,7 @@ private static String findTemplateWithinText(String text, String template) throw * @param license The standard SPDX license to search for (should not be null) * @return True if the license is found within the text, false otherwise (or if either argument is null) */ - public static boolean isStandardLicenseWithinText(String text, SpdxListedLicense license) { + public static boolean isStandardLicenseWithinText(String text, ExpandedLicensingListedLicense license) { boolean result = false; if (text == null || text.isEmpty() || license == null) { @@ -992,14 +975,14 @@ public static boolean isStandardLicenseWithinText(String text, SpdxListedLicense } try { - String completeText = findTemplateWithinText(text, license.getStandardLicenseTemplate()); + String completeText = findTemplateWithinText(text, license.getExpandedLicensingStandardLicenseTemplate()); if (completeText != null) { result = !isTextStandardLicense(license, completeText).isDifferenceFound(); } } catch (SpdxCompareException e) { - logger.warn("Error getting optional text for license ID " + license.getLicenseId(), e); + logger.warn("Error getting optional text for license ID " + license.getObjectUri(), e); } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting optional text for license ID " + license.getLicenseId(), e); + logger.warn("Error getting optional text for license ID " + license.getObjectUri(), e); } return result; @@ -1012,7 +995,7 @@ public static boolean isStandardLicenseWithinText(String text, SpdxListedLicense * @param exception The standard SPDX license exception to search for (should not be null) * @return True if the license exception is found within the text, false otherwise (or if either argument is null) */ - public static boolean isStandardLicenseExceptionWithinText(String text, ListedLicenseException exception) { + public static boolean isStandardLicenseExceptionWithinText(String text, ExpandedLicensingListedLicenseException exception) { boolean result = false; if (text == null || text.isEmpty() || exception == null) { @@ -1020,14 +1003,14 @@ public static boolean isStandardLicenseExceptionWithinText(String text, ListedLi } try { - String completeText = findTemplateWithinText(text, exception.getLicenseExceptionTemplate()); + String completeText = findTemplateWithinText(text, exception.getExpandedLicensingStandardAdditionTemplate()); if (completeText != null) { result = !isTextStandardException(exception, completeText).isDifferenceFound(); } } catch (SpdxCompareException e) { - logger.warn("Error getting optional text for license exception ID " + exception.getLicenseExceptionId(), e); + logger.warn("Error getting optional text for license exception ID " + exception.getObjectUri(), e); } catch (InvalidSPDXAnalysisException e) { - logger.warn("Error getting optional text for license exception ID " + exception.getLicenseExceptionId(), e); + logger.warn("Error getting optional text for license exception ID " + exception.getObjectUri(), e); } return result; @@ -1046,7 +1029,7 @@ public static String[] matchingStandardLicenseIds(String licenseText) throws Inv List stdLicenseIds = ListedLicenses.getListedLicenses().getSpdxListedLicenseIds(); List matchingIds = new ArrayList<>(); for (String stdLicId : stdLicenseIds) { - SpdxListedLicense license = ListedLicenses.getListedLicenses().getListedLicenseById(stdLicId); + ExpandedLicensingListedLicense license = ListedLicenses.getListedLicenses().getListedLicenseById(stdLicId); if (!isTextStandardLicense(license, licenseText).isDifferenceFound()) { matchingIds.add(license.getLicenseId()); } @@ -1214,5 +1197,277 @@ public static boolean isLicensePassWhiteList( return contains(whiteList, license.toString()); } } + + /** + * The following methods are provided for compatibility with the SPDX 2.X versions of the + * library + */ + + /** + * Compares two licenses from potentially two different documents which may have + * different license ID's for the same license + * @param license1 + * @param license2 + * @param xlationMap Mapping the license ID's from license 1 to license 2 + * @return + * @throws SpdxCompareException + * @throws InvalidSPDXAnalysisException + */ + public static boolean isLicenseEqual(org.spdx.library.model.v2.license.AnyLicenseInfo license1, + org.spdx.library.model.v2.license.AnyLicenseInfo license2, Map xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisException { + if (license1 instanceof org.spdx.library.model.v2.license.ConjunctiveLicenseSet) { + if (!(license2 instanceof org.spdx.library.model.v2.license.ConjunctiveLicenseSet)) { + return false; + } else { + return isLicenseSetsEqual((org.spdx.library.model.v2.license.ConjunctiveLicenseSet)license1, + (org.spdx.library.model.v2.license.ConjunctiveLicenseSet)license2, xlationMap); + } + } else if (license1 instanceof org.spdx.library.model.v2.license.DisjunctiveLicenseSet) { + if (!(license2 instanceof org.spdx.library.model.v2.license.DisjunctiveLicenseSet)) { + return false; + } else { + return isLicenseSetsEqual((org.spdx.library.model.v2.license.DisjunctiveLicenseSet)license1, + (org.spdx.library.model.v2.license.DisjunctiveLicenseSet)license2, xlationMap); + } + } else if (license1 instanceof org.spdx.library.model.v2.license.ExtractedLicenseInfo) { + if (!(license2 instanceof org.spdx.library.model.v2.license.ExtractedLicenseInfo)) { + return false; + } else { + String licenseid1 = ((org.spdx.library.model.v2.license.ExtractedLicenseInfo)license1).getLicenseId(); + String licenseid2 = ((org.spdx.library.model.v2.license.ExtractedLicenseInfo)license2).getLicenseId(); + String xlatedLicenseId = xlationMap.get(licenseid1); + if (xlatedLicenseId == null) { + return false; // no equivalent license was found + } + return xlatedLicenseId.equals(licenseid2); + } + } else { + return license1.equals(license2); + } + } + + /** + * Compares two license sets using the xlationMap for the non-standard license IDs + * @param license1 + * @param license2 + * @return + * @throws SpdxCompareException + * @throws InvalidSPDXAnalysisException + */ + private static boolean isLicenseSetsEqual(org.spdx.library.model.v2.license.LicenseSet license1, + org.spdx.library.model.v2.license.LicenseSet license2, Map xlationMap) throws SpdxCompareException, InvalidSPDXAnalysisException { + // note - order does not matter + Collection licenseInfos1 = license1.getMembers(); + Collection licenseInfos2 = license2.getMembers(); + if (licenseInfos1 == null) { + return licenseInfos2 == null; + } + if (licenseInfos2 == null) { + return false; + } + if (licenseInfos1.size() != licenseInfos2.size()) { + return false; + } + for (org.spdx.library.model.v2.license.AnyLicenseInfo ali1:licenseInfos1) { + boolean found = false; + for (org.spdx.library.model.v2.license.AnyLicenseInfo ali2:licenseInfos2) { + if (isLicenseEqual(ali1, ali2, xlationMap)) { + found = true; + break; + } + } + if (!found) { + return false; + } + } + return true; + } + + /** + * Compares license text to the license text of an SPDX Standard License + * @param license SPDX Standard License to compare + * @param compareText Text to compare to the standard license + * @return any differences found + * @throws SpdxCompareException + * @throws InvalidSPDXAnalysisException + */ + public static DifferenceDescription isTextStandardLicense(org.spdx.library.model.v2.license.License license, String compareText) throws SpdxCompareException, InvalidSPDXAnalysisException { + String licenseTemplate = license.getStandardLicenseTemplate(); + if (licenseTemplate == null || licenseTemplate.trim().isEmpty()) { + licenseTemplate = license.getLicenseText(); + } + CompareTemplateOutputHandler compareTemplateOutputHandler = null; + try { + compareTemplateOutputHandler = new CompareTemplateOutputHandler(removeLineSeparators(removeCommentChars(compareText))); + } catch (IOException e1) { + throw new SpdxCompareException("IO Error reading the compare text: "+e1.getMessage(),e1); + } + try { + //TODO: The remove comment chars will not be removed for lines beginning with a template << or ending with >> + SpdxLicenseTemplateHelper.parseTemplate(removeCommentChars(licenseTemplate), compareTemplateOutputHandler); + } catch (LicenseTemplateRuleException e) { + throw new SpdxCompareException("Invalid template rule found during compare: "+e.getMessage(),e); + } catch (LicenseParserException e) { + throw new SpdxCompareException("Invalid template found during compare: "+e.getMessage(),e); + } + return compareTemplateOutputHandler.getDifferences(); + } + + /** + * Compares exception text to the exception text of an SPDX Standard exception + * @param exception SPDX Standard exception to compare + * @param compareText Text to compare to the standard exceptions + * @return any differences found + * @throws SpdxCompareException + * @throws InvalidSPDXAnalysisException + */ + public static DifferenceDescription isTextStandardException(org.spdx.library.model.v2.license.LicenseException exception, String compareText) throws SpdxCompareException, InvalidSPDXAnalysisException { + String exceptionTemplate = exception.getLicenseExceptionTemplate(); + if (exceptionTemplate == null || exceptionTemplate.trim().isEmpty()) { + exceptionTemplate = exception.getLicenseExceptionText(); + } + CompareTemplateOutputHandler compareTemplateOutputHandler = null; + try { + compareTemplateOutputHandler = new CompareTemplateOutputHandler(removeLineSeparators(removeCommentChars(compareText))); + } catch (IOException e1) { + throw new SpdxCompareException("IO Error reading the compare text: "+e1.getMessage(),e1); + } + try { + //TODO: The remove comment chars will not be removed for lines beginning with a template << or ending with >> + SpdxLicenseTemplateHelper.parseTemplate(removeCommentChars(exceptionTemplate), compareTemplateOutputHandler); + } catch (LicenseTemplateRuleException e) { + throw new SpdxCompareException("Invalid template rule found during compare: "+e.getMessage(),e); + } catch (LicenseParserException e) { + throw new SpdxCompareException("Invalid template found during compare: "+e.getMessage(),e); + } + return compareTemplateOutputHandler.getDifferences(); + } + + /** + * Detect if a text contains the standard license (perhaps along with other text before and/or after) + * @param text The text to search within (should not be null) + * @param license The standard SPDX license to search for (should not be null) + * @return True if the license is found within the text, false otherwise (or if either argument is null) + */ + public static boolean isStandardLicenseWithinText(String text, org.spdx.library.model.v2.license.SpdxListedLicense license) { + boolean result = false; + + if (text == null || text.isEmpty() || license == null) { + return false; + } + + try { + String completeText = findTemplateWithinText(text, license.getStandardLicenseTemplate()); + if (completeText != null) { + result = !isTextStandardLicense(license, completeText).isDifferenceFound(); + } + } catch (SpdxCompareException e) { + logger.warn("Error getting optional text for license ID " + license.getLicenseId(), e); + } catch (InvalidSPDXAnalysisException e) { + logger.warn("Error getting optional text for license ID " + license.getLicenseId(), e); + } + + return result; + } + + + /** + * Detect if a text contains the standard license exception (perhaps along with other text before and/or after) + * @param text The text to search within (should not be null) + * @param exception The standard SPDX license exception to search for (should not be null) + * @return True if the license exception is found within the text, false otherwise (or if either argument is null) + */ + public static boolean isStandardLicenseExceptionWithinText(String text, org.spdx.library.model.v2.license.ListedLicenseException exception) { + boolean result = false; + + if (text == null || text.isEmpty() || exception == null) { + return false; + } + + try { + String completeText = findTemplateWithinText(text, exception.getLicenseExceptionTemplate()); + if (completeText != null) { + result = !isTextStandardException(exception, completeText).isDifferenceFound(); + } + } catch (SpdxCompareException e) { + logger.warn("Error getting optional text for license exception ID " + exception.getLicenseExceptionId(), e); + } catch (InvalidSPDXAnalysisException e) { + logger.warn("Error getting optional text for license exception ID " + exception.getLicenseExceptionId(), e); + } + + return result; + } + + /** + * Detect if a license pass black lists + * @param license license + * @param blackList license black list + * @return if the license pass black lists + * @throws InvalidSPDXAnalysisException + */ + public static boolean isLicensePassBlackList( + org.spdx.library.model.v2.license.AnyLicenseInfo license, + String... blackList + ) throws InvalidSPDXAnalysisException { + if (license == null) { + return true; + } + if (blackList == null || blackList.length == 0) { + return true; + } + if (license instanceof org.spdx.library.model.v2.license.ConjunctiveLicenseSet) { + for (org.spdx.library.model.v2.license.AnyLicenseInfo member : ((org.spdx.library.model.v2.license.ConjunctiveLicenseSet) license).getMembers()) { + if (!isLicensePassBlackList(member, blackList)) { + return false; + } + } + return true; + } else if (license instanceof org.spdx.library.model.v2.license. DisjunctiveLicenseSet) { + for (org.spdx.library.model.v2.license.AnyLicenseInfo member : ((org.spdx.library.model.v2.license.DisjunctiveLicenseSet) license).getMembers()) { + if (isLicensePassBlackList(member, blackList)) { + return true; + } + } + return false; + } else { + return !contains(blackList, license.toString()); + } + } + + /** + * Detect if a license pass white lists + * @param license license + * @param whiteList license white list + * @return if the license pass white lists + * @throws InvalidSPDXAnalysisException + */ + public static boolean isLicensePassWhiteList( + org.spdx.library.model.v2.license.AnyLicenseInfo license, + String... whiteList + ) throws InvalidSPDXAnalysisException { + if (license == null) { + return false; + } + if (whiteList == null || whiteList.length == 0) { + return false; + } + if (license instanceof org.spdx.library.model.v2.license.ConjunctiveLicenseSet) { + for (org.spdx.library.model.v2.license.AnyLicenseInfo member : ((org.spdx.library.model.v2.license.ConjunctiveLicenseSet) license).getMembers()) { + if (!isLicensePassWhiteList(member, whiteList)) { + return false; + } + } + return true; + } else if (license instanceof org.spdx.library.model.v2.license.DisjunctiveLicenseSet) { + for (org.spdx.library.model.v2.license.AnyLicenseInfo member : ((org.spdx.library.model.v2.license.DisjunctiveLicenseSet) license).getMembers()) { + if (isLicensePassWhiteList(member, whiteList)) { + return true; + } + } + return false; + } else { + return contains(whiteList, license.toString()); + } + } } \ No newline at end of file diff --git a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java new file mode 100644 index 000000000..f44193aac --- /dev/null +++ b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java @@ -0,0 +1,385 @@ +/** + * Copyright (c) 2019 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.utility.license; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EmptyStackException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Stack; + +import org.spdx.core.IModelCopyManager; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.LicenseInfoFactory; +import org.spdx.library.model.v2.ModelObjectV2; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.SpdxModelFactory; +import org.spdx.library.model.v2.license.AnyLicenseInfo; +import org.spdx.library.model.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.v2.license.ExternalExtractedLicenseInfo; +import org.spdx.library.model.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.OrLaterOperator; +import org.spdx.library.model.v2.license.SimpleLicensingInfo; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.v2.license.SpdxNoneLicense; +import org.spdx.library.model.v2.license.WithExceptionOperator; +import org.spdx.storage.IModelStore; +import org.spdx.storage.IModelStore.IdType; + +/** + * A parser for the SPDX License Expressions as documented in the SPDX appendix. + * + * This is a static help class. The primary method is parseLicenseExpression which + * returns an AnyLicenseInfo. + * @author Gary O'Neall + * + */ +public class LicenseExpressionParser { + + enum Operator { + OR_LATER, WITH, AND, OR //NOTE: These must be in precedence order + }; + static final String LEFT_PAREN = "("; + static final String RIGHT_PAREN = ")"; + static final Map OPERATOR_MAP = new HashMap<>(); + public static final String UNINITIALIZED_LICENSE_TEXT = "[Initialized with license Parser. The actual license text is not available]"; + + static { + OPERATOR_MAP.put("+", Operator.OR_LATER); + OPERATOR_MAP.put("AND", Operator.AND); + OPERATOR_MAP.put("OR", Operator.OR); + OPERATOR_MAP.put("WITH", Operator.WITH); + OPERATOR_MAP.put("and", Operator.AND); + OPERATOR_MAP.put("or", Operator.OR); + OPERATOR_MAP.put("with", Operator.WITH); + } + /** + * Parses a license expression into an license for use in the Model + * @param expression Expression to be parsed + * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model store will be used. + * @param documentUri Document URI for the document containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model document URI will be used. + * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's + * @return the parsed license expression + * @throws InvalidSPDXAnalysisException + */ + public static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (expression == null || expression.trim().isEmpty()) { + throw new LicenseParserException("Empty license expression"); + } + Objects.requireNonNull(store, "Model store can not be null"); + Objects.requireNonNull(documentUri, "Document URI can not be null"); + String[] tokens = tokenizeExpression(expression); + if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) { + return new SpdxNoAssertionLicense(); + } else if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NONE_VALUE)) { + return new SpdxNoneLicense(); + } else { + try { + return parseLicenseExpression(tokens, store, documentUri, copyManager); + } catch (LicenseParserException ex) { + // Add the expression to the error message to provide additional information to the user + throw new LicenseParserException(ex.getMessage()+" License expression: '"+expression+"'", ex); + } catch (EmptyStackException ex) { + throw new LicenseParserException("Invalid license expression: '"+expression+"' - check that every operator (e.g. AND and OR) has operators and that parenthesis are matched"); + } + } + } + + /** + * A custom tokenizer since there is not white space between parents and pluses + * @param expression + * @return + */ + private static String[] tokenizeExpression(String expression) { + String[] startTokens = expression.split("\\s"); + List endTokens = new ArrayList<>(); + for (String token : startTokens) { + processPreToken(token, endTokens); + } + return endTokens.toArray(new String[endTokens.size()]); + } + + /** + * @param preToken + * @param tokenList + */ + private static void processPreToken(String preToken, + List tokenList) { + if (preToken.isEmpty()) { + return; + } else if (preToken.startsWith("(")) { + tokenList.add("("); + processPreToken(preToken.substring(1), tokenList); + } else if (preToken.endsWith(")")) { + processPreToken(preToken.substring(0, preToken.length()-1), tokenList); + tokenList.add(")"); + } else if (preToken.endsWith("+")) { + processPreToken(preToken.substring(0, preToken.length()-1), tokenList); + tokenList.add("+"); + } else { + tokenList.add(preToken); + } + } + + /** + * Parses a tokenized license expression into a license for use in the RDF Parser + * @param tokens + * @param store + * @param documentUri + * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's + * @return + * @throws InvalidSPDXAnalysisException + */ + private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (tokens == null || tokens.length == 0) { + throw new LicenseParserException("Expected license expression"); + } + Stack operandStack = new Stack(); + Stack operatorStack = new Stack(); + int tokenIndex = 0; + String token; + while (tokenIndex < tokens.length) { + token = tokens[tokenIndex++]; + // left operand + if (LEFT_PAREN.equals(token)) { + int rightParenIndex = findMatchingParen(tokens, tokenIndex); + if (rightParenIndex < 0) { + throw new LicenseParserException("Missing right parenthesis"); + } + String[] nestedTokens = Arrays.copyOfRange(tokens, tokenIndex, rightParenIndex); + operandStack.push(parseLicenseExpression(nestedTokens, store, documentUri, copyManager)); + tokenIndex = rightParenIndex + 1; + } else if (OPERATOR_MAP.get(token) == null) { // assumed to be a simple licensing type + operandStack.push(parseSimpleLicenseToken(token, store, documentUri, copyManager)); + } else { + Operator operator = OPERATOR_MAP.get(token); + if (operator == Operator.WITH) { + // special processing here since With must be with an exception, not a licenseInfo + if (!operatorStack.isEmpty() && Operator.OR_LATER.equals(operatorStack.peek())) { + Operator tosOperator = operatorStack.pop(); + evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + } + if (tokenIndex >= tokens.length) { + throw new LicenseParserException("Missing exception clause"); + } + token = tokens[tokenIndex++]; + ListedLicenseException licenseException = null; + Optional exceptionId = Optional.empty(); + if (LicenseInfoFactory.isSpdxListedExceptionId(token)) { + exceptionId = LicenseInfoFactory.listedExceptionIdCaseSensitive(token); + } + if (exceptionId.isPresent()) { + licenseException = LicenseInfoFactory.getListedExceptionById(exceptionId.get()); + } else if (token.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { + throw new LicenseParserException("WITH must be followed by a license exception. "+token+" is a Listed License type."); + } else { + licenseException = (ListedLicenseException) SpdxModelFactory.createModelObjectV2(store, + documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, copyManager); + } + AnyLicenseInfo operand = operandStack.pop(); + if (operand == null) { + throw new LicenseParserException("Missing license for with clause"); + } + if (!((operand instanceof SimpleLicensingInfo) || (operand instanceof OrLaterOperator))) { + throw new LicenseParserException("License with exception is not of type SimpleLicensingInfo or OrLaterOperator"); + } + WithExceptionOperator weo = new WithExceptionOperator(store, documentUri, store.getNextId(IdType.Anonymous), copyManager, true); + weo.setLicense(operand); + weo.setException(licenseException); + operandStack.push(weo); + } else { + // process in order of precedence using the shunting yard algorithm + while (!operatorStack.isEmpty() && + operatorStack.peek().ordinal() <= operator.ordinal()) { + Operator tosOperator = operatorStack.pop(); + evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + } + operatorStack.push(operator); + } + } + } + // go through the rest of the stack + while (!operatorStack.isEmpty()) { + Operator tosOperator = operatorStack.pop(); + evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + } + AnyLicenseInfo retval = operandStack.pop(); + if (!operandStack.isEmpty()) { + throw new LicenseParserException("Invalid license expression. Expecting more operands."); + } + return retval; + } + + /** + * Returns the index of the rightmost parenthesis or -1 if not found + * @param tokens + * @return + */ + private static int findMatchingParen(String[] tokens, int startToken) { + if (tokens == null) { + return -1; + } + int nestCount = 0; + for (int i = startToken; i < tokens.length; i++) { + if (LEFT_PAREN.equals(tokens[i])) { + nestCount++; + } else if (RIGHT_PAREN.equals(tokens[i])) { + if (nestCount == 0) { + return i; + } else { + nestCount--; + } + } + } + return -1; + } + + /** + * Converts a string token into its equivalent license + * checking for a listed license + * @param token + * @param baseStore + * @param documentUri + * @param copyManager + * @return + * @throws InvalidSPDXAnalysisException + */ + private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String documentUri, + IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(token, "Token can not be null"); + Objects.requireNonNull(store, "Model store can not be null"); + Objects.requireNonNull(documentUri, "Document URI can not be null"); + if (token.contains(":")) { + // External License Ref + return new ExternalExtractedLicenseInfo(store, documentUri, token, copyManager, true); + } + Optional licenseId = Optional.empty(); + if (LicenseInfoFactory.isSpdxListedLicenseId(token)) { + // listed license + licenseId = LicenseInfoFactory.listedLicenseIdCaseSensitive(token); + } + if (licenseId.isPresent()) { + if (!store.exists(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX + licenseId.get())) { + SpdxListedLicense listedLicense = LicenseInfoFactory.getListedLicenseById(licenseId.get()); + if (Objects.nonNull(copyManager)) { + // copy to the local store + copyManager.copy(store, listedLicense.getObjectUri(), listedLicense.getModelStore(), + listedLicense.getObjectUri(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, + ModelObjectV2.LATEST_SPDX_2_VERSION, listedLicense.getDocumentUri()); + } + } + return (AnyLicenseInfo) SpdxModelFactory.getModelObjectV2(store, SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, + licenseId.get(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager, true); + } else { + // LicenseRef + Optional caseSensitiveId = store.getCaseSensisitiveId(documentUri, token); + ExtractedLicenseInfo localLicense = null; + if (caseSensitiveId.isPresent()) { + localLicense = new ExtractedLicenseInfo(store, documentUri, caseSensitiveId.get(), copyManager, false); + + } else { + localLicense = (ExtractedLicenseInfo) SpdxModelFactory.createModelObjectV2( + store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); + localLicense.setExtractedText(UNINITIALIZED_LICENSE_TEXT); + } + return localLicense; + } + } + + /** + * Evaluate the given operator using paramaeters in the parameter stack + * @param operator + * @param operandStack + * @param copyManager + * @throws InvalidSPDXAnalysisException + */ + private static void evaluateExpression(Operator operator, + Stack operandStack, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (operator == Operator.OR_LATER) { + // unary operator + AnyLicenseInfo license = operandStack.pop(); + if (!(license instanceof SimpleLicensingInfo)) { + throw new LicenseParserException("Missing license for the '+' or later operator"); + } + OrLaterOperator olo = new OrLaterOperator(store, documentUri, store.getNextId(IdType.Anonymous), copyManager, true); + olo.setLicense((SimpleLicensingInfo)license); + operandStack.push(olo); + } else { + // binary operator + AnyLicenseInfo operand2 = operandStack.pop(); + AnyLicenseInfo operand1 = operandStack.pop(); + if (operand1 == null || operand2 == null) { + throw new LicenseParserException("Missing operands for the "+operator.toString()+" operator"); + } + operandStack.push(evaluateBinary(operator, operand1, operand2, store, documentUri, copyManager)); + } + } + + /** + * Evaluates a binary expression and merges conjuctive and disjunctive licenses + * @param tosOperator + * @param operand1 + * @param operand2 + * @param copyManager + * @return + * @throws InvalidSPDXAnalysisException + */ + private static AnyLicenseInfo evaluateBinary(Operator tosOperator, + AnyLicenseInfo operand1, AnyLicenseInfo operand2, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (tosOperator == Operator.AND) { + if (operand1 instanceof ConjunctiveLicenseSet) { + // just merge into operand1 + ((ConjunctiveLicenseSet) operand1).addMember(operand2); + return operand1; + } else { + ConjunctiveLicenseSet retval = new ConjunctiveLicenseSet(store, documentUri, + store.getNextId(IdType.Anonymous), copyManager, true); + retval.addMember(operand1); + retval.addMember(operand2); + return retval; + } + } else if (tosOperator == Operator.OR) { + if (operand1 instanceof DisjunctiveLicenseSet) { + // just merge into operand1 + ((DisjunctiveLicenseSet) operand1).addMember(operand2); + return operand1; + } else { + DisjunctiveLicenseSet retval = new DisjunctiveLicenseSet(store, documentUri, + store.getNextId(IdType.Anonymous), copyManager, true); + retval.addMember(operand1); + retval.addMember(operand2); + return retval; + } + } else { + throw new LicenseParserException("Unknown operator "+tosOperator.toString()); + } + } +} diff --git a/src/main/java/org/spdx/utility/license/LicenseParserException.java b/src/main/java/org/spdx/utility/license/LicenseParserException.java new file mode 100644 index 000000000..3e02a9407 --- /dev/null +++ b/src/main/java/org/spdx/utility/license/LicenseParserException.java @@ -0,0 +1,22 @@ +package org.spdx.utility.license; + +import org.spdx.core.InvalidSPDXAnalysisException; + +public class LicenseParserException extends InvalidSPDXAnalysisException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * @param msg + */ + public LicenseParserException(String msg) { + super(msg); + } + + public LicenseParserException(String msg, Throwable inner) { + super(msg, inner); + } +} diff --git a/src/main/java/org/spdx/utility/license/package-info.java b/src/main/java/org/spdx/utility/license/package-info.java new file mode 100644 index 000000000..d7bb67e42 --- /dev/null +++ b/src/main/java/org/spdx/utility/license/package-info.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Gary O'Neall + * + * Utilities to help with license expression parsing and creation + * + */ +package org.spdx.utility.license; \ No newline at end of file diff --git a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonV2Test.java similarity index 60% rename from src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java rename to src/test/java/org/spdx/storage/listedlicense/CrossRefJsonV2Test.java index 3ab53416e..1dbd38030 100644 --- a/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/CrossRefJsonV2Test.java @@ -7,32 +7,33 @@ import java.util.Map; import java.util.Objects; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.InvalidSpdxPropertyException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.license.CrossRef; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSpdxPropertyException; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.CrossRef; import org.spdx.storage.IModelStore; +import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.simple.InMemSpdxStore; import junit.framework.TestCase; -public class CrossRefJsonTest extends TestCase { +public class CrossRefJsonV2Test extends TestCase { - static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH.getName(), - SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP.getName(), - SpdxConstantsCompatV2.PROP_CROSS_REF_URL.getName()); + static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( + SpdxConstantsCompatV2.PROP_CROSS_REF_MATCH, + SpdxConstantsCompatV2.PROP_CROSS_REF_TIMESTAMP, + SpdxConstantsCompatV2.PROP_CROSS_REF_URL); - static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE.getName(), - SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID.getName(), - SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK.getName() + static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( + SpdxConstantsCompatV2.PROP_CROSS_REF_IS_LIVE, + SpdxConstantsCompatV2.PROP_CROSS_REF_IS_VALID, + SpdxConstantsCompatV2.PROP_CROSS_REF_WAYBACK_LINK ); - static final List INTEGER_PROPERTY_VALUE_NAMES = Arrays.asList(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER.getName()); + static final List INTEGER_PROPERTY_VALUE_NAMES = Arrays.asList(SpdxConstantsCompatV2.PROP_CROSS_REF_ORDER); - static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); + static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); static { PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); @@ -42,6 +43,7 @@ public class CrossRefJsonTest extends TestCase { protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } protected void tearDown() throws Exception { @@ -49,7 +51,7 @@ protected void tearDown() throws Exception { } public void testCrossRefJsonCrossRef() throws InvalidSPDXAnalysisException { - IModelStore modelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + IModelStore modelStore = new InMemSpdxStore(); String docUri = "http://doc/uri"; String id = "tempid"; String url = "http://url"; @@ -80,21 +82,21 @@ public void testCrossRefJsonCrossRef() throws InvalidSPDXAnalysisException { public void testGetPropertyValueNames() throws InvalidSpdxPropertyException { CrossRefJson crj = new CrossRefJson(); - List result = crj.getPropertyValueNames(); + List result = crj.getPropertyValueDescriptors(); assertEquals(0, result.size()); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTY_VALUE_NAMES) { crj.setPrimativeValue(valueName, "ValueFor"+valueName); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { crj.setPrimativeValue(valueName, false); } int i = 1; - for (String valueName:INTEGER_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:INTEGER_PROPERTY_VALUE_NAMES) { crj.setPrimativeValue(valueName, i++); } - result = crj.getPropertyValueNames(); + result = crj.getPropertyValueDescriptors(); assertEquals(PROPERTY_VALUE_NAMES.size(), result.size()); - for (String valueName:PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:PROPERTY_VALUE_NAMES) { if (!result.contains(valueName)) { fail("Missing "+valueName); } @@ -102,30 +104,30 @@ public void testGetPropertyValueNames() throws InvalidSpdxPropertyException { } public void testSetPrimativeValue() throws InvalidSpdxPropertyException { - Map stringValues = new HashMap<>(); + Map stringValues = new HashMap<>(); CrossRefJson crj = new CrossRefJson(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTY_VALUE_NAMES) { stringValues.put(valueName, "ValueFor"+valueName); crj.setPrimativeValue(valueName, stringValues.get(valueName)); } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { booleanValues.put(valueName, false); crj.setPrimativeValue(valueName, booleanValues.get(valueName)); } - Map integerValues = new HashMap<>(); + Map integerValues = new HashMap<>(); int i = 1; - for (String valueName:INTEGER_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:INTEGER_PROPERTY_VALUE_NAMES) { integerValues.put(valueName, i++); crj.setPrimativeValue(valueName, integerValues.get(valueName)); } - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTY_VALUE_NAMES) { assertEquals(stringValues.get(valueName), crj.getValue(valueName)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { assertEquals(booleanValues.get(valueName), crj.getValue(valueName)); } - for (String valueName:INTEGER_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:INTEGER_PROPERTY_VALUE_NAMES) { assertEquals(integerValues.get(valueName), crj.getValue(valueName)); } } @@ -139,55 +141,55 @@ public void testGetId() { } public void testRemoveProperty() throws InvalidSpdxPropertyException { - Map stringValues = new HashMap<>(); + Map stringValues = new HashMap<>(); CrossRefJson crj = new CrossRefJson(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTY_VALUE_NAMES) { stringValues.put(valueName, "ValueFor"+valueName); crj.setPrimativeValue(valueName, stringValues.get(valueName)); } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { booleanValues.put(valueName, false); crj.setPrimativeValue(valueName, booleanValues.get(valueName)); } - Map integerValues = new HashMap<>(); + Map integerValues = new HashMap<>(); int i = 1; - for (String valueName:INTEGER_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:INTEGER_PROPERTY_VALUE_NAMES) { integerValues.put(valueName, i++); crj.setPrimativeValue(valueName, integerValues.get(valueName)); } - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTY_VALUE_NAMES) { assertEquals(stringValues.get(valueName), crj.getValue(valueName)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { assertEquals(booleanValues.get(valueName), crj.getValue(valueName)); } - for (String valueName:INTEGER_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:INTEGER_PROPERTY_VALUE_NAMES) { assertEquals(integerValues.get(valueName), crj.getValue(valueName)); } - for (String valueName:PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:PROPERTY_VALUE_NAMES) { crj.removeProperty(valueName); } - for (String valueName:PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:PROPERTY_VALUE_NAMES) { assertTrue(Objects.isNull(crj.getValue(valueName))); } } public void testIsPropertyValueAssignableTo() throws InvalidSpdxPropertyException { CrossRefJson crj = new CrossRefJson(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTY_VALUE_NAMES) { assertTrue(crj.isPropertyValueAssignableTo(valueName, String.class)); assertFalse(crj.isPropertyValueAssignableTo(valueName, Boolean.class)); assertFalse(crj.isPropertyValueAssignableTo(valueName, Integer.class)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { assertFalse(crj.isPropertyValueAssignableTo(valueName, String.class)); assertTrue(crj.isPropertyValueAssignableTo(valueName, Boolean.class)); assertFalse(crj.isPropertyValueAssignableTo(valueName, Integer.class)); } - for (String valueName:INTEGER_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:INTEGER_PROPERTY_VALUE_NAMES) { assertFalse(crj.isPropertyValueAssignableTo(valueName, String.class)); assertFalse(crj.isPropertyValueAssignableTo(valueName, Boolean.class)); assertTrue(crj.isPropertyValueAssignableTo(valueName, Integer.class)); diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java index b30d22d7f..5240312fa 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTOCTest.java @@ -22,8 +22,8 @@ import java.util.Map; import java.util.Objects; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.license.ListedLicenseException; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -40,6 +40,7 @@ public class ExceptionJsonTOCTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } /* (non-Javadoc) @@ -84,7 +85,7 @@ public void testGetReleaseDate() { */ public void testAddException() throws Exception { ExceptionJsonTOC ejt = new ExceptionJsonTOC(); - InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + InMemSpdxStore store = new InMemSpdxStore(); String docUri = "http://temp.doc.uri"; String detailsUrl1 = "http://details1"; String exceptionId1 = "id1"; diff --git a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java index 592b1ac02..abd0c7bc7 100644 --- a/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/ExceptionJsonTest.java @@ -20,14 +20,19 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.InvalidSpdxPropertyException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSpdxPropertyException; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -45,24 +50,34 @@ public class ExceptionJsonTest extends TestCase { * @see junit.framework.TestCase#setUp() */ - static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID.getName(), SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), - SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME.getName(), SpdxConstantsCompatV2.RDFS_PROP_COMMENT.getName(), - SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE.getName(), - SpdxConstantsCompatV2.PROP_EXAMPLE.getName(), SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION.getName(), - SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML.getName() - ); + static final List STRING_PROPERTIES = Arrays.asList( + SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID, SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, + SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME, SpdxConstantsCompatV2.RDFS_PROP_COMMENT, + SpdxConstantsCompatV2.PROP_EXCEPTION_TEMPLATE, + SpdxConstantsCompatV2.PROP_EXAMPLE, SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, + SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT_HTML, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_ADDITION_TEXT, + SpdxConstantsV3.PROP_NAME, SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_ADDITION_TEMPLATE, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_DEPRECATED_VERSION, SpdxConstantsV3.PROP_COMMENT, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_LICENSE_XML, SpdxConstantsV3.PROP_EXPANDED_LICENSING_OBSOLETED_BY, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_LIST_VERSION_ADDED); - static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName() + static final List BOOLEAN_PROPERTIES = Arrays.asList( + SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_DEPRECATED_ADDITION_ID ); - static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName()); - static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); + static final List LIST_PROPERTIES = Arrays.asList( + SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + static final List ALL_PROPERTIES = new ArrayList<>(); + static final Set ALL_PROPERTY_NAMES = new HashSet<>(); static { - PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); - PROPERTY_VALUE_NAMES.addAll(BOOLEAN_PROPERTY_VALUE_NAMES); - PROPERTY_VALUE_NAMES.addAll(PROPERTY_VALUE_LIST_NAMES); + ALL_PROPERTIES.addAll(STRING_PROPERTIES); + ALL_PROPERTIES.addAll(BOOLEAN_PROPERTIES); + ALL_PROPERTIES.addAll(LIST_PROPERTIES); + for (PropertyDescriptor ps:ALL_PROPERTIES) { + ALL_PROPERTY_NAMES.add(ExceptionJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(ps)); + } } /* (non-Javadoc) @@ -70,6 +85,7 @@ public class ExceptionJsonTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } /* (non-Javadoc) @@ -85,12 +101,30 @@ public void testExceptionJson() { assertEquals(exceptionId, ej.licenseExceptionId); } - public void testGetPropertyValueNames() { + public void testGetPropertyValueDescriptors() { String exceptionId = "SpdxexceptionId1"; ExceptionJson ej = new ExceptionJson(exceptionId); - List result = ej.getPropertyValueNames(); - assertEquals(PROPERTY_VALUE_NAMES.size(), result.size()); - for (String valueName:PROPERTY_VALUE_NAMES) { + List result = ej.getPropertyValueDescriptors(); + int emptySize = result.size(); + ej.comment = "comment"; + ej.deprecatedVersion = "deprecatedVersion"; + ej.example = "example"; + ej.exceptionTextHtml = "exceptionTextHtml"; + ej.isDeprecatedLicenseId = true; + ej.licenseComments = "licenseComents"; + ej.licenseExceptionId = exceptionId; + ej.licenseExceptionTemplate = "template"; + ej.licenseExceptionText = "text"; + ej.licenseXml = "licenseXml"; + ej.listVersionAdded = "2.3"; + ej.name = "name"; + ej.obsoletedBy = "obsoletedBy"; + ej.seeAlso = Arrays.asList("see1", "see2"); + ej.licenseExceptionId = exceptionId; + result = ej.getPropertyValueDescriptors(); + assertTrue(result.size() > emptySize); + assertTrue(ALL_PROPERTIES.size() <= result.size()); + for (PropertyDescriptor valueName:ALL_PROPERTIES) { if (!result.contains(valueName)) { fail("Missing "+valueName); } @@ -109,23 +143,23 @@ public void testSetTypedProperty() { } public void testGetSetPrimativeValue() throws InvalidSpdxPropertyException { - Map stringValues = new HashMap<>(); + Map stringValues = new HashMap<>(); String exceptionId = "SpdxexceptionId1"; ExceptionJson ej = new ExceptionJson(exceptionId); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - stringValues.put(valueName, "ValueFor"+valueName); - ej.setPrimativeValue(valueName, stringValues.get(valueName)); + for (PropertyDescriptor property:STRING_PROPERTIES) { + stringValues.put(property, "ValueFor"+ExceptionJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property)); + ej.setPrimativeValue(property, stringValues.get(property)); } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - booleanValues.put(valueName, false); - ej.setPrimativeValue(valueName, booleanValues.get(valueName)); + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + booleanValues.put(property, false); + ej.setPrimativeValue(property, booleanValues.get(property)); } - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - assertEquals(stringValues.get(valueName), ej.getValue(valueName)); + for (PropertyDescriptor property:STRING_PROPERTIES) { + assertEquals(stringValues.get(property), ej.getValue(property)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - assertEquals(booleanValues.get(valueName), ej.getValue(valueName)); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + assertEquals(booleanValues.get(property), ej.getValue(property)); } } @@ -133,53 +167,86 @@ public void testRemove() throws InvalidSpdxPropertyException { String exceptionId = "SpdxexceptionId1"; ExceptionJson ej = new ExceptionJson(exceptionId); String value = "value"; - ej.setPrimativeValue(STRING_PROPERTY_VALUE_NAMES.get(0), value); - assertEquals("value", ej.getValue(STRING_PROPERTY_VALUE_NAMES.get(0))); - ej.removeProperty(STRING_PROPERTY_VALUE_NAMES.get(0)); - assertTrue(ej.getValue(STRING_PROPERTY_VALUE_NAMES.get(0)) == null); + ej.setPrimativeValue(STRING_PROPERTIES.get(0), value); + assertEquals("value", ej.getValue(STRING_PROPERTIES.get(0))); + ej.removeProperty(STRING_PROPERTIES.get(0)); + assertTrue(ej.getValue(STRING_PROPERTIES.get(0)) == null); } @SuppressWarnings("unchecked") - public void testAddClearGetPropertyValueList() throws InvalidSpdxPropertyException { + public void testAddClearGetPropertyValueListV2() throws InvalidSpdxPropertyException { String exceptionId = "SpdxexceptionId1"; ExceptionJson ej = new ExceptionJson(exceptionId); - List result = (List) ej.getValueList("seeAlso"); + List result = (List) ej.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(0, result.size()); String firstItem = "first"; String secondItem = "second"; - ej.addPrimitiveValueToList("seeAlso", firstItem); - result = (List) ej.getValueList("seeAlso"); + ej.addPrimitiveValueToList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, firstItem); + result = (List) ej.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(1, result.size()); assertEquals(firstItem, result.get(0)); - ej.addPrimitiveValueToList("seeAlso", secondItem); - result = (List) ej.getValueList("seeAlso"); + ej.addPrimitiveValueToList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, secondItem); + result = (List) ej.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(2, result.size()); assertEquals(firstItem, result.get(0)); assertEquals(secondItem, result.get(1)); - ej.clearPropertyValueList("seeAlso"); - result = (List) ej.getValueList("seeAlso"); + ej.clearPropertyValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + result = (List) ej.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(0, result.size()); } + @SuppressWarnings("unchecked") + public void testAddClearGetPropertyValueListV3() throws InvalidSpdxPropertyException { + String exceptionId = "SpdxexceptionId1"; + ExceptionJson ej = new ExceptionJson(exceptionId); + List result = (List) ej.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(0, result.size()); + String firstItem = "first"; + String secondItem = "second"; + ej.addPrimitiveValueToList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, firstItem); + result = (List) ej.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(1, result.size()); + assertEquals(firstItem, result.get(0)); + ej.addPrimitiveValueToList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, secondItem); + result = (List) ej.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(2, result.size()); + assertEquals(firstItem, result.get(0)); + assertEquals(secondItem, result.get(1)); + ej.clearPropertyValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + result = (List) ej.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(0, result.size()); + } + + @SuppressWarnings("unchecked") public void testJson() throws Exception { StringBuilder json = new StringBuilder("{\n"); - Map stringValues = new HashMap<>(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - stringValues.put(valueName, "ValueFor"+valueName); - json.append("\t\""); - json.append(valueName); - json.append("\":\""); - json.append(stringValues.get(valueName)); - json.append("\",\n"); + Map stringValues = new HashMap<>(); + Set addedPropertyNames = new HashSet<>(); + for (PropertyDescriptor property:STRING_PROPERTIES) { + String propertyName = ExceptionJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property); + stringValues.put(property, "ValueFor"+propertyName); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + json.append(propertyName); + json.append("\":\""); + json.append(stringValues.get(property)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); + } + } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - booleanValues.put(valueName, false); - json.append("\t\""); - json.append(valueName); - json.append("\":\""); - json.append(booleanValues.get(valueName)); - json.append("\",\n"); + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + String propertyName = ExceptionJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property); + booleanValues.put(property, false); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + json.append(propertyName); + json.append("\":\""); + json.append(booleanValues.get(property)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); + } } List seeAlsoValues = Arrays.asList("seeAlso1", "seeAlso2"); json.append("\t\"seeAlso\": [\n\t\t\""); @@ -191,14 +258,20 @@ public void testJson() throws Exception { json.append("\"\n\t]\n}"); Gson gson = new Gson(); ExceptionJson ej = gson.fromJson(json.toString(), ExceptionJson.class); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - assertEquals(stringValues.get(valueName), ej.getValue(valueName)); + for (PropertyDescriptor property:STRING_PROPERTIES) { + assertEquals(stringValues.get(property), ej.getValue(property)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - assertEquals(booleanValues.get(valueName), ej.getValue(valueName)); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + assertEquals(booleanValues.get(property), ej.getValue(property)); + } + List seeAlsoResult = (List)ej.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); + for (String seeAlsoValue:seeAlsoValues) { + if (!seeAlsoResult.contains(seeAlsoValue)) { + fail("Missing "+seeAlsoValue); + } } - @SuppressWarnings("unchecked") - List seeAlsoResult = (List)ej.getValueList("seeAlso"); + seeAlsoResult = (List)ej.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); for (String seeAlsoValue:seeAlsoValues) { if (!seeAlsoResult.contains(seeAlsoValue)) { @@ -207,30 +280,40 @@ public void testJson() throws Exception { } } + @SuppressWarnings("unchecked") public void testLegacyJson() throws Exception { //TODO: In SPDX 3.0 this test should be removed once Spec issue #158 is resolved (https://github.com/spdx/spdx-spec/issues/158) StringBuilder json = new StringBuilder("{\n"); - Map stringValues = new HashMap<>(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - stringValues.put(valueName, "ValueFor"+valueName); - json.append("\t\""); - if (SpdxConstantsCompatV2.RDFS_PROP_COMMENT.equals(valueName)) { - json.append("licenseComments"); // Legacy value - } else { - json.append(valueName); + Map stringValues = new HashMap<>(); + Set addedPropertyNames = new HashSet<>(); + for (PropertyDescriptor property:STRING_PROPERTIES) { + String propertyName = ExceptionJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property); + stringValues.put(property, "ValueFor"+propertyName); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + if (SpdxConstantsCompatV2.RDFS_PROP_COMMENT.equals(property)) { + json.append("licenseComments"); // Legacy value + } else { + json.append(propertyName); + } + json.append("\":\""); + json.append(stringValues.get(property)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); } - json.append("\":\""); - json.append(stringValues.get(valueName)); - json.append("\",\n"); } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - booleanValues.put(valueName, false); - json.append("\t\""); - json.append(valueName); - json.append("\":\""); - json.append(booleanValues.get(valueName)); - json.append("\",\n"); + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + String propertyName = ExceptionJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property); + booleanValues.put(property, false); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + json.append(propertyName); + json.append("\":\""); + json.append(booleanValues.get(property)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); + } } List seeAlsoValues = Arrays.asList("seeAlso1", "seeAlso2"); json.append("\t\"seeAlso\": [\n\t\t\""); @@ -242,14 +325,20 @@ public void testLegacyJson() throws Exception { json.append("\"\n\t]\n}"); Gson gson = new Gson(); ExceptionJson ej = gson.fromJson(json.toString(), ExceptionJson.class); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - assertEquals(stringValues.get(valueName), ej.getValue(valueName)); + for (PropertyDescriptor property:STRING_PROPERTIES) { + assertEquals(stringValues.get(property), ej.getValue(property)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - assertEquals(booleanValues.get(valueName), ej.getValue(valueName)); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + assertEquals(booleanValues.get(property), ej.getValue(property)); } - @SuppressWarnings("unchecked") - List seeAlsoResult = (List)ej.getValueList("seeAlso"); + List seeAlsoResult = (List)ej.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); + for (String seeAlsoValue:seeAlsoValues) { + if (!seeAlsoResult.contains(seeAlsoValue)) { + fail("Missing "+seeAlsoValue); + } + } + seeAlsoResult = (List)ej.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); for (String seeAlsoValue:seeAlsoValues) { if (!seeAlsoResult.contains(seeAlsoValue)) { @@ -261,25 +350,26 @@ public void testLegacyJson() throws Exception { public void testIsCollectionMembersAssignableTo() throws Exception { String exceptionId = "excId"; ExceptionJson ej = new ExceptionJson(exceptionId); - assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); - assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), String.class)); + assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertTrue(ej.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, String.class)); + assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, Boolean.class)); + assertFalse(ej.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, String.class)); } public void testIsPropertyValueAssignableTo() throws Exception { String exceptionId = "excId"; ExceptionJson ej = new ExceptionJson(exceptionId); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertTrue(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), String.class)); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT.getName(), Boolean.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertTrue(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, String.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_EXCEPTION_TEXT, Boolean.class)); - assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), String.class)); - assertTrue(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); + assertFalse(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class)); + assertTrue(ej.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class)); } @SuppressWarnings("deprecation") - public void testCopyFrom() throws Exception { - InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + public void testCopyFromV2() throws Exception { + InMemSpdxStore store = new InMemSpdxStore(); String docUri = "http://temp.uri"; String exceptionId = "exceptionId"; String comment = "comment"; @@ -321,4 +411,50 @@ public void testCopyFrom() throws Exception { UnitTestHelper.isListsEqual(seeAlso, ej.seeAlso); } + + public void testCopyFromV3() throws Exception { + InMemSpdxStore store = new InMemSpdxStore(); + String exceptionId = "exceptionId"; + String objectUri = "https://spdx.org/licenses/" + exceptionId; + String comment = "comment"; + Boolean deprecated = true; + String deprecatedVersion = "v1"; + String text = "text"; + String name = "name"; + String[] seeAlsoArray = new String[]{"http://seealso1", "http://see/also/2"}; + List seeAlso = Arrays.asList(seeAlsoArray); + String template = "template"; + String licenseXml = "licenseXml"; + String obsoletedBy = "obsoletedBy"; + String listVersionAdded = "2.3.2"; + ExpandedLicensingListedLicenseException exception = new ExpandedLicensingListedLicenseException(store, + objectUri, null, true); + exception.setComment(comment); + exception.setExpandedLicensingIsDeprecatedAdditionId(deprecated); + exception.setExpandedLicensingDeprecatedVersion(deprecatedVersion); + exception.setExpandedLicensingStandardAdditionTemplate(template); + exception.setExpandedLicensingAdditionText(text); + exception.setName(name); + exception.getExpandedLicensingSeeAlsos().addAll(seeAlso); + exception.setExpandedLicensingIsDeprecatedAdditionId(deprecated); + exception.setExpandedLicensingObsoletedBy(obsoletedBy); + exception.setComment(comment); + exception.setExpandedLicensingLicenseXml(licenseXml); + exception.setExpandedLicensingListVersionAdded(listVersionAdded); + ExceptionJson ej = new ExceptionJson(); + ej.copyFrom(exception); + + assertEquals(exceptionId, ej.licenseExceptionId); + assertEquals(comment, ej.comment); + assertEquals(deprecated, ej.isDeprecatedLicenseId); + assertEquals(deprecatedVersion, ej.deprecatedVersion); + assertEquals(template, ej.licenseExceptionTemplate); + assertEquals(text, ej.licenseExceptionText); + assertEquals(name, ej.name); + UnitTestHelper.isListsEqual(seeAlso, ej.seeAlso); + assertEquals(obsoletedBy, ej.obsoletedBy); + assertEquals(comment, ej.comment); + assertEquals(licenseXml, ej.licenseXml); + assertEquals(listVersionAdded, ej.listVersionAdded); + } } diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseCreationInfoTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseCreationInfoTest.java new file mode 100644 index 000000000..ecb6de475 --- /dev/null +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseCreationInfoTest.java @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import static org.junit.Assert.*; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.core.Agent; + +/** + * @author gary + * + */ +public class LicenseCreationInfoTest { + + static final String LICENSE_LIST_VERSION = "3.24.0"; + + LicenseCreatorAgent licenseCreatorAgent; + String licenseListReleaseDate = new SimpleDateFormat(SpdxConstantsCompatV2.SPDX_DATE_FORMAT).format(new Date()); + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + SpdxModelFactory.init(); + licenseCreatorAgent = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreationInfo#getTypedValue()}. + * @throws InvalidSPDXAnalysisException + */ + @Test + public void testGetTypedValue() throws InvalidSPDXAnalysisException { + LicenseCreationInfo lci = new LicenseCreationInfo(licenseCreatorAgent, licenseListReleaseDate); + TypedValue result = lci.getTypedValue(); + assertEquals(LicenseCreationInfo.CREATION_INFO_URI, result.getObjectUri()); + assertEquals(SpdxConstantsV3.CORE_CREATION_INFO, result.getType()); + assertEquals(SpdxConstantsV3.MODEL_SPEC_VERSION, result.getSpecVersion()); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreationInfo#isCollectionProperty(org.spdx.storage.PropertyDescriptor)}. + */ + @Test + public void testIsCollectionProperty() throws InvalidSPDXAnalysisException { + LicenseCreationInfo lci = new LicenseCreationInfo(licenseCreatorAgent, licenseListReleaseDate); + assertTrue(lci.isCollectionProperty(SpdxConstantsV3.PROP_CREATED_BY)); + assertFalse(lci.isCollectionProperty(SpdxConstantsV3.PROP_CREATED)); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreationInfo#getValueList(org.spdx.storage.PropertyDescriptor)}. + */ + @Test + public void testGetValueList() throws InvalidSPDXAnalysisException { + LicenseCreationInfo lci = new LicenseCreationInfo(licenseCreatorAgent, licenseListReleaseDate); + List result = lci.getValueList(SpdxConstantsV3.PROP_CREATED_BY); + assertEquals(1, result.size()); + Object value = result.toArray()[0]; + assertTrue(value instanceof TypedValue); + assertEquals(licenseCreatorAgent.getObjectUri(), ((TypedValue)value).getObjectUri()); + assertEquals(SpdxConstantsV3.CORE_AGENT, ((TypedValue)value).getType()); + assertEquals(SpdxConstantsV3.MODEL_SPEC_VERSION, ((TypedValue)value).getSpecVersion()); + assertTrue(lci.getValueList(SpdxConstantsV3.PROP_CREATED).isEmpty()); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreationInfo#getValue(org.spdx.storage.PropertyDescriptor)}. + */ + @Test + public void testGetValue() throws InvalidSPDXAnalysisException { + LicenseCreationInfo lci = new LicenseCreationInfo(licenseCreatorAgent, licenseListReleaseDate); + Object result = lci.getValue(SpdxConstantsV3.PROP_COMMENT); + assertTrue(result instanceof String); + assertFalse(((String)result).isEmpty()); + result = lci.getValue(SpdxConstantsV3.PROP_CREATED); + assertTrue(result instanceof String); + assertEquals(licenseListReleaseDate, result); + result = lci.getValue(SpdxConstantsV3.PROP_CREATED_BY); + assertTrue(result instanceof List); + assertFalse(((List)result).isEmpty()); + result = lci.getValue(SpdxConstantsV3.PROP_SPEC_VERSION); + assertTrue(result instanceof String); + assertEquals(SpdxConstantsV3.MODEL_SPEC_VERSION, result); + assertTrue(Objects.isNull(lci.getValue(SpdxConstantsV3.PROP_A_I_DOMAIN))); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreationInfo#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + @Test + public void testIsCollectionMembersAssignableTo() throws InvalidSPDXAnalysisException { + LicenseCreationInfo lci = new LicenseCreationInfo(licenseCreatorAgent, licenseListReleaseDate); + assertTrue(lci.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_CREATED_BY, Agent.class)); + assertTrue(lci.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_CREATED_BY, LicenseCreatorAgent.class)); + assertFalse(lci.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_CREATED_BY, String.class)); + assertFalse(lci.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_CREATED, String.class)); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreationInfo#isPropertyValueAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + @Test + public void testIsPropertyValueAssignableTo() throws InvalidSPDXAnalysisException { + LicenseCreationInfo lci = new LicenseCreationInfo(licenseCreatorAgent, licenseListReleaseDate); + assertTrue(lci.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_COMMENT, String.class)); + assertTrue(lci.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_CREATED, String.class)); + assertTrue(lci.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_SPEC_VERSION, String.class)); + assertFalse(lci.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_CREATED_BY, String.class)); + assertFalse(lci.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_SOFTWARE_DOWNLOAD_LOCATION, String.class)); + } + +} diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseCreatorAgentTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseCreatorAgentTest.java new file mode 100644 index 000000000..36475f8e0 --- /dev/null +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseCreatorAgentTest.java @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.spdx.storage.listedlicense; + +import static org.junit.Assert.*; + +import java.util.Objects; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.ModelRegistryException; +import org.spdx.core.SpdxInvalidIdException; +import org.spdx.core.SpdxInvalidTypeException; +import org.spdx.core.TypedValue; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.core.CreationInfo; + +/** + * @author gary + * + */ +public class LicenseCreatorAgentTest { + + static final String LICENSE_LIST_VERSION = "3.24.0"; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + SpdxModelFactory.init(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#getObjectUri()}. + * @throws ModelRegistryException + * @throws SpdxInvalidTypeException + * @throws SpdxInvalidIdException + */ + @Test + public void testGetObjectUri() throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + assertEquals(LicenseCreatorAgent.OBJECT_URI_PREFIX + "3_24_0", lca.getObjectUri()); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#getTypedValue()}. + * @throws ModelRegistryException + * @throws SpdxInvalidTypeException + * @throws SpdxInvalidIdException + */ + @Test + public void testGetTypedValue() throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + TypedValue result = lca.getTypedValue(); + assertEquals(LicenseCreatorAgent.OBJECT_URI_PREFIX + "3_24_0", result.getObjectUri()); + assertEquals(SpdxConstantsV3.MODEL_SPEC_VERSION, result.getSpecVersion()); + assertEquals(SpdxConstantsV3.CORE_AGENT, result.getType()); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#getValueList(org.spdx.storage.PropertyDescriptor)}. + */ + @Test + public void testGetValueList() throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + assertTrue(lca.getValueList(SpdxConstantsV3.PROP_CREATED).isEmpty()); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#getValue(org.spdx.storage.PropertyDescriptor)}. + * @throws InvalidSPDXAnalysisException + */ + @Test + public void testGetValue() throws InvalidSPDXAnalysisException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + Object result = lca.getValue(SpdxConstantsV3.PROP_CREATION_INFO); + assertTrue(result instanceof TypedValue); + assertEquals(LicenseCreationInfo.CREATION_INFO_URI, ((TypedValue)result).getObjectUri()); + assertEquals(SpdxConstantsV3.CORE_CREATION_INFO, ((TypedValue)result).getType()); + assertEquals(SpdxConstantsV3.MODEL_SPEC_VERSION, ((TypedValue)result).getSpecVersion()); + result = lca.getValue(SpdxConstantsV3.PROP_NAME); + assertTrue(result instanceof String); + assertFalse(((String)result).isEmpty()); + result = lca.getValue(SpdxConstantsV3.PROP_DESCRIPTION); + assertTrue(result instanceof String); + assertFalse(((String)result).isEmpty()); + result = lca.getValue(SpdxConstantsV3.PROP_A_I_DOMAIN); + assertTrue(Objects.isNull(result)); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#isCollectionMembersAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + @Test + public void testIsCollectionMembersAssignableTo() throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + assertFalse(lca.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_CREATION_INFO, CreationInfo.class)); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#isPropertyValueAssignableTo(org.spdx.storage.PropertyDescriptor, java.lang.Class)}. + */ + @Test + public void testIsPropertyValueAssignableTo() throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + assertTrue(lca.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_CREATION_INFO, CreationInfo.class)); + assertTrue(lca.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_CREATION_INFO, LicenseCreationInfo.class)); + assertFalse(lca.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_CREATION_INFO, String.class)); + assertTrue(lca.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_NAME, String.class)); + assertTrue(lca.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_DESCRIPTION, String.class)); + assertFalse(lca.isPropertyValueAssignableTo(SpdxConstantsV3.PROP_COMMENT, String.class)); + } + + /** + * Test method for {@link org.spdx.storage.listedlicense.LicenseCreatorAgent#isCollectionProperty(org.spdx.storage.PropertyDescriptor)}. + */ + @Test + public void testIsCollectionProperty() throws SpdxInvalidIdException, SpdxInvalidTypeException, ModelRegistryException { + LicenseCreatorAgent lca = new LicenseCreatorAgent(LICENSE_LIST_VERSION); + assertFalse(lca.isCollectionProperty(SpdxConstantsV3.PROP_NAME)); + } +} diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java index 70b45a67a..983f32d85 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTOCTest.java @@ -21,10 +21,10 @@ import java.util.List; import java.util.Objects; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.SpdxListedLicense; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -41,6 +41,7 @@ public class LicenseJsonTOCTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } /* (non-Javadoc) @@ -87,7 +88,7 @@ public void testGetReleaseDate() { */ public void testAddLicense() throws InvalidSPDXAnalysisException { LicenseJsonTOC ljt = new LicenseJsonTOC(); - InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + InMemSpdxStore store = new InMemSpdxStore(); String docUri = "http://docuri.temp1"; String licenseId1 = "licenseId1"; String licHTMLReference1 = "./licHTMLReference1"; diff --git a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java index 0a3efc362..e5e121a2f 100644 --- a/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/LicenseJsonTest.java @@ -20,16 +20,20 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.InvalidSpdxPropertyException; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSpdxPropertyException; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; -import org.spdx.library.model.compat.v2.license.CrossRef; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.CrossRef; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.storage.PropertyDescriptor; import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.UnitTestHelper; @@ -43,27 +47,39 @@ */ public class LicenseJsonTest extends TestCase { - static final List STRING_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstantsCompatV2.PROP_LICENSE_ID.getName(), SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), - SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML.getName(), - SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME.getName(), SpdxConstantsCompatV2.RDFS_PROP_COMMENT.getName(), - SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE.getName(), SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE.getName(), - SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML.getName(), SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE.getName(), - SpdxConstantsCompatV2.PROP_EXAMPLE.getName(), SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION.getName() + static final List STRING_PROPERTIES = Arrays.asList( + SpdxConstantsCompatV2.PROP_LICENSE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, + SpdxConstantsCompatV2.PROP_LICENSE_TEXT_HTML, + SpdxConstantsCompatV2.PROP_STD_LICENSE_NAME, SpdxConstantsCompatV2.RDFS_PROP_COMMENT, + SpdxConstantsCompatV2.PROP_STD_LICENSE_NOTICE, SpdxConstantsCompatV2.PROP_STD_LICENSE_HEADER_TEMPLATE, + SpdxConstantsCompatV2.PROP_LICENSE_HEADER_HTML, SpdxConstantsCompatV2.PROP_STD_LICENSE_TEMPLATE, + SpdxConstantsCompatV2.PROP_EXAMPLE, SpdxConstantsCompatV2.PROP_LIC_DEPRECATED_VERSION, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_LICENSE_XML, SpdxConstantsV3.PROP_EXPANDED_LICENSING_OBSOLETED_BY, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_LIST_VERSION_ADDED, SpdxConstantsV3.PROP_SIMPLE_LICENSING_LICENSE_TEXT, + SpdxConstantsV3.PROP_NAME, SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_LICENSE_HEADER, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_STANDARD_LICENSE_TEMPLATE, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_DEPRECATED_VERSION, SpdxConstantsV3.PROP_COMMENT ); - static final List BOOLEAN_PROPERTY_VALUE_NAMES = Arrays.asList( - SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED.getName(), SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE.getName(), - SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName() + static final List BOOLEAN_PROPERTIES = Arrays.asList( + SpdxConstantsCompatV2.PROP_STD_LICENSE_OSI_APPROVED, SpdxConstantsCompatV2.PROP_STD_LICENSE_FSF_LIBRE, + SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_OSI_APPROVED, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_FSF_LIBRE, + SpdxConstantsV3.PROP_EXPANDED_LICENSING_IS_DEPRECATED_LICENSE_ID ); - static final List PROPERTY_VALUE_NAMES = new ArrayList<>(); - static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), - SpdxConstantsCompatV2.PROP_CROSS_REF.getName()); + static final List ALL_PROPERTIES = new ArrayList<>(); + static final Set ALL_PROPERTY_NAMES = new HashSet<>(); + static final List PROPERTY_VALUE_LIST_NAMES = Arrays.asList( + SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, + SpdxConstantsCompatV2.PROP_CROSS_REF); static { - PROPERTY_VALUE_NAMES.addAll(STRING_PROPERTY_VALUE_NAMES); - PROPERTY_VALUE_NAMES.addAll(BOOLEAN_PROPERTY_VALUE_NAMES); - PROPERTY_VALUE_NAMES.addAll(PROPERTY_VALUE_LIST_NAMES); + ALL_PROPERTIES.addAll(STRING_PROPERTIES); + ALL_PROPERTIES.addAll(BOOLEAN_PROPERTIES); + ALL_PROPERTIES.addAll(PROPERTY_VALUE_LIST_NAMES); + for (PropertyDescriptor pd:ALL_PROPERTIES) { + ALL_PROPERTY_NAMES.add(LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(pd)); + } } @@ -72,6 +88,7 @@ public class LicenseJsonTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } /* (non-Javadoc) @@ -92,13 +109,25 @@ public void testLicenseJson() { /** * Test method for {@link org.spdx.storage.listedlicense.LicenseJson#getPropertyValueNames()}. + * @throws InvalidSPDXAnalysisException */ - public void testGetPropertyValueNames() { + public void testGetPropertyValueNames() throws InvalidSPDXAnalysisException { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - List result = lj.getPropertyValueNames(); - assertEquals(PROPERTY_VALUE_NAMES.size(), result.size()); - for (String valueName:PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor desc:STRING_PROPERTIES) { + lj.setPrimativeValue(desc, "s"); + } + for (PropertyDescriptor desc:BOOLEAN_PROPERTIES) { + lj.setPrimativeValue(desc, true); + } + CrossRefJson firstItem = new CrossRefJson(); + firstItem.url = "http://first"; + lj.addPrimitiveValueToList(SpdxConstantsCompatV2.PROP_CROSS_REF, firstItem); + String secondItem = "second"; + lj.addPrimitiveValueToList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, secondItem); + List result = lj.getPropertyValueDescriptors(); + assertTrue(ALL_PROPERTIES.size() < result.size()); + for (PropertyDescriptor valueName:ALL_PROPERTIES) { if (!result.contains(valueName)) { fail("Missing "+valueName); } @@ -124,22 +153,22 @@ public void testSetTypedProperty() { * @throws InvalidSpdxPropertyException */ public void testGetSetPrimativeValue() throws InvalidSpdxPropertyException { - Map stringValues = new HashMap<>(); + Map stringValues = new HashMap<>(); String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - stringValues.put(valueName, "ValueFor"+valueName); + for (PropertyDescriptor valueName:STRING_PROPERTIES) { + stringValues.put(valueName, "ValueFor"+LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(valueName)); lj.setPrimativeValue(valueName, stringValues.get(valueName)); } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor valueName:BOOLEAN_PROPERTIES) { booleanValues.put(valueName, false); lj.setPrimativeValue(valueName, booleanValues.get(valueName)); } - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:STRING_PROPERTIES) { assertEquals(stringValues.get(valueName), lj.getValue(valueName)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { + for (PropertyDescriptor valueName:BOOLEAN_PROPERTIES) { assertEquals(booleanValues.get(valueName), lj.getValue(valueName)); } } @@ -149,24 +178,46 @@ public void testGetSetPrimativeValue() throws InvalidSpdxPropertyException { * @throws InvalidSPDXAnalysisException */ @SuppressWarnings("unchecked") - public void testAddClearGetPropertyValueListSeeAlso() throws InvalidSPDXAnalysisException { + public void testAddClearGetPropertyValueListSeeAlsoV2() throws InvalidSPDXAnalysisException { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - List result = (List) lj.getValueList("seeAlso"); + List result = (List) lj.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(0, result.size()); String firstItem = "first"; String secondItem = "second"; - lj.addPrimitiveValueToList("seeAlso", firstItem); - result = (List) lj.getValueList("seeAlso"); + lj.addPrimitiveValueToList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, firstItem); + result = (List) lj.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(1, result.size()); assertEquals(firstItem, result.get(0)); - lj.addPrimitiveValueToList("seeAlso", secondItem); - result = (List) lj.getValueList("seeAlso"); + lj.addPrimitiveValueToList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, secondItem); + result = (List) lj.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(2, result.size()); assertEquals(firstItem, result.get(0)); assertEquals(secondItem, result.get(1)); - lj.clearPropertyValueList("seeAlso"); - result = (List) lj.getValueList("seeAlso"); + lj.clearPropertyValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + result = (List) lj.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + assertEquals(0, result.size()); + } + + @SuppressWarnings("unchecked") + public void testAddClearGetPropertyValueListSeeAlsoV3() throws InvalidSPDXAnalysisException { + String licenseId = "SpdxLicenseId1"; + LicenseJson lj = new LicenseJson(licenseId); + List result = (List) lj.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(0, result.size()); + String firstItem = "first"; + String secondItem = "second"; + lj.addPrimitiveValueToList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, firstItem); + result = (List) lj.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(1, result.size()); + assertEquals(firstItem, result.get(0)); + lj.addPrimitiveValueToList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, secondItem); + result = (List) lj.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(2, result.size()); + assertEquals(firstItem, result.get(0)); + assertEquals(secondItem, result.get(1)); + lj.clearPropertyValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + result = (List) lj.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); assertEquals(0, result.size()); } @@ -174,46 +225,55 @@ public void testAddClearGetPropertyValueListSeeAlso() throws InvalidSPDXAnalysis public void testAddClearGetPropertyValueListCrossRef() throws InvalidSPDXAnalysisException { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - List result = (List) lj.getValueList("crossRef"); + List result = (List) lj.getValueList(SpdxConstantsCompatV2.PROP_CROSS_REF); assertEquals(0, result.size()); CrossRefJson firstItem = new CrossRefJson(); firstItem.url = "http://first"; CrossRefJson secondItem = new CrossRefJson(); secondItem.url = "http://second"; - lj.addPrimitiveValueToList("crossRef", firstItem); - result = (List) lj.getValueList("crossRef"); + lj.addPrimitiveValueToList(SpdxConstantsCompatV2.PROP_CROSS_REF, firstItem); + result = (List) lj.getValueList(SpdxConstantsCompatV2.PROP_CROSS_REF); assertEquals(1, result.size()); assertEquals(firstItem, result.get(0)); - lj.addPrimitiveValueToList("crossRef", secondItem); - result = (List) lj.getValueList("crossRef"); + lj.addPrimitiveValueToList(SpdxConstantsCompatV2.PROP_CROSS_REF, secondItem); + result = (List) lj.getValueList(SpdxConstantsCompatV2.PROP_CROSS_REF); assertEquals(2, result.size()); assertEquals(firstItem, result.get(0)); assertEquals(secondItem, result.get(1)); - lj.clearPropertyValueList("crossRef"); - result = (List) lj.getValueList("crossRef"); + lj.clearPropertyValueList(SpdxConstantsCompatV2.PROP_CROSS_REF); + result = (List) lj.getValueList(SpdxConstantsCompatV2.PROP_CROSS_REF); assertEquals(0, result.size()); } @SuppressWarnings("unchecked") public void testJson() throws Exception { StringBuilder json = new StringBuilder("{\n"); - Map stringValues = new HashMap<>(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - stringValues.put(valueName, "ValueFor"+valueName); - json.append("\t\""); - json.append(valueName); - json.append("\":\""); - json.append(stringValues.get(valueName)); - json.append("\",\n"); + Map stringValues = new HashMap<>(); + Set addedPropertyNames = new HashSet<>(); + for (PropertyDescriptor properties:STRING_PROPERTIES) { + String propertyName = LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(properties); + stringValues.put(properties, "ValueFor"+propertyName); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + json.append(propertyName); + json.append("\":\""); + json.append(stringValues.get(properties)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); + } } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - booleanValues.put(valueName, false); - json.append("\t\""); - json.append(valueName); - json.append("\":\""); - json.append(booleanValues.get(valueName)); - json.append("\",\n"); + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor properties:BOOLEAN_PROPERTIES) { + String propertyName = LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(properties); + booleanValues.put(properties, false); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + json.append(LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(properties)); + json.append("\":\""); + json.append(booleanValues.get(properties)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); + } } List seeAlsoValues = Arrays.asList("seeAlso1", "seeAlso2"); json.append("\t\"seeAlso\": [\n\t\t\""); @@ -270,20 +330,27 @@ public void testJson() throws Exception { json.append("\"\n\t\t}\n\t]\n}"); Gson gson = new Gson(); LicenseJson lj = gson.fromJson(json.toString(), LicenseJson.class); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - assertEquals(stringValues.get(valueName), lj.getValue(valueName)); + for (PropertyDescriptor properties:STRING_PROPERTIES) { + assertEquals(stringValues.get(properties), lj.getValue(properties)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - assertEquals(booleanValues.get(valueName), lj.getValue(valueName)); + for (PropertyDescriptor properties:BOOLEAN_PROPERTIES) { + assertEquals(booleanValues.get(properties), lj.getValue(properties)); } - List seeAlsoResult = (List)lj.getValueList("seeAlso"); + List seeAlsoResult = (List)lj.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); for (String seeAlsoValue:seeAlsoValues) { if (!seeAlsoResult.contains(seeAlsoValue)) { fail("Missing "+seeAlsoValue); } } - List crossRefResult = (List)lj.getValueList("crossRef"); + seeAlsoResult = (List)lj.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); + assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); + for (String seeAlsoValue:seeAlsoValues) { + if (!seeAlsoResult.contains(seeAlsoValue)) { + fail("Missing "+seeAlsoValue); + } + } + List crossRefResult = (List)lj.getValueList(SpdxConstantsCompatV2.PROP_CROSS_REF); assertEquals(2, crossRefResult.size()); assertEquals(crossRef1.match, crossRefResult.get(0).match); assertEquals(crossRef1.timestamp, crossRefResult.get(0).timestamp); @@ -305,27 +372,38 @@ public void testJson() throws Exception { public void testLegacyJson() throws Exception { //TODO: In SPDX 3.0 this test should be removed once Spec issue #158 is resolved (https://github.com/spdx/spdx-spec/issues/158) StringBuilder json = new StringBuilder("{\n"); - Map stringValues = new HashMap<>(); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - stringValues.put(valueName, "ValueFor"+valueName); - json.append("\t\""); - if (SpdxConstantsCompatV2.RDFS_PROP_COMMENT.equals(valueName)) { - json.append("licenseComments"); // Legacy value - } else { - json.append(valueName); + Set addedPropertyNames = new HashSet<>(); + Map stringValues = new HashMap<>(); + for (PropertyDescriptor property:STRING_PROPERTIES) { + String propertyName = LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property); + stringValues.put(property, "ValueFor"+propertyName); + if (!addedPropertyNames.contains(propertyName)) { + stringValues.put(property, "ValueFor"+propertyName); + json.append("\t\""); + if (SpdxConstantsCompatV2.RDFS_PROP_COMMENT.equals(property)) { + json.append("licenseComments"); // Legacy value + } else { + json.append(LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property)); + } + json.append("\":\""); + json.append(stringValues.get(property)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); } - json.append("\":\""); - json.append(stringValues.get(valueName)); - json.append("\",\n"); + } - Map booleanValues = new HashMap<>(); - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - booleanValues.put(valueName, false); - json.append("\t\""); - json.append(valueName); - json.append("\":\""); - json.append(booleanValues.get(valueName)); - json.append("\",\n"); + Map booleanValues = new HashMap<>(); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + String propertyName = LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property); + booleanValues.put(property, false); + if (!addedPropertyNames.contains(propertyName)) { + json.append("\t\""); + json.append(LicenseJson.PROPERTY_DESCRIPTOR_TO_VALUE_NAME.get(property)); + json.append("\":\""); + json.append(booleanValues.get(property)); + json.append("\",\n"); + addedPropertyNames.add(propertyName); + } } List seeAlsoValues = Arrays.asList("seeAlso1", "seeAlso2"); json.append("\t\"seeAlso\": [\n\t\t\""); @@ -337,13 +415,20 @@ public void testLegacyJson() throws Exception { json.append("\"\n\t]\n}"); Gson gson = new Gson(); LicenseJson lj = gson.fromJson(json.toString(), LicenseJson.class); - for (String valueName:STRING_PROPERTY_VALUE_NAMES) { - assertEquals(stringValues.get(valueName), lj.getValue(valueName)); + for (PropertyDescriptor property:STRING_PROPERTIES) { + assertEquals(stringValues.get(property), lj.getValue(property)); } - for (String valueName:BOOLEAN_PROPERTY_VALUE_NAMES) { - assertEquals(booleanValues.get(valueName), lj.getValue(valueName)); + for (PropertyDescriptor property:BOOLEAN_PROPERTIES) { + assertEquals(booleanValues.get(property), lj.getValue(property)); } - List seeAlsoResult = (List)lj.getValueList("seeAlso"); + List seeAlsoResult = (List)lj.getValueList(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); + for (String seeAlsoValue:seeAlsoValues) { + if (!seeAlsoResult.contains(seeAlsoValue)) { + fail("Missing "+seeAlsoValue); + } + } + seeAlsoResult = (List)lj.getValueList(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO); assertEquals(seeAlsoValues.size(), seeAlsoResult.size()); for (String seeAlsoValue:seeAlsoValues) { if (!seeAlsoResult.contains(seeAlsoValue)) { @@ -356,35 +441,85 @@ public void testRemoveProperty() throws InvalidSpdxPropertyException { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); String value = "value"; - lj.setPrimativeValue(STRING_PROPERTY_VALUE_NAMES.get(0), value); - assertEquals("value", lj.getValue(STRING_PROPERTY_VALUE_NAMES.get(0))); - lj.removeProperty(STRING_PROPERTY_VALUE_NAMES.get(0)); - assertTrue(lj.getValue(STRING_PROPERTY_VALUE_NAMES.get(0)) == null); + lj.setPrimativeValue(STRING_PROPERTIES.get(0), value); + assertEquals("value", lj.getValue(STRING_PROPERTIES.get(0))); + lj.removeProperty(STRING_PROPERTIES.get(0)); + assertTrue(lj.getValue(STRING_PROPERTIES.get(0)) == null); } public void testIsCollectionMembersAssignableTo() throws Exception { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), Boolean.class)); - assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), String.class)); - assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_CROSS_REF.getName(), CrossRef.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsV3.PROP_EXPANDED_LICENSING_SEE_ALSO, String.class)); + assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, Boolean.class)); + assertFalse(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); + assertTrue(lj.isCollectionMembersAssignableTo(SpdxConstantsCompatV2.PROP_CROSS_REF, CrossRef.class)); } public void testIsPropertyValueAssignableTo() throws Exception { String licenseId = "SpdxLicenseId1"; LicenseJson lj = new LicenseJson(licenseId); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO.getName(), String.class)); - assertTrue(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), String.class)); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT.getName(), Boolean.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); + assertTrue(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LICENSE_TEXT, Boolean.class)); - assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), String.class)); - assertTrue(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED.getName(), Boolean.class)); + assertFalse(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class)); + assertTrue(lj.isPropertyValueAssignableTo(SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class)); + } + + public void testFromListedLicenseV3() throws InvalidSPDXAnalysisException { + LicenseJson lj = new LicenseJson(); + InMemSpdxStore store = new InMemSpdxStore(); + String objectUri = "http://spdx.org/licenses/test"; + ModelCopyManager copyManager = new ModelCopyManager(); + ExpandedLicensingListedLicense license = new ExpandedLicensingListedLicense(store, objectUri, copyManager, true); + boolean deprecated = true; + String comment = "comment"; + String deprecatedVersion = "deprecatedVersion"; + String licenseText = "licenseText"; + String name = "name"; + String standardLicenseHeader = "standardLicenseHeader"; + String standardLicenseTemplate = "standardLicenseTemplate"; + Boolean fsfLibre = true; + Boolean osiApproved = true; + List seeAlsoUrl = Arrays.asList(new String[]{"http://url1", "http://url2"}); + String licenseXml = "licenseXml"; + String listVersionAdded = "12.1.1"; + String obsoletedBy = "something"; + + license.setComment(comment); + license.setExpandedLicensingDeprecatedVersion(deprecatedVersion); + license.setSimpleLicensingLicenseText(licenseText); + license.setName(name); + license.setExpandedLicensingStandardLicenseHeader(standardLicenseHeader); + license.setExpandedLicensingStandardLicenseTemplate(standardLicenseTemplate); + license.setExpandedLicensingIsFsfLibre(fsfLibre); + license.setExpandedLicensingIsOsiApproved(osiApproved); + license.getExpandedLicensingSeeAlsos().addAll(seeAlsoUrl); + license.setExpandedLicensingIsDeprecatedLicenseId(deprecated); + license.setExpandedLicensingLicenseXml(licenseXml); + license.setExpandedLicensingListVersionAdded(listVersionAdded); + license.setExpandedLicensingObsoletedBy(obsoletedBy); + + lj.copyFrom(license); + assertEquals(fsfLibre, lj.isFsfLibre); + assertEquals(osiApproved, lj.isOsiApproved); + assertEquals(comment, lj.comment); + assertEquals(deprecatedVersion, lj.deprecatedVersion); + assertEquals(licenseText, lj.licenseText); + assertEquals(name, lj.name); + assertEquals(standardLicenseHeader, lj.standardLicenseHeader); + assertEquals(standardLicenseTemplate, lj.standardLicenseTemplate); + assertTrue(UnitTestHelper.isListsEqual(seeAlsoUrl, lj.seeAlso)); + assertEquals(obsoletedBy, lj.obsoletedBy); + assertEquals(licenseXml, lj.licenseXml); + assertEquals(listVersionAdded, lj.listVersionAdded); } - public void testCopyFromLicense() throws Exception { + public void testCopyFromLicenseV2() throws Exception { LicenseJson lj = new LicenseJson(); - InMemSpdxStore store = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + InMemSpdxStore store = new InMemSpdxStore(); String docUri = "http://doc.uri"; String id = "licenseId"; boolean deprecated = true; @@ -402,7 +537,7 @@ public void testCopyFromLicense() throws Exception { List seeAlsoUrl = Arrays.asList(new String[]{"http://url1", "http://url2"}); ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = new SpdxListedLicense(store, docUri, id, copyManager, true); + org.spdx.library.model.v2.license.SpdxListedLicense license = new org.spdx.library.model.v2.license.SpdxListedLicense(store, docUri, id, copyManager, true); List crossRefs = new ArrayList<>(); List crossRefUrls = Arrays.asList(new String[]{"http://crossref1", "http://crossref2"}); for (String crossRefUrl:crossRefUrls) { @@ -427,8 +562,7 @@ public void testCopyFromLicense() throws Exception { assertEquals(fsfLibre, lj.isFsfLibre); assertEquals(standardLicenseHeaderHtml, lj.standardLicenseHeaderHtml); assertEquals(osiApproved, lj.isOsiApproved); - //TODO: Uncomment out the following line in SPDX 3.0 - //assertEquals(comment, lj.comment); + assertEquals(comment, lj.comment); assertEquals(comment, lj.licenseComments); assertEquals(deprecatedVersion, lj.deprecatedVersion); assertEquals(id, lj.licenseId); diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java index 48d1f393b..2a7004919 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStoreTest.java @@ -22,16 +22,20 @@ import java.util.Iterator; import java.util.List; -import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; -import org.spdx.library.TypedValue; -import org.spdx.library.model.compat.v2.license.CrossRef; -import org.spdx.library.model.compat.v2.license.LicenseException; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.CrossRef; +import org.spdx.library.model.v2.license.LicenseException; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -47,7 +51,7 @@ public class SpdxListedLicenseLocalStoreTest extends TestCase { private static final String APACHE_ID = "Apache-2.0"; - private static final String LICENSE_LIST_URI = "https://spdx.org/licenses/"; + private static final String LICENSE_LIST_URI = "http://spdx.org/licenses/"; private static final String LICENSE_LIST_VERSION = "3.17"; private static final String APACHE_LICENSE_NAME = "Apache License 2.0"; @@ -60,6 +64,7 @@ public class SpdxListedLicenseLocalStoreTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } /* (non-Javadoc) @@ -87,13 +92,13 @@ public void testExists() throws Exception { */ public void testCreate() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String nextId = slll.getNextId(IdType.ListedLicense); + slll.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, "SPDX-2.3")); String result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); - nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + nextId = slll.getNextId(IdType.ListedLicense); + slll.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, "SPDX-2.3")); result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); slll.close(); @@ -105,8 +110,8 @@ public void testCreate() throws Exception { */ public void testGetNextId() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - String nextNextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); + String nextId = slll.getNextId(IdType.ListedLicense); + String nextNextId = slll.getNextId(IdType.ListedLicense); assertTrue(nextId.compareTo(nextNextId) < 0); slll.close(); } @@ -168,9 +173,10 @@ public void testSetValue() throws Exception { slll.close(); } - public void testCreateLicense() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { + public void testCreateLicenseV2() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); + SpdxV2ListedLicenseModelStore modelStore = new SpdxV2ListedLicenseModelStore(slll); + SpdxListedLicense result = (SpdxListedLicense)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(modelStore, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); assertEquals(APACHE_ID, result.getLicenseId()); assertEquals(APACHE_LICENSE_NAME, result.getName()); String licenseText = result.getLicenseText(); @@ -190,11 +196,33 @@ public void testCreateLicense() throws InvalidSPDXAnalysisException, InvalidLice assertTrue(lResult.get(0).length() > 10); assertTrue(result.getStandardLicenseHeader().length() > 100); assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, (result.getType())); + assertTrue(result.verify().isEmpty()); } - public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { + public void testCreateLicenseV3() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - LicenseException result = (LicenseException)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + SpdxV3ListedLicenseModelStore modelStore = new SpdxV3ListedLicenseModelStore(slll); + ExpandedLicensingListedLicense result = new ExpandedLicensingListedLicense(modelStore, LICENSE_LIST_URI + APACHE_ID, null, true); + assertEquals(LICENSE_LIST_URI + APACHE_ID, result.getObjectUri()); + assertEquals(APACHE_LICENSE_NAME, result.getName().get()); + String licenseText = result.getSimpleLicensingLicenseText(); + assertTrue(licenseText.length() > 100); + assertTrue(result.getComment().get().length() > 5); + assertTrue(result.getExpandedLicensingIsFsfLibre().get()); + assertFalse(result.getExpandedLicensingIsDeprecatedLicenseId().get()); + assertTrue(result.getExpandedLicensingIsOsiApproved().get()); + List lResult = new ArrayList(result.getExpandedLicensingSeeAlsos()); + assertTrue(lResult.size() > 0); + assertTrue(lResult.get(0).length() > 10); + assertTrue(result.getExpandedLicensingStandardLicenseHeader().get().length() > 100); + assertEquals(SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE, (result.getType())); + assertTrue(result.verify().isEmpty()); + } + + public void testCreateExceptionV2() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { + SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); + SpdxV2ListedLicenseModelStore v2store = new SpdxV2ListedLicenseModelStore(slll); + LicenseException result = (LicenseException)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(v2store, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); assertEquals(ECOS_EXCEPTION_ID, result.getLicenseExceptionId()); assertEquals(ECOS_EXCEPTION_ID, result.getId()); assertTrue(result.getComment().length() > 5); @@ -206,20 +234,38 @@ public void testCreateException() throws InvalidSPDXAnalysisException, InvalidLi assertTrue(lResult.get(0).length() > 10); assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, (result.getType())); assertFalse(result.isDeprecated()); + assertTrue(result.verify().isEmpty()); + } + + public void testCreateExceptionV3() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { + SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); + SpdxV3ListedLicenseModelStore v3store = new SpdxV3ListedLicenseModelStore(slll); + ExpandedLicensingListedLicenseException result = new ExpandedLicensingListedLicenseException(v3store, LICENSE_LIST_URI+ECOS_EXCEPTION_ID, null, true); + assertEquals(LICENSE_LIST_URI+ECOS_EXCEPTION_ID, result.getObjectUri()); + assertTrue(result.getComment().get().length() > 5); + assertTrue(result.getExpandedLicensingAdditionText().length() > 100); + assertEquals(ECOS_LICENSE_NAME, result.getName().get()); + List lResult = new ArrayList(result.getExpandedLicensingSeeAlsos()); + assertTrue(lResult.size() > 0); + assertTrue(lResult.get(0).length() > 10); + assertEquals(SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION, (result.getType())); + assertFalse(result.getExpandedLicensingIsDeprecatedAdditionId().get()); + assertTrue(result.verify().isEmpty()); } @SuppressWarnings("unchecked") public void testList() throws InvalidSPDXAnalysisException { - SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); + SpdxListedLicenseLocalStore slls = new SpdxListedLicenseLocalStore(); + SpdxV2ListedLicenseModelStore spdx2localstore = new SpdxV2ListedLicenseModelStore(slls); // Exception - ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + ListedLicenseException exception = (ListedLicenseException)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(spdx2localstore, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); String seeAlso1 = "seeAlso1"; String seeAlso2 = "seeAlso2"; List seeAlsos = Arrays.asList(new String[]{seeAlso1, seeAlso2}); exception.setSeeAlso(seeAlsos); // getValueList List result = new ArrayList<>(); - Iterator resultIter = slll.listValues(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + Iterator resultIter = spdx2localstore.listValues(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -227,29 +273,29 @@ public void testList() throws InvalidSPDXAnalysisException { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(spdx2localstore.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), spdx2localstore.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection String seeAlso3 = "seeAlso3"; - assertFalse(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.addValueToCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(spdx2localstore.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(spdx2localstore.addValueToCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(spdx2localstore.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, spdx2localstore.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(slll.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(spdx2localstore.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(spdx2localstore.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), spdx2localstore.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(spdx2localstore.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // License ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(slll, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); + SpdxListedLicense license = (SpdxListedLicense)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(spdx2localstore, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); license.setSeeAlso(seeAlsos); // getValueList result.clear(); - resultIter = slll.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + resultIter = spdx2localstore.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -257,63 +303,63 @@ public void testList() throws InvalidSPDXAnalysisException { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), spdx2localstore.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection - assertFalse(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(spdx2localstore.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, spdx2localstore.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(slll.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(slll.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(spdx2localstore.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), spdx2localstore.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(spdx2localstore.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // license crossRefs license.getCrossRef().clear(); - assertEquals(0, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - IModelStore simpleModelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + assertEquals(0, spdx2localstore.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + IModelStore simpleModelStore = new InMemSpdxStore(); String docUri = "http://some.other.doc"; - CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); + CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous), copyManager, true); crossRef1.setUrl("http://url1"); - CrossRef crossRef2 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); + CrossRef crossRef2 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous), copyManager, true); crossRef2.setUrl("http://url2"); List crossRefs = Arrays.asList(new CrossRef[]{crossRef1, crossRef2}); license.getCrossRef().add(crossRef1); license.getCrossRef().add(crossRef2); result.clear(); - resultIter = slll.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); + resultIter = spdx2localstore.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); List tvResult = new ArrayList<>(); while (resultIter.hasNext()) { TypedValue tv = (TypedValue)resultIter.next(); tvResult.add(tv); - result.add(new CrossRef(slll, LICENSE_LIST_URI, tv.getObjectUri(), copyManager, false)); + result.add(new CrossRef(spdx2localstore, LICENSE_LIST_URI, tv.getObjectUri(), copyManager, false)); } List result2 = (List)(List)Arrays.asList(license.getCrossRef().toArray()); assertEquals(2, result.size()); assertEquals(2, result2.size()); - assertEquals(2, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertEquals(2, spdx2localstore.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, (List)(List)result)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, result2)); for (TypedValue tv:tvResult) { - assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); + assertTrue(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); } for (CrossRef crossRef:crossRefs) { // collectionContains assertTrue(license.getCrossRef().contains(crossRef)); } - CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); + CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous), copyManager, true); crossRef3.setUrl("http://url3"); - String newCrossRefId = slll.getNextId(IdType.Anonymous, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI + newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - slll.setValue(LICENSE_LIST_URI + newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); - TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - slll.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertEquals(3, slll.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - assertTrue(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + String newCrossRefId = spdx2localstore.getNextId(IdType.Anonymous); + spdx2localstore.create(new TypedValue(LICENSE_LIST_URI + newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF, "SPDX-2.3")); + spdx2localstore.setValue(LICENSE_LIST_URI + newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); + TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF, "SPDX-2.3"); + spdx2localstore.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertEquals(3, spdx2localstore.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertTrue(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); boolean found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -322,8 +368,8 @@ public void testList() throws InvalidSPDXAnalysisException { } } assertTrue(found); - slll.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertFalse(slll.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + spdx2localstore.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertFalse(spdx2localstore.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -346,12 +392,12 @@ public void testIsCollectionMembersAssignableTo() throws Exception { public void testIsPropertyValueAssignableTo() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class)); - assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class)); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, Boolean.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, String.class, "SPDX-2.3")); + assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, String.class, "SPDX-2.3")); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LICENSE_TEXT, Boolean.class, "SPDX-2.3")); - assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class)); - assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class)); + assertFalse(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, String.class, "SPDX-2.3")); + assertTrue(slll.isPropertyValueAssignableTo(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_LIC_ID_DEPRECATED, Boolean.class, "SPDX-2.3")); slll.close(); } @@ -364,16 +410,16 @@ public void testIsCollectionProperty() throws Exception { public void testDelete() throws Exception { SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); - String nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String nextId = slll.getNextId(IdType.ListedLicense); + slll.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, "SPDX-2.3")); String result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); assertTrue(slll.exists(LICENSE_LIST_URI + nextId)); slll.delete(LICENSE_LIST_URI + nextId); assertFalse(slll.exists(LICENSE_LIST_URI + nextId)); - nextId = slll.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - slll.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + nextId = slll.getNextId(IdType.ListedLicense); + slll.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, "SPDX-2.3")); result = (String)slll.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); assertTrue(slll.exists(LICENSE_LIST_URI + nextId)); @@ -381,5 +427,17 @@ public void testDelete() throws Exception { assertFalse(slll.exists(LICENSE_LIST_URI + nextId)); slll.close(); } + + public void testCreationInfo() throws Exception { + SpdxListedLicenseLocalStore slll = new SpdxListedLicenseLocalStore(); + SpdxV3ListedLicenseModelStore modelStore = new SpdxV3ListedLicenseModelStore(slll); + ExpandedLicensingListedLicense license = new ExpandedLicensingListedLicense(modelStore, LICENSE_LIST_URI + APACHE_ID, null, true); + assertTrue(license.verify().isEmpty()); + CreationInfo creationInfo = license.getCreationInfo(); + assertFalse(creationInfo.getCreated().isEmpty()); + List createdBys = new ArrayList<>(creationInfo.getCreatedBys()); + assertEquals(1, createdBys.size()); + assertFalse(createdBys.get(0).getName().get().isEmpty()); + } } diff --git a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java index b8bae4d99..450709f7c 100644 --- a/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java +++ b/src/test/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStoreTest.java @@ -22,16 +22,21 @@ import java.util.Iterator; import java.util.List; -import org.spdx.library.InvalidSPDXAnalysisException; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.core.TypedValue; import org.spdx.library.ModelCopyManager; -import org.spdx.library.SpdxConstantsCompatV2; import org.spdx.library.SpdxModelFactory; -import org.spdx.library.TypedValue; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.license.CrossRef; -import org.spdx.library.model.compat.v2.license.LicenseException; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; +import org.spdx.library.model.v2.license.CrossRef; +import org.spdx.library.model.v2.license.LicenseException; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.core.Agent; +import org.spdx.library.model.v3.core.CreationInfo; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.licenseTemplate.InvalidLicenseTemplateException; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; import org.spdx.storage.simple.InMemSpdxStore; @@ -46,7 +51,7 @@ public class SpdxListedLicenseWebStoreTest extends TestCase { private static final String APACHE_ID = "Apache-2.0"; - private static final String LICENSE_LIST_URI = "https://spdx.org/licenses/"; + private static final String LICENSE_LIST_URI = "http://spdx.org/licenses/"; private static final String LICENSE_LIST_VERSION = "3.17"; private static final String APACHE_LICENSE_NAME = "Apache License 2.0"; private static final int NUM_3_7_LICENSES = 373; @@ -60,6 +65,7 @@ public class SpdxListedLicenseWebStoreTest extends TestCase { */ protected void setUp() throws Exception { super.setUp(); + SpdxModelFactory.init(); } /* (non-Javadoc) @@ -86,13 +92,13 @@ public void testExists() throws Exception { */ public void testCreate() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String nextId = sllw.getNextId(IdType.ListedLicense); + sllw.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, "SPDX-2.3")); String result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); - nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + nextId = sllw.getNextId(IdType.ListedLicense); + sllw.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, "SPDX-2.3")); result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); sllw.close(); @@ -103,8 +109,8 @@ public void testCreate() throws Exception { */ public void testGetNextId() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - String nextNextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); + String nextId = sllw.getNextId(IdType.ListedLicense); + String nextNextId = sllw.getNextId(IdType.ListedLicense); assertTrue(nextId.compareTo(nextNextId) < 0); sllw.close(); } @@ -191,15 +197,15 @@ public void testSetValue() throws Exception { sllw.close(); } - public void testCreateLicense() throws Exception { + public void testCreateLicenseV2() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - SpdxListedLicense result = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); + SpdxV2ListedLicenseModelStore modelStore = new SpdxV2ListedLicenseModelStore(sllw); + SpdxListedLicense result = (SpdxListedLicense)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(modelStore, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, null); assertEquals(APACHE_ID, result.getLicenseId()); assertEquals(APACHE_LICENSE_NAME, result.getName()); String licenseText = result.getLicenseText(); assertTrue(licenseText.length() > 100); assertTrue(result.getComment().length() > 5); - result.getDeprecatedVersion(); assertEquals(LICENSE_LIST_URI, result.getDocumentUri()); assertTrue(result.getFsfLibre()); assertFalse(result.isDeprecated()); @@ -214,19 +220,37 @@ public void testCreateLicense() throws Exception { assertTrue(lResult.get(0).length() > 10); assertTrue(result.getStandardLicenseHeader().length() > 100); assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, (result.getType())); + assertTrue(result.verify().isEmpty()); } - @SuppressWarnings("deprecation") - public void testCreateException() throws Exception { + public void testCreateLicenseV3() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - LicenseException result = (LicenseException)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + SpdxV3ListedLicenseModelStore modelStore = new SpdxV3ListedLicenseModelStore(sllw); + ExpandedLicensingListedLicense result = new ExpandedLicensingListedLicense(modelStore, LICENSE_LIST_URI + APACHE_ID, null, true); + assertEquals(LICENSE_LIST_URI + APACHE_ID, result.getObjectUri()); + assertEquals(APACHE_LICENSE_NAME, result.getName().get()); + String licenseText = result.getSimpleLicensingLicenseText(); + assertTrue(licenseText.length() > 100); + assertTrue(result.getComment().get().length() > 5); + assertTrue(result.getExpandedLicensingIsFsfLibre().get()); + assertFalse(result.getExpandedLicensingIsDeprecatedLicenseId().get()); + assertTrue(result.getExpandedLicensingIsOsiApproved().get()); + List lResult = new ArrayList(result.getExpandedLicensingSeeAlsos()); + assertTrue(lResult.size() > 0); + assertTrue(lResult.get(0).length() > 10); + assertTrue(result.getExpandedLicensingStandardLicenseHeader().get().length() > 100); + assertEquals(SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE, (result.getType())); + assertTrue(result.verify().isEmpty()); + } + + public void testCreateExceptionV2() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { + SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); + SpdxV2ListedLicenseModelStore v2store = new SpdxV2ListedLicenseModelStore(sllw); + LicenseException result = (LicenseException)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(v2store, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); assertEquals(ECOS_EXCEPTION_ID, result.getLicenseExceptionId()); assertEquals(ECOS_EXCEPTION_ID, result.getId()); assertTrue(result.getComment().length() > 5); - result.getDeprecatedVersion(); assertEquals(LICENSE_LIST_URI, result.getDocumentUri()); - result.getExample(); - result.getLicenseExceptionTemplate(); assertTrue(result.getLicenseExceptionText().length() > 100); assertEquals(ECOS_LICENSE_NAME, result.getName()); List lResult = new ArrayList(result.getSeeAlso()); @@ -234,20 +258,38 @@ public void testCreateException() throws Exception { assertTrue(lResult.get(0).length() > 10); assertEquals(SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, (result.getType())); assertFalse(result.isDeprecated()); + assertTrue(result.verify().isEmpty()); + } + + public void testCreateExceptionV3() throws InvalidSPDXAnalysisException, InvalidLicenseTemplateException { + SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); + SpdxV3ListedLicenseModelStore v3store = new SpdxV3ListedLicenseModelStore(sllw); + ExpandedLicensingListedLicenseException result = new ExpandedLicensingListedLicenseException(v3store, LICENSE_LIST_URI+ECOS_EXCEPTION_ID, null, true); + assertEquals(LICENSE_LIST_URI+ECOS_EXCEPTION_ID, result.getObjectUri()); + assertTrue(result.getComment().get().length() > 5); + assertTrue(result.getExpandedLicensingAdditionText().length() > 100); + assertEquals(ECOS_LICENSE_NAME, result.getName().get()); + List lResult = new ArrayList(result.getExpandedLicensingSeeAlsos()); + assertTrue(lResult.size() > 0); + assertTrue(lResult.get(0).length() > 10); + assertEquals(SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE_EXCEPTION, (result.getType())); + assertFalse(result.getExpandedLicensingIsDeprecatedAdditionId().get()); + assertTrue(result.verify().isEmpty()); } @SuppressWarnings("unchecked") public void testList() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); + SpdxV2ListedLicenseModelStore v2store = new SpdxV2ListedLicenseModelStore(sllw); // Exception - ListedLicenseException exception = (ListedLicenseException)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); + ListedLicenseException exception = (ListedLicenseException)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(v2store, LICENSE_LIST_URI, ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, null); String seeAlso1 = "seeAlso1"; String seeAlso2 = "seeAlso2"; List seeAlsos = Arrays.asList(new String[]{seeAlso1, seeAlso2}); exception.setSeeAlso(seeAlsos); // getValueList List result = new ArrayList<>(); - Iterator resultIter = sllw.listValues(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + Iterator resultIter = v2store.listValues(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -255,29 +297,29 @@ public void testList() throws Exception { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(v2store.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), v2store.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection String seeAlso3 = "seeAlso3"; - assertFalse(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(v2store.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(v2store.addValueToCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(v2store.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, v2store.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(v2store.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(v2store.collectionContains(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), v2store.collectionSize(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(v2store.removeValueFromCollection(LICENSE_LIST_URI + ECOS_EXCEPTION_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // License ModelCopyManager copyManager = new ModelCopyManager(); - SpdxListedLicense license = (SpdxListedLicense)SpdxModelFactory.createModelObjectV2(sllw, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); + SpdxListedLicense license = (SpdxListedLicense)org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(v2store, LICENSE_LIST_URI, APACHE_ID, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager); license.setSeeAlso(seeAlsos); // getValueList result.clear(); - resultIter = sllw.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); + resultIter = v2store.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO); while (resultIter.hasNext()) { result.add(resultIter.next()); } @@ -285,63 +327,63 @@ public void testList() throws Exception { for (String seeAlso:seeAlsos) { assertTrue(result.contains(seeAlso)); // collectionContains - assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); + assertTrue(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso)); } // collectionSize - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertEquals(seeAlsos.size(), v2store.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // addValueToCollection - assertFalse(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size()+1, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(v2store.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size()+1, v2store.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); // remove value - assertTrue(sllw.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); - assertEquals(seeAlsos.size(), sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); - assertFalse(sllw.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertTrue(v2store.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertFalse(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); + assertEquals(seeAlsos.size(), v2store.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO)); + assertFalse(v2store.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.RDFS_PROP_SEE_ALSO, seeAlso3)); // license crossRefs license.getCrossRef().clear(); - assertEquals(0, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - IModelStore simpleModelStore = new InMemSpdxStore(SpdxMajorVersion.VERSION_2); + assertEquals(0, v2store.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + IModelStore simpleModelStore = new InMemSpdxStore(); String docUri = "http://some.other.doc"; - CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); + CrossRef crossRef1 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous), copyManager, true); crossRef1.setUrl("http://url1"); - CrossRef crossRef2 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); + CrossRef crossRef2 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous), copyManager, true); crossRef2.setUrl("http://url2"); List crossRefs = Arrays.asList(new CrossRef[]{crossRef1, crossRef2}); license.getCrossRef().add(crossRef1); license.getCrossRef().add(crossRef2); result.clear(); - resultIter = sllw.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); + resultIter = v2store.listValues(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF); List tvResult = new ArrayList<>(); while (resultIter.hasNext()) { TypedValue tv = (TypedValue)resultIter.next(); tvResult.add(tv); - result.add(new CrossRef(sllw, LICENSE_LIST_URI, tv.getObjectUri(), copyManager, false)); + result.add(new CrossRef(v2store, LICENSE_LIST_URI, tv.getObjectUri(), copyManager, false)); } List result2 = (List)(List)Arrays.asList(license.getCrossRef().toArray()); assertEquals(2, result.size()); assertEquals(2, result2.size()); - assertEquals(2, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertEquals(2, v2store.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, (List)(List)result)); assertTrue(UnitTestHelper.isListsEquivalent(crossRefs, result2)); for (TypedValue tv:tvResult) { - assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); + assertTrue(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, tv)); } for (CrossRef crossRef:crossRefs) { // collectionContains assertTrue(license.getCrossRef().contains(crossRef)); } - CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous, docUri), copyManager, true); + CrossRef crossRef3 = new CrossRef(simpleModelStore, docUri, simpleModelStore.getNextId(IdType.Anonymous), copyManager, true); crossRef3.setUrl("http://url3"); - String newCrossRefId = sllw.getNextId(IdType.Anonymous, LICENSE_LIST_URI); - sllw.create(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - sllw.setValue(newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); - TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF); - sllw.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertEquals(3, sllw.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); - assertTrue(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + String newCrossRefId = v2store.getNextId(IdType.Anonymous); + v2store.create(new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF, "SPDX-2.3")); + v2store.setValue(newCrossRefId, SpdxConstantsCompatV2.PROP_CROSS_REF_URL, "http://url3"); + TypedValue newCrossRefTv = new TypedValue(newCrossRefId, SpdxConstantsCompatV2.CLASS_CROSS_REF, "SPDX-2.3"); + v2store.addValueToCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertEquals(3, v2store.collectionSize(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF)); + assertTrue(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); boolean found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -350,8 +392,8 @@ public void testList() throws Exception { } } assertTrue(found); - sllw.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); - assertFalse(sllw.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); + v2store.removeValueFromCollection(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv); + assertFalse(v2store.collectionContains(LICENSE_LIST_URI + APACHE_ID, SpdxConstantsCompatV2.PROP_CROSS_REF, newCrossRefTv)); found = false; for (CrossRef cr:license.getCrossRef()) { if (cr.equivalent(crossRef3)) { @@ -360,7 +402,7 @@ public void testList() throws Exception { } } assertFalse(found); - sllw.close(); + v2store.close(); } public void testIsCollectionProperty() throws Exception { @@ -374,16 +416,16 @@ public void testIsCollectionProperty() throws Exception { public void testDelete() throws Exception { SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); - String nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE); + String nextId = sllw.getNextId(IdType.ListedLicense); + sllw.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, "SPDX-2.3")); String result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_ID).get(); assertEquals(nextId, result); assertTrue(sllw.exists(LICENSE_LIST_URI + nextId)); sllw.delete(LICENSE_LIST_URI + nextId); assertFalse(sllw.exists(LICENSE_LIST_URI + nextId)); - nextId = sllw.getNextId(IdType.ListedLicense, LICENSE_LIST_URI); - sllw.create(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION); + nextId = sllw.getNextId(IdType.ListedLicense); + sllw.create(new TypedValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, "SPDX-2.3")); result = (String)sllw.getValue(LICENSE_LIST_URI + nextId, SpdxConstantsCompatV2.PROP_LICENSE_EXCEPTION_ID).get(); assertEquals(nextId, result); assertTrue(sllw.exists(LICENSE_LIST_URI + nextId)); @@ -391,4 +433,16 @@ public void testDelete() throws Exception { assertFalse(sllw.exists(LICENSE_LIST_URI + nextId)); sllw.close(); } + + public void testCreationInfo() throws Exception { + SpdxListedLicenseWebStore sllw = new SpdxListedLicenseWebStore(); + SpdxV3ListedLicenseModelStore modelStore = new SpdxV3ListedLicenseModelStore(sllw); + ExpandedLicensingListedLicense license = new ExpandedLicensingListedLicense(modelStore, LICENSE_LIST_URI + APACHE_ID, null, true); + assertTrue(license.verify().isEmpty()); + CreationInfo creationInfo = license.getCreationInfo(); + assertFalse(creationInfo.getCreated().isEmpty()); + List createdBys = new ArrayList<>(creationInfo.getCreatedBys()); + assertEquals(1, createdBys.size()); + assertFalse(createdBys.get(0).getName().get().isEmpty()); + } } diff --git a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java index a82a731d9..aa4b0f2e9 100644 --- a/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java +++ b/src/test/java/org/spdx/utility/compare/LicenseCompareHelperTest.java @@ -29,19 +29,23 @@ import java.util.Map; import java.util.Objects; -import org.spdx.library.DefaultModelStore; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.SpdxConstants.SpdxMajorVersion; -import org.spdx.library.model.compat.v2.license.AnyLicenseInfo; -import org.spdx.library.model.compat.v2.license.ConjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.DisjunctiveLicenseSet; -import org.spdx.library.model.compat.v2.license.ExtractedLicenseInfo; -import org.spdx.library.model.compat.v2.license.LicenseInfoFactory; -import org.spdx.library.model.compat.v2.license.ListedLicenseException; -import org.spdx.library.model.compat.v2.license.ListedLicenses; -import org.spdx.library.model.compat.v2.license.SpdxListedLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoAssertionLicense; -import org.spdx.library.model.compat.v2.license.SpdxNoneLicense; +import org.spdx.core.DefaultModelStore; +import org.spdx.core.IModelCopyManager; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.ModelCopyManager; +import org.spdx.library.SpdxModelFactory; +import org.spdx.library.model.v2.license.AnyLicenseInfo; +import org.spdx.library.model.v2.license.ConjunctiveLicenseSet; +import org.spdx.library.model.v2.license.DisjunctiveLicenseSet; +import org.spdx.library.model.v2.license.ExtractedLicenseInfo; +import org.spdx.library.model.v2.license.LicenseInfoFactory; +import org.spdx.library.model.v2.license.ListedLicenseException; +import org.spdx.library.model.v2.license.ListedLicenses; +import org.spdx.library.model.v2.license.SpdxListedLicense; +import org.spdx.library.model.v2.license.SpdxNoAssertionLicense; +import org.spdx.library.model.v2.license.SpdxNoneLicense; +import org.spdx.storage.IModelStore; +import org.spdx.storage.simple.InMemSpdxStore; import org.spdx.utility.compare.CompareTemplateOutputHandler.DifferenceDescription; import org.spdx.utility.compare.FilterTemplateOutputHandler.VarTextHandling; @@ -82,19 +86,27 @@ public class LicenseCompareHelperTest extends TestCase { static final String POLYFORM_NC_TEMPLATE = "TestFiles" + File.separator + "PolyForm-Noncommercial-1.0.0.template.txt"; static final String APL_1_TEXT = "TestFiles" + File.separator + "APL-1.0.txt"; static final String APL_1_TEMPLATE = "TestFiles" + File.separator + "APL-1.0.template.txt"; + + IModelStore modelStore; + IModelCopyManager copyManager; + String DEFAULT_DOCUMENT_URI = "http://default/doc"; + /** * @throws java.lang.Exception */ public void setUp() throws Exception { - DefaultModelStore.reset(SpdxMajorVersion.VERSION_2); + SpdxModelFactory.init(); + modelStore = new InMemSpdxStore(); + copyManager = new ModelCopyManager(); + DefaultModelStore.initialize(modelStore, DEFAULT_DOCUMENT_URI, copyManager); } /** * @throws java.lang.Exception */ public void tearDown() throws Exception { - DefaultModelStore.reset(SpdxMajorVersion.VERSION_3); + DefaultModelStore.initialize(new InMemSpdxStore(), DEFAULT_DOCUMENT_URI, new ModelCopyManager()); } /** diff --git a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java index 8e472b622..99772c681 100644 --- a/src/test/java/org/spdx/utility/compare/UnitTestHelper.java +++ b/src/test/java/org/spdx/utility/compare/UnitTestHelper.java @@ -30,11 +30,10 @@ import java.net.URI; import java.net.URLConnection; -import org.spdx.library.InvalidSPDXAnalysisException; -import org.spdx.library.model.compat.v2.ModelObject; -import org.spdx.library.model.compat.v2.SpdxDocument; -import org.spdx.storage.IModelStore.IdType; -import org.spdx.storage.compat.v2.CompatibleModelStoreWrapper; +import org.spdx.core.InvalidSPDXAnalysisException; +import org.spdx.library.model.v2.ModelObjectV2; +import org.spdx.library.model.v2.SpdxDocument; +import org.spdx.storage.CompatibleModelStoreWrapper; /** * Helper class for unit tests @@ -193,11 +192,7 @@ public static void copyObjectsToDoc(SpdxDocument doc, Collection Date: Mon, 27 May 2024 21:50:19 -0700 Subject: [PATCH 32/62] WIP - updating license expression parser for V3 Signed-off-by: Gary O'Neall --- .../org/spdx/library/LicenseInfoFactory.java | 2 +- .../license/LicenseExpressionParser.java | 41 ++++++++++++++++++- .../license/LicenseExpressionParserTest.java | 26 ++++++------ 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/spdx/library/LicenseInfoFactory.java b/src/main/java/org/spdx/library/LicenseInfoFactory.java index c46890cb5..7af614737 100644 --- a/src/main/java/org/spdx/library/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/LicenseInfoFactory.java @@ -102,7 +102,7 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla copyManager = DefaultModelStore.getDefaultCopyManager(); } try { - return LicenseExpressionParser.parseLicenseExpression(licenseString, store, documentUri, + return LicenseExpressionParser.parseLicenseExpressionCompatV2(licenseString, store, documentUri, copyManager); } catch (LicenseParserException e) { throw new InvalidLicenseStringException(e.getMessage(),e); diff --git a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java index f44193aac..31d5df09f 100644 --- a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java @@ -45,6 +45,7 @@ import org.spdx.library.model.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.v2.license.SpdxNoneLicense; import org.spdx.library.model.v2.license.WithExceptionOperator; +import org.spdx.library.model.v3.simplelicensing.SimpleLicensingAnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -75,8 +76,44 @@ enum Operator { OPERATOR_MAP.put("or", Operator.OR); OPERATOR_MAP.put("with", Operator.WITH); } + + /** + * Parses a license expression into an license for use in the Model using the SPDX Version 3.X model + * @param expression Expression to be parsed + * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model store will be used. + * @param documentUri Document URI for the document containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model document URI will be used. + * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's + * @return the parsed license expression + * @throws InvalidSPDXAnalysisException + */ + public static SimpleLicensingAnyLicenseInfo parseLicenseExpressionCompat(String expression, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (expression == null || expression.trim().isEmpty()) { + throw new LicenseParserException("Empty license expression"); + } + Objects.requireNonNull(store, "Model store can not be null"); + Objects.requireNonNull(documentUri, "Document URI can not be null"); + String[] tokens = tokenizeExpression(expression); + if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) { + return new SpdxNoAssertionLicense(); + } else if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NONE_VALUE)) { + return new SpdxNoneLicense(); + } else { + try { + return parseLicenseExpression(tokens, store, documentUri, copyManager); + } catch (LicenseParserException ex) { + // Add the expression to the error message to provide additional information to the user + throw new LicenseParserException(ex.getMessage()+" License expression: '"+expression+"'", ex); + } catch (EmptyStackException ex) { + throw new LicenseParserException("Invalid license expression: '"+expression+"' - check that every operator (e.g. AND and OR) has operators and that parenthesis are matched"); + } + } + } + /** - * Parses a license expression into an license for use in the Model + * Parses a license expression into an license for use in the Model using the SPDX Version 2.X model * @param expression Expression to be parsed * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If * none exist for an ID, they will be added. If null, the default model store will be used. @@ -86,7 +123,7 @@ enum Operator { * @return the parsed license expression * @throws InvalidSPDXAnalysisException */ - public static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore store, + public static AnyLicenseInfo parseLicenseExpressionCompatV2(String expression, IModelStore store, String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (expression == null || expression.trim().isEmpty()) { throw new LicenseParserException("Empty license expression"); diff --git a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java index 7247d6884..2488c5c7c 100644 --- a/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java +++ b/src/test/java/org/spdx/library/model/compat/v2/license/LicenseExpressionParserTest.java @@ -88,7 +88,7 @@ protected void tearDown() throws Exception { public void testSingleStdLicense() throws InvalidSPDXAnalysisException { String parseString = STD_IDS[0]; AnyLicenseInfo expected = STANDARD_LICENSES[0]; - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -97,14 +97,14 @@ public void testSingleStdLicense() throws InvalidSPDXAnalysisException { public void testSingleExtractedLicense() throws InvalidSPDXAnalysisException { String parseString = NONSTD_IDS[0]; AnyLicenseInfo expected = NON_STD_LICENSES[0]; - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, DefaultModelStore.getDefaultModelStore(), + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } public void testUninitializedExtractedLicense() throws InvalidSPDXAnalysisException { String parseString = "LicenseRef-3242"; - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, DefaultModelStore.getDefaultModelStore(), + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertEquals(parseString, result.getId()); } @@ -113,7 +113,7 @@ public void testUninitializedExtractedLicense() throws InvalidSPDXAnalysisExcept public void testOrLater() throws InvalidSPDXAnalysisException { String parseString = STD_IDS[0]+"+"; AnyLicenseInfo expected = new OrLaterOperator(STANDARD_LICENSES[0]); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -122,7 +122,7 @@ public void testOrLater() throws InvalidSPDXAnalysisException { public void testWithException() throws InvalidSPDXAnalysisException { String parseString = STD_IDS[0]+" WITH " + EXCEPTION_IDS[0]; AnyLicenseInfo expected = new WithExceptionOperator(STANDARD_LICENSES[0], LICENSE_EXCEPTIONS[0]); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, DefaultModelStore.getDefaultModelStore(), + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -131,7 +131,7 @@ public void testWithException() throws InvalidSPDXAnalysisException { public void testSimpleAnd() throws InvalidSPDXAnalysisException { String parseString = STD_IDS[0] + " AND " + NONSTD_IDS[0]; AnyLicenseInfo expected = gmo.createConjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[0], NON_STD_LICENSES[0]}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -140,7 +140,7 @@ public void testSimpleAnd() throws InvalidSPDXAnalysisException { public void testSimpleOr() throws InvalidSPDXAnalysisException { String parseString = STD_IDS[0] + " OR " + NONSTD_IDS[0]; AnyLicenseInfo expected = gmo.createDisjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[0], NON_STD_LICENSES[0]}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -151,7 +151,7 @@ public void testLargerAnd() throws InvalidSPDXAnalysisException { STD_IDS[2] + " AND " + STD_IDS[3]; AnyLicenseInfo expected = gmo.createConjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1], NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, DefaultModelStore.getDefaultModelStore(), + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -162,7 +162,7 @@ public void testLargerOr() throws InvalidSPDXAnalysisException { STD_IDS[2] + " OR " + STD_IDS[3]; AnyLicenseInfo expected = gmo.createDisjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1], NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, DefaultModelStore.getDefaultModelStore(), + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -173,7 +173,7 @@ public void testOuterParens() throws InvalidSPDXAnalysisException { STD_IDS[2] + " OR " + STD_IDS[3] + ")"; AnyLicenseInfo expected = gmo.createDisjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1], NON_STD_LICENSES[1], STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -185,7 +185,7 @@ public void testInnerParens() throws InvalidSPDXAnalysisException { DisjunctiveLicenseSet dls = gmo.createDisjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[2], STANDARD_LICENSES[3]}))); AnyLicenseInfo expected = gmo.createConjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1] , NON_STD_LICENSES[1], dls}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, DefaultModelStore.getDefaultModelStore(), + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } @@ -197,14 +197,14 @@ public void testAndOrPrecedence() throws InvalidSPDXAnalysisException { ConjunctiveLicenseSet cls = gmo.createConjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {NON_STD_LICENSES[1], STANDARD_LICENSES[2]}))); AnyLicenseInfo expected = gmo.createDisjunctiveLicenseSet(new ArrayList(Arrays.asList(new AnyLicenseInfo[] {STANDARD_LICENSES[1] , cls, STANDARD_LICENSES[3]}))); - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(parseString, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(parseString, DefaultModelStore.getDefaultModelStore(), DefaultModelStore.getDefaultDocumentUri(), DefaultModelStore.getDefaultCopyManager()); assertTrue(expected.equals(result)); } public void testExternalLicenseRef() throws InvalidSPDXAnalysisException { String externalExtractedId = DOCID + ":" + SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM + "232"; - AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpression(externalExtractedId, + AnyLicenseInfo result = LicenseExpressionParser.parseLicenseExpressionCompatV2(externalExtractedId, modelStore, TEST_DOCUMENT_URI, null); assertTrue(result instanceof ExternalExtractedLicenseInfo); assertEquals(externalExtractedId, ((ExternalExtractedLicenseInfo)result).getId()); From b83cad4cb22a277be260e5dd2c8506a869dd1788 Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Wed, 29 May 2024 16:27:23 -0700 Subject: [PATCH 33/62] Partial implementation of license expression parser Signed-off-by: Gary O'Neall --- .../org/spdx/library/SpdxModelFactory.java | 40 ++- .../license/LicenseExpressionParser.java | 264 ++++++++++++++++-- 2 files changed, 285 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index 9193c204c..0ab18cc75 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.stream.Stream; import javax.annotation.Nullable; @@ -31,6 +32,7 @@ import org.spdx.core.ModelRegistryException; import org.spdx.library.model.v2.SpdxModelInfoV2_X; import org.spdx.library.model.v3.SpdxModelInfoV3_0; +import org.spdx.library.model.v3.simplelicensing.SimpleLicensingAnyLicenseInfo; import org.spdx.storage.IModelStore; /** @@ -84,7 +86,7 @@ static String verifyVersion(String version) { /** * @return the latest version of the spec supported by the library */ - static String getLatestSpecVersion() { + public static String getLatestSpecVersion() { List allVersions = ModelRegistry.getModelRegistry().getSupportedVersions(); List preVersion2Versions = new ArrayList<>(); List post2Versions = new ArrayList<>(); @@ -205,5 +207,41 @@ public static Object getExternalElement(IModelStore store, String uri, public static @Nullable Enum uriToEnum(String uri) throws ModelRegistryException { return uriToEnum(uri, getLatestSpecVersion()); } + + /** + * @param store model store + * @param copyManager optional copy manager + * @param typeFilter type to filter on + * @param objectUriPrefixFilter only return objects with URI's starting with this string + * @return stream of objects stored in the model store - an object being any non primitive type + * @throws InvalidSPDXAnalysisException + */ + public static Stream getSpdxObjects(IModelStore store, @Nullable IModelCopyManager copyManager, + String typeFilter, String objectUriPrefixFilter) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(store, "Store must not be null"); + return store.getAllItems(objectUriPrefixFilter, typeFilter).map(tv -> { + //TODO: Change this a null namespace and filtering on anonomous or startswith document URI - this will catch the anon. types + try { + return inflateModelObject(store, tv.getObjectUri(), tv.getType(), copyManager, tv.getSpecVersion(), false); + } catch (InvalidSPDXAnalysisException e) { + throw new RuntimeException(e); + } + }); + } + + /** + * @param store + * @param string + * @param copyManager + * @param latestSpecVersion + * @return + */ + public static SimpleLicensingAnyLicenseInfo getExternalAnyLicenseInfo( + IModelStore store, String string, IModelCopyManager copyManager, + String latestSpecVersion) { + // TODO Figure out how to implement + // TODO Auto-generated method stub + return null; + } } diff --git a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java index 31d5df09f..1132fd2c3 100644 --- a/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/utility/license/LicenseExpressionParser.java @@ -30,9 +30,9 @@ import org.spdx.core.IModelCopyManager; import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.library.LicenseInfoFactory; +import org.spdx.library.SpdxModelFactory; import org.spdx.library.model.v2.ModelObjectV2; import org.spdx.library.model.v2.SpdxConstantsCompatV2; -import org.spdx.library.model.v2.SpdxModelFactory; import org.spdx.library.model.v2.license.AnyLicenseInfo; import org.spdx.library.model.v2.license.ConjunctiveLicenseSet; import org.spdx.library.model.v2.license.DisjunctiveLicenseSet; @@ -45,7 +45,20 @@ import org.spdx.library.model.v2.license.SpdxNoAssertionLicense; import org.spdx.library.model.v2.license.SpdxNoneLicense; import org.spdx.library.model.v2.license.WithExceptionOperator; +import org.spdx.library.model.v3.SpdxConstantsV3; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingConjunctiveLicenseSet; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingCustomLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingDisjunctiveLicenseSet; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingExtendableLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingNoAssertionLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingNoneLicense; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingOrLaterOperator; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingWithAdditionOperator; import org.spdx.library.model.v3.simplelicensing.SimpleLicensingAnyLicenseInfo; +import org.spdx.storage.CompatibleModelStoreWrapper; import org.spdx.storage.IModelStore; import org.spdx.storage.IModelStore.IdType; @@ -88,7 +101,7 @@ enum Operator { * @return the parsed license expression * @throws InvalidSPDXAnalysisException */ - public static SimpleLicensingAnyLicenseInfo parseLicenseExpressionCompat(String expression, IModelStore store, + public static SimpleLicensingAnyLicenseInfo parseLicenseExpression(String expression, IModelStore store, String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (expression == null || expression.trim().isEmpty()) { throw new LicenseParserException("Empty license expression"); @@ -97,9 +110,9 @@ public static SimpleLicensingAnyLicenseInfo parseLicenseExpressionCompat(String Objects.requireNonNull(documentUri, "Document URI can not be null"); String[] tokens = tokenizeExpression(expression); if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NOASSERTION_VALUE)) { - return new SpdxNoAssertionLicense(); + return new ExpandedLicensingNoAssertionLicense(); } else if (tokens.length == 1 && tokens[0].equals(SpdxConstantsCompatV2.NONE_VALUE)) { - return new SpdxNoneLicense(); + return new ExpandedLicensingNoneLicense(); } else { try { return parseLicenseExpression(tokens, store, documentUri, copyManager); @@ -137,7 +150,7 @@ public static AnyLicenseInfo parseLicenseExpressionCompatV2(String expression, I return new SpdxNoneLicense(); } else { try { - return parseLicenseExpression(tokens, store, documentUri, copyManager); + return parseLicenseExpressionCompatV2(tokens, store, documentUri, copyManager); } catch (LicenseParserException ex) { // Add the expression to the error message to provide additional information to the user throw new LicenseParserException(ex.getMessage()+" License expression: '"+expression+"'", ex); @@ -192,12 +205,12 @@ private static void processPreToken(String preToken, * @return * @throws InvalidSPDXAnalysisException */ - private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStore store, + private static SimpleLicensingAnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStore store, String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (tokens == null || tokens.length == 0) { throw new LicenseParserException("Expected license expression"); } - Stack operandStack = new Stack(); + Stack operandStack = new Stack(); Stack operatorStack = new Stack(); int tokenIndex = 0; String token; @@ -226,7 +239,8 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor throw new LicenseParserException("Missing exception clause"); } token = tokens[tokenIndex++]; - ListedLicenseException licenseException = null; + //TODO Update this to handle custom additions + ExpandedLicensingListedLicenseException licenseException = null; Optional exceptionId = Optional.empty(); if (LicenseInfoFactory.isSpdxListedExceptionId(token)) { exceptionId = LicenseInfoFactory.listedExceptionIdCaseSensitive(token); @@ -236,7 +250,99 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor } else if (token.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { throw new LicenseParserException("WITH must be followed by a license exception. "+token+" is a Listed License type."); } else { - licenseException = (ListedLicenseException) SpdxModelFactory.createModelObjectV2(store, + licenseException = new ExpandedLicensingListedLicenseException(store, + CompatibleModelStoreWrapper.documentUriIdToUri(documentUri, token, false), + copyManager, true); + } + SimpleLicensingAnyLicenseInfo operand = operandStack.pop(); + if (operand == null) { + throw new LicenseParserException("Missing license for with clause"); + } + if (!(operand instanceof ExpandedLicensingExtendableLicense)) { + throw new LicenseParserException("License with exception is not of type License or OrLaterOperator"); + } + ExpandedLicensingWithAdditionOperator weo = new ExpandedLicensingWithAdditionOperator(store, + store.getNextId(IdType.Anonymous), copyManager, true); + weo.setExpandedLicensingSubjectExtendableLicense((ExpandedLicensingExtendableLicense)operand); + weo.setExpandedLicensingSubjectAddition(licenseException); + operandStack.push(weo); + } else { + // process in order of precedence using the shunting yard algorithm + while (!operatorStack.isEmpty() && + operatorStack.peek().ordinal() <= operator.ordinal()) { + Operator tosOperator = operatorStack.pop(); + evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + } + operatorStack.push(operator); + } + } + } + // go through the rest of the stack + while (!operatorStack.isEmpty()) { + Operator tosOperator = operatorStack.pop(); + evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + } + SimpleLicensingAnyLicenseInfo retval = operandStack.pop(); + if (!operandStack.isEmpty()) { + throw new LicenseParserException("Invalid license expression. Expecting more operands."); + } + return retval; + } + + /** + * Parses a tokenized license expression into a license for use in the RDF Parser + * @param tokens + * @param store + * @param documentUri + * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's + * @return + * @throws InvalidSPDXAnalysisException + */ + private static AnyLicenseInfo parseLicenseExpressionCompatV2(String[] tokens, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (tokens == null || tokens.length == 0) { + throw new LicenseParserException("Expected license expression"); + } + Stack operandStack = new Stack(); + Stack operatorStack = new Stack(); + int tokenIndex = 0; + String token; + while (tokenIndex < tokens.length) { + token = tokens[tokenIndex++]; + // left operand + if (LEFT_PAREN.equals(token)) { + int rightParenIndex = findMatchingParen(tokens, tokenIndex); + if (rightParenIndex < 0) { + throw new LicenseParserException("Missing right parenthesis"); + } + String[] nestedTokens = Arrays.copyOfRange(tokens, tokenIndex, rightParenIndex); + operandStack.push(parseLicenseExpressionCompatV2(nestedTokens, store, documentUri, copyManager)); + tokenIndex = rightParenIndex + 1; + } else if (OPERATOR_MAP.get(token) == null) { // assumed to be a simple licensing type + operandStack.push(parseSimpleLicenseTokenCompatV2(token, store, documentUri, copyManager)); + } else { + Operator operator = OPERATOR_MAP.get(token); + if (operator == Operator.WITH) { + // special processing here since With must be with an exception, not a licenseInfo + if (!operatorStack.isEmpty() && Operator.OR_LATER.equals(operatorStack.peek())) { + Operator tosOperator = operatorStack.pop(); + evaluateExpressionCompatV2(tosOperator, operandStack, store, documentUri, copyManager); + } + if (tokenIndex >= tokens.length) { + throw new LicenseParserException("Missing exception clause"); + } + token = tokens[tokenIndex++]; + ListedLicenseException licenseException = null; + Optional exceptionId = Optional.empty(); + if (LicenseInfoFactory.isSpdxListedExceptionId(token)) { + exceptionId = LicenseInfoFactory.listedExceptionIdCaseSensitive(token); + } + if (exceptionId.isPresent()) { + licenseException = LicenseInfoFactory.getListedExceptionV2ById(exceptionId.get()); + } else if (token.startsWith(SpdxConstantsCompatV2.NON_STD_LICENSE_ID_PRENUM)) { + throw new LicenseParserException("WITH must be followed by a license exception. "+token+" is a Listed License type."); + } else { + licenseException = (ListedLicenseException) org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2(store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE_EXCEPTION, copyManager); } AnyLicenseInfo operand = operandStack.pop(); @@ -255,7 +361,7 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor while (!operatorStack.isEmpty() && operatorStack.peek().ordinal() <= operator.ordinal()) { Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + evaluateExpressionCompatV2(tosOperator, operandStack, store, documentUri, copyManager); } operatorStack.push(operator); } @@ -264,7 +370,7 @@ private static AnyLicenseInfo parseLicenseExpression(String[] tokens, IModelStor // go through the rest of the stack while (!operatorStack.isEmpty()) { Operator tosOperator = operatorStack.pop(); - evaluateExpression(tosOperator, operandStack, store, documentUri, copyManager); + evaluateExpressionCompatV2(tosOperator, operandStack, store, documentUri, copyManager); } AnyLicenseInfo retval = operandStack.pop(); if (!operandStack.isEmpty()) { @@ -307,7 +413,58 @@ private static int findMatchingParen(String[] tokens, int startToken) { * @return * @throws InvalidSPDXAnalysisException */ - private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String documentUri, + private static SimpleLicensingAnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore store, String documentUri, + IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + Objects.requireNonNull(token, "Token can not be null"); + Objects.requireNonNull(store, "Model store can not be null"); + Objects.requireNonNull(documentUri, "Document URI can not be null"); + if (token.contains(":")) { + // External License Ref + return SpdxModelFactory.getExternalAnyLicenseInfo(store, documentUri + token, copyManager, SpdxModelFactory.getLatestSpecVersion()); + } + Optional licenseId = Optional.empty(); + if (LicenseInfoFactory.isSpdxListedLicenseId(token)) { + // listed license + licenseId = LicenseInfoFactory.listedLicenseIdCaseSensitive(token); + } + ExpandedLicensingListedLicense listedLicense = LicenseInfoFactory.getListedLicenseById(licenseId.get()); + if (licenseId.isPresent()) { + if (!store.exists(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX + licenseId.get())) { + if (Objects.nonNull(copyManager)) { + // copy to the local store + copyManager.copy(store, listedLicense.getObjectUri(), listedLicense.getModelStore(), + listedLicense.getObjectUri(), SpdxConstantsV3.EXPANDED_LICENSING_EXPANDED_LICENSING_LISTED_LICENSE, + SpdxModelFactory.getLatestSpecVersion(), null); + // copy to the local store + } + } + return new ExpandedLicensingListedLicense(store, listedLicense.getObjectUri(), copyManager, true); + } else { + // LicenseRef + Optional caseSensitiveId = store.getCaseSensisitiveId(documentUri, token); + ExpandedLicensingCustomLicense localLicense = null; + if (caseSensitiveId.isPresent()) { + localLicense = new ExpandedLicensingCustomLicense(store, documentUri + caseSensitiveId.get(), copyManager, false); + + } else { + localLicense = new ExpandedLicensingCustomLicense(store, documentUri + caseSensitiveId.get(), copyManager, true); + localLicense.setSimpleLicensingLicenseText(UNINITIALIZED_LICENSE_TEXT); + } + return localLicense; + } + } + + /** + * Converts a string token into its equivalent license + * checking for a listed license + * @param token + * @param baseStore + * @param documentUri + * @param copyManager + * @return + * @throws InvalidSPDXAnalysisException + */ + private static AnyLicenseInfo parseSimpleLicenseTokenCompatV2(String token, IModelStore store, String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { Objects.requireNonNull(token, "Token can not be null"); Objects.requireNonNull(store, "Model store can not be null"); @@ -323,7 +480,7 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore } if (licenseId.isPresent()) { if (!store.exists(SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX + licenseId.get())) { - SpdxListedLicense listedLicense = LicenseInfoFactory.getListedLicenseById(licenseId.get()); + SpdxListedLicense listedLicense = LicenseInfoFactory.getListedLicenseV2ByIdCompat(licenseId.get()); if (Objects.nonNull(copyManager)) { // copy to the local store copyManager.copy(store, listedLicense.getObjectUri(), listedLicense.getModelStore(), @@ -331,7 +488,7 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore ModelObjectV2.LATEST_SPDX_2_VERSION, listedLicense.getDocumentUri()); } } - return (AnyLicenseInfo) SpdxModelFactory.getModelObjectV2(store, SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, + return (AnyLicenseInfo) org.spdx.library.model.v2.SpdxModelFactory.getModelObjectV2(store, SpdxConstantsCompatV2.LISTED_LICENSE_NAMESPACE_PREFIX, licenseId.get(), SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE, copyManager, true); } else { // LicenseRef @@ -341,14 +498,14 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore localLicense = new ExtractedLicenseInfo(store, documentUri, caseSensitiveId.get(), copyManager, false); } else { - localLicense = (ExtractedLicenseInfo) SpdxModelFactory.createModelObjectV2( + localLicense = (ExtractedLicenseInfo) org.spdx.library.model.v2.SpdxModelFactory.createModelObjectV2( store, documentUri, token, SpdxConstantsCompatV2.CLASS_SPDX_EXTRACTED_LICENSING_INFO, copyManager); localLicense.setExtractedText(UNINITIALIZED_LICENSE_TEXT); } return localLicense; } } - + /** * Evaluate the given operator using paramaeters in the parameter stack * @param operator @@ -357,6 +514,36 @@ private static AnyLicenseInfo parseSimpleLicenseToken(String token, IModelStore * @throws InvalidSPDXAnalysisException */ private static void evaluateExpression(Operator operator, + Stack operandStack, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (operator == Operator.OR_LATER) { + // unary operator + SimpleLicensingAnyLicenseInfo license = operandStack.pop(); + if (!(license instanceof ExpandedLicensingLicense)) { + throw new LicenseParserException("Missing license for the '+' or later operator"); + } + ExpandedLicensingOrLaterOperator olo = new ExpandedLicensingOrLaterOperator(store, store.getNextId(IdType.Anonymous), copyManager, true); + olo.setExpandedLicensingSubjectLicense((ExpandedLicensingLicense)license); + operandStack.push(olo); + } else { + // binary operator + SimpleLicensingAnyLicenseInfo operand2 = operandStack.pop(); + SimpleLicensingAnyLicenseInfo operand1 = operandStack.pop(); + if (operand1 == null || operand2 == null) { + throw new LicenseParserException("Missing operands for the "+operator.toString()+" operator"); + } + operandStack.push(evaluateBinary(operator, operand1, operand2, store, documentUri, copyManager)); + } + } + + /** + * Evaluate the given operator using paramaeters in the parameter stack + * @param operator + * @param operandStack + * @param copyManager + * @throws InvalidSPDXAnalysisException + */ + private static void evaluateExpressionCompatV2(Operator operator, Stack operandStack, IModelStore store, String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (operator == Operator.OR_LATER) { @@ -375,7 +562,7 @@ private static void evaluateExpression(Operator operator, if (operand1 == null || operand2 == null) { throw new LicenseParserException("Missing operands for the "+operator.toString()+" operator"); } - operandStack.push(evaluateBinary(operator, operand1, operand2, store, documentUri, copyManager)); + operandStack.push(evaluateBinaryCompatV2(operator, operand1, operand2, store, documentUri, copyManager)); } } @@ -388,7 +575,48 @@ private static void evaluateExpression(Operator operator, * @return * @throws InvalidSPDXAnalysisException */ - private static AnyLicenseInfo evaluateBinary(Operator tosOperator, + private static SimpleLicensingAnyLicenseInfo evaluateBinary(Operator tosOperator, + SimpleLicensingAnyLicenseInfo operand1, SimpleLicensingAnyLicenseInfo operand2, IModelStore store, + String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { + if (tosOperator == Operator.AND) { + if (operand1 instanceof ExpandedLicensingConjunctiveLicenseSet) { + // just merge into operand1 + ((ExpandedLicensingConjunctiveLicenseSet) operand1).getExpandedLicensingMembers().add(operand2); + return operand1; + } else { + ExpandedLicensingConjunctiveLicenseSet retval = new ExpandedLicensingConjunctiveLicenseSet(store, + store.getNextId(IdType.Anonymous), copyManager, true); + retval.getExpandedLicensingMembers().add(operand1); + retval.getExpandedLicensingMembers().add(operand2); + return retval; + } + } else if (tosOperator == Operator.OR) { + if (operand1 instanceof ExpandedLicensingDisjunctiveLicenseSet) { + // just merge into operand1 + ((ExpandedLicensingDisjunctiveLicenseSet) operand1).getExpandedLicensingMembers().add(operand2); + return operand1; + } else { + ExpandedLicensingDisjunctiveLicenseSet retval = new ExpandedLicensingDisjunctiveLicenseSet(store, + store.getNextId(IdType.Anonymous), copyManager, true); + retval.getExpandedLicensingMembers().add(operand1); + retval.getExpandedLicensingMembers().add(operand2); + return retval; + } + } else { + throw new LicenseParserException("Unknown operator "+tosOperator.toString()); + } + } + + /** + * Evaluates a binary expression and merges conjuctive and disjunctive licenses + * @param tosOperator + * @param operand1 + * @param operand2 + * @param copyManager + * @return + * @throws InvalidSPDXAnalysisException + */ + private static AnyLicenseInfo evaluateBinaryCompatV2(Operator tosOperator, AnyLicenseInfo operand1, AnyLicenseInfo operand2, IModelStore store, String documentUri, IModelCopyManager copyManager) throws InvalidSPDXAnalysisException { if (tosOperator == Operator.AND) { From 51f6eb6b47f32dcaf4bb0231e5edd3b1684dc74a Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Fri, 31 May 2024 16:56:18 -0700 Subject: [PATCH 34/62] Intermediate checkin - partial implementation license expression parser Signed-off-by: Gary O'Neall --- .../org/spdx/library/LicenseInfoFactory.java | 69 ++++- .../org/spdx/library/SpdxModelFactory.java | 2 +- .../utility/compare/LicenseCompareHelper.java | 57 ++-- .../spdx/utility/compare/SpdxComparer.java | 28 +- .../license/LicenseExpressionParser.java | 49 ++-- .../model/compat/v2/RelationshipTest.java | 4 +- .../v2/license/LicenseInfoFactoryTest.java | 14 +- .../v2/license/WithExceptionOperatorTest.java | 2 +- .../utility/compare/SpdxComparerTest.java | 16 +- .../utility/compare/SpdxFileComparerTest.java | 70 ++--- .../compare/SpdxSnippetComparerTest.java | 4 +- .../license/LicenseExpressionParserTest.java | 251 ++++++++++++++++++ .../LicenseExpressionParserTestV2.java} | 44 ++- 13 files changed, 477 insertions(+), 133 deletions(-) create mode 100644 src/test/java/org/spdx/utility/license/LicenseExpressionParserTest.java rename src/test/java/org/spdx/{library/model/compat/v2/license/LicenseExpressionParserTest.java => utility/license/LicenseExpressionParserTestV2.java} (87%) diff --git a/src/main/java/org/spdx/library/LicenseInfoFactory.java b/src/main/java/org/spdx/library/LicenseInfoFactory.java index 7af614737..27877556f 100644 --- a/src/main/java/org/spdx/library/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/LicenseInfoFactory.java @@ -36,6 +36,7 @@ import org.spdx.library.model.v2.license.SpdxListedLicense; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; +import org.spdx.library.model.v3.simplelicensing.SimpleLicensingAnyLicenseInfo; import org.spdx.storage.IModelStore; import org.spdx.utility.license.LicenseExpressionParser; @@ -90,7 +91,7 @@ public static SpdxListedLicense getListedLicenseV2ByIdCompat(String licenseId)th * @throws InvalidLicenseStringException * @throws DefaultStoreNotInitialized */ - public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, + public static AnyLicenseInfo parseSPDXLicenseStringV2(String licenseString, @Nullable IModelStore store, @Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws InvalidLicenseStringException, DefaultStoreNotInitialized { if (Objects.isNull(store)) { store = DefaultModelStore.getDefaultModelStore(); @@ -110,6 +111,49 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla throw new InvalidLicenseStringException("Unexpected SPDX error parsing license string"); } } + + /** + * Parses a license string and converts it into a SPDXLicenseInfo object + * Syntax - A license set must start and end with a parenthesis "(" + * A conjunctive license set will have and AND after the first + * licenseInfo term + * A disjunctive license set will have an OR after the first + * licenseInfo term + * If there is no And or Or, then it is converted to a simple + * license type + * A space or tab must be used between license ID's and the + * keywords AND and OR + * A licenseID must NOT be "AND" or "OR" + * @param licenseString String conforming to the syntax + * @param store Store containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model store will be used. + * @param documentUri Document URI for the document containing any extractedLicenseInfos - if any extractedLicenseInfos by ID already exist, they will be used. If + * none exist for an ID, they will be added. If null, the default model document URI will be used. + * @param copyManager if non-null, allows for copying of any properties set which use other model stores or document URI's + * @return an SPDXLicenseInfo created from the string + * @throws InvalidLicenseStringException + * @throws DefaultStoreNotInitialized + */ + public static SimpleLicensingAnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store, + @Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws InvalidLicenseStringException, DefaultStoreNotInitialized { + if (Objects.isNull(store)) { + store = DefaultModelStore.getDefaultModelStore(); + } + if (Objects.isNull(documentUri)) { + documentUri = DefaultModelStore.getDefaultDocumentUri(); + } + if (Objects.isNull(copyManager)) { + copyManager = DefaultModelStore.getDefaultCopyManager(); + } + try { + return LicenseExpressionParser.parseLicenseExpression(licenseString, store, documentUri, + copyManager); + } catch (LicenseParserException e) { + throw new InvalidLicenseStringException(e.getMessage(),e); + } catch (InvalidSPDXAnalysisException e) { + throw new InvalidLicenseStringException("Unexpected SPDX error parsing license string"); + } + } /** * Parses a license string and converts it into a SPDXLicenseInfo object @@ -128,9 +172,30 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla * @throws InvalidLicenseStringException * @throws DefaultStoreNotInitialized */ - public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitialized { + public static SimpleLicensingAnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitialized { return parseSPDXLicenseString(licenseString, null, null, null); } + + /** + * Parses a license string and converts it into a SPDXLicenseInfo object + * Syntax - A license set must start and end with a parenthesis "(" + * A conjunctive license set will have and AND after the first + * licenseInfo term + * A disjunctive license set will have an OR after the first + * licenseInfo term + * If there is no And or Or, then it is converted to a simple + * license type + * A space or tab must be used between license ID's and the + * keywords AND and OR + * A licenseID must NOT be "AND" or "OR" + * @param licenseString String conforming to the syntax + * @return an SPDXLicenseInfo created from the string + * @throws InvalidLicenseStringException + * @throws DefaultStoreNotInitialized + */ + public static AnyLicenseInfo parseSPDXLicenseV2String(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitialized { + return parseSPDXLicenseStringV2(licenseString, null, null, null); + } diff --git a/src/main/java/org/spdx/library/SpdxModelFactory.java b/src/main/java/org/spdx/library/SpdxModelFactory.java index 0ab18cc75..69d835f8f 100644 --- a/src/main/java/org/spdx/library/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/SpdxModelFactory.java @@ -238,7 +238,7 @@ public static Stream getSpdxObjects(IModelStore store, @Nullable IModelCopyMa */ public static SimpleLicensingAnyLicenseInfo getExternalAnyLicenseInfo( IModelStore store, String string, IModelCopyManager copyManager, - String latestSpecVersion) { + String specVersion) { // TODO Figure out how to implement // TODO Auto-generated method stub return null; diff --git a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java index bbd1ef977..f55b8b5a3 100644 --- a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java +++ b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java @@ -39,9 +39,11 @@ import org.slf4j.LoggerFactory; import org.spdx.core.InvalidSPDXAnalysisException; import org.spdx.library.ListedLicenses; +import org.spdx.library.model.v2.SpdxConstantsCompatV2; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingConjunctiveLicenseSet; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingCustomLicense; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingDisjunctiveLicenseSet; +import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingLicense; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicense; import org.spdx.library.model.v3.expandedlicensing.ExpandedLicensingListedLicenseException; import org.spdx.library.model.v3.simplelicensing.SimpleLicensingAnyLicenseInfo; @@ -144,6 +146,15 @@ public class LicenseCompareHelper { static final Pattern COPYRIGHT_SYMBOL_PATTERN = Pattern.compile("\\(c\\)", Pattern.CASE_INSENSITIVE); static final String START_COMMENT_CHAR_PATTERN = "(//|/\\*|\\*|#|' |REM |