Autopsy  4.12.0
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;
28 import org.sleuthkit.datamodel.Account;
29 import org.sleuthkit.datamodel.AccountDeviceInstance;
30 import org.sleuthkit.datamodel.BlackboardArtifact;
31 import org.sleuthkit.datamodel.CommunicationsFilter;
32 import org.sleuthkit.datamodel.CommunicationsManager;
33 import org.sleuthkit.datamodel.Content;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
40 public final class SelectionInfo {
41 
42  private static final Logger logger = Logger.getLogger(SelectionInfo.class.getName());
43 
44  private final Set<AccountDeviceInstance> selectedNodes;
45  private final Set<GraphEdge> selectedEdges;
46  private final CommunicationsFilter communicationFilter;
47  private final Set<Account> accounts;
48 
49  private Set<BlackboardArtifact> accountArtifacts = null;
50  private SelectionSummary summary = null;
51 
59  public SelectionInfo(Set<AccountDeviceInstance> selectedNodes, Set<GraphEdge> selectedEdges,
60  CommunicationsFilter communicationFilter) {
61  this.selectedNodes = selectedNodes;
62  this.selectedEdges = selectedEdges;
63  this.communicationFilter = communicationFilter;
64 
65  accounts = new HashSet<>();
66  selectedNodes.forEach((instance) -> {
67  accounts.add(instance.getAccount());
68  });
69  }
70 
76  public Set<AccountDeviceInstance> getSelectedNodes() {
77  return selectedNodes;
78  }
79 
85  public Set<GraphEdge> getSelectedEdges() {
86  return selectedEdges;
87  }
88 
94  public CommunicationsFilter getCommunicationsFilter() {
95  return communicationFilter;
96  }
97 
98  public Set<Account> getAccounts() {
99  return accounts;
100  }
101 
109  Set<Content> getRelationshipSources() throws TskCoreException {
110 
111  CommunicationsManager communicationManager;
112  try {
113  communicationManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
114  } catch (NoCurrentCaseException ex) {
115  throw new TskCoreException("Failed to get current case", ex);
116  }
117 
118  Set<Content> relationshipSources = new HashSet<>();
119  try {
120  // Add all nodes
121  relationshipSources.addAll(communicationManager.getRelationshipSources(getSelectedNodes(), getCommunicationsFilter()));
122 
123  // Add all edges. For edges, the relationship has to include both endpoints
124  for (SelectionInfo.GraphEdge edge : getSelectedEdges()) {
125  relationshipSources.addAll(communicationManager.getRelationshipSources(edge.getStartNode(),
126  edge.getEndNode(), getCommunicationsFilter()));
127  }
128  } catch (TskCoreException ex) {
129  logger.log(Level.SEVERE, "Failed to get relationships from case database.", ex); //NON-NLS
130 
131  }
132  return relationshipSources;
133  }
134 
135  public Set<BlackboardArtifact> getArtifacts() {
136  if (accountArtifacts == null) {
137  accountArtifacts = new HashSet<>();
138 
139  try {
140  final Set<Content> relationshipSources = getRelationshipSources();
141  relationshipSources.stream().filter((content) -> (content instanceof BlackboardArtifact)).forEachOrdered((content) -> {
142  accountArtifacts.add((BlackboardArtifact) content);
143  });
144  } catch (TskCoreException ex) {
145  logger.log(Level.SEVERE, "Failed to load relationship sources.", ex); //NON-NLS
146  return accountArtifacts;
147  }
148  }
149 
150  return accountArtifacts;
151  }
152 
153  public SelectionSummary getSummary() {
154  if (summary == null) {
155  summary = new SelectionSummary();
156  }
157 
158  return summary;
159  }
160 
161  final class SelectionSummary {
162 
163  int attachmentCnt;
164  int messagesCnt;
165  int emailCnt;
166  int callLogCnt;
167  int contactsCnt;
168  int mediaCnt;
169 
170  SelectionSummary() {
171  getCounts();
172  }
173 
174  private void getCounts() {
175  for (BlackboardArtifact artifact : getArtifacts()) {
176  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
177  if (null != fromID) {
178  switch (fromID) {
179  case TSK_EMAIL_MSG:
180  emailCnt++;
181  break;
182  case TSK_CALLLOG:
183  callLogCnt++;
184  break;
185  case TSK_MESSAGE:
186  messagesCnt++;
187  break;
188  case TSK_CONTACT:
189  contactsCnt++;
190  break;
191  default:
192  break;
193  }
194  }
195  try {
196  attachmentCnt += artifact.getChildrenCount();
197  for (Content childContent : artifact.getChildren()) {
198  if (ImageUtils.thumbnailSupported(childContent)) {
199  mediaCnt++;
200  }
201  }
202  } catch (TskCoreException ex) {
203  logger.log(Level.WARNING, String.format("Exception thrown "
204  + "from getChildrenCount artifactID: %d",
205  artifact.getArtifactID()), ex); //NON-NLS
206  }
207  }
208  }
209 
210  public int getAttachmentCnt() {
211  return attachmentCnt;
212  }
213 
214  public int getMessagesCnt() {
215  return messagesCnt;
216  }
217 
218  public int getEmailCnt() {
219  return emailCnt;
220  }
221 
222  public int getCallLogCnt() {
223  return callLogCnt;
224  }
225 
226  public int getContactsCnt() {
227  return contactsCnt;
228  }
229 
230  public int getThumbnailCnt() {
231  return mediaCnt;
232  }
233  }
234 
238  public static class GraphEdge {
239 
240  AccountDeviceInstance startNode;
241  AccountDeviceInstance endNode;
242 
243  public GraphEdge(AccountDeviceInstance startNode, AccountDeviceInstance endNode) {
244  this.startNode = startNode;
245  this.endNode = endNode;
246  }
247 
248  public AccountDeviceInstance getStartNode() {
249  return startNode;
250  }
251 
252  public AccountDeviceInstance getEndNode() {
253  return endNode;
254  }
255  }
256 }
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-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.