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

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