This commit is contained in:
tworrall 2013-10-15 16:03:32 -04:00
parent 48181193b7
commit 2a7b54d139
4 changed files with 91 additions and 36 deletions

View file

@ -56,7 +56,7 @@
<#if title?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <#if title?has_content> <#-- true when the property is in the list, even if not populated (when editing) -->
<#if (title.statements?size < 1) > <#if (title.statements?size < 1) >
<@p.addLinkWithLabel title editable /> <@p.addLinkWithLabel title editable />
<#else> <#elseif editable>
<h2>${title.name?capitalize!}</h2> <h2>${title.name?capitalize!}</h2>
<@p.verboseDisplay title /> <@p.verboseDisplay title />
</#if> </#if>

View file

@ -5,7 +5,7 @@
<#if positions?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <#if positions?has_content> <#-- true when the property is in the list, even if not populated (when editing) -->
<#assign localName = positions.localName> <#assign localName = positions.localName>
<h2 id="${localName}" class="mainPropGroup">${positions.name?capitalize} <@p.addLink positions editable /> <@p.verboseDisplay positions /></h2> <h2 id="${localName}" class="mainPropGroup">${positions.name?capitalize} <@p.addLink positions editable /> <@p.verboseDisplay positions /></h2>
<ul id="individual-${localName}" role="list"> <ul id="individual-personInPosition" role="list">
<@p.objectProperty positions editable /> <@p.objectProperty positions editable />
</ul> </ul>
</#if> </#if>

View file

