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 org.apache.commons.lang3.StringUtils;
38 "SELECT pa.id, pa.persona_id, pa.alias, pa.justification, pa.confidence_id, pa.date_added, pa.examiner_id, e.login_name, e.display_name "
39 +
"FROM persona_alias as pa "
40 +
"INNER JOIN examiners as e ON e.id = pa.examiner_id ";
42 private final long id;
103 Instant instant = Instant.now();
104 Long timeStampMillis = instant.toEpochMilli();
106 String insertClause =
" INTO persona_alias (persona_id, alias, justification, confidence_id, date_added, examiner_id ) "
108 + persona.
getId() +
", "
109 +
"'" + alias +
"', "
110 +
"'" + ((StringUtils.isBlank(justification) ?
"" : SleuthkitCase.escapeSingleQuotes(justification))) +
"', "
112 + timeStampMillis.toString() +
", "
118 String queryClause = SELECT_QUERY_BASE
119 +
"WHERE pa.persona_id = " + persona.
getId()
120 +
" AND pa.alias = '" + alias +
"'"
121 +
" AND pa.date_added = " + timeStampMillis
122 +
" AND pa.examiner_id = " + examiner.
getId();
124 PersonaAliasesQueryCallback queryCallback =
new PersonaAliasesQueryCallback();
127 Collection<PersonaAlias> aliases = queryCallback.getAliases();
128 if (aliases.size() != 1) {
129 throw new CentralRepoException(
"Alias add query failed");
132 return aliases.iterator().next();
142 static void removePersonaAlias(
PersonaAlias alias)
throws CentralRepoException {
143 String deleteClause =
" DELETE FROM persona_alias WHERE id = " + alias.getId();
154 static void modifyPersonaAlias(
PersonaAlias alias, Persona.Confidence
confidence, String justification)
throws CentralRepoException {
155 CentralRepository cr = CentralRepository.getInstance();
158 throw new CentralRepoException(
"Failed to modify persona alias, Central Repo is not enabled");
161 String updateClause =
"UPDATE persona_alias SET confidence_id = " +
confidence.getLevelId() +
", justification = '" + justification +
"' WHERE id = " + alias.
id;
162 cr.executeUpdateSQL(updateClause);
169 static class PersonaAliasesQueryCallback
implements CentralRepositoryDbQueryCallback {
171 private final Collection<PersonaAlias> personaAliases =
new ArrayList<>();
174 public void process(ResultSet rs)
throws SQLException {
177 CentralRepoExaminer examiner =
new CentralRepoExaminer(
178 rs.getInt(
"examiner_id"),
179 rs.getString(
"login_name"));
183 rs.getLong(
"persona_id"),
184 rs.getString(
"alias"),
185 rs.getString(
"justification"),
186 Persona.Confidence.fromId(rs.getInt(
"confidence_id")),
187 Long.parseLong(rs.getString(
"date_added")),
190 personaAliases.add(alias);
194 Collection<PersonaAlias> getAliases() {
195 return Collections.unmodifiableCollection(personaAliases);
207 public static Collection<PersonaAlias>
getPersonaAliases(
long personaId)
throws CentralRepoException {
208 String queryClause = SELECT_QUERY_BASE +
"WHERE pa.persona_id = " +
personaId;
210 PersonaAliasesQueryCallback queryCallback =
new PersonaAliasesQueryCallback();
213 return queryCallback.getAliases();
227 if(instance == null) {
228 throw new CentralRepoException(
"Failed to get instance of CentralRespository, CR was null");
void executeSelectSQL(String sql, CentralRepositoryDbQueryCallback queryCallback)
CentralRepoExaminer getExaminer()
final String justification
Persona.Confidence getConfidence()
CentralRepoExaminer getOrInsertExaminer(String examinerLoginName)
static final String SELECT_QUERY_BASE
void executeDeleteSQL(String sql)
static Collection< PersonaAlias > getPersonaAliases(long personaId)
String getJustification()
static CentralRepository getCRInstance()
final Persona.Confidence confidence
final CentralRepoExaminer examiner
void executeInsertSQL(String sql)
PersonaAlias(long id, long personaId, String alias, String justification, Persona.Confidence confidence, long dateAdded, CentralRepoExaminer examiner)
static CentralRepository getInstance()