use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ScheduledEventVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("alarmLevel");
if (text != null) {
alarmLevel = AlarmLevels.CODES.getId(text);
if (!AlarmLevels.CODES.isValidId(alarmLevel))
throw new TranslatableJsonException("emport.error.scheduledEvent.invalid", "alarmLevel", text, AlarmLevels.CODES.getCodeList());
}
text = jsonObject.getString("scheduleType");
if (text != null) {
scheduleType = TYPE_CODES.getId(text);
if (!TYPE_CODES.isValidId(scheduleType))
throw new TranslatableJsonException("emport.error.scheduledEvent.invalid", "scheduleType", text, TYPE_CODES.getCodeList());
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class VMStatPointLocatorVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("attributeId");
if (text == null)
throw new TranslatableJsonException("emport.error.missing", "attributeId", ATTRIBUTE_CODES.getCodeList());
attributeId = ATTRIBUTE_CODES.getId(text);
if (!ATTRIBUTE_CODES.isValidId(attributeId))
throw new TranslatableJsonException("emport.error.invalid", "attributeId", text, ATTRIBUTE_CODES.getCodeList());
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class PointLinkVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
String xid = jsonObject.getString("sourcePointId");
if (xid != null) {
DataPointVO vo = dataPointDao.getDataPoint(xid);
if (vo == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
sourcePointId = vo.getId();
}
xid = jsonObject.getString("targetPointId");
if (xid != null) {
DataPointVO vo = dataPointDao.getDataPoint(xid);
if (vo == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
targetPointId = vo.getId();
}
String text = jsonObject.getString("event");
if (text != null) {
event = EVENT_CODES.getId(text);
if (!EVENT_CODES.isValidId(event))
throw new TranslatableJsonException("emport.error.link.invalid", "event", text, EVENT_CODES.getCodeList());
}
text = jsonObject.getString("logLevel");
if (text != null) {
logLevel = ScriptLog.LOG_LEVEL_CODES.getId(text);
if (logLevel == -1)
throw new TranslatableJsonException("emport.error.invalid", "logLevel", text, ScriptLog.LOG_LEVEL_CODES.getCodeList());
} else {
logLevel = ScriptLog.LogLevel.NONE;
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class PointLinkEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject pointLink = jsonValue.toJsonObject();
PointLinkDao pointLinkDao = PointLinkDao.instance;
String xid = pointLink.getString("xid");
if (StringUtils.isBlank(xid))
xid = pointLinkDao.generateUniqueXid();
PointLinkVO vo = pointLinkDao.getPointLink(xid);
if (vo == null) {
vo = new PointLinkVO();
vo.setXid(xid);
}
try {
importContext.getReader().readInto(vo, pointLink);
// Now validate it. Use a new response object so we can distinguish errors in this vo from other errors.
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(voResponse, "emport.pointLink.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
RTMDefinition.instance.savePointLink(vo);
importContext.addSuccessMessage(isnew, "emport.pointLink.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.pointLink.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.pointLink.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class WatchlistEmportDefinitionNoCase method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject watchListJson = jsonValue.toJsonObject();
String xid = watchListJson.getString("xid");
if (StringUtils.isBlank(xid))
xid = WatchListDao.instance.generateUniqueXid();
WatchListVO watchList = WatchListDao.instance.getWatchList(xid);
if (watchList == null) {
watchList = new WatchListVO();
watchList.setXid(xid);
}
try {
importContext.getReader().readInto(watchList, watchListJson);
// Now validate it. Use a new response object so we can distinguish errors in this user from other
// errors.
ProcessResult watchListResponse = new ProcessResult();
watchList.validate(watchListResponse);
if (watchListResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(watchListResponse, "emport.watchList.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = watchList.getId() == Common.NEW_ID;
WatchListDao.instance.saveWatchList(watchList);
importContext.addSuccessMessage(isnew, "emport.watchList.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
Aggregations