From b8cb95d252ccd32b114a5a5920bf901d91a4669d Mon Sep 17 00:00:00 2001 From: Tim Worrall Date: Fri, 5 Dec 2014 16:57:09 -0500 Subject: [PATCH] VIVO-922: updates for new faux listing functionality. New controller, template and js file, updated web.xml and site admin page, and updates to the all.properties --- .../languages/es_GO/i18n/all_es_GO.properties | 8 +- .../freemarker/BaseSiteAdminController.java | 1 + .../ListFauxPropertiesController.java | 233 ++++++++++++++++++ webapp/web/WEB-INF/web.xml | 9 + webapp/web/i18n/all.properties | 8 +- .../siteAdmin/fauxPropertiesListingUtils.js | 19 ++ .../siteAdmin-fauxPropertiesList.ftl | 123 +++++++++ .../siteAdmin/siteAdmin-ontologyEditor.ftl | 1 + 8 files changed, 400 insertions(+), 2 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListFauxPropertiesController.java create mode 100644 webapp/web/js/siteAdmin/fauxPropertiesListingUtils.js create mode 100644 webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-fauxPropertiesList.ftl diff --git a/webapp/languages/es_GO/i18n/all_es_GO.properties b/webapp/languages/es_GO/i18n/all_es_GO.properties index fb56a2344..6acd5e2a5 100644 --- a/webapp/languages/es_GO/i18n/all_es_GO.properties +++ b/webapp/languages/es_GO/i18n/all_es_GO.properties @@ -874,4 +874,10 @@ view_labels_for = Ver Etiquetas de select_an_existing_document = Seleccione un documento existente datetime_year_required = Intervalos de fecha / hora deben empezar por un año. Ingrese una Fecha de inicio, un fin de año o los dos. -select_a_language = Seleccione un idioma \ No newline at end of file +select_a_language = Seleccione un idioma + +base_property_capitalized = Base propiedad +faux_property_capitalized = Faux propiedad +faux_property_listing = Lista de faux propiedades +faux_property_by_base = Faux propiedades por base propriedad +faux_property_alpha = Faux propiedades en orden alfabético \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BaseSiteAdminController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BaseSiteAdminController.java index 5bcdbc53e..16362f70f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BaseSiteAdminController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BaseSiteAdminController.java @@ -187,6 +187,7 @@ public class BaseSiteAdminController extends FreemarkerHttpServlet { urls.put("classHierarchy", UrlBuilder.getUrl("/showClassHierarchy")); urls.put("classGroups", UrlBuilder.getUrl("/listGroups")); urls.put("dataPropertyHierarchy", UrlBuilder.getUrl("/showDataPropertyHierarchy")); + urls.put("fauxPropertyList", UrlBuilder.getUrl("/listFauxProperties")); urls.put("propertyGroups", UrlBuilder.getUrl("/listPropertyGroups")); urls.put("objectPropertyHierarchy", UrlBuilder.getUrl("/showObjectPropertyHierarchy", new ParamMap("iffRoot", "true"))); map.put("urls", urls); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListFauxPropertiesController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListFauxPropertiesController.java new file mode 100644 index 000000000..f2303bfcb --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ListFauxPropertiesController.java @@ -0,0 +1,233 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.controller.freemarker; + +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import net.sf.json.util.JSONUtils; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizationRequest; +import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty; +import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; +import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; +import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; +import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao; +import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; +import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; +import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; +import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; + +public class ListFauxPropertiesController extends FreemarkerHttpServlet { + + private static final Log log = LogFactory.getLog(ListFauxPropertiesController.class.getName()); + + private static final String TEMPLATE_NAME = "siteAdmin-fauxPropertiesList.ftl"; + + private ObjectPropertyDao opDao = null; + private PropertyGroupDao pgDao = null; + private FauxPropertyDao fpDao = null; + private String notFoundMessage = ""; + + @Override + protected AuthorizationRequest requiredActions(VitroRequest vreq) { + return SimplePermission.EDIT_ONTOLOGY.ACTION; + } + + @Override + protected ResponseValues processRequest(VitroRequest vreq) { + + Map body = new HashMap(); + try { + + String displayOption = ""; + + if ( vreq.getParameter("displayOption") != null ) { + displayOption = vreq.getParameter("displayOption"); + } + else { + displayOption = "listing"; + } + body.put("displayOption", displayOption); + + if ( displayOption.equals("listing") ) { + body.put("pageTitle", "Faux Property Listing"); + } + else { + body.put("pageTitle", "Faux Properties by Base Property"); + } + + opDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getObjectPropertyDao(); + fpDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getFauxPropertyDao(); + pgDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getPropertyGroupDao(); + + List objectProps = null; + objectProps = opDao.getRootObjectProperties(); + + Map allFauxProps = new TreeMap(); + // get the faux depending on the display option + if ( displayOption.equals("listing") ) { + allFauxProps = getFauxPropertyList(objectProps); + } + else { + allFauxProps = getFauxByBaseList(objectProps); + } + + log.debug(allFauxProps.toString()); + + if ( notFoundMessage.length() == 0 ) { + body.put("message", notFoundMessage); + } + else { + body.put("fauxProps", allFauxProps); + } + + } catch (Throwable t) { + t.printStackTrace(); + } + return new TemplateResponseValues(TEMPLATE_NAME, body); + + } + + private TreeMap getFauxPropertyList(List objectProps) { + List fauxProps = null; + TreeMap theFauxProps = new TreeMap(); + if ( objectProps != null ) { + Iterator opIt = objectProps.iterator(); + if ( !opIt.hasNext()) { + notFoundMessage = "No object properties found."; + } + else { + while (opIt.hasNext()) { + + ObjectProperty op = opIt.next(); + String baseURI = op.getURI(); + fauxProps = fpDao.getFauxPropertiesForBaseUri(baseURI); + + if ( fauxProps != null ) { + Iterator fpIt = fauxProps.iterator(); + if ( !fpIt.hasNext()) { + notFoundMessage = "No faux properties found."; + } + else { + while (fpIt.hasNext()) { + // No point in getting these unless we have a faux property + String baseLabel = getDisplayLabel(op) == null ? "(no name)" : getDisplayLabel(op); + String baseLocalName = op.getLocalNameWithPrefix(); + baseLabel = baseLabel.substring(0,baseLabel.indexOf("(")); + baseLabel += "(" + baseLocalName + ")"; + // get the info we need from the faux property + FauxProperty fp = fpIt.next(); + String fauxLabel = fp.getDisplayName(); + String rangeLabel = fp.getRangeLabel(); + String rangeURI = fp.getRangeURI(); + String domainLabel = fp.getDomainLabel(); + String domainURI = fp.getDomainURI(); + String groupURI = fp.getGroupURI(); + // FauxProperty only gets groupURI but we want the label + PropertyGroup pGroup = pgDao.getGroupByURI(groupURI); + String groupLabel = ( pGroup == null ) ? "unspecified" : pGroup.getName(); + // store all the strings in a hash with the faux property label as the key + Map tmpHash = new HashMap(); + tmpHash.put("base", baseLabel); + tmpHash.put("baseURI", baseURI); + tmpHash.put("group", groupLabel); + tmpHash.put("range", rangeLabel); + tmpHash.put("rangeURI", rangeURI); + tmpHash.put("domain", domainLabel); + tmpHash.put("domainURI", domainURI); + // add the faux and its details to the treemap + theFauxProps.put(fauxLabel, tmpHash); + } + } + } + } + } + } + return theFauxProps; + } + + private TreeMap getFauxByBaseList(List objectProps) { + List fauxProps = null; + TreeMap fauxByBaseProps = new TreeMap(); + if ( objectProps != null ) { + Iterator opIt = objectProps.iterator(); + if ( !opIt.hasNext()) { + notFoundMessage = "No object properties found."; + } + else { + while (opIt.hasNext()) { + TreeMap fauxForGivenBase = new TreeMap(); + ObjectProperty op = opIt.next(); + String baseURI = op.getURI(); + fauxProps = fpDao.getFauxPropertiesForBaseUri(baseURI); + + if ( fauxProps != null ) { + Iterator fpIt = fauxProps.iterator(); + if ( !fpIt.hasNext()) { + notFoundMessage = "No faux properties found."; + } + else { + String baseLabel = getDisplayLabel(op) == null ? "(no name)" : getDisplayLabel(op); + String baseLocalName = op.getLocalNameWithPrefix(); + baseLabel = baseLabel.substring(0,baseLabel.indexOf("(")); + baseLabel += "(" + baseLocalName + ")" + "|" + baseURI; + while (fpIt.hasNext()) { + // get the info we need from the faux property + FauxProperty fp = fpIt.next(); + String fauxLabel = fp.getDisplayName(); + String rangeLabel = fp.getRangeLabel(); + String rangeURI = fp.getRangeURI(); + String domainLabel = fp.getDomainLabel(); + String domainURI = fp.getDomainURI(); + String groupURI = fp.getGroupURI(); + // FauxProperty only gets groupURI but we want the label + PropertyGroup pGroup = pgDao.getGroupByURI(groupURI); + String groupLabel = ( pGroup == null ) ? "unspecified" : pGroup.getName(); + // store all the strings in a hash with the faux property label as the key + Map tmpHash = new HashMap(); + tmpHash.put("baseURI", baseURI); + tmpHash.put("group", groupLabel); + tmpHash.put("range", rangeLabel); + tmpHash.put("rangeURI", rangeURI); + tmpHash.put("domain", domainLabel); + tmpHash.put("domainURI", domainURI); + // add the faux and its details to the treemap + fauxForGivenBase.put(fauxLabel, tmpHash); + } + fauxByBaseProps.put(baseLabel, fauxForGivenBase); + } + } + } + } + } + return fauxByBaseProps; + } + + /* + * should never be null + */ + public static String getDisplayLabel(ObjectProperty op) { + String displayLabel = op.getPickListName(); + displayLabel = (displayLabel != null && displayLabel.length() > 0) + ? displayLabel + : op.getLocalName(); + return (displayLabel != null) ? displayLabel : "[object property]" ; + } + +} \ No newline at end of file diff --git a/webapp/web/WEB-INF/web.xml b/webapp/web/WEB-INF/web.xml index b13c3fa0e..6c8a7db6b 100644 --- a/webapp/web/WEB-INF/web.xml +++ b/webapp/web/WEB-INF/web.xml @@ -762,6 +762,15 @@ /showDataPropertyHierarchy + + ListFauxPropertiesController + edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListFauxPropertiesController + + + ListFauxPropertiesController + /listFauxProperties + + ListPropertyWebappsController edu.cornell.mannlib.vitro.webapp.controller.freemarker.ListPropertyWebappsController diff --git a/webapp/web/i18n/all.properties b/webapp/web/i18n/all.properties index 3f7c0ef3c..ae220a033 100644 --- a/webapp/web/i18n/all.properties +++ b/webapp/web/i18n/all.properties @@ -887,4 +887,10 @@ view_labels_for = View Labels for select_an_existing_document = Select an existing document datetime_year_required = Date/time intervals must begin with a year. Enter either a Start Year, an End Year or both. -select_a_language = Select a language \ No newline at end of file +select_a_language = Select a language + +base_property_capitalized = Base Property +faux_property_capitalized = Faux Property +faux_property_listing = Faux Property Listing +faux_property_by_base = faux properties by base property +faux_property_alpha = faux properties alphabetically \ No newline at end of file diff --git a/webapp/web/js/siteAdmin/fauxPropertiesListingUtils.js b/webapp/web/js/siteAdmin/fauxPropertiesListingUtils.js new file mode 100644 index 000000000..61ee8cfe3 --- /dev/null +++ b/webapp/web/js/siteAdmin/fauxPropertiesListingUtils.js @@ -0,0 +1,19 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + + var fauxPropertiesListingUtils = { + onLoad: function() { + this.initObjects(); + this.bindEventListeners(); + }, + + initObjects: function() { + this.select = $('select#displayOption'); + this.theForm = $('form#fauxListing'); + }, + + bindEventListeners: function() { + this.select.change(function() { + fauxPropertiesListingUtils.theForm.submit(); + }); + } +} diff --git a/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-fauxPropertiesList.ftl b/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-fauxPropertiesList.ftl new file mode 100644 index 000000000..748197437 --- /dev/null +++ b/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-fauxPropertiesList.ftl @@ -0,0 +1,123 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#-- + Used to display both the object and data property hierarchies, though there are + separate controllers for those. Also used to display lists of "all" object and + data properties, though there are separate controllers for those, too. + --> + <#if propertyType??> + <#assign propType = propertyType> +<#else> + <#assign propType = "group"> + + + +
+

${pageTitle!}

+ <#if message?has_content> +

${message}

+ <#else> + <#if !displayOption?has_content> + <#assign displayOption = "listing"> + +
+ + +
+
+ <#if displayOption == "listing" > + <#assign keys = fauxProps?keys/> + <#list keys as key> + <#assign ks = fauxProps[key] /> +
+
+ ${key} +
+ + + + + + + + + + + + + + + +
${i18n().base_property_capitalized}:${ks["base"]!}
${i18n().group_capitalized}:${ks["group"]?capitalize}
${i18n().domain_class}: + ${ks["domain"]!} + ${i18n().range_class}: + ${ks["range"]!} +
+
+ + <#else> + <#assign keys = fauxProps?keys /> + <#list keys as key> + <#assign fauxList = fauxProps[key] /> +
+ <#assign baseLabel = key?substring(0,key?index_of("|")) /> + <#assign baseUri = key?substring(key?index_of("|")+1) /> + + <#assign keysTwo = fauxList?keys /> + <#assign firstLoop = true /> + <#list keysTwo as k2> + <#assign faux = fauxList[k2] /> + style="margin-top:-16px"> + + + + + + + + + + + + + + +
${i18n().faux_property_capitalized}:${k2}
${i18n().group_capitalized}:${faux["group"]?capitalize} +
${i18n().domain_class}: + ${faux["domain"]!} + ${i18n().range_class}: + ${faux["range"]!} +
+ <#assign firstLoop = false /> + +
+ + +
+ +
+ + + + + + + +${stylesheets.add('')} + +${scripts.add('', + '')} + diff --git a/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-ontologyEditor.ftl b/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-ontologyEditor.ftl index 946861559..7db60e3be 100644 --- a/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-ontologyEditor.ftl +++ b/webapp/web/templates/freemarker/body/siteAdmin/siteAdmin-ontologyEditor.ftl @@ -33,6 +33,7 @@