Search in sources :

Example 11 with JsonValue

use of com.serotonin.json.type.JsonValue 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 12 with JsonValue

use of com.serotonin.json.type.JsonValue 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 13 with JsonValue

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

the class GraphicalView method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    if (isNew()) {
        String username = jsonObject.getString("user");
        if (StringUtils.isBlank(username))
            throw new TranslatableJsonException("emport.error.missingValue", "user");
        User user = UserDao.instance.getUser(username);
        if (user == null)
            throw new TranslatableJsonException("emport.error.missingUser", username);
        userId = user.getId();
    }
    JsonArray components = jsonObject.getJsonArray("viewComponents");
    if (components != null) {
        viewComponents.clear();
        for (JsonValue jv : components) addViewComponent(reader.read(ViewComponent.class, jv));
    }
    String text = jsonObject.getString("anonymousAccess");
    if (text != null) {
        anonymousAccess = ShareUser.ACCESS_CODES.getId(text);
        if (anonymousAccess == -1)
            throw new TranslatableJsonException("emport.error.invalid", "anonymousAccess", text, ShareUser.ACCESS_CODES.getCodeList());
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) ShareUser(com.serotonin.m2m2.view.ShareUser) User(com.serotonin.m2m2.vo.User) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 14 with JsonValue

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

the class CompoundComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonObject jsonChildren = jsonObject.getJsonObject("children");
    if (jsonChildren != null) {
        for (Map.Entry<String, JsonValue> jsonChild : jsonChildren.entrySet()) {
            CompoundChild child = getChild(jsonChild.getKey());
            if (child == null || !child.getViewComponent().isPointComponent())
                throw new TranslatableJsonException("emport.error.compound.invalidChildId", jsonChild.getKey(), definition().getId(), getPointComponentChildIds());
            jsonReadDataPoint(jsonChild.getValue(), (PointComponent) child.getViewComponent());
        }
    }
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with JsonValue

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

the class MultistateGraphicComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonArray jsonStateList = jsonObject.getJsonArray("stateImageMappings");
    if (jsonStateList != null) {
        stateImageMap.clear();
        for (JsonValue jv : jsonStateList) {
            JsonObject jsonMapping = jv.toJsonObject();
            Integer state = jsonMapping.getInt("state");
            if (state == null)
                throw new TranslatableJsonException("emport.error.missingValue", "state");
            Integer index = jsonMapping.getInt("imageIndex");
            if (index == null)
                throw new TranslatableJsonException("emport.error.missingValue", "index");
            stateImageMap.put(state, index);
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

JsonValue (com.serotonin.json.type.JsonValue)41 JsonArray (com.serotonin.json.type.JsonArray)26 JsonObject (com.serotonin.json.type.JsonObject)21 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)15 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)15 JsonWriter (com.serotonin.json.JsonWriter)10 StringWriter (java.io.StringWriter)10 HttpPost (org.apache.http.client.methods.HttpPost)10 StringEntity (org.apache.http.entity.StringEntity)10 JsonException (com.serotonin.json.JsonException)8 IOException (java.io.IOException)7 JsonString (com.serotonin.json.type.JsonString)5 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)5 User (com.serotonin.m2m2.vo.User)5 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 IntStringPair (com.serotonin.db.pair.IntStringPair)3 JsonReader (com.serotonin.json.JsonReader)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 Type (java.lang.reflect.Type)3