Skip to content

Commit

Permalink
Scrub Case class API
Browse files Browse the repository at this point in the history
  • Loading branch information
rcordovano committed Jul 21, 2016
1 parent 48bb082 commit 60f5cc6
Show file tree
Hide file tree
Showing 19 changed files with 1,175 additions and 1,121 deletions.
Expand Up @@ -101,7 +101,7 @@ public void run() {
try {
currentCase.getSleuthkitCase().acquireExclusiveLock();
synchronized (tskAddImageProcessLock) {
tskAddImageProcess = currentCase.makeAddImageProcess(timeZone, true, ignoreFatOrphanFiles);
tskAddImageProcess = currentCase.getSleuthkitCase().makeAddImageProcess(timeZone, true, ignoreFatOrphanFiles);
}
Thread progressUpdateThread = new Thread(new ProgressUpdater(progressMonitor, tskAddImageProcess));
progressUpdateThread.start();
Expand Down
2,168 changes: 1,091 additions & 1,077 deletions Core/src/org/sleuthkit/autopsy/casemodule/Case.java

Large diffs are not rendered by default.

Expand Up @@ -87,7 +87,7 @@ public void actionPerformed(ActionEvent e) {
}
}

if (Case.existsCurrentCase() == false) {
if (Case.isCaseOpen() == false) {
return;
}
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Expand Down
25 changes: 12 additions & 13 deletions Core/src/org/sleuthkit/autopsy/casemodule/CollaborationMonitor.java
Expand Up @@ -62,7 +62,7 @@ final class CollaborationMonitor {
private static final String PERIODIC_TASK_THREAD_NAME = "collab-monitor-periodic-tasks-%d"; //NON-NLS
private static final long HEARTBEAT_INTERVAL_MINUTES = 1;
private static final long MAX_MISSED_HEARTBEATS = 5;
private static final long STALE_TASKS_DETECTION_INTERVAL_MINUTES = 2;
private static final long STALE_TASKS_DETECT_INTERVAL_MINS = 2;
private static final long EXECUTOR_TERMINATION_WAIT_SECS = 30;
private static final Logger logger = Logger.getLogger(CollaborationMonitor.class.getName());
private final String hostName;
Expand Down Expand Up @@ -120,7 +120,7 @@ final class CollaborationMonitor {
*/
periodicTasksExecutor = new ScheduledThreadPoolExecutor(NUMBER_OF_PERIODIC_TASK_THREADS, new ThreadFactoryBuilder().setNameFormat(PERIODIC_TASK_THREAD_NAME).build());
periodicTasksExecutor.scheduleAtFixedRate(new HeartbeatTask(), HEARTBEAT_INTERVAL_MINUTES, HEARTBEAT_INTERVAL_MINUTES, TimeUnit.MINUTES);
periodicTasksExecutor.scheduleAtFixedRate(new StaleTaskDetectionTask(), STALE_TASKS_DETECTION_INTERVAL_MINUTES, STALE_TASKS_DETECTION_INTERVAL_MINUTES, TimeUnit.MINUTES);
periodicTasksExecutor.scheduleAtFixedRate(new StaleTaskDetectionTask(), STALE_TASKS_DETECT_INTERVAL_MINS, STALE_TASKS_DETECT_INTERVAL_MINS, TimeUnit.MINUTES);
}

/**
Expand Down Expand Up @@ -159,7 +159,7 @@ void shutdown() {
private final class LocalTasksManager implements PropertyChangeListener {

private long nextTaskId;
private final Map<Integer, Task> uuidsToAddDataSourceTasks;
private final Map<Integer, Task> eventIdsToAddDataSourceTasks;
private final Map<Long, Task> jobIdsTodataSourceAnalysisTasks;

/**
Expand All @@ -169,7 +169,7 @@ private final class LocalTasksManager implements PropertyChangeListener {
*/
LocalTasksManager() {
nextTaskId = 0;
uuidsToAddDataSourceTasks = new HashMap<>();
eventIdsToAddDataSourceTasks = new HashMap<>();
jobIdsTodataSourceAnalysisTasks = new HashMap<>();
}

Expand All @@ -186,9 +186,9 @@ public void propertyChange(PropertyChangeEvent event) {
if (eventName.equals(Case.Events.ADDING_DATA_SOURCE.toString())) {
addDataSourceAddTask((AddingDataSourceEvent) event);
} else if (eventName.equals(Case.Events.ADDING_DATA_SOURCE_FAILED.toString())) {
removeDataSourceAddTask(((AddingDataSourceFailedEvent) event).getDataSourceId());
removeDataSourceAddTask(((AddingDataSourceFailedEvent) event).getAddingDataSourceEventId());
} else if (eventName.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
removeDataSourceAddTask(((DataSourceAddedEvent) event).getDataSourceId());
removeDataSourceAddTask(((DataSourceAddedEvent) event).getAddingDataSourceEventId());
} else if (eventName.equals(IngestManager.IngestJobEvent.DATA_SOURCE_ANALYSIS_STARTED.toString())) {
addDataSourceAnalysisTask((DataSourceAnalysisStartedEvent) event);
} else if (eventName.equals(IngestManager.IngestJobEvent.DATA_SOURCE_ANALYSIS_COMPLETED.toString())) {
Expand All @@ -205,20 +205,19 @@ public void propertyChange(PropertyChangeEvent event) {
*/
synchronized void addDataSourceAddTask(AddingDataSourceEvent event) {
String status = NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.addingDataSourceStatus.msg", hostName);
uuidsToAddDataSourceTasks.put(event.getDataSourceId().hashCode(), new Task(++nextTaskId, status));
eventIdsToAddDataSourceTasks.put(event.getEventId().hashCode(), new Task(++nextTaskId, status));
eventPublisher.publishRemotely(new CollaborationEvent(hostName, getCurrentTasks()));
}

/**
* Removes an adding data source task from the collection of local tasks
* and publishes the updated collection to any collaborating nodes.
*
* @param dataSourceId A data source id to pair a data source added or
* adding data source failed event with an adding
* data source event.
* @param eventId An event id to pair a data source added or adding data
* source failed event with an adding data source event.
*/
synchronized void removeDataSourceAddTask(UUID dataSourceId) {
uuidsToAddDataSourceTasks.remove(dataSourceId.hashCode());
synchronized void removeDataSourceAddTask(UUID eventId) {
eventIdsToAddDataSourceTasks.remove(eventId.hashCode());
eventPublisher.publishRemotely(new CollaborationEvent(hostName, getCurrentTasks()));
}

Expand Down Expand Up @@ -253,7 +252,7 @@ synchronized void removeDataSourceAnalysisTask(DataSourceAnalysisCompletedEvent
*/
synchronized Map<Long, Task> getCurrentTasks() {
Map<Long, Task> currentTasks = new HashMap<>();
uuidsToAddDataSourceTasks.values().stream().forEach((task) -> {
eventIdsToAddDataSourceTasks.values().stream().forEach((task) -> {
currentTasks.put(task.getId(), task);
});
jobIdsTodataSourceAnalysisTasks.values().stream().forEach((task) -> {
Expand Down
7 changes: 4 additions & 3 deletions Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java
Expand Up @@ -36,6 +36,7 @@
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.DriveUtils;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.PathValidator;

Expand Down Expand Up @@ -272,9 +273,9 @@ public boolean validatePanel() {
// display warning if there is one (but don't disable "next" button)
warnIfPathIsInvalid(path);

boolean isExist = Case.pathExists(path);
boolean isPhysicalDrive = Case.isPhysicalDrive(path);
boolean isPartition = Case.isPartition(path);
boolean isExist = new File(path).isFile();
boolean isPhysicalDrive = DriveUtils.isPhysicalDrive(path);
boolean isPartition = DriveUtils.isPartition(path);

return (isExist || isPhysicalDrive || isPartition);
}
Expand Down
Expand Up @@ -31,6 +31,7 @@
import javax.swing.JOptionPane;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.coreutils.DriveUtils;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;
Expand Down Expand Up @@ -118,7 +119,7 @@ private void updateSelectButton() {
// Enable this based on whether there is a valid path
if (!pathNameTextField.getText().isEmpty()) {
String filePath = pathNameTextField.getText();
boolean isExist = Case.pathExists(filePath) || Case.driveExists(filePath);
boolean isExist = new File(filePath).isFile() || DriveUtils.driveExists(filePath);
selectButton.setEnabled(isExist);
}
}
Expand Down
Expand Up @@ -31,7 +31,7 @@
public final class AddingDataSourceEvent extends AutopsyEvent implements Serializable {

private static final long serialVersionUID = 1L;
private final UUID dataSourceId;
private final UUID eventId;

/**
* Constructs an event published when a data source is being added to a
Expand All @@ -42,20 +42,33 @@ public final class AddingDataSourceEvent extends AutopsyEvent implements Seriali
* DataSourceAddedEvent or a
* AddingDataSourceFailedEvent.
*/
public AddingDataSourceEvent(UUID dataSourceId) {
public AddingDataSourceEvent(UUID eventId) {
super(Case.Events.ADDING_DATA_SOURCE.toString(), null, null);
this.dataSourceId = dataSourceId;
this.eventId = eventId;
}

/**
* Gets the unique id for the data source used to pair this
* AddindDataSourceEvent with a a DataSourceAddedEvent or a
* Gets the unique event id used to pair this
* AddindDataSourceEvent with a corresponding DataSourceAddedEvent or
* AddingDataSourceFailedEvent.
*
* @return The unique id.
* @return The unique event id.
*/
public UUID getEventId() {
return eventId;
}

/**
* Gets the unique event id used to pair this
* AddindDataSourceEvent with a corresponding DataSourceAddedEvent or
* AddingDataSourceFailedEvent.
*
* @return The unique event id.
* @deprecated Use getEventId instead.
*/
@Deprecated
public UUID getDataSourceId() {
return dataSourceId;
return eventId;
}

}
Expand Up @@ -47,11 +47,23 @@ public AddingDataSourceFailedEvent(UUID dataSourceId) {
}

/**
* Gets the unique id for the data source used to pair this
* AddingDataSourceFailedEvent with a AddingDataSourceEvent.
* Gets the unique id used to pair this AddingDataSourceFailedEvent with the
* corresponding AddingDataSourceEvent.
*
* @return The unique id.
* @return The unique event id.
*/
public UUID getAddingDataSourceEventId() {
return dataSourceId;
}

/**
* Gets the unique id used to pair this AddingDataSourceFailedEvent with the
* corresponding AddingDataSourceEvent.
*
* @return The unique event id.
* @deprecated Use getAddingDataSourceEventId instead.
*/
@Deprecated
public UUID getDataSourceId() {
return dataSourceId;
}
Expand Down
Expand Up @@ -96,11 +96,24 @@ public Content getDataSource() {
}

/**
* Gets the unique id for the data source used to pair this
* DataSourceAddedEvent with a AddingDataSourceEvent.
* Gets the unique id used to pair this DataSourceAddedEvent with the
* corresponding AddingDataSourceEvent.
*
* @return The unique id.
* @return The unique event id.
*/
public UUID getAddingDataSourceEventId() {
return dataSourceId;
}

/**
* Gets the unique id used to pair this DataSourceAddedEvent with the
* corresponding AddingDataSourceEvent.
*
* @return The unique event id.
*
* @deprecated Use getAddingDataSourceEventId instead.
*/
@Deprecated
public UUID getDataSourceId() {
return dataSourceId;
}
Expand Down
Expand Up @@ -171,7 +171,7 @@ public void setNode(Node selectedNode) {

@Override
public boolean canClose() {
return (!this.isDefault) || !Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
return (!this.isDefault) || !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
}

@Override
Expand Down
Expand Up @@ -477,7 +477,7 @@ public List<DataResultViewer> getViewers() {
}

public boolean canClose() {
return (!this.isMain) || !Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
return (!this.isMain) || !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
}

@Override
Expand Down
Expand Up @@ -310,7 +310,7 @@ public boolean isMain() {

@Override
public boolean canClose() {
return (!this.isMain) || !Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
return (!this.isMain) || !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java
Expand Up @@ -37,6 +37,7 @@
import org.sleuthkit.autopsy.casemodule.CaseActionException;
import org.sleuthkit.autopsy.casemodule.CaseMetadata;
import org.sleuthkit.autopsy.casemodule.OpenFromArguments;
import org.sleuthkit.autopsy.casemodule.StartupWindowProvider;
import org.sleuthkit.autopsy.coreutils.Logger;

/**
Expand Down Expand Up @@ -91,7 +92,7 @@ public void restored() {
}
}
}
Case.invokeStartupDialog();
StartupWindowProvider.getInstance().open();
});

}
Expand Down
Expand Up @@ -343,7 +343,7 @@ public void componentOpened() {
// change the cursor to "waiting cursor" for this operation
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
if (Case.existsCurrentCase()) {
if (Case.isCaseOpen()) {
Case currentCase = Case.getCurrentCase();

// close the top component if there's no image in this case
Expand Down Expand Up @@ -479,7 +479,7 @@ protected String preferredID() {

@Override
public boolean canClose() {
return !Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
return !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
}

/**
Expand Down
Expand Up @@ -166,11 +166,11 @@ private static List<String> createTimeZoneList() {

List<String> timeZones = new ArrayList<>();

if (Case.existsCurrentCase()) {
if (Case.isCaseOpen()) {
// get the latest case
Case currentCase = Case.getCurrentCase(); // get the most updated case

Set<TimeZone> caseTimeZones = currentCase.getTimeZone();
Set<TimeZone> caseTimeZones = currentCase.getTimeZones();
Iterator<TimeZone> iterator = caseTimeZones.iterator();
while (iterator.hasNext()) {
TimeZone zone = iterator.next();
Expand Down
Expand Up @@ -50,7 +50,7 @@ public JComponent[] getMenuPresenters() {

defaultItem.addActionListener(new OpenTopComponentAction(contentWin));

if (!Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false) {
if (!Case.isCaseOpen() || Case.getCurrentCase().hasData() == false) {
defaultItem.setEnabled(false); // disable the menu items when no case is opened
} else {
defaultItem.setEnabled(true); // enable the menu items when there's a case opened / created
Expand Down
Expand Up @@ -53,7 +53,7 @@ public JComponent[] getMenuPresenters() {
JMenuItem item = new JMenuItem(explorerWin.getName());
item.addActionListener(new OpenTopComponentAction(explorerWin));

if (!Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false) {
if (!Case.isCaseOpen() || Case.getCurrentCase().hasData() == false) {
item.setEnabled(false); // disable the menu when no case is opened
} else {
item.setEnabled(true); // enable the menu if the case is opened or created
Expand Down
Expand Up @@ -221,7 +221,7 @@ private ImageGalleryController() {

listeningEnabled.addListener((observable, oldValue, newValue) -> {
//if we just turned on listening and a case is open and that case is not up to date
if (newValue && !oldValue && Case.existsCurrentCase() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) {
if (newValue && !oldValue && Case.isCaseOpen() && ImageGalleryModule.isDrawableDBStale(Case.getCurrentCase())) {
//populate the db
queueDBWorkerTask(new CopyAnalyzedFiles(instance, db, sleuthKitCase));
}
Expand Down
Expand Up @@ -80,7 +80,7 @@ public Component getToolbarPresenter() {
public void performAction() {

//check case
if (!Case.existsCurrentCase()) {
if (!Case.isCaseOpen()) {
return;
}
final Case currentCase = Case.getCurrentCase();
Expand Down

0 comments on commit 60f5cc6

Please sign in to comment.