Search in sources :

Example 11 with TranslatableJsonException

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

the class DataPointAccess method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("dataPointXid");
    if (StringUtils.isBlank(text))
        throw new TranslatableJsonException("emport.error.permission.missing", "dataPointXid");
    Integer dpid = DataPointDao.instance.getIdByXid(text);
    if (dpid == null)
        throw new TranslatableJsonException("emport.error.missingPoint", text);
    dataPointId = dpid;
    text = jsonObject.getString("permission");
    if (StringUtils.isBlank(text))
        throw new TranslatableJsonException("emport.error.missing", "permission", ACCESS_CODES.getCodeList());
    permission = ACCESS_CODES.getId(text);
    if (permission == -1)
        throw new TranslatableJsonException("emport.error.invalid", "permission", text, ACCESS_CODES.getCodeList());
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 12 with TranslatableJsonException

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

the class PublishedPointVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String xid = jsonObject.getString("dataPointId");
    if (xid == null)
        throw new TranslatableJsonException("emport.error.publishedPoint.missing", "dataPointId");
    Integer id = DataPointDao.instance.getIdByXid(xid);
    if (id == null)
        throw new TranslatableJsonException("emport.error.missingPoint", xid);
    dataPointId = id;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 13 with TranslatableJsonException

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

the class PublisherVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    // Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
    name = jsonObject.getString("name");
    enabled = jsonObject.getBoolean("enabled");
    // Legacy conversion for publishType
    if (jsonObject.containsKey("publishType")) {
        String publishTypeCode = jsonObject.getString("publishType");
        int publishTypeId = PUBLISH_TYPE_CODES.getId(publishTypeCode);
        if (publishTypeId == -1)
            throw new TranslatableJsonException("emport.error.invalid", "publishType", publishTypeCode, PUBLISH_TYPE_CODES.getCodeList());
        publishType = publishTypeId;
    } else if (jsonObject.containsKey("changesOnly")) {
        boolean changesOnly = jsonObject.getBoolean("changesOnly");
        if (changesOnly) {
            this.publishType = PublishType.CHANGES_ONLY;
        } else {
            this.publishType = PublishType.ALL;
        }
    }
    // Could wrap the readInto with a try-catch in case one dataPointId entry is null,
    // however this would be a silent suppression of the issue, so we have elected not to.
    // infiniteautomation/ma-core-public#948
    JsonArray arr = jsonObject.getJsonArray("points");
    if (arr != null) {
        points.clear();
        for (JsonValue jv : arr) {
            T point = createPublishedPointInstance();
            reader.readInto(point, jv.toJsonObject());
            points.add(point);
        }
    }
    String text = jsonObject.getString("snapshotSendPeriodType");
    if (text != null) {
        snapshotSendPeriodType = Common.TIME_PERIOD_CODES.getId(text);
        if (snapshotSendPeriodType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "snapshotSendPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
    JsonObject alarmCodeLevels = jsonObject.getJsonObject("alarmLevels");
    if (alarmCodeLevels != null) {
        ExportCodes eventCodes = getEventCodes();
        if (eventCodes != null && eventCodes.size() > 0) {
            for (String code : alarmCodeLevels.keySet()) {
                int eventId = eventCodes.getId(code);
                if (!eventCodes.isValidId(eventId))
                    throw new TranslatableJsonException("emport.error.eventCode", code, eventCodes.getCodeList());
                text = alarmCodeLevels.getString(code);
                int level = AlarmLevels.CODES.getId(text);
                if (!AlarmLevels.CODES.isValidId(level))
                    throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
                setAlarmLevel(eventId, level);
            }
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) ExportCodes(com.serotonin.m2m2.util.ExportCodes) PublisherRT(com.serotonin.m2m2.rt.publish.PublisherRT) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject)

Example 14 with TranslatableJsonException

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

the class RecipientListEntryBean method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("recipientType");
    if (text == null)
        throw new TranslatableJsonException("emport.error.recipient.missing", "recipientType", EmailRecipient.TYPE_CODES.getCodeList());
    recipientType = EmailRecipient.TYPE_CODES.getId(text);
    if (recipientType == -1)
        throw new TranslatableJsonException("emport.error.recipient.invalid", "recipientType", text, EmailRecipient.TYPE_CODES.getCodeList());
    if (recipientType == EmailRecipient.TYPE_MAILING_LIST) {
        text = jsonObject.getString("mailingList");
        if (text == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "mailingList");
        MailingList ml = MailingListDao.instance.getMailingList(text);
        if (ml == null)
            throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "mailingList", text);
        referenceId = ml.getId();
    } else if (recipientType == EmailRecipient.TYPE_USER) {
        text = jsonObject.getString("username");
        if (text == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "username");
        User user = UserDao.instance.getUser(text);
        if (user == null)
            throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "user", text);
        referenceId = user.getId();
    } else if (recipientType == EmailRecipient.TYPE_ADDRESS) {
        referenceAddress = jsonObject.getString("address");
        if (referenceAddress == null)
            throw new TranslatableJsonException("emport.error.recipient.missing.reference", "address");
    }
}
Also used : User(com.serotonin.m2m2.vo.User) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 15 with TranslatableJsonException

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

the class JsonDataVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String json = jsonObject.getString("jsonData");
    try {
        jsonData = JsonDataDao.instance.readValueFromString(json);
    } catch (Exception e) {
        throw new TranslatableJsonException("emport.error.parseError", "jsonData");
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) IOException(java.io.IOException) JsonException(com.serotonin.json.JsonException)

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