19 package org.sleuthkit.autopsy.communications.relationships;
21 import java.util.HashMap;
22 import java.util.List;
24 import java.util.Optional;
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;
46 final class CorrelationCaseChildNodeFactory
extends ChildFactory<CorrelationCase> {
48 private static final Logger logger = Logger.getLogger(CorrelationCaseChildNodeFactory.class.getName());
50 private final Set<Account> accounts;
57 CorrelationCaseChildNodeFactory(Set<Account> accounts) {
58 this.accounts = accounts;
62 protected boolean createKeys(List<CorrelationCase> list) {
63 if (!CentralRepository.isEnabled()) {
67 CentralRepository dbInstance;
70 }
catch (CentralRepoException ex) {
71 logger.log(Level.SEVERE,
"Unable to connect to the Central Repository database.", ex);
75 Map<String, CorrelationCase> uniqueCaseMap =
new HashMap<>();
77 accounts.forEach((account) -> {
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);
87 }
catch (CentralRepoException | CorrelationAttributeNormalizationException ex) {
88 logger.log(Level.WARNING, String.format(
"Unable to getArtifactInstance for accountID: %d", account.getAccountID()), ex);
92 list.addAll(uniqueCaseMap.values());
98 protected Node createNodeForKey(CorrelationCase correlationCase) {
99 return new CaseNode(correlationCase);
112 private Optional<CorrelationAttributeInstance.Type> getCorrelationType(Account.Type accountType) throws CentralRepoException {
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));
122 return Optional.empty();
129 final class CaseNode
extends AbstractNode {
131 private final CorrelationCase correlationCase;
138 CaseNode(CorrelationCase correlationCase) {
139 super(Children.LEAF);
140 this.correlationCase = correlationCase;
142 setDisplayName(correlationCase.getDisplayName());
143 setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/briefcase.png");
147 protected Sheet createSheet() {
149 Sheet sheet =
new Sheet();
150 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
151 if (sheetSet == null) {
152 sheetSet = Sheet.createPropertiesSet();
156 sheetSet.put(
new NodeProperty<>(
"creationDate",
157 correlationCase.getTitleCreationDate(),
158 correlationCase.getTitleCreationDate(),
159 correlationCase.getCreationDate()));
static CentralRepository getInstance()