use of com.serotonin.m2m2.rt.event.type.AuditEventType in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseDeletedEvent.
public static void raiseDeletedEvent(String auditEventType, AbstractVO<?> o) {
Map<String, Object> context = new HashMap<String, Object>();
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findValues(o);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_DELETE, auditEventType, o, "event.audit.extended.deleted", context);
}
use of com.serotonin.m2m2.rt.event.type.AuditEventType in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseAddedEvent.
public static void raiseAddedEvent(String auditEventType, AbstractVO<?> o) {
Map<String, Object> context = new HashMap<String, Object>();
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findValues(o);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_CREATE, auditEventType, o, "event.audit.extended.added", context);
}
use of com.serotonin.m2m2.rt.event.type.AuditEventType 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.m2m2.rt.event.type.AuditEventType in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseEvent.
private static void raiseEvent(int changeType, String auditEventType, AbstractVO<?> to, String key, Map<String, Object> context) {
User user = Common.getUser();
Object username;
if (user != null)
username = user.getUsername() + " (" + user.getId() + ")";
else {
String descKey = Common.getBackgroundProcessDescription();
if (descKey == null)
username = new TranslatableMessage("common.unknown");
else
username = new TranslatableMessage(descKey);
}
TranslatableMessage message = new TranslatableMessage(key, username, new TranslatableMessage(to.getTypeKey()), to.getName(), to.getXid());
AuditEventType type = new AuditEventType(auditEventType, changeType, to.getId());
type.setRaisingUser(user);
Common.backgroundProcessing.addWorkItem(new AuditEventWorkItem(type, Common.timer.currentTimeMillis(), message, context));
}
use of com.serotonin.m2m2.rt.event.type.AuditEventType 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);
}
}
Aggregations