Search in sources :

Example 21 with DataPointDao

use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-modules-public by infiniteautomation.

the class WatchListVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    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 jsonDataPoints = jsonObject.getJsonArray("dataPoints");
    if (jsonDataPoints != null) {
        pointList.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonDataPoints) {
            String xid = jv.toString();
            DataPointVO dpVO = dataPointDao.getDataPoint(xid);
            if (dpVO == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            pointList.add(dpVO);
        }
    }
    JsonObject o = jsonObject.getJsonObject("data");
    if (o != null)
        this.data = o.toMap();
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject)

Example 22 with DataPointDao

use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.

the class EventHandlerVO method jsonRead.

@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    DataPointDao dataPointDao = DataPointDao.instance;
    String text = jsonObject.getString("handlerType");
    if (text != null) {
        handlerType = TYPE_CODES.getId(text);
        if (!TYPE_CODES.isValidId(handlerType))
            throw new TranslatableJsonException("emport.error.eventHandler.invalid", "handlerType", text, TYPE_CODES.getCodeList());
    }
    if (handlerType == TYPE_SET_POINT) {
        String xid = jsonObject.getString("targetPointId");
        if (xid != null) {
            Integer id = dataPointDao.getIdByXid(xid);
            if (id == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            targetPointId = id;
        }
        // Active
        text = jsonObject.getString("activeAction");
        if (text != null) {
            activeAction = SET_ACTION_CODES.getId(text);
            if (!SET_ACTION_CODES.isValidId(activeAction))
                throw new TranslatableJsonException("emport.error.eventHandler.invalid", "activeAction", text, SET_ACTION_CODES.getCodeList());
        }
        if (activeAction == SET_ACTION_POINT_VALUE) {
            xid = jsonObject.getString("activePointId");
            if (xid != null) {
                Integer id = dataPointDao.getIdByXid(xid);
                if (id == null)
                    throw new TranslatableJsonException("emport.error.missingPoint", xid);
                activePointId = id;
            }
        } else if (activeAction == SET_ACTION_STATIC_VALUE) {
            text = jsonObject.getString("activeValueToSet");
            if (text != null)
                activeValueToSet = text;
        }
        // Inactive
        text = jsonObject.getString("inactiveAction");
        if (text != null) {
            inactiveAction = SET_ACTION_CODES.getId(text);
            if (!SET_ACTION_CODES.isValidId(inactiveAction))
                throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveAction", text, SET_ACTION_CODES.getCodeList());
        }
        if (inactiveAction == SET_ACTION_POINT_VALUE) {
            xid = jsonObject.getString("inactivePointId");
            if (xid != null) {
                Integer id = dataPointDao.getIdByXid(xid);
                if (id == null)
                    throw new TranslatableJsonException("emport.error.missingPoint", xid);
                inactivePointId = id;
            }
        } else if (inactiveAction == SET_ACTION_STATIC_VALUE) {
            text = jsonObject.getString("inactiveValueToSet");
            if (text != null)
                inactiveValueToSet = text;
        }
    } else if (handlerType == TYPE_EMAIL) {
        TypeDefinition recipType = new TypeDefinition(List.class, RecipientListEntryBean.class);
        JsonArray jsonActiveRecipients = jsonObject.getJsonArray("activeRecipients");
        if (jsonActiveRecipients != null)
            activeRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonActiveRecipients);
        JsonBoolean b = jsonObject.getJsonBoolean("sendEscalation");
        if (b != null)
            sendEscalation = b.booleanValue();
        if (sendEscalation) {
            text = jsonObject.getString("escalationDelayType");
            if (text != null) {
                escalationDelayType = Common.TIME_PERIOD_CODES.getId(text);
                if (escalationDelayType == -1)
                    throw new TranslatableJsonException("emport.error.invalid", "escalationDelayType", text, Common.TIME_PERIOD_CODES.getCodeList());
            }
            JsonNumber i = jsonObject.getJsonNumber("escalationDelay");
            if (i != null)
                escalationDelay = i.intValue();
            JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
            if (jsonEscalationRecipients != null)
                escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
        }
        b = jsonObject.getJsonBoolean("sendInactive");
        if (b != null)
            sendInactive = b.booleanValue();
        if (sendInactive) {
            b = jsonObject.getJsonBoolean("inactiveOverride");
            if (b != null)
                inactiveOverride = b.booleanValue();
            if (inactiveOverride) {
                JsonArray jsonInactiveRecipients = jsonObject.getJsonArray("inactiveRecipients");
                if (jsonInactiveRecipients != null)
                    inactiveRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonInactiveRecipients);
            }
        }
        b = jsonObject.getJsonBoolean("includeSystemInformation");
        if (b != null) {
            includeSystemInfo = b.booleanValue();
        }
        includePointValueCount = jsonObject.getInt("includePointValueCount", 0);
        b = jsonObject.getJsonBoolean("includeLogfile");
        if (b != null) {
            includeSystemInfo = b.booleanValue();
        }
    } else if (handlerType == TYPE_PROCESS) {
        text = jsonObject.getString("activeProcessCommand");
        if (text != null)
            activeProcessCommand = text;
        JsonNumber i = jsonObject.getJsonNumber("activeProcessTimeout");
        if (i != null)
            activeProcessTimeout = i.intValue();
        text = jsonObject.getString("inactiveProcessCommand");
        if (text != null)
            inactiveProcessCommand = text;
        i = jsonObject.getJsonNumber("inactiveProcessTimeout");
        if (i != null)
            inactiveProcessTimeout = i.intValue();
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonNumber(com.serotonin.json.type.JsonNumber) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) List(java.util.List) JsonBoolean(com.serotonin.json.type.JsonBoolean) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean) TypeDefinition(com.serotonin.json.util.TypeDefinition)

