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());
}
}
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));
}
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;
}
}
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;
}
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());
}
}
Aggregations