Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
NewCaseWizardAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.Component;
22 import java.awt.Cursor;
23 import java.awt.Dialog;
24 import java.io.File;
25 import java.text.MessageFormat;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
28 import javax.swing.JComponent;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingWorker;
31 import org.openide.DialogDisplayer;
32 import org.openide.WizardDescriptor;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.openide.util.actions.CallableSystemAction;
36 import org.openide.util.actions.SystemAction;
37 import org.openide.windows.WindowManager;
45 
53 final class NewCaseWizardAction extends CallableSystemAction {
54 
55  private static final long serialVersionUID = 1L;
56  private static final Logger logger = Logger.getLogger(NewCaseWizardAction.class.getName());
57  private WizardDescriptor.Panel<WizardDescriptor>[] panels;
58 
59  @Override
60  public void performAction() {
61  String optionsDlgTitle = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning.title");
62  String optionsDlgMessage = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning");
63  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
64  runNewCaseWizard();
65  }
66  }
67 
68  private void runNewCaseWizard() {
69  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
70  final WizardDescriptor wizardDescriptor = new WizardDescriptor(getNewCaseWizardPanels());
71  wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
72  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.newCase.windowTitle.text"));
73  Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
74  // Workaround to ensure new case dialog is not hidden on macOS
75  dialog.setAlwaysOnTop(true);
76  dialog.setVisible(true);
77  dialog.toFront();
78  if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
79  new SwingWorker<Void, Void>() {
80  @Override
81  protected Void doInBackground() throws Exception {
82  String caseNumber = (String) wizardDescriptor.getProperty("caseNumber"); //NON-NLS
83  String examinerName = (String) wizardDescriptor.getProperty("caseExaminerName"); //NON-NLS
84  String examinerPhone = (String) wizardDescriptor.getProperty("caseExaminerPhone"); //NON-NLS
85  String examinerEmail = (String) wizardDescriptor.getProperty("caseExaminerEmail"); //NON-NLS
86  String caseNotes = (String) wizardDescriptor.getProperty("caseNotes"); //NON-NLS
87  String organizationName = (String) wizardDescriptor.getProperty("caseOrganization"); //NON-NLS
88  final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
89  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
90  CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty("caseType")]; //NON-NLS
91  Case.createAsCurrentCase(caseType, createdDirectory, new CaseDetails(caseName, caseNumber, examinerName, examinerPhone, examinerEmail, caseNotes));
92  if (CentralRepository.isEnabled()) { //if the eam is enabled we need to save the case organization information now
93  CentralRepository dbManager = CentralRepository.getInstance();
94  if (dbManager != null) {
95  CorrelationCase cRCase = dbManager.getCase(Case.getCurrentCaseThrows());
96  if (cRCase == null) {
97  cRCase = dbManager.newCase(Case.getCurrentCaseThrows());
98  }
99  if (!organizationName.isEmpty()) {
100  for (CentralRepoOrganization org : dbManager.getOrganizations()) {
101  if (org.getName().equals(organizationName)) {
102  cRCase.setOrg(org);
103  dbManager.updateCase(cRCase);
104  }
105  }
106  }
107  }
108  }
109  return null;
110  }
111 
112  @Override
113  protected void done() {
114  try {
115  get();
116  /*
117  * Run the Add Data Source wizard by invoking the Add
118  * Data Source wizard.
119  */
120  AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
121  addImageAction.actionPerformed(null);
122  } catch (InterruptedException | ExecutionException ex) {
123  if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
124  logger.log(Level.SEVERE, String.format("Error creating case %s", wizardDescriptor.getProperty("caseName")), ex); //NON-NLS
125  JOptionPane.showMessageDialog(
126  WindowManager.getDefault().getMainWindow(),
127  (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
128  NbBundle.getMessage(this.getClass(), "CaseCreateAction.msgDlg.cantCreateCase.msg"), //NON-NLS
129  JOptionPane.ERROR_MESSAGE);
130  }
131  doFailedCaseCleanup(wizardDescriptor);
132  StartupWindowProvider.getInstance().close();
133  StartupWindowProvider.getInstance().open();
134  } finally {
135  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
136  }
137  }
138  }.execute();
139  } else {
140  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
141  new Thread(() -> {
142  doFailedCaseCleanup(wizardDescriptor);
143  }).start();
144  }
145  }
146 
147  private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
148  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
149  if (createdDirectory != null) {
150  FileUtil.deleteDir(new File(createdDirectory));
151  }
152  }
153 
157  @SuppressWarnings({"unchecked", "rawtypes"})
158  private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
159  if (panels == null) {
160  panels = new WizardDescriptor.Panel[]{
161  new NewCaseWizardPanel1(),
162  new NewCaseWizardPanel2()
163  };
164  String[] steps = new String[panels.length];
165  for (int i = 0; i < panels.length; i++) {
166  Component c = panels[i].getComponent();
167  // Default step name to component name of panel. Mainly useful
168  // for getting the name of the target chooser to appear in the
169  // list of steps.
170  steps[i] = c.getName();
171  if (c instanceof JComponent) { // assume Swing components
172  JComponent jc = (JComponent) c;
173  // Sets step number of a component
174  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
175  // Sets steps names for a panel
176  jc.putClientProperty("WizardPanel_contentData", steps);
177  // Turn on subtitle creation on each step
178  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
179  // Show steps on the left side with the image on the background
180  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
181  // Turn on numbering of all steps
182  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
183  }
184  }
185  }
186  return panels;
187  }
188 
192  @Override
193  public String getName() {
194  return NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.getName.text");
195  }
196 
200  @Override
201  public String iconResource() {
202  return null;
203  }
204 
208  @Override
209  public HelpCtx getHelpCtx() {
210  return HelpCtx.DEFAULT_HELP;
211  }
212 
216  @Override
217  protected boolean asynchronous() {
218  return false;
219  }
220 }

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