Search in sources :

Example 6 with AuditEvent

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

the class ArrayDesignServiceImpl method getMostRecentEvents.

private void getMostRecentEvents(Map<Long, Collection<AuditEvent>> eventMap, Map<Long, AuditEvent> lastEventMap, Set<Long> aaIds, Class<? extends ArrayDesignAnalysisEvent> eventclass) {
    for (Long arrayDesignId : aaIds) {
        Collection<AuditEvent> events = eventMap.get(arrayDesignId);
        AuditEvent lastEvent;
        if (events == null) {
            lastEventMap.put(arrayDesignId, null);
        } else {
            ArrayDesign ad = this.load(arrayDesignId);
            lastEvent = this.auditEventDao.getLastEvent(ad, eventclass);
            lastEventMap.put(arrayDesignId, lastEvent);
        }
        /*
             * Check if the subsuming or merged array (if any) was updated more recently. To do this: 1) load the AA; 2)
             * check for merged; check for subsumed; check events for those.
             */
        ArrayDesign arrayDesign = this.load(arrayDesignId);
        if (arrayDesign.getSubsumingArrayDesign() != null) {
            ArrayDesign subsumedInto = arrayDesign.getSubsumingArrayDesign();
            this.checkForMoreRecentMethod(lastEventMap, eventclass, arrayDesignId, subsumedInto);
        }
        if (arrayDesign.getMergedInto() != null) {
            ArrayDesign mergedInto = arrayDesign.getMergedInto();
            this.checkForMoreRecentMethod(lastEventMap, eventclass, arrayDesignId, mergedInto);
        }
    }
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 7 with AuditEvent

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

the class ExpressionExperimentDaoImpl method getSampleRemovalEvents.

@Override
public Map<ExpressionExperiment, Collection<AuditEvent>> getSampleRemovalEvents(Collection<ExpressionExperiment> expressionExperiments) {
    // language=HQL
    final String queryString = "select ee,ev from ExpressionExperiment ee inner join ee.bioAssays ba " + "inner join ba.auditTrail trail inner join trail.events ev inner join ev.eventType et " + "inner join fetch ev.performer where ee in (:ees) and et.class = 'SampleRemovalEvent'";
    Map<ExpressionExperiment, Collection<AuditEvent>> result = new HashMap<>();
    List r = this.getSessionFactory().getCurrentSession().createQuery(queryString).setParameterList("ees", expressionExperiments).list();
    for (Object o : r) {
        Object[] ol = (Object[]) o;
        ExpressionExperiment e = (ExpressionExperiment) ol[0];
        if (!result.containsKey(e)) {
            result.put(e, new HashSet<AuditEvent>());
        }
        AuditEvent ae = (AuditEvent) ol[1];
        result.get(e).add(ae);
    }
    return result;
}
Also used : ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 8 with AuditEvent

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

the class AuditEventDaoImpl method getLastEvent.

private AuditEvent getLastEvent(final AuditTrail auditTrail, Class<? extends AuditEventType> type) {
    /*
         * For the = operator to work in hibernate the class or class name can't be passed in as a parameter :type -
         * also queryObject.setParameter("type", type.getClass()); doesn't work. Although technically this is now
         * vulnerable to an sql injection attack, it seems moot as an attacker would have to have access to the JVM to
         * inject a malformed AuditEventType class name and if they had access to the JVM then sql injection is the
         * least of our worries. The real annoyance here is dealing with subclasses of event types.
         */
    List<String> classes = this.getClassHierarchy(type);
    if (classes.size() == 0) {
        return null;
    }
    // language=HQL
    final String queryString = "select event from AuditTrailImpl trail " + "inner join trail.events event inner join event.eventType et inner join fetch event.performer " + "fetch all properties where trail = :trail and et.class in (:classes) " + "order by event.date,event.id desc ";
    org.hibernate.Query queryObject = this.getSessionFactory().getCurrentSession().createQuery(queryString);
    queryObject.setCacheable(true);
    queryObject.setReadOnly(true);
    queryObject.setParameter("trail", auditTrail);
    queryObject.setParameterList("classes", classes);
    queryObject.setMaxResults(1);
    // noinspection unchecked
    Collection<AuditEvent> results = queryObject.list();
    if (results == null || results.isEmpty())
        return null;
    AuditEvent result = results.iterator().next();
    // Hit performer to make hibernate initialize it.
    Hibernate.initialize(result.getPerformer());
    return result;
}
Also used : Query(org.hibernate.Query) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 9 with AuditEvent

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

the class AuditEventDaoImpl method putAllQrs.

private void putAllQrs(Map<Auditable, AuditEvent> result, List<?> qr, Map<AuditTrail, Auditable> atMap) {
    for (Object o : qr) {
        Object[] ar = (Object[]) o;
        AuditTrail t = (AuditTrail) ar[0];
        AuditEvent e = (AuditEvent) ar[1];
        // only one event per object, please - the most recent.
        if (result.containsKey(atMap.get(t)))
            continue;
        result.put(atMap.get(t), e);
    }
}
Also used : AuditEventValueObject(ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) AuditTrail(ubic.gemma.model.common.auditAndSecurity.AuditTrail)

Example 10 with AuditEvent

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

the class TableMaintenanceUtilImpl method updateGene2CsEntries.

@Override
@Transactional
public synchronized void updateGene2CsEntries() {
    if (TableMaintenanceUtilImpl.running.get())
        return;
    TableMaintenanceUtilImpl.log.debug("Running Gene2CS status check");
    String annotation = "";
    try {
        TableMaintenanceUtilImpl.running.set(true);
        Gene2CsStatus status = this.getLastGene2CsUpdateStatus();
        boolean needToRefresh = false;
        if (status == null) {
            needToRefresh = true;
        }
        if (!needToRefresh) {
            Collection<Auditable> newObj = auditEventService.getNewSinceDate(status.getLastUpdate());
            for (Auditable a : newObj) {
                if (a instanceof ArrayDesign) {
                    needToRefresh = true;
                    annotation = a + " is new since " + status.getLastUpdate();
                    TableMaintenanceUtilImpl.log.debug(annotation);
                    break;
                }
            }
        }
        if (!needToRefresh) {
            Collection<Auditable> updatedObj = auditEventService.getUpdatedSinceDate(status.getLastUpdate());
            for (Auditable a : updatedObj) {
                if (a instanceof ArrayDesign) {
                    for (AuditEvent ae : auditEventService.getEvents(a)) {
                        if (ae == null)
                            // legacy of ordered-list which could end up with gaps; should
                            continue;
                        // not be needed any more
                        if (ae.getEventType() != null && ae.getEventType() instanceof ArrayDesignGeneMappingEvent && ae.getDate().after(status.getLastUpdate())) {
                            needToRefresh = true;
                            annotation = a + " had probe mapping done since: " + status.getLastUpdate();
                            TableMaintenanceUtilImpl.log.debug(annotation);
                            break;
                        }
                    }
                }
                if (needToRefresh)
                    break;
            }
        }
        if (needToRefresh) {
            TableMaintenanceUtilImpl.log.debug("Update of GENE2CS initiated");
            this.generateGene2CsEntries();
            Gene2CsStatus updatedStatus = this.writeUpdateStatus(annotation, null);
            this.sendEmail(updatedStatus);
        } else {
            TableMaintenanceUtilImpl.log.debug("No update of GENE2CS needed");
        }
    } catch (Exception e) {
        try {
            TableMaintenanceUtilImpl.log.info("Error during attempt to check status or update GENE2CS", e);
            Gene2CsStatus updatedStatus = this.writeUpdateStatus(annotation, e);
            this.sendEmail(updatedStatus);
        } catch (IOException e1) {
            throw new RuntimeException(e1);
        }
    } finally {
        TableMaintenanceUtilImpl.running.set(false);
    }
}
Also used : Auditable(ubic.gemma.model.common.Auditable) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Gene2CsStatus(ubic.gemma.persistence.model.Gene2CsStatus) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) ArrayDesignGeneMappingEvent(ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignGeneMappingEvent) Transactional(org.springframework.transaction.annotation.Transactional)

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