Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
MultiUserNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-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.Desktop;
22 import java.awt.event.ActionEvent;
23 import java.io.IOException;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.AbstractAction;
30 import javax.swing.Action;
31 import javax.swing.JOptionPane;
32 import javax.swing.SwingUtilities;
33 import org.openide.nodes.AbstractNode;
34 import org.openide.nodes.ChildFactory;
35 import org.openide.nodes.Children;
36 import org.openide.nodes.Node;
37 import org.openide.nodes.Sheet;
38 import org.openide.util.NbBundle.Messages;
42 
46 final class MultiUserNode extends AbstractNode {
47 
48  @Messages({"CaseNode.column.name=Name",
49  "CaseNode.column.createdTime=Created Time",
50  "CaseNode.column.metadataFilePath=Path"})
51  private static final Logger LOGGER = Logger.getLogger(MultiUserNode.class.getName());
52  private static final String LOG_FILE_NAME = "auto_ingest_log.txt";
53 
59  MultiUserNode(List<CaseMetadata> caseList) {
60  super(Children.create(new MultiUserNodeChildren(caseList), true));
61  }
62 
63  static class MultiUserNodeChildren extends ChildFactory<CaseMetadata> {
64 
65  private final List<CaseMetadata> caseList;
66 
67  MultiUserNodeChildren(List<CaseMetadata> caseList) {
68  this.caseList = caseList;
69  }
70 
71  @Override
72  protected boolean createKeys(List<CaseMetadata> list) {
73  if (caseList != null && caseList.size() > 0) {
74  list.addAll(caseList);
75  }
76  return true;
77  }
78 
79  @Override
80  protected Node createNodeForKey(CaseMetadata key) {
81  return new MultiUserCaseNode(key);
82  }
83 
84  }
85 
89  static final class MultiUserCaseNode extends AbstractNode {
90 
91  private final String caseName;
92  private final String caseCreatedDate;
93  private final String caseMetadataFilePath;
94  private final Path caseLogFilePath;
95 
96  MultiUserCaseNode(CaseMetadata multiUserCase) {
97  super(Children.LEAF);
98  caseName = multiUserCase.getCaseDisplayName();
99  caseCreatedDate = multiUserCase.getCreatedDate();
100  super.setName(caseName);
101  setName(caseName);
102  setDisplayName(caseName);
103  caseMetadataFilePath = multiUserCase.getFilePath().toString();
104  caseLogFilePath = Paths.get(multiUserCase.getCaseDirectory(), LOG_FILE_NAME);
105  }
106 
111  @Override
112  public Action getPreferredAction() {
113  return new OpenMultiUserCaseAction(caseMetadataFilePath);
114  }
115 
116  @Override
117  protected Sheet createSheet() {
118  Sheet sheet = super.createSheet();
119  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
120  if (sheetSet == null) {
121  sheetSet = Sheet.createPropertiesSet();
122  sheet.put(sheetSet);
123  }
124  sheetSet.put(new NodeProperty<>(Bundle.CaseNode_column_name(), Bundle.CaseNode_column_name(), Bundle.CaseNode_column_name(),
125  caseName));
126  sheetSet.put(new NodeProperty<>(Bundle.CaseNode_column_createdTime(), Bundle.CaseNode_column_createdTime(), Bundle.CaseNode_column_createdTime(),
127  caseCreatedDate));
128  sheetSet.put(new NodeProperty<>(Bundle.CaseNode_column_metadataFilePath(), Bundle.CaseNode_column_metadataFilePath(), Bundle.CaseNode_column_metadataFilePath(),
129  caseMetadataFilePath));
130  return sheet;
131  }
132 
133  @Override
134  public Action[] getActions(boolean context) {
135  List<Action> actions = new ArrayList<>();
136  actions.add(new OpenMultiUserCaseAction(caseMetadataFilePath)); //open case context menu option
137  actions.add(new OpenCaseLogAction(caseLogFilePath));
138  return actions.toArray(new Action[actions.size()]);
139  }
140  }
141 
142  @Messages({"MultiUserNode.OpenMultiUserCaseAction.text=Open Case"})
147  private static final class OpenMultiUserCaseAction extends AbstractAction {
148 
149  private static final long serialVersionUID = 1L;
150 
151  private final String caseMetadataFilePath;
152 
153  OpenMultiUserCaseAction(String path) {
154  super(Bundle.MultiUserNode_OpenMultiUserCaseAction_text());
155  caseMetadataFilePath = path;
156  }
157 
158  @Override
159  public void actionPerformed(ActionEvent e) {
161  MultiUserCasesDialog.getInstance().setVisible(false);
162  new Thread(
163  () -> {
164  try {
165  Case.openAsCurrentCase(caseMetadataFilePath);
166  } catch (CaseActionException ex) {
167  if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
168  LOGGER.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", caseMetadataFilePath), ex); //NON-NLS
169  MessageNotifyUtil.Message.error(ex.getCause().getLocalizedMessage());
170  }
171  SwingUtilities.invokeLater(() -> {
172  //GUI changes done back on the EDT
174  MultiUserCasesDialog.getInstance().setVisible(true);
175  });
176  }
177  }
178  ).start();
179  }
180 
181  @Override
182  public Object clone() throws CloneNotSupportedException {
183  return super.clone(); //To change body of generated methods, choose Tools | Templates.
184  }
185  }
186 
187  @Messages({"MultiUserNode.OpenCaseLogAction.text=Open Log File"})
192  private static final class OpenCaseLogAction extends AbstractAction {
193 
194  private static final long serialVersionUID = 1L;
195 
196  private final Path pathToLog;
197 
198  OpenCaseLogAction(Path caseLogFilePath) {
199  super(Bundle.MultiUserNode_OpenCaseLogAction_text());
200  pathToLog = caseLogFilePath;
201  this.setEnabled(caseLogFilePath != null && caseLogFilePath.toFile().exists());
202  }
203 
204  @Override
205  public void actionPerformed(ActionEvent e) {
206 
207  if (pathToLog != null) {
208  try {
209  if (pathToLog.toFile().exists()) {
210  Desktop.getDesktop().edit(pathToLog.toFile());
211 
212  } else {
213  JOptionPane.showMessageDialog(MultiUserCasesDialog.getInstance(), org.openide.util.NbBundle.getMessage(MultiUserNode.class, "DisplayLogDialog.cannotFindLog"),
214  org.openide.util.NbBundle.getMessage(MultiUserNode.class, "DisplayLogDialog.unableToShowLogFile"), JOptionPane.ERROR_MESSAGE);
215  }
216  } catch (IOException ex) {
217  LOGGER.log(Level.SEVERE, String.format("Error attempting to open case auto ingest log file %s", pathToLog), ex);
218  JOptionPane.showMessageDialog(MultiUserCasesDialog.getInstance(),
219  org.openide.util.NbBundle.getMessage(MultiUserNode.class, "DisplayLogDialog.cannotOpenLog"),
220  org.openide.util.NbBundle.getMessage(MultiUserNode.class, "DisplayLogDialog.unableToShowLogFile"),
221  JOptionPane.PLAIN_MESSAGE);
222  }
223  }
224  }
225 
226  @Override
227  public Object clone() throws CloneNotSupportedException {
228  return super.clone(); //To change body of generated methods, choose Tools | Templates.
229  }
230  }
231 
232 }
static void openAsCurrentCase(String caseMetadataFilePath)
Definition: Case.java:573

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.