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;
40 =
"SELECT pmd.id, pmd.persona_id, pmd.name, pmd.value, pmd.justification, pmd.confidence_id, pmd.date_added, pmd.examiner_id, e.login_name, e.display_name "
41 +
"FROM persona_metadata as pmd "
42 +
"INNER JOIN examiners as e ON e.id = pmd.examiner_id ";
44 private final long id;
112 Instant instant = Instant.now();
113 Long timeStampMillis = instant.toEpochMilli();
115 String insertSQL =
"INSERT INTO persona_metadata (persona_id, name, value, justification, confidence_id, date_added, examiner_id ) "
116 +
"VALUES ( ?, ?, ?, ?, ?, ?, ?)";
118 List<Object> params =
new ArrayList<>();
119 params.add(personaId);
122 params.add(StringUtils.isBlank(justification) ?
"" :
justification);
124 params.add(timeStampMillis);
125 params.add(examiner.
getId());
130 +
"WHERE pmd.persona_id = ?"
131 +
" AND pmd.name = ?"
132 +
" AND pmd.value = ?"
133 +
" AND pmd.date_added = ?"
134 +
" AND pmd.examiner_id = ?";
136 List<Object> queryParams =
new ArrayList<>();
137 queryParams.add(personaId);
138 queryParams.add(name);
139 queryParams.add(value);
140 queryParams.add(timeStampMillis);
141 queryParams.add(examiner.
getId());
143 PersonaMetadataQueryCallback queryCallback =
new PersonaMetadataQueryCallback();
146 Collection<PersonaMetadata> metadata = queryCallback.getMetadataList();
147 if (metadata.size() != 1) {
148 throw new CentralRepoException(
"Metadata add query failed");
151 return metadata.iterator().next();
162 static void removePersonaMetadata(
PersonaMetadata metadata)
throws CentralRepoException {
163 String deleteSql =
" DELETE FROM persona_metadata WHERE id = ?";
165 List<Object> params =
new ArrayList<>();
166 params.add(metadata.getId());
179 static void modifyPersonaMetadata(
PersonaMetadata metadata, Persona.Confidence
confidence, String justification)
throws CentralRepoException {
180 CentralRepository cr = CentralRepository.getInstance();
183 throw new CentralRepoException(
"Failed to modify persona metadata, Central Repo is not enabled");
186 String updateSql =
"UPDATE persona_metadata SET confidence_id = ?, justification = ? WHERE id = ?";
188 List<Object> params =
new ArrayList<>();
190 params.add(StringUtils.isBlank(justification) ?
"" :
justification);
191 params.add(metadata.id);
201 Collection<PersonaMetadata> personaMetadataList =
new ArrayList<>();
204 public void process(ResultSet rs)
throws SQLException {
208 rs.getInt(
"examiner_id"),
209 rs.getString(
"login_name"));
213 rs.getLong(
"persona_id"),
214 rs.getString(
"name"),
215 rs.getString(
"value"),
216 rs.getString(
"justification"),
218 Long.parseLong(rs.getString(
"date_added")),
221 personaMetadataList.add(metaData);
225 Collection<PersonaMetadata> getMetadataList() {
226 return Collections.unmodifiableCollection(personaMetadataList);
238 static Collection<PersonaMetadata> getPersonaMetadata(
long personaId)
throws CentralRepoException {
240 +
"WHERE pmd.persona_id = ?";
242 List<Object> params =
new ArrayList<>();
243 params.add(personaId);
245 PersonaMetadataQueryCallback queryCallback =
new PersonaMetadataQueryCallback();
248 return queryCallback.getMetadataList();
263 if (instance == null) {
264 throw new CentralRepoException(
"Failed to get instance of CentralRespository, CR was null");
void executeQuery(String sql, List< Object > params, CentralRepositoryDbQueryCallback queryCallback)
CentralRepoExaminer getOrInsertExaminer(String examinerLoginName)
static Confidence fromId(int value)
void executeCommand(String sql, List< Object > params)
static CentralRepository getInstance()