Adding first and last name to JSON data service NIHVIVO-1599
This commit is contained in:
parent
acabfe7f38
commit
7cd1f4384c
1 changed files with 31 additions and 18 deletions
|
@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -26,15 +25,15 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import atg.taglib.json.util.HTTP;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
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.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
|
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator;
|
||||||
|
@ -79,12 +78,18 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getLuceneIndividualsByVClass(HttpServletRequest req, HttpServletResponse resp) {
|
private void getLuceneIndividualsByVClass(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
String message = null;
|
String message = null;
|
||||||
VClass vclass=null;
|
VClass vclass=null;
|
||||||
JSONObject rObj = new JSONObject();
|
JSONObject rObj = new JSONObject();
|
||||||
|
|
||||||
|
DataProperty fNameDp = (new DataProperty());
|
||||||
|
fNameDp.setURI("http://xmlns.com/foaf/0.1/firstName");
|
||||||
|
DataProperty lNameDp = (new DataProperty());
|
||||||
|
lNameDp.setURI("http://xmlns.com/foaf/0.1/lastName");
|
||||||
|
|
||||||
if( log.isDebugEnabled() ){
|
if( log.isDebugEnabled() ){
|
||||||
Enumeration<String> e = vreq.getParameterNames();
|
Enumeration<String> e = vreq.getParameterNames();
|
||||||
while(e.hasMoreElements()){
|
while(e.hasMoreElements()){
|
||||||
|
@ -96,6 +101,10 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//need an unfiltered dao to get firstnames and lastnames
|
||||||
|
WebappDaoFactory fullWdf = vreq.getFullWebappDaoFactory();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String vitroClassIdStr = vreq.getParameter("vclassId");
|
String vitroClassIdStr = vreq.getParameter("vclassId");
|
||||||
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
if ( vitroClassIdStr != null && !vitroClassIdStr.isEmpty()){
|
||||||
|
@ -140,18 +149,8 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
jo.put("imageUrl", ind.getImageUrl());
|
jo.put("imageUrl", ind.getImageUrl());
|
||||||
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq.getWebappDaoFactory()));
|
jo.put("profileUrl", UrlBuilder.getIndividualProfileUrl(ind, vreq.getWebappDaoFactory()));
|
||||||
|
|
||||||
//this doesn't work as these properties are filtered out.
|
jo.put("firstName", getDataPropertyValue(ind, fNameDp, fullWdf));
|
||||||
String fname = ind.getDataValue( "http://xmlns.com/foaf/0.1/firstName");
|
jo.put("lastName", getDataPropertyValue(ind, lNameDp, fullWdf));
|
||||||
if( fname != null )
|
|
||||||
jo.put("firstName", fname);
|
|
||||||
else
|
|
||||||
jo.put("firstName", "");
|
|
||||||
|
|
||||||
String lname = ind.getDataValue( "http://xmlns.com/foaf/0.1/lastName");
|
|
||||||
if( lname != null )
|
|
||||||
jo.put("lastName", lname);
|
|
||||||
else
|
|
||||||
jo.put("lastName", "");
|
|
||||||
|
|
||||||
jInds.put(jo);
|
jInds.put(jo);
|
||||||
}
|
}
|
||||||
|
@ -202,6 +201,20 @@ public class JSONServlet extends VitroHttpServlet {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
|
||||||
|
List<DataPropertyStatement> stmts = wdf.getDataPropertyStatementDao()
|
||||||
|
.getDataPropertyStatementsForIndividualByProperty(ind, dp);
|
||||||
|
if( stmts == null || stmts.isEmpty() )
|
||||||
|
return "";
|
||||||
|
else{
|
||||||
|
if( stmts.get(0) != null )
|
||||||
|
return stmts.get(0).getData();
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an option list for a given EditConfiguration and Field.
|
* Gets an option list for a given EditConfiguration and Field.
|
||||||
* Requires following HTTP query parameters:
|
* Requires following HTTP query parameters:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue