Skip to content

Commit 7e25a61

Browse files
authored
Merge pull request #34 from spdx/issue32-2
Fetch listed license/exceptions from listedLiceses
2 parents 4cd148a + 0b53369 commit 7e25a61

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

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) && !this.exists(id)) {
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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ public List<String> getClassUriRestrictions(String classUri, String propertyUri)
219219
if (classUri.endsWith("GenericSpdxElement")) {
220220
ontClass = model.getOntClass(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.CLASS_SPDX_ELEMENT);
221221
} else {
222-
logger.error(classUri + " is not an SPDX class");
222+
logger.warn(classUri + " is not an SPDX class");
223223
throw new SpdxRdfException(classUri + " is not an SPDX class");
224224
}
225225
}
226226
OntProperty property = model.getOntProperty(checkGetOwlUriFromRenamed(propertyUri));
227227
if (Objects.isNull(property)) {
228-
logger.error(propertyUri + " is not an SPDX property");
228+
logger.warn(propertyUri + " is not an SPDX property");
229229
throw new MissingDataTypeAndClassRestriction(propertyUri + " is not an SPDX property");
230230
}
231231
List<Statement> propertyRestrictions = new ArrayList<Statement>();
@@ -253,13 +253,13 @@ public List<String> getDataUriRestrictions(String classUri, String propertyUri)
253253
if (classUri.endsWith("GenericSpdxElement")) {
254254
ontClass = model.getOntClass(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.CLASS_SPDX_ELEMENT);
255255
} else {
256-
logger.error(classUri + " is not an SPDX class");
256+
logger.warn(classUri + " is not an SPDX class");
257257
throw new SpdxRdfException(classUri + " is not an SPDX class");
258258
}
259259
}
260260
OntProperty property = model.getOntProperty(checkGetOwlUriFromRenamed(propertyUri));
261261
if (Objects.isNull(property)) {
262-
logger.error(propertyUri + " is not an SPDX property");
262+
logger.warn(propertyUri + " is not an SPDX property");
263263
throw new SpdxRdfException(propertyUri + " is not an SPDX property");
264264
}
265265
List<Statement> propertyRestrictions = new ArrayList<Statement>();
@@ -287,13 +287,13 @@ public boolean isList(String classUri, String propertyUri) throws SpdxRdfExcepti
287287
if (classUri.endsWith("GenericSpdxElement")) {
288288
ontClass = model.getOntClass(SpdxConstants.SPDX_NAMESPACE + SpdxConstants.CLASS_SPDX_ELEMENT);
289289
} else {
290-
logger.error(classUri + " is not an SPDX class");
290+
logger.warn(classUri + " is not an SPDX class");
291291
throw new SpdxRdfException(classUri + " is not an SPDX class");
292292
}
293293
}
294294
OntProperty property = model.getOntProperty(checkGetOwlUriFromRenamed(propertyUri));
295295
if (Objects.isNull(property)) {
296-
logger.error(propertyUri + " is not an SPDX property");
296+
logger.warn(propertyUri + " is not an SPDX property");
297297
throw new SpdxRdfException(propertyUri + " is not an SPDX property");
298298
}
299299
List<Statement> propertyRestrictions = new ArrayList<Statement>();

src/test/java/org/spdx/library/model/license/SpdxListedLicenseTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.ByteArrayInputStream;
2121
import java.io.ByteArrayOutputStream;
2222
import java.io.IOException;
23-
import java.io.StringWriter;
2423
import java.nio.charset.StandardCharsets;
2524
import java.util.ArrayList;
2625
import java.util.Arrays;

0 commit comments

Comments
 (0)