From 6b0891be6b389f31041e33e052851ee699cb8df5 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Wed, 22 May 2019 15:53:22 -0400 Subject: [PATCH 1/5] create and publish event when a data source is deleted Code to create and publish an event when a data source is deleted. --- .../actions/DeleteDataSourceAction.java | 1 + .../sleuthkit/autopsy/casemodule/Case.java | 14 ++++++ .../events/DataSourceDeletedEvent.java | 44 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java diff --git a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java index 4557cddaef..4170329e2b 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java @@ -54,6 +54,7 @@ public final class DeleteDataSourceAction extends AbstractAction { //VersionNumber checkVersionNumber = Case.getCurrentCaseThrows().getSleuthkitCase().getDBSchemaVersion(); Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(selectDataSource); deleteDataSource(selectDataSource); + Case.getCurrentCaseThrows().notifyDataSourceDeleted(); } catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) { String msg = MessageFormat.format(Bundle.ErrorDeletingDataSource_name_text(), selectDataSource); logger.log(Level.WARNING, msg, e); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index c9640f1a13..b3cbe76595 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -79,6 +79,7 @@ import org.sleuthkit.autopsy.casemodule.events.CommentChangedEvent; import org.sleuthkit.autopsy.casemodule.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceAddedEvent; +import org.sleuthkit.autopsy.casemodule.events.DataSourceDeletedEvent; import org.sleuthkit.autopsy.casemodule.events.DataSourceNameChangedEvent; import org.sleuthkit.autopsy.casemodule.events.ReportAddedEvent; import org.sleuthkit.autopsy.casemodule.multiusercases.CaseNodeData.CaseNodeDataException; @@ -1446,6 +1447,19 @@ public class Case { eventPublisher.publish(new DataSourceNameChangedEvent(dataSource, newName)); } + /** + * Notifies case event subscribers that a data source has been delete from + * the case database. + * + * This should not be called from the event dispatch thread (EDT) + * + * @param dataSource The data source. + * @param newName The new name for the data source + */ + public void notifyDataSourceDeleted() { + eventPublisher.publish(new DataSourceDeletedEvent()); + } + /** * Notifies case event subscribers that a content tag has been added. * diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java new file mode 100644 index 0000000000..2822b82a5a --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java @@ -0,0 +1,44 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015-2019 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.sleuthkit.autopsy.casemodule.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.Content; +import org.sleuthkit.datamodel.TskCoreException; + +public class DataSourceDeletedEvent extends AutopsyEvent implements Serializable { + + /** + * Constructs an event published when a data source is added to a case. + * + * @param dataSource The data source that was added. + * @param newName The new name of the data source + */ + public DataSourceDeletedEvent() { + + super(Case.Events.DATA_SOURCE_DELETED.toString(), null, null); + + } +} From 97ec082f8cd67f958526bb6964886a34bd02917b Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Thu, 23 May 2019 08:43:30 -0400 Subject: [PATCH 2/5] Update DataSourceDeletedEvent.java Added Data Source id --- .../events/DataSourceDeletedEvent.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java index 2822b82a5a..03a5ce7438 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java @@ -20,25 +20,32 @@ package org.sleuthkit.autopsy.casemodule.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.Content; -import org.sleuthkit.datamodel.TskCoreException; public class DataSourceDeletedEvent extends AutopsyEvent implements Serializable { + private static final long serialVersionUID = 1L; + private final long dataSourceId; + /** * Constructs an event published when a data source is added to a case. * - * @param dataSource The data source that was added. - * @param newName The new name of the data source + * @param dataSourceId The data source that was deleted. */ - public DataSourceDeletedEvent() { + public DataSourceDeletedEvent(Long dataSourceId) { - super(Case.Events.DATA_SOURCE_DELETED.toString(), null, null); - + super(Case.Events.DATA_SOURCE_DELETED.toString(), null, dataSourceId); + this.dataSourceId = dataSourceId; } + + /** + * Gets the data source id that is being deleted + * + * @return The data source id. + */ + public long getDataSourced() { + return dataSourceId; + } + } From ac6429c11a2f0ac601b66d58443f996da43b19d1 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Thu, 23 May 2019 08:45:35 -0400 Subject: [PATCH 3/5] Update Case.java Added data source Id --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index b3cbe76595..8fe2b22187 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -1453,11 +1453,10 @@ public class Case { * * This should not be called from the event dispatch thread (EDT) * - * @param dataSource The data source. - * @param newName The new name for the data source + * @param dataSourceId The data source that was deleted. */ - public void notifyDataSourceDeleted() { - eventPublisher.publish(new DataSourceDeletedEvent()); + public void notifyDataSourceDeleted(Long dataSourceId) { + eventPublisher.publish(new DataSourceDeletedEvent(dataSourceId)); } /** From b0ef89b2c9f0e6809105dcec3a973fe352ea61a8 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Thu, 23 May 2019 08:50:30 -0400 Subject: [PATCH 4/5] Update DataSourceDeletedEvent.java Fix typo --- .../autopsy/casemodule/events/DataSourceDeletedEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java index 03a5ce7438..5317a951d0 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java @@ -44,7 +44,7 @@ public class DataSourceDeletedEvent extends AutopsyEvent implements Serializable * * @return The data source id. */ - public long getDataSourced() { + public long getDataSourceId() { return dataSourceId; } From 3887c9b1108a4f4239ddaf8782a614091394f669 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Sat, 25 May 2019 22:18:52 -0400 Subject: [PATCH 5/5] Update DeleteDataSourceAction.java Remove comment. Add data source id to event. --- .../autopsy/actions/DeleteDataSourceAction.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java index 4170329e2b..0b345eda5f 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java @@ -33,18 +33,14 @@ import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; import org.sleuthkit.autopsy.progress.ProgressIndicator; import org.sleuthkit.datamodel.TskCoreException; -/** - * - * @author markm - */ public final class DeleteDataSourceAction extends AbstractAction { private static final Logger logger = Logger.getLogger(DeleteDataSourceAction.class.getName()); - private final Long selectDataSource; + private final Long selectedDataSource; @NbBundle.Messages({"DeleteDataSourceAction.name.text=Delete Data Source"}) public DeleteDataSourceAction(Long selectedDataSource) { super(Bundle.DeleteDataSourceAction_name_text()); - selectDataSource = selectedDataSource; + this.selectedDataSource = selectedDataSource; } @NbBundle.Messages({"ErrorDeletingDataSource.name.text=Error Deleting Data Source"}) @@ -52,11 +48,11 @@ public final class DeleteDataSourceAction extends AbstractAction { public void actionPerformed(ActionEvent event) { try { //VersionNumber checkVersionNumber = Case.getCurrentCaseThrows().getSleuthkitCase().getDBSchemaVersion(); - Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(selectDataSource); - deleteDataSource(selectDataSource); - Case.getCurrentCaseThrows().notifyDataSourceDeleted(); + Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(selectedDataSource); + deleteDataSource(selectedDataSource); + Case.getCurrentCaseThrows().notifyDataSourceDeleted(selectedDataSource); } catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) { - String msg = MessageFormat.format(Bundle.ErrorDeletingDataSource_name_text(), selectDataSource); + String msg = MessageFormat.format(Bundle.ErrorDeletingDataSource_name_text(), selectedDataSource); logger.log(Level.WARNING, msg, e); //throw new TskCoreException(msg, e); }