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