Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AccountDeviceInstanceNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-18 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 java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.concurrent.ExecutionException;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.util.lookup.Lookups;
36 import org.sleuthkit.datamodel.Account;
37 import org.sleuthkit.datamodel.AccountDeviceInstance;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
39 import org.sleuthkit.datamodel.BlackboardAttribute;
40 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME;
41 import org.sleuthkit.datamodel.CommunicationsFilter;
42 import org.sleuthkit.datamodel.CommunicationsManager;
43 import org.sleuthkit.datamodel.TskCoreException;
44 
48 final class AccountDeviceInstanceNode extends AbstractNode {
49 
50  private static final Logger logger = Logger.getLogger(AccountDeviceInstanceNode.class.getName());
51 
52  private final AccountDeviceInstanceKey accountDeviceInstanceKey;
53  private final CommunicationsManager commsManager;
54  private final Account account;
55 
56  private static final BlackboardAttribute.Type NAME_ATTRIBUTE = new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(TSK_NAME.getTypeID()));
57 
58  AccountDeviceInstanceNode(AccountDeviceInstanceKey accountDeviceInstanceKey, CommunicationsManager commsManager) {
59  super(Children.LEAF, Lookups.fixed(accountDeviceInstanceKey, commsManager));
60  this.accountDeviceInstanceKey = accountDeviceInstanceKey;
61  this.commsManager = commsManager;
62  this.account = accountDeviceInstanceKey.getAccountDeviceInstance().getAccount();
63  setName(account.getTypeSpecificID());
64  setDisplayName(getName());
65  String iconPath = Utils.getIconFilePath(account.getAccountType());
66  this.setIconBaseWithExtension(iconPath != null && iconPath.charAt(0) == '/' ? iconPath.substring(1) : iconPath);
67  }
68 
69  AccountDeviceInstance getAccountDeviceInstance() {
70  return accountDeviceInstanceKey.getAccountDeviceInstance();
71  }
72 
73  AccountDeviceInstanceKey getAccountDeviceInstanceKey() {
74  return accountDeviceInstanceKey;
75  }
76 
77  CommunicationsManager getCommsManager() {
78  return commsManager;
79  }
80 
81  long getMessageCount() {
82  return accountDeviceInstanceKey.getMessageCount();
83  }
84 
85  CommunicationsFilter getFilter() {
86  return accountDeviceInstanceKey.getCommunicationsFilter();
87  }
88 
89  @Override
90  @NbBundle.Messages(value = {"AccountNode.device=Device", "AccountNode.accountName=Account", "AccountNode.accountType=Type", "AccountNode.messageCount=Items"})
91  protected Sheet createSheet() {
92  Sheet sheet = super.createSheet();
93  Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
94  if (properties == null) {
95  properties = Sheet.createPropertiesSet();
96  sheet.put(properties);
97  }
98  properties.put(new NodeProperty<>("type",
99  Bundle.AccountNode_accountType(),
100  "type",
101  account.getAccountType().getDisplayName())); // NON-NLS
102  properties.put(new NodeProperty<>("count",
103  Bundle.AccountNode_messageCount(),
104  "count",
105  accountDeviceInstanceKey.getMessageCount())); // NON-NLS
106  properties.put(new NodeProperty<>("device",
107  Bundle.AccountNode_device(),
108  "device",
109  accountDeviceInstanceKey.getDataSourceName())); // NON-NLS
110  return sheet;
111  }
112 
113  @Override
114  public Action[] getActions(boolean context) {
115  ArrayList<Action> actions = new ArrayList<>(Arrays.asList(super.getActions(context)));
116  actions.add(PinAccountsAction.getInstance());
117  actions.add(ResetAndPinAccountsAction.getInstance());
118  return actions.toArray(new Action[actions.size()]);
119  }
120 
121  @Messages({
122  "# {0} - Contact Name",
123  "# {1} - Persona Name",
124  "AccountInstanceNode_Tooltip_Template=Contact: {0} - Persona: {1}",
125  "# {0} - PersonaAccount count",
126  "AccountInstanceNode_Tooltip_suffix=(1 of {0})"
127  })
128  @Override
129  public String getShortDescription() {
130  List<PersonaAccount> personaList;
131  List<BlackboardArtifact> contactArtifactList;
132  try {
133  personaList = CVTPersonaCache.getPersonaAccounts(account);
134  contactArtifactList = ContactCache.getContacts(account);
135  } catch (ExecutionException ex) {
136  logger.log(Level.WARNING, "Failed to retrieve Persona details for node.", ex);
137  return getDisplayName();
138  }
139 
140  String personaName;
141  if (personaList != null && !personaList.isEmpty()) {
142  personaName = personaList.get(0).getPersona().getName();
143  if (personaList.size() > 1) {
144  personaName += Bundle.AccountInstanceNode_Tooltip_suffix(Integer.toString(personaList.size()));
145  }
146  } else {
147  personaName = "None";
148  }
149 
150  String contactName = getDisplayName();
151  if (contactArtifactList != null && !contactArtifactList.isEmpty()) {
152  try {
153  BlackboardArtifact contactArtifact = contactArtifactList.get(0);
154  BlackboardAttribute attribute = contactArtifact.getAttribute(NAME_ATTRIBUTE);
155  if (attribute != null) {
156  contactName = attribute.getValueString();
157  }
158  } catch (TskCoreException ex) {
159  logger.log(Level.WARNING, "Failed to retrive name attribute from contact artifact.", ex);
160  }
161  }
162 
163  return Bundle.AccountInstanceNode_Tooltip_Template(contactName, personaName);
164  }
165 }

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