Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DeleteDataSourceAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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.casemodule;
20 
21 import java.awt.event.ActionEvent;
22 import java.nio.file.Path;
23 import java.util.concurrent.ExecutionException;
24 import java.util.logging.Level;
25 import javax.swing.AbstractAction;
26 import javax.swing.SwingWorker;
27 import org.openide.util.NbBundle;
32 
36 public final class DeleteDataSourceAction extends AbstractAction {
37 
38  private static final long serialVersionUID = 1L;
39  private static final Logger logger = Logger.getLogger(DeleteDataSourceAction.class.getName());
40  private long dataSourceObjectID;
41  private Path caseMetadataFilePath;
42 
49  @NbBundle.Messages({
50  "DeleteDataSourceAction.name.text=Remove Data Source"
51  })
52  public DeleteDataSourceAction(Long dataSourceObjectID) {
53  super(Bundle.DeleteDataSourceAction_name_text());
54  this.dataSourceObjectID = dataSourceObjectID;
55  this.setEnabled(FeatureAccessUtils.canDeleteDataSources());
56  }
57 
58  @NbBundle.Messages({
59  "DeleteDataSourceAction.ingestRunningWarningDialog.message=Data sources cannot be removed from a case when ingest is running.",
60  "DeleteDataSourceAction.confirmationDialog.message=Are you sure you want to remove the selected data source from the case?\nNote that the case will be closed and re-opened during the removal.",
61  "# {0} - exception message", "DeleteDataSourceAction.exceptionMessage.dataSourceDeletionError=An error occurred while removing the data source:\n{0}\nPlease see the application log for details.",
62  "# {0} - exception message", "DeleteDataSourceAction.exceptionMessage.couldNotReopenCase=Failed to re-open the case:\n{0}\nPlease see the application log for details."
63  })
64  @Override
65  public void actionPerformed(ActionEvent event) {
67  MessageNotifyUtil.Message.warn(Bundle.DeleteDataSourceAction_ingestRunningWarningDialog_message());
68  return;
69  }
70 
71  if (MessageNotifyUtil.Message.confirm(Bundle.DeleteDataSourceAction_confirmationDialog_message())) {
72  new DataSourceDeletionWorker().execute();
73  }
74  }
75 
79  private class DataSourceDeletionWorker extends SwingWorker<Void, Void> {
80 
81  @Override
82  protected Void doInBackground() throws Exception {
83  /*
84  * Save the case metadata file path so the case can be reopened if
85  * something goes wrong and the case ends up closed.
86  */
87  caseMetadataFilePath = Case.getCurrentCase().getMetadata().getFilePath();
88  Case.deleteDataSourceFromCurrentCase(dataSourceObjectID);
89  return null;
90  }
91 
92  @Override
93  protected void done() {
94  try {
95  get();
96  } catch (InterruptedException | ExecutionException ex) {
97  logger.log(Level.SEVERE, String.format("Error deleting data source (obj_id=%d)", dataSourceObjectID), ex);
98  MessageNotifyUtil.Message.show(Bundle.DeleteDataSourceAction_exceptionMessage_dataSourceDeletionError(ex.getLocalizedMessage()), MessageNotifyUtil.MessageType.ERROR);
99  if (!Case.isCaseOpen()) {
100  new CaseReopeningWorker().execute();
101  }
102  }
103  }
104 
105  }
106 
111  private class CaseReopeningWorker extends SwingWorker<Void, Void> {
112 
113  @Override
114  protected Void doInBackground() throws Exception {
115  Case.openAsCurrentCase(caseMetadataFilePath.toString());
116  return null;
117  }
118 
119  @Override
120  protected void done() {
121  try {
122  get();
123  } catch (InterruptedException ex) {
124  logger.log(Level.WARNING, String.format("Interrupted reopening case after error deleting data source (obj_id=%d)", dataSourceObjectID), ex);
125 
126  } catch (ExecutionException ex) {
127  logger.log(Level.SEVERE, String.format("Error reopening case after error deleting data source (obj_id=%d)", dataSourceObjectID), ex);
128  MessageNotifyUtil.Message.show(Bundle.DeleteDataSourceAction_exceptionMessage_dataSourceDeletionError(ex.getCause().getLocalizedMessage()), MessageNotifyUtil.MessageType.ERROR);
130  }
131  }
132 
133  }
134 
135  @Override
136  public DeleteDataSourceAction clone() throws CloneNotSupportedException {
137  DeleteDataSourceAction clonedObject = ((DeleteDataSourceAction) super.clone());
138  clonedObject.setDataSourceID(this.dataSourceObjectID);
139  return clonedObject;
140  }
141 
148  private void setDataSourceID(long dataSourceObjectID) {
149  this.dataSourceObjectID = dataSourceObjectID;
150  }
151 
152 }
static synchronized IngestManager getInstance()
static void show(String message, MessageType messageType)
static void openAsCurrentCase(String caseMetadataFilePath)
Definition: Case.java:630
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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