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 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 insertSQL =
"INSERT INTO persona_alias (persona_id, alias, justification, confidence_id, date_added, examiner_id ) "
107 +
" VALUES ( ?, ?, ?, ?, ?, ?)";
109 List<Object> params =
new ArrayList<>();
110 params.add(persona.
getId());
112 params.add(StringUtils.isBlank(justification) ?
"" :
justification);
114 params.add(timeStampMillis);
115 params.add(examiner.
getId());
120 +
"WHERE pa.persona_id = ?"
121 +
" AND pa.alias = ?"
122 +
" AND pa.date_added = ?"
123 +
" AND pa.examiner_id = ?";
125 List<Object> queryParams =
new ArrayList<>();
126 queryParams.add(persona.
getId());
127 queryParams.add(alias);
128 queryParams.add(timeStampMillis);
129 queryParams.add(examiner.
getId());
131 PersonaAliasesQueryCallback queryCallback =
new PersonaAliasesQueryCallback();
134 Collection<PersonaAlias> aliases = queryCallback.getAliases();
135 if (aliases.size() != 1) {
136 throw new CentralRepoException(
"Alias add query failed");
139 return aliases.iterator().next();
149 static void removePersonaAlias(
PersonaAlias alias)
throws CentralRepoException {
150 String deleteSQL =
" DELETE FROM persona_alias WHERE id = ?";
152 List<Object> params =
new ArrayList<>();
153 params.add(alias.getId());
165 static void modifyPersonaAlias(
PersonaAlias alias, Persona.Confidence
confidence, String justification)
throws CentralRepoException {
166 CentralRepository cr = CentralRepository.getInstance();
169 throw new CentralRepoException(
"Failed to modify persona alias, Central Repo is not enabled");
172 String updateClause =
"UPDATE persona_alias SET confidence_id = ?, justification = ? WHERE id = ?";
174 List<Object> params =
new ArrayList<>();
176 params.add(StringUtils.isBlank(justification) ?
"" :
justification);
177 params.add(alias.getId());
179 cr.executeCommand(updateClause, params);
185 static class PersonaAliasesQueryCallback
implements CentralRepositoryDbQueryCallback {
187 private final Collection<PersonaAlias> personaAliases =
new ArrayList<>();
190 public void process(ResultSet rs)
throws SQLException {
193 CentralRepoExaminer examiner =
new CentralRepoExaminer(
194 rs.getInt(
"examiner_id"),
195 rs.getString(
"login_name"));
199 rs.getLong(
"persona_id"),
200 rs.getString(
"alias"),
201 rs.getString(
"justification"),
202 Persona.Confidence.fromId(rs.getInt(
"confidence_id")),
203 Long.parseLong(rs.getString(
"date_added")),
206 personaAliases.add(alias);
210 Collection<PersonaAlias> getAliases() {
211 return Collections.unmodifiableCollection(personaAliases);
223 public static Collection<PersonaAlias>
getPersonaAliases(
long personaId)
throws CentralRepoException {
225 +
"WHERE pa.persona_id = ?";
227 List<Object> params =
new ArrayList<>();
228 params.add(personaId);
230 PersonaAliasesQueryCallback queryCallback =
new PersonaAliasesQueryCallback();
233 return queryCallback.getAliases();
247 if (instance == null) {
248 throw new CentralRepoException(
"Failed to get instance of CentralRespository, CR was null");
CentralRepoExaminer getExaminer()
void executeQuery(String sql, List< Object > params, CentralRepositoryDbQueryCallback queryCallback)
final String justification
Persona.Confidence getConfidence()
CentralRepoExaminer getOrInsertExaminer(String examinerLoginName)
static final String SELECT_QUERY_BASE
static Collection< PersonaAlias > getPersonaAliases(long personaId)
String getJustification()
static CentralRepository getCRInstance()
final Persona.Confidence confidence
final CentralRepoExaminer examiner
void executeCommand(String sql, List< Object > params)
PersonaAlias(long id, long personaId, String alias, String justification, Persona.Confidence confidence, long dateAdded, CentralRepoExaminer examiner)
static CentralRepository getInstance()