Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OtherOccurrencesFilesTableModel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-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.centralrepository.contentviewer;
20 
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.logging.Level;
26 import javax.swing.table.AbstractTableModel;
27 import org.openide.util.NbBundle.Messages;
28 import org.apache.commons.io.FilenameUtils;
33 
38 public class OtherOccurrencesFilesTableModel extends AbstractTableModel {
39 
40  private static final long serialVersionUID = 1L;
41  private static final Logger logger = Logger.getLogger(OtherOccurrencesFilesTableModel.class.getName());
42  private final List<String> nodeKeys = new ArrayList<>();
43  private final Map<String, List<OtherOccurrenceNodeData>> nodeMap = new HashMap<>();
44 
49  // This constructor is intentionally empty.
50  }
51 
52  @Override
53  public int getColumnCount() {
54  return 1;
55  }
56 
57  @Override
58  public int getRowCount() {
59  return nodeKeys.size();
60  }
61 
62  @Messages({"OtherOccurrencesFilesTableModel.fileName=File Name",
63  "OtherOccurrencesFilesTableModel.noData=No Data."})
64  @Override
65  public String getColumnName(int colIdx) {
66  return Bundle.OtherOccurrencesFilesTableModel_fileName();
67  }
68 
69  @Override
70  public Object getValueAt(int rowIdx, int colIdx) {
71  //if anything would prevent this from working we will consider it no data for the sake of simplicity
72  if (nodeMap.isEmpty() || nodeKeys.isEmpty() || rowIdx < 0
73  || rowIdx >= nodeKeys.size() || nodeKeys.get(rowIdx) == null
74  || nodeMap.get(nodeKeys.get(rowIdx)) == null
75  || nodeMap.get(nodeKeys.get(rowIdx)).isEmpty()) {
76  return Bundle.OtherOccurrencesFilesTableModel_noData();
77  }
78  return FilenameUtils.getName(((OtherOccurrenceNodeInstanceData) nodeMap.get(nodeKeys.get(rowIdx)).get(0)).getFilePath());
79  }
80 
90  List<OtherOccurrenceNodeData> getListOfNodesForFile(int rowIdx) {
91  //if anything would prevent this from working return an empty list
92  if (nodeMap.isEmpty() || nodeKeys.isEmpty() || rowIdx < 0
93  || rowIdx >= nodeKeys.size() || nodeKeys.get(rowIdx) == null
94  || nodeMap.get(nodeKeys.get(rowIdx)) == null) {
95  return new ArrayList<>();
96  }
97  return nodeMap.get(nodeKeys.get(rowIdx));
98  }
99 
100  @Override
101  public Class<String> getColumnClass(int colIdx) {
102  return String.class;
103  }
104 
110  void addNodeData(OtherOccurrenceNodeData newNodeData) {
111  String newNodeKey = createNodeKey((OtherOccurrenceNodeInstanceData) newNodeData);//FilenameUtils.getName(((OtherOccurrenceNodeInstanceData)newNodeData).getFilePath());
112  List<OtherOccurrenceNodeData> nodeList = nodeMap.get(newNodeKey);
113  if (nodeList == null) {
114  nodeKeys.add(newNodeKey);
115  nodeList = new ArrayList<>();
116  }
117  nodeList.add(newNodeData);
118  nodeMap.put(newNodeKey, nodeList);
119  fireTableDataChanged();
120  }
121 
122  private String createNodeKey(OtherOccurrenceNodeInstanceData nodeData) {
123  String caseUUID;
124  try {
125  caseUUID = nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID();
126  } catch (CentralRepoException ignored) {
127  //non central repo nodeData won't have a correlation case
128  try {
129  caseUUID = Case.getCurrentCaseThrows().getName();
130  //place holder value will be used since correlation attribute was unavailble
131  } catch (NoCurrentCaseException ex) {
132  logger.log(Level.WARNING, "Unable to get current case", ex);
133  caseUUID = DataContentViewerOtherCases.getPlaceholderUUID();
134  }
135  }
136  return nodeData.getCaseName() + nodeData.getDataSourceName() + nodeData.getDeviceID() + nodeData.getFilePath() + caseUUID;
137  }
138 
142  void clearTable() {
143  nodeKeys.clear();
144  nodeMap.clear();
145  fireTableDataChanged();
146  }
147 
148 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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