19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.time.Instant;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Objects;
29 import java.util.UUID;
30 import org.apache.commons.lang3.StringUtils;
31 import org.openide.util.NbBundle;
45 LOW(1,
"Low confidence"),
47 HIGH(3,
"High confidence");
54 this.level_id = level;
69 if (confidence.getLevelId() == value) {
94 this.description = description;
103 return this.status_id;
117 private final long id;
126 @NbBundle.Messages(
"Persona.defaultName=Unnamed")
128 return Bundle.Persona_defaultName();
168 this.createdDate = created_date;
169 this.modifiedDate = modified_date;
177 hash = 67 * hash + (int) (this.
id ^ (this.
id >>> 32));
178 hash = 67 * hash + Objects.hashCode(this.uuidStr);
190 if (getClass() != obj.getClass()) {
194 if (this.
id != other.
getId()) {
197 return this.uuidStr.equalsIgnoreCase(other.
getUuidStr());
218 persona.
addAccount(account, justification, confidence);
237 String uuidStr = UUID.randomUUID().toString();
240 Instant instant = Instant.now();
241 Long timeStampMillis = instant.toEpochMilli();
243 String insertPersonaSQL =
"INSERT INTO personas (uuid, comment, name, created_date, modified_date, status_id, examiner_id ) "
244 +
" VALUES (?, ?, ?, ?, ?, ?, ?)";
245 List<Object> params =
new ArrayList<>();
247 params.add(StringUtils.isBlank(comment) ?
"" :
comment);
249 params.add(timeStampMillis);
250 params.add(timeStampMillis);
252 params.add(examiner.
getId());
266 String updateSQL =
"UPDATE personas SET comment = ? WHERE id = ?";
269 List<Object> params =
new ArrayList<>();
270 params.add(StringUtils.isBlank(comment) ?
"" :
comment);
285 String updateSQL =
"UPDATE personas SET name = ? WHERE id = ?";
288 List<Object> params =
new ArrayList<>();
310 return PersonaAccount.addPersonaAccount(
this, account, justification, confidence);
336 PersonaAccount.modifyPersonaAccount(account.getId(), confidence, justification);
343 String deleteSQL =
"UPDATE personas SET status_id = ? WHERE id = ?";
346 List<Object> params =
new ArrayList<>();
359 private final Collection<Persona>
personaList =
new ArrayList<>();
362 public void process(ResultSet rs)
throws SQLException {
366 rs.getInt(
"examiner_id"),
367 rs.getString(
"login_name"));
372 rs.getString(
"uuid"),
373 rs.getString(
"name"),
374 rs.getString(
"comment"),
375 Long.parseLong(rs.getString(
"created_date")),
376 Long.parseLong(rs.getString(
"modified_date")),
381 personaList.add(persona);
385 Collection<Persona> getPersonas() {
386 return Collections.unmodifiableCollection(personaList);
393 =
"SELECT 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 "
394 +
"FROM personas as p "
395 +
"INNER JOIN examiners as e ON e.id = p.examiner_id ";
413 +
"WHERE p.uuid = ?";
415 List<Object> params =
new ArrayList<>();
421 Collection<Persona> personas = queryCallback.getPersonas();
423 return personas.isEmpty() ? null : personas.iterator().next();
441 +
"WHERE p.status_id != ? "
442 +
" AND LOWER(p.name) LIKE LOWER(?) ESCAPE '!'";
444 List<Object> params =
new ArrayList<>();
451 return queryCallback.getPersonas();
467 if (initial == null) {
490 String queryClause =
"SELECT p.id, p.uuid, p.name, p.comment, p.created_date, p.modified_date, p.status_id, p.examiner_id, e.login_name\n"
491 +
"FROM personas p\n"
492 +
"LEFT JOIN examiners e ON e.id = p.examiner_id\n"
493 +
"WHERE p.status_id <> ?\n"
495 +
" SELECT pa.persona_id\n"
496 +
" FROM persona_accounts pa\n"
497 +
" INNER JOIN accounts a ON a.id = pa.account_id\n"
498 +
" WHERE LOWER(a.account_unique_identifier) LIKE LOWER(?) ESCAPE '!'\n"
503 List<Object> params =
new ArrayList<>();
508 return queryCallback.getPersonas();
523 return PersonaAlias.addPersonaAlias(
this, alias, justification, confidence);
549 PersonaAlias.modifyPersonaAlias(key, confidence, justification);
576 return PersonaMetadata.addPersonaMetadata(this.
getId(), name, value, justification, confidence);
634 Collection<CorrelationCase> correlationCases =
new ArrayList<>();
639 while (resultSet.next()) {
642 correlationCases.add(correlationCase);
646 Collection<CorrelationCase> getCases() {
647 return Collections.unmodifiableCollection(correlationCases);
659 public Collection<CorrelationCase>
getCases() throws CentralRepoException {
661 Collection<CorrelationCase> casesForPersona =
new ArrayList<>();
664 Collection<CentralRepoAccount> accounts =
PersonaAccount.getAccountsForPersona(this.
getId());
666 int corrTypeId = account.getAccountType().getCorrelationTypeId();
670 String querySql =
"SELECT DISTINCT case_id FROM " + tableName
671 +
" WHERE account_id = ?";
673 List<Object> params =
new ArrayList<>();
674 params.add(account.getId());
681 if (!casesForPersona.stream().anyMatch(p -> p.getCaseUUID().equalsIgnoreCase(corrCase.getCaseUUID()))) {
682 casesForPersona.add(corrCase);
687 return casesForPersona;
696 Collection<CorrelationDataSource> correlationDataSources =
new ArrayList<>();
699 public void process(ResultSet resultSet)
throws CentralRepoException, SQLException {
701 while (resultSet.next()) {
708 if (!correlationDataSources.stream().anyMatch(p -> Objects.equals(p.getDataSourceObjectID(), correlationDatasource.
getDataSourceObjectID()))) {
709 correlationDataSources.add(correlationDatasource);
714 Collection<CorrelationDataSource> getDataSources() {
715 return Collections.unmodifiableCollection(correlationDataSources);
727 public Collection<CorrelationDataSource>
getDataSources() throws CentralRepoException {
728 Collection<CorrelationDataSource> correlationDataSources =
new ArrayList<>();
730 Collection<CentralRepoAccount> accounts =
PersonaAccount.getAccountsForPersona(this.
getId());
732 int corrTypeId = account.getAccountType().getCorrelationTypeId();
736 String querySql =
"SELECT case_id, data_source_id FROM " + tableName
737 +
" WHERE account_id = ?";
739 List<Object> params =
new ArrayList<>();
740 params.add(account.getId());
747 if (!correlationDataSources.stream().anyMatch(p -> Objects.equals(p.getDataSourceObjectID(), correlationDatasource.getDataSourceObjectID()))) {
748 correlationDataSources.add(correlationDatasource);
753 return correlationDataSources;
761 Collection<Persona> personasList =
new ArrayList<>();
764 public void process(ResultSet resultSet)
throws CentralRepoException, SQLException {
766 while (resultSet.next()) {
770 resultSet.getInt(
"persona_examiner_id"),
771 resultSet.getString(
"persona_examiner_login_name"));
776 resultSet.getInt(
"persona_id"),
777 resultSet.getString(
"uuid"),
778 resultSet.getString(
"name"),
779 resultSet.getString(
"comment"),
780 Long.parseLong(resultSet.getString(
"created_date")),
781 Long.parseLong(resultSet.getString(
"modified_date")),
786 personasList.add(persona);
790 Collection<Persona> getPersonasList() {
791 return Collections.unmodifiableCollection(personasList);
807 int corrTypeId = crAccountType.getCorrelationTypeId();
811 return "SELECT " + instanceTableName +
".account_id, case_id, data_source_id, "
812 +
" personas.id as persona_id, personas.uuid, personas.name, personas.comment, personas.created_date, personas.modified_date, personas.status_id, "
813 +
" personas.examiner_id as persona_examiner_id, persona_examiner.login_name as persona_examiner_login_name, persona_examiner.display_name as persona_examiner_display_name "
814 +
" FROM " + instanceTableName
815 +
" JOIN persona_accounts as pa on pa.account_id = " + instanceTableName +
".account_id"
816 +
" JOIN personas as personas on personas.id = pa.persona_id"
817 +
" JOIN examiners as persona_examiner ON persona_examiner.id = personas.examiner_id ";
831 Collection<Persona> personaList =
new ArrayList<>();
837 +
" WHERE case_id = ?"
838 +
" AND personas.status_id != ?";
840 List<Object> params =
new ArrayList<>();
841 params.add(correlationCase.getID());
848 for (
Persona persona : queryCallback.getPersonasList()) {
849 if (!personaList.stream().anyMatch(p -> Objects.equals(p.getUuidStr(), persona.getUuidStr()))) {
850 personaList.add(persona);
868 Collection<Persona> personaList =
new ArrayList<>();
874 +
" WHERE data_source_id = ?"
875 +
" AND personas.status_id != ?";
877 List<Object> params =
new ArrayList<>();
878 params.add(dataSource.getID());
885 for (
Persona persona : queryCallback.getPersonasList()) {
886 if (!personaList.stream().anyMatch(p -> Objects.equals(p.getUuidStr(), persona.getUuidStr()))) {
887 personaList.add(persona);
906 if (instance == null) {
907 throw new CentralRepoException(
"Failed to get instance of CentralRespository, CR was null");
static CentralRepository getCRInstance()
void removeAlias(PersonaAlias alias)
CorrelationCase getCaseById(int caseId)
void modifyAlias(PersonaAlias key, Confidence confidence, String justification)
static Persona getPersonaByUUID(String uuid)
void executeQuery(String sql, List< Object > params, CentralRepositoryDbQueryCallback queryCallback)
Collection< PersonaAccount > getPersonaAccounts()
Confidence(int level, String name)
static Collection< Persona > getPersonaByName(String partialName)
static Persona createPersonaForAccount(String personaName, String comment, PersonaStatus status, CentralRepoAccount account, String justification, Persona.Confidence confidence)
void setName(String name)
PersonaAlias addAlias(String alias, String justification, Persona.Confidence confidence)
PersonaAccount addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
void removeAccount(PersonaAccount account)
Collection< CentralRepoAccountType > getAllAccountTypes()
CentralRepoExaminer getOrInsertExaminer(String examinerLoginName)
void modifyAccount(PersonaAccount account, Confidence confidence, String justification)
PersonaMetadata addMetadata(String name, String value, String justification, Persona.Confidence confidence)
CentralRepoExaminer getExaminer()
Collection< CorrelationDataSource > getDataSources()
void modifyMetadata(PersonaMetadata key, Confidence confidence, String justification)
void process(ResultSet resultSet)
Collection< PersonaAlias > getAliases()
static Collection< Persona > getPersonasForCase(CorrelationCase correlationCase)
Collection< CorrelationCase > getCases()
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
static String getPersonaFromInstanceTableQueryTemplate(CentralRepoAccount.CentralRepoAccountType crAccountType)
PersonaStatus getStatus()
void setComment(String comment)
PersonaStatus(int status, String description)
static Collection< PersonaAlias > getPersonaAliases(long personaId)
static final String PERSONA_QUERY
final CentralRepoExaminer examiner
static Persona createPersona(String name, String comment, PersonaStatus status)
final PersonaStatus status
void process(ResultSet resultSet)
static String getLikeEscaped(String initial)
Long getDataSourceObjectID()
void process(ResultSet resultSet)
final Collection< Persona > personaList
boolean equals(Object obj)
static PersonaStatus fromId(int value)
static Confidence fromId(int value)
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
void executeCommand(String sql, List< Object > params)
static Collection< Persona > getPersonasForDataSource(CorrelationDataSource dataSource)
static Collection< Persona > getPersonaByAccountIdentifierLike(String partialName)
void process(ResultSet rs)
static CentralRepository getInstance()
Collection< PersonaMetadata > getMetadata()
static String getDefaultName()
CorrelationDataSource getDataSourceById(CorrelationCase correlationCase, int dataSourceId)
void removeMetadata(PersonaMetadata metadata)