Autopsy  4.11.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 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;
39 
44 final class CorrelationCaseChildNodeFactory extends ChildFactory<CorrelationCase> {
45 
46  private static final Logger logger = Logger.getLogger(CorrelationCaseChildNodeFactory.class.getName());
47 
48  private Map<Integer, CorrelationAttributeInstance.Type> correlationTypeMap;
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 (!EamDb.isEnabled()) {
63  return true;
64  }
65 
66  EamDb dbInstance;
67  try {
68  dbInstance = EamDb.getInstance();
69  } catch (EamDbException 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 (EamDbException | 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 EamDbException {
112  if (correlationTypeMap == null) {
113  correlationTypeMap = new HashMap<>();
114  List<CorrelationAttributeInstance.Type> correcationTypeList = CorrelationAttributeInstance.getDefaultCorrelationTypes();
115  correcationTypeList.forEach((type) -> {
116  correlationTypeMap.put(type.getId(), type);
117  });
118  }
119 
120  if (Account.Type.EMAIL.equals(accountType)) {
121  return correlationTypeMap.get(CorrelationAttributeInstance.EMAIL_TYPE_ID);
122  } else if (Account.Type.PHONE.equals(accountType)) {
123  return correlationTypeMap.get(CorrelationAttributeInstance.PHONE_TYPE_ID);
124  } else {
125  return null;
126  }
127  }
128 
133  final class CaseNode extends AbstractNode {
134 
135  private final CorrelationCase correlationCase;
136 
142  CaseNode(CorrelationCase correlationCase) {
143  super(Children.LEAF);
144  this.correlationCase = correlationCase;
145 
146  setDisplayName(correlationCase.getDisplayName());
147  setIconBaseWithExtension("org/sleuthkit/autopsy/images/briefcase.png"); //NON-NLS
148  }
149 
150  @Override
151  protected Sheet createSheet() {
152  super.createSheet();
153  Sheet sheet = new Sheet();
154  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
155  if (sheetSet == null) {
156  sheetSet = Sheet.createPropertiesSet();
157  sheet.put(sheetSet);
158  }
159 
160  sheetSet.put(new NodeProperty<>("creationDate", //NON-NLS
161  correlationCase.getTitleCreationDate(),
162  correlationCase.getTitleCreationDate(),
163  correlationCase.getCreationDate()));
164 
165  return sheet;
166  }
167  }
168 
169 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.