Skip to content

Commit e2cb4b9

Browse files
goneallbact
andauthored
Add support for storing properties of type Double (#274)
* Rename IdentifierType.Unkown to IdentifierType.Unknown * Add check for deprecated unkown ID type Required for compatibility in case the deprecated field is still in use * Rename DefaultStoreNotInitialized Exception * Add support for storing properties of type Double This update depends on new versions of the SPDX core library (1.0.0-RC2 or later) and the SPDX 3 Model (1.0.0-RC2 or later) Fixes #273 * Append '#' to document namespace when converting form 2 Fixes #275 * Update src/main/java/org/spdx/storage/simple/InMemSpdxStore.java Co-authored-by: Arthit Suriyawongkul <[email protected]> Signed-off-by: Gary O'Neall <[email protected]> * additional logging for licenses * Fix unit test failures --------- Signed-off-by: Gary O'Neall <[email protected]> Co-authored-by: Arthit Suriyawongkul <[email protected]>
1 parent 77f3f78 commit e2cb4b9

File tree

11 files changed

+32
-32
lines changed

11 files changed

+32
-32
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<dependency>
154154
<groupId>org.spdx</groupId>
155155
<artifactId>spdx-java-core</artifactId>
156-
<version>1.0.0-RC1</version>
156+
<version>1.0.0-RC2</version>
157157
</dependency>
158158
<dependency>
159159
<groupId>org.spdx</groupId>

src/main/java/org/spdx/library/LicenseInfoFactory.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828
import org.spdx.core.DefaultModelStore;
29-
import org.spdx.core.DefaultStoreNotInitialized;
29+
import org.spdx.core.DefaultStoreNotInitializedException;
3030
import org.spdx.core.IModelCopyManager;
3131
import org.spdx.core.InvalidSPDXAnalysisException;
3232
import org.spdx.library.model.v2.license.InvalidLicenseStringException;
@@ -92,10 +92,10 @@ public static SpdxListedLicense getListedLicenseByIdCompatV2(String licenseId)th
9292
* @param copyManager allows for copying of any properties set which use other model stores or document URI's. If null, the default will be used.
9393
* @return an SPDXLicenseInfo created from the string
9494
* @throws InvalidLicenseStringException if the license string is not valid
95-
* @throws DefaultStoreNotInitialized if the default model store is not initialized
95+
* @throws DefaultStoreNotInitializedException if the default model store is not initialized
9696
*/
9797
public static org.spdx.library.model.v2.license.AnyLicenseInfo parseSPDXLicenseStringCompatV2(String licenseString, @Nullable IModelStore store,
98-
@Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws InvalidLicenseStringException, DefaultStoreNotInitialized {
98+
@Nullable String documentUri, @Nullable IModelCopyManager copyManager) throws InvalidLicenseStringException, DefaultStoreNotInitializedException {
9999
if (Objects.isNull(store)) {
100100
store = DefaultModelStore.getDefaultModelStore();
101101
}
@@ -136,11 +136,11 @@ public static org.spdx.library.model.v2.license.AnyLicenseInfo parseSPDXLicenseS
136136
* @param customIdToUri Mapping of the id prefixes used in the license expression to the namespace preceding the external ID
137137
* @return an SPDXLicenseInfo created from the string
138138
* @throws InvalidLicenseStringException if the license string is not valid
139-
* @throws DefaultStoreNotInitialized if the default model store is not initialized
139+
* @throws DefaultStoreNotInitializedException if the default model store is not initialized
140140
*/
141141
public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nullable IModelStore store,
142142
@Nullable String customLicensePrefix, @Nullable IModelCopyManager copyManager,
143-
@Nullable List<DictionaryEntry> customIdToUri) throws InvalidLicenseStringException, DefaultStoreNotInitialized {
143+
@Nullable List<DictionaryEntry> customIdToUri) throws InvalidLicenseStringException, DefaultStoreNotInitializedException {
144144
if (Objects.isNull(store)) {
145145
store = DefaultModelStore.getDefaultModelStore();
146146
}
@@ -175,9 +175,9 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla
175175
* @param licenseString String conforming to the syntax
176176
* @return an SPDXLicenseInfo created from the string
177177
* @throws InvalidLicenseStringException if the license string is not valid
178-
* @throws DefaultStoreNotInitialized if the default model store is not initialized
178+
* @throws DefaultStoreNotInitializedException if the default model store is not initialized
179179
*/
180-
public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitialized {
180+
public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitializedException {
181181
return parseSPDXLicenseString(licenseString, null, null, null, null);
182182
}
183183

@@ -196,9 +196,9 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString) throws
196196
* @param licenseString String conforming to the syntax
197197
* @return an SPDXLicenseInfo created from the string
198198
* @throws InvalidLicenseStringException On invalid license expression
199-
* @throws DefaultStoreNotInitialized On the model store not being initialized - see DefaultModelStore in SPDX core package
199+
* @throws DefaultStoreNotInitializedException On the model store not being initialized - see DefaultModelStore in SPDX core package
200200
*/
201-
public static org.spdx.library.model.v2.license.AnyLicenseInfo parseSPDXLicenseStringCompatV2(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitialized {
201+
public static org.spdx.library.model.v2.license.AnyLicenseInfo parseSPDXLicenseStringCompatV2(String licenseString) throws InvalidLicenseStringException, DefaultStoreNotInitializedException {
202202
return parseSPDXLicenseStringCompatV2(licenseString, null, null, null);
203203
}
204204

src/main/java/org/spdx/library/ListedLicenses.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828
import org.spdx.core.InvalidSPDXAnalysisException;
29-
import org.spdx.core.SpdxIdNotFoundException;
3029
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
3130
import org.spdx.library.model.v2.SpdxModelFactoryCompatV2;
3231
import org.spdx.library.model.v2.license.SpdxListedLicense;
33-
import org.spdx.library.model.v2.license.SpdxListedLicenseException;
3432
import org.spdx.library.model.v3_0_1.core.CreationInfo;
3533
import org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicense;
3634
import org.spdx.library.model.v3_0_1.expandedlicensing.ListedLicenseException;

src/main/java/org/spdx/library/ModelCopyManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private void copyIndividualProperty(IModelStore toStore, String toObjectUri, IMo
351351
}
352352

353353
/**
354-
* Copies a property which is is a collection
354+
* Copies a property which is a collection
355355
* @param toStore Model Store to copy to
356356
* @param toObjectUri URI to copy to
357357
* @param fromStore Model Store containing the source item
@@ -460,7 +460,7 @@ private String sourceUriToObjectUri(String sourceUri, IdType idType, IModelStore
460460
case SpdxId: return toNamespace + toStore.getNextId(IdType.SpdxId);
461461
case ListedLicense: return sourceUri;
462462
case Anonymous:
463-
case Unkown:
463+
case Unknown:
464464
default: return toStore.getNextId(IdType.Anonymous);
465465
}
466466
}
@@ -476,8 +476,9 @@ private String sourceUriToObjectUri(String sourceUri, IdType idType, IModelStore
476476
*/
477477
private String sourceUriToObjectUriV2Compat(String sourceUri, IdType idType,
478478
IModelStore toStore, String toNamespace, boolean isExternalDocRef) throws InvalidSPDXAnalysisException {
479-
if ((isExternalDocRef || !(IdType.Anonymous.equals(idType) ||
480-
IdType.ListedLicense.equals(idType) || IdType.Unkown.equals(idType)))
479+
//noinspection deprecation
480+
if ((isExternalDocRef || !(IdType.Anonymous.equals(idType) || IdType.ListedLicense.equals(idType) ||
481+
IdType.Unknown.equals(idType) || IdType.Unkown.equals(idType)))
481482
&& (Objects.isNull(toNamespace) || toNamespace.isEmpty())) {
482483
throw new InvalidSPDXAnalysisException("A to namespace or document URI must be provided to copy SPDX element for SPDX spec version 2");
483484
}
@@ -510,7 +511,7 @@ private String sourceUriToObjectUriV2Compat(String sourceUri, IdType idType,
510511
toNamespace + toStore.getNextId(IdType.SpdxId);
511512
case ListedLicense: return sourceUri;
512513
case Anonymous:
513-
case Unkown:
514+
case Unknown:
514515
default: return toStore.getNextId(IdType.Anonymous);
515516
}
516517
}

src/main/java/org/spdx/library/conversion/Spdx2to3Converter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ public NamespaceMap convertAndStore(org.spdx.library.model.v2.ExternalDocumentRe
726726
NamespaceMap toNamespaceMap = (NamespaceMap)SpdxModelClassFactoryV3.getModelObject(toModelStore,
727727
toObjectUri, SpdxConstantsV3.CORE_NAMESPACE_MAP, copyManager, true, defaultUriPrefix);
728728
toNamespaceMap.setPrefix(externalDocRef.getId());
729-
toNamespaceMap.setNamespace(externalDocRef.getSpdxDocumentNamespace());
729+
toNamespaceMap.setNamespace(externalDocRef.getSpdxDocumentNamespace() + "#");
730730
return toNamespaceMap;
731731
}
732732

src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ private void loadIds() throws InvalidSPDXAnalysisException {
180180
ExceptionJsonTOC exceptionToc = gson.fromJson(tocJsonStr.toString(), ExceptionJsonTOC.class);
181181
exceptionIds = exceptionToc.getExceptionIds();
182182
} catch (MalformedURLException e) {
183+
logger.error("License TOC URL invalid", e);
183184
throw new SpdxListedLicenseException("License TOC URL invalid", e) ;
184185
} catch (IOException e) {
186+
logger.error("I/O error reading license TOC", e);
185187
throw new SpdxListedLicenseException("I/O error reading license TOC", e);
186188
} finally {
187189
if (reader != null) {
@@ -1196,7 +1198,7 @@ public IdType getIdType(String objectUri) {
11961198
} else if (objectUri.startsWith(LicenseCreatorAgent.OBJECT_URI_PREFIX)) {
11971199
return IdType.SpdxId;
11981200
} else {
1199-
return IdType.Unkown;
1201+
return IdType.Unknown;
12001202
}
12011203
}
12021204

src/main/java/org/spdx/storage/simple/InMemSpdxStore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public IdType getIdType(String objectUri) {
393393
if (objectUri.contains("://spdx.org/licenses/") || LicenseInfoFactory.isSpdxListedLicenseId(objectUri) || LicenseInfoFactory.isSpdxListedExceptionId(objectUri)) {
394394
return IdType.ListedLicense;
395395
} else {
396-
return IdType.Unkown;
396+
return IdType.Unknown;
397397
}
398398
}
399399

@@ -414,10 +414,10 @@ public void leaveCriticalSection(IModelStoreLock lock) {
414414
}
415415

416416
@Override
417-
public Optional<String> getCaseSensisitiveId(String nameSpace, String caseInsensisitiveId) {
417+
public Optional<String> getCaseSensitiveId(String nameSpace, String caseInsensitiveId) {
418418
Objects.requireNonNull(nameSpace, "Namespace can not be null");
419-
Objects.requireNonNull(caseInsensisitiveId, "CaseInsensisitiveId can not be null");
420-
String objectUri = nameSpace + "#" + caseInsensisitiveId;
419+
Objects.requireNonNull(caseInsensitiveId, "CaseInsensitiveId can not be null");
420+
String objectUri = nameSpace + "#" + caseInsensitiveId;
421421
StoredTypedItem item = typedValueMap.get(objectUri.toLowerCase());
422422
if (Objects.isNull(item)) {
423423
return Optional.empty();

src/main/java/org/spdx/storage/simple/StoredTypedItem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public void setValue(PropertyDescriptor propertyDescriptor, Object value) throws
137137
!String.class.isAssignableFrom(value.getClass()) &&
138138
!Boolean.class.isAssignableFrom(value.getClass()) &&
139139
!Integer.class.isAssignableFrom(value.getClass()) &&
140+
!Double.class.isAssignableFrom(value.getClass()) &&
141+
!Float.class.isAssignableFrom((value.getClass())) &&
140142
!TypedValue.class.isAssignableFrom(value.getClass()) &&
141143
!(value instanceof IndividualUriValue)) {
142144
throw new SpdxInvalidTypeException(value.getClass() +" is not a supported class to be stored.");

src/test/java/org/spdx/library/LicenseInfoFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222

2323
import org.spdx.core.DefaultModelStore;
24-
import org.spdx.core.DefaultStoreNotInitialized;
24+
import org.spdx.core.DefaultStoreNotInitializedException;
2525
import org.spdx.core.InvalidSPDXAnalysisException;
2626
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
2727
import org.spdx.library.model.v2.license.InvalidLicenseStringException;
@@ -133,7 +133,7 @@ protected void tearDown() throws Exception {
133133
DefaultModelStore.initialize(new InMemSpdxStore(), "https://default/prefix", new ModelCopyManager());
134134
}
135135

136-
public void testParseSPDXLicenseString() throws InvalidLicenseStringException, DefaultStoreNotInitialized {
136+
public void testParseSPDXLicenseString() throws InvalidLicenseStringException, DefaultStoreNotInitializedException {
137137
String parseString = COMPLEX_LICENSE.toString();
138138
AnyLicenseInfo li = LicenseInfoFactory.parseSPDXLicenseString(parseString);
139139
if (!li.equals(COMPLEX_LICENSE)) {

src/test/java/org/spdx/library/LicenseInfoFactoryTestV2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222

2323
import org.spdx.core.DefaultModelStore;
24-
import org.spdx.core.DefaultStoreNotInitialized;
24+
import org.spdx.core.DefaultStoreNotInitializedException;
2525
import org.spdx.core.InvalidSPDXAnalysisException;
2626
import org.spdx.library.model.v2.GenericModelObject;
2727
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
@@ -117,7 +117,7 @@ protected void tearDown() throws Exception {
117117
DefaultModelStore.initialize(new InMemSpdxStore(), "https://default/prefix", new ModelCopyManager());
118118
}
119119

120-
public void testParseSPDXLicenseString() throws InvalidLicenseStringException, DefaultStoreNotInitialized {
120+
public void testParseSPDXLicenseString() throws InvalidLicenseStringException, DefaultStoreNotInitializedException {
121121
String parseString = COMPLEX_LICENSE.toString();
122122
AnyLicenseInfo li = LicenseInfoFactory.parseSPDXLicenseStringCompatV2(parseString);
123123
if (!li.equals(COMPLEX_LICENSE)) {

0 commit comments

Comments
 (0)