NIHVIVO-2343 Allow configuration of what types of Individual are eligible to have proxies.

This commit is contained in:
j2blake 2011-11-06 17:13:02 +00:00
parent 89ea62af47
commit 2203b09fed
6 changed files with 49 additions and 4 deletions

View file

@ -125,3 +125,9 @@ selfEditing.idMatchingProperty = http://vitro.mydomain.edu/ns#networkId
# #
#externalAuth.buttonText = Log in using BearCat Shibboleth #externalAuth.buttonText = Log in using BearCat Shibboleth
#externalAuth.netIdHeaderName = remote_userID #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

View file

@ -35,6 +35,8 @@ public class ManageProxiesListPage extends AbstractPageHandler {
private static final String TEMPLATE_NAME = "manageProxies-list.ftl"; 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 private static final String DEFAULT_IMAGE_URL = UrlBuilder
.getUrl("/images/placeholders/person.thumbnail.jpg"); .getUrl("/images/placeholders/person.thumbnail.jpg");
@ -94,6 +96,7 @@ public class ManageProxiesListPage extends AbstractPageHandler {
body.put("page", buildPageMap(selection)); body.put("page", buildPageMap(selection));
body.put("matchingProperty", getMatchingProperty()); body.put("matchingProperty", getMatchingProperty());
body.put("profileTypes", buildProfileTypesString());
body.put("formUrls", buildUrlsMap()); body.put("formUrls", buildUrlsMap());
@ -103,6 +106,11 @@ public class ManageProxiesListPage extends AbstractPageHandler {
return body; return body;
} }
private String buildProfileTypesString() {
return ConfigurationProperties.getBean(vreq).getProperty(
PROPERTY_PROFILE_TYPES, "http://www.w3.org/2002/07/owl#Thing");
}
private List<ProxyRelationship> wrapProxyRelationships( private List<ProxyRelationship> wrapProxyRelationships(
ProxyRelationshipSelection selection) { ProxyRelationshipSelection selection) {
List<ProxyRelationship> wrapped = new ArrayList<ProxyRelationship>(); List<ProxyRelationship> wrapped = new ArrayList<ProxyRelationship>();

View file

@ -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.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount; 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.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage; import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
import edu.cornell.mannlib.vitro.webapp.controller.accounts.admin.UserAccountsEditPage; 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 TEMPLATE_NAME = "userAccounts-myAccount.ftl";
private static final String PROPERTY_PROFILE_TYPES = "proxy.eligibleTypeList";
private final UserAccountsMyAccountPageStrategy strategy; private final UserAccountsMyAccountPageStrategy strategy;
private final UserAccount userAccount; private final UserAccount userAccount;
@ -148,6 +151,7 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
} }
body.put("formUrls", buildUrlsMap()); body.put("formUrls", buildUrlsMap());
body.put("myAccountUri", userAccount.getUri()); body.put("myAccountUri", userAccount.getUri());
body.put("profileTypes", buildProfileTypesString());
// Could I do this without exposing this mechanism? But how to search // Could I do this without exposing this mechanism? But how to search
// for an associated profile in AJAX? // for an associated profile in AJAX?
@ -172,6 +176,11 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
return new TemplateResponseValues(TEMPLATE_NAME, body); 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() { public void updateAccount() {
userAccount.setEmailAddress(emailAddress); userAccount.setEmailAddress(emailAddress);
userAccount.setFirstName(firstName); userAccount.setFirstName(firstName);

View file

@ -128,6 +128,7 @@ function statusFieldUpdater(element, minLength) {
var profileQuery = "" var profileQuery = ""
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n" + "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" + "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n"
@ -136,8 +137,8 @@ var profileQuery = ""
+ "\n" + "\n"
+ "SELECT DISTINCT ?uri ?label ?classLabel ?imageUrl \n" + "SELECT DISTINCT ?uri ?label ?classLabel ?imageUrl \n"
+ "WHERE { \n" + "WHERE { \n"
+ " ?uri a foaf:Person ; \n" + " %typesUnion% \n"
+ " rdfs:label ?label ; \n" + " ?uri rdfs:label ?label ; \n"
+ " OPTIONAL { \n" + " OPTIONAL { \n"
+ " ?uri vitro:mostSpecificType ?type. \n" + " ?uri vitro:mostSpecificType ?type. \n"
+ " ?type rdfs:label ?classLabel \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. * 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. * profile query against the main model.
*/ */
$("div[name='proxyProfilesPanel']").each(function(i) { $("div[name='proxyProfilesPanel']").each(function(i) {
var query = applyProfileTypes(profileQuery);
var context = { var context = {
excludedUris: [], excludedUris: [],
baseUrl: proxyContextInfo.baseUrl, baseUrl: proxyContextInfo.baseUrl,
sparqlQueryUrl: proxyContextInfo.sparqlQueryUrl, sparqlQueryUrl: proxyContextInfo.sparqlQueryUrl,
defaultImageUrl: proxyContextInfo.defaultImageUrl, defaultImageUrl: proxyContextInfo.defaultImageUrl,
query: profileQuery, query: query,
model: '' model: ''
} }
this["proxyItemsPanel"] = new proxyItemsPanel(this, context); this["proxyItemsPanel"] = new proxyItemsPanel(this, context);

View file

@ -54,6 +54,7 @@ var proxyContextInfo = {
sparqlQueryUrl: '${formUrls.sparqlQueryAjax}', sparqlQueryUrl: '${formUrls.sparqlQueryAjax}',
defaultImageUrl: '${formUrls.defaultImageUrl}', defaultImageUrl: '${formUrls.defaultImageUrl}',
matchingProperty: '${matchingProperty}', matchingProperty: '${matchingProperty}',
profileTypes: '${profileTypes}'
}; };
</script> </script>

View file

@ -212,6 +212,7 @@ var proxyContextInfo = {
sparqlQueryUrl: '${formUrls.sparqlQueryAjax}', sparqlQueryUrl: '${formUrls.sparqlQueryAjax}',
defaultImageUrl: '${formUrls.defaultImageUrl}', defaultImageUrl: '${formUrls.defaultImageUrl}',
matchingProperty: '${matchingProperty}', matchingProperty: '${matchingProperty}',
profileTypes: '${profileTypes}'
}; };
</script> </script>