use of org.molgenis.emx2.tasks.Task in project molgenis-emx2 by molgenis.
the class ImportSchemaTask method rollback.
private void rollback(Task task) {
for (Step step : task.getSteps()) {
if (step.getStatus().equals(COMPLETED)) {
step.setStatus(SKIPPED);
step.setDescription("Rolled back: " + step.getDescription());
}
if (step instanceof Task) {
this.rollback((Task) step);
}
}
}
use of org.molgenis.emx2.tasks.Task in project molgenis-emx2 by molgenis.
the class ImportDataTask method run.
@Override
public void run() {
this.start();
// create a task for each table
boolean skipped = true;
// create task for the import, including subtasks for each sheet
for (Table table : schema.getTablesSorted()) {
if (tableStore.containsTable(table.getName())) {
ImportTableTask importTableTask = new ImportTableTask(tableStore, table, isStrict());
this.addSubTask(importTableTask);
importTableTask.run();
skipped = false;
}
}
// check what files we skipped
Collection<String> tableNames = schema.getTableNames();
try {
for (String sheet : tableStore.tableNames()) {
if (!sheet.startsWith("_files/") && !"molgenis".equals(sheet) && !"molgenis_settings".equals(sheet) && !"molgenis_members".equals(sheet) && !tableNames.contains(sheet)) {
this.addSubTask("Sheet with name '" + sheet + "' was skipped: no table with that name found").setSkipped();
}
}
} catch (UnsupportedOperationException e) {
// ignore, not important
}
// execute the import tasks
if (skipped) {
this.addSubTask("Import data skipped: No data sheet included").setSkipped();
}
this.complete();
}
use of org.molgenis.emx2.tasks.Task in project molgenis-emx2 by molgenis.
the class WebApiSmokeTests method testExcelApi.
@Test
public void testExcelApi() throws IOException, InterruptedException {
// download json schema
String schemaCSV = given().sessionId(SESSION_ID).accept(ACCEPT_CSV).when().get("/pet store/api/csv").asString();
// create a new schema for excel
db.dropCreateSchema("pet store excel");
// download excel contents from schema
byte[] excelContents = given().sessionId(SESSION_ID).accept(ACCEPT_EXCEL).when().get("/pet store/api/excel").asByteArray();
File excelFile = createTempFile(excelContents, ".xlsx");
// upload excel into new schema
String message = given().sessionId(SESSION_ID).multiPart(excelFile).when().post("/pet store excel/api/excel?async=true").asString();
Map<String, String> val = new ObjectMapper().readValue(message, Map.class);
String url = val.get("url");
String id = val.get("id");
// poll task until complete
Response poll = given().sessionId(SESSION_ID).when().get(url);
int count = 0;
// (previously we checked on 'complete' but then it also fired if subtask was complete)
while (poll.body().asString().contains("UNKNOWN") || poll.body().asString().contains("RUNNING")) {
if (count++ > 100) {
throw new MolgenisException("failed: polling took too long");
}
poll = given().sessionId(SESSION_ID).when().get(url);
Thread.sleep(500);
}
// check if id in tasks list
assertTrue(given().sessionId(SESSION_ID).multiPart(excelFile).when().get("/pet store/api/tasks").asString().contains(id));
// check if schema equal using json representation
String schemaCSV2 = given().sessionId(SESSION_ID).accept(ACCEPT_CSV).when().get("/pet store excel/api/csv").asString();
assertTrue(schemaCSV2.contains("Pet"));
// delete a new schema for excel
db.dropSchema("pet store excel");
}
use of org.molgenis.emx2.tasks.Task in project molgenis-emx2 by molgenis.
the class DummyTask method run.
@Override
public void run() {
start();
System.out.println("started");
for (Task t : this) {
t.start();
for (int item = 1; item <= noItems; item++) {
try {
Thread.sleep(5);
} catch (InterruptedException e) {
throw new MolgenisException("Error", e);
}
t.setProgress(item);
}
t.complete();
}
complete();
}
use of org.molgenis.emx2.tasks.Task in project molgenis-emx2 by molgenis.
the class TestGraphqSchemaFields method testTasksApi.
@Test
public void testTasksApi() throws IOException {
// fake something into taskservice
Task task = new Task("test");
task.addSubTask(new Task("subtest"));
taskService.submit(task);
// list all tasks
assertTrue(execute("{_tasks{id,description,status}}").at("/_tasks/0/description").textValue().startsWith("test"));
// load single task
assertTrue(execute("{_tasks(id:\"" + task.getId() + "\"){id,description,status,subTasks{id,description,status,subTasks{id,description,status}}}}").at("/_tasks/0/description").textValue().startsWith("test"));
}
Aggregations