Remove all references to org.json in gdata extension
This commit is contained in:
parent
916ede440b
commit
1df2d15e6d
@ -11,13 +11,11 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
import com.google.api.services.drive.model.File;
|
import com.google.api.services.drive.model.File;
|
||||||
@ -100,7 +98,7 @@ public class GDataImportingController implements ImportingController {
|
|||||||
writer.writeEndArray();
|
writer.writeEndArray();
|
||||||
writer.writeEndObject();
|
writer.writeEndObject();
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (IOException e) {
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
} finally {
|
} finally {
|
||||||
writer.flush();
|
writer.flush();
|
||||||
@ -111,7 +109,7 @@ public class GDataImportingController implements ImportingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void listSpreadsheets(Drive drive, JsonGenerator writer)
|
private void listSpreadsheets(Drive drive, JsonGenerator writer)
|
||||||
throws IOException, JSONException {
|
throws IOException {
|
||||||
com.google.api.services.drive.Drive.Files.List files = drive.files().list();
|
com.google.api.services.drive.Drive.Files.List files = drive.files().list();
|
||||||
files.setQ("mimeType = 'application/vnd.google-apps.spreadsheet'");
|
files.setQ("mimeType = 'application/vnd.google-apps.spreadsheet'");
|
||||||
files.setFields("nextPageToken, files(id, name, webViewLink, owners, modifiedTime)");
|
files.setFields("nextPageToken, files(id, name, webViewLink, owners, modifiedTime)");
|
||||||
@ -142,7 +140,7 @@ public class GDataImportingController implements ImportingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void listFusionTables(Fusiontables service, JsonGenerator writer)
|
private void listFusionTables(Fusiontables service, JsonGenerator writer)
|
||||||
throws IOException, JSONException {
|
throws IOException {
|
||||||
|
|
||||||
Fusiontables.Table.List listTables = service.table().list();
|
Fusiontables.Table.List listTables = service.table().list();
|
||||||
TableList tablelist = listTables.execute();
|
TableList tablelist = listTables.execute();
|
||||||
@ -172,8 +170,8 @@ public class GDataImportingController implements ImportingController {
|
|||||||
String token = TokenCookie.getToken(request);
|
String token = TokenCookie.getToken(request);
|
||||||
String type = parameters.getProperty("docType");
|
String type = parameters.getProperty("docType");
|
||||||
String urlString = parameters.getProperty("docUrl");
|
String urlString = parameters.getProperty("docUrl");
|
||||||
JSONObject result = new JSONObject();
|
ObjectNode result = ParsingUtilities.mapper.createObjectNode();
|
||||||
JSONObject options = new JSONObject();
|
ObjectNode options = ParsingUtilities.mapper.createObjectNode();
|
||||||
|
|
||||||
JSONUtilities.safePut(result, "status", "ok");
|
JSONUtilities.safePut(result, "status", "ok");
|
||||||
JSONUtilities.safePut(result, "options", options);
|
JSONUtilities.safePut(result, "options", options);
|
||||||
@ -182,7 +180,7 @@ public class GDataImportingController implements ImportingController {
|
|||||||
JSONUtilities.safePut(options, "storeBlankCellsAsNulls", true);
|
JSONUtilities.safePut(options, "storeBlankCellsAsNulls", true);
|
||||||
|
|
||||||
if ("spreadsheet".equals(type)) {
|
if ("spreadsheet".equals(type)) {
|
||||||
JSONArray worksheets = new JSONArray();
|
ArrayNode worksheets = ParsingUtilities.mapper.createArrayNode();
|
||||||
// extract spreadSheetId from URL
|
// extract spreadSheetId from URL
|
||||||
String spreadSheetId = GoogleAPIExtension.extractSpreadSheetId(urlString);
|
String spreadSheetId = GoogleAPIExtension.extractSpreadSheetId(urlString);
|
||||||
|
|
||||||
@ -193,7 +191,7 @@ public class GDataImportingController implements ImportingController {
|
|||||||
List<Sheet> worksheetEntries =
|
List<Sheet> worksheetEntries =
|
||||||
getWorksheetEntriesForDoc(token, spreadSheetId);
|
getWorksheetEntriesForDoc(token, spreadSheetId);
|
||||||
for (Sheet sheet : worksheetEntries) {
|
for (Sheet sheet : worksheetEntries) {
|
||||||
JSONObject worksheetO = new JSONObject();
|
ObjectNode worksheetO = ParsingUtilities.mapper.createObjectNode();
|
||||||
JSONUtilities.safePut(worksheetO, "name", sheet.getProperties().getTitle());
|
JSONUtilities.safePut(worksheetO, "name", sheet.getProperties().getTitle());
|
||||||
JSONUtilities.safePut(worksheetO, "rows", sheet.getProperties().getGridProperties().getRowCount());
|
JSONUtilities.safePut(worksheetO, "rows", sheet.getProperties().getGridProperties().getRowCount());
|
||||||
JSONUtilities.safePut(worksheetO, "link",
|
JSONUtilities.safePut(worksheetO, "link",
|
||||||
@ -235,55 +233,50 @@ public class GDataImportingController implements ImportingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
job.updating = true;
|
job.updating = true;
|
||||||
|
ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(
|
||||||
|
request.getParameter("options"));
|
||||||
|
|
||||||
|
List<Exception> exceptions = new LinkedList<Exception>();
|
||||||
|
|
||||||
|
job.prepareNewProject();
|
||||||
|
|
||||||
|
GDataImporter.parse(
|
||||||
|
token,
|
||||||
|
job.project,
|
||||||
|
job.metadata,
|
||||||
|
job,
|
||||||
|
100,
|
||||||
|
optionObj,
|
||||||
|
exceptions
|
||||||
|
);
|
||||||
|
|
||||||
|
Writer w = response.getWriter();
|
||||||
|
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
||||||
try {
|
try {
|
||||||
ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(
|
writer.writeStartObject();
|
||||||
request.getParameter("options"));
|
if (exceptions.size() == 0) {
|
||||||
|
job.project.update(); // update all internal models, indexes, caches, etc.
|
||||||
|
|
||||||
List<Exception> exceptions = new LinkedList<Exception>();
|
writer.writeStringField("status", "ok");
|
||||||
|
} else {
|
||||||
|
writer.writeStringField("status", "error");
|
||||||
|
|
||||||
job.prepareNewProject();
|
writer.writeArrayFieldStart("errors");
|
||||||
|
DefaultImportingController.writeErrors(writer, exceptions);
|
||||||
GDataImporter.parse(
|
writer.writeEndArray();
|
||||||
token,
|
|
||||||
job.project,
|
|
||||||
job.metadata,
|
|
||||||
job,
|
|
||||||
100,
|
|
||||||
optionObj,
|
|
||||||
exceptions
|
|
||||||
);
|
|
||||||
|
|
||||||
Writer w = response.getWriter();
|
|
||||||
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
|
||||||
try {
|
|
||||||
writer.writeStartObject();
|
|
||||||
if (exceptions.size() == 0) {
|
|
||||||
job.project.update(); // update all internal models, indexes, caches, etc.
|
|
||||||
|
|
||||||
writer.writeStringField("status", "ok");
|
|
||||||
} else {
|
|
||||||
writer.writeStringField("status", "error");
|
|
||||||
|
|
||||||
writer.writeArrayFieldStart("errors");
|
|
||||||
DefaultImportingController.writeErrors(writer, exceptions);
|
|
||||||
writer.writeEndArray();
|
|
||||||
}
|
|
||||||
writer.writeEndObject();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new ServletException(e);
|
|
||||||
} finally {
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
w.flush();
|
|
||||||
w.close();
|
|
||||||
}
|
}
|
||||||
|
writer.writeEndObject();
|
||||||
} catch (JSONException e) {
|
} catch (IOException e) {
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
} finally {
|
} finally {
|
||||||
job.touch();
|
writer.flush();
|
||||||
job.updating = false;
|
writer.close();
|
||||||
|
w.flush();
|
||||||
|
w.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
job.touch();
|
||||||
|
job.updating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doCreateProject(HttpServletRequest request, HttpServletResponse response, Properties parameters)
|
private void doCreateProject(HttpServletRequest request, HttpServletResponse response, Properties parameters)
|
||||||
@ -299,57 +292,53 @@ public class GDataImportingController implements ImportingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
job.updating = true;
|
job.updating = true;
|
||||||
try {
|
final ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(
|
||||||
final ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(
|
request.getParameter("options"));
|
||||||
request.getParameter("options"));
|
|
||||||
|
|
||||||
final List<Exception> exceptions = new LinkedList<Exception>();
|
final List<Exception> exceptions = new LinkedList<Exception>();
|
||||||
|
|
||||||
job.setState("creating-project");
|
job.setState("creating-project");
|
||||||
|
|
||||||
final Project project = new Project();
|
final Project project = new Project();
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ProjectMetadata pm = new ProjectMetadata();
|
ProjectMetadata pm = new ProjectMetadata();
|
||||||
pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
|
pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
|
||||||
pm.setEncoding(JSONUtilities.getString(optionObj, "encoding", "UTF-8"));
|
pm.setEncoding(JSONUtilities.getString(optionObj, "encoding", "UTF-8"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GDataImporter.parse(
|
GDataImporter.parse(
|
||||||
token,
|
token,
|
||||||
project,
|
project,
|
||||||
pm,
|
pm,
|
||||||
job,
|
job,
|
||||||
-1,
|
-1,
|
||||||
optionObj,
|
optionObj,
|
||||||
exceptions
|
exceptions
|
||||||
);
|
);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(ExceptionUtils.getStackTrace(e));
|
logger.error(ExceptionUtils.getStackTrace(e));
|
||||||
}
|
|
||||||
|
|
||||||
if (!job.canceled) {
|
|
||||||
if (exceptions.size() > 0) {
|
|
||||||
job.setError(exceptions);
|
|
||||||
} else {
|
|
||||||
project.update(); // update all internal models, indexes, caches, etc.
|
|
||||||
|
|
||||||
ProjectManager.singleton.registerProject(project, pm);
|
|
||||||
|
|
||||||
job.setState("created-project");
|
|
||||||
job.setProjectID(project.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
job.touch();
|
|
||||||
job.updating = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.start();
|
|
||||||
|
|
||||||
HttpUtilities.respond(response, "ok", "done");
|
if (!job.canceled) {
|
||||||
} catch (JSONException e) {
|
if (exceptions.size() > 0) {
|
||||||
throw new ServletException(e);
|
job.setError(exceptions);
|
||||||
}
|
} else {
|
||||||
|
project.update(); // update all internal models, indexes, caches, etc.
|
||||||
|
|
||||||
|
ProjectManager.singleton.registerProject(project, pm);
|
||||||
|
|
||||||
|
job.setState("created-project");
|
||||||
|
job.setProjectID(project.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
job.touch();
|
||||||
|
job.updating = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
|
||||||
|
HttpUtilities.respond(response, "ok", "done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user