Skip to content

Commit

Permalink
Add new event subclasses
Browse files Browse the repository at this point in the history
Add two abstract event types to easily identify events that affect the
needs attention and troubled flags.

Add new APIs for retrieving all the auditables that have an event of a
given type.

Use generic types.
  • Loading branch information
arteymix committed Jun 8, 2024
1 parent e6124b7 commit 5bfbd30
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Component;
import ubic.basecode.util.FileTools;
import ubic.gemma.model.common.auditAndSecurity.Auditable;
import ubic.gemma.core.config.Settings;
import ubic.gemma.model.common.auditAndSecurity.AuditEvent;
import ubic.gemma.model.common.auditAndSecurity.eventType.*;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject;
import ubic.gemma.persistence.service.common.auditAndSecurity.AuditEventService;
import ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService;
import ubic.gemma.persistence.util.EntityUtils;
import ubic.gemma.core.config.Settings;

import java.io.*;
import java.util.*;
Expand Down Expand Up @@ -287,14 +286,14 @@ public void fillEventInformation( Collection<ArrayDesignValueObject> adVos ) {

Map<Long, ArrayDesign> idMap = EntityUtils.getIdMap( arrayDesigns );

Map<Class<? extends AuditEventType>, Map<Auditable, AuditEvent>> events = auditEventService
Map<Class<? extends AuditEventType>, Map<ArrayDesign, AuditEvent>> events = auditEventService
.getLastEvents( arrayDesigns, typesToGet );

Map<Auditable, AuditEvent> geneMappingEvents = events.get( ArrayDesignGeneMappingEvent.class );
Map<Auditable, AuditEvent> sequenceUpdateEvents = events.get( ArrayDesignSequenceUpdateEvent.class );
Map<Auditable, AuditEvent> sequenceAnalysisEvents = events.get( ArrayDesignSequenceAnalysisEvent.class );
Map<Auditable, AuditEvent> repeatAnalysisEvents = events.get( ArrayDesignRepeatAnalysisEvent.class );
Map<Auditable, AuditEvent> creationEvents = auditEventService.getCreateEvents( arrayDesigns );
Map<ArrayDesign, AuditEvent> geneMappingEvents = events.get( ArrayDesignGeneMappingEvent.class );
Map<ArrayDesign, AuditEvent> sequenceUpdateEvents = events.get( ArrayDesignSequenceUpdateEvent.class );
Map<ArrayDesign, AuditEvent> sequenceAnalysisEvents = events.get( ArrayDesignSequenceAnalysisEvent.class );
Map<ArrayDesign, AuditEvent> repeatAnalysisEvents = events.get( ArrayDesignRepeatAnalysisEvent.class );
Map<ArrayDesign, AuditEvent> creationEvents = auditEventService.getCreateEvents( arrayDesigns );

for ( ArrayDesignValueObject adVo : adVos ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.springframework.transaction.annotation.Transactional;
import ubic.gemma.core.visualization.ExperimentalDesignVisualizationService;
import ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisValueObject;
import ubic.gemma.model.common.auditAndSecurity.Auditable;
import ubic.gemma.model.common.auditAndSecurity.AuditEvent;
import ubic.gemma.model.common.auditAndSecurity.Auditable;
import ubic.gemma.model.common.auditAndSecurity.eventType.*;
import ubic.gemma.model.expression.experiment.BatchEffectType;
import ubic.gemma.model.expression.experiment.ExpressionExperiment;
Expand Down Expand Up @@ -195,16 +195,16 @@ public void populateEventInformation( Collection<ExpressionExperimentDetailsValu
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<Class<? extends AuditEventType>, Map<ExpressionExperiment, 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<ExpressionExperiment, AuditEvent> linkAnalysisEvents = events.get( LinkAnalysisEvent.class );
Map<ExpressionExperiment, AuditEvent> missingValueAnalysisEvents = events.get( MissingValueAnalysisEvent.class );
Map<ExpressionExperiment, 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> batchMissingEvents = events.get( BatchInformationMissingEvent.class );
Map<Auditable, AuditEvent> pcaAnalysisEvents = events.get( PCAAnalysisEvent.class );
Map<ExpressionExperiment, AuditEvent> differentialAnalysisEvents = events.get( DifferentialExpressionAnalysisEvent.class );
Map<ExpressionExperiment, AuditEvent> batchFetchEvents = events.get( BatchInformationFetchingEvent.class );
Map<ExpressionExperiment, AuditEvent> batchMissingEvents = events.get( BatchInformationMissingEvent.class );
Map<ExpressionExperiment, AuditEvent> pcaAnalysisEvents = events.get( PCAAnalysisEvent.class );

Map<Long, Collection<AuditEvent>> sampleRemovalEvents = this.getSampleRemovalEvents( ees );

Expand Down Expand Up @@ -435,11 +435,9 @@ public void recalculateExperimentBatchInfo( ExpressionExperiment ee ) {
}
}

private Map<Class<? extends AuditEventType>, Map<Auditable, AuditEvent>> getEvents(
private Map<Class<? extends AuditEventType>, Map<ExpressionExperiment, AuditEvent>> getEvents(
Collection<ExpressionExperiment> ees, Collection<Class<? extends AuditEventType>> types ) {

return auditEventService.getLastEvents( ees, types );

}

private Map<Long, Collection<AuditEvent>> getSampleRemovalEvents( Collection<ExpressionExperiment> ees ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ private WhatsNew getReportAsAnonymousUser( Date date ) {
private WhatsNew getReport( Date date ) {
WhatsNew wn = new WhatsNew( date );

Collection<Auditable> updatedObjects = auditEventService.getUpdatedSinceDate( date );
Collection<Auditable> updatedObjects = new HashSet<>();
updatedObjects.addAll( auditEventService.getUpdatedSinceDate( ArrayDesign.class, date ) );
updatedObjects.addAll( auditEventService.getUpdatedSinceDate( ExpressionExperiment.class, date ) );
wn.setUpdatedObjects( updatedObjects );
WhatsNewServiceImpl.log.info( wn.getUpdatedObjects().size() + " updated objects since " + date );

Collection<Auditable> newObjects = auditEventService.getNewSinceDate( date );
Collection<Auditable> newObjects = new HashSet<>();
newObjects.addAll( auditEventService.getNewSinceDate( ArrayDesign.class, date ) );
newObjects.addAll( auditEventService.getNewSinceDate( ExpressionExperiment.class, date ) );
wn.setNewObjects( newObjects );
WhatsNewServiceImpl.log.info( wn.getNewObjects().size() + " new objects since " + date );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.core.context.SecurityContextHolder;
import ubic.gemma.core.util.BuildInfo;
import ubic.gemma.core.config.Settings;
import ubic.gemma.core.util.BuildInfo;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Paul
*/
public class DoesNotNeedAttentionEvent extends CurationDetailsEvent {
public class DoesNotNeedAttentionEvent extends NeedsAttentionAlteringEvent {

/**
* The serial version UID of this class. Needed for serialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ubic.gemma.model.common.auditAndSecurity.eventType;

import ubic.gemma.model.common.auditAndSecurity.curation.CurationDetails;

/**
* Base class for events altering {@link CurationDetails#getNeedsAttention()}.
*/
public abstract class NeedsAttentionAlteringEvent extends CurationDetailsEvent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Paul
*/
public class NeedsAttentionEvent extends CurationDetailsEvent {
public class NeedsAttentionEvent extends NeedsAttentionAlteringEvent {

/**
* The serial version UID of this class. Needed for serialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Paul
*/
public class NotTroubledStatusFlagEvent extends CurationDetailsEvent {
public class NotTroubledStatusFlagEvent extends TroubledStatusFlagAlteringEvent {

/**
* The serial version UID of this class. Needed for serialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ubic.gemma.model.common.auditAndSecurity.eventType;

import ubic.gemma.model.common.auditAndSecurity.curation.CurationDetails;

/**
* Base class for events that alter the {@link CurationDetails#getTroubled()} flag.
* @author poirigui
*/
public abstract class TroubledStatusFlagAlteringEvent extends CurationDetailsEvent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Paul
*/
public class TroubledStatusFlagEvent extends CurationDetailsEvent {
public class TroubledStatusFlagEvent extends TroubledStatusFlagAlteringEvent {

/**
* The serial version UID of this class. Needed for serialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package ubic.gemma.persistence.service.common.auditAndSecurity;

import ubic.gemma.model.common.auditAndSecurity.Auditable;
import ubic.gemma.model.common.auditAndSecurity.AuditEvent;
import ubic.gemma.model.common.auditAndSecurity.Auditable;
import ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType;
import ubic.gemma.persistence.service.BaseDao;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
Expand All @@ -35,47 +36,53 @@
public interface AuditEventDao extends BaseDao<AuditEvent> {

/**
* @param auditable auditable
* @return events for the given auditable.
* Obtain the audit events associated to a given auditable.
* <p>
* Events are sorted by date in ascending order.
*/
List<AuditEvent> getEvents( Auditable auditable );

/**
* @param auditable auditable
* @param type type
* @return the last AuditEvent of the specified type from the given auditable.
* Obtain the creation events for the given auditables.
* <p>
* If an auditable has more than one creation event (which is in itself a bug), the earliest one is returned.
*/
<T extends Auditable> Map<T, AuditEvent> getCreateEvents( Collection<T> auditables );

/**
* Obtain the latest event of a given type for a given auditable.
* @see #getLastEvent(Auditable, Class)
*/
@Nullable
AuditEvent getLastEvent( Auditable auditable, Class<? extends AuditEventType> type );

/**
* Obtain the latest {@link AuditEvent} of a specified type, excluding a certain number of types.
* Obtain the latest event of a given type, excluding a certain number of types.
* @param type type of event to retrieve, augmented by its hierarchy
* @param excludedTypes excluded event types (their hierarchy is also excluded)
*/
@Nullable
AuditEvent getLastEvent( Auditable auditable, Class<? extends AuditEventType> type, Collection<Class<? extends AuditEventType>> excludedTypes );

Map<Class<? extends AuditEventType>, Map<Auditable, AuditEvent>> getLastEventsByType(
Collection<? extends Auditable> auditables, Collection<Class<? extends AuditEventType>> types );

/**
* Get auditables that have been Created since the given date
*
* @param date date
* @return auditables
* Obtain the latest events of a specified type for all given auditables.
* @see #getLastEvent(Auditable, Class)
*/
Collection<Auditable> getNewSinceDate( Date date );
<T extends Auditable> Map<T, AuditEvent> getLastEvents( Collection<T> auditables, Class<? extends AuditEventType> type );

/**
* Get auditables that have been Updated since the given date
*
* @param date date
* @return auditables
* Obtain the latest events of a specified type for all auditable of a given type.
* @see #getLastEvent(Auditable, Class)
*/
Collection<Auditable> getUpdatedSinceDate( Date date );
<T extends Auditable> Map<T, AuditEvent> getLastEvents( Class<T> auditableClass, Class<? extends AuditEventType> type );

boolean hasEvent( Auditable a, Class<? extends AuditEventType> type );

void retainHavingEvent( Collection<? extends Auditable> a, Class<? extends AuditEventType> type );

void retainLackingEvent( Collection<? extends Auditable> a, Class<? extends AuditEventType> type );
/**
* Get auditables that have been created since the given date.
*/
<T extends Auditable> Collection<T> getNewSinceDate( Class<T> auditableClass, Date date );

Map<Auditable, AuditEvent> getCreateEvents( Collection<? extends Auditable> auditables );
/**
* Get auditables that have been updated since the given date.
*/
<T extends Auditable> Collection<T> getUpdatedSinceDate( Class<T> auditableClass, Date date );
}
Loading

0 comments on commit 5bfbd30

Please sign in to comment.