NIHVIVO-3728 vivo components of publications management

This commit is contained in:
tworrall 2012-05-22 20:27:32 +00:00
parent 596310913b
commit 91881dc6f5
7 changed files with 306 additions and 3 deletions

View file

@ -797,6 +797,15 @@
</servlet-mapping>
<servlet>
<servlet-name>ManagePublicationsForIndividualController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.generators.ManagePublicationsForIndividualController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ManagePublicationsForIndividualController</servlet-name>
<url-pattern>/managePublications</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ShowClassHierarchyController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ShowClassHierarchyController</servlet-class>

View file

@ -55,7 +55,8 @@
OPTIONAL { ?infoResource core:dateTimeValue ?dateTimeValue .
?dateTimeValue core:dateTime ?dateTime
}
}
}
NOT EXISTS { ?authorship core:hideFromDisplay ?hideThis }
<critical-data-required>
FILTER ( bound(?infoResource) )
</critical-data-required>

View file

@ -239,4 +239,10 @@ a.qrCloseLink {
padding: 0.2em 0.4em;
font-size: 0.8em;
background: #f4f4f4;
}
}
/* <---- Manage Prop Link, individual-properties.ftl -----*/
a#managePropLink {
float:right;font-size:.8em;
padding-right:10px;
display:inline;
}

View file

@ -121,4 +121,29 @@ fieldset.dateTime label {
}
fieldset.dateTime select {
margin-top: 0;
}
}
/* ---------------------------------- */
/* ----- FOR MANAGE PUBLICATIONS ---- */
/* ---------------------------------- */
section#pubsContainer {
margin-top:-8px;
padding-left:25px;
}
section#pubsContainer ul {
padding-left:25px;
text-indent:-25px;
}
section#pubsContainer li {
margin-bottom:6px;
line-height:20px;
}
section#pubsContainer input {
margin-right:8px;
}

View file

@ -0,0 +1,85 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
var managePublications = {
/* *** 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.initPublicationData();
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.
initPublicationData: function() {
$('.pubCheckbox').each(function(index) {
$(this).data(publicationData[index]);
});
},
bindEventListeners: function() {
$('.pubCheckbox').click(function() {
managePublications.processPublication(this);
//return false;
});
},
processPublication: function(publication) {
var add = "";
var retract = "";
var n3String = "<" + $(publication).data('authorshipUri') + "> <http://vivoweb.org/ontology/core#hideFromDisplay> \"true\" ." ;
if ( $(publication).is(':checked') ) {
add = n3String;
}
else {
retract = n3String;
}
$.ajax({
url: managePublications.processingUrl,
type: 'POST',
data: {
additions: add,
retractions: retract
},
dataType: 'json',
context: publication, // context for callback
complete: function(request, status) {
if (status === 'success') {
window.status = "The publication will has been successfully excluded from the profile page.";
} else {
alert('Error processing request: the publication cannot be excluded from the profile page.');
$(publication).removeAttr('checked');
}
}
});
},
};
$(document).ready(function() {
managePublications.onLoad();
});

View file

@ -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) />
<h2>Manage Publications for ${firstName} ${lastName}</h2>
<#else>
<h2>Manage Publications for ${subjectName}</h2>
</#if>
<p style="margin-left:25px;margin-bottom:12px">
Check those publications you want to exclude from the profile page.
<script type="text/javascript">
var publicationData = [];
</script>
</p>
<#list allSubclasses as sub>
<h4>${sub}s</h4>
<section id="pubsContainer" role="container">
<#assign pubs = publications[sub]>
<ul >
<#list pubs as pub>
<li>
<input type="checkbox" class="pubCheckbox" <#if pub.hideThis??>checked</#if> />${pub.title}
</li>
<script type="text/javascript">
publicationData.push({
"authorshipUri": "${pub.authorship}"
});
</script>
</#list>
</ul>
</section>
</#list>
<br />
<p>
<a href="${urls.referringPage}#publications" title="return to profile page">Return to profile page</a>
</p>
<script type="text/javascript">
var customFormData = {
processingUrl: '${urls.base}/edit/primitiveRdfEdit'
};
</script>
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/templates/freemarker/edit/forms/css/customForm.css" />',
'<link rel="stylesheet" href="${urls.base}/js/jquery-ui/css/smoothness/jquery-ui-1.8.9.custom.css" />')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/utils.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>',
'<script type="text/javascript" src="${urls.base}/templates/freemarker/edit/forms/js/managePublicationsForIndividual.js"></script>')}

View file

@ -0,0 +1,121 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker.generators;
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 ManagePublicationsForIndividualController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(ManagePublicationsForIndividualController.class.getName());
private VClassDao vcDao = null;
private static final String TEMPLATE_NAME = "managePublicationsForIndividual.ftl";
private List<String> allSubclasses;
@Override
protected Actions requiredActions(VitroRequest vreq) {
return SimplePermission.DO_FRONT_END_EDITING.ACTIONS;
}
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, Object> body = new HashMap<String, Object>();
String subjectUri = vreq.getParameter("subjectUri");
body.put("subjectUri", subjectUri);
if (vreq.getAssertionsWebappDaoFactory() != null) {
vcDao = vreq.getAssertionsWebappDaoFactory().getVClassDao();
} else {
vcDao = vreq.getFullWebappDaoFactory().getVClassDao();
}
HashMap<String, List<Map<String,String>>> publications = getPublications(subjectUri, vreq);
log.debug("publications = " + publications);
body.put("publications", publications);
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 PUBLICATION_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n"
+ "PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#> \n"
+ "SELECT DISTINCT ?subclass ?authorship ?title ?pub ?hideThis WHERE { \n"
+ " ?subject core:authorInAuthorship ?authorship . \n"
+ " OPTIONAL { ?authorship core:linkedInformationResource ?pub . "
+ " ?pub rdfs:label ?title } \n"
+ " OPTIONAL { ?pub vitro:mostSpecificType ?subclass . \n"
+ " ?subclass rdfs:subClassOf core:InformationResource } \n"
+ " OPTIONAL { ?authorship core:hideFromDisplay ?hideThis } \n "
+ "} ORDER BY ?subclass ?title";
HashMap<String, List<Map<String,String>>> getPublications(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(PUBLICATION_QUERY, "subject", subjectUri);
log.debug("queryStr = " + queryStr);
HashMap<String, List<Map<String,String>>> subclassToPublications = new HashMap<String, List<Map<String,String>>>();
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(!subclassToPublications.containsKey(subclass)) {
subclassToPublications.put(subclass, new ArrayList<Map<String,String>>()); //list of publication information
}
List<Map<String,String>> publicationsList = subclassToPublications.get(subclass);
publicationsList.add(QueryUtils.querySolutionToStringValueMap(soln));
}
} catch (Exception e) {
log.error(e, e);
}
allSubclasses = new ArrayList<String>(subclassToPublications.keySet());
Collections.sort(allSubclasses);
return subclassToPublications;
}
}