Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EventUpdateHandler.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.Set;
30 import org.sleuthkit.datamodel.AbstractFile;
31 
36 public class EventUpdateHandler {
37 
42  @Override
43  public void refresh() {
44  // delegate to EventUpdateHandler method.
46  }
47 
48  @Override
49  public boolean isRefreshRequired(PropertyChangeEvent evt) {
50  String eventType = evt.getPropertyName();
51  if (Case.isCaseOpen()) {
52  if (IngestManager.IngestModuleEvent.DATA_ADDED.toString().equals(eventType) && evt.getOldValue() instanceof ModuleDataEvent) {
53  ModuleDataEvent dataEvent = (ModuleDataEvent) evt.getOldValue();
54  return EventUpdateHandler.this.isRefreshRequired(dataEvent);
55  } else if (IngestManager.IngestModuleEvent.CONTENT_CHANGED.toString().equals(eventType) && evt.getOldValue() instanceof ModuleContentEvent) {
56  ModuleContentEvent contentEvent = (ModuleContentEvent) evt.getOldValue();
57  return EventUpdateHandler.this.isRefreshRequired(contentEvent);
58  } else if (IngestManager.IngestModuleEvent.FILE_DONE.toString().equals(eventType) && evt.getNewValue() instanceof AbstractFile) {
59  AbstractFile analyzedFile = (AbstractFile) evt.getNewValue();
60  return EventUpdateHandler.this.isRefreshRequired(analyzedFile);
61  }
62  }
63  return false;
64  }
65  });
66 
70  private final PropertyChangeListener caseEventsListener = (evt) -> {
72  onRefresh();
73  }
74  };
75 
76  private final PropertyChangeListener ingestJobEventsListener = (evt) -> {
77  if (evt == null) {
78  return;
79  }
80 
81  String eventName = evt.getPropertyName();
82  for (IngestJobEvent ingestEvt : IngestJobEvent.values()) {
83  if (ingestEvt.name().equals(eventName) && isRefreshRequired(ingestEvt)) {
84  onRefresh();
85  }
86  }
87  };
88 
89  private final UpdateGovernor governor;
90  private final Set<Case.Events> caseEvents;
91  private final Set<IngestJobEvent> ingestEvents;
92  private final Runnable onUpdate;
93 
102  public EventUpdateHandler(Runnable onUpdate, UpdateGovernor governor) {
103  if (onUpdate == null) {
104  throw new IllegalArgumentException("onUpdate parameter must be non-null.");
105  }
106 
107  this.onUpdate = onUpdate;
108  this.governor = governor;
109  this.caseEvents = governor.getCaseEventUpdates();
110  this.ingestEvents = governor.getIngestJobEventUpdates();
111  }
112 
120  protected boolean isRefreshRequired(ModuleDataEvent evt) {
121  return governor.isRefreshRequired(evt);
122  }
123 
131  protected boolean isRefreshRequired(ModuleContentEvent evt) {
132  return governor.isRefreshRequired(evt);
133  }
134 
143  protected boolean isRefreshRequired(AbstractFile evt) {
144  return governor.isRefreshRequired(evt);
145  }
146 
154  protected boolean isRefreshRequired(IngestJobEvent evt) {
155  return governor.isRefreshRequired(evt);
156  }
157 
165  protected boolean isRefreshRequiredForCaseEvent(PropertyChangeEvent evt) {
166  return governor.isRefreshRequiredForCaseEvent(evt);
167  }
168 
172  protected void onRefresh() {
173  onUpdate.run();
174  }
175 
179  public void register() {
180  if (!caseEvents.isEmpty()) {
181  Case.addEventTypeSubscriber(caseEvents, caseEventsListener);
182  }
183 
184  IngestManager.getInstance().addIngestJobEventListener(ingestEvents, ingestJobEventsListener);
185  refreshThrottler.registerForIngestModuleEvents();
186  }
187 
191  public void unregister() {
192  if (!caseEvents.isEmpty()) {
193  Case.removeEventTypeSubscriber(caseEvents, caseEventsListener);
194  }
195 
196  IngestManager.getInstance().removeIngestJobEventListener(ingestEvents, ingestJobEventsListener);
197  refreshThrottler.unregisterEventListener();
198  }
199 }
static synchronized IngestManager getInstance()
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:491
boolean isRefreshRequiredForCaseEvent(PropertyChangeEvent evt)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:536

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.