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.Objects;
28 import java.util.UUID;
29 import org.apache.commons.lang3.StringUtils;
30 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());
217 persona.
addAccount(account, justification, confidence);
236 String uuidStr = UUID.randomUUID().toString();
239 Instant instant = Instant.now();
240 Long timeStampMillis = instant.toEpochMilli();
241 String insertClause =
" INTO personas (uuid, comment, name, created_date, modified_date, status_id, examiner_id ) "
242 +
"VALUES ( '" + uuidStr +
"', "
243 +
"'" + ((StringUtils.isBlank(comment) ?
"" : SleuthkitCase.escapeSingleQuotes(comment))) +
"',"
244 +
"'" + ((StringUtils.isBlank(name) ?
getDefaultName() : SleuthkitCase.escapeSingleQuotes(name))) +
"',"
245 + timeStampMillis.toString() +
","
246 + timeStampMillis.toString() +
","
263 String updateClause =
"UPDATE personas SET comment = '" + comment +
"' WHERE id = " +
id;
278 String updateClause =
"UPDATE personas SET name = '" + name +
"' WHERE id = " +
id;
298 return PersonaAccount.addPersonaAccount(
this, account, justification, confidence);
324 PersonaAccount.modifyPersonaAccount(account.getId(), confidence, justification);
331 String deleteSQL =
"UPDATE personas SET status_id = " +
PersonaStatus.
DELETED.status_id +
" WHERE id = " + this.
id;
343 private final Collection<Persona>
personaList =
new ArrayList<>();
346 public void process(ResultSet rs)
throws SQLException {
350 rs.getInt(
"examiner_id"),
351 rs.getString(
"login_name"));
356 rs.getString(
"uuid"),
357 rs.getString(
"name"),
358 rs.getString(
"comment"),
359 Long.parseLong(rs.getString(
"created_date")),
360 Long.parseLong(rs.getString(
"modified_date")),
365 personaList.add(persona);
369 Collection<Persona> getPersonas() {
370 return Collections.unmodifiableCollection(personaList);
377 "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 "
378 +
"FROM personas as p "
379 +
"INNER JOIN examiners as e ON e.id = p.examiner_id ";
397 +
"WHERE p.uuid = '" + uuid +
"'";
402 Collection<Persona> personas = queryCallback.getPersonas();
404 return personas.isEmpty() ? null : personas.iterator().next();
420 String queryClause = PERSONA_QUERY
422 " AND LOWER(p.name) LIKE " +
"LOWER('%" + partialName +
"%')" ;
427 return queryCallback.getPersonas();
442 String queryClause =
"SELECT DISTINCT accounts.id as a_id,"
443 +
"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"
445 +
" JOIN persona_accounts as pa ON pa.account_id = accounts.id"
446 +
" JOIN personas as p ON p.id = pa.persona_id"
447 +
" JOIN examiners as e ON e.id = p.examiner_id"
448 +
" WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + partialName +
"%')"
458 return queryCallback.getPersonas();
472 return PersonaAlias.addPersonaAlias(
this, alias, justification, confidence);
498 PersonaAlias.modifyPersonaAlias(key, confidence, justification);
524 return PersonaMetadata.addPersonaMetadata(this.
getId(), name, value, justification, confidence);
582 Collection<CorrelationCase> correlationCases =
new ArrayList<>();
587 while (resultSet.next()) {
590 correlationCases.add(correlationCase);
594 Collection<CorrelationCase> getCases() {
595 return Collections.unmodifiableCollection(correlationCases);
606 public Collection<CorrelationCase>
getCases() throws CentralRepoException {
608 Collection<CorrelationCase> casesForPersona =
new ArrayList<>();
611 Collection<CentralRepoAccount> accounts =
PersonaAccount.getAccountsForPersona(this.
getId());
613 int corrTypeId = account.getAccountType().getCorrelationTypeId();
617 String querySql =
"SELECT DISTINCT case_id FROM " + tableName
618 +
" WHERE account_id = " + account.getId();
625 if (!casesForPersona.stream().anyMatch(p -> p.getCaseUUID().equalsIgnoreCase(corrCase.getCaseUUID()))) {
626 casesForPersona.add(corrCase);
631 return casesForPersona;
640 Collection<CorrelationDataSource> correlationDataSources =
new ArrayList<>();
643 public void process(ResultSet resultSet)
throws CentralRepoException, SQLException {
645 while (resultSet.next()) {
652 if (!correlationDataSources.stream().anyMatch(p -> Objects.equals(p.getDataSourceObjectID(), correlationDatasource.
getDataSourceObjectID()))) {
653 correlationDataSources.add(correlationDatasource);
658 Collection<CorrelationDataSource> getDataSources() {
659 return Collections.unmodifiableCollection(correlationDataSources);
671 public Collection<CorrelationDataSource>
getDataSources() throws CentralRepoException {
672 Collection<CorrelationDataSource> correlationDataSources =
new ArrayList<>();
674 Collection<CentralRepoAccount> accounts =
PersonaAccount.getAccountsForPersona(this.
getId());
676 int corrTypeId = account.getAccountType().getCorrelationTypeId();
680 String querySql =
"SELECT case_id, data_source_id FROM " + tableName
681 +
" WHERE account_id = " + account.getId();
688 if (!correlationDataSources.stream().anyMatch(p -> Objects.equals(p.getDataSourceObjectID(), correlationDatasource.getDataSourceObjectID()))) {
689 correlationDataSources.add(correlationDatasource);
694 return correlationDataSources;
702 Collection<Persona> personasList =
new ArrayList<>();
705 public void process(ResultSet resultSet)
throws CentralRepoException, SQLException {
707 while (resultSet.next()) {
711 resultSet.getInt(
"persona_examiner_id"),
712 resultSet.getString(
"persona_examiner_login_name"));
717 resultSet.getInt(
"persona_id"),
718 resultSet.getString(
"uuid"),
719 resultSet.getString(
"name"),
720 resultSet.getString(
"comment"),
721 Long.parseLong(resultSet.getString(
"created_date")),
722 Long.parseLong(resultSet.getString(
"modified_date")),
727 personasList.add(persona);
731 Collection<Persona> getPersonasList() {
732 return Collections.unmodifiableCollection(personasList);
746 int corrTypeId = crAccountType.getCorrelationTypeId();
750 return "SELECT " + instanceTableName +
".account_id, case_id, data_source_id, "
751 +
" personas.id as persona_id, personas.uuid, personas.name, personas.comment, personas.created_date, personas.modified_date, personas.status_id, "
752 +
" 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 "
753 +
" FROM " + instanceTableName
754 +
" JOIN persona_accounts as pa on pa.account_id = " + instanceTableName +
".account_id"
755 +
" JOIN personas as personas on personas.id = pa.persona_id"
756 +
" JOIN examiners as persona_examiner ON persona_examiner.id = personas.examiner_id ";
769 Collection<Persona> personaList =
new ArrayList<>();
775 +
" WHERE case_id = " + correlationCase.getID()
782 for (
Persona persona : queryCallback.getPersonasList()) {
783 if (!personaList.stream().anyMatch(p -> Objects.equals(p.getUuidStr(), persona.getUuidStr()))) {
784 personaList.add(persona);
801 Collection<Persona> personaList =
new ArrayList<>();
807 +
" WHERE data_source_id = " + dataSource.getID()
814 for (
Persona persona : queryCallback.getPersonasList()) {
815 if (!personaList.stream().anyMatch(p -> Objects.equals(p.getUuidStr(), persona.getUuidStr()))) {
816 personaList.add(persona);
836 if(instance == null) {
837 throw new CentralRepoException(
"Failed to get instance of CentralRespository, CR was null");
void executeSelectSQL(String sql, CentralRepositoryDbQueryCallback queryCallback)
static CentralRepository getCRInstance()
void removeAlias(PersonaAlias alias)
CorrelationCase getCaseById(int caseId)
void modifyAlias(PersonaAlias key, Confidence confidence, String justification)
static Persona getPersonaByUUID(String uuid)
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)
void executeUpdateSQL(String sql)
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)
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 executeInsertSQL(String sql)
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)