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