VIVO-17: QR Code info now generated via an Ajax call when the icon is clicked.

This commit is contained in:
Tim Worrall 2014-10-03 11:33:26 -04:00
parent 0ab6d244f5
commit 1c118fc044
13 changed files with 439 additions and 111 deletions

View file

@ -675,6 +675,15 @@
<url-pattern>/homePageAjax</url-pattern> <url-pattern>/homePageAjax</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet>
<servlet-name>QrCodeAjax</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.ajax.QrCodeAjaxController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>QrCodeAjax</servlet-name>
<url-pattern>/qrCodeAjax</url-pattern>
</servlet-mapping>
<servlet> <servlet>
<servlet-name>ShowAuth</servlet-name> <servlet-name>ShowAuth</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.admin.ShowAuthController</servlet-class> <servlet-class>edu.cornell.mannlib.vitro.webapp.controller.admin.ShowAuthController</servlet-class>

View file

@ -104,8 +104,64 @@ $(document).ready(function(){
// Reveal vCard QR code when QR icon is clicked // Reveal vCard QR code when QR icon is clicked
$('#qrIcon, .qrCloseLink').click(function() { $('#qrIcon, .qrCloseLink').click(function() {
// only create the img the first time, so check if it already exists
if ( !$('img#codeImage').length ) {
$.ajax({
url: "/vivo/qrCodeAjax",
dataType: "json",
data: {
action: "getQrCodeDetails",
uri: individualUri,
},
complete: function(xhr, status) {
var results = $.parseJSON(xhr.responseText);
if ( results.length == 0 ) {
var html = i18nStrings.currentlyNoResearchers;
}
else {
if ( results[0].firstName.length < 1 || results[1].lastName.length < 1 ) {
$('#qrCodeImage').css("width","225px");
var noCodeStr = "<div style='padding:25px 0 30px 22px;font-size:13px'>"
+ "The QR Code could not be generated due to incomplete information about this person. </div>"
$('#qrCodeImage').prepend(noCodeStr);
}
else if ( results[0].firstName.length > 0 || results[1] == null || results[1].lastName.length > 0 ) {
var vcard = "";
vcard += "BEGIN:VCARD" + String.fromCharCode(13);
vcard += "VERSION:3.0" + String.fromCharCode(13);
vcard += "N:" + results[1].lastName + String.fromCharCode(13);
vcard += "FN:" + results[0].firstName + String.fromCharCode(13);
if ( results[2].preferredTitle.length > 0 ) {
vcard += "TITLE:" + results[2].preferredTitle + String.fromCharCode(13);
}
if ( results[3].phoneNumber.length > 0 ) {
vcard += "TEL;TYPE=WORK,VOICE:" + results[3].phoneNumber + String.fromCharCode(13);
}
if ( results[4].email.length > 0 ) {
vcard += "EMAIL;TYPE=PREF,INTERNET:" + results[4].email + String.fromCharCode(13);
}
vcard += "URL:" + individualUri + String.fromCharCode(13);
if ( individualPhoto.length > 0 ) {
vcard += "PHOTO;VALUE=URL;TYPE=JPG:" + individualPhoto + String.fromCharCode(13);
}
vcard += "END:VCARD";
spanStr = "<a title='${i18n().export_qr_codes}' href='"
+ exportQrCodeUrl + "'>"
+ "<img id='codeImage' src='https://chart.googleapis.com/chart?cht=qr&amp;chs=125x125&amp;chl="
+ vcard
+ "&amp;choe=UTF-8'/>"
+ "</a>";
$('#qrCodeImage').prepend(spanStr);
}
}
}
});
}
$('#qrCodeImage').toggleClass('hidden'); $('#qrCodeImage').toggleClass('hidden');
return false;
}); });
// For pubs and grants on the foaf:person profile, and affiliated people // For pubs and grants on the foaf:person profile, and affiliated people

View file

@ -5,7 +5,7 @@
<#include "individual-qrCodeGenerator.ftl"> <#include "individual-qrCodeGenerator.ftl">
<h2>${i18n().export_qr_code} <em>(<a href="${individual.qrData().aboutQrCodesUrl}" title="${i18n().more_qr_info}">${i18n().what_is_this}</a>)</em></h2> <h2>${i18n().export_qr_code} <em>(<a href="${qrData.aboutQrCodesUrl}" title="${i18n().more_qr_info}">${i18n().what_is_this}</a>)</em></h2>
<#assign thumbUrl = individual.thumbUrl! "${urls.images}/placeholders/person.thumbnail.jpg" > <#assign thumbUrl = individual.thumbUrl! "${urls.images}/placeholders/person.thumbnail.jpg" >
<img class="individual-photo qrCode" src="${thumbUrl}" width="160" alt="${i18n().alt_thumbnail_photo}"/> <img class="individual-photo qrCode" src="${thumbUrl}" width="160" alt="${i18n().alt_thumbnail_photo}"/>

View file

@ -160,6 +160,9 @@
</script> </script>
</#if> </#if>
<script type="text/javascript"> <script type="text/javascript">
var individualUri = '${individual.uri!}';
var individualPhoto = '${individual.thumbNail!}';
var exportQrCodeUrl = '${urls.base}/qrcode?uri=${individual.uri!}';
var profileTypeData = { var profileTypeData = {
processingUrl: '${urls.base}/edit/primitiveRdfEdit', processingUrl: '${urls.base}/edit/primitiveRdfEdit',
individualUri: '${individual.uri!}', individualUri: '${individual.uri!}',

View file

@ -210,6 +210,9 @@
</script> </script>
</#if> </#if>
<script type="text/javascript"> <script type="text/javascript">
var individualUri = '${individual.uri!}';
var individualPhoto = '${individual.thumbNail!}';
var exportQrCodeUrl = '${urls.base}/qrcode?uri=${individual.uri!}';
var profileTypeData = { var profileTypeData = {
processingUrl: '${urls.base}/edit/primitiveRdfEdit', processingUrl: '${urls.base}/edit/primitiveRdfEdit',
individualUri: '${individual.uri!}', individualUri: '${individual.uri!}',

View file

@ -3,7 +3,11 @@
<#-- Icon controls displayed in upper-right corner --> <#-- Icon controls displayed in upper-right corner -->
<img id="uriIcon" title="${individual.uri}" src="${urls.images}/individual/share-uri-icon.png" alt="${i18n().share_the_uri}" /> <img id="uriIcon" title="${individual.uri}" src="${urls.images}/individual/share-uri-icon.png" alt="${i18n().share_the_uri}" />
<@qr.renderCode qrCodeIcon /> <img id="qrIcon" src="${urls.images}/individual/qr_icon.png" alt="${i18n().qr_icon}" />
<span id="qrCodeImage" class="hidden">${qrCodeLinkedImage!}
<a class="qrCloseLink" href="#" title="${i18n().qr_code}">${i18n().close_capitalized}</a>
</span>
<#-- <#--

View file

@ -31,7 +31,7 @@
--> -->
<#macro renderCode imageFile display="icon" width="125"> <#macro renderCode imageFile display="icon" width="125">
<#if hasValidVCard()> <#if hasValidVCard()>
<#local qrData = individual.qrData()> <#local qrData = qrData>
<#local qrCodeLinkedImage><a title="${i18n().export_qr_codes}" href="${qrData.exportQrCodeUrl}"><@qrCodeVCard qrCodeWidth=width /></a></#local> <#local qrCodeLinkedImage><a title="${i18n().export_qr_codes}" href="${qrData.exportQrCodeUrl}"><@qrCodeVCard qrCodeWidth=width /></a></#local>
<#if (display == "full")> <#if (display == "full")>
@ -51,7 +51,7 @@
<#function getQrCodeUrlForVCard qrCodeWidth> <#function getQrCodeUrlForVCard qrCodeWidth>
<#local qrData = individual.qrData()> <#local qrData = qrData>
<#local core = "http://vivoweb.org/ontology/core#"> <#local core = "http://vivoweb.org/ontology/core#">
<#local foaf = "http://xmlns.com/foaf/0.1/"> <#local foaf = "http://xmlns.com/foaf/0.1/">
@ -95,13 +95,14 @@
<#function getQrCodeUrlForLink qrCodeWidth> <#function getQrCodeUrlForLink qrCodeWidth>
<#local qrData = individual.qrData()> <#local qrData = qrData>
<#local url = qrData.externalUrl! > <#local externalUrl = qrData.externalUrl! >
<#local qrCodeUrl = ""> <#local qrCodeUrl = "">
<#if url != ""> <#if externalUrl != "">
<#local qrCodeContent = url?url> <#local fullExternalUrl = externalUrl + individual.profileUrl>
<#local qrCodeContent = fullExternalUrl?url>
<#local qrCodeUrl = "https://chart.googleapis.com/chart?cht=qr&amp;chs=${qrCodeWidth}x${qrCodeWidth}&amp;chl=${qrCodeContent}&amp;choe=UTF-8" > <#local qrCodeUrl = "https://chart.googleapis.com/chart?cht=qr&amp;chs=${qrCodeWidth}x${qrCodeWidth}&amp;chl=${qrCodeContent}&amp;choe=UTF-8" >
</#if> </#if>
@ -131,7 +132,7 @@
<#function hasValidVCard> <#function hasValidVCard>
<#local qrData = individual.qrData()> <#local qrData = qrData>
<#local firstName = qrData.firstName! > <#local firstName = qrData.firstName! >
<#local lastName = qrData.lastName! > <#local lastName = qrData.lastName! >

View file

@ -0,0 +1,37 @@
# $This file is distributed under the terms of the license in /doc/license.txt$
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix core: <http://vivoweb.org/ontology/core#> .
@prefix vivoweb: <http://vivoweb.org/ontology#> .
@prefix afn: <http://jena.hpl.hp.com/ARQ/function#> .
#### Check to see if the person being viewed has a first and last name. ####
#### If so, the page will display the QR code icon link. ####
## associate the classes with the datagetter (COUNT(?vIndividual) AS ?theCount)##
<http://xmlns.com/foaf/0.1/Person> display:hasDataGetter display:checkNamesForQrCodeDG .
## define the datagetter ##
display:checkNamesForQrCodeDG
a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
display:saveToVar "checkNamesResult";
display:query
"""
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
SELECT DISTINCT ?vIndividual
WHERE {
?individualURI obo:ARG_2000028 ?vIndividual .
?vIndividual vcard:hasName ?vName .
?vName vcard:givenName ?firstName .
?vName vcard:familyName ?lastName .
}
""" .

View file

@ -2,20 +2,29 @@
package edu.cornell.mannlib.vitro.webapp.controller; package edu.cornell.mannlib.vitro.webapp.controller;
import java.util.ArrayList;
import java.util.Enumeration;
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.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; 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.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalysisContextImpl; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalysisContextImpl;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo; import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import freemarker.ext.beans.BeansWrapper; import freemarker.ext.beans.BeansWrapper;
import freemarker.template.DefaultObjectWrapper; import freemarker.template.DefaultObjectWrapper;
@ -25,18 +34,41 @@ public class ExportQrCodeController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(ExportQrCodeController.class); private static final Log log = LogFactory.getLog(ExportQrCodeController.class);
private static final String TEMPLATE_DEFAULT = "foaf-person--exportQrCode.ftl"; private static final String TEMPLATE_DEFAULT = "foaf-person--exportQrCode.ftl";
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;
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
try { try {
Individual individual = getIndividualFromRequest(vreq); Individual individual = getIndividualFromRequest(vreq);
qrData = generateQrData(individual, vreq);
DefaultObjectWrapper wrapper = new DefaultObjectWrapper(); DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
wrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE); wrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE);
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("individual", wrapper.wrap(new IndividualTemplateModel(individual, vreq))); body.put("individual", wrapper.wrap(new IndividualTemplateModel(individual, vreq)));
body.put("qrData", qrData);
return new TemplateResponseValues(TEMPLATE_DEFAULT, body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} catch (Throwable e) { } catch (Throwable e) {
log.error(e, e); log.error(e, e);
@ -60,4 +92,71 @@ public class ExportQrCodeController extends FreemarkerHttpServlet {
} }
} }
private Map<String, String> generateQrData(Individual individual, VitroRequest vreq) {
try {
String firstName = "";
String lastName = "";
String preferredTitle = "";
String phoneNumber = "";
String email = "";
vcardData = getVcardData(individual, vreq);
Map<String,String> qrData = new HashMap<String,String>();
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");
}
if(firstName != null && firstName.length() > 0)
qrData.put("firstName", firstName);
if(lastName != null && lastName.length() > 0)
qrData.put("lastName", lastName);
if(preferredTitle != null && preferredTitle.length() > 0)
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 tempUrl = vreq.getRequestURL().toString();
String prefix = "http://";
tempUrl = tempUrl.substring(0, tempUrl.replace(prefix, "").indexOf("/") + prefix.length());
String externalUrl = tempUrl ;
qrData.put("externalUrl", externalUrl);
String individualUri = individual.getURI();
String contextPath = vreq.getContextPath();
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri));
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;
}
} }

View file

@ -0,0 +1,43 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.ajax;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
/**
* Handle the AJAX functions that are specific to the "new" home page sections, at
* this point just the mapping of geographic locations.
*/
public class QrCodeAjaxController extends VitroAjaxController {
private static final Log log = LogFactory
.getLog(QrCodeAjaxController.class);
private static final String PARAMETER_ACTION = "action";
@Override
protected void doRequest(VitroRequest vreq, HttpServletResponse resp)
throws ServletException, IOException {
try {
String function = vreq.getParameter(PARAMETER_ACTION);
if ("getQrCodeDetails".equals(function)) {
new QrCodeDetails(this, vreq, resp).processRequest();
}
else {
resp.getWriter().write("[]");
}
} catch (Exception e) {
log.error(e, e);
resp.getWriter().write("[]");
}
}
}

View file

@ -0,0 +1,162 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.ajax;
import java.io.IOException;
import java.lang.Integer;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
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.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
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.controller.individual.IndividualRequestAnalysisContextImpl;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestAnalyzer;
import edu.cornell.mannlib.vitro.webapp.controller.individual.IndividualRequestInfo;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
public class QrCodeDetails extends AbstractAjaxResponder {
private static final Log log = LogFactory.getLog(QrCodeDetails.class.getName());
private List<Map<String,String>> vcardData;
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"
+ "} " ;
public QrCodeDetails(HttpServlet parent, VitroRequest vreq,
HttpServletResponse resp) {
super(parent, vreq, resp);
}
@Override
public String prepareResponse() throws IOException, JSONException {
try {
Individual individual = getIndividualFromRequest(vreq);
String firstName = "";
String lastName = "";
String preferredTitle = "";
String phoneNumber = "";
String email = "";
String response = "[";
vcardData = getVcardData(individual, vreq);
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");
}
/*
String tempUrl = vreq.getRequestURL().toString();
String prefix = "http://";
tempUrl = tempUrl.substring(0, tempUrl.replace(prefix, "").indexOf("/") + prefix.length());
String profileUrl = UrlBuilder.getIndividualProfileUrl(individual, vreq);
String externalUrl = tempUrl + profileUrl;
*/
if (firstName != null && firstName.length() > 0) {
response += "{\"firstName\": \"" + firstName + "\"},";
}
else {
response += "{\"firstName\": \"\"},";
}
if (lastName != null && lastName.length() > 0) {
response += "{\"lastName\": \"" + lastName + "\"},";
}
else {
response += "{\"lastName\": \"\"},";
}
if (preferredTitle != null && preferredTitle.length() > 0) {
response += "{\"preferredTitle\": \"" + preferredTitle + "\"},";
}
else {
response += "{\"preferredTitle\": \"\"},";
}
if (phoneNumber != null && phoneNumber.length() > 0) {
response += "{\"phoneNumber\": \"\"},";
}
else {
response += "{\"phoneNumber\": \"\"},";
}
if (email != null && email.length() > 0) {
response += "{\"email\": \"" + email + "\"},";
}
else {
response += "{\"email\": \"\"},";
}
response += " ]";
response = response.replace(", ]"," ]");
log.debug(response);
return response;
} catch (Exception e) {
log.error("Could not retrieve vCard information", e);
return EMPTY_RESPONSE;
}
}
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 Individual getIndividualFromRequest(VitroRequest vreq) {
IndividualRequestInfo requestInfo = new IndividualRequestAnalyzer(vreq,
new IndividualRequestAnalysisContextImpl(vreq)).analyze();
return requestInfo.getIndividual();
}
}

View file

@ -39,101 +39,11 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
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;
public IndividualTemplateModel(Individual individual, VitroRequest vreq) { public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
super(individual, vreq); super(individual, vreq);
} }
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>();
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");
}
if(firstName != null && firstName.length() > 0)
qrData.put("firstName", firstName);
if(lastName != null && lastName.length() > 0)
qrData.put("lastName", lastName);
if(preferredTitle != null && preferredTitle.length() > 0)
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 tempUrl = vreq.getRequestURL().toString();
String prefix = "http://";
tempUrl = tempUrl.substring(0, tempUrl.replace(prefix, "").indexOf("/") + prefix.length());
String profileUrl = getProfileUrl();
String externalUrl = tempUrl + profileUrl;
qrData.put("externalUrl", externalUrl);
String individualUri = individual.getURI();
String contextPath = vreq.getContextPath();
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri));
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) {
String visUrl; String visUrl;
boolean isUsingDefaultNameSpace = UrlBuilder.isUriInDefaultNamespace( boolean isUsingDefaultNameSpace = UrlBuilder.isUriInDefaultNamespace(
@ -192,10 +102,4 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
return getVisUrl(url); return getVisUrl(url);
} }
public Map<String, String> qrData() {
if(qrData == null)
qrData = generateQrData();
return qrData;
}
} }

