Skip to content

Commit

Permalink
Fix: check if the literals are null
Browse files Browse the repository at this point in the history
Avoid the null exception and catch the UnsupportedEncodingException
Related #23
  • Loading branch information
mosoriob committed Jun 18, 2019
1 parent 0aa14c3 commit ce9576f
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/main/java/edu/isi/wings/opmm/WorkflowTemplateExport.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.isi.wings.opmm;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
import org.apache.jena.datatypes.xsd.XSDDatatype;
Expand Down Expand Up @@ -169,33 +170,34 @@ private String convertTemplateToOPMW(Individual wingsTemplate, int versionNumber
if(rs.hasNext()){
//variables to extract: ?doc ?contrib ?time ?license
QuerySolution qs = rs.next();
try{
Literal docContent = qs.getLiteral("?doc");
Literal docContent = qs.getLiteral("?doc");
if (docContent != null)
wtInstance.addLiteral(opmwModel.createProperty(Constants.OPMW_DATA_PROP_HAS_DOCUMENTATION), docContent);
}catch(Exception e){}
try{
Literal contrib = qs.getLiteral("?contrib");
Literal contrib = qs.getLiteral("?contrib");
if (contrib != null){
OntClass agentClass = opmwModel.createClass(Constants.OPM_AGENT);
Individual contributor = agentClass.createIndividual(Constants.PREFIX_EXPORT_RESOURCE+
Constants.CONCEPT_AGENT+"/"+URLEncoder.encode(""+contrib, "UTF-8"));
contributor.addLabel(contrib);
wtInstance.addProperty(opmwModel.createProperty(Constants.PROP_HAS_CONTRIBUTOR), contributor);
}catch(Exception e){}
try{
Literal timeLastModified = qs.getLiteral("?time");
try {
Individual contributor = agentClass.createIndividual(Constants.PREFIX_EXPORT_RESOURCE+
Constants.CONCEPT_AGENT+"/"+ URLEncoder.encode(""+contrib, "UTF-8"));
contributor.addLabel(contrib);
wtInstance.addProperty(opmwModel.createProperty(Constants.PROP_HAS_CONTRIBUTOR), contributor);
} catch (UnsupportedEncodingException e) {
System.err.println("Unsupported encoding");
e.printStackTrace();
}
}
Literal timeLastModified = qs.getLiteral("?time");
if (timeLastModified != null)
wtInstance.addLiteral(opmwModel.createProperty(Constants.DATA_PROP_MODIFIED), timeLastModified);
}catch(Exception e){}
try{
Literal userVersion = qs.getLiteral("?version");
Literal userVersion = qs.getLiteral("?version");
if (userVersion != null)
wtInstance.addLiteral(opmwModel.createProperty(Constants.OPMW_DATA_PROP_RELEASE_VERSION), userVersion);
}catch(Exception e){}
try{
Literal license = qs.getLiteral("?license");
Literal license = qs.getLiteral("?license");
if (license != null)
wtInstance.addLiteral(opmwModel.createProperty(Constants.DATA_PROP_RIGHTS), license);
}catch(Exception e){//no license declared, add license by default
opmwModel.add(wtInstance,opmwModel.createProperty(Constants.DC_LICENSE),"http://creativecommons.org/licenses/by/3.0/",
else
opmwModel.add(wtInstance, opmwModel.createProperty(Constants.DC_LICENSE), "http://creativecommons.org/licenses/by/3.0/",
XSDDatatype.XSDanyURI);
}
}
//if there is any derivation, this template is a concrete template. Publish the abstract template
String queryDerivation = QueriesWorkflowTemplateExport.queryWINGSDerivations();
Expand Down

0 comments on commit ce9576f

Please sign in to comment.