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

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