Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CallLogsChildNodeFactory.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.ArrayList;
22 import java.util.Comparator;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.logging.Level;
28 import org.openide.nodes.ChildFactory;
29 import org.openide.nodes.Node;
34 import org.sleuthkit.datamodel.Account;
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 
45 final class CallLogsChildNodeFactory extends ChildFactory<CallLogNodeKey>{
46 
47  private static final Logger logger = Logger.getLogger(CallLogsChildNodeFactory.class.getName());
48 
49  private SelectionInfo selectionInfo;
50 
51  private final Map<String, String> deviceIDMap = new HashMap<>();
52 
53  CallLogsChildNodeFactory(SelectionInfo selectionInfo) {
54  this.selectionInfo = selectionInfo;
55  }
56 
57  void refresh(SelectionInfo selectionInfo) {
58  this.selectionInfo = selectionInfo;
59  refresh(true);
60  }
61 
62  @Override
63  protected boolean createKeys(List<CallLogNodeKey> list) {
64 
65  if(selectionInfo == null) {
66  return true;
67  }
68 
69  final Set<Content> relationshipSources;
70  try {
71  relationshipSources = selectionInfo.getRelationshipSources();
72  } catch (TskCoreException ex) {
73  logger.log(Level.SEVERE, "Failed to load relationship sources.", ex); //NON-NLS
74  return false;
75  }
76 
77 
78  for(Content content: relationshipSources) {
79  if( !(content instanceof BlackboardArtifact)){
80  continue;
81  }
82 
83  BlackboardArtifact bba = (BlackboardArtifact) content;
84  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(bba.getArtifactTypeID());
85 
86  if ( fromID == BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG) {
87 
88  String deviceID = "";
89  try {
90  deviceID = getDeviceIDForDataSource(bba.getDataSource().getName());
91  } catch (NoCurrentCaseException | TskCoreException ex) {
92  logger.log(Level.WARNING, String.format("Unable to get account for artifact data source: artifactID = %d", bba.getId()), ex);
93  }
94 
95  list.add(new CallLogNodeKey(bba, deviceID));
96  }
97  }
98 
99  list.sort(new CallLogComparator(BlackboardArtifactDateComparator.ACCENDING));
100 
101  return true;
102  }
103 
104  @Override
105  protected Node createNodeForKey(CallLogNodeKey key) {
106 
107  return new CallLogNode(key.getArtifact(), key.getDeviceID());
108  }
109 
123  private String getDeviceIDForDataSource(String dataSourceName) throws NoCurrentCaseException, TskCoreException{
124 
125  String deviceID = deviceIDMap.get(dataSourceName);
126 
127  if(deviceID == null) {
128  CommunicationsManager manager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
129  CommunicationsFilter filter = new CommunicationsFilter();
130 
131  List<String> list = new ArrayList<>();
132  list.add(dataSourceName);
133 
134  List<Account.Type> typeList = new ArrayList<Account.Type>();
135  typeList.add(Account.Type.DEVICE);
136 
137  filter.addAndFilter(new CommunicationsFilter.DeviceFilter(list));
138  filter.addAndFilter(new CommunicationsFilter.AccountTypeFilter(typeList));
139 
140 
141  // This list should just have 1 item in it
142  List<AccountDeviceInstance> adiList = manager.getAccountDeviceInstancesWithRelationships(filter);
143 
144  if( adiList != null && !adiList.isEmpty() ) {
145  deviceID = adiList.get(0).getDeviceId();
146  } else {
147  deviceID = "";
148  }
149 
150  deviceIDMap.put(dataSourceName, deviceID);
151  }
152 
153  return (deviceID != null ? deviceID : "");
154  }
155 
160  final class CallLogNodeKey{
161  private final BlackboardArtifact artifact;
162  private final String deviceID;
163 
164  private CallLogNodeKey(BlackboardArtifact artifact, String deviceID) {
165  this.artifact = artifact;
166  this.deviceID = deviceID;
167  }
168 
174  BlackboardArtifact getArtifact() {
175  return artifact;
176  }
177 
183  String getDeviceID() {
184  return deviceID;
185  }
186  }
187 
191  final class CallLogComparator implements Comparator<CallLogNodeKey>{
192 
193  final BlackboardArtifactDateComparator comparator;
194 
195  CallLogComparator(int direction) {
196  comparator = new BlackboardArtifactDateComparator(direction);
197  }
198 
199  @Override
200  public int compare(CallLogNodeKey key1, CallLogNodeKey key2) {
201  return comparator.compare(key1.getArtifact(), key2.getArtifact());
202  }
203  }
204 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.