From 3e5c7705067f71e7342570167b70dbc5a19408a4 Mon Sep 17 00:00:00 2001 From: hudajkhan Date: Wed, 2 Oct 2013 14:58:01 -0400 Subject: [PATCH] updates for page management security, labels --- .../{firsttime => everytime}/pageList.n3 | 2 +- .../{firsttime => everytime}/permissions.n3 | 0 webapp/rdf/display/firsttime/application.owl | 7 +++-- .../individual/IndividualResponseBuilder.java | 27 +++++++++++++++++++ .../vitro/webapp/dao/DisplayVocabulary.java | 2 +- .../vitro/webapp/dao/jena/PageDaoJena.java | 2 +- .../body/individual/individual-vitro.ftl | 8 +++++- .../manageLabelsForIndividualMacros.ftl | 13 ++++++--- .../individual/viewLabelsForIndividual.ftl | 10 +++---- .../freemarker/lib/lib-properties.ftl | 6 ++--- 10 files changed, 60 insertions(+), 17 deletions(-) rename webapp/rdf/display/{firsttime => everytime}/pageList.n3 (97%) rename webapp/rdf/display/{firsttime => everytime}/permissions.n3 (100%) diff --git a/webapp/rdf/display/firsttime/pageList.n3 b/webapp/rdf/display/everytime/pageList.n3 similarity index 97% rename from webapp/rdf/display/firsttime/pageList.n3 rename to webapp/rdf/display/everytime/pageList.n3 index 4db1c18d0..6c2301851 100644 --- a/webapp/rdf/display/firsttime/pageList.n3 +++ b/webapp/rdf/display/everytime/pageList.n3 @@ -14,7 +14,7 @@ display:pageListPage display:urlMapping "/pageList" ; display:requiresBodyTemplate "pageList.ftl" ; display:hasDataGetter display:pageListData; - display:requiredAction ; + display:requiresAction ; display:cannotDeletePage "true" . display:pageListData diff --git a/webapp/rdf/display/firsttime/permissions.n3 b/webapp/rdf/display/everytime/permissions.n3 similarity index 100% rename from webapp/rdf/display/firsttime/permissions.n3 rename to webapp/rdf/display/everytime/permissions.n3 diff --git a/webapp/rdf/display/firsttime/application.owl b/webapp/rdf/display/firsttime/application.owl index 18f1d8b90..1023146e8 100644 --- a/webapp/rdf/display/firsttime/application.owl +++ b/webapp/rdf/display/firsttime/application.owl @@ -54,7 +54,8 @@ - + + @@ -127,7 +128,9 @@ - + + + diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java index 0fd8ae2f4..a971bf160 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/individual/IndividualResponseBuilder.java @@ -111,6 +111,7 @@ class IndividualResponseBuilder { */ // body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE)); body.put("labelCount", getLabelCount(itm.getUri(), vreq)); + body.put("languageCount", getLanguagesRepresentedCount(itm.getUri(), vreq)); //We also need to know the number of available locales body.put("localesCount", SelectedLocale.getSelectableLocales(vreq).size()); body.put("profileType", getProfileType(itm.getUri(), vreq)); @@ -279,6 +280,13 @@ class IndividualResponseBuilder { + " FILTER isLiteral(?label) \n" + "}" ; + private static String DISTINCT_LANGUAGE_QUERY = "" + + "PREFIX rdfs: \n" + + "SELECT ( str(COUNT(DISTINCT lang(?label))) AS ?languageCount ) WHERE { \n" + + " ?subject rdfs:label ?label \n" + + " FILTER isLiteral(?label) \n" + + "}" ; + private static Integer getLabelCount(String subjectUri, VitroRequest vreq) { String queryStr = QueryUtils.subUriForQueryVar(LABEL_COUNT_QUERY, "subject", subjectUri); log.debug("queryStr = " + queryStr); @@ -297,6 +305,25 @@ class IndividualResponseBuilder { } return theCount; } + + //what is the number of languages represented across the labels + private static Integer getLanguagesRepresentedCount(String subjectUri, VitroRequest vreq) { + String queryStr = QueryUtils.subUriForQueryVar(DISTINCT_LANGUAGE_QUERY, "subject", subjectUri); + log.debug("queryStr = " + queryStr); + int theCount = 0; + try { + + ResultSet results = QueryUtils.getLanguageNeutralQueryResults(queryStr, vreq); + if (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + String countStr = soln.get("languageCount").toString(); + theCount = Integer.parseInt(countStr); + } + } catch (Exception e) { + log.error(e, e); + } + return theCount; + } private static String PROFILE_TYPE_QUERY = "" + "PREFIX display: \n" diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java index a3f0fdab3..511644afe 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java @@ -48,7 +48,7 @@ public class DisplayVocabulary { public static final String ITEM_TO_PAGE = NS + "toPage"; public static final String HAS_ELEMENT = NS + "hasElement"; public static final String USES_DATAGETTER_CLASS = NS + "usesDataGetterClass"; - public static final String REQUIRED_ACTIONS = NS + "requiredAction"; + public static final String REQUIRES_ACTIONS = NS + "requiresAction"; /**Data Getter object properties **/ public static final String HAS_DATA_GETTER = NS + "hasDataGetter"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PageDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PageDaoJena.java index e723e0a2b..23e300013 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PageDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PageDaoJena.java @@ -83,7 +83,7 @@ public class PageDaoJena extends JenaBaseDao implements PageDao { static final protected String requiredActionsQuery = prefixes + "\n" + "SELECT ?requiredAction WHERE{\n" + - " ?pageUri <" + DisplayVocabulary.REQUIRED_ACTIONS + "> ?requiredAction .\n"+ + " ?pageUri <" + DisplayVocabulary.REQUIRES_ACTIONS + "> ?requiredAction .\n"+ "}"; //Get data getter URIs diff --git a/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl b/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl index 742d8470d..45042708d 100644 --- a/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl +++ b/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl @@ -1,10 +1,16 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> +<#--Number of labels present--> <#if !labelCount??> <#assign labelCount = 0 > +<#--Number of available locales--> <#if !localesCount??> <#assign localesCount = 1> +<#--Number of distinct languages represented, with no language tag counting as a language, across labels--> +<#if !languageCount??> + <#assign languageCount = 1> + <#-- Default individual profile page template --> <#--@dumpAll /--> @@ -35,7 +41,7 @@ <#else>

<#-- Label --> - <@p.label individual editable labelCount localesCount/> + <@p.label individual editable labelCount localesCount languageCount/> <#-- Most-specific types --> <@p.mostSpecificTypes individual /> diff --git a/webapp/web/templates/freemarker/body/individual/manageLabelsForIndividualMacros.ftl b/webapp/web/templates/freemarker/body/individual/manageLabelsForIndividualMacros.ftl index 28a1a1b6f..dbefd870d 100644 --- a/webapp/web/templates/freemarker/body/individual/manageLabelsForIndividualMacros.ftl +++ b/webapp/web/templates/freemarker/body/individual/manageLabelsForIndividualMacros.ftl @@ -14,7 +14,11 @@ <#assign label = labelLiteral /> <#assign labelLang = labelObject.languageName /> <#assign languageCode = labelObject.languageCode /> - <#assign labelEditLink = labelObject.editLinkURL /> + <#assign labelEditLink = ""/> + <#if labelObject.editLinkURL?has_content> + <#assign labelEditLink = labelObject.editLinkURL/> + + <#if label?? && ( label?index_of("@") > -1 ) > <#assign labelStr = label?substring(0, label?index_of("@")) > <#assign tagOrTypeStr = label?substring(label?index_of("@")) > @@ -52,7 +56,10 @@ <#assign label = labelLiteral /> <#assign labelLang = labelObject.languageName /> <#assign languageCode = labelObject.languageCode /> - <#assign labelEditLink = labelObject.editLinkURL /> + <#assign labelEditLink = ""/> + <#if labelObject.editLinkURL?has_content> + <#assign labelEditLink = labelObject.editLinkURL/> + <#if label?? && ( label?index_of("@") > -1 ) > <#assign labelStr = label?substring(0, label?index_of("@")) > <#assign tagOrTypeStr = label?substring(label?index_of("@")) > @@ -75,7 +82,7 @@ <#macro displayLabel labelSeq labelStr languageCode labelEditLink tagOrTypeStr editGenerator editable displayRemoveLink>
  • ${labelStr} <#if labelSeq?seq_contains(labelStr)> (duplicate value) <#if editable> <#if labelEditLink?has_content> Edit - <#if displayRemoveLink = true> + <#if displayRemoveLink> ${i18n().remove_capitalized} diff --git a/webapp/web/templates/freemarker/body/individual/viewLabelsForIndividual.ftl b/webapp/web/templates/freemarker/body/individual/viewLabelsForIndividual.ftl index 9907cb355..23b4d0385 100644 --- a/webapp/web/templates/freemarker/body/individual/viewLabelsForIndividual.ftl +++ b/webapp/web/templates/freemarker/body/individual/viewLabelsForIndividual.ftl @@ -8,11 +8,11 @@ <#assign labelStr = "" > <#assign languageTag = "" > <#assign labelSeq = [] > -<#assign editable = "false"/> -<#assign displayRemoveLink = "false"/> +<#assign editable = false/> +<#assign displayRemoveLink = false/> <#if subjectName?? > -

    ${i18n().view_labels_for} ${editConfiguration.pageData.subjectName}

    +

    ${i18n().view_labels_for} ${subjectName}

    <#else>

    ${i18n().view_labels_capitalized}

    @@ -21,9 +21,9 @@
      - <#if editConfiguration.pageData.labelsSortedByLanguageName?has_content> + <#if labelsSortedByLanguageName?has_content> <#--List of labelInformation objects as value where key = language name --> - <#assign labelsSorted = editConfiguration.pageData.labelsSortedByLanguageName /> + <#assign labelsSorted = labelsSortedByLanguageName /> <#--Keys would be the actual names of languages--> <#assign labelLanguages = labelsSorted?keys?sort /> diff --git a/webapp/web/templates/freemarker/lib/lib-properties.ftl b/webapp/web/templates/freemarker/lib/lib-properties.ftl index 1d92f3595..3034fba7c 100644 --- a/webapp/web/templates/freemarker/lib/lib-properties.ftl +++ b/webapp/web/templates/freemarker/lib/lib-properties.ftl @@ -238,7 +238,7 @@ name will be used as the label. --> <#-- Label --> -<#macro label individual editable labelCount localesCount=1> +<#macro label individual editable labelCount localesCount=1 languageCount=1> <#assign labelPropertyUri = ("http://www.w3.org/2000/01/rdf-schema#label"?url) /> <#assign useEditLink = false /> <#--edit link used if in edit mode and only one label and one language--> @@ -249,8 +249,8 @@ name will be used as the label. --> ${label.value} <#if useEditLink> <@editingLinks "label" "" label editable /> - <#elseif editable || (labelCount > 1)> - <#--We display the link even when the user is not logged in case of multiple labels--> + <#elseif editable || (languageCount > 1)> + <#--We display the link even when the user is not logged in case of multiple labels with different languages--> <#assign labelLink = ""/> <#-- Manage labels now goes to generator --> <#assign individualUri = individual.uri!""/>