Search in sources :

Example 1 with InvalidSyntaxException

use of com.yahoo.elide.core.audit.InvalidSyntaxException in project elide by yahoo.

the class PersistentResource method auditField.

/**
 * Audit an action on field.
 *
 * @param changeSpec Change spec for audit
 */
protected void auditField(final ChangeSpec changeSpec) {
    final String fieldName = changeSpec.getFieldName();
    Audit[] annotations = dictionary.getAttributeOrRelationAnnotations(getResourceType(), Audit.class, fieldName);
    if (annotations == null || annotations.length == 0) {
        // Default to class-level annotation for action
        auditClass(Audit.Action.UPDATE, changeSpec);
        return;
    }
    for (Audit annotation : annotations) {
        if (annotation.action().length == 1 && annotation.action()[0] == Audit.Action.UPDATE) {
            LogMessage message = new LogMessageImpl(annotation, this, Optional.of(changeSpec));
            getRequestScope().getAuditLogger().log(message);
        } else {
            throw new InvalidSyntaxException("Only Audit.Action.UPDATE is allowed on fields.");
        }
    }
}
Also used : Audit(com.yahoo.elide.annotation.Audit) LogMessage(com.yahoo.elide.core.audit.LogMessage) LogMessageImpl(com.yahoo.elide.core.audit.LogMessageImpl) InvalidSyntaxException(com.yahoo.elide.core.audit.InvalidSyntaxException)

Aggregations

Audit (com.yahoo.elide.annotation.Audit)1 InvalidSyntaxException (com.yahoo.elide.core.audit.InvalidSyntaxException)1 LogMessage (com.yahoo.elide.core.audit.LogMessage)1 LogMessageImpl (com.yahoo.elide.core.audit.LogMessageImpl)1