Search in sources :

Example 1 with ImportTask

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()));
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ImportTask(com.serotonin.m2m2.web.dwr.emport.ImportTask) BufferedReader(java.io.BufferedReader) JsonReader(com.serotonin.json.JsonReader) JsonObject(com.serotonin.json.type.JsonObject) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) FileInputStream(java.io.FileInputStream)

Example 2 with ImportTask

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;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) User(com.serotonin.m2m2.vo.User) ImportTask(com.serotonin.m2m2.web.dwr.emport.ImportTask) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) IOException(java.io.IOException) Translations(com.serotonin.m2m2.i18n.Translations) JsonTypeReader(com.serotonin.json.type.JsonTypeReader) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with ImportTask

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;
}
Also used : User(com.serotonin.m2m2.vo.User) ImportTask(com.serotonin.m2m2.web.dwr.emport.ImportTask) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

ImportTask (com.serotonin.m2m2.web.dwr.emport.ImportTask)3 JsonObject (com.serotonin.json.type.JsonObject)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 User (com.serotonin.m2m2.vo.User)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 JsonException (com.serotonin.json.JsonException)1 JsonReader (com.serotonin.json.JsonReader)1 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)1 JsonValue (com.serotonin.json.type.JsonValue)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 Translations (com.serotonin.m2m2.i18n.Translations)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1