Skip to content

Commit 2cf49ad

Browse files
committed
Fetch listed license/exceptions from listedLiceses
If the properties are not stored in the local document, fetch from the listed licenses. Fixes #32 Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
1 parent 86faccb commit 2cf49ad

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<dependency>
9292
<groupId>org.spdx</groupId>
9393
<artifactId>java-spdx-library</artifactId>
94-
<version>1.1.0</version>
94+
<version>1.1.1</version>
9595
</dependency>
9696
<dependency>
9797
<groupId>org.apache.jena</groupId>

src/main/java/org/spdx/spdxRdfStore/RdfSpdxDocumentModelManager.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,14 @@ public Optional<Object> getPropertyValue(String id, String propertyName) throws
665665
Property property = model.createProperty(SpdxResourceFactory.propertyNameToUri(propertyName));
666666
NodeIterator iter = model.listObjectsOfProperty(idResource, property);
667667
if (!iter.hasNext()) {
668-
return Optional.empty();
668+
if (isListedLicenseOrException(idResource)) {
669+
// If there is no locally stored property for a listed license or exception
670+
// fetch it from listed licenses store
671+
return ListedLicenses.getListedLicenses().getLicenseModelStore()
672+
.getValue(HTTPS_LISTED_LICENSE_NAMESPACE_PREFIX, id, propertyName);
673+
} else {
674+
return Optional.empty();
675+
}
669676
}
670677
Optional<Object> result = valueNodeToObject(iter.next(), property);
671678
if (iter.hasNext()) {
@@ -678,6 +685,24 @@ public Optional<Object> getPropertyValue(String id, String propertyName) throws
678685
}
679686
}
680687

688+
/**
689+
* @param idResource Resource for the ID
690+
* @return true if the type of the ID is a ListedLicenseException or a Listed License
691+
*/
692+
private boolean isListedLicenseOrException(Resource idResource) {
693+
Resource valueType = idResource.getPropertyResourceValue(RDF.type);
694+
if (Objects.isNull(valueType)) {
695+
return false;
696+
}
697+
Optional<String> sValueType = SpdxResourceFactory.resourceToSpdxType(valueType);
698+
if (sValueType.isEmpty()) {
699+
return false;
700+
}
701+
String sValueTypeStr = sValueType.get();
702+
return SpdxConstants.CLASS_SPDX_LISTED_LICENSE.equals(sValueTypeStr) ||
703+
SpdxConstants.CLASS_SPDX_LISTED_LICENSE_EXCEPTION.equals(sValueTypeStr);
704+
}
705+
681706
/**
682707
* Convert a node in the RDF graph to a Java object
683708
* @param propertyValue node containing the value

0 commit comments

Comments
 (0)