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