merging r4248 into the trunk
This commit is contained in:
parent
2c460312d3
commit
ff7ef0267f
4 changed files with 265 additions and 1 deletions
|
@ -33,7 +33,9 @@
|
|||
?dateTimeEndValue core:dateTime ?dateTimeEnd
|
||||
}
|
||||
# Get current positions only: end date is either null or not in the past
|
||||
} FILTER ( !bound(?dateTimeEnd) ||
|
||||
}
|
||||
NOT EXISTS { ?position core:hideFromDisplay ?hideThis }
|
||||
FILTER ( !bound(?dateTimeEnd) ||
|
||||
afn:substring(str(?dateTimeEnd), 0, 4) >= afn:substring(str(afn:now()), 0, 4) )
|
||||
<critical-data-required>
|
||||
FILTER ( bound(?person) )
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var managePeople = {
|
||||
|
||||
/* *** 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.initPeopleData();
|
||||
|
||||
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.
|
||||
initPeopleData: function() {
|
||||
$('.pubCheckbox').each(function(index) {
|
||||
$(this).data(peopleData[index]);
|
||||
});
|
||||
},
|
||||
|
||||
bindEventListeners: function() {
|
||||
|
||||
$('.pubCheckbox').click(function() {
|
||||
managePeople.processPeople(this);
|
||||
//return false;
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
processPeople: function(person) {
|
||||
|
||||
var add = "";
|
||||
var retract = "";
|
||||
var n3String = "<" + $(person).data('positionUri') + "> <http://vivoweb.org/ontology/core#hideFromDisplay> \"true\" ." ;
|
||||
|
||||
if ( $(person).is(':checked') ) {
|
||||
add = n3String;
|
||||
}
|
||||
else {
|
||||
retract = n3String;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: managePeople.processingUrl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
additions: add,
|
||||
retractions: retract
|
||||
},
|
||||
dataType: 'json',
|
||||
context: person, // context for callback
|
||||
complete: function(request, status) {
|
||||
|
||||
if (status === 'success') {
|
||||
window.status = "The person has been successfully excluded from the organization page.";
|
||||
|
||||
} else {
|
||||
alert('Error processing request: the person cannot be excluded from the organization page.');
|
||||
$(person).removeAttr('checked');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
managePeople.onLoad();
|
||||
});
|
|
@ -0,0 +1,55 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#import "lib-vivo-form.ftl" as lvf>
|
||||
|
||||
<#-- Custom form for managing web pages for individuals -->
|
||||
<h2>Manage People Affiliated with ${subjectName}</h2>
|
||||
<p style="margin-left:25px;margin-bottom:12px">
|
||||
Check those people you want to exclude from the profile page.
|
||||
<script type="text/javascript">
|
||||
var peopleData = [];
|
||||
</script>
|
||||
</p>
|
||||
|
||||
<@lvf.unsupportedBrowser urls.base />
|
||||
|
||||
|
||||
<#list allSubclasses as sub>
|
||||
<h4>${sub}s</h4>
|
||||
<section id="pubsContainer" role="container">
|
||||
<#assign peeps = people[sub]>
|
||||
<ul >
|
||||
<#list peeps as person>
|
||||
<li>
|
||||
<input type="checkbox" class="pubCheckbox" <#if person.hideThis??>checked</#if> />${person.name}
|
||||
</li>
|
||||
<script type="text/javascript">
|
||||
peopleData.push({
|
||||
"positionUri": "${person.position}"
|
||||
});
|
||||
</script>
|
||||
|
||||
</#list>
|
||||
</ul>
|
||||
</section>
|
||||
</#list>
|
||||
|
||||
<br />
|
||||
<p>
|
||||
<a href="${urls.referringPage}#affiliation" 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/managePeopleForOrganization.js"></script>')}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/* $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 ManagePeopleForOrganizationController extends FreemarkerHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ManagePeopleForOrganizationController.class.getName());
|
||||
private VClassDao vcDao = null;
|
||||
private static final String TEMPLATE_NAME = "managePeopleForOrganization.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>>> people = getPeople(subjectUri, vreq);
|
||||
log.debug("people = " + people);
|
||||
body.put("people", people);
|
||||
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 PEOPLE_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 ?position (str(?label) as ?name) ?person ?hideThis WHERE { \n"
|
||||
+ " ?subject core:organizationForPosition ?position . \n"
|
||||
+ " OPTIONAL { ?position core:positionForPerson ?person . "
|
||||
+ " ?person rdfs:label ?label } \n"
|
||||
+ " OPTIONAL { ?position vitro:mostSpecificType ?subclass . \n"
|
||||
+ " ?subclass rdfs:subClassOf core:Position } \n"
|
||||
+ " OPTIONAL { ?position core:hideFromDisplay ?hideThis } \n "
|
||||
+ "} ORDER BY ?subclass ?name";
|
||||
|
||||
HashMap<String, List<Map<String,String>>> getPeople(String subjectUri, VitroRequest vreq) {
|
||||
|
||||
String queryStr = QueryUtils.subUriForQueryVar(PEOPLE_QUERY, "subject", subjectUri);
|
||||
log.debug("queryStr = " + queryStr);
|
||||
HashMap<String, List<Map<String,String>>> subclassToPeople = new HashMap<String, List<Map<String,String>>>();
|
||||
try {
|
||||
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||
while (results.hasNext()) {
|
||||
QuerySolution soln = results.nextSolution();
|
||||
RDFNode subclassUri= soln.get("subclass");
|
||||
if ( subclassUri != null ) {
|
||||
String subclassUriStr = soln.get("subclass").toString();
|
||||
VClass vClass = (VClass) vcDao.getVClassByURI(subclassUriStr);
|
||||
String subclass = ((vClass.getName() == null) ? subclassUriStr : vClass.getName());
|
||||
if(!subclassToPeople.containsKey(subclass)) {
|
||||
subclassToPeople.put(subclass, new ArrayList<Map<String,String>>());
|
||||
}
|
||||
List<Map<String,String>> peopleList = subclassToPeople.get(subclass);
|
||||
peopleList.add(QueryUtils.querySolutionToStringValueMap(soln));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
|
||||
allSubclasses = new ArrayList<String>(subclassToPeople.keySet());
|
||||
Collections.sort(allSubclasses);
|
||||
return subclassToPeople;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue