Search in sources :

Example 21 with AuditEventType

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

the class AuditControllerTest method testAddUpdateEvent.

@Test
public void testAddUpdateEvent() {
    ExpressionExperiment e = this.getTestPersistentExpressionExperiment();
    EntityDelegator ed = new EntityDelegator(e);
    assertEquals("ubic.gemma.model.expression.experiment.ExpressionExperiment", ed.getClassDelegatingFor());
    auditController.addAuditEvent(ed, "CommentedEvent", "foo", "bar");
    e = expressionExperimentService.load(e.getId());
    assertNotNull(e);
    e = expressionExperimentService.thawLite(e);
    assertNotNull(e);
    AuditTrail auditTrail = e.getAuditTrail();
    assertNotNull(auditTrail);
    AuditEvent lastEvent = auditTrail.getLast();
    assertNotNull(lastEvent);
    AuditEventType eventType = lastEvent.getEventType();
    assertNotNull(eventType);
    assertEquals(CommentedEvent.class, eventType.getClass());
}
Also used : AuditEventType(ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) AuditTrail(ubic.gemma.model.common.auditAndSecurity.AuditTrail) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) Test(org.junit.Test) BaseSpringWebTest(ubic.gemma.web.util.BaseSpringWebTest)

Example 22 with AuditEventType

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

the class AuditEventDaoImpl method getLastEvents.

@Override
public Map<Class<? extends AuditEventType>, Map<Auditable, AuditEvent>> getLastEvents(Collection<? extends Auditable> auditables, Collection<Class<? extends AuditEventType>> types) {
    StopWatch timer = new StopWatch();
    timer.start();
    Map<Class<? extends AuditEventType>, Map<Auditable, AuditEvent>> results = new HashMap<>();
    if (auditables.size() == 0)
        return results;
    for (Class<? extends AuditEventType> t : types) {
        results.put(t, new HashMap<Auditable, AuditEvent>());
    }
    final Map<AuditTrail, Auditable> atMap = this.getAuditTrailMap(auditables);
    List<String> classes = this.getClassHierarchy(types);
    // language=HQL
    final String queryString = "select et, trail, event from AuditTrailImpl trail " + "inner join trail.events event inner join event.eventType et inner join fetch event.performer where trail in (:trails) " + "and et.class in (:classes) order by event.date desc, event.id desc ";
    Query queryObject = this.getSessionFactory().getCurrentSession().createQuery(queryString);
    queryObject.setParameterList("trails", atMap.keySet());
    queryObject.setParameterList("classes", classes);
    List<?> qr = queryObject.list();
    for (Object o : qr) {
        Object[] ar = (Object[]) o;
        AuditEventType ty = (AuditEventType) ar[0];
        AuditTrail t = (AuditTrail) ar[1];
        AuditEvent e = (AuditEvent) ar[2];
        /*
             * This is a bit inefficient. Loop needed because returned type is Impl (and probably a proxy). But probably
             * query is the bottleneck.
             */
        for (Class<? extends AuditEventType> ti : types) {
            if (ti.isAssignableFrom(ty.getClass())) {
                Map<Auditable, AuditEvent> innerMap = results.get(ti);
                assert innerMap != null;
                // only replace event if its date is more recent.
                Auditable ae = atMap.get(t);
                if (!innerMap.containsKey(ae) || innerMap.get(ae).getDate().compareTo(e.getDate()) < 0) {
                    innerMap.put(atMap.get(t), e);
                }
                break;
            }
        }
    }
    timer.stop();
    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Last events retrieved for  " + types.size() + " different types for " + auditables.size() + " items in " + timer.getTime() + "ms");
    }
    return results;
}
Also used : Auditable(ubic.gemma.model.common.Auditable) AuditEventType(ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType) Query(org.hibernate.Query) StopWatch(org.apache.commons.lang3.time.StopWatch) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) AuditEventValueObject(ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject) AuditTrail(ubic.gemma.model.common.auditAndSecurity.AuditTrail)

Aggregations

AuditEventType (ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType)22 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)5 AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)3 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)3 AffyPowerToolsProbesetSummarize (ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize)2 AuditTrail (ubic.gemma.model.common.auditAndSecurity.AuditTrail)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 Taxon (ubic.gemma.model.genome.Taxon)2 AuditTrailService (ubic.gemma.persistence.service.common.auditAndSecurity.AuditTrailService)2 SecurityService (gemma.gsec.SecurityService)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Query (org.hibernate.Query)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)1 RawDataFetcher (ubic.gemma.core.loader.expression.geo.fetcher.RawDataFetcher)1 Auditable (ubic.gemma.model.common.Auditable)1 AuditEventValueObject (ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject)1