From 2203b09fedc4aa33070eba6ca6ac933d64ed6f0d Mon Sep 17 00:00:00 2001 From: j2blake Date: Sun, 6 Nov 2011 17:13:02 +0000 Subject: [PATCH] NIHVIVO-2343 Allow configuration of what types of Individual are eligible to have proxies. --- webapp/config/example.deploy.properties | 6 ++++ .../manageproxies/ManageProxiesListPage.java | 8 ++++++ .../user/UserAccountsMyAccountPage.java | 9 ++++++ .../web/js/account/accountProxyItemsPanel.js | 28 ++++++++++++++++--- .../accounts/userAccounts-myProxiesPanel.ftl | 1 + .../body/manageproxies/manageProxies-list.ftl | 1 + 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/webapp/config/example.deploy.properties b/webapp/config/example.deploy.properties index 90dec34e3..bfe4bbdb4 100644 --- a/webapp/config/example.deploy.properties +++ b/webapp/config/example.deploy.properties @@ -125,3 +125,9 @@ selfEditing.idMatchingProperty = http://vitro.mydomain.edu/ns#networkId # #externalAuth.buttonText = Log in using BearCat Shibboleth #externalAuth.netIdHeaderName = remote_userID + +# +# Types of individual for which we can create proxy editors. +# If this is omitted, defaults to http://www.w3.org/2002/07/owl#Thing +proxy.eligibleTypeList = http://www.w3.org/2002/07/owl#Thing + diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java index 1995f5f89..782f69b0a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java @@ -35,6 +35,8 @@ public class ManageProxiesListPage extends AbstractPageHandler { private static final String TEMPLATE_NAME = "manageProxies-list.ftl"; + private static final String PROPERTY_PROFILE_TYPES = "proxy.eligibleTypeList"; + private static final String DEFAULT_IMAGE_URL = UrlBuilder .getUrl("/images/placeholders/person.thumbnail.jpg"); @@ -94,6 +96,7 @@ public class ManageProxiesListPage extends AbstractPageHandler { body.put("page", buildPageMap(selection)); body.put("matchingProperty", getMatchingProperty()); + body.put("profileTypes", buildProfileTypesString()); body.put("formUrls", buildUrlsMap()); @@ -103,6 +106,11 @@ public class ManageProxiesListPage extends AbstractPageHandler { return body; } + private String buildProfileTypesString() { + return ConfigurationProperties.getBean(vreq).getProperty( + PROPERTY_PROFILE_TYPES, "http://www.w3.org/2002/07/owl#Thing"); + } + private List wrapProxyRelationships( ProxyRelationshipSelection selection) { List wrapped = new ArrayList(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/user/UserAccountsMyAccountPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/user/UserAccountsMyAccountPage.java index 08e24bea8..ee80bc8fd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/user/UserAccountsMyAccountPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/user/UserAccountsMyAccountPage.java @@ -18,6 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageOwnP import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; +import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage; import edu.cornell.mannlib.vitro.webapp.controller.accounts.admin.UserAccountsEditPage; @@ -47,6 +48,8 @@ public class UserAccountsMyAccountPage extends UserAccountsPage { private static final String TEMPLATE_NAME = "userAccounts-myAccount.ftl"; + private static final String PROPERTY_PROFILE_TYPES = "proxy.eligibleTypeList"; + private final UserAccountsMyAccountPageStrategy strategy; private final UserAccount userAccount; @@ -148,6 +151,7 @@ public class UserAccountsMyAccountPage extends UserAccountsPage { } body.put("formUrls", buildUrlsMap()); body.put("myAccountUri", userAccount.getUri()); + body.put("profileTypes", buildProfileTypesString()); // Could I do this without exposing this mechanism? But how to search // for an associated profile in AJAX? @@ -172,6 +176,11 @@ public class UserAccountsMyAccountPage extends UserAccountsPage { return new TemplateResponseValues(TEMPLATE_NAME, body); } + private String buildProfileTypesString() { + return ConfigurationProperties.getBean(vreq).getProperty( + PROPERTY_PROFILE_TYPES, "http://www.w3.org/2002/07/owl#Thing"); + } + public void updateAccount() { userAccount.setEmailAddress(emailAddress); userAccount.setFirstName(firstName); diff --git a/webapp/web/js/account/accountProxyItemsPanel.js b/webapp/web/js/account/accountProxyItemsPanel.js index 447bef705..08bc65e8b 100644 --- a/webapp/web/js/account/accountProxyItemsPanel.js +++ b/webapp/web/js/account/accountProxyItemsPanel.js @@ -128,6 +128,7 @@ function statusFieldUpdater(element, minLength) { var profileQuery = "" + "PREFIX fn: \n" + + "PREFIX rdf: \n" + "PREFIX rdfs: \n" + "PREFIX foaf: \n" + "PREFIX vitro: \n" @@ -136,8 +137,8 @@ var profileQuery = "" + "\n" + "SELECT DISTINCT ?uri ?label ?classLabel ?imageUrl \n" + "WHERE { \n" - + " ?uri a foaf:Person ; \n" - + " rdfs:label ?label ; \n" + + " %typesUnion% \n" + + " ?uri rdfs:label ?label ; \n" + " OPTIONAL { \n" + " ?uri vitro:mostSpecificType ?type. \n" + " ?type rdfs:label ?classLabel \n" @@ -220,6 +221,23 @@ var getAdditionalProxyInfo = function(parent, info, externalAuthId) { }); } +/* + * The profileTypes context string must have one or more type URIs, separated by commas. + */ +var applyProfileTypes = function(rawQuery) { + var typeClause = ''; + var types = proxyContextInfo.profileTypes.split(','); + + for (var i = 0; i < types.length; i++) { + typeClause += '{ ?uri rdf:type <' + types[i].trim() + '> }'; + if (i + 1 < types.length) { + typeClause += ' UNION '; + } else { + typeClause += ' .'; + } + } + return rawQuery.replace("%typesUnion%", typeClause); +} /* * Execute this when the page loads. @@ -245,16 +263,18 @@ $(document).ready(function() { } /* - * For each proxyProfilesPanel, create a plain vanilla panel using the + * For each proxyProfilesPanel, modify the profile query to restrict it + * to the permitted types, then create a plain vanilla panel using the * profile query against the main model. */ $("div[name='proxyProfilesPanel']").each(function(i) { + var query = applyProfileTypes(profileQuery); var context = { excludedUris: [], baseUrl: proxyContextInfo.baseUrl, sparqlQueryUrl: proxyContextInfo.sparqlQueryUrl, defaultImageUrl: proxyContextInfo.defaultImageUrl, - query: profileQuery, + query: query, model: '' } this["proxyItemsPanel"] = new proxyItemsPanel(this, context); diff --git a/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl b/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl index 263226a80..fd92b62b8 100644 --- a/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl +++ b/webapp/web/templates/freemarker/body/accounts/userAccounts-myProxiesPanel.ftl @@ -54,6 +54,7 @@ var proxyContextInfo = { sparqlQueryUrl: '${formUrls.sparqlQueryAjax}', defaultImageUrl: '${formUrls.defaultImageUrl}', matchingProperty: '${matchingProperty}', + profileTypes: '${profileTypes}' }; diff --git a/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl b/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl index c7c91725d..5fad34cd5 100644 --- a/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl +++ b/webapp/web/templates/freemarker/body/manageproxies/manageProxies-list.ftl @@ -212,6 +212,7 @@ var proxyContextInfo = { sparqlQueryUrl: '${formUrls.sparqlQueryAjax}', defaultImageUrl: '${formUrls.defaultImageUrl}', matchingProperty: '${matchingProperty}', + profileTypes: '${profileTypes}' };