From 2c294c38e9c84551204ace4eaa9e97f59b0fd83b Mon Sep 17 00:00:00 2001 From: tworrall Date: Fri, 25 May 2012 15:28:56 +0000 Subject: [PATCH] NIHVIVO-3768 grants management page --- productMods/WEB-INF/web.xml | 8 ++ .../listViewConfig-hasInvestigatorRole.xml | 3 +- productMods/config/listViewConfig-hasRole.xml | 3 +- .../forms/js/manageGrantsForIndividual.js | 85 ++++++++++++ .../edit/forms/manageGrantsForIndividual.ftl | 56 ++++++++ .../ManageGrantsForIndividualController.java | 124 ++++++++++++++++++ ...gePublicationsForIndividualController.java | 4 +- 7 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 productMods/templates/freemarker/edit/forms/js/manageGrantsForIndividual.js create mode 100644 productMods/templates/freemarker/edit/forms/manageGrantsForIndividual.ftl create mode 100644 src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManageGrantsForIndividualController.java diff --git a/productMods/WEB-INF/web.xml b/productMods/WEB-INF/web.xml index 473eb560..2733e9a0 100644 --- a/productMods/WEB-INF/web.xml +++ b/productMods/WEB-INF/web.xml @@ -796,6 +796,14 @@ /listIndividuals + + ManageGrantsForIndividualController + edu.cornell.mannlib.vitro.webapp.controller.freemarker.ManageGrantsForIndividualController + + + ManageGrantsForIndividualController + /manageGrants + ManagePublicationsForIndividualController diff --git a/productMods/config/listViewConfig-hasInvestigatorRole.xml b/productMods/config/listViewConfig-hasInvestigatorRole.xml index 4f24b799..ebf8b0d8 100644 --- a/productMods/config/listViewConfig-hasInvestigatorRole.xml +++ b/productMods/config/listViewConfig-hasInvestigatorRole.xml @@ -54,7 +54,8 @@ OPTIONAL { ?dateTimeIntervalGrant core:end ?dateTimeEndValueGrant . ?dateTimeEndValueGrant core:dateTime ?dateTimeEndGrant } - } + } + NOT EXISTS { ?role core:hideFromDisplay ?hideThis } FILTER ( bound(?activity) ) diff --git a/productMods/config/listViewConfig-hasRole.xml b/productMods/config/listViewConfig-hasRole.xml index 69879a08..e75ebcfd 100644 --- a/productMods/config/listViewConfig-hasRole.xml +++ b/productMods/config/listViewConfig-hasRole.xml @@ -47,7 +47,8 @@ OPTIONAL { ?dateTimeInterval core:end ?dateTimeEndValue . ?dateTimeEndValue core:dateTime ?dateTimeEnd } - } + } + NOT EXISTS { ?role core:hideFromDisplay ?hideThis } FILTER ( bound(?activity) ) diff --git a/productMods/templates/freemarker/edit/forms/js/manageGrantsForIndividual.js b/productMods/templates/freemarker/edit/forms/js/manageGrantsForIndividual.js new file mode 100644 index 00000000..5c673c55 --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/js/manageGrantsForIndividual.js @@ -0,0 +1,85 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var manageGrants = { + + /* *** Initial page setup *** */ + + onLoad: function() { + + this.mixIn(); + this.initPage(); + }, + + mixIn: function() { + + // Get the custom form data from the page + $.extend(this, customFormData); + }, + + // Initial page setup. Called only at page load. + initPage: function() { + + this.initGrantData(); + + this.bindEventListeners(); + + }, + + // On page load, associate data with each list item. Then we don't + // have to keep retrieving data from or modifying the DOM as we manipulate the + // items. + initGrantData: function() { + $('.grantCheckbox').each(function(index) { + $(this).data(grantData[index]); + }); + }, + + bindEventListeners: function() { + + $('.grantCheckbox').click(function() { + manageGrants.processGrant(this); + //return false; + }); + + }, + + processGrant: function(grant) { + + var add = ""; + var retract = ""; + var n3String = "<" + $(grant).data('roleUri') + "> \"true\" ." ; + + if ( $(grant).is(':checked') ) { + add = n3String; + } + else { + retract = n3String; + } + + $.ajax({ + url: manageGrants.processingUrl, + type: 'POST', + data: { + additions: add, + retractions: retract + }, + dataType: 'json', + context: grant, // context for callback + complete: function(request, status) { + + if (status === 'success') { + window.status = "The item has been successfully excluded from the profile page."; + + } else { + alert('Error processing request: the item cannot be excluded from the profile page.'); + $(grant).removeAttr('checked'); + } + } + }); + }, + +}; + +$(document).ready(function() { + manageGrants.onLoad(); +}); diff --git a/productMods/templates/freemarker/edit/forms/manageGrantsForIndividual.ftl b/productMods/templates/freemarker/edit/forms/manageGrantsForIndividual.ftl new file mode 100644 index 00000000..0127bf09 --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/manageGrantsForIndividual.ftl @@ -0,0 +1,56 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#-- Custom form for managing web pages for individuals --> +<#if subjectName?contains(",") > +<#assign lastName = subjectName?substring(0,subjectName?index_of(",")) /> +<#assign firstName = subjectName?substring(subjectName?index_of(",") + 1) /> +

Manage Grants & Projects for ${firstName} ${lastName}

+<#else> +

Manage Grants & Projects for ${subjectName}

+ +

+Check those grants and projects you want to exclude from the profile page. + +

+ + <#list allSubclasses as sub> +

${sub}

+
+ <#assign grantList = grants[sub]> +
    + <#list grantList as grant> +
  • + checked />${grant.label!} +
  • + + + +
+
+ + +
+

+ Return to profile page +

+ + + +${stylesheets.add('', + '')} + +${scripts.add('', + '', + '', + '')} + diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManageGrantsForIndividualController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManageGrantsForIndividualController.java new file mode 100644 index 00000000..291458dd --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManageGrantsForIndividualController.java @@ -0,0 +1,124 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ +package edu.cornell.mannlib.vitro.webapp.controller.freemarker; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.RDFNode; + +import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; +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.jena.QueryUtils; +import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; + + +public class ManageGrantsForIndividualController extends FreemarkerHttpServlet { + + private static final Log log = LogFactory.getLog(ManageGrantsForIndividualController.class.getName()); + private VClassDao vcDao = null; + private static final String TEMPLATE_NAME = "manageGrantsForIndividual.ftl"; + private List allSubclasses; + + @Override + protected Actions requiredActions(VitroRequest vreq) { + return SimplePermission.DO_FRONT_END_EDITING.ACTIONS; + } + + @Override + protected ResponseValues processRequest(VitroRequest vreq) { + + Map body = new HashMap(); + + String subjectUri = vreq.getParameter("subjectUri"); + + body.put("subjectUri", subjectUri); + + if (vreq.getAssertionsWebappDaoFactory() != null) { + vcDao = vreq.getAssertionsWebappDaoFactory().getVClassDao(); + } else { + vcDao = vreq.getFullWebappDaoFactory().getVClassDao(); + } + + HashMap>> grants = getGrants(subjectUri, vreq); + log.debug("grants = " + grants); + body.put("grants", grants); + body.put("allSubclasses", allSubclasses); + + Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); + if( subject != null && subject.getName() != null ){ + body.put("subjectName", subject.getName()); + }else{ + body.put("subjectName", null); + } + + return new TemplateResponseValues(TEMPLATE_NAME, body); + } + + private static String GRANT_QUERY = "" + + "PREFIX core: \n" + + "PREFIX rdfs: \n" + + "PREFIX vitro: \n" + + "PREFIX afn: \n" + + "SELECT DISTINCT ?subclass ?role (str(?label2) as ?label) ?activity ?hideThis WHERE { \n" + + " ?subject ?roleProp ?role . \n" + + " ?roleProp rdfs:subPropertyOf core:hasResearcherRole . \n" + + " ?role vitro:mostSpecificType ?subclass \n" + + " OPTIONAL { ?role core:roleRealizedIn ?activity \n" + + " OPTIONAL { ?activity rdfs:label ?label2 } \n" + + " } \n" + + " OPTIONAL { ?role core:roleContributesTo ?activity \n" + + " OPTIONAL { ?activity rdfs:label ?label2 } \n" + + " } \n" + + " OPTIONAL { ?role core:hideFromDisplay ?hideThis } \n" + + "} ORDER BY ?subclass ?label2"; + + + HashMap>> getGrants(String subjectUri, VitroRequest vreq) { + + String queryStr = QueryUtils.subUriForQueryVar(GRANT_QUERY, "subject", subjectUri); + log.debug("queryStr = " + queryStr); + HashMap>> subclassToGrants = new HashMap>>(); + try { + ResultSet results = QueryUtils.getQueryResults(queryStr, vreq); + while (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + String subclassUri = soln.get("subclass").toString(); + VClass vClass = (VClass) vcDao.getVClassByURI(subclassUri); + String subclass = ((vClass.getName() == null) ? subclassUri : vClass.getName()); + if(!subclassToGrants.containsKey(subclass)) { + subclassToGrants.put(subclass, new ArrayList>()); //list of grant information + } + String label = soln.get("label").toString(); + List> grantsList = subclassToGrants.get(subclass); + grantsList.add(QueryUtils.querySolutionToStringValueMap(soln)); + } + } catch (Exception e) { + log.error(e, e); + } + + allSubclasses = new ArrayList(subclassToGrants.keySet()); + Collections.sort(allSubclasses); + return subclassToGrants; + } +} + + diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePublicationsForIndividualController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePublicationsForIndividualController.java index 7e5374e0..780c0ac6 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePublicationsForIndividualController.java +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePublicationsForIndividualController.java @@ -79,10 +79,10 @@ public class ManagePublicationsForIndividualController extends FreemarkerHttpSer + "PREFIX rdfs: \n" + "PREFIX vitro: \n" + "PREFIX afn: \n" - + "SELECT DISTINCT ?subclass ?authorship ?title ?pub ?hideThis WHERE { \n" + + "SELECT DISTINCT ?subclass ?authorship (str(?label) as ?title) ?pub ?hideThis WHERE { \n" + " ?subject core:authorInAuthorship ?authorship . \n" + " OPTIONAL { ?authorship core:linkedInformationResource ?pub . " - + " ?pub rdfs:label ?title } \n" + + " ?pub rdfs:label ?label } \n" + " OPTIONAL { ?pub vitro:mostSpecificType ?subclass . \n" + " ?subclass rdfs:subClassOf core:InformationResource } \n" + " OPTIONAL { ?authorship core:hideFromDisplay ?hideThis } \n "