Search in sources :

Example 16 with AuditEvent

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

the class AuditAdviceTest method testCascadingCreateWithAssociatedAuditable.

@Test
public void testCascadingCreateWithAssociatedAuditable() {
    ExpressionExperiment ee = this.getTestPersistentCompleteExpressionExperiment(false);
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    assertEquals(16, ee.getBioAssays().size());
    assertNotNull(ee.getBioAssays().iterator().next().getId());
    assertEquals(1, ee.getAuditTrail().getEvents().size());
    for (BioAssay prod : ee.getBioAssays()) {
        assertNotNull(prod.getAuditTrail());
        Collection<AuditEvent> events = this.auditTrailService.getEvents(prod);
        assertEquals(1, events.size());
        for (AuditEvent e : events) {
            assertNotNull(e.getId());
            assertEquals(AuditAction.CREATE, e.getAction());
        }
    }
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 17 with AuditEvent

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

the class AuditAdviceTest method testSimpleAuditCreateUpdateUser.

@Test
public void testSimpleAuditCreateUpdateUser() {
    String USERNAME = RandomStringUtils.randomAlphabetic(BaseSpringContextTest.RANDOM_STRING_LENGTH);
    String encodedPassword = passwordEncoder.encodePassword(USERNAME, USERNAME);
    UserDetailsImpl u = new UserDetailsImpl(encodedPassword, USERNAME, true, null, null, null, new Date());
    userManager.createUser(u);
    User user = (User) userService.findByUserName(USERNAME);
    List<AuditEvent> events = auditTrailService.getEvents(user);
    assertEquals("Should have just one event, a 'create'", 1, events.size());
    assertEquals(AuditAction.CREATE, events.get(0).getAction());
    assertNotNull(events.get(0).getId());
    // change something.
    user.setEmail(RandomStringUtils.randomNumeric(10));
    userService.update(user);
    events = auditTrailService.getEvents(user);
    int sizeAfterFirstUpdate = events.size();
    assertEquals("Should have a 'create' and an 'update'", 2, sizeAfterFirstUpdate);
    // debugging...
    if (!events.get(0).getAction().equals(AuditAction.CREATE)) {
        log.info("First event wasn't 'C', dumping trail");
        for (AuditEvent ae : events) {
            log.info(ae);
        }
    }
    assertEquals(AuditAction.CREATE, events.get(0).getAction());
    assertEquals(AuditAction.UPDATE, events.get(sizeAfterFirstUpdate - 1).getAction());
    // third time.
    // change something.
    user.setEmail(RandomStringUtils.randomNumeric(10));
    userService.update(user);
    events = auditTrailService.getEvents(user);
    assertEquals(3, user.getAuditTrail().getEvents().size());
    assertEquals(AuditAction.UPDATE, events.get(2).getAction());
    // cleanup
    userManager.deleteUser(USERNAME);
}
Also used : UserDetailsImpl(gemma.gsec.authentication.UserDetailsImpl) User(ubic.gemma.model.common.auditAndSecurity.User) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 18 with AuditEvent

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

the class AuditAdviceTest method checkAuditTrail.

private void checkAuditTrail(Auditable c, Collection<Long> trailIds, Collection<Long> eventIds) {
    AuditTrail auditTrail = c.getAuditTrail();
    assertNotNull("No audit trail for " + c, auditTrail);
    trailIds.add(auditTrail.getId());
    assertTrue("Trail but no events for " + c, auditTrail.getEvents().size() > 0);
    for (AuditEvent ae : auditTrail.getEvents()) {
        eventIds.add(ae.getId());
    }
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) AuditTrail(ubic.gemma.model.common.auditAndSecurity.AuditTrail)

Example 19 with AuditEvent

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

the class AbstractSpringAwareCLI method noNeedToRun.

/**
 * @param auditable  auditable
 * @param eventClass can be null
 * @return boolean
 */
protected boolean noNeedToRun(Auditable auditable, Class<? extends AuditEventType> eventClass) {
    boolean needToRun = true;
    Date skipIfLastRunLaterThan = this.getLimitingDate();
    List<AuditEvent> events = this.auditEventService.getEvents(auditable);
    // assume okay unless indicated otherwise
    boolean okToRun = true;
    // count.
    for (int j = events.size() - 1; j >= 0; j--) {
        AuditEvent event = events.get(j);
        if (event == null) {
            // legacy of ordered-list which could end up with gaps; should not be needed any more
            continue;
        }
        AuditEventType eventType = event.getEventType();
        if (eventType != null && eventClass != null && eventClass.isAssignableFrom(eventType.getClass()) && !eventType.getClass().getSimpleName().startsWith("Fail")) {
            if (skipIfLastRunLaterThan != null) {
                if (event.getDate().after(skipIfLastRunLaterThan)) {
                    AbstractCLI.log.info(auditable + ": " + " run more recently than " + skipIfLastRunLaterThan);
                    errorObjects.add(auditable + ": " + " run more recently than " + skipIfLastRunLaterThan);
                    needToRun = false;
                }
            } else {
                // it has been run already at some point
                needToRun = false;
            }
        }
    }
    /*
         * Always skip if the object is curatable and troubled
         */
    if (auditable instanceof Curatable) {
        Curatable curatable = (Curatable) auditable;
        // not ok if troubled
        okToRun = !curatable.getCurationDetails().getTroubled();
        // special case for expression experiments - check associated ADs.
        if (okToRun && curatable instanceof ExpressionExperiment) {
            ExpressionExperimentService ees = this.getBean(ExpressionExperimentService.class);
            for (ArrayDesign ad : ees.getArrayDesignsUsed((ExpressionExperiment) auditable)) {
                if (ad.getCurationDetails().getTroubled()) {
                    // not ok if even one parent AD is troubled, no need to check the remaining ones.
                    okToRun = false;
                    break;
                }
            }
        }
        if (!okToRun) {
            AbstractCLI.log.info(auditable + ": has an active 'trouble' flag");
            errorObjects.add(auditable + ": has an active 'trouble' flag");
        }
    }
    return !needToRun || !okToRun;
}
Also used : Curatable(ubic.gemma.model.common.auditAndSecurity.curation.Curatable) AuditEventType(ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) Date(java.util.Date)

Example 20 with AuditEvent

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

the class ExpressionExperimentServiceImpl method getLastEvent.

/**
 * @return a map of the expression experiment ids to the last audit event for the given audit event type the map
 * can contain nulls if the specified auditEventType isn't found for a given expression experiment id
 */
private Map<Long, AuditEvent> getLastEvent(Collection<ExpressionExperiment> ees, AuditEventType type) {
    Map<Long, AuditEvent> lastEventMap = new HashMap<>();
    AuditEvent last;
    for (ExpressionExperiment experiment : ees) {
        last = this.auditEventDao.getLastEvent(experiment, type.getClass());
        lastEventMap.put(experiment.getId(), last);
    }
    return lastEventMap;
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

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