use of com.serotonin.json.JsonException in project ma-modules-public by infiniteautomation.
the class SerotoninJsonValueSerializer method serialize.
@Override
public void serialize(JsonValue value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, new SerotoninToJacksonJsonWriter(jgen));
// TODO Make configurable
writer.setPrettyIndent(3);
writer.setPrettyOutput(true);
try {
writer.writeObject(value);
} catch (JsonException e) {
throw new IOException(e);
}
}
use of com.serotonin.json.JsonException in project ma-modules-public by infiniteautomation.
the class AuditEventInstanceModel method getContext.
@JsonRawValue
public String getContext() {
// Since the JsonData table can contain JSON within the context, return raw JSON all the time here
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
writer.setPrettyIndent(3);
writer.setPrettyOutput(true);
try {
writer.writeObject(this.data.getContext());
return stringWriter.toString();
} catch (JsonException e) {
throw new ShouldNeverHappenException(e);
} catch (IOException e) {
throw new ShouldNeverHappenException(e);
}
}
use of com.serotonin.json.JsonException 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.json.JsonException 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));
}
}
use of com.serotonin.json.JsonException in project ma-modules-public by infiniteautomation.
the class MaintenanceEventEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
JsonObject maintenanceEvent = jsonValue.toJsonObject();
String xid = maintenanceEvent.getString("xid");
if (StringUtils.isBlank(xid))
xid = maintenanceEventDao.generateUniqueXid();
MaintenanceEventVO vo = maintenanceEventDao.getMaintenanceEvent(xid);
if (vo == null) {
vo = new MaintenanceEventVO();
vo.setXid(xid);
}
try {
importContext.getReader().readInto(vo, maintenanceEvent);
// 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.maintenanceEvent.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
RTMDefinition.instance.saveMaintenanceEvent(vo);
importContext.addSuccessMessage(isnew, "emport.maintenanceEvent.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
Aggregations