Skip to content

Commit

Permalink
Merge pull request #273 from spdx/issue272
Browse files Browse the repository at this point in the history
Add license ID property when reading listed licenses
  • Loading branch information
goneall authored Mar 22, 2021
2 parents abb67ee + 6351890 commit d5c23fd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/org/spdx/rdfparser/license/ListedLicenses.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.Triple;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.util.FileManager;
import org.apache.jena.util.iterator.ExtendedIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.rdfparser.IModelContainer;
Expand Down Expand Up @@ -332,6 +334,17 @@ private Model getLicenseModel(String uri, String base) throws NoListedLicenseRdf
try {
retval.read(in, base, "JSON-LD");
Property p = retval.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_ID);
if (!retval.contains(null, p)) {
Property typeProperty = retval.getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
Resource licenseType = retval.getResource(SpdxRdfConstants.SPDX_NAMESPACE + "ListedLicense");
Triple m = Triple.createMatch(null, typeProperty.asNode(), licenseType.asNode());
ExtendedIterator<Triple> tripleIter = retval.getGraph().find(m);
if (tripleIter.hasNext()) {
Resource licenseIdResource = retval.createResource(tripleIter.next().getSubject().getURI());
String id = licenseIdResource.getURI().substring("http://spdx.org/licenses/".length());
((Resource)licenseIdResource).addProperty(p, id);
}
}
if (retval.isEmpty() || !retval.contains(null, p)) {
try {
in.close();
Expand Down

0 comments on commit d5c23fd

Please sign in to comment.