Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OtherOccurrenceOneTypeWorker.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2021 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.Collection;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28 import java.util.logging.Level;
29 import javax.swing.SwingWorker;
30 import org.apache.commons.lang3.StringUtils;
42 import org.sleuthkit.datamodel.AbstractFile;
43 
50 class OtherOccurrenceOneTypeWorker extends SwingWorker<OneTypeData, Void> {
51 
52  private static final Logger logger = Logger.getLogger(OtherOccurrenceOneTypeWorker.class.getName());
53 
54  private final CorrelationAttributeInstance.Type aType;
55  private final String value;
56  private final AbstractFile file;
57  private final String deviceId;
58  private final String dataSourceName;
59 
69  OtherOccurrenceOneTypeWorker(CorrelationAttributeInstance.Type aType, String value, AbstractFile file, String deviceId, String dataSourceName) {
70  this.aType = aType;
71  this.value = value;
72  this.file = file;
73  this.deviceId = deviceId;
74  this.dataSourceName = dataSourceName;
75  }
76 
77  @Override
78  protected OneTypeData doInBackground() throws Exception {
79  Map<String, CorrelationCase> caseNames = new HashMap<>();
80  int totalCount = 0;
81  Set<String> dataSources = new HashSet<>();
82  Collection<CorrelationAttributeInstance> correlationAttributesToAdd = new ArrayList<>();
83  String earliestDate = OtherOccurrences.getEarliestCaseDate();
84  OneTypeData results = null;
85 
86  if (CentralRepository.isEnabled()) {
87  List<CorrelationAttributeInstance> instances;
88  instances = CentralRepository.getInstance().getArtifactInstancesByTypeValue(aType, value);
89  HashMap<UniquePathKey, NodeData> nodeDataMap = new HashMap<>();
90  String caseUUID = Case.getCurrentCase().getName();
91  for (CorrelationAttributeInstance artifactInstance : instances) {
92  if (isCancelled()) {
93  break;
94  }
95 
96  // Only add the attribute if it isn't the object the user selected.
97  // We consider it to be a different object if at least one of the following is true:
98  // - the case UUID is different
99  // - the data source name is different
100  // - the data source device ID is different
101  // - the file path is different
102  if (artifactInstance.getCorrelationCase().getCaseUUID().equals(caseUUID)
103  && (!StringUtils.isBlank(dataSourceName) && artifactInstance.getCorrelationDataSource().getName().equals(dataSourceName))
104  && (!StringUtils.isBlank(deviceId) && artifactInstance.getCorrelationDataSource().getDeviceID().equals(deviceId))
105  && (file != null && artifactInstance.getFilePath().equalsIgnoreCase(file.getParentPath() + file.getName()))) {
106 
107  continue;
108  }
109  correlationAttributesToAdd.add(artifactInstance);
110  NodeData newNode = new NodeData(artifactInstance, aType, value);
111  UniquePathKey uniquePathKey = new UniquePathKey(newNode);
112  nodeDataMap.put(uniquePathKey, newNode);
113  }
114 
115  for (NodeData nodeData : nodeDataMap.values()) {
116  if (isCancelled()) {
117  break;
118  }
119 
120  if (nodeData.isCentralRepoNode()) {
121  try {
122  dataSources.add(OtherOccurrences.makeDataSourceString(nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID(), nodeData.getDeviceID(), nodeData.getDataSourceName()));
123  caseNames.put(nodeData.getCorrelationAttributeInstance().getCorrelationCase().getCaseUUID(), nodeData.getCorrelationAttributeInstance().getCorrelationCase());
124  } catch (CentralRepoException ex) {
125  logger.log(Level.WARNING, "Unable to get correlation case for displaying other occurrence for case: " + nodeData.getCaseName(), ex);
126  }
127  } else {
128  try {
129  dataSources.add(OtherOccurrences.makeDataSourceString(Case.getCurrentCaseThrows().getName(), nodeData.getDeviceID(), nodeData.getDataSourceName()));
130  caseNames.put(Case.getCurrentCaseThrows().getName(), new CorrelationCase(Case.getCurrentCaseThrows().getName(), Case.getCurrentCaseThrows().getDisplayName()));
131  } catch (NoCurrentCaseException ex) {
132  logger.log(Level.WARNING, "No current case open for other occurrences", ex);
133  }
134  }
135  totalCount++;
136  }
137  }
138 
139  if (!isCancelled()) {
140  results = new OneTypeData(caseNames, totalCount, dataSources.size(), earliestDate, correlationAttributesToAdd);
141  }
142 
143  return results;
144  }
145 
149  static final class OneTypeData {
150 
151  private final Map<String, CorrelationCase> caseNames;
152  private final int totalCount;
153  private final int dataSourceCount;
154  private final Collection<CorrelationAttributeInstance> correlationAttributesToAdd;
155  private final String earliestCaseDate;
156 
168  OneTypeData(Map<String, CorrelationCase> caseNames, int totalCount, int dataSourceCount, String earliestCaseDate, Collection<CorrelationAttributeInstance> correlationAttributesToAdd) {
169  this.caseNames = caseNames;
170  this.totalCount = totalCount;
171  this.dataSourceCount = dataSourceCount;
172  this.correlationAttributesToAdd = correlationAttributesToAdd;
173  this.earliestCaseDate = earliestCaseDate;
174  }
175 
176  public Map<String, CorrelationCase> getCaseNames() {
177  return caseNames;
178  }
179 
180  public int getTotalCount() {
181  return totalCount;
182  }
183 
184  public int getDataSourceCount() {
185  return dataSourceCount;
186  }
187 
188  public Collection<CorrelationAttributeInstance> getCorrelationAttributesToAdd() {
189  return correlationAttributesToAdd;
190  }
191 
192  public String getEarliestCaseDate() {
193  return earliestCaseDate;
194  }
195  }
196 }

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