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