19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.awt.Component;
22 import java.awt.event.ActionListener;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.concurrent.CancellationException;
29 import java.util.concurrent.ExecutionException;
30 import java.util.logging.Level;
31 import javax.swing.JButton;
32 import javax.swing.SwingWorker;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbBundle.Messages;
49 import org.
sleuthkit.datamodel.InvalidAccountIDException;
54 class PersonaAccountFetcher
extends SwingWorker<Map<String, Collection<Persona>>, Void> {
56 private final static Logger logger = Logger.getLogger(PersonaAccountFetcher.class.getName());
58 private final BlackboardArtifact artifact;
59 private final List<AccountPersonaSearcherData> personaSearchDataList;
60 private final Component parentComponent;
69 PersonaAccountFetcher(BlackboardArtifact artifact, List<AccountPersonaSearcherData> personaSearchDataList, Component parentComponent) {
70 this.artifact = artifact;
71 this.personaSearchDataList = personaSearchDataList;
72 this.parentComponent = parentComponent;
76 protected Map<String, Collection<Persona>> doInBackground() throws Exception {
77 Map<String, Collection<Persona>> accountMap =
new HashMap<>();
79 CommunicationsManager commManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
81 List<Account> relatedAccountList = commManager.getAccountsRelatedToArtifact(artifact);
83 for (Account account : relatedAccountList) {
86 return new HashMap<>();
89 Collection<PersonaAccount> personaAccountList = PersonaAccount.getPersonaAccountsForAccount(account);
90 Collection<Persona> personaList =
new ArrayList<>();
91 for (PersonaAccount pAccount : personaAccountList) {
92 personaList.add(pAccount.getPersona());
95 accountMap.put(account.getTypeSpecificID(), personaList);
102 protected void done() {
108 Map<String, Collection<Persona>> accountMap =
get();
110 for (AccountPersonaSearcherData searcherData : personaSearchDataList) {
111 Collection<Persona> persona = accountMap.get(searcherData.getAccountIdentifer());
112 updatePersonaControls(searcherData, persona);
115 }
catch (CancellationException ex) {
116 logger.log(Level.INFO,
"Persona searching was canceled.");
117 }
catch (InterruptedException ex) {
118 logger.log(Level.INFO,
"Persona searching was interrupted.");
119 }
catch (ExecutionException ex) {
120 logger.log(Level.SEVERE,
"Fatal error during Persona search.", ex);
123 parentComponent.repaint();
127 "# {0} - Persona count",
128 "PersonaDisplayTask_persona_count_suffix=(1 of {0})"
137 private void updatePersonaControls(AccountPersonaSearcherData personaSearcherData, Collection<Persona> personas) {
139 String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
140 String personaButtonText;
141 ActionListener buttonActionListener;
143 if (personas == null || personas.isEmpty()) {
145 personaLabelText += Bundle.CommunicationArtifactViewerHelper_persona_unknown();
148 personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_create();
149 buttonActionListener =
new CreatePersonaButtonListener(parentComponent, personaSearcherData);
151 Persona persona = personas.iterator().next();
152 personaLabelText += persona.getName();
153 if (personas.size() > 1) {
154 personaLabelText += Bundle.PersonaDisplayTask_persona_count_suffix(Integer.toString(personas.size()));
157 personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_view();
158 buttonActionListener =
new ViewPersonaButtonListener(parentComponent, persona);
161 personaSearcherData.getPersonaNameLabel().setText(personaLabelText);
162 personaSearcherData.getPersonaActionButton().setText(personaButtonText);
163 personaSearcherData.getPersonaActionButton().setEnabled(
true);
166 personaSearcherData.getPersonaActionButton().addActionListener(buttonActionListener);
183 "PersonaAccountFetcher.account.justification=Account found in Call Log artifact",
184 "# {0} - accountIdentifer",
185 "PersonaAccountFetcher_not_account_in_cr=Unable to find an account with identifier {0} in the Central Repository."
198 personaPanel.
setPersonaName(personaSearcherData.getAccountIdentifer());
203 boolean showErrorMessage =
true;
209 if (account != null) {
211 showErrorMessage =
false;
214 }
catch (InvalidAccountIDException ex2) {
218 if ((personaSearcherData.getAccountIdentifer() != null
219 && !personaSearcherData.getAccountIdentifer().isEmpty()) && showErrorMessage) {
220 dialog.
setStartupPopupMessage(Bundle.PersonaAccountFetcher_not_account_in_cr(personaSearcherData.getAccountIdentifer()));
223 logger.log(Level.SEVERE,
"Error looking up account types in the central repository", ex);
256 private final Component parentComponent;
257 private final AccountPersonaSearcherData personaSearcherData;
259 PersonaCreateCallbackImpl(Component parentComponent, AccountPersonaSearcherData personaSearcherData) {
260 this.parentComponent = parentComponent;
261 this.personaSearcherData = personaSearcherData;
265 public void callback(Persona persona) {
266 JButton personaButton = personaSearcherData.getPersonaActionButton();
267 if (persona != null) {
270 personaSearcherData.getPersonaNameLabel().setText(Bundle.CommunicationArtifactViewerHelper_persona_label() + persona.getName());
271 personaSearcherData.getPersonaActionButton().setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
274 for (ActionListener act : personaButton.getActionListeners()) {
275 personaButton.removeActionListener(act);
277 personaButton.addActionListener(
new ViewPersonaButtonListener(parentComponent, persona));
281 personaButton.getParent().revalidate();
288 class PersonaViewCallbackImpl
implements PersonaDetailsDialogCallback {
291 public void callback(Persona persona) {
boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
void actionPerformed(java.awt.event.ActionEvent evt)
final AccountPersonaSearcherData personaSearcherData
void setStartupPopupMessage(String message)
CentralRepoAccount getAccount(CentralRepoAccount.CentralRepoAccountType crAccountType, String accountUniqueID)
final Component parentComponent
PersonaDetailsPanel getDetailsPanel()
final Component parentComponent
Collection< CentralRepoAccountType > getAllAccountTypes()
void actionPerformed(java.awt.event.ActionEvent evt)
void setPersonaName(String name)
static CentralRepository getInstance()