use of com.yahoo.elide.annotation.Audit in project elide by yahoo.
the class PersistentResource method auditClass.
/**
* Audit an action on an entity.
*
* @param action the action
* @param changeSpec the change that occurred
*/
protected void auditClass(Audit.Action action, ChangeSpec changeSpec) {
Audit[] annotations = getResourceType().getAnnotationsByType(Audit.class);
if (annotations == null) {
return;
}
for (Audit annotation : annotations) {
for (Audit.Action auditAction : annotation.action()) {
if (auditAction == action) {
// compare object reference
LogMessage message = new LogMessageImpl(annotation, this, Optional.ofNullable(changeSpec));
getRequestScope().getAuditLogger().log(message);
}
}
}
}
use of com.yahoo.elide.annotation.Audit 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.");
}
}
}
Aggregations