Search in sources :

Example 1 with Curatable

use of ubic.gemma.model.common.auditAndSecurity.curation.Curatable 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 2 with Curatable

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

the class AuditTrailServiceImpl method addUpdateEvent.

/**
 * This method creates a new event in the audit trail of the passed Auditable object. If this object also implements
 * the {@link Curatable} interface, and the passed auditEventType is one of the extensions of
 * {@link CurationDetailsEvent} AuditEventType, this method will pass its result to
 * {@link CurationDetailsService#update(Curatable, AuditEvent)}, to update the curatable objects curation details,
 * before returning it.
 *
 * @param auditable      the auditable object to whose audit trail should a new event be added.
 * @param auditEventType the type of the event that should be created.
 * @param note           string displayed as a note for the event
 * @param detail         detailed description of the event.
 * @return the new AuditEvent that was created in the audit trail of the given auditable object.
 * @see AuditTrailService#addUpdateEvent(Auditable, AuditEventType, String, String)
 */
@Override
@Transactional
public AuditEvent addUpdateEvent(final Auditable auditable, final AuditEventType auditEventType, final String note, final String detail) {
    // Create new audit event
    AuditEvent auditEvent = AuditEvent.Factory.newInstance(new Date(), AuditAction.UPDATE, note, detail, null, auditEventType);
    auditEvent = this.auditTrailDao.addEvent(auditable, auditEvent);
    // If object is curatable, update curation details
    if (auditable instanceof Curatable && auditEvent != null && auditEvent.getEventType() != null) {
        curationDetailsService.update((Curatable) auditable, auditEvent);
    }
    // return the newly created event
    return auditEvent;
}
Also used : Curatable(ubic.gemma.model.common.auditAndSecurity.curation.Curatable) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Date (java.util.Date)2 AuditEvent (ubic.gemma.model.common.auditAndSecurity.AuditEvent)2 Curatable (ubic.gemma.model.common.auditAndSecurity.curation.Curatable)2 Transactional (org.springframework.transaction.annotation.Transactional)1 AuditEventType (ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 ExpressionExperimentService (ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService)1