Search in sources :

Example 1 with AbstractVO

use of com.serotonin.m2m2.vo.AbstractVO 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 AbstractVO

use of com.serotonin.m2m2.vo.AbstractVO 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 AbstractVO

use of com.serotonin.m2m2.vo.AbstractVO in project ma-core-public by infiniteautomation.

the class MangoTestBase method validate.

/**
 * Validate a vo, fail if invalid
 * @param vo
 */
public void validate(AbstractVO<?> vo) {
    ProcessResult result = new ProcessResult();
    vo.validate(result);
    if (result.getHasMessages()) {
        String messages = new String();
        for (ProcessMessage message : result.getMessages()) messages += message.toString(Common.getTranslations()) + " ";
        fail("Validation of " + vo.getClass().getName() + " failed because " + messages);
    }
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Example 4 with AbstractVO

use of com.serotonin.m2m2.vo.AbstractVO 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 5 with AbstractVO

use of com.serotonin.m2m2.vo.AbstractVO 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)

Aggregations

JsonObject (com.serotonin.json.type.JsonObject)4 JsonException (com.serotonin.json.JsonException)3 JsonSerializableUtility (com.serotonin.m2m2.util.JsonSerializableUtility)3 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 User (com.serotonin.m2m2.vo.User)1