Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
CorrelationCaseChildNodeFactory.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2020 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.communications.relationships;
20 
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Optional;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.ChildFactory;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.nodes.Sheet;
40 import org.sleuthkit.datamodel.Account;
42 
47 final class CorrelationCaseChildNodeFactory extends ChildFactory<CorrelationCase> {
48 
49  private static final Logger logger = Logger.getLogger(CorrelationCaseChildNodeFactory.class.getName());
50 
51  private final Set<Account> accounts;
52 
58  CorrelationCaseChildNodeFactory(Set<Account> accounts) {
59  this.accounts = accounts;
60  }
61 
62  @Override
63  protected boolean createKeys(List<CorrelationCase> list) {
64  if (!CentralRepository.isEnabled()) {
65  return true;
66  }
67 
68  CentralRepository dbInstance;
69  try {
70  dbInstance = CentralRepository.getInstance();
71  } catch (CentralRepoException ex) {
72  logger.log(Level.SEVERE, "Unable to connect to the Central Repository database.", ex); //NON-NLS
73  return false;
74  }
75 
76  Map<String, CorrelationCase> uniqueCaseMap = new HashMap<>();
77 
78  String currentCaseName = Case.getCurrentCase().getName();
79 
80  accounts.forEach((account) -> {
81  try {
82  Optional<CorrelationAttributeInstance.Type> optCorrelationType = getCorrelationType(account.getAccountType());
83  if (optCorrelationType.isPresent()) {
84  List<CorrelationAttributeInstance> correlationInstances = dbInstance.getArtifactInstancesByTypeValue(optCorrelationType.get(), account.getTypeSpecificID());
85  correlationInstances.forEach((correlationInstance) -> {
86  CorrelationCase correlationCase = correlationInstance.getCorrelationCase();
87  if(!correlationCase.getCaseUUID().equals(currentCaseName)) {
88  uniqueCaseMap.put(correlationCase.getCaseUUID(), correlationCase);
89  }
90  });
91  }
92  } catch (CentralRepoException | CorrelationAttributeNormalizationException ex) {
93  logger.log(Level.WARNING, String.format("Unable to getArtifactInstance for accountID: %d", account.getAccountID()), ex); //NON-NLS
94  }
95  });
96 
97  list.addAll(uniqueCaseMap.values());
98 
99  return true;
100  }
101 
102  @Override
103  protected Node createNodeForKey(CorrelationCase correlationCase) {
104  return new CaseNode(correlationCase);
105  }
106 
117  private Optional<CorrelationAttributeInstance.Type> getCorrelationType(Account.Type accountType) throws CentralRepoException {
118 
119  String accountTypeStr = accountType.getTypeName();
120  if (Account.Type.DEVICE.getTypeName().equalsIgnoreCase(accountTypeStr) == false) {
121  Optional<CentralRepoAccount.CentralRepoAccountType> optCrAccountType = CentralRepository.getInstance().getAccountTypeByName(accountTypeStr);
122  if (optCrAccountType.isPresent()) {
123  int corrTypeId = optCrAccountType.get().getCorrelationTypeId();
124  return Optional.of(CentralRepository.getInstance().getCorrelationTypeById(corrTypeId));
125  }
126  }
127  return Optional.empty();
128  }
129 
134  final class CaseNode extends AbstractNode {
135 
136  private final CorrelationCase correlationCase;
137 
143  CaseNode(CorrelationCase correlationCase) {
144  super(Children.LEAF);
145  this.correlationCase = correlationCase;
146 
147  setDisplayName(correlationCase.getDisplayName());
148  setIconBaseWithExtension("org/sleuthkit/autopsy/images/briefcase.png"); //NON-NLS
149  }
150 
151  @Override
152  protected Sheet createSheet() {
153  super.createSheet();
154  Sheet sheet = new Sheet();
155  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
156  if (sheetSet == null) {
157  sheetSet = Sheet.createPropertiesSet();
158  sheet.put(sheetSet);
159  }
160 
161  sheetSet.put(new NodeProperty<>("creationDate", //NON-NLS
162  correlationCase.getTitleCreationDate(),
163  correlationCase.getTitleCreationDate(),
164  correlationCase.getCreationDate()));
165 
166  return sheet;
167  }
168  }
169 
170 }

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