Search in sources :

Example 16 with JsonObject

use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.

the class JsonEmportScriptUtility method doImportGetStatus.

public List<ProcessMessage> doImportGetStatus(String json) throws Exception {
    if (admin) {
        JsonTypeReader reader = new JsonTypeReader(json);
        JsonValue value = reader.read();
        JsonObject jo = value.toJsonObject();
        if (importExclusions != null)
            doExclusions(jo);
        ScriptImportTask sit = new ScriptImportTask(jo);
        sit.run(Common.timer.currentTimeMillis());
        return sit.getMessages();
    }
    return null;
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Example 17 with JsonObject

use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.

the class JsonEmportScriptUtility method doImport.

public void doImport(String json) throws Exception {
    if (admin) {
        JsonTypeReader reader = new JsonTypeReader(json);
        JsonValue value = reader.read();
        JsonObject jo = value.toJsonObject();
        if (importExclusions != null)
            doExclusions(jo);
        ScriptImportTask sit = new ScriptImportTask(jo);
        sit.run(Common.timer.currentTimeMillis());
    }
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) JsonTypeReader(com.serotonin.json.type.JsonTypeReader)

Example 18 with JsonObject

use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.

the class VirtualSerialPortConfigResolver method resolve.

@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
    if (jsonValue == null)
        return null;
    JsonObject json = jsonValue.toJsonObject();
    String text = json.getString("type");
    if (text == null)
        throw new TranslatableJsonException("emport.error.virtual.comm.missing", "type", VirtualSerialPortConfig.PORT_TYPE_CODES);
    return findClass(text);
}
Also used : JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 19 with JsonObject

use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.

the class EventTypeResolver method resolve.

@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
    if (jsonValue == null)
        throw new TranslatableJsonException("emport.error.eventType.null");
    JsonObject json = jsonValue.toJsonObject();
    String text = json.getString("sourceType");
    if (text == null)
        throw new TranslatableJsonException("emport.error.eventType.missing", "sourceType", EventType.SOURCE_NAMES.getCodeList());
    if (!EventType.SOURCE_NAMES.hasCode(text))
        throw new TranslatableJsonException("emport.error.eventType.invalid", "sourceType", text, EventType.SOURCE_NAMES.getCodeList());
    if (text.equalsIgnoreCase(EventTypeNames.DATA_POINT))
        return DataPointEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.DATA_SOURCE))
        return DataSourceEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.SYSTEM))
        return SystemEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.PUBLISHER))
        return PublisherEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.AUDIT))
        return AuditEventType.class;
    EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(text);
    if (def != null)
        return def.getEventTypeClass();
    return null;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition)

Example 20 with JsonObject

use of com.serotonin.json.type.JsonObject in project ma-modules-public by infiniteautomation.

the class GraphicalViewEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject viewJson = jsonValue.toJsonObject();
    String xid = viewJson.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = graphicalViewDao.generateUniqueXid();
    ensureDao();
    GraphicalView view = graphicalViewDao.getViewByXid(xid);
    if (view == null) {
        view = new GraphicalView();
        view.setXid(xid);
    }
    try {
        importContext.getReader().readInto(view, viewJson);
        // Now validate it. Use a new response object so we can distinguish errors in this view from other
        // errors.
        ProcessResult viewResponse = new ProcessResult();
        view.validate(viewResponse);
        if (viewResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(viewResponse, "emport.view.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = view.isNew();
            graphicalViewDao.saveView(view);
            importContext.addSuccessMessage(isnew, "emport.view.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.view.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.view.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

JsonObject (com.serotonin.json.type.JsonObject)44 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)24 JsonValue (com.serotonin.json.type.JsonValue)20 JsonArray (com.serotonin.json.type.JsonArray)17 JsonException (com.serotonin.json.JsonException)15 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)11 JsonString (com.serotonin.json.type.JsonString)7 IOException (java.io.IOException)7 IntStringPair (com.serotonin.db.pair.IntStringPair)6 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)6 JsonReader (com.serotonin.json.JsonReader)5 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)5 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)4 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 User (com.serotonin.m2m2.vo.User)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)2 GenericRestException (com.infiniteautomation.mango.rest.v2.exception.GenericRestException)2