use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class AbstractPublisherModel method setAlarmLevels.
public void setAlarmLevels(Map<String, String> alarmCodeLevels) throws TranslatableJsonException {
if (alarmCodeLevels != null) {
ExportCodes eventCodes = this.data.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.get(code);
int level = AlarmLevels.CODES.getId(text);
if (!AlarmLevels.CODES.isValidId(level))
throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
this.data.setAlarmLevel(eventId, level);
}
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method jsonRead.
@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = null;
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());
}
Integer i = jsonObject.getInt("escalationDelay", 1);
if (i != null)
escalationDelay = i;
JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
if (jsonEscalationRecipients != null)
escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
b = jsonObject.getJsonBoolean("keepSendingEscalations");
if (b != null)
repeatEscalations = b.booleanValue();
}
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();
customTemplate = jsonObject.getString("customTemplate");
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");
DataPointVO dpvo = DataPointDao.instance.getByXid(dataPointXid);
if (dpvo == 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(dpvo.getId(), contextKey));
}
this.additionalContext = additionalContext;
} else
this.additionalContext = new ArrayList<>();
script = jsonObject.getString("script");
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;
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class PointEventDetectorVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("type");
if (text == null)
throw new TranslatableJsonException("emport.error.ped.missing", "type", TYPE_CODES.getCodeList());
detectorType = TYPE_CODES.getId(text);
if (!TYPE_CODES.isValidId(detectorType))
throw new TranslatableJsonException("emport.error.ped.invalid", "type", text, TYPE_CODES.getCodeList());
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());
}
switch(detectorType) {
case TYPE_ANALOG_HIGH_LIMIT:
limit = getDouble(jsonObject, "limit");
updateDuration(jsonObject);
if (jsonObject.containsKey("notHigher"))
binaryState = getBoolean(jsonObject, "notHigher");
else
binaryState = false;
if (jsonObject.containsKey("resetLimit")) {
multistateState = 1;
weight = getDouble(jsonObject, "resetLimit");
}
break;
case TYPE_ANALOG_LOW_LIMIT:
limit = getDouble(jsonObject, "limit");
updateDuration(jsonObject);
if (jsonObject.containsKey("notLower"))
binaryState = getBoolean(jsonObject, "notLower");
else
binaryState = false;
if (jsonObject.containsKey("resetLimit")) {
multistateState = 1;
weight = getDouble(jsonObject, "resetLimit");
}
break;
case TYPE_BINARY_STATE:
binaryState = getBoolean(jsonObject, "state");
updateDuration(jsonObject);
break;
case TYPE_MULTISTATE_STATE:
multistateState = getInt(jsonObject, "state");
updateDuration(jsonObject);
break;
case TYPE_POINT_CHANGE:
break;
case TYPE_STATE_CHANGE_COUNT:
changeCount = getInt(jsonObject, "changeCount");
updateDuration(jsonObject);
break;
case TYPE_NO_CHANGE:
updateDuration(jsonObject);
break;
case TYPE_NO_UPDATE:
updateDuration(jsonObject);
break;
case TYPE_ALPHANUMERIC_STATE:
alphanumericState = getString(jsonObject, "state");
updateDuration(jsonObject);
break;
case TYPE_ALPHANUMERIC_REGEX_STATE:
alphanumericState = getString(jsonObject, "state");
updateDuration(jsonObject);
break;
case TYPE_POSITIVE_CUSUM:
limit = getDouble(jsonObject, "limit");
weight = getDouble(jsonObject, "weight");
updateDuration(jsonObject);
break;
case TYPE_NEGATIVE_CUSUM:
limit = getDouble(jsonObject, "limit");
weight = getDouble(jsonObject, "weight");
updateDuration(jsonObject);
break;
case TYPE_ANALOG_RANGE:
weight = getDouble(jsonObject, "low");
limit = getDouble(jsonObject, "high");
binaryState = getBoolean(jsonObject, "withinRange");
break;
case TYPE_SMOOTHNESS:
limit = getDouble(jsonObject, "limit");
changeCount = getInt(jsonObject, "boxcar");
updateDuration(jsonObject);
break;
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class DataPointVO 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");
String text = jsonObject.getString("loggingType");
if (text != null) {
loggingType = LOGGING_TYPE_CODES.getId(text);
if (loggingType == -1)
throw new TranslatableJsonException("emport.error.invalid", "loggingType", text, 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 = INTERVAL_LOGGING_TYPE_CODES.getId(text);
if (intervalLoggingType == -1)
throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingType", text, 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(TimePeriods.MILLISECONDS, TimePeriods.SECONDS, TimePeriods.MINUTES, TimePeriods.HOURS));
}
JsonObject locatorJson = jsonObject.getJsonObject("pointLocator");
if (locatorJson != null)
reader.readInto(pointLocator, locatorJson);
JsonArray pedArray = jsonObject.getJsonArray("eventDetectors");
if (pedArray != null) {
for (JsonValue jv : pedArray) {
JsonObject pedObject = jv.toJsonObject();
String pedXid = pedObject.getString("xid");
if (StringUtils.isBlank(pedXid))
throw new TranslatableJsonException("emport.error.ped.missingAttr", "xid");
// Use the ped xid to lookup an existing ped.
AbstractEventDetectorVO<?> ped = null;
for (AbstractPointEventDetectorVO<?> existing : eventDetectors) {
if (StringUtils.equals(pedXid, existing.getXid())) {
ped = existing;
break;
}
}
JsonArray handlerXids = pedObject.getJsonArray("handlers");
if (handlerXids != null)
for (int k = 0; k < handlerXids.size(); k += 1) {
AbstractEventHandlerVO<?> eh = EventHandlerDao.instance.getByXid(handlerXids.getString(k));
if (eh == null) {
throw new TranslatableJsonException("emport.eventHandler.missing", handlerXids.getString(k));
}
}
if (ped == null) {
String typeStr = pedObject.getString("type");
if (typeStr == null)
throw new TranslatableJsonException("emport.error.ped.missingAttr", "type");
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null)
throw new TranslatableJsonException("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
else {
ped = def.baseCreateEventDetectorVO();
ped.setDefinition(def);
}
// Create a new one
ped.setId(Common.NEW_ID);
ped.setXid(pedXid);
AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) ped;
dped.njbSetDataPoint(this);
eventDetectors.add(dped);
}
reader.readInto(ped, pedObject);
}
}
text = jsonObject.getString("unit");
if (text != null) {
unit = parseUnitString(text, "unit");
unitString = UnitUtil.formatUcum(unit);
}
text = jsonObject.getString("integralUnit");
if (text != null) {
useIntegralUnit = true;
integralUnit = parseUnitString(text, "integralUnit");
integralUnitString = UnitUtil.formatUcum(integralUnit);
}
text = jsonObject.getString("renderedUnit");
if (text != null) {
useRenderedUnit = true;
renderedUnit = parseUnitString(text, "renderedUnit");
renderedUnitString = UnitUtil.formatUcum(renderedUnit);
}
text = jsonObject.getString("plotType");
if (text != null) {
plotType = PLOT_TYPE_CODES.getId(text);
if (plotType == -1)
throw new TranslatableJsonException("emport.error.invalid", "plotType", text, PLOT_TYPE_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());
}
// Simplify
text = jsonObject.getString("simplifyType");
if (text != null) {
simplifyType = SIMPLIFY_TYPE_CODES.getId(text);
if (simplifyType == -1)
throw new TranslatableJsonException("emport.error.invalid", "simplifyType", text, 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 AbstractPointLocatorVO method readDataType.
protected Integer readDataType(JsonObject json, int... excludeIds) throws JsonException {
String text = json.getString("dataType");
if (text == null)
return null;
int dataType = DataTypes.CODES.getId(text);
if (!DataTypes.CODES.isValidId(dataType, excludeIds))
throw new TranslatableJsonException("emport.error.invalid", "dataType", text, DataTypes.CODES.getCodeList(excludeIds));
return dataType;
}
Aggregations