Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DeletePersonAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.datamodel.persons;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.List;
23 import java.util.logging.Level;
24 import javax.swing.AbstractAction;
25 import javax.swing.JOptionPane;
26 import org.apache.commons.collections.CollectionUtils;
27 import org.openide.util.NbBundle.Messages;
28 import org.openide.windows.WindowManager;
31 import org.sleuthkit.datamodel.TskCoreException;
33 import org.sleuthkit.datamodel.Host;
34 import org.sleuthkit.datamodel.Person;
35 
39 @Messages({
40  "DeletePersonAction_menuTitle=Delete Person",
41  "DeletePersonAction_onError_title=Error Delete Host from Person",
42  "# {0} - personName",
43  "DeletePersonAction_onError_description=There was an error removing person: {0}.",})
44 public class DeletePersonAction extends AbstractAction {
45 
46  private static final Logger logger = Logger.getLogger(DeletePersonAction.class.getName());
47 
48  private final Person person;
49 
55  public DeletePersonAction(Person person) {
56  super(Bundle.DeletePersonAction_menuTitle());
57  this.person = person;
58  setEnabled();
59  }
60 
64  private void setEnabled() {
65  if (person == null) {
66  this.setEnabled(false);
67  } else {
68  try {
69  List<Host> hosts = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getHostsForPerson(person);
70  if (CollectionUtils.isNotEmpty(hosts)) {
71  this.setEnabled(false);
72  return;
73  }
74  } catch (NoCurrentCaseException | TskCoreException ex) {
75  logger.log(Level.WARNING, String.format("Unable to fetch hosts belonging to person: %s", person.getName() == null ? "<null>" : person.getName(), ex));
76  }
77  this.setEnabled(true);
78  }
79  }
80 
81  @Override
82  public void actionPerformed(ActionEvent e) {
83  if (person != null && person.getName() != null) {
84  try {
85  Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().deletePerson(person.getName());
86  } catch (NoCurrentCaseException | TskCoreException ex) {
87  String personName = this.person == null || this.person.getName() == null ? "" : this.person.getName();
88  logger.log(Level.WARNING, String.format("Unable to remove parent from host: %s", personName), ex);
89 
90  JOptionPane.showMessageDialog(
91  WindowManager.getDefault().getMainWindow(),
92  Bundle.DeletePersonAction_onError_description(personName),
93  Bundle.DeletePersonAction_onError_title(),
94  JOptionPane.WARNING_MESSAGE);
95  }
96  }
97 
98  }
99 
100 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.