Example 23 with DataPointDao

use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.

the class SetPointEventHandlerVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    DataPointDao dataPointDao = DataPointDao.instance;
    String xid = jsonObject.getString("targetPointId");
    if (xid != null) {
        Integer id = dataPointDao.getIdByXid(xid);
        if (id == null)
            throw new TranslatableJsonException("emport.error.missingPoint", xid);
        targetPointId = id;
    }
    // Active
    String text = jsonObject.getString("activeAction");
    if (text != null) {
        activeAction = SET_ACTION_CODES.getId(text);
        if (!SET_ACTION_CODES.isValidId(activeAction))
            throw new TranslatableJsonException("emport.error.eventHandler.invalid", "activeAction", text, SET_ACTION_CODES.getCodeList());
    }
    if (activeAction == SET_ACTION_POINT_VALUE) {
        xid = jsonObject.getString("activePointId");
        if (xid != null) {
            Integer id = dataPointDao.getIdByXid(xid);
            if (id == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            activePointId = id;
        }
    } else if (activeAction == SET_ACTION_STATIC_VALUE) {
        text = jsonObject.getString("activeValueToSet");
        if (text != null)
            activeValueToSet = text;
    } else if (activeAction == SET_ACTION_SCRIPT_VALUE) {
        text = jsonObject.getString("activeScript");
        if (text == null)
            throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveScript");
        activeValueToSet = text;
    }
    // Inactive
    text = jsonObject.getString("inactiveAction");
    if (text != null) {
        inactiveAction = SET_ACTION_CODES.getId(text);
        if (!SET_ACTION_CODES.isValidId(inactiveAction))
            throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveAction", text, SET_ACTION_CODES.getCodeList());
    }
    if (inactiveAction == SET_ACTION_POINT_VALUE) {
        xid = jsonObject.getString("inactivePointId");
        if (xid != null) {
            Integer id = dataPointDao.getIdByXid(xid);
            if (id == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            inactivePointId = id;
        }
    } else if (inactiveAction == SET_ACTION_STATIC_VALUE) {
        text = jsonObject.getString("inactiveValueToSet");
        if (text != null)
            inactiveValueToSet = text;
    } else if (inactiveAction == SET_ACTION_SCRIPT_VALUE) {
        text = jsonObject.getString("inactiveScript");
        if (text == null)
            throw new TranslatableJsonException("emport.error.eventHandler.invalid", "inactiveScript");
        inactiveValueToSet = text;
    }
    JsonArray context = jsonObject.getJsonArray("additionalContext");
    if (context != null) {
        List<IntStringPair> additionalContext = new ArrayList<>();
        for (JsonValue jv : context) {
            JsonObject jo = jv.toJsonObject();
            String dataPointXid = jo.getString("dataPointXid");
            if (dataPointXid == null)
                throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
            Integer id = DataPointDao.instance.getIdByXid(dataPointXid);
            if (id == null)
                throw new TranslatableJsonException("emport.error.missingPoint", dataPointXid);
            String contextKey = jo.getString("contextKey");
            if (contextKey == null)
                throw new TranslatableJsonException("emport.error.context.missing", "contextKey");
            additionalContext.add(new IntStringPair(id, contextKey));
        }
        this.additionalContext = additionalContext;
    } else
        this.additionalContext = new ArrayList<>();
    JsonObject permissions = jsonObject.getJsonObject("scriptPermissions");
    ScriptPermissions scriptPermissions = new ScriptPermissions();
    if (permissions != null) {
        String perm = permissions.getString(ScriptPermissions.DATA_SOURCE);
        if (perm != null)
            scriptPermissions.setDataSourcePermissions(perm);
        perm = permissions.getString(ScriptPermissions.DATA_POINT_READ);
        if (perm != null)
            scriptPermissions.setDataPointReadPermissions(perm);
        perm = permissions.getString(ScriptPermissions.DATA_POINT_SET);
        if (perm != null)
            scriptPermissions.setDataPointSetPermissions(perm);
    }
    this.scriptPermissions = scriptPermissions;
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject) ScriptPermissions(com.serotonin.m2m2.rt.script.ScriptPermissions)

Example 24 with DataPointDao

use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.

the class PointFolder method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    JsonArray jsonPoints = jsonObject.getJsonArray("points");
    if (jsonPoints != null) {
        points.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonPoints) {
            String xid = jv.toString();
            DataPointVO dp = dataPointDao.getDataPoint(xid);
            if (dp == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            points.add(new DataPointSummary(dp));
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 25 with DataPointDao

use of com.serotonin.m2m2.db.dao.DataPointDao in project ma-core-public by infiniteautomation.

the class VarNames method jsonWriteVarContext.

public static void jsonWriteVarContext(ObjectWriter writer, List<IntStringPair> context) throws IOException, JsonException {
    DataPointDao dataPointDao = DataPointDao.instance;
    JsonArray pointList = new JsonArray();
    for (IntStringPair p : context) {
        JsonObject point = new JsonObject();
        pointList.add(point);
        point.put("varName", new JsonString(p.getValue()));
        point.put("dataPointXid", new JsonString(dataPointDao.getXidById(p.getKey())));
    }
    writer.writeEntry("context", pointList);
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IntStringPair(com.serotonin.db.pair.IntStringPair) JsonObject(com.serotonin.json.type.JsonObject) JsonString(com.serotonin.json.type.JsonString)

Aggregations

DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)21 JsonArray (com.serotonin.json.type.JsonArray)8 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)8 User (com.serotonin.m2m2.vo.User)8 JsonObject (com.serotonin.json.type.JsonObject)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 ArrayList (java.util.ArrayList)6 JsonValue (com.serotonin.json.type.JsonValue)5 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)5 HashMap (java.util.HashMap)5 IntStringPair (com.serotonin.db.pair.IntStringPair)4 JsonString (com.serotonin.json.type.JsonString)4 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 InvalidArgumentException (com.serotonin.InvalidArgumentException)3 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 ReportPointVO (com.serotonin.m2m2.reports.vo.ReportPointVO)3 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)3 DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)3