use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class ArrayConverter method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonValue jsonValue, Object array, Type type) throws JsonException {
JsonArray jsonArray = (JsonArray) jsonValue;
Class<?> clazz = array.getClass().getComponentType();
for (int i = 0; i < jsonArray.size(); i++) {
try {
Array.set(array, i, reader.read(clazz, jsonArray.get(i)));
} catch (Exception e) {
throw new JsonException("JsonException reading array element " + i, e);
}
}
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseChangedEvent.
public static void raiseChangedEvent(String auditEventType, AbstractVO<?> from, AbstractVO<?> to) {
Map<String, Object> context = new HashMap<String, Object>();
// Find the annotated properties
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findChanges(from, to);
if (context.size() == 0)
// If the object wasn't in fact changed, don't raise an event.
return;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_MODIFY, auditEventType, to, "event.audit.extended.changed", context);
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class EventDao method saveEvent.
public void saveEvent(EventInstance event) {
if (event.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT)) {
AuditEventInstanceVO vo = new AuditEventInstanceVO();
AuditEventType type = (AuditEventType) event.getEventType();
vo.setTypeName(type.getEventSubtype());
vo.setAlarmLevel(event.getAlarmLevel());
if (type.getRaisingUser() != null)
vo.setUserId(type.getRaisingUser().getId());
else
vo.setUserId(Common.NEW_ID);
vo.setChangeType(type.getChangeType());
vo.setObjectId(type.getReferenceId1());
vo.setTimestamp(event.getActiveTimestamp());
try {
vo.setContext(JsonSerializableUtility.convertMapToJsonObject(event.getContext()));
} catch (JsonException e) {
LOG.error(e.getMessage(), e);
}
vo.setMessage(event.getMessage());
AuditEventDao.instance.save(vo);
// Save for use in the cache
type.setReferenceId2(vo.getId());
} else {
if (event.getId() == Common.NEW_ID)
insertEvent(event);
else
updateEvent(event);
}
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class EventDetectorRowMapper method mapRow.
/* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
@Override
public AbstractEventDetectorVO<?> mapRow(ResultSet rs, int rowNum) throws SQLException {
EventDetectorDefinition<?> definition = ModuleRegistry.getEventDetectorDefinition(rs.getString(this.firstColumn + 3));
if (definition == null)
throw new ShouldNeverHappenException("Event Detector defintion of type: " + rs.getString(this.firstColumn + 3) + " not found.");
AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
vo.setId(rs.getInt(this.firstColumn));
vo.setXid(rs.getString(this.firstColumn + 1));
vo.setDefinition(definition);
// Extract the source id
int sourceIdColumnIndex;
if (this.sourceIdColumnOffset < 0)
sourceIdColumnIndex = this.firstColumn + 5 + EventDetectorDao.instance.getSourceIdIndex(definition.getSourceTypeName());
else
sourceIdColumnIndex = this.firstColumn + this.sourceIdColumnOffset;
vo.setSourceId(rs.getInt(sourceIdColumnIndex));
// Read Into Detector
JsonTypeReader typeReader = new JsonTypeReader(rs.getString(this.firstColumn + 4));
try {
JsonValue value = typeReader.read();
JsonObject root = value.toJsonObject();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
root.remove("handlers");
reader.readInto(vo);
} catch (ClassCastException | IOException | JsonException e) {
LOG.error(e.getMessage(), e);
}
return vo;
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class ThrowableSerializingConverter method jsonRead.
@Override
public Object jsonRead(JsonReader reader, JsonValue jsonValue, Type type) throws JsonException {
String hex = jsonValue.toString();
byte[] bs = StreamUtils.fromHex(hex);
ByteArrayInputStream bais = new ByteArrayInputStream(bs);
try {
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (Exception e) {
throw new JsonException(e);
}
}
Aggregations