Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OtherOccurrencesDataSourcesTableModel.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 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 
22 import java.util.LinkedHashSet;
23 import java.util.Objects;
24 import java.util.Set;
25 import java.util.logging.Level;
26 import javax.swing.table.AbstractTableModel;
27 import org.openide.util.NbBundle;
33 
38 final class OtherOccurrencesDataSourcesTableModel extends AbstractTableModel {
39 
40  private static final long serialVersionUID = 1L;
41  private static final Logger logger = Logger.getLogger(OtherOccurrencesDataSourcesTableModel.class.getName());
42  private final Set<DataSourceColumnItem> dataSourceSet = new LinkedHashSet<>();
43 
47  OtherOccurrencesDataSourcesTableModel() {
48  // This constructor is intentionally empty.
49  }
50 
51  @Override
52  public int getColumnCount() {
53  return 1;
54  }
55 
56  @Override
57  public int getRowCount() {
58  return dataSourceSet.size();
59  }
60 
61  @NbBundle.Messages({"OtherOccurrencesDataSourcesTableModel.dataSourceName=Data Source Name",
62  "OtherOccurrencesDataSourcesTableModel.noData=No Data."})
63  @Override
64  public String getColumnName(int colIdx) {
65  return Bundle.OtherOccurrencesDataSourcesTableModel_dataSourceName();
66  }
67 
68  @Override
69  public Object getValueAt(int rowIdx, int colIdx) {
70  //if anything would prevent this from working we will consider it no data for the sake of simplicity
71  if (dataSourceSet.isEmpty() || rowIdx < 0
72  || rowIdx >= dataSourceSet.size()
73  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
74  return Bundle.OtherOccurrencesDataSourcesTableModel_noData();
75  }
76  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getDataSourceName();
77  }
78 
87  String getDeviceIdForRow(int rowIdx) {
88  //if anything would prevent this from working we will return an empty string
89  if (dataSourceSet.isEmpty() || rowIdx < 0
90  || rowIdx >= dataSourceSet.size()
91  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
92  return "";
93  }
94  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getDeviceId();
95  }
96 
106  String getCaseUUIDForRow(int rowIdx) {
107  //if anything would prevent this from working we will return an empty string
108  if (dataSourceSet.isEmpty() || rowIdx < 0
109  || rowIdx >= dataSourceSet.size()
110  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
111  return "";
112  }
113  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getCaseUUID();
114  }
115 
124  String getCaseNameForRow(int rowIdx) {
125  //if anything would prevent this from working we will return an empty string
126  if (dataSourceSet.isEmpty() || rowIdx < 0
127  || rowIdx >= dataSourceSet.size()
128  || !(dataSourceSet.toArray()[rowIdx] instanceof DataSourceColumnItem)) {
129  return "";
130  }
131  return ((DataSourceColumnItem) dataSourceSet.toArray()[rowIdx]).getCaseName();
132  }
133 
134  @Override
135  public Class<String> getColumnClass(int colIdx) {
136  return String.class;
137  }
138 
144  void addNodeData(NodeData newNodeData) {
145  String caseUUID;
146  try {
147  caseUUID = newNodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID();
148  } catch (CentralRepoException ignored) {
149  //non central repo nodeData won't have a correlation case
150  try {
151  caseUUID = Case.getCurrentCaseThrows().getName();
152  //place holder value will be used since correlation attribute was unavailble
153  } catch (NoCurrentCaseException ex) {
154  logger.log(Level.WARNING, "Unable to get current case", ex);
155  caseUUID = OtherOccurrences.getPlaceholderUUID();
156  }
157  }
158  dataSourceSet.add(new DataSourceColumnItem(newNodeData.getCaseName(), newNodeData.getDeviceID(), newNodeData.getDataSourceName(), caseUUID));
159  fireTableDataChanged();
160  }
161 
165  void clearTable() {
166  dataSourceSet.clear();
167  fireTableDataChanged();
168  }
169 
174  private final class DataSourceColumnItem {
175 
176  private final String caseName;
177  private final String deviceId;
178  private final String dataSourceName;
179  private final String caseUUID;
180 
191  private DataSourceColumnItem(String caseName, String deviceId, String dataSourceName, String caseUUID) {
192  this.caseName = caseName;
193  this.deviceId = deviceId;
194  this.dataSourceName = dataSourceName;
195  this.caseUUID = caseUUID;
196  }
197 
203  private String getDeviceId() {
204  return deviceId;
205  }
206 
212  private String getDataSourceName() {
213  return dataSourceName;
214  }
215 
221  private String getCaseName() {
222  return caseName;
223  }
224 
230  private String getCaseUUID() {
231  return caseUUID;
232  }
233 
234  @Override
235  public boolean equals(Object other) {
236  return other instanceof DataSourceColumnItem
237  && caseName.equals(((DataSourceColumnItem) other).getCaseName())
238  && dataSourceName.equals(((DataSourceColumnItem) other).getDataSourceName())
239  && deviceId.equals(((DataSourceColumnItem) other).getDeviceId())
240  && caseUUID.equals(((DataSourceColumnItem) other).getCaseUUID());
241  }
242 
243  @Override
244  public int hashCode() {
245  return Objects.hash(caseName, deviceId, dataSourceName, caseUUID);
246  }
247  }
248 
249 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.