19 package org.sleuthkit.autopsy.communications.relationships;
21 import java.util.ArrayList;
22 import java.util.Comparator;
23 import java.util.HashMap;
24 import java.util.List;
27 import java.util.logging.Level;
28 import org.openide.nodes.ChildFactory;
29 import org.openide.nodes.Node;
45 final class CallLogsChildNodeFactory
extends ChildFactory<CallLogNodeKey>{
47 private static final Logger logger = Logger.getLogger(CallLogsChildNodeFactory.class.getName());
49 private SelectionInfo selectionInfo;
51 private final Map<String, String> deviceIDMap =
new HashMap<>();
53 CallLogsChildNodeFactory(SelectionInfo selectionInfo) {
54 this.selectionInfo = selectionInfo;
57 void refresh(SelectionInfo selectionInfo) {
58 this.selectionInfo = selectionInfo;
63 protected boolean createKeys(List<CallLogNodeKey> list) {
65 if(selectionInfo == null) {
69 final Set<Content> relationshipSources;
71 relationshipSources = selectionInfo.getRelationshipSources();
72 }
catch (TskCoreException ex) {
73 logger.log(Level.SEVERE,
"Failed to load relationship sources.", ex);
78 for(Content content: relationshipSources) {
79 if( !(content instanceof BlackboardArtifact)){
83 BlackboardArtifact bba = (BlackboardArtifact) content;
84 BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(bba.getArtifactTypeID());
86 if ( fromID == BlackboardArtifact.ARTIFACT_TYPE.TSK_CALLLOG) {
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);
95 list.add(
new CallLogNodeKey(bba, deviceID));
99 list.sort(
new CallLogComparator(BlackboardArtifactDateComparator.ACCENDING));
105 protected Node createNodeForKey(CallLogNodeKey key) {
107 return new CallLogNode(key.getArtifact(), key.getDeviceID());
123 private String getDeviceIDForDataSource(String dataSourceName)
throws NoCurrentCaseException, TskCoreException{
125 String deviceID = deviceIDMap.get(dataSourceName);
127 if(deviceID == null) {
128 CommunicationsManager manager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
129 CommunicationsFilter filter =
new CommunicationsFilter();
131 List<String> list =
new ArrayList<>();
132 list.add(dataSourceName);
134 List<Account.Type> typeList =
new ArrayList<Account.Type>();
135 typeList.add(Account.Type.DEVICE);
137 filter.addAndFilter(
new CommunicationsFilter.DeviceFilter(list));
138 filter.addAndFilter(
new CommunicationsFilter.AccountTypeFilter(typeList));
142 List<AccountDeviceInstance> adiList = manager.getAccountDeviceInstancesWithRelationships(filter);
144 if( adiList != null && !adiList.isEmpty() ) {
145 deviceID = adiList.get(0).getDeviceId();
150 deviceIDMap.put(dataSourceName, deviceID);
153 return (deviceID != null ? deviceID :
"");
160 final class CallLogNodeKey{
161 private final BlackboardArtifact artifact;
162 private final String deviceID;
164 private CallLogNodeKey(BlackboardArtifact artifact, String deviceID) {
165 this.artifact = artifact;
166 this.deviceID = deviceID;
174 BlackboardArtifact getArtifact() {
183 String getDeviceID() {
191 final class CallLogComparator
implements Comparator<CallLogNodeKey>{
193 final BlackboardArtifactDateComparator comparator;
195 CallLogComparator(
int direction) {
196 comparator =
new BlackboardArtifactDateComparator(direction);
200 public int compare(CallLogNodeKey key1, CallLogNodeKey key2) {
201 return comparator.compare(key1.getArtifact(), key2.getArtifact());