From 6b0891be6b389f31041e33e052851ee699cb8df5 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Wed, 22 May 2019 15:53:22 -0400 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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); } From 66beead5c511433f82ee8cf410b97e9b57d98d98 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Mon, 28 Oct 2019 11:43:38 -0400 Subject: [PATCH 6/8] Address IDE hints for DeleteDataSourceAction.java --- .../actions/DeleteDataSourceAction.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java index 15664110a3..21690120c3 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java @@ -31,36 +31,47 @@ import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; import org.sleuthkit.datamodel.TskCoreException; /** - * Instances of this Action allow users to delete the specified data source. + * Instances of this Action allow users to delete data sources. */ public final class DeleteDataSourceAction extends AbstractAction { + private static final long serialVersionUID = 1L; private static final Logger logger = Logger.getLogger(DeleteDataSourceAction.class.getName()); - private final Long dataSourceId; + private long dataSourceID; - @NbBundle.Messages({"DeleteDataSourceAction.name.text=Delete Data Source"}) - public DeleteDataSourceAction(Long dataSourceId) { + /** + * Constructs an Action that allows a user to delete a data source. + * + * @param dataSourceID The object ID of the data source to be deleted. + */ + @NbBundle.Messages({ + "DeleteDataSourceAction.name.text=Delete Data Source" + }) + public DeleteDataSourceAction(Long dataSourceID) { super(Bundle.DeleteDataSourceAction_name_text()); - this.dataSourceId = dataSourceId; + this.dataSourceID = dataSourceID; } @Override public void actionPerformed(ActionEvent event) { try { - Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(dataSourceId); - deleteDataSource(dataSourceId); - } catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) { - logger.log(Level.WARNING, "Error Deleting Data source " + dataSourceId, e); - } - } - - private static void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException { - try { + Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(dataSourceID); KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class); - kwsService.deleteDataSource(dataSourceId); - } catch (KeywordSearchServiceException e) { - logger.log(Level.WARNING, "KWS Error", e); + kwsService.deleteDataSource(dataSourceID); + } catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) { + logger.log(Level.WARNING, String.format("Error Deleting data source (obj_id=%d)", dataSourceID), e); } - } + + @Override + public Object clone() throws CloneNotSupportedException { + Object clonedObject = super.clone(); + ((DeleteDataSourceAction) clonedObject).setDataSourceID(this.dataSourceID); + return clonedObject; + } + + private void setDataSourceID(long dataSourceID) { + this.dataSourceID = dataSourceID; + } + } From 9b4ad347bd63edc8cddcf829d06a9b97d749e4a1 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Mon, 28 Oct 2019 13:55:01 -0400 Subject: [PATCH 7/8] Merge in new data source deletion code from McKinnon --- .../sleuthkit/autopsy/actions/DeleteDataSourceAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java index 3ac6f0eec8..3909c59827 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java @@ -65,9 +65,9 @@ public final class DeleteDataSourceAction extends AbstractAction { } @Override - public Object clone() throws CloneNotSupportedException { - Object clonedObject = super.clone(); - ((DeleteDataSourceAction) clonedObject).setDataSourceID(this.dataSourceID); + public DeleteDataSourceAction clone() throws CloneNotSupportedException { + DeleteDataSourceAction clonedObject = ((DeleteDataSourceAction) super.clone()); + clonedObject.setDataSourceID(this.dataSourceID); return clonedObject; } From 5cb4348f34272fa3de1fa47d8d040b4e16d7495f Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Mon, 28 Oct 2019 14:10:39 -0400 Subject: [PATCH 8/8] Merge in new data source deletion code from McKinnon --- .../actions/DeleteDataSourceAction.java | 4 +-- .../sleuthkit/autopsy/casemodule/Case.java | 14 +++++----- .../events/DataSourceDeletedEvent.java | 28 ++++++++++--------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java index 3909c59827..b71f9db7a2 100644 --- a/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java +++ b/Core/src/org/sleuthkit/autopsy/actions/DeleteDataSourceAction.java @@ -31,7 +31,7 @@ import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; import org.sleuthkit.datamodel.TskCoreException; /** - * Instances of this Action allow users to delete data sources. + * An Action that allows a user to delete a data source. */ public final class DeleteDataSourceAction extends AbstractAction { @@ -60,7 +60,7 @@ public final class DeleteDataSourceAction extends AbstractAction { kwsService.deleteDataSource(dataSourceID); Case.getCurrentCaseThrows().notifyDataSourceDeleted(dataSourceID); } catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) { - logger.log(Level.WARNING, String.format("Error Deleting data source (obj_id=%d)", dataSourceID), e); + logger.log(Level.SEVERE, String.format("Error Deleting data source (obj_id=%d)", dataSourceID), e); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 300b563d02..e70607424e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -399,9 +399,9 @@ public class Case { * TimelineEvent that was added. */ TIMELINE_EVENT_ADDED, - /* An item in the central repository has had its comment - * modified. The old value is null, the new value is string for current - * comment. + /* + * An item in the central repository has had its comment modified. The + * old value is null, the new value is string for current comment. */ CR_COMMENT_CHANGED; @@ -536,8 +536,8 @@ public class Case { */ public static boolean isValidName(String caseName) { return !(caseName.contains("\\") || caseName.contains("/") || caseName.contains(":") - || caseName.contains("*") || caseName.contains("?") || caseName.contains("\"") - || caseName.contains("<") || caseName.contains(">") || caseName.contains("|")); + || caseName.contains("*") || caseName.contains("?") || caseName.contains("\"") + || caseName.contains("<") || caseName.contains(">") || caseName.contains("|")); } /** @@ -1484,12 +1484,12 @@ public class Case { } /** - * Notifies case event subscribers that a data source has been delete from + * Notifies case event subscribers that a data source has been deleted from * the case database. * * This should not be called from the event dispatch thread (EDT) * - * @param dataSourceId The data source that was deleted. + * @param dataSourceId The object ID of the data source that was deleted. */ public void notifyDataSourceDeleted(Long dataSourceId) { eventPublisher.publish(new DataSourceDeletedEvent(dataSourceId)); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java index 5317a951d0..5550ad9313 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/events/DataSourceDeletedEvent.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2015-2019 Basis Technology Corp. + * Copyright 2019 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,36 +16,38 @@ * 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 org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.events.AutopsyEvent; +/** + * An application event that is published when a data source has been deleted. + */ public class DataSourceDeletedEvent extends AutopsyEvent implements Serializable { private static final long serialVersionUID = 1L; - private final long dataSourceId; - + private final long dataSourceID; + /** - * Constructs an event published when a data source is added to a case. + * Constructs an application event that is published when a data source has + * been deleted. * - * @param dataSourceId The data source that was deleted. + * @param dataSourceId The object ID of the data source that was deleted. */ public DataSourceDeletedEvent(Long dataSourceId) { - super(Case.Events.DATA_SOURCE_DELETED.toString(), null, dataSourceId); - this.dataSourceId = dataSourceId; - } - + this.dataSourceID = dataSourceId; + } + /** - * Gets the data source id that is being deleted + * Gets the object ID of the data source that was deleted. * * @return The data source id. */ public long getDataSourceId() { - return dataSourceId; + return dataSourceID; } - + }