[VIVO-1320] Convert some org.json usages to Jackson
This commit is contained in:
parent
5175ef9c50
commit
7c1390d745
9 changed files with 65 additions and 56 deletions
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.beans;
|
package edu.cornell.mannlib.vitro.webapp.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: bdc34
|
* User: bdc34
|
||||||
* Date: Oct 18, 2007
|
* Date: Oct 18, 2007
|
||||||
|
@ -97,7 +96,7 @@ public interface Individual extends ResourceBean, Comparable<Individual> {
|
||||||
|
|
||||||
void sortForDisplay();
|
void sortForDisplay();
|
||||||
|
|
||||||
JSONObject toJSON() throws JSONException;
|
JsonNode toJSON();
|
||||||
|
|
||||||
Float getSearchBoost();
|
Float getSearchBoost();
|
||||||
void setSearchBoost( Float boost );
|
void setSearchBoost( Float boost );
|
||||||
|
|
|
@ -11,9 +11,9 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.json.JSONObject;
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
|
||||||
|
|
||||||
|
@ -313,15 +313,11 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
|
||||||
Collections.sort(getObjectPropertyList(), new ObjectProperty.DisplayComparator());
|
Collections.sort(getObjectPropertyList(), new ObjectProperty.DisplayComparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String [] INCLUDED_IN_JSON = {
|
public JsonNode toJSON() {
|
||||||
"URI",
|
ObjectNode jsonObj = JsonNodeFactory.instance.objectNode();
|
||||||
"name",
|
jsonObj.put("URI", this.URI);
|
||||||
"vClassId"
|
jsonObj.put("name", this.name);
|
||||||
};
|
jsonObj.put("vClassId", this.vClassURI);
|
||||||
|
|
||||||
|
|
||||||
public JSONObject toJSON() throws JSONException {
|
|
||||||
JSONObject jsonObj = new JSONObject(this, INCLUDED_IN_JSON);
|
|
||||||
return jsonObj;
|
return jsonObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ import java.util.List;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
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 org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||||
|
@ -56,7 +56,7 @@ class ExternalAuthChecker extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
if (someoneElseIsUsingThisExternalAuthId()) {
|
if (someoneElseIsUsingThisExternalAuthId()) {
|
||||||
return respondExternalAuthIdAlreadyUsed();
|
return respondExternalAuthIdAlreadyUsed();
|
||||||
}
|
}
|
||||||
|
@ -93,8 +93,8 @@ class ExternalAuthChecker extends AbstractAjaxResponder {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String respondExternalAuthIdAlreadyUsed() throws JSONException {
|
private String respondExternalAuthIdAlreadyUsed() {
|
||||||
JSONObject jsonObject = new JSONObject();
|
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
|
||||||
jsonObject.put(RESPONSE_ID_IN_USE, true);
|
jsonObject.put(RESPONSE_ID_IN_USE, true);
|
||||||
return jsonObject.toString();
|
return jsonObject.toString();
|
||||||
}
|
}
|
||||||
|
@ -110,12 +110,12 @@ class ExternalAuthChecker extends AbstractAjaxResponder {
|
||||||
this.matchingProfile = inds.get(0);
|
this.matchingProfile = inds.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String respondWithMatchingProfile() throws JSONException {
|
private String respondWithMatchingProfile() {
|
||||||
String uri = matchingProfile.getURI();
|
String uri = matchingProfile.getURI();
|
||||||
String url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
String url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
||||||
String label = matchingProfile.getRdfsLabel();
|
String label = matchingProfile.getRdfsLabel();
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
|
||||||
jsonObject.put(RESPONSE_MATCHES_PROFILE, true);
|
jsonObject.put(RESPONSE_MATCHES_PROFILE, true);
|
||||||
jsonObject.put(RESPONSE_PROFILE_URI, uri);
|
jsonObject.put(RESPONSE_PROFILE_URI, uri);
|
||||||
jsonObject.put(RESPONSE_PROFILE_URL, url);
|
jsonObject.put(RESPONSE_PROFILE_URL, url);
|
||||||
|
|
|
@ -11,10 +11,9 @@ import java.util.Map;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
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 org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import org.apache.jena.ontology.OntModel;
|
import org.apache.jena.ontology.OntModel;
|
||||||
import org.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
|
@ -68,7 +67,7 @@ public class BasicProxiesGetter extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
log.debug("search term is '" + term + "'");
|
log.debug("search term is '" + term + "'");
|
||||||
if (term.isEmpty()) {
|
if (term.isEmpty()) {
|
||||||
return EMPTY_RESPONSE;
|
return EMPTY_RESPONSE;
|
||||||
|
@ -76,7 +75,7 @@ public class BasicProxiesGetter extends AbstractAjaxResponder {
|
||||||
String cleanTerm = SparqlQueryUtils.escapeForRegex(term);
|
String cleanTerm = SparqlQueryUtils.escapeForRegex(term);
|
||||||
String queryStr = QUERY_BASIC_PROXIES.replace("%term%", cleanTerm);
|
String queryStr = QUERY_BASIC_PROXIES.replace("%term%", cleanTerm);
|
||||||
|
|
||||||
JSONArray jsonArray = SparqlQueryRunner
|
ArrayNode jsonArray = SparqlQueryRunner
|
||||||
.createSelectQueryContext(userAccountsModel, queryStr)
|
.createSelectQueryContext(userAccountsModel, queryStr)
|
||||||
.execute()
|
.execute()
|
||||||
.parse(new BasicProxyInfoParser(placeholderImageUrl));
|
.parse(new BasicProxyInfoParser(placeholderImageUrl));
|
||||||
|
|
|
@ -9,10 +9,11 @@ import java.util.Map;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
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 org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -42,7 +43,7 @@ public class MoreProfileInfo extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
log.debug("profile URI is '" + profileUri + "'");
|
log.debug("profile URI is '" + profileUri + "'");
|
||||||
if (profileUri.isEmpty()) {
|
if (profileUri.isEmpty()) {
|
||||||
return EMPTY_RESPONSE;
|
return EMPTY_RESPONSE;
|
||||||
|
@ -58,8 +59,12 @@ public class MoreProfileInfo extends AbstractAjaxResponder {
|
||||||
map.put("imageUrl", getFullImageUrl(profileInd));
|
map.put("imageUrl", getFullImageUrl(profileInd));
|
||||||
map.put("classLabel", getMostSpecificTypeLabel(profileInd.getURI()));
|
map.put("classLabel", getMostSpecificTypeLabel(profileInd.getURI()));
|
||||||
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
|
||||||
jsonArray.put(map);
|
ObjectNode jsonObj = JsonNodeFactory.instance.objectNode();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
jsonObj.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
jsonArray.add(jsonObj);
|
||||||
String response = jsonArray.toString();
|
String response = jsonArray.toString();
|
||||||
|
|
||||||
log.debug("response is '" + response + "'");
|
log.debug("response is '" + response + "'");
|
||||||
|
|
|
@ -10,10 +10,11 @@ import java.util.Map;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
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 org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||||
|
@ -47,7 +48,7 @@ public class MoreProxyInfo extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
log.debug("proxy URI is '" + proxyUri + "'");
|
log.debug("proxy URI is '" + proxyUri + "'");
|
||||||
if (proxyUri.isEmpty()) {
|
if (proxyUri.isEmpty()) {
|
||||||
return EMPTY_RESPONSE;
|
return EMPTY_RESPONSE;
|
||||||
|
@ -74,8 +75,12 @@ public class MoreProxyInfo extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
map.put("classLabel", getMostSpecificTypeLabel(profileInd.getURI()));
|
map.put("classLabel", getMostSpecificTypeLabel(profileInd.getURI()));
|
||||||
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
|
||||||
jsonArray.put(map);
|
ObjectNode jsonObj = JsonNodeFactory.instance.objectNode();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
jsonObj.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
jsonArray.add(jsonObj);
|
||||||
String response = jsonArray.toString();
|
String response = jsonArray.toString();
|
||||||
|
|
||||||
log.debug("response is '" + response + "'");
|
log.debug("response is '" + response + "'");
|
||||||
|
|
|
@ -13,10 +13,11 @@ import java.util.Map;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
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 org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import org.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.query.ResultSet;
|
import org.apache.jena.query.ResultSet;
|
||||||
|
@ -59,8 +60,7 @@ public abstract class AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String prepareResponse() throws IOException,
|
protected abstract String prepareResponse() throws IOException;
|
||||||
JSONException;
|
|
||||||
|
|
||||||
protected String getStringParameter(String key, String defaultValue) {
|
protected String getStringParameter(String key, String defaultValue) {
|
||||||
String value = vreq.getParameter(key);
|
String value = vreq.getParameter(key);
|
||||||
|
@ -81,9 +81,13 @@ public abstract class AbstractAjaxResponder {
|
||||||
* objects with fields.
|
* objects with fields.
|
||||||
*/
|
*/
|
||||||
protected String assembleJsonResponse(List<Map<String, String>> maps) {
|
protected String assembleJsonResponse(List<Map<String, String>> maps) {
|
||||||
JSONArray jsonArray = new JSONArray();
|
ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
|
||||||
for (Map<String, String> map : maps) {
|
for (Map<String, String> map : maps) {
|
||||||
jsonArray.put(map);
|
ObjectNode jsonObj = JsonNodeFactory.instance.objectNode();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
jsonObj.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
jsonArray.add(jsonObj);
|
||||||
}
|
}
|
||||||
return jsonArray.toString();
|
return jsonArray.toString();
|
||||||
}
|
}
|
||||||
|
@ -93,19 +97,23 @@ public abstract class AbstractAjaxResponder {
|
||||||
* implement "parseSolutionRow()"
|
* implement "parseSolutionRow()"
|
||||||
*/
|
*/
|
||||||
protected abstract static class JsonArrayParser extends
|
protected abstract static class JsonArrayParser extends
|
||||||
ResultSetParser<JSONArray> {
|
ResultSetParser<ArrayNode> {
|
||||||
@Override
|
@Override
|
||||||
protected JSONArray defaultValue() {
|
protected ArrayNode defaultValue() {
|
||||||
return new JSONArray();
|
return JsonNodeFactory.instance.arrayNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONArray parseResults(String queryStr, ResultSet results) {
|
protected ArrayNode parseResults(String queryStr, ResultSet results) {
|
||||||
JSONArray jsonArray = new JSONArray();
|
ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
Map<String, String> map = parseSolutionRow(results.next());
|
Map<String, String> map = parseSolutionRow(results.next());
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
jsonArray.put(map);
|
ObjectNode jsonObj = JsonNodeFactory.instance.objectNode();
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
|
jsonObj.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
jsonArray.add(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
|
|
|
@ -13,12 +13,11 @@ import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import net.sf.jga.algorithms.Filter;
|
import net.sf.jga.algorithms.Filter;
|
||||||
|
|
||||||
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 org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||||
|
@ -421,7 +420,7 @@ public class IndividualFiltering implements Individual {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject toJSON() throws JSONException {
|
public JsonNode toJSON() {
|
||||||
return _innerIndividual.toJSON();
|
return _innerIndividual.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import org.apache.jena.rdf.model.Resource;
|
import org.apache.jena.rdf.model.Resource;
|
||||||
import org.apache.jena.rdf.model.ResourceFactory;
|
import org.apache.jena.rdf.model.ResourceFactory;
|
||||||
|
|
||||||
|
@ -472,7 +470,7 @@ public class IndividualStub implements Individual {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject toJSON() throws JSONException {
|
public JsonNode toJSON() {
|
||||||
throw new RuntimeException("Individual.toJSON() not implemented.");
|
throw new RuntimeException("Individual.toJSON() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue