Search in sources :

Example 6 with TranslatableJsonException

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

the class DataSourceVO 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");
    // Don't change the type.
    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());
                String 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);
            }
        }
    }
    String text = jsonObject.getString("purgeType");
    if (text != null) {
        purgeType = Common.TIME_PERIOD_CODES.getId(text);
        if (purgeType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "purgeType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
}
Also used : ExportCodes(com.serotonin.m2m2.util.ExportCodes) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 7 with TranslatableJsonException

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

the class ShareUser method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("user");
    if (StringUtils.isBlank(text))
        throw new TranslatableJsonException("emport.error.viewShare.missing", "user");
    User user = UserDao.instance.getUser(text);
    if (user == null)
        throw new TranslatableJsonException("emport.error.missingUser", text);
    userId = user.getId();
    text = jsonObject.getString("accessType");
    if (StringUtils.isBlank(text))
        throw new TranslatableJsonException("emport.error.missing", "accessType", ACCESS_CODES.getCodeList(ACCESS_OWNER));
    accessType = ACCESS_CODES.getId(text, ACCESS_OWNER);
    if (accessType == -1)
        throw new TranslatableJsonException("emport.error.invalid", "permission", text, ACCESS_CODES.getCodeList(ACCESS_OWNER));
}
Also used : User(com.serotonin.m2m2.vo.User) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 8 with TranslatableJsonException

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

the class ConvertingRenderer method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    // To ensure we have this property as it is a new one
    if (jsonObject.containsKey("useUnitAsSuffix")) {
        useUnitAsSuffix = jsonObject.getBoolean("useUnitAsSuffix");
    }
    String text = jsonObject.getString("unit");
    if (text != null) {
        try {
            unit = UnitUtil.parseUcum(text);
        } catch (Exception e) {
            throw new TranslatableJsonException("emport.error.parseError", "unit");
        }
    }
    text = jsonObject.getString("renderedUnit");
    if (text != null) {
        try {
            renderedUnit = UnitUtil.parseUcum(text);
        } catch (Exception e) {
            throw new TranslatableJsonException("emport.error.parseError", "renderedUnit");
        }
    } else {
        renderedUnit = unit;
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) IOException(java.io.IOException)

Example 9 with TranslatableJsonException

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

the class DataPointPropertiesTemplateVO 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");
    // Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
    String text = jsonObject.getString("templateType");
    if (text != null) {
        dataTypeId = TEMPLATE_TYPE_CODES.getId(text);
        if (dataTypeId == -1)
            throw new TranslatableJsonException("emport.error.invalid", "templateType", text, TEMPLATE_TYPE_CODES.getCodeList());
    }
    text = jsonObject.getString("dataType");
    if (text != null) {
        dataTypeId = DataTypes.CODES.getId(text);
        if (dataTypeId == -1)
            throw new TranslatableJsonException("emport.error.invalid", "dataType", text, DataTypes.CODES.getCodeList());
    }
    // Rollup
    text = jsonObject.getString("rollup");
    if (text != null) {
        rollup = Common.ROLLUP_CODES.getId(text);
        if (rollup == -1)
            throw new TranslatableJsonException("emport.error.chart.invalid", "rollup", text, Common.ROLLUP_CODES.getCodeList());
    }
    text = jsonObject.getString("loggingType");
    if (text != null) {
        loggingType = DataPointVO.LOGGING_TYPE_CODES.getId(text);
        if (loggingType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "loggingType", text, DataPointVO.LOGGING_TYPE_CODES.getCodeList());
    }
    text = jsonObject.getString("intervalLoggingPeriodType");
    if (text != null) {
        intervalLoggingPeriodType = Common.TIME_PERIOD_CODES.getId(text);
        if (intervalLoggingPeriodType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
    text = jsonObject.getString("intervalLoggingType");
    if (text != null) {
        intervalLoggingType = DataPointVO.INTERVAL_LOGGING_TYPE_CODES.getId(text);
        if (intervalLoggingType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingType", text, DataPointVO.INTERVAL_LOGGING_TYPE_CODES.getCodeList());
    }
    text = jsonObject.getString("purgeType");
    if (text != null) {
        purgeType = Common.TIME_PERIOD_CODES.getId(text);
        if (purgeType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "purgeType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
    text = jsonObject.getString("plotType");
    if (text != null) {
        plotType = DataPointVO.PLOT_TYPE_CODES.getId(text);
        if (plotType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "plotType", text, DataPointVO.PLOT_TYPE_CODES.getCodeList());
    }
    // Simplify
    text = jsonObject.getString("simplifyType");
    if (text != null) {
        simplifyType = DataPointVO.SIMPLIFY_TYPE_CODES.getId(text);
        if (simplifyType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "simplifyType", text, DataPointVO.SIMPLIFY_TYPE_CODES.getCodeList());
    }
    int simplifyTarget = jsonObject.getInt("simplifyTarget", Integer.MIN_VALUE);
    if (simplifyTarget != Integer.MIN_VALUE)
        this.simplifyTarget = simplifyTarget;
    double simplifyTolerance = jsonObject.getDouble("simplifyTolerance", Double.NaN);
    if (simplifyTolerance != Double.NaN)
        this.simplifyTolerance = simplifyTolerance;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 10 with TranslatableJsonException

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

the class AbstractPointEventDetectorVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    // TODO Some configuration descriptions will throw NPE if dataPoint isn't set
    // this.dataPoint = DataPointDao.instance.get(sourceId);
    super.jsonRead(reader, jsonObject);
    String text = jsonObject.getString("alarmLevel");
    if (text != null) {
        alarmLevel = AlarmLevels.CODES.getId(text);
        if (!AlarmLevels.CODES.isValidId(alarmLevel))
            throw new TranslatableJsonException("emport.error.ped.invalid", "alarmLevel", text, AlarmLevels.CODES.getCodeList());
    }
}
Also used : 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