use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class AnalogAttractorChangeVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = jsonObject.getString("attractionPointId");
if (text != null) {
DataPointVO dp = DataPointDao.instance.getDataPoint(text);
if (dp == null)
throw new TranslatableJsonException("virtual.error.attractor.missingPoint", "attractionPointId", text);
attractionPointId = dp.getId();
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class WatchListEmportDefinition 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.save(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));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class VirtualPointLocatorVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
Integer value = readDataType(jsonObject, DataTypes.IMAGE);
if (value != null)
dataTypeId = value;
JsonObject ctjson = jsonObject.getJsonObject("changeType");
if (ctjson == null)
throw new TranslatableJsonException("emport.error.missingObject", "changeType");
String text = ctjson.getString("type");
if (text == null)
throw new TranslatableJsonException("emport.error.missing", "type", ChangeTypeVO.CHANGE_TYPE_CODES.getCodeList());
changeTypeId = ChangeTypeVO.CHANGE_TYPE_CODES.getId(text);
if (changeTypeId == -1)
throw new TranslatableJsonException("emport.error.invalid", "changeType", text, ChangeTypeVO.CHANGE_TYPE_CODES.getCodeList());
reader.readInto(getChangeType(), ctjson);
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class WatchListVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String username = jsonObject.getString("user");
if (StringUtils.isBlank(username))
throw new TranslatableJsonException("emport.error.missingValue", "user");
User user = UserDao.instance.getUser(username);
if (user == null)
throw new TranslatableJsonException("emport.error.missingUser", username);
userId = user.getId();
JsonArray jsonDataPoints = jsonObject.getJsonArray("dataPoints");
if (jsonDataPoints != null) {
pointList.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonDataPoints) {
String xid = jv.toString();
DataPointVO dpVO = dataPointDao.getDataPoint(xid);
if (dpVO == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
pointList.add(dpVO);
}
}
JsonObject o = jsonObject.getJsonObject("data");
if (o != null)
this.data = o.toMap();
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class EmportDwr method importData.
@DwrPermission(admin = true)
public ProcessResult importData(String data) {
ProcessResult response = new ProcessResult();
Translations translations = getTranslations();
User user = Common.getHttpUser();
JsonTypeReader reader = new JsonTypeReader(data);
try {
JsonValue value = reader.read();
if (value instanceof JsonObject) {
JsonObject root = value.toJsonObject();
ImportTask importTask = new ImportTask(root, translations, user, true);
user.setImportTask(importTask);
response.addData("importStarted", true);
} else {
response.addGenericMessage("emport.invalidImportData");
}
} catch (ClassCastException e) {
response.addGenericMessage("emport.parseError", e.getMessage());
} catch (TranslatableJsonException e) {
response.addMessage(e.getMsg());
} catch (IOException e) {
response.addGenericMessage("emport.parseError", e.getMessage());
} catch (JsonException e) {
response.addGenericMessage("emport.parseError", e.getMessage());
}
return response;
}
Aggregations