Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
SelectionInfo.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 obt ain 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.HashSet;
22 import java.util.Set;
23 import java.util.logging.Level;
27 import org.sleuthkit.datamodel.Account;
28 import org.sleuthkit.datamodel.AccountDeviceInstance;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
30 import org.sleuthkit.datamodel.CommunicationsFilter;
31 import org.sleuthkit.datamodel.CommunicationsManager;
32 import org.sleuthkit.datamodel.Content;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
39 public final class SelectionInfo {
40 
41  private static final Logger logger = Logger.getLogger(SelectionInfo.class.getName());
42 
43  private final Set<AccountDeviceInstance> selectedNodes;
44  private final Set<GraphEdge> selectedEdges;
45  private final CommunicationsFilter communicationFilter;
46  private final Set<Account> accounts;
47 
48  private Set<BlackboardArtifact> accountArtifacts = null;
49 
57  public SelectionInfo(Set<AccountDeviceInstance> selectedNodes, Set<GraphEdge> selectedEdges,
58  CommunicationsFilter communicationFilter) {
59  this.selectedNodes = selectedNodes;
60  this.selectedEdges = selectedEdges;
61  this.communicationFilter = communicationFilter;
62 
63  accounts = new HashSet<>();
64  selectedNodes.forEach((instance) -> {
65  accounts.add(instance.getAccount());
66  });
67  }
68 
74  public Set<AccountDeviceInstance> getSelectedNodes() {
75  return selectedNodes;
76  }
77 
83  public Set<GraphEdge> getSelectedEdges() {
84  return selectedEdges;
85  }
86 
92  public CommunicationsFilter getCommunicationsFilter() {
93  return communicationFilter;
94  }
95 
96  public Set<Account> getAccounts() {
97  return accounts;
98  }
99 
107  Set<Content> getRelationshipSources() throws TskCoreException {
108 
109  CommunicationsManager communicationManager;
110  try {
111  communicationManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
112  } catch (NoCurrentCaseException ex) {
113  throw new TskCoreException("Failed to get current case", ex);
114  }
115 
116  Set<Content> relationshipSources = new HashSet<>();
117  try {
118  // Add all nodes
119  relationshipSources.addAll(communicationManager.getRelationshipSources(getSelectedNodes(), getCommunicationsFilter()));
120 
121  // Add all edges. For edges, the relationship has to include both endpoints
122  for (SelectionInfo.GraphEdge edge : getSelectedEdges()) {
123  relationshipSources.addAll(communicationManager.getRelationshipSources(edge.getStartNode(),
124  edge.getEndNode(), getCommunicationsFilter()));
125  }
126  } catch (TskCoreException ex) {
127  logger.log(Level.SEVERE, "Failed to get relationships from case database.", ex); //NON-NLS
128 
129  }
130  return relationshipSources;
131  }
132 
133  public Set<BlackboardArtifact> getArtifacts() {
134  if (accountArtifacts == null) {
135  accountArtifacts = new HashSet<>();
136 
137  try {
138  final Set<Content> relationshipSources = getRelationshipSources();
139  relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
140  accountArtifacts.add((BlackboardArtifact) content);
141  });
142  } catch (TskCoreException ex) {
143  logger.log(Level.SEVERE, "Failed to load relationship sources.", ex); //NON-NLS
144  return accountArtifacts;
145  }
146  }
147 
148  return accountArtifacts;
149  }
150 
154  public static class GraphEdge {
155 
156  AccountDeviceInstance startNode;
157  AccountDeviceInstance endNode;
158 
159  public GraphEdge(AccountDeviceInstance startNode, AccountDeviceInstance endNode) {
160  this.startNode = startNode;
161  this.endNode = endNode;
162  }
163 
164  public AccountDeviceInstance getStartNode() {
165  return startNode;
166  }
167 
168  public AccountDeviceInstance getEndNode() {
169  return endNode;
170  }
171  }
172 }
SelectionInfo(Set< AccountDeviceInstance > selectedNodes, Set< GraphEdge > selectedEdges, CommunicationsFilter communicationFilter)
GraphEdge(AccountDeviceInstance startNode, AccountDeviceInstance endNode)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Fri Sep 30 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.