From 88129af70e31ba5057457d49682f2ffe8407286b Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Wed, 25 Mar 2020 15:40:32 -0400 Subject: [PATCH 01/52] Layer uqam updates onto master (minus trailing whitespace) --- .../freemarker/BrowseController.java | 35 ++ .../freemarker/FreemarkerHttpServlet.java | 16 +- .../freemarker/HomePageController.java | 1 + .../freemarker/TemplateProcessingHelper.java | 8 + .../GetRandomSearchIndividualsByVClass.java | 5 +- .../vitro/webapp/dao/jena/JenaBaseDao.java | 9 + .../webapp/dao/jena/RDFServiceGraph.java | 11 +- .../vitro/webapp/dao/jena/SparqlGraph.java | 16 +- .../VTwo/AdditionsAndRetractions.java | 5 +- .../n3editing/VTwo/BaseEditElementVTwo.java | 8 +- .../VTwo/EditConfigurationUtils.java | 34 +- .../n3editing/VTwo/EditN3GeneratorVTwo.java | 2 + .../VTwo/MultiValueEditSubmission.java | 79 +++- .../edit/n3editing/VTwo/ProcessRdfForm.java | 142 ++++++- .../VTwo/fields/ChildVClassesWithParent.java | 52 ++- .../VTwo/fields/SelectListGeneratorVTwo.java | 162 ++++--- .../DefaultObjectPropertyFormGenerator.java | 9 +- .../EditRequestDispatchController.java | 40 +- .../controller/PostEditCleanupController.java | 8 +- .../controller/ProcessRdfFormController.java | 5 +- .../webapp/filters/PageRoutingFilter.java | 5 + .../config/FreemarkerConfiguration.java | 9 + .../vitro/webapp/rdfservice/RDFService.java | 8 + .../filter/LanguageFilteringRDFService.java | 27 +- .../impl/RDFServiceFactorySingle.java | 394 +++++++++--------- .../rdfservice/impl/RDFServiceImpl.java | 35 +- .../rdfservice/impl/jena/RDFServiceJena.java | 16 + .../impl/jena/model/RDFServiceModel.java | 209 +++++----- .../impl/logging/LoggingRDFService.java | 16 + .../FakeApplicationOntologyService.java | 27 +- .../servlet/setup/UpdateKnowledgeBase.java | 6 +- .../dataGetter/SparqlQueryDataGetter.java | 345 +++++++-------- .../utils/threads/VitroBackgroundThread.java | 4 + .../edit/EditConfigurationTemplateModel.java | 18 +- 34 files changed, 1132 insertions(+), 634 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java index 0ee20f2fe7..fcf655e366 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java @@ -3,6 +3,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -42,6 +44,8 @@ protected ResponseValues processRequest(VitroRequest vreq) { List groups = null; VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq); groups =vcgc.getGroups(); + Collections.sort(groups, publicNameComparator); +// sortGroupListByPublicName(groups); List vcgroups = new ArrayList(groups.size()); for (VClassGroup group : groups) { vcgroups.add(new VClassGroupTemplateModel(group)); @@ -50,4 +54,35 @@ protected ResponseValues processRequest(VitroRequest vreq) { return new TemplateResponseValues(templateName, body); } + public Comparator publicNameComparator = new Comparator() { + + public int compare(VClassGroup s1, VClassGroup s2) { + String groupName1 = s1.getPublicName().toUpperCase(); + String groupName2 = s2.getPublicName().toUpperCase(); + + //ascending order + return groupName1.compareTo(groupName2); + + //descending order + //return groupName2.compareTo(groupName1); + }}; + +// +// public void sortGroupListByPublicName(List groupList) { +// groupList.sort(new Comparator() { +// public int compare(VClassGroup first, VClassGroup second) { +// if (first != null) { +// if (second != null) { +// return (first.getDisplayRank() - second.getDisplayRank()); +// } else { +// log.error("error--2nd VClassGroup is null in VClassGroupDao.getGroupList().compare()"); +// } +// } else { +// log.error("error--1st VClassGroup is null in VClassGroupDao.getGroupList().compare()"); +// } +// return 0; +// } +// }); +// } + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java index bc7766e83f..975ee9768b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.charset.Charset; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -17,7 +18,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import edu.cornell.mannlib.vitro.webapp.dao.jena.MenuDaoJena; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -93,6 +93,8 @@ public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { super.doGet(request,response); +//UQAM set for UTF-8 + response.setCharacterEncoding("UTF-8"); VitroRequest vreq = new VitroRequest(request); ResponseValues responseValues = null; @@ -103,8 +105,8 @@ public void doGet( HttpServletRequest request, HttpServletResponse response ) if (!isAuthorizedToDisplayPage(request, response, requiredActions(vreq))) { return; } - responseValues = processRequest(vreq); + doResponse(vreq, response, responseValues); } catch (Throwable e) { @@ -256,7 +258,7 @@ private void doNotAuthorized(VitroRequest vreq, protected void doTemplate(VitroRequest vreq, HttpServletResponse response, ResponseValues values) throws TemplateProcessingException { - Map templateDataModel = new HashMap(); + Map templateDataModel = new HashMap(); templateDataModel.putAll(getPageTemplateValues(vreq)); // Add the values that we got from the subcontroller processRequest() method, and merge to the template. @@ -276,8 +278,14 @@ protected void doTemplate(VitroRequest vreq, HttpServletResponse response, // is specified in the main page template. bodyString = ""; } + + //UQAM Add linguistic control management + // String bodyStringUTF = new String(bodyString.getBytes(), Charset.forName("UTF-8")); templateDataModel.put("body", bodyString); + String lang = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); + templateDataModel.put("country", lang); + // Tell the template and any directives it uses that we're processing a page template. templateDataModel.put("templateType", PAGE_TEMPLATE_TYPE); @@ -462,7 +470,7 @@ private String normalizeServletName(String name) { protected MainMenu getDisplayModelMenu(VitroRequest vreq){ String url = vreq.getRequestURI().substring(vreq.getContextPath().length()); - return vreq.getWebappDaoFactory().getMenuDao().getMainMenu(vreq, url); + return vreq.getWebappDaoFactory().getMenuDao().getMainMenu(url); } // NIHVIVO-3307: we need this here instead of FreemarkerConfiguration.java so that updates to diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java index 6f59dbd429..40472bf34f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java @@ -32,6 +32,7 @@ protected ResponseValues processRequest(VitroRequest vreq) throws InstantiationE Map body = new HashMap(); + List dgList = DataGetterUtils.getDataGettersForPage(vreq, vreq.getDisplayModel(), DisplayVocabulary.HOME_PAGE_URI); for( DataGetter dg : dgList){ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java index 85d648f6b6..0159a72746 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -33,6 +34,8 @@ public StringWriter processTemplate(String templateName, Map map throws TemplateProcessingException { Template template = getTemplate(templateName); StringWriter sw = new StringWriter(); + + processTemplate(template, map, sw); return sw; } @@ -42,6 +45,10 @@ private void processTemplate(Template template, Map map, Writer try { Environment env = template.createProcessingEnvironment(map, writer); + /* + * UQAM Set encoding to UTF-8 for i18n special character + */ +// env.setOutputEncoding("utf-8"); // Define a setup template to be included by every page template String templateType = (String) map.get("templateType"); @@ -53,6 +60,7 @@ private void processTemplate(Template template, Map map, Writer // TODO clean this up VIVO-249 FreemarkerConfigurationImpl.retrieveAndRunDataGetters(env, template.getName()); + // Now process it. env.process(); } catch (TemplateException e) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java index 8f3aaa3119..d26f27efad 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -15,6 +16,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale; import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService; import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewService.ShortViewContext; import edu.cornell.mannlib.vitro.webapp.services.shortview.ShortViewServiceSetup; @@ -73,7 +75,8 @@ private String renderShortView(String individualUri, String vclassName) { modelMap.put("individual", IndividualTemplateModelBuilder.build(individual, vreq)); modelMap.put("vclass", vclassName); - + String langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); //UQAM build the linguistic context + modelMap.put("langCtx", langCtx); // UQAM add the linguistic context to map ShortViewService svs = ShortViewServiceSetup.getService(ctx); return svs.renderShortView(individual, ShortViewContext.BROWSE, modelMap, vreq); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java index f96349bcf4..5713d2e5fc 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java @@ -1,10 +1,12 @@ /* $This file is distributed under the terms of the license in LICENSE$ */ +// package edu.cornell.mannlib.vitro.webapp.dao.jena; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -780,6 +782,13 @@ private Literal getLabel(String lang, ListlabelList) { } if ((lang != null) && (lang.equals(labelLanguage))) { return labelLit; + } else + /* + * UQAM + * Check for country-part of lang (ex: 'en' for default consideration of labelLanguage in english but not encoded by 'en-US' most case of labels in vivo.owl) + */ + if ((lang != null) && (Arrays.asList(lang.split("-")).get(0).equals(labelLanguage))) { + return labelLit; } } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java index 4918584533..9c543f06fc 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java @@ -290,10 +290,15 @@ public static String sparqlNode(Node node, String varName) { literalBuff.append("\""); pyString(literalBuff, node.getLiteralLexicalForm()); literalBuff.append("\""); - if (node.getLiteralDatatypeURI() != null) { - literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); - } else if (!StringUtils.isEmpty(node.getLiteralLanguage())) { + /* + * UQAM + * reversing the condition tests. + * It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data + */ + if (!StringUtils.isEmpty(node.getLiteralLanguage())) { literalBuff.append("@").append(node.getLiteralLanguage()); + } else if (node.getLiteralDatatypeURI() != null) { + literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); } return literalBuff.toString(); } else { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java index 8b2ed8668a..50ace6c280 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java @@ -232,10 +232,20 @@ public static String sparqlNode(Node node, String varName) { literalBuff.append("\""); pyString(literalBuff, node.getLiteralLexicalForm()); literalBuff.append("\""); - if (node.getLiteralDatatypeURI() != null) { - literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); - } else if (!StringUtils.isEmpty(node.getLiteralLanguage())) { + /* + * UQAM + * reversing the condition tests. + * It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data + */ +// if (node.getLiteralDatatypeURI() != null) { +// literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); +// } else if (node.getLiteralLanguage() != null && node.getLiteralLanguage().length() > 0) { +// literalBuff.append("@").append(node.getLiteralLanguage()); +// } + if (!StringUtils.isEmpty(node.getLiteralLanguage())) { literalBuff.append("@").append(node.getLiteralLanguage()); + } else if (node.getLiteralDatatypeURI() != null) { + literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); } return literalBuff.toString(); } else { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java index 7c83d88225..fcb72e7ab2 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java @@ -57,7 +57,8 @@ public String toString(){ str += "\nadditions:["; if( getAdditions() != null ) { StringWriter writer = new StringWriter(); - getAdditions().write(writer, "N3-PP"); + // UQAM Replacing N3-PP by N3 (N3-PP does not exist in Jena + getAdditions().write(writer, "N3"); str += "\n" + writer.toString() + "\n"; } str += "],\n"; @@ -65,7 +66,7 @@ public String toString(){ str += "\nretractions:["; if( getRetractions() != null ) { StringWriter writer = new StringWriter(); - getRetractions().write(writer, "N3-PP"); + getRetractions().write(writer, "N3"); str += "\n" + writer.toString() + "\n"; } str += "],\n"; diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java index a3e90d0836..eb46ac1b96 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.io.StringWriter; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Map; import org.apache.commons.logging.Log; @@ -44,7 +47,10 @@ protected String merge(Configuration fmConfig, String templateName, Map map){ } catch (TemplateException | IOException e) { log.error(e,e); } - return writer.toString(); + String sWrite = writer.toString(); + + // String UTF8String = new String(sWrite.getBytes(), Charset.forName("UTF-8")); + return sWrite; } /** diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java index e72e172c13..cf5c4dcbb7 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java @@ -28,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfiguration; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption; import freemarker.template.Configuration; public class EditConfigurationUtils { @@ -62,6 +63,7 @@ public static String getRangeUri(VitroRequest vreq) { } public static VClass getRangeVClass(VitroRequest vreq) { + // This needs a WebappDaoFactory with no filtering/RDFService // funny business because it needs to be able to retrieve anonymous union // classes by their "pseudo-bnode URIs". @@ -71,6 +73,17 @@ public static VClass getRangeVClass(VitroRequest vreq) { return ctxDaoFact.getVClassDao().getVClassByURI(getRangeUri(vreq)); } + public static VClass getLangAwardRangeVClass(VitroRequest vreq) { + // UQAM + // + + // This needs a WebappDaoFactory with linguistic context filtering/RDFService + // funny business because it needs to be able to retrieve anonymous union + // classes by their "pseudo-bnode URIs". + // Someday we'll need to figure out a different way of doing this. + WebappDaoFactory ctxDaoFact = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); + return ctxDaoFact.getVClassDao().getVClassByURI(getRangeUri(vreq)); + } //get individual public static Individual getSubjectIndividual(VitroRequest vreq) { @@ -122,12 +135,24 @@ public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri, String domainUri, String rangeUri) { - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + // WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + // UQAM Use linguistic context + WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs( predicateUri, domainUri, rangeUri); return objectProp; } + // UQAM Use linguistic context + public static ObjectProperty getObjectPropertyForPredicateLangAware(VitroRequest vreq, + String predicateUri, String domainUri, String rangeUri) { + // WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + // UQAM Use linguistic context + WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); + ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs( + predicateUri, domainUri, rangeUri); + return objectProp; + } public static DataProperty getDataPropertyForPredicate(VitroRequest vreq, String predicateUri) { WebappDaoFactory wdf = vreq.getWebappDaoFactory(); //TODO: Check reason for employing unfiltered webapp dao factory and note if using a different version @@ -205,6 +230,7 @@ public static boolean isObjectProperty(String predicateUri, VitroRequest vreq) { return (op != null && dp == null); } + private static boolean isVitroLabel(String predicateUri) { return predicateUri.equals(VitroVocabulary.LABEL); } @@ -281,6 +307,12 @@ public static Map> getExistingUriValues(EditConfigurationVT public static String generateHTMLForElement(VitroRequest vreq, String fieldName, EditConfigurationVTwo editConfig) { String html = ""; Configuration fmConfig = FreemarkerConfiguration.getConfig(vreq); + /* + * UQAM, encoded ftl to UTF-8 + */ + // fmConfig.setDefaultEncoding("utf-8"); + // fmConfig.setOutputEncoding("utf-8"); + // fmConfig.setURLEscapingCharset("UTF-8"); FieldVTwo field = editConfig == null ? null : editConfig.getField(fieldName); MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(vreq.getSession(), editConfig); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java index 0156524458..b81ce06d55 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditN3GeneratorVTwo.java @@ -366,6 +366,8 @@ protected static String formatLiteral(Literal literal) { sbuff.append("@") ; sbuff.append(lang) ; + // added by UQAM to exit at this point without adding datatype + return sbuff.toString() ; } // Format the datatype diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java index 8f61f48700..5810b3ea0e 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java @@ -25,6 +25,7 @@ import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.vocabulary.XSD; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; @@ -34,21 +35,34 @@ public class MultiValueEditSubmission { private Map> literalsFromForm ; private Map> urisFromForm ; - private Map validationErrors; private BasicValidationVTwo basicValidation; - + private static DateTimeFormatter dformater = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:00"); + private static DateTimeFormatter dateFormater = DateTimeFormat.forPattern("yyyy-MM-dd"); private Map> filesFromForm; - private static Model literalCreationModel; - private String entityToReturnTo; + private VitroRequest _vreq; + private static final String DATE_TIME_URI = XSD.dateTime.getURI(); + private static final String DATE_URI = XSD.date.getURI(); + private static final String TIME_URI = XSD.time.getURI(); + static{ literalCreationModel = ModelFactory.createDefaultModel(); } - - public MultiValueEditSubmission(Map queryParameters, EditConfigurationVTwo editConfig){ + /* + * UQAM + * replace + * public MultiValueEditSubmission(Map queryParameters, EditConfigurationVTwo editConfig) + * by this new signature + * This affect PostEditCleanupController and ProcessRdfFormController classes. + * This replacement is justified by the fact that we need a linguistic context in this class. + */ + public MultiValueEditSubmission(VitroRequest vreq, EditConfigurationVTwo editConfig){ + // UQAM add this both lines + _vreq = vreq; + Map queryParameters = vreq.getParameterMap(); if( editConfig == null ) throw new Error("EditSubmission needs an EditConfiguration"); this.editKey = editConfig.getEditKey(); @@ -96,7 +110,8 @@ public MultiValueEditSubmission(Map queryParameters, EditConfi Map errors = basicValidation.validateUris( urisFromForm ); //Validate literals and add errors to the list of existing errors errors.putAll(basicValidation.validateLiterals( literalsFromForm )); - if( errors != null ) { + // UQAM Add empty contition + if( errors != null && !errors.isEmpty()) { validationErrors.putAll( errors); } @@ -141,9 +156,8 @@ protected void processEditElementFields(EditConfigurationVTwo editConfig, Map 0 ) return ResourceFactory.createLangLiteral(value, lang); + } + return literalCreationModel.createTypedLiteral(value, datatypeUri); + // UQAM take into account the linguistic context + } else if( lang != null && lang.length() > 0 ) + return ResourceFactory.createLangLiteral(value, lang); + return ResourceFactory.createPlainLiteral(value); + } public Map getValidationErrors(){ return validationErrors; @@ -264,12 +294,31 @@ public void addLiteralToForm(EditConfigurationVTwo editConfig, FieldVTwo field, for(String value:valueList) { value = N3EditUtils.stripInvalidXMLChars(value); //Add to array of literals corresponding to this variable + /* UQAM OLD if (!StringUtils.isEmpty(value)) { literalsArray.add(createLiteral( value, field.getRangeDatatypeUri(), field.getRangeLang())); } + */ + /* + * UQAM Replaced by this to take the linguistic context into consideration. + */ + if (!StringUtils.isEmpty(value)) { + String rangeLang = field.getRangeLang(); //UQAM Default value + try { + if (_vreq != null ) { + rangeLang = _vreq.getLocale().getLanguage() + "-"+_vreq.getLocale().getCountry(); + } + + } catch (Exception e) { + } + literalsArray.add(createLiteral( + value, + field.getRangeDatatypeUri(), + rangeLang)); + } } literalsFromForm.put(var, literalsArray); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java index 54fd7fb1b3..da2a0ac0d9 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java @@ -9,15 +9,23 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - +import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.ontology.OntModel; import org.apache.jena.rdf.model.Literal; 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.RDFNode; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.rdf.model.Statement; import org.apache.jena.shared.Lock; +import org.apache.jena.vocabulary.RDF; +import org.apache.jena.vocabulary.XSD; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.InsertException; @@ -41,6 +49,7 @@ public class ProcessRdfForm { private EditN3GeneratorVTwo populator; private Map urisForNewResources = null; +// private VitroRequest _vreq; /** * Construct the ProcessRdfForm object. */ @@ -76,9 +85,9 @@ public AdditionsAndRetractions process( AdditionsAndRetractions changes; if( configuration.isUpdate() ){ - changes = editExistingStatements(configuration, submission); + changes = editExistingStatements(configuration, submission, vreq); //UQAM vreq for getting linguistic context } else { - changes = createNewStatements(configuration, submission ); + changes = createNewStatements(configuration, submission, vreq ); //UQAM vreq for getting linguistic context } changes = getMinimalChanges(changes); @@ -99,12 +108,15 @@ public AdditionsAndRetractions process( * any optional N3 is to originally configure the * configuration.setN3Optional() to be empty. * + * UQAM add vreq for linguistic context managing + * * @throws Exception May throw an exception if the required N3 * does not parse. + * */ private AdditionsAndRetractions createNewStatements( EditConfigurationVTwo configuration, - MultiValueEditSubmission submission) throws Exception { + MultiValueEditSubmission submission, VitroRequest vreq) throws Exception { log.debug("in createNewStatements()" ); //getN3Required and getN3Optional will return copies of the @@ -113,10 +125,10 @@ private AdditionsAndRetractions createNewStatements( List optionalN3 = configuration.getN3Optional(); /* substitute in the form values and existing values */ - subInValuesToN3( configuration, submission, requiredN3, optionalN3, null , null); + subInValuesToN3( configuration, submission, requiredN3, optionalN3, null , null, vreq); /* parse N3 to RDF Models, No retractions since all of the statements are new. */ - return parseN3ToChange(requiredN3, optionalN3, null, null); + return parseN3ToChange(requiredN3, optionalN3, null, null, vreq); } /* for a list of N3 strings, substitute in the subject, predicate and object URIs @@ -140,10 +152,12 @@ protected void substituteInSubPredObjURIs( * retractions are mutually diff'ed before statements are added to or * removed from the model. The explicit change check can cause problems in * more complex setups, like the automatic form building in DataStaR. + * @param vreq For getting linguistic context + */ protected AdditionsAndRetractions editExistingStatements( EditConfigurationVTwo editConfig, - MultiValueEditSubmission submission) throws Exception { + MultiValueEditSubmission submission, VitroRequest vreq) throws Exception { log.debug("editing an existing resource: " + editConfig.getObject() ); @@ -156,18 +170,18 @@ protected AdditionsAndRetractions editExistingStatements( subInValuesToN3(editConfig, submission, N3RequiredAssert, N3OptionalAssert, - N3RequiredRetract, N3OptionalRetract); + N3RequiredRetract, N3OptionalRetract, vreq); return parseN3ToChange( N3RequiredAssert,N3OptionalAssert, - N3RequiredRetract, N3OptionalRetract); + N3RequiredRetract, N3OptionalRetract, vreq); } @SuppressWarnings("unchecked") protected void subInValuesToN3( EditConfigurationVTwo editConfig, MultiValueEditSubmission submission, List requiredAsserts, List optionalAsserts, - List requiredRetracts, List optionalRetracts ) throws InsertException{ + List requiredRetracts, List optionalRetracts, VitroRequest vreq ) throws InsertException{ //need to substitute into the return to URL becase it may need new resource URIs List URLToReturnTo = Arrays.asList(submission.getEntityToReturnTo()); @@ -184,7 +198,36 @@ protected void subInValuesToN3( //Retractions does NOT get values from form. /* ******** Form submission Literals *********** */ - substituteInMultiLiterals( submission.getLiteralsFromForm(), requiredAsserts, optionalAsserts, URLToReturnTo); + /* + * UQAM Set all literals in the linguistic context + */ + Map> literalsFromForm = submission.getLiteralsFromForm(); + Set keys = literalsFromForm.keySet(); + for (Iterator iterator = keys.iterator(); iterator.hasNext();) { + String aKey = (String) iterator.next(); + List literalFromForm = literalsFromForm.get(aKey); + List newLiteralFromForm = new ArrayList<>(); + for (Iterator iterator2 = literalFromForm.iterator(); iterator2.hasNext();) { + Literal aLiteral = (Literal) iterator2.next(); + String aLiteratDT = aLiteral.getDatatype().getURI(); + Literal newLiteral= null; + String aText = aLiteral.getLexicalForm(); + /* + * do it only if aLiteral are xstring datatype + */ + + if ( XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT) ) { + String lang =vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); + newLiteral = ResourceFactory.createLangLiteral(aText, lang); + } else { + newLiteral = ResourceFactory.createTypedLiteral(aText, aLiteral.getDatatype()); + } + newLiteralFromForm.add(newLiteral); + } + literalsFromForm.replace(aKey, newLiteralFromForm); + } + + substituteInMultiLiterals( literalsFromForm, requiredAsserts, optionalAsserts, URLToReturnTo); logSubstitue( "Added form Literals", requiredAsserts, optionalAsserts, requiredRetracts, optionalRetracts); //Retractions does NOT get values from form. @@ -254,20 +297,87 @@ public static void applyChangesToWriteModel( protected AdditionsAndRetractions parseN3ToChange( List requiredAdds, List optionalAdds, - List requiredDels, List optionalDels) throws Exception{ + List requiredDels, List optionalDels, VitroRequest vreq) throws Exception{ List adds = parseN3ToRDF(requiredAdds, REQUIRED); adds.addAll( parseN3ToRDF(optionalAdds, OPTIONAL)); - List retracts = new ArrayList(); if( requiredDels != null && optionalDels != null ){ - retracts.addAll( parseN3ToRDF(requiredDels, REQUIRED) ); - retracts.addAll( parseN3ToRDF(optionalDels, OPTIONAL) ); + String lingCxt=null; + //UQAM Taking into account the linguistic context in retract + try { + lingCxt = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); + } catch (Exception e) { + } + retracts.addAll( parseN3ToRDF(requiredDels, REQUIRED, lingCxt) ); + retracts.addAll( parseN3ToRDF(optionalDels, OPTIONAL, lingCxt) ); } return new AdditionsAndRetractions(adds,retracts); } + /** + * Parse the n3Strings to a List of RDF Model objects. + * + * @param n3Strings N3 Strings to parse + * @param parseType if OPTIONAL, then don't throw exceptions on errors + * @param linguisticContext For Literals, Making parse only if the literal linguisticContext are same than linguisticContext parameter //UQAM + * If REQUIRED, then throw exceptions on errors. + * @throws Exception + */ + protected static List parseN3ToRDF( + List n3Strings, N3ParseType parseType, String linguisticContext ) throws Exception { + List errorMessages = new ArrayList(); + List rdfModels = new ArrayList(); + for(String n3 : n3Strings){ + try{ + Model model = ModelFactory.createDefaultModel(); + StringReader reader = new StringReader(n3); + model.read(reader, "", "N3"); + List stmts = model.listStatements().toList(); + for (Iterator iterator = stmts.iterator(); iterator.hasNext();) { + Statement stmt = (Statement) iterator.next(); + Resource subj = stmt.getSubject(); + Property pred = stmt.getPredicate(); + RDFNode obj = stmt.getObject(); + if (obj.isLiteral()) { + Literal lit = obj.asLiteral(); + String lang = lit.getLanguage(); + if (! linguisticContext.equals(lang)) { + //UQAM Remove if linguisticContext != lang of the Literal + model.remove(subj, pred, obj); + } + } + + } + rdfModels.add( model ); + }catch(Throwable t){ + errorMessages.add(t.getMessage() + "\nN3: \n" + n3 + "\n"); + } + } + + StringBuilder errors = new StringBuilder(); + for( String errorMsg : errorMessages){ + errors.append(errorMsg).append('\n'); + } + + if( !errorMessages.isEmpty() ){ + if( REQUIRED.equals(parseType) ){ + throw new Exception("Errors processing required N3. The EditConfiguration should " + + "be setup so that if a submission passes validation, there will not be errors " + + "in the required N3.\n" + errors ); + }else if( OPTIONAL.equals(parseType) ){ + log.debug("Some Optional N3 did not parse, if a optional N3 does not parse it " + + "will be ignored. This allows optional parts of a form submission to " + + "remain unfilled out and then the optional N3 does not get values subsituted in from" + + "the form submission values. It may also be the case that there are unintentional " + + "syntax errors the optional N3." ); + log.debug(errors.toString()); + } + } + + return rdfModels; + } /** * Parse the n3Strings to a List of RDF Model objects. * @@ -479,4 +589,4 @@ private void substituteInForcedNewURIs( private static Log log = LogFactory.getLog(ProcessRdfForm.class); -} +} \ No newline at end of file diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java index 135b384748..d5f7b9dbff 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in LICENSE$ */ -package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields; +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; @@ -12,9 +12,12 @@ import org.apache.jena.vocabulary.OWL; import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; public class ChildVClassesWithParent implements FieldOptions { @@ -22,6 +25,7 @@ public class ChildVClassesWithParent implements FieldOptions { String fieldName; String classUri; String defaultOptionLabel = null; + private I18nBundle i18n; public ChildVClassesWithParent(String classUri) throws Exception { super(); @@ -37,6 +41,49 @@ public ChildVClassesWithParent setDefaultOption(String label){ return this; } +/* + * UQAM + * This method is polymorphism of getOptions(EditConfigurationVTwo editConfig,String fieldName, WebappDaoFactory wDaoFact) + * for the internationalization of word "other" in the scroling list of personHasAdvisorRelationship.ftl + */ + public Map getOptions( + EditConfigurationVTwo editConfig, + String fieldName, + VitroRequest vreq) throws Exception { +// WebappDaoFactory wDaoFact) throws Exception { + this.i18n = I18n.bundle(vreq); + HashMap optionsMap = new LinkedHashMap(); + // first test to see whether there's a default "leave blank" value specified with the literal options + if ( ! StringUtils.isEmpty( defaultOptionLabel ) ){ + optionsMap.put(LEFT_BLANK, defaultOptionLabel); + } + String other_i18n = i18n.text("other"); + // first character in capital + optionsMap.put(classUri, other_i18n.substring(0, 1).toUpperCase() + other_i18n.substring(1)); + WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory(); + VClassDao vclassDao = wDaoFact.getVClassDao(); + List subClassList = vclassDao.getAllSubClassURIs(classUri); + if (subClassList != null && subClassList.size() > 0) { + for (String subClassUri : subClassList) { + VClass subClass = vclassDao.getVClassByURI(subClassUri); + if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { + optionsMap.put(subClassUri, subClass.getName().trim()); + } + } + } + return optionsMap; + } + + public Comparator getCustomComparator() { + return null; + } + + /* + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldOptions#getOptions(edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo, java.lang.String, edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory) + * UQAM this version is a not internationalized use this method (see line below) more often + * getOptions(EditConfigurationVTwo editConfig, String fieldName, VitroRequest vreq) + */ @Override public Map getOptions( EditConfigurationVTwo editConfig, @@ -64,8 +111,5 @@ public Map getOptions( return optionsMap; } - public Comparator getCustomComparator() { - return null; - } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java index 3e732ce588..67436009d3 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java @@ -20,8 +20,7 @@ public class SelectListGeneratorVTwo { - static Log log = LogFactory.getLog(SelectListGeneratorVTwo.class); - + static Log log = LogFactory.getLog(SelectListGeneratorVTwo.class); public static Map getOptions( EditConfigurationVTwo editConfig, String fieldName, @@ -54,63 +53,104 @@ public static Map getOptions( return Collections.emptyMap(); } } - - - //Methods to sort the options map - // from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708 - //Modified to allow for a custom comparator to be sent in, defaults to mapPairsComparator - public static Map getSortedMap(Map hmap, - Comparator comparator, VitroRequest vreq){ - // first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator - List objectsToSort = new ArrayList(hmap.size()); - for (String key:hmap.keySet()) { - String[] x = new String[2]; - x[0] = key; - x[1] = hmap.get(key); - objectsToSort.add(x); - } - - //if no comparator is passed in, utilize MapPairsComparator - if(comparator == null) { - comparator = new MapPairsComparator(vreq); - } - - objectsToSort.sort(comparator); - - HashMap map = new LinkedHashMap(objectsToSort.size()); - for (String[] pair:objectsToSort) { - map.put(pair[0],pair[1]); - } - return map; - } - - //Sorts by the value of the 2nd element in each of the arrays - private static class MapPairsComparator implements Comparator { - - private Collator collator; - - public MapPairsComparator(VitroRequest vreq) { - this.collator = vreq.getCollator(); - } - public int compare (String[] s1, String[] s2) { - if (s2 == null) { - return 1; - } else if (s1 == null) { - return -1; - } else { - if ("".equals(s1[0])) { - return -1; - } else if ("".equals(s2[0])) { - return 1; - } - if (s2[1]==null) { - return 1; - } else if (s1[1] == null){ - return -1; - } else { - return collator.compare(s1[1],s2[1]); - } - } - } - } + // UQAM Overcharge method for linguistic contexte processisng + public static Map getOptions( + EditConfigurationVTwo editConfig, + String fieldName, + VitroRequest vreq){ + + + if( editConfig == null ){ + log.error( "fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo "); + return Collections.emptyMap(); + } + if( fieldName == null ){ + log.error( "fieldToSelectItemList() must be called with a non-null fieldName"); + return Collections.emptyMap(); + } + + FieldVTwo field = editConfig.getField(fieldName); + if (field==null) { + log.error("no field \""+fieldName+"\" found from editConfig."); + return Collections.emptyMap(); + } + + if( field.getFieldOptions() == null ){ + return Collections.emptyMap(); + } + + try { + //UQAM need vreq instead of WebappDaoFactory + Map parentClass = Collections.emptyMap(); + FieldOptions fieldOptions = field.getFieldOptions(); + // UQAM TODO - Only internationalization of ChildVClassesWithParent are implemented. For TODO, implement the internationalization for the rest of instanceof "FieldOptions" + if (fieldOptions instanceof ChildVClassesWithParent ) { + return ((ChildVClassesWithParent)fieldOptions).getOptions(editConfig,fieldName,vreq); + } else { + return fieldOptions.getOptions(editConfig,fieldName,vreq.getWebappDaoFactory()); + } + } catch (Exception e) { + log.error("Error runing getFieldOptionis()",e); + return Collections.emptyMap(); + } + } + + + //Methods to sort the options map + // from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708 + //Modified to allow for a custom comparator to be sent in, defaults to mapPairsComparator + public static Map getSortedMap(Map hmap, + Comparator comparator, VitroRequest vreq){ + // first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator + List objectsToSort = new ArrayList(hmap.size()); + for (String key:hmap.keySet()) { + String[] x = new String[2]; + x[0] = key; + x[1] = hmap.get(key); + objectsToSort.add(x); + } + + //if no comparator is passed in, utilize MapPairsComparator + if(comparator == null) { + comparator = new MapPairsComparator(vreq); + } + + objectsToSort.sort(comparator); + + HashMap map = new LinkedHashMap(objectsToSort.size()); + for (String[] pair:objectsToSort) { + map.put(pair[0],pair[1]); + } + return map; + } + + //Sorts by the value of the 2nd element in each of the arrays + private static class MapPairsComparator implements Comparator { + + private Collator collator; + + public MapPairsComparator(VitroRequest vreq) { + this.collator = vreq.getCollator(); + } + public int compare (String[] s1, String[] s2) { + if (s2 == null) { + return 1; + } else if (s1 == null) { + return -1; + } else { + if ("".equals(s1[0])) { + return -1; + } else if ("".equals(s2[0])) { + return 1; + } + if (s2[1]==null) { + return 1; + } else if (s1[1] == null){ + return -1; + } else { + return collator.compare(s1[1],s2[1]); + } + } + } + } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index ce471ca98b..c172294dfc 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -2,6 +2,8 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; +import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LANGUAGE_NEUTRAL; +import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.POLICY_NEUTRAL; import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY; import java.util.ArrayList; @@ -35,6 +37,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation; import edu.cornell.mannlib.vitro.webapp.i18n.I18n; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; @@ -125,7 +129,10 @@ protected List getRangeTypes(VitroRequest vreq) { // Someday we'll need to figure out a different way of doing this. //WebappDaoFactory ctxDaoFact = ModelAccess.on( // vreq.getSession().getServletContext()).getWebappDaoFactory(); - WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory(); +// WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory(); + //UQAM Manage linguistic context + WebappDaoFactory ctxDaoFact = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE, PolicyOption.POLICY_NEUTRAL); + List types = new ArrayList(); Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java index 96d6556b8d..8e6e0d681e 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java @@ -13,18 +13,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.jena.ontology.OntModel; + import org.apache.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; -import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditDataPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AbstractObjectPropertyStatementAction; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Property; @@ -42,11 +35,9 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditSubmissionUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator; -import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.EditConfigurationTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.MultiValueEditSubmissionTemplateModel; - /** * This servlet is intended to handle all requests to create a form for use * by the N3 editing system. It will examine the request parameters, determine @@ -69,33 +60,8 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { final String DEFAULT_DELETE_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator"; @Override - protected AuthorizationRequest requiredActions(VitroRequest vreq) { - //Check if this statement can be edited here and return unauthorized if not - String subjectUri = EditConfigurationUtils.getSubjectUri(vreq); - String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); - String objectUri = EditConfigurationUtils.getObjectUri(vreq); - String domainUri = EditConfigurationUtils.getDomainUri(vreq); - String rangeUri = EditConfigurationUtils.getRangeUri(vreq); - Property predicateProp = new Property(); - predicateProp.setURI(predicateUri); - predicateProp.setDomainVClassURI(domainUri); - predicateProp.setRangeVClassURI(rangeUri); - OntModel ontModel = ModelAccess.on(vreq).getOntModel(); - AbstractObjectPropertyStatementAction objectPropertyAction; - if (objectUri == null) { - objectPropertyAction = new AddObjectPropertyStatement(ontModel, subjectUri, predicateProp, RequestedAction.SOME_URI); - } else { - if (isDeleteForm(vreq)) { - objectPropertyAction = new DropObjectPropertyStatement(ontModel, subjectUri, predicateProp, objectUri); - } else { - objectPropertyAction = new EditObjectPropertyStatement(ontModel, subjectUri, predicateProp, objectUri); - } - } - boolean isAuthorized = PolicyHelper.isAuthorizedForActions(vreq, - new EditDataPropertyStatement(ontModel, subjectUri, predicateUri, objectUri). - or(objectPropertyAction)); - - return isAuthorized? SimplePermission.DO_FRONT_END_EDITING.ACTION: AuthorizationRequest.UNAUTHORIZED; + protected AuthorizationRequest requiredActions(VitroRequest vreq) { + return SimplePermission.DO_FRONT_END_EDITING.ACTION; } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java index 64f6051034..a0497b03f9 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java @@ -74,9 +74,11 @@ protected static ResponseValues doPostEditRedirect( VitroRequest vreq , String e //The submission for getting the entity to return to is not retrieved from the session but needs //to be created - as it is in processRdfForm3.jsp if( entityToReturnTo == null ){ - //this will not work if there entityToReturnTo has a new resource URI, - //in that case entityToReturnTo should not have been passed to this method as null - MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig); + // this will not work if there entityToReturnTo has a new resource URI, + // in that case entityToReturnTo should not have been passed to this method as null + // UQAM + // MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig); + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, editConfig); entityToReturnTo = N3EditUtils.processEntityToReturnTo(editConfig, submission, vreq); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java index 790781a95e..5bf7f1a485 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java @@ -66,7 +66,9 @@ protected ResponseValues processRequest(VitroRequest vreq) { return handleMissingConfiguration(vreq); //get the EditSubmission - MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration); + // MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration); + // Modified by UQAM + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, configuration); EditSubmissionUtils.putEditSubmissionInSession(vreq.getSession(), submission); //if errors, return error response @@ -102,7 +104,6 @@ protected ResponseValues processRequest(VitroRequest vreq) { changes = ProcessRdfForm.addDependentDeletes(changes, queryModel); N3EditUtils.preprocessModels(changes, configuration, vreq); - ProcessRdfForm.applyChangesToWriteModel(changes, queryModel, writeModel, N3EditUtils.getEditorUri(vreq) ); //Here we are trying to get the entity to return to URL, diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java index d956483f6b..2ef05e2789 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java @@ -63,6 +63,11 @@ public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chai // get URL without hostname or servlet context HttpServletResponse response = (HttpServletResponse) arg1; HttpServletRequest req = (HttpServletRequest) arg0; + // UQAM Manage UTF-8 for i18n + // req.setCharacterEncoding("UTF-8"); + // response.setContentType("text/html; charset=UTF-8"); + // response.setCharacterEncoding("UTF-8"); + String path = req.getRequestURI().substring(req.getContextPath().length()); // check for first part of path diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java index c0ab92d253..718f9543e8 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.servlet.ServletContext; @@ -73,6 +74,14 @@ public static Configuration getConfig(HttpServletRequest req) { clearTemplateCacheIfRequested(); keepTemplateLoaderCurrentWithThemeDirectory(req); setThreadLocalsForRequest(req); + /* + * UQAM, encoded ftl to UTF-8 + */ +// instance.setEncoding(req.getLocale(), "utf-8"); +// instance.setIncompatibleImprovements(freemarker.template.Configuration.VERSION_2_3_23); +// instance.setDefaultEncoding("utf-8"); +// instance.setOutputEncoding("utf-8"); +// instance.setURLEscapingCharset("UTF-8"); return instance; } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java index babac6c529..2601fb9549 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java @@ -10,6 +10,8 @@ import org.apache.jena.rdf.model.ModelChangedListener; import org.apache.jena.rdf.model.RDFNode; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; + /** * Interface for API to write, read, and update Vitro's RDF store, with support * to allow listening, logging and auditing. @@ -263,4 +265,10 @@ public void unregisterJenaModelChangedListener(ModelChangedListener changeListen * multiple invocations do not cause an error. */ public void close(); + /** + * UQAM Useful among other things to transport the linguistic context in the service + * @param vitroRequest + */ + public void setVitroRequest(VitroRequest vitroRequest); + public VitroRequest getVitroRequest(); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java index 903711e529..42d2a5c095 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java @@ -22,11 +22,11 @@ import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelChangedListener; -import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.RDFNode; import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; @@ -91,15 +91,7 @@ public InputStream sparqlConstructQuery(String query, @Override public void sparqlConstructQuery(String query, Model model) throws RDFServiceException { - if (model.isEmpty()) { - s.sparqlConstructQuery(query, model); - filterModel(model); - } else { - Model constructedModel = ModelFactory.createDefaultModel(); - s.sparqlConstructQuery(query, constructedModel); - filterModel(constructedModel); - model.add(constructedModel); - } + s.sparqlConstructQuery(query, model); } @Override @@ -254,7 +246,6 @@ public InputStream sparqlSelectQuery(String query, @Override public void sparqlSelectQuery(String query, ResultSetConsumer consumer) throws RDFServiceException { log.debug("sparqlSelectQuery: " + query.replaceAll("\\s+", " ")); - s.sparqlSelectQuery(query, new ResultSetConsumer.Chaining(consumer) { List vars; List solnList = new ArrayList(); @@ -562,6 +553,20 @@ public int compare(Statement s1, Statement s2) { return compareLangs(s1lang, s2lang); } } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; + } + + public VitroRequest getVitroRequest() { + return vitroRequest; + } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java index f44d2b59fe..0b6e92faaf 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java @@ -9,6 +9,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelChangedListener; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; @@ -25,200 +26,215 @@ */ public class RDFServiceFactorySingle implements RDFServiceFactory { - private RDFService rdfService; - - public RDFServiceFactorySingle(RDFService rdfService) { - this.rdfService = new UnclosableRDFService(rdfService); - } - - @Override - public RDFService getRDFService() { - return this.rdfService; - } - - @Override - public RDFService getShortTermRDFService() { - return this.rdfService; - } - - @Override - public void registerListener(ChangeListener listener) throws RDFServiceException { - this.rdfService.registerListener(listener); - } - - @Override - public void unregisterListener(ChangeListener listener) throws RDFServiceException { - this.rdfService.unregisterListener(listener); - } - - @Override - public void registerJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { - this.rdfService.registerJenaModelChangedListener(listener); - } - - @Override - public void unregisterJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { - this.rdfService.unregisterJenaModelChangedListener(listener); - } - - public class UnclosableRDFService implements RDFService { - - private RDFService s; - - public UnclosableRDFService(RDFService rdfService) { - this.s = rdfService; - } - - @Override - public boolean changeSetUpdate(ChangeSet changeSet) - throws RDFServiceException { - return s.changeSetUpdate(changeSet); - } - - @Override - public void newIndividual(String individualURI, String individualTypeURI) - throws RDFServiceException { - s.newIndividual(individualURI, individualTypeURI); - } - - @Override - public void newIndividual(String individualURI, - String individualTypeURI, String graphURI) - throws RDFServiceException { - s.newIndividual(individualURI, individualTypeURI, graphURI); - } - - @Override - public InputStream sparqlConstructQuery(String query, - ModelSerializationFormat resultFormat) - throws RDFServiceException { - return s.sparqlConstructQuery(query, resultFormat); - } - - @Override - public void sparqlConstructQuery(String query, Model model) - throws RDFServiceException { - s.sparqlConstructQuery(query, model); - } - - @Override - public InputStream sparqlDescribeQuery(String query, - ModelSerializationFormat resultFormat) - throws RDFServiceException { - return s.sparqlDescribeQuery(query, resultFormat); - } - - @Override - public InputStream sparqlSelectQuery(String query, - ResultFormat resultFormat) throws RDFServiceException { - return s.sparqlSelectQuery(query, resultFormat); - } - - @Override - public void sparqlSelectQuery(String query, ResultSetConsumer consumer) throws RDFServiceException { - s.sparqlSelectQuery(query, consumer); - } - - @Override - public boolean sparqlAskQuery(String query) throws RDFServiceException { - return s.sparqlAskQuery(query); - } - - @Override - public List getGraphURIs() throws RDFServiceException { - return s.getGraphURIs(); - } - - @Override - public void getGraphMetadata() throws RDFServiceException { - s.getGraphMetadata(); - } - - @Override - public String getDefaultWriteGraphURI() throws RDFServiceException { - return s.getDefaultWriteGraphURI(); - } - - @Override - public void serializeAll(OutputStream outputStream) - throws RDFServiceException { - s.serializeAll(outputStream); - } - - @Override - public void serializeGraph(String graphURI, OutputStream outputStream) - throws RDFServiceException { - s.serializeGraph(graphURI, outputStream); - } - - @Override - public boolean isEquivalentGraph(String graphURI, - InputStream serializedGraph, - ModelSerializationFormat serializationFormat) throws RDFServiceException { - return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat); - } - - @Override - public boolean isEquivalentGraph(String graphURI, - Model graph) throws RDFServiceException { - return s.isEquivalentGraph(graphURI, graph); - } - - @Override - public void registerListener(ChangeListener changeListener) - throws RDFServiceException { - s.registerListener(changeListener); - } - - @Override - public void unregisterListener(ChangeListener changeListener) - throws RDFServiceException { - s.unregisterListener(changeListener); - } - - @Override - public void registerJenaModelChangedListener(ModelChangedListener changeListener) - throws RDFServiceException { - s.registerJenaModelChangedListener(changeListener); - } - - @Override - public void unregisterJenaModelChangedListener(ModelChangedListener changeListener) - throws RDFServiceException { - s.unregisterJenaModelChangedListener(changeListener); - } - - @Override - public ChangeSet manufactureChangeSet() { - return s.manufactureChangeSet(); - } - - @Override - public long countTriples(RDFNode subject, RDFNode predicate, RDFNode object) throws RDFServiceException { - return s.countTriples(subject, predicate, object); - } - - @Override - public Model getTriples(RDFNode subject, RDFNode predicate, RDFNode object, long limit, long offset) throws RDFServiceException { - return s.getTriples(subject, predicate, object, limit, offset); - } - - @Override - public boolean preferPreciseOptionals() { - return s.preferPreciseOptionals(); - } - - @Override - public void close() { - // Don't close s. It's being used by everybody. - } + private RDFService rdfService; + + public RDFServiceFactorySingle(RDFService rdfService) { + this.rdfService = new UnclosableRDFService(rdfService); + } + + @Override + public RDFService getRDFService() { + return this.rdfService; + } + + @Override + public RDFService getShortTermRDFService() { + return this.rdfService; + } + + @Override + public void registerListener(ChangeListener listener) throws RDFServiceException { + this.rdfService.registerListener(listener); + } + + @Override + public void unregisterListener(ChangeListener listener) throws RDFServiceException { + this.rdfService.unregisterListener(listener); + } + + @Override + public void registerJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { + this.rdfService.registerJenaModelChangedListener(listener); + } + + @Override + public void unregisterJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { + this.rdfService.unregisterJenaModelChangedListener(listener); + } + + public class UnclosableRDFService implements RDFService { + + private RDFService s; + + public UnclosableRDFService(RDFService rdfService) { + this.s = rdfService; + } + + @Override + public boolean changeSetUpdate(ChangeSet changeSet) + throws RDFServiceException { + return s.changeSetUpdate(changeSet); + } + + @Override + public void newIndividual(String individualURI, String individualTypeURI) + throws RDFServiceException { + s.newIndividual(individualURI, individualTypeURI); + } + + @Override + public void newIndividual(String individualURI, + String individualTypeURI, String graphURI) + throws RDFServiceException { + s.newIndividual(individualURI, individualTypeURI, graphURI); + } + + @Override + public InputStream sparqlConstructQuery(String query, + ModelSerializationFormat resultFormat) + throws RDFServiceException { + return s.sparqlConstructQuery(query, resultFormat); + } + + @Override + public void sparqlConstructQuery(String query, Model model) + throws RDFServiceException { + s.sparqlConstructQuery(query, model); + } + + @Override + public InputStream sparqlDescribeQuery(String query, + ModelSerializationFormat resultFormat) + throws RDFServiceException { + return s.sparqlDescribeQuery(query, resultFormat); + } + + @Override + public InputStream sparqlSelectQuery(String query, + ResultFormat resultFormat) throws RDFServiceException { + return s.sparqlSelectQuery(query, resultFormat); + } + + @Override + public void sparqlSelectQuery(String query, ResultSetConsumer consumer) throws RDFServiceException { + s.sparqlSelectQuery(query, consumer); + } + + @Override + public boolean sparqlAskQuery(String query) throws RDFServiceException { + return s.sparqlAskQuery(query); + } + + @Override + public List getGraphURIs() throws RDFServiceException { + return s.getGraphURIs(); + } + + @Override + public void getGraphMetadata() throws RDFServiceException { + s.getGraphMetadata(); + } + + @Override + public String getDefaultWriteGraphURI() throws RDFServiceException { + return s.getDefaultWriteGraphURI(); + } + + @Override + public void serializeAll(OutputStream outputStream) + throws RDFServiceException { + s.serializeAll(outputStream); + } + + @Override + public void serializeGraph(String graphURI, OutputStream outputStream) + throws RDFServiceException { + s.serializeGraph(graphURI, outputStream); + } + + @Override + public boolean isEquivalentGraph(String graphURI, + InputStream serializedGraph, + ModelSerializationFormat serializationFormat) throws RDFServiceException { + return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat); + } + + @Override + public boolean isEquivalentGraph(String graphURI, + Model graph) throws RDFServiceException { + return s.isEquivalentGraph(graphURI, graph); + } + + @Override + public void registerListener(ChangeListener changeListener) + throws RDFServiceException { + s.registerListener(changeListener); + } + + @Override + public void unregisterListener(ChangeListener changeListener) + throws RDFServiceException { + s.unregisterListener(changeListener); + } + + @Override + public void registerJenaModelChangedListener(ModelChangedListener changeListener) + throws RDFServiceException { + s.registerJenaModelChangedListener(changeListener); + } + + @Override + public void unregisterJenaModelChangedListener(ModelChangedListener changeListener) + throws RDFServiceException { + s.unregisterJenaModelChangedListener(changeListener); + } + + @Override + public ChangeSet manufactureChangeSet() { + return s.manufactureChangeSet(); + } + + @Override + public long countTriples(RDFNode subject, RDFNode predicate, RDFNode object) throws RDFServiceException { + return s.countTriples(subject, predicate, object); + } + + @Override + public Model getTriples(RDFNode subject, RDFNode predicate, RDFNode object, long limit, long offset) throws RDFServiceException { + return s.getTriples(subject, predicate, object, limit, offset); + } + + @Override + public boolean preferPreciseOptionals() { + return s.preferPreciseOptionals(); + } + + @Override + public void close() { + // Don't close s. It's being used by everybody. + } @Override public String toString() { return ToString.simpleName(this) + "[" + ToString.hashHex(this) - + ", inner=" + s + "]"; + + ", inner=" + s + "]"; + } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; } - } + public VitroRequest getVitroRequest() { + return vitroRequest; + } + + + } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java index 2171492838..e6d34fe54b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java @@ -32,6 +32,7 @@ import org.apache.jena.riot.out.NodeFormatterTTL; import org.apache.jena.vocabulary.RDF; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange; @@ -141,8 +142,8 @@ protected void notifyListenersOfChanges(ChangeSet changeSet) } protected void notifyListeners(ModelChange modelChange) throws IOException { + modelChange.getSerializedModel().reset(); for (ChangeListener listener : registeredListeners) { - modelChange.getSerializedModel().reset(); listener.notifyModelChange(modelChange); } log.debug(registeredJenaListeners.size() + " registered Jena listeners"); @@ -254,11 +255,22 @@ protected static String sparqlNode(Node node, String varName) { literalBuff.append("\""); pyString(literalBuff, node.getLiteralLexicalForm()); literalBuff.append("\""); - if (node.getLiteralDatatypeURI() != null) { - literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); - } else if (node.getLiteralLanguage() != null && node.getLiteralLanguage().length() > 0) { + /* + * UQAM + * reversing the condition tests. + * It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data + */ +// if (node.getLiteralDatatypeURI() != null) { +// literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); +// } else if (node.getLiteralLanguage() != null && node.getLiteralLanguage().length() > 0) { +// literalBuff.append("@").append(node.getLiteralLanguage()); +// } + if (node.getLiteralLanguage() != null && node.getLiteralLanguage().length() > 0) { literalBuff.append("@").append(node.getLiteralLanguage()); + } else if (node.getLiteralDatatypeURI() != null) { + literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); } + return literalBuff.toString(); } else { return varName; @@ -453,4 +465,19 @@ protected void processQuerySolution(QuerySolution qs) { } } } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; + } + + public VitroRequest getVitroRequest() { + return vitroRequest; + } + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java index dadccfed4a..7e363a0cac 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java @@ -42,6 +42,7 @@ import org.apache.jena.shared.Lock; import org.apache.jena.sparql.core.Quad; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset; import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph; @@ -704,4 +705,19 @@ public void close() { protected QueryExecution createQueryExecution(String queryString, Query q, Dataset d) { return QueryExecutionFactory.create(q, d); } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; + } + + public VitroRequest getVitroRequest() { + return vitroRequest; + } + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java index 496928fbcc..864156a52b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java @@ -13,6 +13,7 @@ import org.apache.jena.query.DatasetFactory; import org.apache.jena.rdf.model.Model; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange; @@ -22,101 +23,115 @@ public class RDFServiceModel extends RDFServiceJena implements RDFService { - private final static Log log = LogFactory.getLog(RDFServiceModel.class); - - private Model model; - private Dataset dataset; - private String modelName; - - /** - * Create an RDFService to access a single default graph - * @param model Jena Model - */ - public RDFServiceModel(Model model) { - this.model = model; - } - - /** - * Create an RDFService to access a Jena Dataset - * @param dataset Jena Dataset - */ - public RDFServiceModel(Dataset dataset) { - this.dataset = dataset; - } - - @Override - protected DatasetWrapper getDatasetWrapper() { - Dataset d = null; - if (dataset != null) { - d = dataset; - } else { - d = DatasetFactory.createMem(); - if (modelName == null) { - d.setDefaultModel(this.model); - } else { - d.addNamedModel(this.modelName, model); - } - } - DatasetWrapper datasetWrapper = new DatasetWrapper(d); - return datasetWrapper; - } - - @Override - public boolean changeSetUpdate(ChangeSet changeSet) - throws RDFServiceException { - - if (changeSet.getPreconditionQuery() != null - && !isPreconditionSatisfied( - changeSet.getPreconditionQuery(), - changeSet.getPreconditionQueryType())) { - return false; - } - - //Dataset dataset = getDatasetWrapper().getDataset(); - - try { - for (Object o : changeSet.getPreChangeEvents()) { - this.notifyListenersOfEvent(o); - } - - for (ModelChange modelChange : changeSet.getModelChanges()) { - if (!modelChange.getSerializedModel().markSupported()) { - byte[] bytes = IOUtils.toByteArray(modelChange.getSerializedModel()); - modelChange.setSerializedModel(new ByteArrayInputStream(bytes)); - } - modelChange.getSerializedModel().mark(Integer.MAX_VALUE); - Model m = this.model; - if (m == null && dataset != null) { - String changeGraphURI = modelChange.getGraphURI(); - if (changeGraphURI != null) { - m = dataset.getNamedModel(changeGraphURI); - } else { - m = dataset.getDefaultModel(); - } - } - operateOnModel(m, modelChange, null); - } - - // notify listeners of triple changes - notifyListenersOfChanges(changeSet); -// csIt = changeSet.getModelChanges().iterator(); -// while (csIt.hasNext()) { -// ModelChange modelChange = csIt.next(); -// modelChange.getSerializedModel().reset(); -// Model model = ModelFactory.createModelForGraph( -// new ListeningGraph(modelChange.getGraphURI(), this)); -// operateOnModel(model, modelChange, null); -// } - - for (Object o : changeSet.getPostChangeEvents()) { - this.notifyListenersOfEvent(o); - } - - } catch (Exception e) { - log.error(e, e); - throw new RDFServiceException(e); - } - - return true; - } + private final static Log log = LogFactory.getLog(RDFServiceModel.class); + + private Model model; + private Dataset dataset; + private String modelName; + + /** + * Create an RDFService to access a single default graph + * @param model Jena Model + */ + public RDFServiceModel(Model model) { + this.model = model; + } + + /** + * Create an RDFService to access a Jena Dataset + * @param dataset Jena Dataset + */ + public RDFServiceModel(Dataset dataset) { + this.dataset = dataset; + } + + @Override + protected DatasetWrapper getDatasetWrapper() { + Dataset d = null; + if (dataset != null) { + d = dataset; + } else { + d = DatasetFactory.createMem(); + if (modelName == null) { + d.setDefaultModel(this.model); + } else { + d.addNamedModel(this.modelName, model); + } + } + DatasetWrapper datasetWrapper = new DatasetWrapper(d); + return datasetWrapper; + } + + @Override + public boolean changeSetUpdate(ChangeSet changeSet) + throws RDFServiceException { + + if (changeSet.getPreconditionQuery() != null + && !isPreconditionSatisfied( + changeSet.getPreconditionQuery(), + changeSet.getPreconditionQueryType())) { + return false; + } + + //Dataset dataset = getDatasetWrapper().getDataset(); + + try { + for (Object o : changeSet.getPreChangeEvents()) { + this.notifyListenersOfEvent(o); + } + + for (ModelChange modelChange : changeSet.getModelChanges()) { + if (!modelChange.getSerializedModel().markSupported()) { + byte[] bytes = IOUtils.toByteArray(modelChange.getSerializedModel()); + modelChange.setSerializedModel(new ByteArrayInputStream(bytes)); + } + modelChange.getSerializedModel().mark(Integer.MAX_VALUE); + Model m = this.model; + if (m == null && dataset != null) { + String changeGraphURI = modelChange.getGraphURI(); + if (changeGraphURI != null) { + m = dataset.getNamedModel(changeGraphURI); + } else { + m = dataset.getDefaultModel(); + } + } + operateOnModel(m, modelChange, null); + } + + // notify listeners of triple changes + notifyListenersOfChanges(changeSet); + // csIt = changeSet.getModelChanges().iterator(); + // while (csIt.hasNext()) { + // ModelChange modelChange = csIt.next(); + // modelChange.getSerializedModel().reset(); + // Model model = ModelFactory.createModelForGraph( + // new ListeningGraph(modelChange.getGraphURI(), this)); + // operateOnModel(model, modelChange, null); + // } + + for (Object o : changeSet.getPostChangeEvents()) { + this.notifyListenersOfEvent(o); + } + + } catch (Exception e) { + log.error(e, e); + throw new RDFServiceException(e); + } + + return true; + } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; + } + + public VitroRequest getVitroRequest() { + return vitroRequest; + } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java index 5a0189f411..7a45dbcf29 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java @@ -9,6 +9,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelChangedListener; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; @@ -207,4 +208,19 @@ public void close() { public String toString() { return "LoggingRDFService[inner=" + innerService + "]"; } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; + } + + public VitroRequest getVitroRequest() { + return vitroRequest; + } + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java index 383177cd78..fd8c4f5cbf 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java @@ -185,7 +185,7 @@ private List contextsFromNames(Resource view, */ private Map> createClassMappings( Map viewSpecsByUri) - throws ShortViewConfigException { + throws ShortViewConfigException { Property hasView = viewModel.getProperty(HAS_VIEW); StmtIterator stmts = viewModel.listStatements(null, hasView, @@ -445,14 +445,26 @@ public ShortViewConfigException(String message, Throwable cause) { * "display model". The query finds a preferred title for the individual. */ private static class FakeVivoPeopleDataGetter extends SparqlQueryDataGetter { - private static String QUERY_STRING = "" + // private static String QUERY_STRING = "" + // + "PREFIX obo: \n" + // + "PREFIX vcard: \n" + // + "SELECT ?pt \n" + "WHERE { \n" + // + " ?uri obo:ARG_2000028 ?vIndividual . \n" + // + " ?vIndividual vcard:hasTitle ?vTitle . \n" + // + " ?vTitle vcard:title ?pt . \n" + "} LIMIT 1"; + + /* + * UQAM New query including Linguistic context + */ + private static String QUERY_STRING_LANG = "" + "PREFIX obo: \n" + "PREFIX vcard: \n" + "SELECT ?pt \n" + "WHERE { \n" + " ?uri obo:ARG_2000028 ?vIndividual . \n" + " ?vIndividual vcard:hasTitle ?vTitle . \n" - + " ?vTitle vcard:title ?pt . \n" + "} LIMIT 1"; - + + " ?vTitle vcard:title ?pt . \n" + + " FILTER (lang(?pt) = '?langCtx' ) \n" + + " } LIMIT 1"; private static final String FAKE_VIVO_PEOPLE_DATA_GETTER_URI = "http://FakeVivoPeopleDataGetter"; private static OntModel fakeDisplayModel = initializeFakeDisplayModel(); @@ -467,7 +479,7 @@ private static OntModel initializeFakeDisplayModel() { Property saveToVarProperty = m .getProperty(DisplayVocabulary.SAVE_TO_VAR); - m.add(dataGetter, queryProperty, QUERY_STRING); + m.add(dataGetter, queryProperty, QUERY_STRING_LANG); //UQAM Using query with linguistic context m.add(dataGetter, saveToVarProperty, "extra"); return m; } @@ -475,18 +487,21 @@ private static OntModel initializeFakeDisplayModel() { private String individualUri; private VitroRequest vreq; private ServletContext ctx; + private String langCtx = "en-US"; public FakeVivoPeopleDataGetter(VitroRequest vreq, String individualUri) { - super(vreq, fakeDisplayModel, "http://FakeVivoPeopleDataGetter"); + super(vreq, initializeFakeDisplayModel(), "http://FakeVivoPeopleDataGetter"); this.individualUri = individualUri; this.vreq = vreq; this.ctx = vreq.getSession().getServletContext(); + this.langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); // UQAM add the linguistic context } @Override public Map getData(Map pageData) { Map parms = new HashMap<>(); parms.put("uri", individualUri); + parms.put("langCtx", langCtx); //UQAM add the linguistic context return super.getData(parms); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java index 00fdcf1b0c..be09c3623f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java @@ -534,8 +534,12 @@ private void readFile(File f, OntModel om, String path) { try { if (f.getName().endsWith(".md")) { // Markdown files are documentation - skip. - } else if (f.getName().endsWith(".n3")) { + // UQAM accept lower and upper case in fn extension + } else if (f.getName().toLowerCase().endsWith(".n3")) { om.read(fis, null, "N3"); + // UQAM Accept Turtle + } else if (f.getName().toLowerCase().endsWith(".ttl")) { + om.read(fis, null, "TURTLE"); } else { om.read(fis, null, "RDF/XML"); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java index 7c1da263e4..5df1680ee2 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java @@ -34,111 +34,111 @@ public class SparqlQueryDataGetter extends DataGetterBase implements DataGetter{ private final static Log log = LogFactory.getLog(SparqlQueryDataGetter.class); - private static final String queryPropertyURI = "<" + DisplayVocabulary.QUERY + ">"; - private static final String saveToVarPropertyURI= "<" + DisplayVocabulary.SAVE_TO_VAR+ ">"; - private static final String queryModelPropertyURI= "<" + DisplayVocabulary.QUERY_MODEL+ ">"; - - public static final String defaultVarNameForResults = "results"; - private static final String defaultTemplate = "menupage--defaultSparql.ftl"; - - String dataGetterURI; - String queryText; - String saveToVar; - String modelURI; - VitroRequest vreq; - ServletContext context; - - /** - * Constructor with display model and data getter URI that will be called by reflection. - */ - public SparqlQueryDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){ - this.configure(vreq, displayModel,dataGetterURI); - } + private static final String queryPropertyURI = "<" + DisplayVocabulary.QUERY + ">"; + private static final String saveToVarPropertyURI= "<" + DisplayVocabulary.SAVE_TO_VAR+ ">"; + private static final String queryModelPropertyURI= "<" + DisplayVocabulary.QUERY_MODEL+ ">"; + + public static final String defaultVarNameForResults = "results"; + private static final String defaultTemplate = "menupage--defaultSparql.ftl"; + + String dataGetterURI; + String queryText; + String saveToVar; + String modelURI; + VitroRequest vreq; + ServletContext context; + + /** + * Constructor with display model and data getter URI that will be called by reflection. + */ + public SparqlQueryDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){ + this.configure(vreq, displayModel,dataGetterURI); + } /** - * Configure this instance based on the URI and display model. - */ - @SuppressWarnings("hiding") + * Configure this instance based on the URI and display model. + */ + @SuppressWarnings("hiding") protected void configure(VitroRequest vreq, Model displayModel, String dataGetterURI) { - if( vreq == null ) - throw new IllegalArgumentException("VitroRequest may not be null."); - if( displayModel == null ) - throw new IllegalArgumentException("Display Model may not be null."); - if( dataGetterURI == null ) - throw new IllegalArgumentException("PageUri may not be null."); - - this.vreq = vreq; - this.context = vreq.getSession().getServletContext(); - this.dataGetterURI = dataGetterURI; - - QuerySolutionMap initBindings = new QuerySolutionMap(); - initBindings.add("dataGetterURI", ResourceFactory.createResource(this.dataGetterURI)); - - Query dataGetterConfigurationQuery = QueryFactory.create(dataGetterQuery) ; - displayModel.enterCriticalSection(Lock.READ); - try{ - QueryExecution qexec = QueryExecutionFactory.create( - dataGetterConfigurationQuery, displayModel, initBindings) ; - ResultSet res = qexec.execSelect(); - try{ - while( res.hasNext() ){ - QuerySolution soln = res.next(); - - //query is NOT OPTIONAL - Literal value = soln.getLiteral("query"); - if( dataGetterConfigurationQuery == null ) - log.error("no query defined for page " + this.dataGetterURI); - else - this.queryText = value.getLexicalForm(); - - //model is OPTIONAL - RDFNode node = soln.get("queryModel"); - if( node != null && node.isURIResource() ){ - this.modelURI = node.asResource().getURI(); - }else if( node != null && node.isLiteral() ){ - this.modelURI = node.asLiteral().getLexicalForm(); - }else{ - this.modelURI = null; - } - - //saveToVar is OPTIONAL - Literal saveTo = soln.getLiteral("saveToVar"); - if( saveTo != null && saveTo.isLiteral() ){ - this.saveToVar = saveTo.asLiteral().getLexicalForm(); - }else{ - this.saveToVar = defaultVarNameForResults; - } - } - }finally{ qexec.close(); } - }finally{ displayModel.leaveCriticalSection(); } - } - - /** - * Query to get the definition of the SparqlDataGetter for a given URI. - */ - private static final String dataGetterQuery = - "PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" + - "SELECT ?query ?saveToVar ?queryModel WHERE { \n" + - " ?dataGetterURI "+queryPropertyURI+" ?query . \n" + - " OPTIONAL{ ?dataGetterURI "+saveToVarPropertyURI+" ?saveToVar } \n " + - " OPTIONAL{ ?dataGetterURI "+queryModelPropertyURI+" ?queryModel } \n" + - "}"; - - - @Override - public Map getData(Map pageData) { - Map merged = mergeParameters(vreq.getParameterMap(), pageData); - - String boundQueryText = bindParameters(queryText, merged); - - if (modelURI != null) { - return doQueryOnModel(boundQueryText, getModel(context, vreq, modelURI)); - } else { - return doQueryOnRDFService(boundQueryText); - } - } - - /** Merge the pageData with the request parameters. PageData overrides. */ + if( vreq == null ) + throw new IllegalArgumentException("VitroRequest may not be null."); + if( displayModel == null ) + throw new IllegalArgumentException("Display Model may not be null."); + if( dataGetterURI == null ) + throw new IllegalArgumentException("PageUri may not be null."); + + this.vreq = vreq; + this.context = vreq.getSession().getServletContext(); + this.dataGetterURI = dataGetterURI; + + QuerySolutionMap initBindings = new QuerySolutionMap(); + initBindings.add("dataGetterURI", ResourceFactory.createResource(this.dataGetterURI)); + + Query dataGetterConfigurationQuery = QueryFactory.create(dataGetterQuery) ; + displayModel.enterCriticalSection(Lock.READ); + try{ + QueryExecution qexec = QueryExecutionFactory.create( + dataGetterConfigurationQuery, displayModel, initBindings) ; + ResultSet res = qexec.execSelect(); + try{ + while( res.hasNext() ){ + QuerySolution soln = res.next(); + + //query is NOT OPTIONAL + Literal value = soln.getLiteral("query"); + if( dataGetterConfigurationQuery == null ) + log.error("no query defined for page " + this.dataGetterURI); + else + this.queryText = value.getLexicalForm(); + + //model is OPTIONAL + RDFNode node = soln.get("queryModel"); + if( node != null && node.isURIResource() ){ + this.modelURI = node.asResource().getURI(); + }else if( node != null && node.isLiteral() ){ + this.modelURI = node.asLiteral().getLexicalForm(); + }else{ + this.modelURI = null; + } + + //saveToVar is OPTIONAL + Literal saveTo = soln.getLiteral("saveToVar"); + if( saveTo != null && saveTo.isLiteral() ){ + this.saveToVar = saveTo.asLiteral().getLexicalForm(); + }else{ + this.saveToVar = defaultVarNameForResults; + } + } + }finally{ qexec.close(); } + }finally{ displayModel.leaveCriticalSection(); } + } + + /** + * Query to get the definition of the SparqlDataGetter for a given URI. + */ + private static final String dataGetterQuery = + "PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" + + "SELECT ?query ?saveToVar ?queryModel WHERE { \n" + + " ?dataGetterURI "+queryPropertyURI+" ?query . \n" + + " OPTIONAL{ ?dataGetterURI "+saveToVarPropertyURI+" ?saveToVar } \n " + + " OPTIONAL{ ?dataGetterURI "+queryModelPropertyURI+" ?queryModel } \n" + + "}"; + + + @Override + public Map getData(Map pageData) { + Map merged = mergeParameters(vreq.getParameterMap(), pageData); + + String boundQueryText = bindParameters(queryText, merged); + + if (modelURI != null) { + return doQueryOnModel(boundQueryText, getModel(context, vreq, modelURI)); + } else { + return doQueryOnRDFService(boundQueryText); + } + } + + /** Merge the pageData with the request parameters. PageData overrides. */ private Map mergeParameters( Map parameterMap, Map pageData) { Map merged = new HashMap<>(); @@ -165,7 +165,16 @@ private Map mergeParameters( private String bindParameters(String text, Map merged) { String bound = text; for (String key : merged.keySet()) { - bound = bound.replaceAll("([?$]" + key + ")([^a-zA-Z0-9_\\-])", "<" + merged.get(key) + ">$2"); + String value = merged.get(key); + if (value.startsWith("http:")) { + /* + * UQAM if the "value" looks like an URI then wrap the value with the characters '<' '>' + * + */ + bound = bound.replaceAll("([?$]" + key + ")([^a-zA-Z0-9_\\-])", "<" + value + ">$2"); + } else { + bound = bound.replaceAll("([?$]" + key + ")([^a-zA-Z0-9_\\-])", value + "$2"); + } } if (log.isDebugEnabled()) { log.debug("parameters: " + merged); @@ -181,27 +190,27 @@ private String bindParameters(String text, Map merged) { */ protected Map doQueryOnRDFService(String q) { log.debug("Going to RDFService with " + q); - ResultSet results = QueryUtils.getQueryResults(q, vreq); - return assembleMap(parseResults(results)); + ResultSet results = QueryUtils.getQueryResults(q, vreq); + return assembleMap(parseResults(results)); } - /** + /** * Do the query and return a result. This is in its own method, with * protected access, to make testing easy. */ - protected Map doQueryOnModel(String q, Model queryModel){ + protected Map doQueryOnModel(String q, Model queryModel){ log.debug("Going to model " + modelURI + " with " + q); - if (q == null) { - return Collections.emptyMap(); - } + if (q == null) { + return Collections.emptyMap(); + } Query query = makeQuery(q); - if (query == null) { - return Collections.emptyMap(); - } + if (query == null) { + return Collections.emptyMap(); + } - return assembleMap(executeQuery( query, queryModel)); - } + return assembleMap(executeQuery( query, queryModel)); + } private Query makeQuery(String q) { try { @@ -213,69 +222,69 @@ private Query makeQuery(String q) { } private List> executeQuery(Query query, Model model) { - model.enterCriticalSection(Lock.READ); - try{ - QueryExecution qexec= QueryExecutionFactory.create(query, model ); - ResultSet results = qexec.execSelect(); - try{ - return parseResults(results); - }finally{ qexec.close(); } - }finally{ model.leaveCriticalSection(); } - } - - /** - * Converts a ResultSet into a List of Maps. + model.enterCriticalSection(Lock.READ); + try{ + QueryExecution qexec= QueryExecutionFactory.create(query, model ); + ResultSet results = qexec.execSelect(); + try{ + return parseResults(results); + }finally{ qexec.close(); } + }finally{ model.leaveCriticalSection(); } + } + + /** + * Converts a ResultSet into a List of Maps. */ private List> parseResults(ResultSet results) { - List> rows = new ArrayList>(); - while (results.hasNext()) { - QuerySolution soln = results.nextSolution(); - rows.add( toRow( soln ) ); - } - return rows; + List> rows = new ArrayList>(); + while (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + rows.add( toRow( soln ) ); + } + return rows; } /** - * Converts a row from a QuerySolution to a Map - */ - private Map toRow(QuerySolution soln) { - HashMap row = new HashMap(); - Iterator varNames = soln.varNames(); - while( varNames.hasNext()){ - String varname = varNames.next(); - row.put(varname, toCell( soln.get(varname))); - } - return row; - } - - private String toCell(RDFNode rdfNode) { - if( rdfNode == null){ - return ""; - }else if( rdfNode.isLiteral() ){ - return rdfNode.asLiteral().getLexicalForm(); - }else if( rdfNode.isResource() ){ - Resource resource = (Resource)rdfNode; - if( ! resource.isAnon() ){ - return resource.getURI(); - }else{ - return resource.getId().getLabelString(); - } - }else{ - return rdfNode.toString(); - } - } + * Converts a row from a QuerySolution to a Map + */ + private Map toRow(QuerySolution soln) { + HashMap row = new HashMap(); + Iterator varNames = soln.varNames(); + while( varNames.hasNext()){ + String varname = varNames.next(); + row.put(varname, toCell( soln.get(varname))); + } + return row; + } + + private String toCell(RDFNode rdfNode) { + if( rdfNode == null){ + return ""; + }else if( rdfNode.isLiteral() ){ + return rdfNode.asLiteral().getLexicalForm(); + }else if( rdfNode.isResource() ){ + Resource resource = (Resource)rdfNode; + if( ! resource.isAnon() ){ + return resource.getURI(); + }else{ + return resource.getId().getLabelString(); + } + }else{ + return rdfNode.toString(); + } + } private Map assembleMap(List> results) { Map rmap = new HashMap(); - //put results in page data - rmap.put(this.saveToVar, results); - //also store the variable name within which results will be returned - rmap.put("variableName", this.saveToVar); - //This will be overridden at page level in display model if template specified there - rmap.put("bodyTemplate", defaultTemplate); + //put results in page data + rmap.put(this.saveToVar, results); + //also store the variable name within which results will be returned + rmap.put("variableName", this.saveToVar); + //This will be overridden at page level in display model if template specified there + rmap.put("bodyTemplate", defaultTemplate); - return rmap; + return rmap; } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java index d0ff197f71..0c080102bf 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java @@ -21,6 +21,10 @@ * check their current status. */ public class VitroBackgroundThread extends Thread { + // UQAM add start + public synchronized void start() { + super.start(); + } private static final Log log = LogFactory.getLog(VitroBackgroundThread.class); private static final ConcurrentLinkedQueue> allThreads = new ConcurrentLinkedQueue>(); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java index 7f88848ecf..1a92035b33 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java @@ -39,6 +39,9 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo; import edu.cornell.mannlib.vitro.webapp.i18n.I18n; import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption; +import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.PolicyOption; import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyStatementTemplateModel; @@ -98,7 +101,9 @@ private void retrieveEditData() throws Exception { private void populateDropdowns() throws Exception { //For each field with an optionType defined, create the options - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); +// WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + // UQAM Manage Linguistic context + WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); for(String fieldName: editConfig.getFields().keySet()){ FieldVTwo field = editConfig.getField(fieldName); //TODO: Check if we even need empty options if field options do not exist @@ -106,7 +111,9 @@ private void populateDropdowns() throws Exception { //empty options field.setOptions(new ConstantFieldOptions()); } + //UQAM changing signature for including internationalization in scroll-down menu Map optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf); +// Map optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, vreq); optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap, field.getFieldOptions().getCustomComparator(), vreq); if(pageData.containsKey(fieldName)) { log.error("Check the edit configuration setup as pageData already contains " + fieldName + " and this will be overwritten now with empty collection"); @@ -184,7 +191,7 @@ public String getObjectPropertyNameForDisplay() { Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq); ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq); Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq); - VClass rangeClass = EditConfigurationUtils.getRangeVClass(vreq); + VClass rangeClass = EditConfigurationUtils.getLangAwardRangeVClass(vreq); if(objectIndividual != null) { propertyTitle = prop.getDomainPublic(); } else { @@ -529,14 +536,17 @@ private String getDataLiteralValuesFromParameter() { //TODO:Check where this logic should actually go, copied from input element formatting tag //Updating to enable multiple vclasses applicable to subject to be analyzed to understand possible range of types public Map getOfferTypesCreateNew() { - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); +// WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + // UQAM Manage Linguistic context + WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); ObjectProperty op = wdf.getObjectPropertyDao().getObjectPropertyByURI(editConfig.getPredicateUri()); Individual sub = wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri()); - VClass rangeClass = EditConfigurationUtils.getRangeVClass(vreq); + // UQAM Manage Linguistic context + VClass rangeClass = EditConfigurationUtils.getLangAwardRangeVClass(vreq); List vclasses = null; List subjectVClasses = sub.getVClasses(); From 1cb9a1da52c12b7533dc564c99e76bf5955e4e76 Mon Sep 17 00:00:00 2001 From: Nicolas D <46490666+nicalico@users.noreply.github.com> Date: Fri, 27 Mar 2020 14:39:33 -0400 Subject: [PATCH 02/52] Update RDFServiceFactorySingle.java --- .../impl/RDFServiceFactorySingle.java | 410 +++++++++--------- 1 file changed, 204 insertions(+), 206 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java index 0b6e92faaf..fc9ef4c3df 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java @@ -26,215 +26,213 @@ */ public class RDFServiceFactorySingle implements RDFServiceFactory { - private RDFService rdfService; - - public RDFServiceFactorySingle(RDFService rdfService) { - this.rdfService = new UnclosableRDFService(rdfService); - } - - @Override - public RDFService getRDFService() { - return this.rdfService; - } - - @Override - public RDFService getShortTermRDFService() { - return this.rdfService; - } - - @Override - public void registerListener(ChangeListener listener) throws RDFServiceException { - this.rdfService.registerListener(listener); - } - - @Override - public void unregisterListener(ChangeListener listener) throws RDFServiceException { - this.rdfService.unregisterListener(listener); - } - - @Override - public void registerJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { - this.rdfService.registerJenaModelChangedListener(listener); - } - - @Override - public void unregisterJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { - this.rdfService.unregisterJenaModelChangedListener(listener); - } - - public class UnclosableRDFService implements RDFService { - - private RDFService s; - - public UnclosableRDFService(RDFService rdfService) { - this.s = rdfService; - } - - @Override - public boolean changeSetUpdate(ChangeSet changeSet) - throws RDFServiceException { - return s.changeSetUpdate(changeSet); - } - - @Override - public void newIndividual(String individualURI, String individualTypeURI) - throws RDFServiceException { - s.newIndividual(individualURI, individualTypeURI); - } - - @Override - public void newIndividual(String individualURI, - String individualTypeURI, String graphURI) - throws RDFServiceException { - s.newIndividual(individualURI, individualTypeURI, graphURI); - } - - @Override - public InputStream sparqlConstructQuery(String query, - ModelSerializationFormat resultFormat) - throws RDFServiceException { - return s.sparqlConstructQuery(query, resultFormat); - } - - @Override - public void sparqlConstructQuery(String query, Model model) - throws RDFServiceException { - s.sparqlConstructQuery(query, model); - } - - @Override - public InputStream sparqlDescribeQuery(String query, - ModelSerializationFormat resultFormat) - throws RDFServiceException { - return s.sparqlDescribeQuery(query, resultFormat); - } - - @Override - public InputStream sparqlSelectQuery(String query, - ResultFormat resultFormat) throws RDFServiceException { - return s.sparqlSelectQuery(query, resultFormat); - } - - @Override - public void sparqlSelectQuery(String query, ResultSetConsumer consumer) throws RDFServiceException { - s.sparqlSelectQuery(query, consumer); - } - - @Override - public boolean sparqlAskQuery(String query) throws RDFServiceException { - return s.sparqlAskQuery(query); - } - - @Override - public List getGraphURIs() throws RDFServiceException { - return s.getGraphURIs(); - } - - @Override - public void getGraphMetadata() throws RDFServiceException { - s.getGraphMetadata(); - } - - @Override - public String getDefaultWriteGraphURI() throws RDFServiceException { - return s.getDefaultWriteGraphURI(); - } - - @Override - public void serializeAll(OutputStream outputStream) - throws RDFServiceException { - s.serializeAll(outputStream); - } - - @Override - public void serializeGraph(String graphURI, OutputStream outputStream) - throws RDFServiceException { - s.serializeGraph(graphURI, outputStream); - } - - @Override - public boolean isEquivalentGraph(String graphURI, - InputStream serializedGraph, - ModelSerializationFormat serializationFormat) throws RDFServiceException { - return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat); - } - - @Override - public boolean isEquivalentGraph(String graphURI, - Model graph) throws RDFServiceException { - return s.isEquivalentGraph(graphURI, graph); - } - - @Override - public void registerListener(ChangeListener changeListener) - throws RDFServiceException { - s.registerListener(changeListener); - } - - @Override - public void unregisterListener(ChangeListener changeListener) - throws RDFServiceException { - s.unregisterListener(changeListener); - } - - @Override - public void registerJenaModelChangedListener(ModelChangedListener changeListener) - throws RDFServiceException { - s.registerJenaModelChangedListener(changeListener); - } - - @Override - public void unregisterJenaModelChangedListener(ModelChangedListener changeListener) - throws RDFServiceException { - s.unregisterJenaModelChangedListener(changeListener); - } - - @Override - public ChangeSet manufactureChangeSet() { - return s.manufactureChangeSet(); - } - - @Override - public long countTriples(RDFNode subject, RDFNode predicate, RDFNode object) throws RDFServiceException { - return s.countTriples(subject, predicate, object); - } - - @Override - public Model getTriples(RDFNode subject, RDFNode predicate, RDFNode object, long limit, long offset) throws RDFServiceException { - return s.getTriples(subject, predicate, object, limit, offset); - } - - @Override - public boolean preferPreciseOptionals() { - return s.preferPreciseOptionals(); - } - - @Override - public void close() { - // Don't close s. It's being used by everybody. - } + private RDFService rdfService; + + public RDFServiceFactorySingle(RDFService rdfService) { + this.rdfService = new UnclosableRDFService(rdfService); + } + + @Override + public RDFService getRDFService() { + return this.rdfService; + } + + @Override + public RDFService getShortTermRDFService() { + return this.rdfService; + } + + @Override + public void registerListener(ChangeListener listener) throws RDFServiceException { + this.rdfService.registerListener(listener); + } + + @Override + public void unregisterListener(ChangeListener listener) throws RDFServiceException { + this.rdfService.unregisterListener(listener); + } + + @Override + public void registerJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { + this.rdfService.registerJenaModelChangedListener(listener); + } + + @Override + public void unregisterJenaModelChangedListener(ModelChangedListener listener) throws RDFServiceException { + this.rdfService.unregisterJenaModelChangedListener(listener); + } + + public class UnclosableRDFService implements RDFService { + + private RDFService s; + + public UnclosableRDFService(RDFService rdfService) { + this.s = rdfService; + } + + @Override + public boolean changeSetUpdate(ChangeSet changeSet) + throws RDFServiceException { + return s.changeSetUpdate(changeSet); + } + + @Override + public void newIndividual(String individualURI, String individualTypeURI) + throws RDFServiceException { + s.newIndividual(individualURI, individualTypeURI); + } + + @Override + public void newIndividual(String individualURI, + String individualTypeURI, String graphURI) + throws RDFServiceException { + s.newIndividual(individualURI, individualTypeURI, graphURI); + } + + @Override + public InputStream sparqlConstructQuery(String query, + ModelSerializationFormat resultFormat) + throws RDFServiceException { + return s.sparqlConstructQuery(query, resultFormat); + } + + @Override + public void sparqlConstructQuery(String query, Model model) + throws RDFServiceException { + s.sparqlConstructQuery(query, model); + } + + @Override + public InputStream sparqlDescribeQuery(String query, + ModelSerializationFormat resultFormat) + throws RDFServiceException { + return s.sparqlDescribeQuery(query, resultFormat); + } + + @Override + public InputStream sparqlSelectQuery(String query, + ResultFormat resultFormat) throws RDFServiceException { + return s.sparqlSelectQuery(query, resultFormat); + } + + @Override + public void sparqlSelectQuery(String query, ResultSetConsumer consumer) throws RDFServiceException { + s.sparqlSelectQuery(query, consumer); + } + + @Override + public boolean sparqlAskQuery(String query) throws RDFServiceException { + return s.sparqlAskQuery(query); + } + + @Override + public List getGraphURIs() throws RDFServiceException { + return s.getGraphURIs(); + } + + @Override + public void getGraphMetadata() throws RDFServiceException { + s.getGraphMetadata(); + } + + @Override + public String getDefaultWriteGraphURI() throws RDFServiceException { + return s.getDefaultWriteGraphURI(); + } + + @Override + public void serializeAll(OutputStream outputStream) + throws RDFServiceException { + s.serializeAll(outputStream); + } + + @Override + public void serializeGraph(String graphURI, OutputStream outputStream) + throws RDFServiceException { + s.serializeGraph(graphURI, outputStream); + } + + @Override + public boolean isEquivalentGraph(String graphURI, + InputStream serializedGraph, + ModelSerializationFormat serializationFormat) throws RDFServiceException { + return s.isEquivalentGraph(graphURI, serializedGraph, serializationFormat); + } + + @Override + public boolean isEquivalentGraph(String graphURI, + Model graph) throws RDFServiceException { + return s.isEquivalentGraph(graphURI, graph); + } + + @Override + public void registerListener(ChangeListener changeListener) + throws RDFServiceException { + s.registerListener(changeListener); + } + + @Override + public void unregisterListener(ChangeListener changeListener) + throws RDFServiceException { + s.unregisterListener(changeListener); + } + + @Override + public void registerJenaModelChangedListener(ModelChangedListener changeListener) + throws RDFServiceException { + s.registerJenaModelChangedListener(changeListener); + } + + @Override + public void unregisterJenaModelChangedListener(ModelChangedListener changeListener) + throws RDFServiceException { + s.unregisterJenaModelChangedListener(changeListener); + } + + @Override + public ChangeSet manufactureChangeSet() { + return s.manufactureChangeSet(); + } + + @Override + public long countTriples(RDFNode subject, RDFNode predicate, RDFNode object) throws RDFServiceException { + return s.countTriples(subject, predicate, object); + } + + @Override + public Model getTriples(RDFNode subject, RDFNode predicate, RDFNode object, long limit, long offset) throws RDFServiceException { + return s.getTriples(subject, predicate, object, limit, offset); + } + + @Override + public boolean preferPreciseOptionals() { + return s.preferPreciseOptionals(); + } + + @Override + public void close() { + // Don't close s. It's being used by everybody. + } @Override public String toString() { return ToString.simpleName(this) + "[" + ToString.hashHex(this) - + ", inner=" + s + "]"; - } - /* - * UQAM Useful among other things to transport the linguistic context in the service - * (non-Javadoc) - * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) - */ - private VitroRequest vitroRequest; - - public void setVitroRequest(VitroRequest vitroRequest) { - this.vitroRequest = vitroRequest; - } - - public VitroRequest getVitroRequest() { - return vitroRequest; - } - - - } + + ", inner=" + s + "]"; + } + /* + * UQAM Useful among other things to transport the linguistic context in the service + * (non-Javadoc) + * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) + */ + private VitroRequest vitroRequest; + + public void setVitroRequest(VitroRequest vitroRequest) { + this.vitroRequest = vitroRequest; + } + + public VitroRequest getVitroRequest() { + return vitroRequest; + } + } } From 1f7998b4c14e8d67bc800af7335021bf0518507f Mon Sep 17 00:00:00 2001 From: VIVO UQAM <62542918+UQAM-VIVO@users.noreply.github.com> Date: Mon, 30 Mar 2020 10:12:18 -0400 Subject: [PATCH 03/52] Sprint i18n whitespace (#143) * Removed extraneous whitespace - modified: api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java * move RootUserPolicy.java from VIVO to Vitro repo. --- .../webapp/auth/policy/RootUserPolicy.java | 38 ++++++++++++++++++- .../n3editing/VTwo/BaseEditElementVTwo.java | 8 +--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java index e724361524..466988967a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java @@ -37,7 +37,14 @@ public class RootUserPolicy implements PolicyIface { private static final Log log = LogFactory.getLog(RootUserPolicy.class); private static final String PROPERTY_ROOT_USER_EMAIL = "rootUser.emailAddress"; + /* + * UQAM For parameterization of rootUser + */ + private static final String PROPERTY_ROOT_USER_PASSWORD = "rootUser.password"; + private static final String PROPERTY_ROOT_USER_PASSWORD_CHANGE_REQUIRED = "rootUser.passwordChangeRequired"; + private static final String ROOT_USER_INITIAL_PASSWORD = "rootPassword"; + private static final String ROOT_USER_INITIAL_PASSWORD_CHANGE_REQUIRED = "true"; /** * This is the entire policy. If you are a root user, you are authorized. @@ -150,10 +157,13 @@ private void createRootUser() { ua.setEmailAddress(configuredRootUser); ua.setFirstName("root"); ua.setLastName("user"); + // UQAM using getRootPasswordFromConfig() ua.setArgon2Password(Authenticator.applyArgon2iEncoding( - ROOT_USER_INITIAL_PASSWORD)); + getRootPasswordFromConfig())); ua.setMd5Password(""); - ua.setPasswordChangeRequired(true); + Boolean toto; + // UQAM using getRootPasswdChangeRequiredFromConfig() + ua.setPasswordChangeRequired(getRootPasswdChangeRequiredFromConfig().booleanValue()); ua.setStatus(Status.ACTIVE); ua.setRootUser(true); @@ -191,7 +201,31 @@ private void complainAboutWrongRootUsers() { ss.warning(this, "For security, " + "it is best to delete unneeded root user accounts."); } + /* + * UQAM + * Add for getting rootUser.password property value from runtime.properties + */ + private String getRootPasswordFromConfig() { + String passwd = ConfigurationProperties.getBean(ctx).getProperty( + PROPERTY_ROOT_USER_PASSWORD); + if (passwd == null) { + passwd = ROOT_USER_INITIAL_PASSWORD; + } + return passwd; + } + /* + * UQAM + * Add for getting rootUser.passwordChangeRequired property value from runtime.properties + */ + private Boolean getRootPasswdChangeRequiredFromConfig() { + String passwdCR = ConfigurationProperties.getBean(ctx).getProperty( + PROPERTY_ROOT_USER_PASSWORD_CHANGE_REQUIRED); + if (passwdCR == null) { + passwdCR = ROOT_USER_INITIAL_PASSWORD_CHANGE_REQUIRED; + } + return new Boolean(passwdCR); + } @Override public void contextDestroyed(ServletContextEvent sce) { // Nothing to destroy diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java index eb46ac1b96..a3e90d0836 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/BaseEditElementVTwo.java @@ -4,9 +4,6 @@ import java.io.IOException; import java.io.StringWriter; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.Map; import org.apache.commons.logging.Log; @@ -47,10 +44,7 @@ protected String merge(Configuration fmConfig, String templateName, Map map){ } catch (TemplateException | IOException e) { log.error(e,e); } - String sWrite = writer.toString(); - - // String UTF8String = new String(sWrite.getBytes(), Charset.forName("UTF-8")); - return sWrite; + return writer.toString(); } /** From be6ef1323d04b943037f26c1fa1b846ad13d8099 Mon Sep 17 00:00:00 2001 From: Nicolas D <46490666+nicalico@users.noreply.github.com> Date: Mon, 30 Mar 2020 10:57:03 -0400 Subject: [PATCH 04/52] Remove blank line --- .../vitro/webapp/controller/freemarker/HomePageController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java index 40472bf34f..6f59dbd429 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/HomePageController.java @@ -32,7 +32,6 @@ protected ResponseValues processRequest(VitroRequest vreq) throws InstantiationE Map body = new HashMap(); - List dgList = DataGetterUtils.getDataGettersForPage(vreq, vreq.getDisplayModel(), DisplayVocabulary.HOME_PAGE_URI); for( DataGetter dg : dgList){ From 9ae724073c286dea363c77a71bc263f4f845e9cd Mon Sep 17 00:00:00 2001 From: Nicolas D <46490666+nicalico@users.noreply.github.com> Date: Mon, 30 Mar 2020 12:11:02 -0400 Subject: [PATCH 05/52] Fixed indentations --- .../shortview/FakeApplicationOntologyService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java index fd8c4f5cbf..b488cfc7b5 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java @@ -185,7 +185,7 @@ private List contextsFromNames(Resource view, */ private Map> createClassMappings( Map viewSpecsByUri) - throws ShortViewConfigException { + throws ShortViewConfigException { Property hasView = viewModel.getProperty(HAS_VIEW); StmtIterator stmts = viewModel.listStatements(null, hasView, @@ -487,21 +487,21 @@ private static OntModel initializeFakeDisplayModel() { private String individualUri; private VitroRequest vreq; private ServletContext ctx; - private String langCtx = "en-US"; + private String langCtx = "en-US"; public FakeVivoPeopleDataGetter(VitroRequest vreq, String individualUri) { super(vreq, initializeFakeDisplayModel(), "http://FakeVivoPeopleDataGetter"); this.individualUri = individualUri; this.vreq = vreq; this.ctx = vreq.getSession().getServletContext(); - this.langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); // UQAM add the linguistic context + this.langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); // UQAM add the linguistic context } @Override public Map getData(Map pageData) { Map parms = new HashMap<>(); parms.put("uri", individualUri); - parms.put("langCtx", langCtx); //UQAM add the linguistic context + parms.put("langCtx", langCtx); //UQAM add the linguistic context return super.getData(parms); } From 0a2403c002eec7d1936093cabb7e63ea75c3e1cb Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Mon, 30 Mar 2020 15:50:22 -0400 Subject: [PATCH 06/52] Update whitespace for: TemplateProcessingHelper.java --- .../controller/freemarker/TemplateProcessingHelper.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java index 0159a72746..6f66940354 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.nio.charset.StandardCharsets; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -34,8 +33,6 @@ public StringWriter processTemplate(String templateName, Map map throws TemplateProcessingException { Template template = getTemplate(templateName); StringWriter sw = new StringWriter(); - - processTemplate(template, map, sw); return sw; } @@ -60,7 +57,6 @@ private void processTemplate(Template template, Map map, Writer // TODO clean this up VIVO-249 FreemarkerConfigurationImpl.retrieveAndRunDataGetters(env, template.getName()); - // Now process it. env.process(); } catch (TemplateException e) { From 771df103264414a1f167ee53c716fff73e1e2b95 Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Mon, 30 Mar 2020 17:11:52 -0400 Subject: [PATCH 07/52] Update whitespace for: RDFServiceModel.java --- .../impl/jena/model/RDFServiceModel.java | 194 +++++++++--------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java index 864156a52b..fc7c6249f6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java @@ -23,103 +23,103 @@ public class RDFServiceModel extends RDFServiceJena implements RDFService { - private final static Log log = LogFactory.getLog(RDFServiceModel.class); - - private Model model; - private Dataset dataset; - private String modelName; - - /** - * Create an RDFService to access a single default graph - * @param model Jena Model - */ - public RDFServiceModel(Model model) { - this.model = model; - } - - /** - * Create an RDFService to access a Jena Dataset - * @param dataset Jena Dataset - */ - public RDFServiceModel(Dataset dataset) { - this.dataset = dataset; - } - - @Override - protected DatasetWrapper getDatasetWrapper() { - Dataset d = null; - if (dataset != null) { - d = dataset; - } else { - d = DatasetFactory.createMem(); - if (modelName == null) { - d.setDefaultModel(this.model); - } else { - d.addNamedModel(this.modelName, model); - } - } - DatasetWrapper datasetWrapper = new DatasetWrapper(d); - return datasetWrapper; - } - - @Override - public boolean changeSetUpdate(ChangeSet changeSet) - throws RDFServiceException { - - if (changeSet.getPreconditionQuery() != null - && !isPreconditionSatisfied( - changeSet.getPreconditionQuery(), - changeSet.getPreconditionQueryType())) { - return false; - } - - //Dataset dataset = getDatasetWrapper().getDataset(); - - try { - for (Object o : changeSet.getPreChangeEvents()) { - this.notifyListenersOfEvent(o); - } - - for (ModelChange modelChange : changeSet.getModelChanges()) { - if (!modelChange.getSerializedModel().markSupported()) { - byte[] bytes = IOUtils.toByteArray(modelChange.getSerializedModel()); - modelChange.setSerializedModel(new ByteArrayInputStream(bytes)); - } - modelChange.getSerializedModel().mark(Integer.MAX_VALUE); - Model m = this.model; - if (m == null && dataset != null) { - String changeGraphURI = modelChange.getGraphURI(); - if (changeGraphURI != null) { - m = dataset.getNamedModel(changeGraphURI); - } else { - m = dataset.getDefaultModel(); - } - } - operateOnModel(m, modelChange, null); - } - - // notify listeners of triple changes - notifyListenersOfChanges(changeSet); - // csIt = changeSet.getModelChanges().iterator(); - // while (csIt.hasNext()) { - // ModelChange modelChange = csIt.next(); - // modelChange.getSerializedModel().reset(); - // Model model = ModelFactory.createModelForGraph( - // new ListeningGraph(modelChange.getGraphURI(), this)); - // operateOnModel(model, modelChange, null); - // } - - for (Object o : changeSet.getPostChangeEvents()) { - this.notifyListenersOfEvent(o); - } - - } catch (Exception e) { - log.error(e, e); - throw new RDFServiceException(e); - } - - return true; - } + private final static Log log = LogFactory.getLog(RDFServiceModel.class); + + private Model model; + private Dataset dataset; + private String modelName; + + /** + * Create an RDFService to access a single default graph + * @param model Jena Model + */ + public RDFServiceModel(Model model) { + this.model = model; + } + + /** + * Create an RDFService to access a Jena Dataset + * @param dataset Jena Dataset + */ + public RDFServiceModel(Dataset dataset) { + this.dataset = dataset; + } + + @Override + protected DatasetWrapper getDatasetWrapper() { + Dataset d = null; + if (dataset != null) { + d = dataset; + } else { + d = DatasetFactory.createMem(); + if (modelName == null) { + d.setDefaultModel(this.model); + } else { + d.addNamedModel(this.modelName, model); + } + } + DatasetWrapper datasetWrapper = new DatasetWrapper(d); + return datasetWrapper; + } + + @Override + public boolean changeSetUpdate(ChangeSet changeSet) + throws RDFServiceException { + + if (changeSet.getPreconditionQuery() != null + && !isPreconditionSatisfied( + changeSet.getPreconditionQuery(), + changeSet.getPreconditionQueryType())) { + return false; + } + + //Dataset dataset = getDatasetWrapper().getDataset(); + + try { + for (Object o : changeSet.getPreChangeEvents()) { + this.notifyListenersOfEvent(o); + } + + for (ModelChange modelChange : changeSet.getModelChanges()) { + if (!modelChange.getSerializedModel().markSupported()) { + byte[] bytes = IOUtils.toByteArray(modelChange.getSerializedModel()); + modelChange.setSerializedModel(new ByteArrayInputStream(bytes)); + } + modelChange.getSerializedModel().mark(Integer.MAX_VALUE); + Model m = this.model; + if (m == null && dataset != null) { + String changeGraphURI = modelChange.getGraphURI(); + if (changeGraphURI != null) { + m = dataset.getNamedModel(changeGraphURI); + } else { + m = dataset.getDefaultModel(); + } + } + operateOnModel(m, modelChange, null); + } + + // notify listeners of triple changes + notifyListenersOfChanges(changeSet); +// csIt = changeSet.getModelChanges().iterator(); +// while (csIt.hasNext()) { +// ModelChange modelChange = csIt.next(); +// modelChange.getSerializedModel().reset(); +// Model model = ModelFactory.createModelForGraph( +// new ListeningGraph(modelChange.getGraphURI(), this)); +// operateOnModel(model, modelChange, null); +// } + + for (Object o : changeSet.getPostChangeEvents()) { + this.notifyListenersOfEvent(o); + } + + } catch (Exception e) { + log.error(e, e); + throw new RDFServiceException(e); + } + + return true; + } /* * UQAM Useful among other things to transport the linguistic context in the service * (non-Javadoc) From 66c50255a9418889cb40197326fdb8da920d3de3 Mon Sep 17 00:00:00 2001 From: Matthias Luehr Date: Thu, 2 Apr 2020 20:23:48 +0200 Subject: [PATCH 08/52] Removed extraneous whitespaces. --- .../vitro/webapp/dao/jena/JenaBaseDao.java | 1 - .../dataGetter/SparqlQueryDataGetter.java | 334 +++++++++--------- 2 files changed, 167 insertions(+), 168 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java index 5713d2e5fc..d92c901360 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java @@ -1,6 +1,5 @@ /* $This file is distributed under the terms of the license in LICENSE$ */ -// package edu.cornell.mannlib.vitro.webapp.dao.jena; import java.text.DateFormat; diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java index 5df1680ee2..0de494abd9 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java @@ -34,111 +34,111 @@ public class SparqlQueryDataGetter extends DataGetterBase implements DataGetter{ private final static Log log = LogFactory.getLog(SparqlQueryDataGetter.class); - private static final String queryPropertyURI = "<" + DisplayVocabulary.QUERY + ">"; - private static final String saveToVarPropertyURI= "<" + DisplayVocabulary.SAVE_TO_VAR+ ">"; - private static final String queryModelPropertyURI= "<" + DisplayVocabulary.QUERY_MODEL+ ">"; - - public static final String defaultVarNameForResults = "results"; - private static final String defaultTemplate = "menupage--defaultSparql.ftl"; - - String dataGetterURI; - String queryText; - String saveToVar; - String modelURI; - VitroRequest vreq; - ServletContext context; + private static final String queryPropertyURI = "<" + DisplayVocabulary.QUERY + ">"; + private static final String saveToVarPropertyURI= "<" + DisplayVocabulary.SAVE_TO_VAR+ ">"; + private static final String queryModelPropertyURI= "<" + DisplayVocabulary.QUERY_MODEL+ ">"; + + public static final String defaultVarNameForResults = "results"; + private static final String defaultTemplate = "menupage--defaultSparql.ftl"; + + String dataGetterURI; + String queryText; + String saveToVar; + String modelURI; + VitroRequest vreq; + ServletContext context; + + /** + * Constructor with display model and data getter URI that will be called by reflection. + */ + public SparqlQueryDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){ + this.configure(vreq, displayModel,dataGetterURI); + } /** - * Constructor with display model and data getter URI that will be called by reflection. - */ - public SparqlQueryDataGetter(VitroRequest vreq, Model displayModel, String dataGetterURI){ - this.configure(vreq, displayModel,dataGetterURI); - } - - /** - * Configure this instance based on the URI and display model. - */ - @SuppressWarnings("hiding") + * Configure this instance based on the URI and display model. + */ + @SuppressWarnings("hiding") protected void configure(VitroRequest vreq, Model displayModel, String dataGetterURI) { - if( vreq == null ) - throw new IllegalArgumentException("VitroRequest may not be null."); - if( displayModel == null ) - throw new IllegalArgumentException("Display Model may not be null."); - if( dataGetterURI == null ) - throw new IllegalArgumentException("PageUri may not be null."); - - this.vreq = vreq; - this.context = vreq.getSession().getServletContext(); - this.dataGetterURI = dataGetterURI; - - QuerySolutionMap initBindings = new QuerySolutionMap(); - initBindings.add("dataGetterURI", ResourceFactory.createResource(this.dataGetterURI)); - - Query dataGetterConfigurationQuery = QueryFactory.create(dataGetterQuery) ; - displayModel.enterCriticalSection(Lock.READ); - try{ - QueryExecution qexec = QueryExecutionFactory.create( - dataGetterConfigurationQuery, displayModel, initBindings) ; - ResultSet res = qexec.execSelect(); - try{ - while( res.hasNext() ){ - QuerySolution soln = res.next(); - - //query is NOT OPTIONAL - Literal value = soln.getLiteral("query"); - if( dataGetterConfigurationQuery == null ) - log.error("no query defined for page " + this.dataGetterURI); - else - this.queryText = value.getLexicalForm(); - - //model is OPTIONAL - RDFNode node = soln.get("queryModel"); - if( node != null && node.isURIResource() ){ - this.modelURI = node.asResource().getURI(); - }else if( node != null && node.isLiteral() ){ - this.modelURI = node.asLiteral().getLexicalForm(); - }else{ - this.modelURI = null; - } - - //saveToVar is OPTIONAL - Literal saveTo = soln.getLiteral("saveToVar"); - if( saveTo != null && saveTo.isLiteral() ){ - this.saveToVar = saveTo.asLiteral().getLexicalForm(); - }else{ - this.saveToVar = defaultVarNameForResults; - } - } - }finally{ qexec.close(); } - }finally{ displayModel.leaveCriticalSection(); } - } - - /** - * Query to get the definition of the SparqlDataGetter for a given URI. - */ - private static final String dataGetterQuery = - "PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" + - "SELECT ?query ?saveToVar ?queryModel WHERE { \n" + - " ?dataGetterURI "+queryPropertyURI+" ?query . \n" + - " OPTIONAL{ ?dataGetterURI "+saveToVarPropertyURI+" ?saveToVar } \n " + - " OPTIONAL{ ?dataGetterURI "+queryModelPropertyURI+" ?queryModel } \n" + - "}"; - - - @Override - public Map getData(Map pageData) { - Map merged = mergeParameters(vreq.getParameterMap(), pageData); - - String boundQueryText = bindParameters(queryText, merged); - - if (modelURI != null) { - return doQueryOnModel(boundQueryText, getModel(context, vreq, modelURI)); - } else { - return doQueryOnRDFService(boundQueryText); - } - } - - /** Merge the pageData with the request parameters. PageData overrides. */ + if( vreq == null ) + throw new IllegalArgumentException("VitroRequest may not be null."); + if( displayModel == null ) + throw new IllegalArgumentException("Display Model may not be null."); + if( dataGetterURI == null ) + throw new IllegalArgumentException("PageUri may not be null."); + + this.vreq = vreq; + this.context = vreq.getSession().getServletContext(); + this.dataGetterURI = dataGetterURI; + + QuerySolutionMap initBindings = new QuerySolutionMap(); + initBindings.add("dataGetterURI", ResourceFactory.createResource(this.dataGetterURI)); + + Query dataGetterConfigurationQuery = QueryFactory.create(dataGetterQuery) ; + displayModel.enterCriticalSection(Lock.READ); + try{ + QueryExecution qexec = QueryExecutionFactory.create( + dataGetterConfigurationQuery, displayModel, initBindings) ; + ResultSet res = qexec.execSelect(); + try{ + while( res.hasNext() ){ + QuerySolution soln = res.next(); + + //query is NOT OPTIONAL + Literal value = soln.getLiteral("query"); + if( dataGetterConfigurationQuery == null ) + log.error("no query defined for page " + this.dataGetterURI); + else + this.queryText = value.getLexicalForm(); + + //model is OPTIONAL + RDFNode node = soln.get("queryModel"); + if( node != null && node.isURIResource() ){ + this.modelURI = node.asResource().getURI(); + }else if( node != null && node.isLiteral() ){ + this.modelURI = node.asLiteral().getLexicalForm(); + }else{ + this.modelURI = null; + } + + //saveToVar is OPTIONAL + Literal saveTo = soln.getLiteral("saveToVar"); + if( saveTo != null && saveTo.isLiteral() ){ + this.saveToVar = saveTo.asLiteral().getLexicalForm(); + }else{ + this.saveToVar = defaultVarNameForResults; + } + } + }finally{ qexec.close(); } + }finally{ displayModel.leaveCriticalSection(); } + } + + /** + * Query to get the definition of the SparqlDataGetter for a given URI. + */ + private static final String dataGetterQuery = + "PREFIX display: <" + DisplayVocabulary.DISPLAY_NS +"> \n" + + "SELECT ?query ?saveToVar ?queryModel WHERE { \n" + + " ?dataGetterURI "+queryPropertyURI+" ?query . \n" + + " OPTIONAL{ ?dataGetterURI "+saveToVarPropertyURI+" ?saveToVar } \n " + + " OPTIONAL{ ?dataGetterURI "+queryModelPropertyURI+" ?queryModel } \n" + + "}"; + + + @Override + public Map getData(Map pageData) { + Map merged = mergeParameters(vreq.getParameterMap(), pageData); + + String boundQueryText = bindParameters(queryText, merged); + + if (modelURI != null) { + return doQueryOnModel(boundQueryText, getModel(context, vreq, modelURI)); + } else { + return doQueryOnRDFService(boundQueryText); + } + } + + /** Merge the pageData with the request parameters. PageData overrides. */ private Map mergeParameters( Map parameterMap, Map pageData) { Map merged = new HashMap<>(); @@ -190,27 +190,27 @@ private String bindParameters(String text, Map merged) { */ protected Map doQueryOnRDFService(String q) { log.debug("Going to RDFService with " + q); - ResultSet results = QueryUtils.getQueryResults(q, vreq); - return assembleMap(parseResults(results)); + ResultSet results = QueryUtils.getQueryResults(q, vreq); + return assembleMap(parseResults(results)); } - /** + /** * Do the query and return a result. This is in its own method, with * protected access, to make testing easy. */ - protected Map doQueryOnModel(String q, Model queryModel){ + protected Map doQueryOnModel(String q, Model queryModel){ log.debug("Going to model " + modelURI + " with " + q); - if (q == null) { - return Collections.emptyMap(); - } + if (q == null) { + return Collections.emptyMap(); + } Query query = makeQuery(q); - if (query == null) { - return Collections.emptyMap(); - } + if (query == null) { + return Collections.emptyMap(); + } - return assembleMap(executeQuery( query, queryModel)); - } + return assembleMap(executeQuery( query, queryModel)); + } private Query makeQuery(String q) { try { @@ -222,69 +222,69 @@ private Query makeQuery(String q) { } private List> executeQuery(Query query, Model model) { - model.enterCriticalSection(Lock.READ); - try{ - QueryExecution qexec= QueryExecutionFactory.create(query, model ); - ResultSet results = qexec.execSelect(); - try{ - return parseResults(results); - }finally{ qexec.close(); } - }finally{ model.leaveCriticalSection(); } - } - - /** - * Converts a ResultSet into a List of Maps. + model.enterCriticalSection(Lock.READ); + try{ + QueryExecution qexec= QueryExecutionFactory.create(query, model ); + ResultSet results = qexec.execSelect(); + try{ + return parseResults(results); + }finally{ qexec.close(); } + }finally{ model.leaveCriticalSection(); } + } + + /** + * Converts a ResultSet into a List of Maps. */ private List> parseResults(ResultSet results) { - List> rows = new ArrayList>(); - while (results.hasNext()) { - QuerySolution soln = results.nextSolution(); - rows.add( toRow( soln ) ); - } - return rows; + List> rows = new ArrayList>(); + while (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + rows.add( toRow( soln ) ); + } + return rows; } /** - * Converts a row from a QuerySolution to a Map - */ - private Map toRow(QuerySolution soln) { - HashMap row = new HashMap(); - Iterator varNames = soln.varNames(); - while( varNames.hasNext()){ - String varname = varNames.next(); - row.put(varname, toCell( soln.get(varname))); - } - return row; - } - - private String toCell(RDFNode rdfNode) { - if( rdfNode == null){ - return ""; - }else if( rdfNode.isLiteral() ){ - return rdfNode.asLiteral().getLexicalForm(); - }else if( rdfNode.isResource() ){ - Resource resource = (Resource)rdfNode; - if( ! resource.isAnon() ){ - return resource.getURI(); - }else{ - return resource.getId().getLabelString(); - } - }else{ - return rdfNode.toString(); - } - } + * Converts a row from a QuerySolution to a Map + */ + private Map toRow(QuerySolution soln) { + HashMap row = new HashMap(); + Iterator varNames = soln.varNames(); + while( varNames.hasNext()){ + String varname = varNames.next(); + row.put(varname, toCell( soln.get(varname))); + } + return row; + } + + private String toCell(RDFNode rdfNode) { + if( rdfNode == null){ + return ""; + }else if( rdfNode.isLiteral() ){ + return rdfNode.asLiteral().getLexicalForm(); + }else if( rdfNode.isResource() ){ + Resource resource = (Resource)rdfNode; + if( ! resource.isAnon() ){ + return resource.getURI(); + }else{ + return resource.getId().getLabelString(); + } + }else{ + return rdfNode.toString(); + } + } private Map assembleMap(List> results) { Map rmap = new HashMap(); - //put results in page data - rmap.put(this.saveToVar, results); - //also store the variable name within which results will be returned - rmap.put("variableName", this.saveToVar); - //This will be overridden at page level in display model if template specified there - rmap.put("bodyTemplate", defaultTemplate); + //put results in page data + rmap.put(this.saveToVar, results); + //also store the variable name within which results will be returned + rmap.put("variableName", this.saveToVar); + //This will be overridden at page level in display model if template specified there + rmap.put("bodyTemplate", defaultTemplate); - return rmap; + return rmap; } } From 46b05bfa6ac5775216dd461a663da1430b384d10 Mon Sep 17 00:00:00 2001 From: michelheonuqam Date: Thu, 2 Apr 2020 06:37:34 -0400 Subject: [PATCH 09/52] Tagging UQAM Comments with following tags -Add-Feature -Optimization -Linguistic-Management -Bug-Correction --- .../vitro/webapp/auth/policy/RootUserPolicy.java | 11 +++++------ .../controller/freemarker/FreemarkerHttpServlet.java | 4 +--- .../freemarker/TemplateProcessingHelper.java | 6 +----- .../json/GetRandomSearchIndividualsByVClass.java | 4 ++-- .../mannlib/vitro/webapp/dao/jena/JenaBaseDao.java | 2 +- .../vitro/webapp/dao/jena/RDFServiceGraph.java | 2 +- .../mannlib/vitro/webapp/dao/jena/SparqlGraph.java | 2 +- .../edit/n3editing/VTwo/AdditionsAndRetractions.java | 2 +- .../edit/n3editing/VTwo/EditConfigurationUtils.java | 10 ++-------- .../VTwo/fields/ChildVClassesWithParent.java | 2 +- .../VTwo/fields/SelectListGeneratorVTwo.java | 4 ++-- .../DefaultObjectPropertyFormGenerator.java | 2 +- .../controller/PostEditCleanupController.java | 2 +- .../controller/ProcessRdfFormController.java | 2 +- .../vitro/webapp/filters/PageRoutingFilter.java | 4 ---- .../freemarker/config/FreemarkerConfiguration.java | 8 -------- .../mannlib/vitro/webapp/rdfservice/RDFService.java | 2 +- .../filter/LanguageFilteringRDFService.java | 2 +- .../rdfservice/impl/RDFServiceFactorySingle.java | 2 +- .../vitro/webapp/rdfservice/impl/RDFServiceImpl.java | 2 +- .../webapp/rdfservice/impl/jena/RDFServiceJena.java | 2 +- .../rdfservice/impl/jena/model/RDFServiceModel.java | 2 +- .../rdfservice/impl/logging/LoggingRDFService.java | 2 +- .../shortview/FakeApplicationOntologyService.java | 8 ++++---- .../webapp/servlet/setup/UpdateKnowledgeBase.java | 4 ++-- .../utils/dataGetter/SparqlQueryDataGetter.java | 2 +- .../webapp/utils/threads/VitroBackgroundThread.java | 2 +- .../edit/EditConfigurationTemplateModel.java | 8 ++++---- 28 files changed, 40 insertions(+), 65 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java index 466988967a..816bf7d515 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/auth/policy/RootUserPolicy.java @@ -38,7 +38,7 @@ public class RootUserPolicy implements PolicyIface { private static final String PROPERTY_ROOT_USER_EMAIL = "rootUser.emailAddress"; /* - * UQAM For parameterization of rootUser + * UQAM Add-Feature For parameterization of rootUser */ private static final String PROPERTY_ROOT_USER_PASSWORD = "rootUser.password"; private static final String PROPERTY_ROOT_USER_PASSWORD_CHANGE_REQUIRED = "rootUser.passwordChangeRequired"; @@ -157,12 +157,11 @@ private void createRootUser() { ua.setEmailAddress(configuredRootUser); ua.setFirstName("root"); ua.setLastName("user"); - // UQAM using getRootPasswordFromConfig() + // UQAM Add-Feature using getRootPasswordFromConfig() ua.setArgon2Password(Authenticator.applyArgon2iEncoding( getRootPasswordFromConfig())); ua.setMd5Password(""); - Boolean toto; - // UQAM using getRootPasswdChangeRequiredFromConfig() + // UQAM Add-Feature using getRootPasswdChangeRequiredFromConfig() ua.setPasswordChangeRequired(getRootPasswdChangeRequiredFromConfig().booleanValue()); ua.setStatus(Status.ACTIVE); ua.setRootUser(true); @@ -202,7 +201,7 @@ private void complainAboutWrongRootUsers() { + "it is best to delete unneeded root user accounts."); } /* - * UQAM + * UQAM Add-Feature * Add for getting rootUser.password property value from runtime.properties */ private String getRootPasswordFromConfig() { @@ -215,7 +214,7 @@ private String getRootPasswordFromConfig() { } /* - * UQAM + * UQAM Add-Feature * Add for getting rootUser.passwordChangeRequired property value from runtime.properties */ private Boolean getRootPasswdChangeRequiredFromConfig() { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java index 975ee9768b..9d513b3ba1 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerHttpServlet.java @@ -93,7 +93,7 @@ public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { super.doGet(request,response); -//UQAM set for UTF-8 +//UQAM-Optimization set for UTF-8 response.setCharacterEncoding("UTF-8"); VitroRequest vreq = new VitroRequest(request); @@ -279,8 +279,6 @@ protected void doTemplate(VitroRequest vreq, HttpServletResponse response, bodyString = ""; } - //UQAM Add linguistic control management - // String bodyStringUTF = new String(bodyString.getBytes(), Charset.forName("UTF-8")); templateDataModel.put("body", bodyString); String lang = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java index 6f66940354..c5439d4a24 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TemplateProcessingHelper.java @@ -42,11 +42,7 @@ private void processTemplate(Template template, Map map, Writer try { Environment env = template.createProcessingEnvironment(map, writer); - /* - * UQAM Set encoding to UTF-8 for i18n special character - */ -// env.setOutputEncoding("utf-8"); - + // Define a setup template to be included by every page template String templateType = (String) map.get("templateType"); if (FreemarkerHttpServlet.PAGE_TEMPLATE_TYPE.equals(templateType)) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java index d26f27efad..9be3a758de 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/json/GetRandomSearchIndividualsByVClass.java @@ -75,8 +75,8 @@ private String renderShortView(String individualUri, String vclassName) { modelMap.put("individual", IndividualTemplateModelBuilder.build(individual, vreq)); modelMap.put("vclass", vclassName); - String langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); //UQAM build the linguistic context - modelMap.put("langCtx", langCtx); // UQAM add the linguistic context to map + String langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); //UQAM-Linguistic-Management build the linguistic context + modelMap.put("langCtx", langCtx); // UQAM-Linguistic-Management add the linguistic context to map ShortViewService svs = ShortViewServiceSetup.getService(ctx); return svs.renderShortView(individual, ShortViewContext.BROWSE, modelMap, vreq); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java index d92c901360..3e94ca202a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java @@ -783,7 +783,7 @@ private Literal getLabel(String lang, ListlabelList) { return labelLit; } else /* - * UQAM + * UQAM-Linguistic-Management * Check for country-part of lang (ex: 'en' for default consideration of labelLanguage in english but not encoded by 'en-US' most case of labels in vivo.owl) */ if ((lang != null) && (Arrays.asList(lang.split("-")).get(0).equals(labelLanguage))) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java index 9c543f06fc..ab509c82e0 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/RDFServiceGraph.java @@ -291,7 +291,7 @@ public static String sparqlNode(Node node, String varName) { pyString(literalBuff, node.getLiteralLexicalForm()); literalBuff.append("\""); /* - * UQAM + * UQAM-Bug-Correction * reversing the condition tests. * It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java index 50ace6c280..b85b7a79bf 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java @@ -233,7 +233,7 @@ public static String sparqlNode(Node node, String varName) { pyString(literalBuff, node.getLiteralLexicalForm()); literalBuff.append("\""); /* - * UQAM + * UQAM-Bug-Correction * reversing the condition tests. * It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java index fcb72e7ab2..1714e8db50 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/AdditionsAndRetractions.java @@ -57,7 +57,7 @@ public String toString(){ str += "\nadditions:["; if( getAdditions() != null ) { StringWriter writer = new StringWriter(); - // UQAM Replacing N3-PP by N3 (N3-PP does not exist in Jena + // UQAM-Bug Replacing N3-PP by N3 (N3-PP does not exist in Jena getAdditions().write(writer, "N3"); str += "\n" + writer.toString() + "\n"; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java index cf5c4dcbb7..837f69febf 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java @@ -74,7 +74,7 @@ public static VClass getRangeVClass(VitroRequest vreq) { } public static VClass getLangAwardRangeVClass(VitroRequest vreq) { - // UQAM + // UQAM-Linguistic-Management // // This needs a WebappDaoFactory with linguistic context filtering/RDFService @@ -136,7 +136,7 @@ public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, public static ObjectProperty getObjectPropertyForPredicate(VitroRequest vreq, String predicateUri, String domainUri, String rangeUri) { // WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - // UQAM Use linguistic context + // UQAM-Linguistic-Management Use linguistic context WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); ObjectProperty objectProp = wdf.getObjectPropertyDao().getObjectPropertyByURIs( predicateUri, domainUri, rangeUri); @@ -307,12 +307,6 @@ public static Map> getExistingUriValues(EditConfigurationVT public static String generateHTMLForElement(VitroRequest vreq, String fieldName, EditConfigurationVTwo editConfig) { String html = ""; Configuration fmConfig = FreemarkerConfiguration.getConfig(vreq); - /* - * UQAM, encoded ftl to UTF-8 - */ - // fmConfig.setDefaultEncoding("utf-8"); - // fmConfig.setOutputEncoding("utf-8"); - // fmConfig.setURLEscapingCharset("UTF-8"); FieldVTwo field = editConfig == null ? null : editConfig.getField(fieldName); MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(vreq.getSession(), editConfig); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java index d5f7b9dbff..c20a63c91b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/ChildVClassesWithParent.java @@ -42,7 +42,7 @@ public ChildVClassesWithParent setDefaultOption(String label){ } /* - * UQAM + * UQAM-Linguistic-Management * This method is polymorphism of getOptions(EditConfigurationVTwo editConfig,String fieldName, WebappDaoFactory wDaoFact) * for the internationalization of word "other" in the scroling list of personHasAdvisorRelationship.ftl */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java index 67436009d3..b57e828795 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java @@ -53,7 +53,7 @@ public static Map getOptions( return Collections.emptyMap(); } } - // UQAM Overcharge method for linguistic contexte processisng + // UQAM-Linguistic-ManagementOvercharge method for linguistic contexte processisng public static Map getOptions( EditConfigurationVTwo editConfig, String fieldName, @@ -80,7 +80,7 @@ public static Map getOptions( } try { - //UQAM need vreq instead of WebappDaoFactory + //UQAM-Linguistic-Management need vreq instead of WebappDaoFactory Map parentClass = Collections.emptyMap(); FieldOptions fieldOptions = field.getFieldOptions(); // UQAM TODO - Only internationalization of ChildVClassesWithParent are implemented. For TODO, implement the internationalization for the rest of instanceof "FieldOptions" diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index c172294dfc..38a63b6219 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -130,7 +130,7 @@ protected List getRangeTypes(VitroRequest vreq) { //WebappDaoFactory ctxDaoFact = ModelAccess.on( // vreq.getSession().getServletContext()).getWebappDaoFactory(); // WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory(); - //UQAM Manage linguistic context + //UQAM Linguistic-Management Manage linguistic context WebappDaoFactory ctxDaoFact = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE, PolicyOption.POLICY_NEUTRAL); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java index a0497b03f9..b1336b50f9 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java @@ -76,7 +76,7 @@ protected static ResponseValues doPostEditRedirect( VitroRequest vreq , String e if( entityToReturnTo == null ){ // this will not work if there entityToReturnTo has a new resource URI, // in that case entityToReturnTo should not have been passed to this method as null - // UQAM + // UQAM-Linguistic-Management // MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig); MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, editConfig); entityToReturnTo = N3EditUtils.processEntityToReturnTo(editConfig, submission, vreq); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java index 5bf7f1a485..cd9f5d8327 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java @@ -67,7 +67,7 @@ protected ResponseValues processRequest(VitroRequest vreq) { //get the EditSubmission // MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration); - // Modified by UQAM + // Modified by UQAM-Linguistic-Management MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, configuration); EditSubmissionUtils.putEditSubmissionInSession(vreq.getSession(), submission); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java index 2ef05e2789..0f739361cd 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/filters/PageRoutingFilter.java @@ -63,10 +63,6 @@ public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chai // get URL without hostname or servlet context HttpServletResponse response = (HttpServletResponse) arg1; HttpServletRequest req = (HttpServletRequest) arg0; - // UQAM Manage UTF-8 for i18n - // req.setCharacterEncoding("UTF-8"); - // response.setContentType("text/html; charset=UTF-8"); - // response.setCharacterEncoding("UTF-8"); String path = req.getRequestURI().substring(req.getContextPath().length()); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java index 718f9543e8..719b041ab9 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfiguration.java @@ -74,14 +74,6 @@ public static Configuration getConfig(HttpServletRequest req) { clearTemplateCacheIfRequested(); keepTemplateLoaderCurrentWithThemeDirectory(req); setThreadLocalsForRequest(req); - /* - * UQAM, encoded ftl to UTF-8 - */ -// instance.setEncoding(req.getLocale(), "utf-8"); -// instance.setIncompatibleImprovements(freemarker.template.Configuration.VERSION_2_3_23); -// instance.setDefaultEncoding("utf-8"); -// instance.setOutputEncoding("utf-8"); -// instance.setURLEscapingCharset("UTF-8"); return instance; } } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java index 2601fb9549..06a17e4f4f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/RDFService.java @@ -266,7 +266,7 @@ public void unregisterJenaModelChangedListener(ModelChangedListener changeListen */ public void close(); /** - * UQAM Useful among other things to transport the linguistic context in the service + * UQAM-Bug-Correction Useful among other things to transport the linguistic context in the service * @param vitroRequest */ public void setVitroRequest(VitroRequest vitroRequest); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java index 42d2a5c095..5413511ad7 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/filter/LanguageFilteringRDFService.java @@ -554,7 +554,7 @@ public int compare(Statement s1, Statement s2) { } } /* - * UQAM Useful among other things to transport the linguistic context in the service + * UQAM-Linguistic-Management Useful among other things to transport the linguistic context in the service * (non-Javadoc) * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java index fc9ef4c3df..44bd2aabb5 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceFactorySingle.java @@ -220,7 +220,7 @@ public String toString() { + ", inner=" + s + "]"; } /* - * UQAM Useful among other things to transport the linguistic context in the service + * UQAM-Linguistic-Management Useful among other things to transport the linguistic context in the service * (non-Javadoc) * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java index e6d34fe54b..6958f27724 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/RDFServiceImpl.java @@ -256,7 +256,7 @@ protected static String sparqlNode(Node node, String varName) { pyString(literalBuff, node.getLiteralLexicalForm()); literalBuff.append("\""); /* - * UQAM + * UQAM-Bug-Correction * reversing the condition tests. * It is important to prioritize the language typology test in order to exploit the linguistic context in testing the type of data */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java index 7e363a0cac..888a51506f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/RDFServiceJena.java @@ -706,7 +706,7 @@ protected QueryExecution createQueryExecution(String queryString, Query q, Datas return QueryExecutionFactory.create(q, d); } /* - * UQAM Useful among other things to transport the linguistic context in the service + * UQAM-Linguistic-Management Useful among other things to transport the linguistic context in the service * (non-Javadoc) * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java index fc7c6249f6..4b910b568c 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/model/RDFServiceModel.java @@ -121,7 +121,7 @@ public boolean changeSetUpdate(ChangeSet changeSet) return true; } /* - * UQAM Useful among other things to transport the linguistic context in the service + * UQAM-Linguistic-Management Useful among other things to transport the linguistic context in the service * (non-Javadoc) * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java index 7a45dbcf29..abae2aeb91 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/logging/LoggingRDFService.java @@ -209,7 +209,7 @@ public String toString() { return "LoggingRDFService[inner=" + innerService + "]"; } /* - * UQAM Useful among other things to transport the linguistic context in the service + * UQAM-Linguistic-Management Useful among other things to transport the linguistic context in the service * (non-Javadoc) * @see edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService#setVitroRequest(edu.cornell.mannlib.vitro.webapp.controller.VitroRequest) */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java index b488cfc7b5..c9b9dee6a7 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/services/shortview/FakeApplicationOntologyService.java @@ -454,7 +454,7 @@ private static class FakeVivoPeopleDataGetter extends SparqlQueryDataGetter { // + " ?vTitle vcard:title ?pt . \n" + "} LIMIT 1"; /* - * UQAM New query including Linguistic context + * UQAM-Optimization New query including Linguistic context */ private static String QUERY_STRING_LANG = "" + "PREFIX obo: \n" @@ -479,7 +479,7 @@ private static OntModel initializeFakeDisplayModel() { Property saveToVarProperty = m .getProperty(DisplayVocabulary.SAVE_TO_VAR); - m.add(dataGetter, queryProperty, QUERY_STRING_LANG); //UQAM Using query with linguistic context + m.add(dataGetter, queryProperty, QUERY_STRING_LANG); //UQAM-Optimization Using query with linguistic context m.add(dataGetter, saveToVarProperty, "extra"); return m; } @@ -494,14 +494,14 @@ public FakeVivoPeopleDataGetter(VitroRequest vreq, String individualUri) { this.individualUri = individualUri; this.vreq = vreq; this.ctx = vreq.getSession().getServletContext(); - this.langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); // UQAM add the linguistic context + this.langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); // UQAM-Optimization add the linguistic context } @Override public Map getData(Map pageData) { Map parms = new HashMap<>(); parms.put("uri", individualUri); - parms.put("langCtx", langCtx); //UQAM add the linguistic context + parms.put("langCtx", langCtx); //UQAM-Optimization add the linguistic context return super.getData(parms); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java index be09c3623f..1bce3fbad6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java @@ -534,10 +534,10 @@ private void readFile(File f, OntModel om, String path) { try { if (f.getName().endsWith(".md")) { // Markdown files are documentation - skip. - // UQAM accept lower and upper case in fn extension + // UQAM-Optimization accept lower and upper case in fn extension } else if (f.getName().toLowerCase().endsWith(".n3")) { om.read(fis, null, "N3"); - // UQAM Accept Turtle + // UQAM-Optimization Accept Turtle (Must for us) } else if (f.getName().toLowerCase().endsWith(".ttl")) { om.read(fis, null, "TURTLE"); } else { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java index 0de494abd9..5b08edf8c0 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/SparqlQueryDataGetter.java @@ -168,7 +168,7 @@ private String bindParameters(String text, Map merged) { String value = merged.get(key); if (value.startsWith("http:")) { /* - * UQAM if the "value" looks like an URI then wrap the value with the characters '<' '>' + * UQAM-Optimization if the "value" looks like an URI then wrap the value with the characters '<' '>' * */ bound = bound.replaceAll("([?$]" + key + ")([^a-zA-Z0-9_\\-])", "<" + value + ">$2"); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java index 0c080102bf..2d38449332 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/threads/VitroBackgroundThread.java @@ -21,7 +21,7 @@ * check their current status. */ public class VitroBackgroundThread extends Thread { - // UQAM add start + // UQAM-Bug-Correction add start public synchronized void start() { super.start(); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java index 1a92035b33..a7c3d26ae6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java @@ -102,7 +102,7 @@ private void populateDropdowns() throws Exception { //For each field with an optionType defined, create the options // WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - // UQAM Manage Linguistic context + // UQAM-Optimization Manage Linguistic context WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); for(String fieldName: editConfig.getFields().keySet()){ FieldVTwo field = editConfig.getField(fieldName); @@ -111,7 +111,7 @@ private void populateDropdowns() throws Exception { //empty options field.setOptions(new ConstantFieldOptions()); } - //UQAM changing signature for including internationalization in scroll-down menu + //UQAM-Optimization changing signature for including internationalization in scroll-down menu Map optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf); // Map optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, vreq); optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap, field.getFieldOptions().getCustomComparator(), vreq); @@ -537,7 +537,7 @@ private String getDataLiteralValuesFromParameter() { //Updating to enable multiple vclasses applicable to subject to be analyzed to understand possible range of types public Map getOfferTypesCreateNew() { // WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - // UQAM Manage Linguistic context + // UQAM-Optimization Manage Linguistic context WebappDaoFactory wdf = ModelAccess.on(vreq).getWebappDaoFactory(LanguageOption.LANGUAGE_AWARE); ObjectProperty op = wdf.getObjectPropertyDao().getObjectPropertyByURI(editConfig.getPredicateUri()); @@ -545,7 +545,7 @@ public Map getOfferTypesCreateNew() { Individual sub = wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri()); - // UQAM Manage Linguistic context + // UQAM-Optimization Manage Linguistic context VClass rangeClass = EditConfigurationUtils.getLangAwardRangeVClass(vreq); List vclasses = null; From 09a6f652cdb1646dc2157d764b567e71b6f1fc0f Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Wed, 1 Apr 2020 13:08:24 -0400 Subject: [PATCH 10/52] Resolve compilation failures in Vitro tests --- .../n3editing/VTwo/ProcessRdfFormTest.java | 52 +++++++++++++++---- .../validators/AntiXssValidationTest.java | 25 +++++++-- .../servlet/http/HttpServletRequestStub.java | 3 +- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfFormTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfFormTest.java index 79ee543655..3f0d5ad8aa 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfFormTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfFormTest.java @@ -19,10 +19,13 @@ import org.apache.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.testing.AbstractTestClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.InsertException; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants; +import stubs.javax.servlet.http.HttpServletRequestStub; + public class ProcessRdfFormTest extends AbstractTestClass{ @Test @@ -40,14 +43,16 @@ public void basicNewStatementTest() throws Exception{ values.put("test3", (new String[] {"http://test.com/uri3"})); values.put("editKey", (new String[] {"mockEditKey"})); - MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config); + VitroRequest vreq = createRequestWithParameters(values); + + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, config); ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker()); /* test just the N3 substitution part */ Listreq = config.getN3Required(); Listopt = config.getN3Optional(); - processor.subInValuesToN3( config , submission, req, opt, null , null); + processor.subInValuesToN3( config , submission, req, opt, null , null, vreq); assertNotNull(req); assertTrue( req.size() > 0); assertNotNull(req.get(0)); @@ -102,7 +107,10 @@ public void basicEditStatement() throws Exception{ Map values = new HashMap(); values.put("testZ", (new String[] {testZURIChanged})); values.put("editKey", (new String[] {"mockEditKey"})); - MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config); + + VitroRequest vreq = createRequestWithParameters(values); + + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, config); ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker()); AdditionsAndRetractions changes = processor.process( config, submission, null ); @@ -176,14 +184,17 @@ public void unicodeTest() throws Exception{ values.put("test2", (new String[] {test2})); values.put("test3", (new String[] {test3})); values.put("editKey", (new String[] {"mockEditKey"})); - MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config); + + VitroRequest vreq = createRequestWithParameters(values); + + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, config); ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker()); /* test just the N3 substitution part */ Listreq = config.getN3Required(); Listopt = config.getN3Optional(); - processor.subInValuesToN3( config , submission, req, opt, null , null); + processor.subInValuesToN3( config , submission, req, opt, null , null, vreq); assertNotNull(req); assertTrue( req.size() > 0); assertNotNull(req.get(0)); @@ -220,14 +231,16 @@ public void basicNewResourceTest() throws Exception{ values.put("test3", (new String[] {"http://test.com/uri3"})); values.put("editKey", (new String[] {"mockEditKey"})); - MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config); + VitroRequest vreq = createRequestWithParameters(values); + + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, config); ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker()); /* test just the N3 substitution part */ Listreq = config.getN3Required(); Listopt = config.getN3Optional(); - processor.subInValuesToN3( config , submission, req, opt, null , null); + processor.subInValuesToN3( config , submission, req, opt, null , null, vreq); assertNotNull(req); assertTrue( req.size() > 0); assertNotNull(req.get(0)); @@ -270,14 +283,16 @@ public void forcedNewResourceTest() throws Exception{ values.put("test3", (new String[] {"http://test.com/uri3"})); values.put("editKey", (new String[] {"mockEditKey"})); - MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config); + VitroRequest vreq = createRequestWithParameters(values); + + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, config); ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker()); /* test just the N3 substitution part */ Listreq = config.getN3Required(); Listopt = config.getN3Optional(); - processor.subInValuesToN3( config , submission, req, opt, null , null); + processor.subInValuesToN3( config , submission, req, opt, null , null, vreq); assertNotNull(req); assertTrue( req.size() > 0); assertNotNull(req.get(0)); @@ -357,10 +372,13 @@ public void basicEditReplaceStatement() throws Exception{ values.put("testZ", (new String[] {testZURIChanged})); values.put("zLabel", (new String[] {"New Z Label"})); values.put("editKey", (new String[] {"mockEditKey"})); - MultiValueEditSubmission submission = new MultiValueEditSubmission(values, config); + + VitroRequest vreq = createRequestWithParameters(values); + + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq, config); ProcessRdfForm processor = new ProcessRdfForm(config,getMockNewURIMaker()); - AdditionsAndRetractions changes = processor.process( config, submission, null ); + AdditionsAndRetractions changes = processor.process( config, submission, vreq ); assertNotNull( changes ); assertNotNull( changes.getAdditions() ); @@ -396,4 +414,16 @@ public String getUnusedNewURI(String prefixURI) throws InsertException { } }; } + + private VitroRequest createRequestWithParameters(Map parameters) { + HttpServletRequestStub req = new HttpServletRequestStub(); + for (String key : parameters.keySet()) { + for (String value : parameters.get(key)) { + req.addParameter(key, value); + } + } + + return new VitroRequest(req); + } + } diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/AntiXssValidationTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/AntiXssValidationTest.java index e9e2c463d7..3c238facd2 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/AntiXssValidationTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/validators/AntiXssValidationTest.java @@ -9,10 +9,13 @@ import org.junit.Assert; import org.junit.Test; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; +import stubs.javax.servlet.http.HttpServletRequestStub; + public class AntiXssValidationTest { @Test @@ -29,8 +32,10 @@ public void testLiteral( ){ String[] vals= { "some sort of string" }; params.put("X", vals); + VitroRequest vreq = createRequestWithParameters(params); + MultiValueEditSubmission mvEditSub = - new MultiValueEditSubmission(params,eConf); + new MultiValueEditSubmission(vreq,eConf); Map res = validator.validate(eConf, mvEditSub); Assert.assertEquals(null, res); @@ -53,8 +58,10 @@ public void testAllURI( ){ String[] strings2 = {"no problem 2"}; params.put("Z", strings2 ); + VitroRequest vreq = createRequestWithParameters(params); + MultiValueEditSubmission mvEditSub = - new MultiValueEditSubmission(params,eConf); + new MultiValueEditSubmission(vreq,eConf); Map res = validator.validate(eConf, mvEditSub); Assert.assertNull( res ); @@ -72,8 +79,10 @@ protected Map testURI( String ... strings){ Map params = new HashMap(); params.put("X", strings ); + VitroRequest vreq = createRequestWithParameters(params); + MultiValueEditSubmission mvEditSub = - new MultiValueEditSubmission(params,eConf); + new MultiValueEditSubmission(vreq,eConf); return validator.validate(eConf, mvEditSub); } @@ -125,5 +134,15 @@ public void testURIValidationWithScriptTagLevel2(){ Assert.assertNotNull(result); } + private VitroRequest createRequestWithParameters(Map parameters) { + HttpServletRequestStub req = new HttpServletRequestStub(); + for (String key : parameters.keySet()) { + for (String value : parameters.get(key)) { + req.addParameter(key, value); + } + } + + return new VitroRequest(req); + } } diff --git a/api/src/test/java/stubs/javax/servlet/http/HttpServletRequestStub.java b/api/src/test/java/stubs/javax/servlet/http/HttpServletRequestStub.java index 27bb5e69fa..35b8da99c4 100644 --- a/api/src/test/java/stubs/javax/servlet/http/HttpServletRequestStub.java +++ b/api/src/test/java/stubs/javax/servlet/http/HttpServletRequestStub.java @@ -510,8 +510,7 @@ public DispatcherType getDispatcherType() { @Override public Locale getLocale() { - throw new RuntimeException( - "HttpServletRequestStub.getLocale() not implemented."); + return Locale.ENGLISH; } @Override From 6fbaab82c1e53d3015ed15866d4ce4dd744dfa0d Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Thu, 9 Apr 2020 12:49:17 -0400 Subject: [PATCH 11/52] Remove whitespace changes from SelectListGeneratorVTwo.java --- .../VTwo/fields/SelectListGeneratorVTwo.java | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java index b57e828795..0af862694f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/fields/SelectListGeneratorVTwo.java @@ -20,7 +20,8 @@ public class SelectListGeneratorVTwo { - static Log log = LogFactory.getLog(SelectListGeneratorVTwo.class); + static Log log = LogFactory.getLog(SelectListGeneratorVTwo.class); + public static Map getOptions( EditConfigurationVTwo editConfig, String fieldName, @@ -53,7 +54,8 @@ public static Map getOptions( return Collections.emptyMap(); } } - // UQAM-Linguistic-ManagementOvercharge method for linguistic contexte processisng + + // UQAM Overcharge method for linguistic contexte processisng public static Map getOptions( EditConfigurationVTwo editConfig, String fieldName, @@ -80,7 +82,7 @@ public static Map getOptions( } try { - //UQAM-Linguistic-Management need vreq instead of WebappDaoFactory + //UQAM need vreq instead of WebappDaoFactory Map parentClass = Collections.emptyMap(); FieldOptions fieldOptions = field.getFieldOptions(); // UQAM TODO - Only internationalization of ChildVClassesWithParent are implemented. For TODO, implement the internationalization for the rest of instanceof "FieldOptions" @@ -96,61 +98,61 @@ public static Map getOptions( } - //Methods to sort the options map - // from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708 - //Modified to allow for a custom comparator to be sent in, defaults to mapPairsComparator - public static Map getSortedMap(Map hmap, - Comparator comparator, VitroRequest vreq){ - // first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator - List objectsToSort = new ArrayList(hmap.size()); - for (String key:hmap.keySet()) { - String[] x = new String[2]; - x[0] = key; - x[1] = hmap.get(key); - objectsToSort.add(x); - } + //Methods to sort the options map + // from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708 + //Modified to allow for a custom comparator to be sent in, defaults to mapPairsComparator + public static Map getSortedMap(Map hmap, + Comparator comparator, VitroRequest vreq){ + // first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator + List objectsToSort = new ArrayList(hmap.size()); + for (String key:hmap.keySet()) { + String[] x = new String[2]; + x[0] = key; + x[1] = hmap.get(key); + objectsToSort.add(x); + } - //if no comparator is passed in, utilize MapPairsComparator - if(comparator == null) { - comparator = new MapPairsComparator(vreq); - } + //if no comparator is passed in, utilize MapPairsComparator + if(comparator == null) { + comparator = new MapPairsComparator(vreq); + } - objectsToSort.sort(comparator); + objectsToSort.sort(comparator); - HashMap map = new LinkedHashMap(objectsToSort.size()); - for (String[] pair:objectsToSort) { - map.put(pair[0],pair[1]); - } - return map; - } + HashMap map = new LinkedHashMap(objectsToSort.size()); + for (String[] pair:objectsToSort) { + map.put(pair[0],pair[1]); + } + return map; + } - //Sorts by the value of the 2nd element in each of the arrays - private static class MapPairsComparator implements Comparator { + //Sorts by the value of the 2nd element in each of the arrays + private static class MapPairsComparator implements Comparator { - private Collator collator; + private Collator collator; - public MapPairsComparator(VitroRequest vreq) { - this.collator = vreq.getCollator(); - } - public int compare (String[] s1, String[] s2) { - if (s2 == null) { - return 1; - } else if (s1 == null) { - return -1; - } else { - if ("".equals(s1[0])) { - return -1; - } else if ("".equals(s2[0])) { - return 1; - } - if (s2[1]==null) { - return 1; - } else if (s1[1] == null){ - return -1; - } else { - return collator.compare(s1[1],s2[1]); - } - } - } - } + public MapPairsComparator(VitroRequest vreq) { + this.collator = vreq.getCollator(); + } + public int compare (String[] s1, String[] s2) { + if (s2 == null) { + return 1; + } else if (s1 == null) { + return -1; + } else { + if ("".equals(s1[0])) { + return -1; + } else if ("".equals(s2[0])) { + return 1; + } + if (s2[1]==null) { + return 1; + } else if (s1[1] == null){ + return -1; + } else { + return collator.compare(s1[1],s2[1]); + } + } + } + } } From 48e893195e0da33b29d4c28a945d4a8f4a42b42f Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Wed, 15 Apr 2020 11:38:36 -0400 Subject: [PATCH 12/52] Add null check on field values of RDF Form (#158) Resolves: https://jira.lyrasis.org/browse/VIVO-1800 Co-authored-by: Andrew Woods --- .../edit/n3editing/VTwo/ProcessRdfForm.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java index da2a0ac0d9..a6a33a68e2 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java @@ -203,26 +203,26 @@ protected void subInValuesToN3( */ Map> literalsFromForm = submission.getLiteralsFromForm(); Set keys = literalsFromForm.keySet(); - for (Iterator iterator = keys.iterator(); iterator.hasNext();) { - String aKey = (String) iterator.next(); + for (String aKey : keys) { List literalFromForm = literalsFromForm.get(aKey); List newLiteralFromForm = new ArrayList<>(); - for (Iterator iterator2 = literalFromForm.iterator(); iterator2.hasNext();) { - Literal aLiteral = (Literal) iterator2.next(); - String aLiteratDT = aLiteral.getDatatype().getURI(); - Literal newLiteral= null; - String aText = aLiteral.getLexicalForm(); - /* - * do it only if aLiteral are xstring datatype - */ - - if ( XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT) ) { - String lang =vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); - newLiteral = ResourceFactory.createLangLiteral(aText, lang); - } else { - newLiteral = ResourceFactory.createTypedLiteral(aText, aLiteral.getDatatype()); - } - newLiteralFromForm.add(newLiteral); + for (Literal aLiteral : literalFromForm) { + if (aLiteral != null) { + String aLiteratDT = aLiteral.getDatatype().getURI(); + Literal newLiteral = null; + String aText = aLiteral.getLexicalForm(); + /* + * do it only if aLiteral are xstring datatype + */ + + if (XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT)) { + String lang = vreq.getLocale().getLanguage() + "-" + vreq.getLocale().getCountry(); + newLiteral = ResourceFactory.createLangLiteral(aText, lang); + } else { + newLiteral = ResourceFactory.createTypedLiteral(aText, aLiteral.getDatatype()); + } + newLiteralFromForm.add(newLiteral); + } } literalsFromForm.replace(aKey, newLiteralFromForm); } From f502d799ad8b8b927935eac011b5a3c484fa7c7f Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Wed, 15 Apr 2020 11:47:46 -0400 Subject: [PATCH 13/52] Fix incorrect tool-tip in language selection dropdown (#156) Resolves: https://jira.lyrasis.org/browse/VIVO-1783 Co-authored-by: Andrew Woods --- .../templates/freemarker/page/partials/languageSelector.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/main/webapp/templates/freemarker/page/partials/languageSelector.ftl b/webapp/src/main/webapp/templates/freemarker/page/partials/languageSelector.ftl index 80a0c633f2..0a2bd19434 100644 --- a/webapp/src/main/webapp/templates/freemarker/page/partials/languageSelector.ftl +++ b/webapp/src/main/webapp/templates/freemarker/page/partials/languageSelector.ftl @@ -8,7 +8,7 @@ <#-- This is included by identity.ftl --> <#if selectLocale??> -
    • ${i18n().select_a_language}