6390 persona searching by account

This commit is contained in:
Ethan Roseman 2020-06-08 18:24:55 -04:00
parent 795fe87f72
commit c8e60d55fa
3 changed files with 41 additions and 3 deletions

View File

@ -394,6 +394,34 @@ public class Persona {
return queryCallback.getPersonas();
}
/**
* Gets the rows from the Personas table where persona accounts' names are
* similar to the given one. Persona marked as DELETED are not returned.
*
* @param partialName Name substring to match.
* @return Collection of personas matching the given name substring, may be
* empty if no match is found.
*
* @throws CentralRepoException If there is an error in querying the
* Personas table.
*/
public static Collection<Persona> getPersonaByAccountIdentifierLike(String partialName) throws CentralRepoException {
String queryClause = "SELECT DISTINCT accounts.id as a_id,"
+ "p.id, p.uuid, p.name, p.comment, p.created_date, p.modified_date, p.status_id, p.examiner_id, e.login_name, e.display_name"
+ " FROM accounts"
+ " JOIN persona_accounts as pa ON pa.account_id = accounts.id"
+ " JOIN personas as p ON p.id = pa.persona_id"
+ " JOIN examiners as e ON e.id = p.examiner_id"
+ " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + partialName + "%')"
+ " AND p.status_id != " + Persona.PersonaStatus.DELETED.getStatusId()
+ " GROUP BY p.id";
PersonaQueryCallback queryCallback = new PersonaQueryCallback();
CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonas();
}
/**
* Creates an alias for the Persona.
*

View File

@ -145,7 +145,6 @@
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/centralrepository/persona/Bundle.properties" key="PersonaManagerTopComponent.searchAccountRadio.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Container class="javax.swing.JScrollPane" name="resultsPane">

View File

@ -113,6 +113,14 @@ public final class PersonaManagerTopComponent extends TopComponent {
handleSelectionChange(e);
}
});
searchNameRadio.addActionListener((ActionEvent e) -> {
searchField.setText("");
});
searchAccountRadio.addActionListener((ActionEvent e) -> {
searchField.setText("");
});
}
/**
@ -200,7 +208,11 @@ public final class PersonaManagerTopComponent extends TopComponent {
private void executeSearch() {
Collection<Persona> results;
try {
results = Persona.getPersonaByName(searchField.getText());
if (searchNameRadio.isSelected()) {
results = Persona.getPersonaByName(searchField.getText());
} else {
results = Persona.getPersonaByAccountIdentifierLike(searchField.getText());
}
} catch (CentralRepoException ex) {
logger.log(Level.SEVERE, "Failed to search personas", ex);
JOptionPane.showMessageDialog(this,
@ -254,7 +266,6 @@ public final class PersonaManagerTopComponent extends TopComponent {
searchButtonGroup.add(searchAccountRadio);
org.openide.awt.Mnemonics.setLocalizedText(searchAccountRadio, org.openide.util.NbBundle.getMessage(PersonaManagerTopComponent.class, "PersonaManagerTopComponent.searchAccountRadio.text")); // NOI18N
searchAccountRadio.setEnabled(false);
resultsTable.setToolTipText(org.openide.util.NbBundle.getMessage(PersonaManagerTopComponent.class, "PersonaManagerTopComponent.resultsTable.toolTipText")); // NOI18N
resultsTable.getTableHeader().setReorderingAllowed(false);