use of com.serotonin.m2m2.web.dwr.emport.ImportTask in project ma-core-public by infiniteautomation.
the class MangoTestBase method loadConfiguration.
protected void loadConfiguration(File jsonFile) throws JsonException, IOException, URISyntaxException {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(jsonFile), Common.UTF8_CS));
JsonReader jr = new JsonReader(reader);
JsonObject jo = jr.read(JsonObject.class);
ImportTask task = new ImportTask(jo, Common.getTranslations(), null, false);
task.run(Common.timer.currentTimeMillis());
if (task.getResponse().getHasMessages()) {
for (ProcessMessage message : task.getResponse().getMessages()) {
switch(message.getLevel()) {
case error:
case warning:
fail(message.toString(Common.getTranslations()));
case info:
LOG.info(message.toString(Common.getTranslations()));
}
}
}
}
use of com.serotonin.m2m2.web.dwr.emport.ImportTask in project ma-core-public by infiniteautomation.
the class EmportDwr method importData.
@DwrPermission(admin = true)
public ProcessResult importData(String data) {
ProcessResult response = new ProcessResult();
Translations translations = getTranslations();
User user = Common.getHttpUser();
JsonTypeReader reader = new JsonTypeReader(data);
try {
JsonValue value = reader.read();
if (value instanceof JsonObject) {
JsonObject root = value.toJsonObject();
ImportTask importTask = new ImportTask(root, translations, user, true);
user.setImportTask(importTask);
response.addData("importStarted", true);
} else {
response.addGenericMessage("emport.invalidImportData");
}
} catch (ClassCastException e) {
response.addGenericMessage("emport.parseError", e.getMessage());
} catch (TranslatableJsonException e) {
response.addMessage(e.getMsg());
} catch (IOException e) {
response.addGenericMessage("emport.parseError", e.getMessage());
} catch (JsonException e) {
response.addGenericMessage("emport.parseError", e.getMessage());
}
return response;
}
use of com.serotonin.m2m2.web.dwr.emport.ImportTask in project ma-core-public by infiniteautomation.
the class EmportDwr method importUpdate.
@DwrPermission(admin = true)
public ProcessResult importUpdate() {
ProcessResult response;
User user = Common.getUser();
ImportTask importTask = user.getImportTask();
if (importTask != null) {
response = importTask.getResponse();
if (importTask.isCancelled()) {
response.addData("cancelled", true);
user.setImportTask(null);
} else if (importTask.isCompleted()) {
response.addData("complete", true);
user.setImportTask(null);
}
} else {
response = new ProcessResult();
response.addData("noImport", true);
}
return response;
}
Aggregations