Search in sources :

Example 16 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean 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)

Aggregations

RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)8 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)5 User (com.serotonin.m2m2.vo.User)5 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)5 ArrayList (java.util.ArrayList)5 JsonArray (com.serotonin.json.type.JsonArray)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)3 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)3 List (java.util.List)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 IntStringPair (com.serotonin.db.pair.IntStringPair)2 JsonBoolean (com.serotonin.json.type.JsonBoolean)2 JsonValue (com.serotonin.json.type.JsonValue)2 TypeDefinition (com.serotonin.json.util.TypeDefinition)2 MailingListDao (com.serotonin.m2m2.db.dao.MailingListDao)2 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)2 Translations (com.serotonin.m2m2.i18n.Translations)2