Search in sources :

Example 1 with AuditEvent

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

the class SearchServiceImpl method searchForNewlyCreatedUserQueryResults.

@Override
public Map<Class<?>, List<SearchResult>> searchForNewlyCreatedUserQueryResults(UserQuery query) {
    Map<Class<?>, List<SearchResult>> searchResults;
    Map<Class<?>, List<SearchResult>> finalResults = new HashMap<>();
    SearchSettings settings = query.getSearchSettings();
    if (StringUtils.isBlank(settings.getTermUri()) && !settings.getQuery().startsWith("http://")) {
        // fill objects=true, speedySearch=false
        searchResults = this.generalSearch(settings, true, false);
    } else {
        // we only attempt an ontology search if the uri looks remotely like a url.
        searchResults = this.ontologyUriSearch(settings);
    }
    if (searchResults == null) {
        return finalResults;
    }
    for (Class<?> clazz : searchResults.keySet()) {
        List<SearchResult> results = searchResults.get(clazz);
        List<SearchResult> updatedResults = new ArrayList<>();
        if (results.size() == 0)
            continue;
        SearchServiceImpl.log.info("Search for newly createdQuery with settings: " + settings + "; result: " + results.size() + " " + clazz.getSimpleName() + "s");
        for (SearchResult sr : results) {
            // Are SearchResults always auditable? maybe put in some error handling in case they are not or
            // enforce searchSettings object to be of a certain form
            Auditable auditableResult = (Auditable) sr.getResultObject();
            // this list is ordered by date (not descending)
            List<AuditEvent> eventList = auditTrailService.getEvents(auditableResult);
            if (eventList == null || eventList.isEmpty())
                continue;
            for (AuditEvent ae : eventList) {
                // assuming there is only one create event
                if (ae.getAction() == AuditAction.CREATE && ae.getDate().after(query.getLastUsed())) {
                    updatedResults.add(sr);
                    break;
                }
            }
        }
        if (!updatedResults.isEmpty()) {
            finalResults.put(clazz, updatedResults);
        }
    }
    return finalResults;
}
Also used : Auditable(ubic.gemma.model.common.Auditable) SearchSettings(ubic.gemma.model.common.search.SearchSettings) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 2 with AuditEvent

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

the class AuditAdviceTest method testCascadingCreateOnUpdate.

