Search in sources :

Example 76 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class EventType method getInt.

protected int getInt(JsonObject json, String name, ExportCodes codes) throws JsonException {
    String text = json.getString(name);
    if (text == null)
        throw new TranslatableJsonException("emport.error.eventType.missing", name, codes.getCodeList());
    int i = codes.getId(text);
    if (i == -1)
        throw new TranslatableJsonException("emport.error.eventType.invalid", name, text, codes.getCodeList());
    return i;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 77 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class EventType method getDataPointId.

protected int getDataPointId(JsonObject json, String name) throws JsonException {
    String xid = json.getString(name);
    if (xid == null)
        throw new TranslatableJsonException("emport.error.eventType.missing.reference", name);
    Integer dpid = DataPointDao.instance.getIdByXid(xid);
    if (dpid == null)
        throw new TranslatableJsonException("emport.error.eventType.invalid.reference", name, xid);
    return dpid;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 78 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class ScriptContextVariable method jsonReadVarContext.

/**
 * Read in context,
 * @param json
 * @param context
 * @return if my XID is in the context, return the name it has to map into the VO otherwise return null
 * @throws JsonException
 */
public static String jsonReadVarContext(JsonObject json, List<ScriptContextVariable> context, boolean isContextUpdate) throws JsonException {
    JsonArray jsonContext = json.getJsonArray("context");
    if (jsonContext != null) {
        context.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonContext) {
            JsonObject jo = jv.toJsonObject();
            String xid = jo.getString("dataPointXid");
            if (xid == null)
                throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
            Integer dpid = dataPointDao.getIdByXid(xid);
            if (dpid == null) {
                // This can also happen if the point is in its own context (Bug from legacy systems).
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            }
            // For compatibility with varName and variableName json types
            String var = jo.getString("varName");
            if (var == null) {
                var = jo.getString("variableName");
                if (var == null)
                    throw new TranslatableJsonException("emport.error.context.missing", "varName");
            }
            // Default for legacy systems
            if (jo.containsKey("updateContext"))
                isContextUpdate = jo.getBoolean("updateContext");
            context.add(new ScriptContextVariable(dpid, var, isContextUpdate));
        }
    }
    return json.getString("variableName");
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonString(com.serotonin.json.type.JsonString)

Example 79 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class DeltamationCommon method parsePoint.

public static int parsePoint(JsonObject jsonObject, String name) throws TranslatableJsonException {
    DataPointDao points = DataPointDao.instance;
    String xid = jsonObject.getString(name);
    Integer dpid = points.getIdByXid(xid);
    if (dpid == null) {
        throw new TranslatableJsonException("validate.pointMissing", name, xid);
    }
    return dpid;
}
Also used : DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)79 JsonObject (com.serotonin.json.type.JsonObject)24 JsonException (com.serotonin.json.JsonException)21 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)17 JsonValue (com.serotonin.json.type.JsonValue)15 JsonArray (com.serotonin.json.type.JsonArray)14 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)8 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)8 User (com.serotonin.m2m2.vo.User)7 ArrayList (java.util.ArrayList)5 ExportCodes (com.serotonin.m2m2.util.ExportCodes)4 IntStringPair (com.serotonin.db.pair.IntStringPair)3 TypeDefinition (com.serotonin.json.util.TypeDefinition)3 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)3 IOException (java.io.IOException)3 List (java.util.List)3 JsonBoolean (com.serotonin.json.type.JsonBoolean)2 JsonString (com.serotonin.json.type.JsonString)2