Merge pull request #5378 from rcordovano/rc-data-src-deletion-integration

Address IDE hints for DeleteDataSourceAction.java
This commit is contained in:
Richard Cordovano 2019-10-28 14:12:34 -04:00 committed by GitHub
commit a3c150f326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 23 deletions

View File

@ -31,36 +31,48 @@ import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
import org.sleuthkit.datamodel.TskCoreException;
/**
* Instances of this Action allow users to delete the specified data source.
* An Action that allows a user to delete a data source.
*/
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);
Case.getCurrentCaseThrows().notifyDataSourceDeleted(dataSourceID);
} catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) {
logger.log(Level.SEVERE, String.format("Error Deleting data source (obj_id=%d)", dataSourceID), e);
}
}
@Override
public DeleteDataSourceAction clone() throws CloneNotSupportedException {
DeleteDataSourceAction clonedObject = ((DeleteDataSourceAction) super.clone());
clonedObject.setDataSourceID(this.dataSourceID);
return clonedObject;
}
private void setDataSourceID(long dataSourceID) {
this.dataSourceID = dataSourceID;
}
}

View File

@ -77,6 +77,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;
@ -398,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;
@ -535,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("|"));
}
/**
@ -1482,6 +1483,18 @@ public class Case {
eventPublisher.publish(new DataSourceNameChangedEvent(dataSource, newName));
}
/**
* 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 object ID of the data source that was deleted.
*/
public void notifyDataSourceDeleted(Long dataSourceId) {
eventPublisher.publish(new DataSourceDeletedEvent(dataSourceId));
}
/**
* Notifies case event subscribers that a content tag has been added.
*

View File

@ -0,0 +1,53 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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 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;
/**
* Constructs an application event that is published when a data source has
* been 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;
}
/**
* Gets the object ID of the data source that was deleted.
*
* @return The data source id.
*/
public long getDataSourceId() {
return dataSourceID;
}
}