@Test
public void testCascadingCreateOnUpdate() {
    ExpressionExperiment ee = this.getTestPersistentCompleteExpressionExperiment(false);
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    // should have create only
    assertEquals(1, ee.getAuditTrail().getEvents().size());
    BioAssay ba = BioAssay.Factory.newInstance();
    String name = RandomStringUtils.randomAlphabetic(20);
    ba.setName(name);
    ba.setArrayDesignUsed(ee.getBioAssays().iterator().next().getArrayDesignUsed());
    ee.getBioAssays().add(ba);
    this.expressionExperimentService.update(ee);
    assertNotNull(ee.getAuditTrail());
    // should have create and 1 updates
    assertEquals(2, ee.getAuditTrail().getEvents().size());
    Session session = sessionFactory.openSession();
    session.update(ee);
    for (BioAssay bioa : ee.getBioAssays()) {
        assertNotNull(bioa.getAuditTrail());
        Collection<AuditEvent> events = bioa.getAuditTrail().getEvents();
        assertEquals(1, events.size());
        for (AuditEvent e : events) {
            assertNotNull(e.getId());
            assertNotNull(e.getAction());
        }
    }
    session.close();
    this.expressionExperimentService.update(ee);
    this.expressionExperimentService.update(ee);
    this.expressionExperimentService.update(ee);
    assertEquals(5, ee.getAuditTrail().getEvents().size());
    /*
         * Check we didn't get any extra events added to children.
         */
    for (BioAssay prod : ee.getBioAssays()) {
        assertEquals(1, prod.getAuditTrail().getEvents().size());
    }
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Session(org.hibernate.Session) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 3 with AuditEvent

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

the class ExpressionExperimentReportServiceImpl method populateEventInformation.

/**
 * Fills in event and security information from the database. This will only retrieve the latest event (if any).
 * This is rather slow so should be avoided if the information isn't needed.
 */
@Override
public void populateEventInformation(Collection<ExpressionExperimentDetailsValueObject> vos) {
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<Long> ids = EntityUtils.getIds(vos);
    // do this ahead to avoid round trips - this also filters...
    Collection<ExpressionExperiment> ees = expressionExperimentService.load(ids);
    if (ees.size() == 0) {
        return;
    }
    Map<Long, ExpressionExperiment> eeMap = EntityUtils.getIdMap(ees);
    Map<Long, Date> lastArrayDesignUpdates = expressionExperimentService.getLastArrayDesignUpdate(ees);
    Collection<Class<? extends AuditEventType>> typesToGet = Arrays.asList(eventTypes);
    Map<Class<? extends AuditEventType>, Map<Auditable, AuditEvent>> events = this.getEvents(ees, typesToGet);
    Map<Auditable, AuditEvent> linkAnalysisEvents = events.get(LinkAnalysisEvent.class);
    Map<Auditable, AuditEvent> missingValueAnalysisEvents = events.get(MissingValueAnalysisEvent.class);
    Map<Auditable, AuditEvent> rankComputationEvents = events.get(ProcessedVectorComputationEvent.class);
    Map<Auditable, AuditEvent> differentialAnalysisEvents = events.get(DifferentialExpressionAnalysisEvent.class);
    Map<Auditable, AuditEvent> batchFetchEvents = events.get(BatchInformationFetchingEvent.class);
    Map<Auditable, AuditEvent> pcaAnalysisEvents = events.get(PCAAnalysisEvent.class);
    Map<Long, Collection<AuditEvent>> sampleRemovalEvents = this.getSampleRemovalEvents(ees);
    /*
         * add in the last events of interest for all eeVos This step is remarkably slow.
         */
    for (ExpressionExperimentDetailsValueObject eeVo : vos) {
        Long id = eeVo.getId();
        ExpressionExperiment ee = eeMap.get(id);
        if (linkAnalysisEvents.containsKey(ee)) {
            AuditEvent event = linkAnalysisEvents.get(ee);
            if (event != null) {
                Date date = event.getDate();
                eeVo.setDateLinkAnalysis(date);
                eeVo.setLinkAnalysisEventType(event.getEventType().getClass().getSimpleName());
            }
        }
        if (missingValueAnalysisEvents.containsKey(ee)) {
            AuditEvent event = missingValueAnalysisEvents.get(ee);
            if (event != null) {
                Date date = event.getDate();
                eeVo.setDateMissingValueAnalysis(date);
                eeVo.setMissingValueAnalysisEventType(event.getEventType().getClass().getSimpleName());
            }
        }
        if (rankComputationEvents.containsKey(ee)) {
            AuditEvent event = rankComputationEvents.get(ee);
            if (event != null) {
                Date date = event.getDate();
                eeVo.setDateProcessedDataVectorComputation(date);
                eeVo.setProcessedDataVectorComputationEventType(event.getEventType().getClass().getSimpleName());
            }
        }
        if (differentialAnalysisEvents.containsKey(ee)) {
            AuditEvent event = differentialAnalysisEvents.get(ee);
            if (event != null) {
                Date date = event.getDate();
                eeVo.setDateDifferentialAnalysis(date);
            }
        }
        if (pcaAnalysisEvents.containsKey(ee)) {
            AuditEvent event = pcaAnalysisEvents.get(ee);
            if (event != null) {
                Date date = event.getDate();
                eeVo.setDatePcaAnalysis(date);
                eeVo.setPcaAnalysisEventType(event.getEventType().getClass().getSimpleName());
            }
        }
        if (batchFetchEvents.containsKey(ee)) {
            AuditEvent event = batchFetchEvents.get(ee);
            if (event != null) {
                Date date = event.getDate();
                eeVo.setDateBatchFetch(date);
                eeVo.setBatchFetchEventType(event.getEventType().getClass().getSimpleName());
            }
        }
        if (lastArrayDesignUpdates.containsKey(id)) {
            Date date = lastArrayDesignUpdates.get(id);
            eeVo.setDateArrayDesignLastUpdated(date);
        }
        if (sampleRemovalEvents.containsKey(id)) {
            Collection<AuditEvent> removalEvents = sampleRemovalEvents.get(id);
            // we find we are getting lazy-load exceptions from this guy.
            eeVo.auditEvents2SampleRemovedFlags(removalEvents);
        }
    }
    if (timer.getTime() > 1000)
        log.info("Retrieving audit events took " + timer.getTime() + "ms");
}
Also used : Auditable(ubic.gemma.model.common.Auditable) ExpressionExperimentDetailsValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) StopWatch(org.apache.commons.lang3.time.StopWatch) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 4 with AuditEvent

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

the class ArrayDesignProbeMapperCli method needToRun.

/**
 * Override to do additional checks to make sure the array design is in a state of readiness for probe mapping.
 */
