Search in sources :

Example 1 with ArrayDesignAnalysisEvent

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

the class ArrayDesignSequenceManipulatingCli method needToAutoRun.

/**
 * Find if the most recent ArrayDesignAnalysisEvent is less recent than the _other_ types of array design events; if
 * so, then we need to refresh it.
 * <ul>
 * <li>If the autoseek option is not turned on, then return false.
 * <li>If the event has never been done, return true.
 * <li>If the last event was of the passed eventClass, then return false.
 * <li>If any other ArrayDesignAnalysisEvent was more recent than the last event of eventClass, return true.
 * <li>Otherwise return false.
 * </ul>
 *
 * @param eventClass The type of event we are considering running on the basis of this call.
 * @return whether the array design needs updating based on the criteria outlined above.
 */
private boolean needToAutoRun(ArrayDesign arrayDesign, Class<? extends ArrayDesignAnalysisEvent> eventClass) {
    if (!autoSeek)
        return false;
    List<AuditEvent> eventsOfCurrentType = this.getEvents(arrayDesign, eventClass);
    List<AuditEvent> allEvents = (List<AuditEvent>) arrayDesign.getAuditTrail().getEvents();
    if (eventsOfCurrentType.size() == 0) {
        // it's never been run.
        return true;
    }
    AuditEvent lastEventOfCurrentType = eventsOfCurrentType.get(eventsOfCurrentType.size() - 1);
    assert lastEventOfCurrentType != null;
    if (lastEventOfCurrentType.getEventType().getClass().isAssignableFrom(eventClass)) {
        // then definitely don't run it. The last event was the same as the one we're trying to renew.
        AbstractCLI.log.debug("Last event on " + arrayDesign + " was also a " + eventClass + ", skipping.");
        return false;
    }
    for (AuditEvent currentEvent : allEvents) {
        if (currentEvent == null)
            // legacy of ordered-list which could end up with gaps; should not be
            continue;
        if (currentEvent.getEventType() == null || currentEvent.getEventType().getClass().equals(eventClass)) {
            continue;
        }
        Class<? extends AuditEventType> currentEventClass = currentEvent.getEventType().getClass();
        // we only care about ArrayDesignAnalysisEvent events.
        if (!ArrayDesignAnalysisEvent.class.isAssignableFrom(currentEventClass)) {
            AbstractCLI.log.debug(currentEventClass.getSimpleName() + " is not of interest");
            continue;
        }
        if (currentEvent.getDate().after(lastEventOfCurrentType.getDate())) {
            AbstractCLI.log.info(arrayDesign + " needs update, last " + eventClass.getSimpleName() + " was before last " + currentEvent.getEventType().getClass().getSimpleName());
            return true;
        }
        AbstractCLI.log.debug(arrayDesign + " " + eventClass.getSimpleName() + " was after last " + currentEvent.getEventType().getClass().getSimpleName() + " (OK)");
    }
    AbstractCLI.log.info(arrayDesign + " does not need an update");
    return false;
}
Also used : ArrayDesignAnalysisEvent(ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignAnalysisEvent) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Aggregations

AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)1 ArrayDesignAnalysisEvent (ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignAnalysisEvent)1