Search in sources :

Example 6 with Auditable

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

the class AuditEventDaoImplTest method testHandleGetNewSinceDate.

@Test
public void testHandleGetNewSinceDate() {
    Calendar c = Calendar.getInstance();
    c.set(2006, Calendar.DECEMBER, 1);
    Date d = c.getTime();
    Collection<Auditable> objs = auditEventService.getNewSinceDate(d);
    assertTrue(objs.size() > 0);
// for ( AbstractAuditable auditable : objs ) {
// if ( objs instanceof ArrayDesign ) {
// }
// }
}
Also used : Auditable(ubic.gemma.model.common.Auditable) Calendar(java.util.Calendar) Date(java.util.Date) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 7 with Auditable

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

the class WhatsNewServiceImpl method retrieveReport.

/**
 * Retrieve the latest WhatsNew report.
 *
 * @return WhatsNew the latest WhatsNew report cache.
 */
@Override
public WhatsNew retrieveReport() {
    WhatsNew wn = new WhatsNew();
    try {
        File newObjects = new File(HOME_DIR + File.separatorChar + WhatsNewServiceImpl.WHATS_NEW_DIR + File.separatorChar + WhatsNewServiceImpl.WHATS_NEW_FILE + ".new");
        File updatedObjects = new File(HOME_DIR + File.separatorChar + WhatsNewServiceImpl.WHATS_NEW_DIR + File.separatorChar + WhatsNewServiceImpl.WHATS_NEW_FILE + ".updated");
        if (!newObjects.exists() && !updatedObjects.exists()) {
            return null;
        }
        // load up all new objects
        if (newObjects.exists()) {
            Collection<AuditableObject> aos = this.loadAuditableObjects(newObjects);
            for (AuditableObject object : aos) {
                Auditable auditable = this.fetch(object);
                if (auditable == null)
                    continue;
                wn.addNewObjects(auditable);
                this.updateDate(wn, object);
            }
        }
        // load up all updated objects
        if (updatedObjects.exists()) {
            Collection<AuditableObject> aos = this.loadAuditableObjects(updatedObjects);
            for (AuditableObject object : aos) {
                /*
                     * This call takes ~ 15-20 ms but it can be called many times if there are a lot of updated
                     * experiments, meaning this loop can take >8500 ms (over tunnel for ~450 experiments).
                     *
                     * Loading objects could be avoided since we only need ids on the front end, but we would need to
                     * refactor the cache, because object-type is used to calculate counts for updated array design
                     * objects vs updated experiments
                     *
                     * This is probably not necessary because usually the number of updated or new experiments will be
                     * much lower than 450.
                     */
                Auditable auditable = this.fetch(object);
                if (auditable == null)
                    continue;
                wn.addUpdatedObjects(auditable);
                this.updateDate(wn, object);
            }
        }
        // build total, new and updated counts by taxon to display in data summary widget on front page
        wn.setNewEEIdsPerTaxon(this.getExpressionExperimentIdsByTaxon(wn.getNewExpressionExperiments()));
        wn.setUpdatedEEIdsPerTaxon(this.getExpressionExperimentIdsByTaxon(wn.getUpdatedExpressionExperiments()));
    } catch (Throwable e) {
        WhatsNewServiceImpl.log.error(e, e);
        return null;
    }
    return wn;
}
Also used : Auditable(ubic.gemma.model.common.Auditable)

Example 8 with Auditable

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

the class WhatsNewServiceImpl method fetch.

private Auditable fetch(AuditableObject object) {
    if (object == null)
        return null;
    Auditable auditable = null;
    Element element = this.whatsNewCache.get(object);
    if (object.type.equalsIgnoreCase("ArrayDesign")) {
        if (element != null) {
            auditable = (Auditable) element.getObjectValue();
        } else {
            try {
                auditable = arrayDesignService.load(object.getId());
            } catch (AccessDeniedException e) {
                return null;
            }
            whatsNewCache.put(new Element(object, auditable));
        }
    } else if (object.type.equalsIgnoreCase("ExpressionExperiment")) {
        if (element != null) {
            auditable = (Auditable) element.getObjectValue();
        } else {
            try {
                auditable = expressionExperimentService.load(object.getId());
            } catch (AccessDeniedException e) {
                return null;
            }
            if (auditable == null) {
                return null;
            }
            whatsNewCache.put(new Element(object, auditable));
        }
    }
    return auditable;
}
Also used : Auditable(ubic.gemma.model.common.Auditable) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Element(net.sf.ehcache.Element)

Example 9 with Auditable

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

the class PersisterHelper method persist.

@Override
@Transactional
public Object persist(Object entity) {
    try {
        this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.COMMIT);
        if (entity instanceof Auditable) {
            Auditable auditable = (Auditable) entity;
            if (auditable.getAuditTrail() == null) {
                auditable.setAuditTrail(AuditTrail.Factory.newInstance());
            }
            auditable.setAuditTrail(persistAuditTrail(auditable.getAuditTrail()));
        }
        return super.persist(entity);
    } finally {
        this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
    }
}
Also used : Auditable(ubic.gemma.model.common.Auditable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Auditable

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

the class AuditEventDaoImpl method retainLackingEvent.

@Override
public void retainLackingEvent(final Collection<? extends Auditable> a, final Class<? extends AuditEventType> type) {
    StopWatch timer = new StopWatch();
    timer.start();
    final Map<Auditable, AuditEvent> events = this.getLastEvent(a, type);
    AbstractDao.log.info("Phase I: " + timer.getTime() + "ms");
    CollectionUtils.filter(a, new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            // noinspection SuspiciousMethodCalls // this is perfectly fine since we are passing this directly into the filter
            return !events.containsKey(arg0);
        }
    });
}
Also used : Auditable(ubic.gemma.model.common.Auditable) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) AuditEventValueObject(ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Predicate(org.apache.commons.collections.Predicate)

Aggregations

Auditable (ubic.gemma.model.common.Auditable)15 AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)9 StopWatch (org.apache.commons.lang3.time.StopWatch)6 AuditEventValueObject (ubic.gemma.model.common.auditAndSecurity.AuditEventValueObject)5 AuditTrail (ubic.gemma.model.common.auditAndSecurity.AuditTrail)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Predicate (org.apache.commons.collections.Predicate)2 Query (org.hibernate.Query)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)2 HashSet (java.util.HashSet)1 Element (net.sf.ehcache.Element)1 HibernateProxy (org.hibernate.proxy.HibernateProxy)1 HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 AbstractAuditable (ubic.gemma.model.common.AbstractAuditable)1 ArrayDesignGeneMappingEvent (ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignGeneMappingEvent)1