VIVO-367
This commit is contained in:
parent
48181193b7
commit
2a7b54d139
4 changed files with 91 additions and 36 deletions
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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,26 +63,35 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
|
||||||
|
|
||||||
private Map<String, String> generateQrData() {
|
private Map<String, String> generateQrData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String firstName = "";
|
||||||
|
String lastName = "";
|
||||||
|
String preferredTitle = "";
|
||||||
|
String phoneNumber = "";
|
||||||
|
String email = "";
|
||||||
|
|
||||||
|
vcardData = getVcardData(individual, vreq);
|
||||||
|
|
||||||
Map<String,String> qrData = new HashMap<String,String>();
|
Map<String,String> qrData = new HashMap<String,String>();
|
||||||
|
|
||||||
WebappDaoFactory wdf = vreq.getUnfilteredWebappDaoFactory();
|
for (Map<String, String> map: vcardData) {
|
||||||
|
firstName = map.get("firstName");
|
||||||
|
lastName = map.get("lastName");
|
||||||
|
preferredTitle = map.get("title");
|
||||||
|
phoneNumber = map.get("phone");
|
||||||
|
email = map.get("email");
|
||||||
|
}
|
||||||
|
|
||||||
Collection<DataPropertyStatement> firstNames = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, FOAF + "firstName");
|
if(firstName != null && firstName.length() > 0)
|
||||||
Collection<DataPropertyStatement> lastNames = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, FOAF + "lastName");
|
qrData.put("firstName", firstName);
|
||||||
Collection<DataPropertyStatement> preferredTitles = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, CORE + "preferredTitle");
|
if(lastName != null && lastName.length() > 0)
|
||||||
Collection<DataPropertyStatement> phoneNumbers = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, CORE + "phoneNumber");
|
qrData.put("lastName", lastName);
|
||||||
Collection<DataPropertyStatement> emails = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, CORE + "email");
|
if(preferredTitle != null && preferredTitle.length() > 0)
|
||||||
|
qrData.put("preferredTitle", preferredTitle);
|
||||||
if(firstNames != null && ! firstNames.isEmpty())
|
if(phoneNumber != null && phoneNumber.length() > 0)
|
||||||
qrData.put("firstName", firstNames.toArray(new DataPropertyStatement[firstNames.size()])[0].getData());
|
qrData.put("phoneNumber", phoneNumber);
|
||||||
if(lastNames != null && ! lastNames.isEmpty())
|
if(email != null && email.length() > 0)
|
||||||
qrData.put("lastName", lastNames.toArray(new DataPropertyStatement[firstNames.size()])[0].getData());
|
qrData.put("email", email);
|
||||||
if(preferredTitles != null && ! preferredTitles.isEmpty())
|
|
||||||
qrData.put("preferredTitle", preferredTitles.toArray(new DataPropertyStatement[firstNames.size()])[0].getData());
|
|
||||||
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();
|
String tempUrl = vreq.getRequestURL().toString();
|
||||||
String prefix = "http://";
|
String prefix = "http://";
|
||||||
|
@ -70,8 +105,28 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
|
||||||
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri));
|
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri));
|
||||||
|
|
||||||
qrData.put("aboutQrCodesUrl", contextPath + "/qrcode/about");
|
qrData.put("aboutQrCodesUrl", contextPath + "/qrcode/about");
|
||||||
|
|
||||||
return qrData;
|
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) {
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue