Autopsy  4.19.0
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;
39 import org.sleuthkit.datamodel.Account;
41 
46 final class CorrelationCaseChildNodeFactory extends ChildFactory<CorrelationCase> {
47 
48  private static final Logger logger = Logger.getLogger(CorrelationCaseChildNodeFactory.class.getName());
49 
50  private final Set<Account> accounts;
51 
57  CorrelationCaseChildNodeFactory(Set<Account> accounts) {
58  this.accounts = accounts;
59  }
60 
61  @Override
62  protected boolean createKeys(List<CorrelationCase> list) {
63  if (!CentralRepository.isEnabled()) {
64  return true;
65  }
66 
67  CentralRepository dbInstance;
68  try {
69  dbInstance = CentralRepository.getInstance();
70  } catch (CentralRepoException ex) {
71  logger.log(Level.SEVERE, "Unable to connect to the Central Repository database.", ex); //NON-NLS
72  return false;
73  }
74 
75  Map<String, CorrelationCase> uniqueCaseMap = new HashMap<>();
76 
77  accounts.forEach((account) -> {
78  try {
79  Optional<CorrelationAttributeInstance.Type> optCorrelationType = getCorrelationType(account.getAccountType());
80  if (optCorrelationType.isPresent()) {
81  List<CorrelationAttributeInstance> correlationInstances = dbInstance.getArtifactInstancesByTypeValue(optCorrelationType.get(), account.getTypeSpecificID());
82  correlationInstances.forEach((correlationInstance) -> {
83  CorrelationCase correlationCase = correlationInstance.getCorrelationCase();
84  uniqueCaseMap.put(correlationCase.getCaseUUID(), correlationCase);
85  });
86  }
87  } catch (CentralRepoException | CorrelationAttributeNormalizationException ex) {
88  logger.log(Level.WARNING, String.format("Unable to getArtifactInstance for accountID: %d", account.getAccountID()), ex); //NON-NLS
89  }
90  });
91 
92  list.addAll(uniqueCaseMap.values());
93 
94  return true;
95  }
96 
97  @Override
98  protected Node createNodeForKey(CorrelationCase correlationCase) {
99  return new CaseNode(correlationCase);
100  }
101 
112  private Optional<CorrelationAttributeInstance.Type> getCorrelationType(Account.Type accountType) throws CentralRepoException {
113 
114  String accountTypeStr = accountType.getTypeName();
115  if (Account.Type.DEVICE.getTypeName().equalsIgnoreCase(accountTypeStr) == false) {
116  Optional<CentralRepoAccount.CentralRepoAccountType> optCrAccountType = CentralRepository.getInstance().getAccountTypeByName(accountTypeStr);
117  if (optCrAccountType.isPresent()) {
118  int corrTypeId = optCrAccountType.get().getCorrelationTypeId();
119  return Optional.of(CentralRepository.getInstance().getCorrelationTypeById(corrTypeId));
120  }
121  }
122  return Optional.empty();
123  }
124 
129  final class CaseNode extends AbstractNode {
130 
131  private final CorrelationCase correlationCase;
132 
138  CaseNode(CorrelationCase correlationCase) {
139  super(Children.LEAF);
140  this.correlationCase = correlationCase;
141 
142  setDisplayName(correlationCase.getDisplayName());
143  setIconBaseWithExtension("org/sleuthkit/autopsy/images/briefcase.png"); //NON-NLS
144  }
145 
146  @Override
147  protected Sheet createSheet() {
148  super.createSheet();
149  Sheet sheet = new Sheet();
150  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
151  if (sheetSet == null) {
152  sheetSet = Sheet.createPropertiesSet();
153  sheet.put(sheetSet);
154  }
155 
156  sheetSet.put(new NodeProperty<>("creationDate", //NON-NLS
157  correlationCase.getTitleCreationDate(),
158  correlationCase.getTitleCreationDate(),
159  correlationCase.getCreationDate()));
160 
161  return sheet;
162  }
163  }
164 
165 }

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.