19 package org.sleuthkit.autopsy.centralrepository.contentviewer;
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;
28 import java.util.logging.Level;
29 import javax.swing.SwingWorker;
30 import org.apache.commons.lang3.StringUtils;
50 class OtherOccurrenceOneTypeWorker
extends SwingWorker<OneTypeData, Void> {
52 private static final Logger logger = Logger.getLogger(OtherOccurrenceOneTypeWorker.class.getName());
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;
69 OtherOccurrenceOneTypeWorker(CorrelationAttributeInstance.Type aType, String value, AbstractFile file, String deviceId, String dataSourceName) {
73 this.deviceId = deviceId;
74 this.dataSourceName = dataSourceName;
78 protected OneTypeData doInBackground() throws Exception {
79 Map<String, CorrelationCase> caseNames =
new HashMap<>();
81 Set<String> dataSources =
new HashSet<>();
82 Collection<CorrelationAttributeInstance> correlationAttributesToAdd =
new ArrayList<>();
83 String earliestDate = OtherOccurrences.getEarliestCaseDate();
84 OneTypeData results = null;
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) {
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()))) {
109 correlationAttributesToAdd.add(artifactInstance);
110 NodeData newNode =
new NodeData(artifactInstance, aType, value);
111 UniquePathKey uniquePathKey =
new UniquePathKey(newNode);
112 nodeDataMap.put(uniquePathKey, newNode);
115 for (NodeData nodeData : nodeDataMap.values()) {
120 if (nodeData.isCentralRepoNode()) {
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);
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);
139 if (!isCancelled()) {
140 results =
new OneTypeData(caseNames, totalCount, dataSources.size(), earliestDate, correlationAttributesToAdd);
149 static final class OneTypeData {
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;
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;
176 public Map<String, CorrelationCase> getCaseNames() {
180 public int getTotalCount() {
184 public int getDataSourceCount() {
185 return dataSourceCount;
188 public Collection<CorrelationAttributeInstance> getCorrelationAttributesToAdd() {
189 return correlationAttributesToAdd;
192 public String getEarliestCaseDate() {
193 return earliestCaseDate;