Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
MergeHostAction.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.hosts;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.logging.Level;
23 import javax.swing.AbstractAction;
24 import javax.swing.JOptionPane;
25 import javax.swing.SwingWorker;
26 import org.openide.util.NbBundle;
27 import org.openide.util.NbBundle.Messages;
28 import org.openide.windows.WindowManager;
33 import org.sleuthkit.datamodel.Host;
34 
38 @Messages({
39  "MergeHostAction_onError_title=Error Merging Hosts",
40  "# {0} - sourceHostName",
41  "# {1} - destHostName",
42  "MergeHostAction_onError_description=There was an error merging host {0} into host {1}.",})
43 public class MergeHostAction extends AbstractAction {
44 
45  private static final Logger logger = Logger.getLogger(MergeHostAction.class.getName());
46 
47  private final Host sourceHost;
48  private final Host destHost;
49 
56  public MergeHostAction(Host sourceHost, Host destHost) {
57  super(destHost.getName());
58 
59  this.sourceHost = sourceHost;
60  this.destHost = destHost;
61  }
62 
63  @NbBundle.Messages({
64  "MergeHostAction.progressIndicatorName=Merging Hosts",
65  "MergeHostAction.confirmTitle=Confirmation",
66  "# {0} - sourceHost",
67  "# {1} - destHost",
68  "MergeHostAction.confirmText=Are you sure you want to merge {0} into {1}?\nThis may include merging OS Accounts and cannot be undone.",
69  "# {0} - sourceHost",
70  "# {1} - destHost",
71  "MergeHostAction.progressText=Merging {0} into {1}..."
72  })
73  @Override
74  public void actionPerformed(ActionEvent e) {
75 
76  // Display confirmation dialog
77  int response = JOptionPane.showConfirmDialog(
78  WindowManager.getDefault().getMainWindow(),
79  NbBundle.getMessage(this.getClass(), "MergeHostAction.confirmText", sourceHost.getName(), destHost.getName()),
80  NbBundle.getMessage(this.getClass(), "MergeHostAction.confirmTitle"),
81  JOptionPane.YES_NO_OPTION);
82  if (response == JOptionPane.NO_OPTION) {
83  return;
84  }
85 
86  ModalDialogProgressIndicator progressDialog = new ModalDialogProgressIndicator(WindowManager.getDefault().getMainWindow(),
87  Bundle.MergeHostAction_progressIndicatorName());
88 
89  MergeHostsBackgroundTask mergeTask = new MergeHostsBackgroundTask(sourceHost, destHost, progressDialog);
90  progressDialog.start(NbBundle.getMessage(this.getClass(), "MergeHostAction.progressText", sourceHost.getName(), destHost.getName()));
91  mergeTask.execute();
92  }
93 
97  private class MergeHostsBackgroundTask extends SwingWorker<Void, Void> {
98 
99  private final Host sourceHost;
100  private final Host destHost;
102 
103  public MergeHostsBackgroundTask(Host sourceHost, Host destHost, ProgressIndicator progress) {
104  this.sourceHost = sourceHost;
105  this.destHost = destHost;
106  this.progress = progress;
107  }
108 
109  @Override
110  protected Void doInBackground() throws Exception {
111  Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().mergeHosts(sourceHost, destHost);
112  return null;
113  }
114 
115  @NbBundle.Messages({
116  "MergeHostAction.errorTitle=Error Merging Hosts",
117  "MergeHostAction.errorText=An error occurred while merging hosts.\nTry again in a few minutes or check the log for details."
118  })
119  @Override
120  protected void done() {
121  progress.finish();
122  try {
123  get();
124  } catch (Exception ex) {
125  logger.log(Level.SEVERE, "Error merging " + sourceHost.getName() + " into " + destHost.getName(), ex);
126 
127  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
128  NbBundle.getMessage(this.getClass(), "MergeHostAction.errorText"),
129  NbBundle.getMessage(this.getClass(), "MergeHostAction.errorTitle"),
130  JOptionPane.ERROR_MESSAGE);
131  }
132  }
133  }
134 
135 }
synchronized void start(String message, int totalWorkUnits)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
MergeHostsBackgroundTask(Host sourceHost, Host destHost, ProgressIndicator progress)

Copyright © 2012-2022 Basis Technology. Generated on: Sun Sep 25 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.