diff --git a/Core/src/org/sleuthkit/autopsy/timeline/events/EventAddedEvent.java b/Core/src/org/sleuthkit/autopsy/timeline/events/EventAddedEvent.java index d12069c8cb..ba5b9a1d2f 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/events/EventAddedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/events/EventAddedEvent.java @@ -18,22 +18,76 @@ */ package org.sleuthkit.autopsy.timeline.events; +import java.io.Serializable; +import java.util.logging.Level; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; +import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.timeline.TimelineEvent; /** - * + * An AutopsyEvent broadcast when a TimelineEvent is added to the case. */ -public class EventAddedEvent extends AutopsyEvent { - - private final long addedEventID; +public class EventAddedEvent extends AutopsyEvent implements Serializable { - public long getAddedEventID() { - return addedEventID; - } + private static final long serialVersionUID = 1L; + private static final Logger logger = Logger.getLogger(EventAddedEvent.class.getName()); + + private transient TimelineEvent addedEvent; public EventAddedEvent(org.sleuthkit.datamodel.TimelineManager.EventAddedEvent event) { - super(Case.Events.EVENT_ADDED.name(), null, event.getEvent()); - addedEventID = event.getEvent().getEventID(); + super(Case.Events.EVENT_ADDED.name(), null, event.getAddedEvent().getEventID()); + addedEvent = event.getAddedEvent(); + } + + /** + * Gets the TimelineEvent that was added. + * + * @return The TimelineEvent or null if there is an error retrieving the + * TimelineEvent. + */ + @Override + public TimelineEvent getNewValue() { + /** + * The addedEvent field is set in the constructor, but it is transient + * so it will become null when the event is serialized for publication + * over a network. Doing a lazy load of the TimelineEvent object + * bypasses the issues related to the serialization and de-serialization + * of TimelineEvent objects and may also save database round trips from + * other nodes since subscribers to this event are often not interested + * in the event data. + */ + if (null != addedEvent) { + return addedEvent; + } + try { + Long addedEventID = (Long) super.getNewValue(); + addedEvent = Case.getCurrentCaseThrows().getSleuthkitCase().getTimelineManager().getEventById(addedEventID); + return addedEvent; + } catch (NoCurrentCaseException | TskCoreException ex) { + logger.log(Level.SEVERE, "Error doing lazy load for remote event", ex); //NON-NLS + return null; + } + } + + /** + * Gets the TimelineEvent that was added. + * + * @return The TimelineEvent or null if there is an error retrieving the + * TimelineEvent. + */ + public TimelineEvent getAddedEvent() { + return getNewValue(); + } + + /** + * Gets the Id of the event that was added. + * + * @return The Id of the event that was added. + */ + public long getAddedEventID() { + return (long) super.getNewValue(); } } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/utils/FilterUtils.java b/Core/src/org/sleuthkit/autopsy/timeline/utils/FilterUtils.java index 0e6ff39d35..2e81aa4be1 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/utils/FilterUtils.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/utils/FilterUtils.java @@ -18,12 +18,10 @@ */ package org.sleuthkit.autopsy.timeline.utils; -import com.google.common.net.MediaType; +import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.openide.util.NbBundle; import org.sleuthkit.datamodel.TimelineManager; import org.sleuthkit.datamodel.timeline.TimelineFilter.FileTypeFilter; @@ -34,16 +32,16 @@ import org.sleuthkit.datamodel.timeline.TimelineFilter.FileTypesFilter; */ public final class FilterUtils { - private static final Set MEDIA_MIME_TYPES = Stream.of( + private static final Set MEDIA_MIME_TYPES = ImmutableSet.of( "image/*",//NON-NLS "video/*",//NON-NLS "audio/*",//NON-NLS "application/vnd.ms-asf", //NON-NLS "application/vnd.rn-realmedia", //NON-NLS "application/x-shockwave-flash" //NON-NLS - ).map(MediaType::parse).collect(Collectors.toSet()); + ); - private static final Set EXECUTABLE_MIME_TYPES = Stream.of( + private static final Set EXECUTABLE_MIME_TYPES = ImmutableSet.of( "application/x-bat",//NON-NLS "application/x-dosexec",//NON-NLS "application/vnd.microsoft.portable-executable",//NON-NLS @@ -55,9 +53,9 @@ public final class FilterUtils { "application/x-winexe",//NON-NLS "application/msdos-windows",//NON-NLS "application/x-msdos-program"//NON-NLS - ).map(MediaType::parse).collect(Collectors.toSet()); + ); - private static final Set DOCUMENT_MIME_TYPES = Stream.of( + private static final Set DOCUMENT_MIME_TYPES =ImmutableSet.of( "text/*", //NON-NLS "application/rtf", //NON-NLS "application/pdf", //NON-NLS @@ -75,9 +73,9 @@ public final class FilterUtils { "application/vnd.oasis.opendocument.presentation", //NON-NLS "application/vnd.oasis.opendocument.spreadsheet", //NON-NLS "application/vnd.oasis.opendocument.text" //NON-NLS - ).map(MediaType::parse).collect(Collectors.toSet()); + ); - private static final Set NON_OTHER_MIME_TYPES = new HashSet<>(); + private static final Set NON_OTHER_MIME_TYPES = new HashSet<>(); static { NON_OTHER_MIME_TYPES.addAll(MEDIA_MIME_TYPES); @@ -116,7 +114,7 @@ public final class FilterUtils { */ private static class InverseFileTypeFilter extends FileTypeFilter { - InverseFileTypeFilter(String displayName, Collection mediaTypes) { + InverseFileTypeFilter(String displayName, Collection mediaTypes) { super(displayName, mediaTypes); }