Search in sources :

Example 1 with AuditEventType

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);
}
Also used : JsonException(com.serotonin.json.JsonException) HashMap(java.util.HashMap) JsonSerializableUtility(com.serotonin.m2m2.util.JsonSerializableUtility) JsonObject(com.serotonin.json.type.JsonObject) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with AuditEventType

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);
}
Also used : JsonException(com.serotonin.json.JsonException) HashMap(java.util.HashMap) JsonSerializableUtility(com.serotonin.m2m2.util.JsonSerializableUtility) JsonObject(com.serotonin.json.type.JsonObject) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with AuditEventType

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);
}
Also used : JsonException(com.serotonin.json.JsonException) HashMap(java.util.HashMap) JsonSerializableUtility(com.serotonin.m2m2.util.JsonSerializableUtility) JsonObject(com.serotonin.json.type.JsonObject) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with AuditEventType

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));
}
Also used : User(com.serotonin.m2m2.vo.User) JsonObject(com.serotonin.json.type.JsonObject) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 5 with AuditEventType

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);
    }
}
Also used : JsonException(com.serotonin.json.JsonException) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)

Aggregations

JsonException (com.serotonin.json.JsonException)4 JsonObject (com.serotonin.json.type.JsonObject)4 JsonSerializableUtility (com.serotonin.m2m2.util.JsonSerializableUtility)3 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 AuditEventType (com.serotonin.m2m2.rt.event.type.AuditEventType)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 EventTypeDefinition (com.serotonin.m2m2.module.EventTypeDefinition)1 DataPointEventType (com.serotonin.m2m2.rt.event.type.DataPointEventType)1 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)1 EventType (com.serotonin.m2m2.rt.event.type.EventType)1 MissingEventType (com.serotonin.m2m2.rt.event.type.MissingEventType)1 PublisherEventType (com.serotonin.m2m2.rt.event.type.PublisherEventType)1 SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)1 User (com.serotonin.m2m2.vo.User)1 AuditEventInstanceVO (com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)1