Autopsy  4.21.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, WindowManager.getDefault().getMainWindow());
74  dialog.setVisible(true);
75  dialog.toFront();
76  if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
77  new SwingWorker<Void, Void>() {
78  @Override
79  protected Void doInBackground() throws Exception {
80  String caseNumber = (String) wizardDescriptor.getProperty("caseNumber"); //NON-NLS
81  String examinerName = (String) wizardDescriptor.getProperty("caseExaminerName"); //NON-NLS
82  String examinerPhone = (String) wizardDescriptor.getProperty("caseExaminerPhone"); //NON-NLS
83  String examinerEmail = (String) wizardDescriptor.getProperty("caseExaminerEmail"); //NON-NLS
84  String caseNotes = (String) wizardDescriptor.getProperty("caseNotes"); //NON-NLS
85  String organizationName = (String) wizardDescriptor.getProperty("caseOrganization"); //NON-NLS
86  final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
87  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
88  CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty("caseType")]; //NON-NLS
89  Case.createAsCurrentCase(caseType, createdDirectory, new CaseDetails(caseName, caseNumber, examinerName, examinerPhone, examinerEmail, caseNotes));
90  if (CentralRepository.isEnabled()) { //if the eam is enabled we need to save the case organization information now
91  CentralRepository dbManager = CentralRepository.getInstance();
92  if (dbManager != null) {
93  CorrelationCase cRCase = dbManager.getCase(Case.getCurrentCaseThrows());
94  if (cRCase == null) {
95  cRCase = dbManager.newCase(Case.getCurrentCaseThrows());
96  }
97  if (!organizationName.isEmpty()) {
98  for (CentralRepoOrganization org : dbManager.getOrganizations()) {
99  if (org.getName().equals(organizationName)) {
100  cRCase.setOrg(org);
101  dbManager.updateCase(cRCase);
102  }
103  }
104  }
105  }
106  }
107  return null;
108  }
109 
110  @Override
111  protected void done() {
112  try {
113  get();
114  /*
115  * Run the Add Data Source wizard by invoking the Add
116  * Data Source wizard.
117  */
118  AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
119  addImageAction.actionPerformed(null);
120  } catch (InterruptedException | ExecutionException ex) {
121  if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
122  logger.log(Level.SEVERE, String.format("Error creating case %s", wizardDescriptor.getProperty("caseName")), ex); //NON-NLS
123  JOptionPane.showMessageDialog(
124  WindowManager.getDefault().getMainWindow(),
125  (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
126  NbBundle.getMessage(this.getClass(), "CaseCreateAction.msgDlg.cantCreateCase.msg"), //NON-NLS
127  JOptionPane.ERROR_MESSAGE);
128  }
129  doFailedCaseCleanup(wizardDescriptor);
130  StartupWindowProvider.getInstance().close();
131  StartupWindowProvider.getInstance().open();
132  } finally {
133  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
134  }
135  }
136  }.execute();
137  } else {
138  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
139  new Thread(() -> {
140  doFailedCaseCleanup(wizardDescriptor);
141  }).start();
142  }
143  }
144 
145  private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
146  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
147  if (createdDirectory != null) {
148  FileUtil.deleteDir(new File(createdDirectory));
149  }
150  }
151 
155  @SuppressWarnings({"unchecked", "rawtypes"})
156  private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
157  if (panels == null) {
158  panels = new WizardDescriptor.Panel[]{
159  new NewCaseWizardPanel1(),
160  new NewCaseWizardPanel2()
161  };
162  String[] steps = new String[panels.length];
163  for (int i = 0; i < panels.length; i++) {
164  Component c = panels[i].getComponent();
165  // Default step name to component name of panel. Mainly useful
166  // for getting the name of the target chooser to appear in the
167  // list of steps.
168  steps[i] = c.getName();
169  if (c instanceof JComponent) { // assume Swing components
170  JComponent jc = (JComponent) c;
171  // Sets step number of a component
172  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
173  // Sets steps names for a panel
174  jc.putClientProperty("WizardPanel_contentData", steps);
175  // Turn on subtitle creation on each step
176  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
177  // Show steps on the left side with the image on the background
178  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
179  // Turn on numbering of all steps
180  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
181  }
182  }
183  }
184  return panels;
185  }
186 
190  @Override
191  public String getName() {
192  return NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.getName.text");
193  }
194 
198  @Override
199  public String iconResource() {
200  return null;
201  }
202 
206  @Override
207  public HelpCtx getHelpCtx() {
208  return HelpCtx.DEFAULT_HELP;
209  }
210 
214  @Override
215  protected boolean asynchronous() {
216  return false;
217  }
218 }

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.