Search in sources :

Example 31 with AuditEvent

use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.

the class AuditHelperImpl method addCreateAuditEvent.

@Override
public AuditEvent addCreateAuditEvent(Auditable auditable, String note, User user) {
    this.addAuditTrailIfNeeded(auditable);
    assert auditable.getAuditTrail() != null;
    assert auditable.getAuditTrail().getEvents().size() == 0;
    AuditEvent auditEvent = AuditEvent.Factory.newInstance(new Date(), AuditAction.CREATE, note, null, user, null);
    return this.tryUpdate(auditable, auditEvent);
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) Date(java.util.Date)

Example 32 with AuditEvent

use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.

the class AuditTrailServiceImpl method addUpdateEvent.

/**
 * This method creates a new event in the audit trail of the passed Auditable object. If this object also implements
 * the {@link Curatable} interface, and the passed auditEventType is one of the extensions of
 * {@link CurationDetailsEvent} AuditEventType, this method will pass its result to
 * {@link CurationDetailsService#update(Curatable, AuditEvent)}, to update the curatable objects curation details,
 * before returning it.
 *
 * @param auditable      the auditable object to whose audit trail should a new event be added.
 * @param auditEventType the type of the event that should be created.
 * @param note           string displayed as a note for the event
 * @param detail         detailed description of the event.
 * @return the new AuditEvent that was created in the audit trail of the given auditable object.
 * @see AuditTrailService#addUpdateEvent(Auditable, AuditEventType, String, String)
 */
@Override
@Transactional
public AuditEvent addUpdateEvent(final Auditable auditable, final AuditEventType auditEventType, final String note, final String detail) {
    // Create new audit event
    AuditEvent auditEvent = AuditEvent.Factory.newInstance(new Date(), AuditAction.UPDATE, note, detail, null, auditEventType);
    auditEvent = this.auditTrailDao.addEvent(auditable, auditEvent);
    // If object is curatable, update curation details
    if (auditable instanceof Curatable && auditEvent != null && auditEvent.getEventType() != null) {
        curationDetailsService.update((Curatable) auditable, auditEvent);
    }
    // return the newly created event
    return auditEvent;
}
Also used : Curatable(ubic.gemma.model.common.auditAndSecurity.curation.Curatable) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with AuditEvent

use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.

the class AuditController method addAuditEvent.

@SuppressWarnings("unchecked")
public void addAuditEvent(EntityDelegator e, String auditEventType, String comment, String detail) {
    AbstractAuditable entity = this.getAuditable(e);
    if (entity == null) {
        AuditController.log.warn("Couldn't find Auditable represented by " + e);
        return;
    }
    Class<?> clazz;
    try {
        clazz = Class.forName("ubic.gemma.model.common.auditAndSecurity.eventType." + auditEventType);
    } catch (ClassNotFoundException e1) {
        throw new RuntimeException("Unknown event type: " + auditEventType);
    }
    AuditEvent auditEvent = auditTrailService.addUpdateEvent(entity, (Class<? extends AuditEventType>) clazz, comment, detail);
    if (auditEvent == null) {
        AuditController.log.error("Persisting the audit event failed! On auditable id " + entity.getId());
    } else {
        AuditController.log.info("created new event: " + auditEvent);
    }
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) AbstractAuditable(ubic.gemma.model.common.AbstractAuditable)

Example 34 with AuditEvent

use of ubic.gemma.model.common.auditAndSecurity.AuditEvent in project Gemma by PavlidisLab.

the class AuditController method getEvents.

public Collection<AuditEventValueObject> getEvents(EntityDelegator e) {
    Collection<AuditEventValueObject> result = new HashSet<>();
    Auditable entity = this.getAuditable(e);
    if (entity == null) {
        return result;
    }
    assert entity.getAuditTrail().getId() != null;
    Collection<AuditEvent> events = auditEventService.getEvents(entity);
    for (AuditEvent ev : events) {
        if (ev == null)
            continue;
        /*
             * Hide generic update events.
             */
        if (ev.getAction().equals(AuditAction.UPDATE) && ev.getEventType() == null)
            continue;
        result.add(new AuditEventValueObject(ev));
    }
    return result;
}
Also used : AbstractAuditable(ubic.gemma.model.common.AbstractAuditable) Auditable(ubic.gemma.model.common.Auditable) AuditEventValueObject(ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) HashSet(java.util.HashSet)

Aggregations

AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)34 Auditable (ubic.gemma.model.common.Auditable)9 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)7 AuditEventValueObject (ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject)6 StopWatch (org.apache.commons.lang3.time.StopWatch)5 AuditTrail (ubic.gemma.model.common.auditAndSecurity.AuditTrail)5 ArrayDesignValueObject (ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject)5 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)5 Date (java.util.Date)4 Test (org.junit.Test)4 Query (org.hibernate.Query)3 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)3 AuditEventType (ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType)3 HashSet (java.util.HashSet)2 Predicate (org.apache.commons.collections.Predicate)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AbstractAuditable (ubic.gemma.model.common.AbstractAuditable)2 Curatable (ubic.gemma.model.common.auditAndSecurity.curation.Curatable)2 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)2 UserDetailsImpl (gemma.gsec.authentication.UserDetailsImpl)1