use of com.serotonin.m2m2.vo.json.JsonDataVO in project ma-core-public by infiniteautomation.
the class JsonDataImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
boolean isNew = false;
if (StringUtils.isBlank(xid)) {
xid = JsonDataDao.instance.generateUniqueXid();
isNew = true;
}
JsonDataVO vo = JsonDataDao.instance.getByXid(xid);
if (vo == null) {
isNew = true;
vo = new JsonDataVO();
vo.setXid(xid);
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
// 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())
setValidationMessages(voResponse, "emport.jsondata.prefix", xid);
else {
// Sweet. Save it.
JsonDataDao.instance.save(vo);
addSuccessMessage(isNew, "emport.jsondata.prefix", xid);
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.jsondata.prefix", xid, getJsonExceptionMessage(e));
}
}
}
Aggregations