@ -2,13 +2,19 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -16,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants; import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
public class IndividualTemplateModel extends BaseIndividualTemplateModel { public class IndividualTemplateModel extends BaseIndividualTemplateModel {
@ -23,12 +30,31 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
private static final Log log = LogFactory.getLog(IndividualTemplateModel.class); private static final Log log = LogFactory.getLog(IndividualTemplateModel.class);
private static final String FOAF = "http://xmlns.com/foaf/0.1/"; private static final String FOAF = "http://xmlns.com/foaf/0.1/";
private static final String CORE = "http://vivoweb.org/ontology/core#";
private static final String PERSON_CLASS = FOAF + "Person"; private static final String PERSON_CLASS = FOAF + "Person";
private static final String ORGANIZATION_CLASS = FOAF + "Organization"; private static final String ORGANIZATION_CLASS = FOAF + "Organization";
private static final String BASE_VISUALIZATION_URL = private static final String BASE_VISUALIZATION_URL =
UrlBuilder.getUrl(Route.VISUALIZATION_SHORT.path()); UrlBuilder.getUrl(Route.VISUALIZATION_SHORT.path());
private static String VCARD_DATA_QUERY = ""
+ "PREFIX obo: <http://purl.obolibrary.org/obo/> \n"
+ "PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> \n"
+ "SELECT DISTINCT ?firstName ?lastName ?email ?phone ?title \n"
+ "WHERE { \n"
+ " ?subject obo:ARG_2000028 ?vIndividual . \n"
+ " ?vIndividual vcard:hasName ?vName . \n"
+ " ?vName vcard:givenName ?firstName . \n"
+ " ?vName vcard:familyName ?lastName . \n"
+ " OPTIONAL { ?vIndividual vcard:hasEmail ?vEmail . \n"
+ " ?vEmail vcard:email ?email . \n"
+ " } \n"
+ " OPTIONAL { ?vIndividual vcard:hasTelephone ?vPhone . \n"
+ " ?vPhone vcard:telephone ?phone . \n"
+ " } \n"
+ " OPTIONAL { ?vIndividual vcard:hasTitle ?vTitle . \n"
+ " ?vTitle vcard:title ?title . \n"
+ " } \n"
+ "} " ;
private List<Map<String,String>> vcardData;
private Map<String, String> qrData = null; private Map<String, String> qrData = null;
public IndividualTemplateModel(Individual individual, VitroRequest vreq) { public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
@ -37,41 +63,70 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
private Map<String, String> generateQrData() { private Map<String, String> generateQrData() {
Map<String,String> qrData = new HashMap<String,String>(); try {
String firstName = "";
String lastName = "";
String preferredTitle = "";
String phoneNumber = "";
String email = "";
WebappDaoFactory wdf = vreq.getUnfilteredWebappDaoFactory(); vcardData = getVcardData(individual, vreq);
Collection<DataPropertyStatement> firstNames = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, FOAF + "firstName"); Map<String,String> qrData = new HashMap<String,String>();
Collection<DataPropertyStatement> lastNames = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, FOAF + "lastName");
Collection<DataPropertyStatement> preferredTitles = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, CORE + "preferredTitle");
Collection<DataPropertyStatement> phoneNumbers = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, CORE + "phoneNumber");
Collection<DataPropertyStatement> emails = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, CORE + "email");
if(firstNames != null && ! firstNames.isEmpty()) for (Map<String, String> map: vcardData) {
qrData.put("firstName", firstNames.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); firstName = map.get("firstName");
if(lastNames != null && ! lastNames.isEmpty()) lastName = map.get("lastName");
qrData.put("lastName", lastNames.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); preferredTitle = map.get("title");
if(preferredTitles != null && ! preferredTitles.isEmpty()) phoneNumber = map.get("phone");
qrData.put("preferredTitle", preferredTitles.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); email = map.get("email");
if(phoneNumbers != null && ! phoneNumbers.isEmpty()) }
qrData.put("phoneNumber", phoneNumbers.toArray(new DataPropertyStatement[firstNames.size()])[0].getData());
if(emails != null && ! emails.isEmpty())
qrData.put("email", emails.toArray(new DataPropertyStatement[firstNames.size()])[0].getData());
String tempUrl = vreq.getRequestURL().toString(); if(firstName != null && firstName.length() > 0)
String prefix = "http://"; qrData.put("firstName", firstName);
tempUrl = tempUrl.substring(0, tempUrl.replace(prefix, "").indexOf("/") + prefix.length()); if(lastName != null && lastName.length() > 0)
String profileUrl = getProfileUrl(); qrData.put("lastName", lastName);
String externalUrl = tempUrl + profileUrl; if(preferredTitle != null && preferredTitle.length() > 0)
qrData.put("externalUrl", externalUrl); qrData.put("preferredTitle", preferredTitle);
if(phoneNumber != null && phoneNumber.length() > 0)
qrData.put("phoneNumber", phoneNumber);
if(email != null && email.length() > 0)
qrData.put("email", email);
String individualUri = individual.getURI(); String tempUrl = vreq.getRequestURL().toString();
String contextPath = vreq.getContextPath(); String prefix = "http://";
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri)); tempUrl = tempUrl.substring(0, tempUrl.replace(prefix, "").indexOf("/") + prefix.length());
String profileUrl = getProfileUrl();
String externalUrl = tempUrl + profileUrl;
qrData.put("externalUrl", externalUrl);
qrData.put("aboutQrCodesUrl", contextPath + "/qrcode/about"); String individualUri = individual.getURI();
String contextPath = vreq.getContextPath();
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri));
return qrData; qrData.put("aboutQrCodesUrl", contextPath + "/qrcode/about");
return qrData;
} catch (Exception e) {
log.error("Failed getting QR code data", e);
return null;
}
}
private List<Map<String,String>> getVcardData(Individual individual, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(VCARD_DATA_QUERY, "subject", individual.getURI());
log.debug("queryStr = " + queryStr);
List<Map<String,String>> vcardData = new ArrayList<Map<String,String>>();
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
vcardData.add(QueryUtils.querySolutionToStringValueMap(soln));
}
} catch (Exception e) {
log.error(e, e);
}
return vcardData;
} }
private String getVisUrl(String visPath) { private String getVisUrl(String visPath) {

View file

@ -71,7 +71,7 @@
<#if title?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <#if title?has_content> <#-- true when the property is in the list, even if not populated (when editing) -->
<#if (title.statements?size < 1) > <#if (title.statements?size < 1) >
<@p.addLinkWithLabel title editable /> <@p.addLinkWithLabel title editable />
<#else> <#elseif editable>
<h2>${title.name?capitalize!}</h2> <h2>${title.name?capitalize!}</h2>
<@p.verboseDisplay title /> <@p.verboseDisplay title />
</#if> </#if>
@ -126,7 +126,7 @@
<#if rdfUrl??> <#if rdfUrl??>
<script> <script>
var individualRdfUrl = '${rdfUrl}'; var individualRdfUrl = '${rdfUrl?replace("display","individual")}';
</script> </script>
</#if> </#if>
<script> <script>