[VIVO-1320] Convert some org.json usages to Jackson
This commit is contained in:
parent
7d52bd097f
commit
93244bd488
4 changed files with 27 additions and 59 deletions
|
@ -14,7 +14,6 @@ import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
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.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.query.ResultSet;
|
import org.apache.jena.query.ResultSet;
|
||||||
|
@ -65,7 +64,7 @@ public class GeoFocusMapLocations extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
try {
|
try {
|
||||||
geoLocations = getGeoLocations(vreq);
|
geoLocations = getGeoLocations(vreq);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
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.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.query.ResultSet;
|
import org.apache.jena.query.ResultSet;
|
||||||
|
@ -44,7 +43,7 @@ public class GeoFocusResearcherCount extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
try {
|
try {
|
||||||
geoFocusCount = getGeoFocusCount(vreq);
|
geoFocusCount = getGeoFocusCount(vreq);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
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.apache.jena.query.QuerySolution;
|
import org.apache.jena.query.QuerySolution;
|
||||||
import org.apache.jena.query.ResultSet;
|
import org.apache.jena.query.ResultSet;
|
||||||
|
@ -54,7 +53,7 @@ public class QrCodeDetails extends AbstractAjaxResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String prepareResponse() throws IOException, JSONException {
|
public String prepareResponse() throws IOException {
|
||||||
try {
|
try {
|
||||||
Individual individual = getIndividualFromRequest(vreq);
|
Individual individual = getIndividualFromRequest(vreq);
|
||||||
String firstName = "";
|
String firstName = "";
|
||||||
|
|
|
@ -25,11 +25,12 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
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.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
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 org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -295,7 +296,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
private void doFileUploadPost(HttpServletRequest request, HttpServletResponse response)
|
private void doFileUploadPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
JSONObject json = generateJson(false);
|
ObjectNode json = generateJson(false);
|
||||||
try {
|
try {
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
|
||||||
|
@ -364,41 +365,22 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
//prepare the results which will be sent back to the browser for display
|
//prepare the results which will be sent back to the browser for display
|
||||||
try {
|
|
||||||
json.put("success", success);
|
json.put("success", success);
|
||||||
json.put("fileName", name);
|
json.put("fileName", name);
|
||||||
json.put("errorMessage", errorMessage);
|
json.put("errorMessage", errorMessage);
|
||||||
}
|
|
||||||
catch(JSONException e) {
|
|
||||||
log.error(e, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//if for some reason no file was included with the request, send an error back
|
//if for some reason no file was included with the request, send an error back
|
||||||
try {
|
|
||||||
json.put("success", false);
|
json.put("success", false);
|
||||||
json.put("fileName", "(none)");
|
json.put("fileName", "(none)");
|
||||||
json.put("errorMessage", "No file uploaded");
|
json.put("errorMessage", "No file uploaded");
|
||||||
} catch(JSONException e) {
|
|
||||||
log.error(e, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch(ExceptionVisibleToUser e) {
|
} catch(ExceptionVisibleToUser e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
|
|
||||||
//handle exceptions whose message is for the user
|
//handle exceptions whose message is for the user
|
||||||
try {
|
|
||||||
json.put("success", false);
|
json.put("success", false);
|
||||||
json.put("filename", "(none)");
|
json.put("filename", "(none)");
|
||||||
json.put("errorMessage", e.getMessage());
|
json.put("errorMessage", e.getMessage());
|
||||||
} catch(JSONException f) {
|
|
||||||
log.error(f, f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
json = generateJson(true);
|
json = generateJson(true);
|
||||||
|
@ -416,7 +398,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
*/
|
*/
|
||||||
private void doHarvestPost(HttpServletRequest request, HttpServletResponse response) {
|
private void doHarvestPost(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
|
||||||
JSONObject json;
|
ObjectNode json;
|
||||||
try {
|
try {
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
FileHarvestJob job = getJob(vreq, vreq.getParameter(PARAMETER_JOB));
|
FileHarvestJob job = getJob(vreq, vreq.getParameter(PARAMETER_JOB));
|
||||||
|
@ -454,7 +436,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
*/
|
*/
|
||||||
private void doCheckHarvestStatusPost(HttpServletRequest request, HttpServletResponse response) {
|
private void doCheckHarvestStatusPost(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
|
||||||
JSONObject json;
|
ObjectNode json;
|
||||||
try {
|
try {
|
||||||
String newline = "\n";
|
String newline = "\n";
|
||||||
|
|
||||||
|
@ -482,15 +464,15 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
boolean abnormalTermination = false;
|
boolean abnormalTermination = false;
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
ArrayList<String> newlyAddedUrls = new ArrayList<String>();
|
ArrayNode newlyAddedUrls = JsonNodeFactory.instance.arrayNode();
|
||||||
ArrayList<String> newlyAddedUris = new ArrayList<String>();
|
ArrayNode newlyAddedUris = JsonNodeFactory.instance.arrayNode();
|
||||||
if(finished) {
|
if(finished) {
|
||||||
newlyAddedUris = sessionInfo.newlyAddedUris;
|
if (sessionInfo.newlyAddedUris != null) {
|
||||||
if(newlyAddedUris != null) {
|
for(String uri : sessionInfo.newlyAddedUris) {
|
||||||
for(String uri : newlyAddedUris) {
|
newlyAddedUris.add(uri);
|
||||||
|
|
||||||
newlyAddedUrls.add(UrlBuilder.getIndividualProfileUrl(uri, vreq));
|
newlyAddedUrls.add(UrlBuilder.getIndividualProfileUrl(uri, vreq));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove all entries in "sessionIdTo..." mappings for this session ID
|
//remove all entries in "sessionIdTo..." mappings for this session ID
|
||||||
|
@ -744,28 +726,17 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new JSON object
|
* Create a new JSON object
|
||||||
* @param fatalError whether the fatal error flag should be set on this object
|
* @param fatalError whether the fatal error flag should be set on this object
|
||||||
* @return the new JSON object
|
* @return the new JSON object
|
||||||
*/
|
*/
|
||||||
private JSONObject generateJson(boolean fatalError) {
|
private ObjectNode generateJson(boolean fatalError) {
|
||||||
JSONObject json = null;
|
ObjectNode json = JsonNodeFactory.instance.objectNode();
|
||||||
try {
|
|
||||||
json = new JSONObject();
|
|
||||||
json.put("fatalError", fatalError);
|
json.put("fatalError", fatalError);
|
||||||
} catch(JSONException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information relating to a particular user session, created just before the harvester thread is starting.
|
* Information relating to a particular user session, created just before the harvester thread is starting.
|
||||||
* @author mbarbieri
|
* @author mbarbieri
|
||||||
|
|
Loading…
Add table
Reference in a new issue