use of com.google.refine.extension.database.model.DatabaseQueryInfo in project OpenRefine by OpenRefine.
the class DatabaseImportController method doParsePreview.
/**
* doParsePreview
* @param request
* @param response
* @param parameters
* @throws ServletException
* @throws IOException
* @throws DatabaseServiceException
*/
private void doParsePreview(HttpServletRequest request, HttpServletResponse response, Properties parameters) throws ServletException, IOException, DatabaseServiceException {
if (logger.isDebugEnabled()) {
logger.debug("JobID::{}", parameters.getProperty("jobID"));
}
long jobID = Long.parseLong(parameters.getProperty("jobID"));
ImportingJob job = ImportingManager.getJob(jobID);
if (job == null) {
HttpUtilities.respond(response, "error", "No such import job");
return;
}
DatabaseQueryInfo databaseQueryInfo = getQueryInfo(request);
if (databaseQueryInfo == null) {
HttpUtilities.respond(response, "error", "Invalid or missing Query Info");
}
job.updating = true;
try {
ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(request.getParameter("options"));
List<Exception> exceptions = new LinkedList<Exception>();
job.prepareNewProject();
parsePreview(databaseQueryInfo, job.project, job.metadata, job, DEFAULT_PREVIEW_LIMIT, optionObj, exceptions);
Writer w = response.getWriter();
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
try {
writer.writeStartObject();
if (exceptions.size() == 0) {
// update all internal models, indexes, caches, etc.
job.project.update();
writer.writeStringField("status", "ok");
} else {
writer.writeStringField("status", "error");
writer.writeStringField("message", getExceptionString(exceptions));
}
writer.writeEndObject();
} catch (IOException e) {
throw new ServletException(e);
} finally {
writer.flush();
writer.close();
w.flush();
w.close();
}
} catch (IOException e) {
throw new ServletException(e);
} finally {
job.touch();
job.updating = false;
}
}
use of com.google.refine.extension.database.model.DatabaseQueryInfo in project OpenRefine by OpenRefine.
the class DatabaseImportController method doCreateProject.
/**
* doCreateProject
* @param request
* @param response
* @param parameters
*/
private void doCreateProject(HttpServletRequest request, HttpServletResponse response, Properties parameters) throws ServletException, IOException {
if (logger.isDebugEnabled()) {
logger.debug("DatabaseImportController::doCreateProject:::{}", parameters.getProperty("jobID"));
}
long jobID = Long.parseLong(parameters.getProperty("jobID"));
final ImportingJob job = ImportingManager.getJob(jobID);
if (job == null) {
HttpUtilities.respond(response, "error", "No such import job");
return;
}
final DatabaseQueryInfo databaseQueryInfo = getQueryInfo(request);
if (databaseQueryInfo == null) {
HttpUtilities.respond(response, "error", "Invalid or missing Query Info");
}
job.updating = true;
try {
final ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(request.getParameter("options"));
final List<Exception> exceptions = new LinkedList<Exception>();
job.setState("creating-project");
final Project project = new Project();
new Thread() {
@Override
public void run() {
ProjectMetadata pm = new ProjectMetadata();
pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
pm.setEncoding(JSONUtilities.getString(optionObj, "encoding", "UTF-8"));
try {
parseCreate(databaseQueryInfo, project, pm, job, -1, optionObj, exceptions);
} catch (DatabaseServiceException e) {
logger.error("DatabaseImportController::doCreateProject:::run{}", e);
// throw new RuntimeException("DatabaseServiceException::", e);
}
if (!job.canceled) {
if (exceptions.size() > 0) {
job.setError(exceptions);
} else {
// update all internal models, indexes, caches, etc.
project.update();
ProjectManager.singleton.registerProject(project, pm);
job.setState("created-project");
job.setProjectID(project.id);
// logger.info("DatabaseImportController::doCreateProject:::run::projectID :{}", project.id);
}
job.touch();
job.updating = false;
}
}
}.start();
HttpUtilities.respond(response, "ok", "done");
} catch (IOException e) {
throw new ServletException(e);
}
}
Aggregations