Skip to content

Commit

Permalink
Update sprint-i18n with master branch (#166)
Browse files Browse the repository at this point in the history
* Make data property richtext editor option selectable from UI

* [VIVO-1755] - Better error handling when reasoner disabled (#137)

* Better error handling when reasoner disabled

* Change reasoner error log message to debug

* Extend reasoner status error handling

* Improve reasoner error log message and extend to JenaAdminActions

* Bump up log level for admin action to 'warn' and edit admin panel error message

* Change Model writer lang from "N3-PP" to "N3" (#149)

Resolves: https://jira.lyrasis.org/browse/VIVO-1761

Co-authored-by: Andrew Woods <awoods@duraspace.org>

* [VIVO-1851] - Add 'remove' option to named graph management page (#162)

* Add 'remove' option to named graph management page

Resolves: https://jira.lyrasis.org/browse/VIVO-1851

* [VIVO-1872] - Add download option to SPARQL Query page (#164)

* Add download option to SPARQL Query page

* Set SPARQL query results content type even if downloading

* Address pull request comments

Co-authored-by: gneissone <mbgross@wustl.edu>
Co-authored-by: Ralph O'Flinn <roflinn@users.noreply.github.com>
Co-authored-by: Andrew Woods <awoods@duraspace.org>
  • Loading branch information
4 people committed Jun 19, 2020
1 parent 9c0050c commit 52f2d53
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import edu.cornell.mannlib.vitro.webapp.utils.http.AcceptHeaderParsingException;
import edu.cornell.mannlib.vitro.webapp.utils.http.NotAcceptableException;
import edu.cornell.mannlib.vitro.webapp.utils.sparql.SparqlQueryUtils;
import edu.cornell.mannlib.vitro.webapp.controller.api.sparqlquery.RdfResultMediaType;
import edu.cornell.mannlib.vitro.webapp.controller.api.sparqlquery.ResultSetMediaType;

/**
* Present the SPARQL Query form, and execute the queries.
Expand Down Expand Up @@ -110,11 +112,20 @@ private void respondToQuery(HttpServletRequest req, HttpServletResponse resp)
.getRDFService();

String queryString = req.getParameter("query");
boolean download = Boolean.parseBoolean(req.getParameter("download"));
Query query = SparqlQueryUtils.create(queryString);
try {
String format = interpretRequestedFormats(req, queryString);
String format = interpretRequestedFormats(req, query);
SparqlQueryApiExecutor core = SparqlQueryApiExecutor.instance(
rdfService, queryString, format);
resp.setContentType(core.getMediaType());

if (download) {
String extension = getFilenameExtension(req, query, format);
resp.setHeader("Content-Transfer-Encoding", "binary");
resp.setHeader("Content-disposition", "attachment; filename=query-results." + extension);
}

core.executeAndFormat(resp.getOutputStream());
} catch (InvalidQueryTypeException e) {
do400BadRequest("Query type is not SELECT, ASK, CONSTRUCT, "
Expand All @@ -132,8 +143,7 @@ private void respondToQuery(HttpServletRequest req, HttpServletResponse resp)
}

private String interpretRequestedFormats(HttpServletRequest req,
String queryString) throws NotAcceptableException {
Query query = SparqlQueryUtils.create(queryString);
Query query) throws NotAcceptableException {
String parameterName = (query.isSelectType() || query.isAskType()) ? "resultFormat"
: "rdfResultFormat";
String parameterValue = req.getParameter(parameterName);
Expand All @@ -145,6 +155,20 @@ private String interpretRequestedFormats(HttpServletRequest req,
}
}

private String getFilenameExtension(HttpServletRequest req,
Query query, String format) {
String extension;
if (query.isSelectType() || query.isAskType()) {
ResultSetMediaType mediaType = ResultSetMediaType.fromContentType(format);
extension = mediaType.getExtension();
}
else {
RdfResultMediaType mediaType = RdfResultMediaType.fromContentType(format);
extension = mediaType.getExtension();
}
return extension;
}

private void do400BadRequest(String message, HttpServletResponse resp)
throws IOException {
resp.setStatus(400);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
* and DESCRIBE).
*/
public enum RdfResultMediaType {
TEXT("text/plain", true, "NTRIPLE", "N-TRIPLE"),
TEXT("text/plain", true, "NTRIPLE", "N-TRIPLE", "nt"),

RDF_XML("application/rdf+xml", true, "RDFXML", "RDF/XML"),
RDF_XML("application/rdf+xml", true, "RDFXML", "RDF/XML", "rdf"),

N3("text/n3", true, "N3", "N3"),
N3("text/n3", true, "N3", "N3", "n3"),

TTL("text/turtle", false, "N3", "TTL"),
TTL("text/turtle", false, "N3", "TTL", "ttl"),

JSON("application/json", false, "N3", "JSON"),
JSON("application/json", false, "N3", "JSON", "json"),

JSON_LD("application/ld+json", false, "N3", "JSON");
JSON_LD("application/ld+json", false, "N3", "JSON", "jsonld");

// ----------------------------------------------------------------------
// Keep a map of content types, for easy conversion back and forth
Expand Down Expand Up @@ -79,12 +79,18 @@ public static RdfResultMediaType fromContentType(String contentType)
*/
private final String jenaResponseFormat;

/**
* What extension should be used if file is downloaded?
*/
private final String extension;

private RdfResultMediaType(String contentType, boolean nativeFormat,
String serializationFormat, String jenaResponseFormat) {
String serializationFormat, String jenaResponseFormat, String extension) {
this.contentType = contentType;
this.nativeFormat = nativeFormat;
this.serializationFormat = serializationFormat;
this.jenaResponseFormat = jenaResponseFormat;
this.extension = extension;
}

public String getContentType() {
Expand All @@ -103,4 +109,8 @@ public String getJenaResponseFormat() {
return jenaResponseFormat;
}

public String getExtension() {
return extension;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* SELECT and ASK).
*/
public enum ResultSetMediaType {
TEXT("text/plain", true, "TEXT", null),
TEXT("text/plain", true, "TEXT", null, "txt"),

CSV("text/csv", true, "CSV", null),
CSV("text/csv", true, "CSV", null, "csv"),

TSV("text/tab-separated-values", false, "CSV", "tsv"),
TSV("text/tab-separated-values", false, "CSV", "tsv", "tsv"),

XML("application/sparql-results+xml", true, "XML", null),
XML("application/sparql-results+xml", true, "XML", null, "xml"),

JSON("application/sparql-results+json", true, "JSON", null);
JSON("application/sparql-results+json", true, "JSON", null, "json");

// ----------------------------------------------------------------------
// Keep a map of content types, for easy conversion back and forth
Expand Down Expand Up @@ -78,12 +78,18 @@ public static ResultSetMediaType fromContentType(String contentType)
*/
private final String jenaResponseFormat;

/**
* What extension should be used if file is downloaded?
*/
private final String extension;

private ResultSetMediaType(String contentType, boolean nativeFormat,
String rdfServiceFormat, String jenaResponseFormat) {
String rdfServiceFormat, String jenaResponseFormat, String extension) {
this.contentType = contentType;
this.nativeFormat = nativeFormat;
this.rdfServiceFormat = rdfServiceFormat;
this.jenaResponseFormat = jenaResponseFormat;
this.extension = extension;
}

public String getContentType() {
Expand All @@ -102,4 +108,8 @@ public String getJenaResponseFormat() {
return jenaResponseFormat;
}

public String getExtension() {
return extension;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void doPost (HttpServletRequest request, HttpServletResponse response) {

VitroRequest vreq = new VitroRequest(request);

final int NUM_COLS=18;
final int NUM_COLS=19;

String datapropURI = request.getParameter("uri");

Expand Down Expand Up @@ -73,8 +73,9 @@ public void doPost (HttpServletRequest request, HttpServletResponse response) {
results.add("display tier"); // column 14
results.add("display limit"); // column 15
results.add("custom entry form"); // column 16
results.add("URI"); // column 17
results.add("publish level"); // column 18
results.add("editing"); // column 17
results.add("URI"); // column 18
results.add("publish level"); // column 19

results.add(dp.getPickListName()); // column 1
results.add(dp.getPublicName() == null ? "(no public label)" : dp.getPublicName()); // column 2
Expand Down Expand Up @@ -142,9 +143,10 @@ public void doPost (HttpServletRequest request, HttpServletResponse response) {
results.add(String.valueOf(dp.getDisplayTier())); // column 14
results.add(String.valueOf(dp.getDisplayLimit())); // column 15
results.add(dp.getCustomEntryForm() == null ? "(unspecified)" : dp.getCustomEntryForm()); // column 16
results.add(dp.getURI() == null ? "" : dp.getURI()); // column 17
results.add(dp.getEditing() == null ? "" : dp.getEditing()); // column 17
results.add(dp.getURI() == null ? "" : dp.getURI()); // column 18
results.add(dp.getHiddenFromPublishBelowRoleLevel() == null ? "(unspecified)"
: dp.getHiddenFromPublishBelowRoleLevel().getDisplayLabel()); // column 18
: dp.getHiddenFromPublishBelowRoleLevel().getDisplayLabel()); // column 19
request.setAttribute("results",results);
request.setAttribute("columncount",NUM_COLS);
request.setAttribute("suppressquery","true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,26 @@ public void doPost (HttpServletRequest request, HttpServletResponse response) {
optionMap.put("ProhibitedFromUpdateBelowRoleLevelUsingRoleUri",RoleLevelOptionsSetup.getUpdateOptionsList(objectForEditing));
optionMap.put("HiddenFromPublishBelowRoleLevelUsingRoleUri",RoleLevelOptionsSetup.getPublishOptionsList(objectForEditing));

// Set the value of the editing parameter (as defined in VitroVocabulary.java).
// Use value to control form types as in defaultDataPropertyForm.ftl
String editingVal = objectForEditing.getEditing();
List<Option> editingOptList = new ArrayList<Option>();
editingOptList.add(0,new Option("","plaintext"));
editingOptList.add(1,new Option("HTML","rich text"));
for (Option val : editingOptList) {
if(editingVal != null && editingVal.equals(val.getValue())) {
val.setSelected(true);
}
}
optionMap.put("Editing", editingOptList);

foo.setOptionLists(optionMap);

request.setAttribute("functional",objectForEditing.getFunctional());

//checkboxes are pretty annoying : we don't know if someone *unchecked* a box, so we have to default to false on updates.
if (objectForEditing.getURI() != null) {
objectForEditing.setFunctional(false);
objectForEditing.setFunctional(false);
}

foo.setErrorMap(epo.getErrMsgMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,17 @@ protected Map<String, Object> getOntologyEditorData(VitroRequest vreq) {

String error = null;
String explanation = null;
TBoxReasonerStatus status = ApplicationUtils.instance().getTBoxReasonerModule().getStatus();
if (!status.isConsistent()) {
error = "INCONSISTENT ONTOLOGY: reasoning halted.";
explanation = status.getExplanation();
} else if ( status.isInErrorState() ) {
error = "An error occurred during reasoning. Reasoning has been halted. See error log for details.";
try {
TBoxReasonerStatus status = ApplicationUtils.instance().getTBoxReasonerModule().getStatus();
if (!status.isConsistent()) {
error = "INCONSISTENT ONTOLOGY: reasoning halted.";
explanation = status.getExplanation();
} else if ( status.isInErrorState() ) {
error = "An error occurred during reasoning. Reasoning has been halted. See error log for details.";
}
} catch (IllegalStateException e) {
error = "The inferencing engine is disabled. Data entered manually may exhibit unexpected behavior prior to inferencing.";
log.debug("Status of reasoner could not be determined. It is likely disabled.", e);
}

if (error != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,29 +192,33 @@ private String testWriteXML() {
}

private void printRestrictions() {
TBoxReasonerModule reasoner = ApplicationUtils.instance().getTBoxReasonerModule();
for (Restriction rest : reasoner.listRestrictions() ) {
if (rest.isAllValuesFromRestriction()) {
log.trace("All values from: ");
AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction();
Resource res = avfr.getAllValuesFrom();
if (res.canAs(OntClass.class)) {
OntClass resClass = res.as(OntClass.class);
for (Resource inst : resClass.listInstances().toList() ) {
log.trace(" -"+inst.getURI());
}
}
} else if (rest.isSomeValuesFromRestriction()) {
log.trace("Some values from: ");
} else if (rest.isHasValueRestriction()) {
log.trace("Has value: ");
}
log.trace("On property "+rest.getOnProperty().getURI());
for (Resource inst : rest.listInstances().toList() ) {
log.trace(" "+inst.getURI());
}

}
try {
TBoxReasonerModule reasoner = ApplicationUtils.instance().getTBoxReasonerModule();
for (Restriction rest : reasoner.listRestrictions() ) {
if (rest.isAllValuesFromRestriction()) {
log.trace("All values from: ");
AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction();
Resource res = avfr.getAllValuesFrom();
if (res.canAs(OntClass.class)) {
OntClass resClass = res.as(OntClass.class);
for (Resource inst : resClass.listInstances().toList() ) {
log.trace(" -"+inst.getURI());
}
}
} else if (rest.isSomeValuesFromRestriction()) {
log.trace("Some values from: ");
} else if (rest.isHasValueRestriction()) {
log.trace("Has value: ");
}
log.trace("On property "+rest.getOnProperty().getURI());
for (Resource inst : rest.listInstances().toList() ) {
log.trace(" "+inst.getURI());
}
}
}
catch (IllegalStateException e) {
log.warn("Status of reasoner could not be determined. It is likely disabled", e);
}
}

private void removeLongLiterals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ public void loadRDF(VitroRequest request, HttpServletResponse response)
String modelName = request.getParameter("modelName");
String docLoc = request.getParameter("docLoc");
String languageStr = request.getParameter("language");
boolean remove = "remove".equals(request.getParameter("mode"));
ModelMaker maker = getModelMaker(request);

String bodyJsp;
Expand All @@ -279,7 +280,7 @@ public void loadRDF(VitroRequest request, HttpServletResponse response)
} else {
RDFService rdfService = getRDFService(request, maker, modelName);
try {
doLoadRDFData(modelName, docLoc, filePath, languageStr, rdfService);
doLoadRDFData(modelName, docLoc, filePath, languageStr, rdfService, remove);
} finally {
rdfService.close();
}
Expand Down Expand Up @@ -378,12 +379,19 @@ private void doLoadRDFData(String modelName,
String docLoc,
String filePath,
String language,
RDFService rdfService) {
RDFService rdfService,
boolean remove) {
try {
if ( (docLoc != null) && (docLoc.length()>0) ) {
URL docLocURL = new URL(docLoc);
InputStream in = docLocURL.openStream();
readIntoModel(in, language, rdfService, modelName);
if(!remove) {
readIntoModel(in, language, rdfService,
modelName);
} else {
removeFromModel(in, language, rdfService,
modelName);
}
} else if ( (filePath != null) && (filePath.length()>0) ) {
File file = new File(filePath);
File[] files;
Expand All @@ -396,8 +404,13 @@ private void doLoadRDFData(String modelName,
for (File currentFile : files) {
log.debug("Reading file " + currentFile.getName());
try {
readIntoModel(fileStream.getInputStream(), language,
rdfService, modelName);
if(!remove) {
readIntoModel(fileStream.getInputStream(), language, rdfService,
modelName);
} else {
removeFromModel(fileStream.getInputStream(), language, rdfService,
modelName);
}
fileStream.delete();
} catch (IOException ioe) {
String errMsg = "Error loading RDF from " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,13 @@ private List<DataProperty> filterAndConvertToDataProperties(
}

protected boolean reasoningAvailable() {
TBoxReasonerStatus status = ApplicationUtils.instance().getTBoxReasonerModule().getStatus();
return status.isConsistent() && !status.isInErrorState();
try {
TBoxReasonerStatus status = ApplicationUtils.instance().getTBoxReasonerModule().getStatus();
return status.isConsistent() && !status.isInErrorState();
} catch (IllegalStateException e) {
log.debug("Status of reasoner could not be determined. It is likely disabled.", e);
return false;
}
}

private String getRequiredDatatypeURI(Individual individual, DataProperty dataprop, List<String> vclassURIs) {
Expand Down Expand Up @@ -514,6 +519,7 @@ public String insertDataProperty(DataProperty dtp, OntModel ontModel) throws Ins
addPropertyStringValue(jDataprop, EXAMPLE, dtp.getExample(), ontModel);
addPropertyStringValue(jDataprop, DESCRIPTION_ANNOT, dtp.getDescription(), ontModel);
addPropertyStringValue(jDataprop, PUBLIC_DESCRIPTION_ANNOT, dtp.getPublicDescription(), ontModel);
addPropertyStringValue(jDataprop, EDITING, dtp.getEditing(), ontModel);
addPropertyNonNegativeIntValue(jDataprop, DISPLAY_RANK_ANNOT, dtp.getDisplayTier(), ontModel);
addPropertyNonNegativeIntValue(jDataprop, DISPLAY_LIMIT, dtp.getDisplayLimit(), ontModel);
//addPropertyStringValue(jDataprop, HIDDEN_ANNOT, dtp.getHidden(), ontModel);
Expand Down Expand Up @@ -584,6 +590,7 @@ public void updateDataProperty(DataProperty dtp, OntModel ontModel) {
updatePropertyStringValue(jDataprop, EXAMPLE, dtp.getExample(), ontModel);
updatePropertyStringValue(jDataprop, DESCRIPTION_ANNOT, dtp.getDescription(), ontModel);
updatePropertyStringValue(jDataprop, PUBLIC_DESCRIPTION_ANNOT, dtp.getPublicDescription(), ontModel);
updatePropertyStringValue(jDataprop, EDITING, dtp.getEditing(), ontModel);
updatePropertyNonNegativeIntValue(jDataprop, DISPLAY_RANK_ANNOT, dtp.getDisplayTier(), ontModel);
updatePropertyNonNegativeIntValue(jDataprop, DISPLAY_LIMIT, dtp.getDisplayLimit(), ontModel);

Expand Down
Loading

0 comments on commit 52f2d53

Please sign in to comment.