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;
47 final class CorrelationCaseChildNodeFactory
extends ChildFactory<CorrelationCase> {
49 private static final Logger logger = Logger.getLogger(CorrelationCaseChildNodeFactory.class.getName());
51 private final Set<Account> accounts;
58 CorrelationCaseChildNodeFactory(Set<Account> accounts) {
59 this.accounts = accounts;
63 protected boolean createKeys(List<CorrelationCase> list) {
64 if (!CentralRepository.isEnabled()) {
68 CentralRepository dbInstance;
71 }
catch (CentralRepoException ex) {
72 logger.log(Level.SEVERE,
"Unable to connect to the Central Repository database.", ex);
76 Map<String, CorrelationCase> uniqueCaseMap =
new HashMap<>();
78 String currentCaseName = Case.getCurrentCase().getName();
80 accounts.forEach((account) -> {
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);
92 }
catch (CentralRepoException | CorrelationAttributeNormalizationException ex) {
93 logger.log(Level.WARNING, String.format(
"Unable to getArtifactInstance for accountID: %d", account.getAccountID()), ex);
97 list.addAll(uniqueCaseMap.values());
103 protected Node createNodeForKey(CorrelationCase correlationCase) {
104 return new CaseNode(correlationCase);
117 private Optional<CorrelationAttributeInstance.Type> getCorrelationType(Account.Type accountType) throws CentralRepoException {
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));
127 return Optional.empty();
134 final class CaseNode
extends AbstractNode {
136 private final CorrelationCase correlationCase;
143 CaseNode(CorrelationCase correlationCase) {
144 super(Children.LEAF);
145 this.correlationCase = correlationCase;
147 setDisplayName(correlationCase.getDisplayName());
148 setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/briefcase.png");
152 protected Sheet createSheet() {
154 Sheet sheet =
new Sheet();
155 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
156 if (sheetSet == null) {
157 sheetSet = Sheet.createPropertiesSet();
161 sheetSet.put(
new NodeProperty<>(
"creationDate",
162 correlationCase.getTitleCreationDate(),
163 correlationCase.getTitleCreationDate(),
164 correlationCase.getCreationDate()));
static CentralRepository getInstance()