View file

@ -6,7 +6,6 @@
--> -->
<#include "individual-setup.ftl"> <#include "individual-setup.ftl">
<#import "individual-qrCodeGenerator.ftl" as qr>
<#import "lib-vivo-properties.ftl" as vp> <#import "lib-vivo-properties.ftl" as vp>
<#--Number of labels present--> <#--Number of labels present-->
<#if !labelCount??> <#if !labelCount??>
@ -46,7 +45,12 @@
<div id="individual-tools-people"> <div id="individual-tools-people">
<span id="iconControlsLeftSide"> <span id="iconControlsLeftSide">
<img id="uriIcon" title="${individual.uri}" src="${urls.images}/individual/uriIcon.gif" alt="${i18n().uri_icon}"/> <img id="uriIcon" title="${individual.uri}" src="${urls.images}/individual/uriIcon.gif" alt="${i18n().uri_icon}"/>
<@qr.renderCode "qr_icon.png" /> <#if checkNamesResult?has_content >
<img id="qrIcon" src="${urls.images}/individual/qr_icon.png" alt="${i18n().qr_icon}" />
<span id="qrCodeImage" class="hidden">${qrCodeLinkedImage!}
<a class="qrCloseLink" href="#" title="${i18n().qr_code}">${i18n().close_capitalized}</a>
</span>
</#if>
</span> </span>
</div> </div>
<#include "individual-contactInfo.ftl"> <#include "individual-contactInfo.ftl">
@ -138,6 +142,9 @@
</#if> </#if>
<script> <script>
var imagesPath = '${urls.images}'; var imagesPath = '${urls.images}';
var individualUri = '${individual.uri!}';
var individualPhoto = '${individual.thumbNail!}';
var exportQrCodeUrl = '${urls.base}/qrcode?uri=${individual.uri!}';
var i18nStrings = { var i18nStrings = {
displayLess: '${i18n().display_less}', displayLess: '${i18n().display_less}',
displayMoreEllipsis: '${i18n().display_more_ellipsis}', displayMoreEllipsis: '${i18n().display_more_ellipsis}',