@Override
boolean needToRun(Date skipIfLastRunLaterThan, ArrayDesign arrayDesign, Class<? extends ArrayDesignAnalysisEvent> eventClass) {
    if (this.hasOption("force")) {
        return true;
    }
    if (this.directAnnotationInputFileName != null) {
        return true;
    }
    arrayDesign = arrayDesignService.thawLite(arrayDesign);
    /*
         * Do not run this on "Generic" platforms or those which are loaded using a direct annotation input file!
         */
    if (arrayDesign.getTechnologyType().equals(TechnologyType.NONE) || !(arrayDesign.getTechnologyType().equals(TechnologyType.DUALMODE) || arrayDesign.getTechnologyType().equals(TechnologyType.ONECOLOR) || arrayDesign.getTechnologyType().equals(TechnologyType.TWOCOLOR))) {
        AbstractCLI.log.info("Skipping because it is not a microarray platform");
        return false;
    }
    if (!super.needToRun(skipIfLastRunLaterThan, arrayDesign, eventClass)) {
        return false;
    }
    AbstractCLI.log.debug("Re-Checking status of " + arrayDesign);
    List<AuditEvent> allEvents = this.auditTrailService.getEvents(arrayDesign);
    AuditEvent lastSequenceAnalysis = null;
    AuditEvent lastRepeatMask = null;
    AuditEvent lastSequenceUpdate = null;
    AuditEvent lastProbeMapping = null;
    AbstractCLI.log.debug(allEvents.size() + " to inspect");
    for (int j = allEvents.size() - 1; j >= 0; j--) {
        AuditEvent currentEvent = allEvents.get(j);
        if (currentEvent == null)
            // legacy of ordered-list which could end up with gaps; should not be
            continue;
        // needed any more
        if (currentEvent.getEventType() == null)
            continue;
        // we only care about ArrayDesignAnalysisEvent events.
        Class<? extends AuditEventType> currentEventClass = currentEvent.getEventType().getClass();
        AbstractCLI.log.debug("Inspecting: " + currentEventClass);
        // Get the most recent event of each type.
        if (lastRepeatMask == null && ArrayDesignRepeatAnalysisEvent.class.isAssignableFrom(currentEventClass)) {
            lastRepeatMask = currentEvent;
            AbstractCLI.log.debug("Last repeat mask: " + lastRepeatMask.getDate());
        } else if (lastSequenceUpdate == null && ArrayDesignSequenceUpdateEvent.class.isAssignableFrom(currentEventClass)) {
            lastSequenceUpdate = currentEvent;
            AbstractCLI.log.debug("Last sequence update: " + lastSequenceUpdate.getDate());
        } else if (lastSequenceAnalysis == null && ArrayDesignSequenceAnalysisEvent.class.isAssignableFrom(currentEventClass)) {
            lastSequenceAnalysis = currentEvent;
            AbstractCLI.log.debug("Last sequence analysis: " + lastSequenceAnalysis.getDate());
        } else if (lastProbeMapping == null && ArrayDesignGeneMappingEvent.class.isAssignableFrom(currentEventClass)) {
            lastProbeMapping = currentEvent;
            AbstractCLI.log.info("Last probe mapping analysis: " + lastProbeMapping.getDate());
        }
    }
    /*
         *
         * The issue addressed here is that we don't normally run sequence analysis etc. on merged platforms either, so
         * it looks like they are not ready for probemapping.
         */
    boolean isNotMerged = arrayDesign.getMergees().isEmpty();
    /*
         * make sure the last repeat mask and sequence analysis were done after the last sequence update. This is a
         * check that is not done by the default 'needToRun' implementation. Note that Repeatmasking can be done in any
         * order w.r.t. the sequence analysis, so we don't need to check that order.
         */
    if (isNotMerged && lastSequenceUpdate != null) {
        if (lastRepeatMask != null && lastSequenceUpdate.getDate().after(lastRepeatMask.getDate())) {
            AbstractCLI.log.warn(arrayDesign + ": Sequences were updated more recently than the last repeat masking");
            return false;
        }
        if (lastSequenceAnalysis != null && lastSequenceUpdate.getDate().after(lastSequenceAnalysis.getDate())) {
            AbstractCLI.log.warn(arrayDesign + ": Sequences were updated more recently than the last sequence analysis");
            return false;
        }
    }
    if (isNotMerged && lastSequenceAnalysis == null) {
        AbstractCLI.log.warn(arrayDesign + ": Must do sequence analysis before probe mapping");
        // We return false because we're not in a state to run it.
        return false;
    }
    if (isNotMerged && lastRepeatMask == null) {
        AbstractCLI.log.warn(arrayDesign + ": Must do repeat mask analysis before probe mapping");
        return false;
    }
    if (skipIfLastRunLaterThan != null && lastProbeMapping != null && lastProbeMapping.getDate().after(skipIfLastRunLaterThan)) {
        AbstractCLI.log.info(arrayDesign + " was probemapped since " + skipIfLastRunLaterThan + ", skipping.");
        return false;
    }
    // we've validated the super.needToRun result, so we pass it on.
    return true;
}
Also used : AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent)

Example 5 with AuditEvent

use of ubic.gemma.model.common.auditAndSecurity.AuditEvent 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)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