Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
SelectionNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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;
20 
21 import com.google.common.collect.Iterables;
22 import com.google.common.collect.Sets;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import java.util.stream.Collectors;
28 import org.openide.nodes.AbstractNode;
29 import org.openide.nodes.ChildFactory;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
32 import org.openide.util.Lookup;
33 import org.openide.util.lookup.Lookups;
35 import org.sleuthkit.datamodel.AccountDeviceInstance;
36 import org.sleuthkit.datamodel.BlackboardArtifact;
37 import org.sleuthkit.datamodel.CommunicationsFilter;
38 import org.sleuthkit.datamodel.CommunicationsManager;
39 import org.sleuthkit.datamodel.Content;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
48 final class SelectionNode extends AbstractNode {
49 
50  private SelectionNode(Children children, Lookup lookup) {
51  super(children, lookup);
52  }
53 
54  static SelectionNode createFromAccountsAndRelationships(
55  Set<Content> edgeRelationshipArtifacts,
56  Set<AccountDeviceInstanceKey> accountDeviceInstanceKeys,
57  CommunicationsFilter filter,
58  CommunicationsManager commsManager) {
59 
60  Set<AccountDeviceInstance> accountDeviceInstances = accountDeviceInstanceKeys.stream()
61  .map(AccountDeviceInstanceKey::getAccountDeviceInstance)
62  .collect(Collectors.toSet());
63 
64  SelectionNode node = new SelectionNode(Children.create(
65  new RelationshipChildren(
66  edgeRelationshipArtifacts,
67  accountDeviceInstances,
68  commsManager,
69  filter),
70  true), Lookups.fixed(accountDeviceInstanceKeys.toArray()));
71 
72  //This is not good for internationalization!!!
73  String name = "";
74  final int accounts = accountDeviceInstances.size();
75  if (accounts > 1) {
76  name = accounts + " accounts";
77  } else if (accounts == 1) {
78  name = Iterables.getOnlyElement(accountDeviceInstances).getAccount().getTypeSpecificID();
79  }
80 
81  final int edges = edgeRelationshipArtifacts.size();
82 
83  if (edges > 0) {
84  name = name + (name.isEmpty() ? "" : " and ") + edges + " relationship" + (edges > 1 ? "s" : "");
85  }
86 
87  node.setDisplayName(name);
88  return node;
89  }
90 
91  static SelectionNode createFromAccounts(
92  Set<AccountDeviceInstanceKey> accountDeviceInstances,
93  CommunicationsFilter filter,
94  CommunicationsManager commsManager) {
95 
96  return createFromAccountsAndRelationships(Collections.emptySet(), accountDeviceInstances, filter, commsManager);
97  }
98 
102  private static class RelationshipChildren extends ChildFactory<Content> {
103 
104  static final private Logger logger = Logger.getLogger(RelationshipChildren.class.getName());
105 
106  private final Set<Content> edgeRelationshipArtifacts;
107 
108  private final Set<AccountDeviceInstance> accountDeviceInstances;
109 
110  private final CommunicationsManager commsManager;
111  private final CommunicationsFilter filter;
112 
113  private RelationshipChildren(Set<Content> selectedEdgeRelationshipSources, Set<AccountDeviceInstance> selecedAccountDeviceInstances, CommunicationsManager commsManager, CommunicationsFilter filter) {
114  this.edgeRelationshipArtifacts = selectedEdgeRelationshipSources;
115  this.accountDeviceInstances = selecedAccountDeviceInstances;
116  this.commsManager = commsManager;
117  this.filter = filter;
118  }
119 
120  @Override
121  protected boolean createKeys(List<Content> list) {
122  try {
123  final Set<Content> relationshipSources = commsManager.getRelationshipSources(accountDeviceInstances, filter);
124  list.addAll(Sets.union(relationshipSources, edgeRelationshipArtifacts));
125  } catch (TskCoreException ex) {
126  logger.log(Level.SEVERE, "Error getting communications", ex);
127  }
128  return true;
129  }
130 
131  @Override
132  protected Node createNodeForKey(Content content) {
133  if (content instanceof BlackboardArtifact) {
134  return new RelationshipNode((BlackboardArtifact) content);
135  } else {
136  throw new UnsupportedOperationException("Cannot create a RelationshipNode for non BlackboardArtifact content.");
137  }
138  }
139  }
140 }
RelationshipChildren(Set< Content > selectedEdgeRelationshipSources, Set< AccountDeviceInstance > selecedAccountDeviceInstances, CommunicationsManager commsManager, CommunicationsFilter filter)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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