19 package org.sleuthkit.autopsy.casemodule.services.contentviewertags;
21 import com.fasterxml.jackson.core.JsonProcessingException;
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 import java.io.IOException;
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
41 private static final ObjectMapper
SERIALIZER =
new ObjectMapper();
43 public static final String
TABLE_NAME =
"beta_tag_app_data";
45 +
"content_tag_id INTEGER NOT NULL, app_data TEXT NOT NULL, "
46 +
"FOREIGN KEY(content_tag_id) REFERENCES content_tags(tag_id))";
48 +
"content_tag_id INTEGER NOT NULL, app_data TEXT NOT NULL, "
49 +
"FOREIGN KEY(content_tag_id) REFERENCES content_tags(tag_id))";
51 private static final String
INSERT_TAG_DATA =
"(content_tag_id, app_data) VALUES (%d, '%s')";
52 private static final String
UPDATE_TAG_DATA =
"SET content_tag_id = %d, app_data = '%s' WHERE app_data_id = %d";
53 private static final String
SELECT_TAG_DATA =
"* FROM " + TABLE_NAME +
" WHERE content_tag_id = %d";
78 long contentTagId = contentTag.getId();
79 String serialAppData = SERIALIZER.writeValueAsString(tagDataBean);
80 String insertTemplateInstance = String.format(INSERT_TAG_DATA,
81 contentTagId, serialAppData);
84 .getCaseDbAccessManager()
85 .insert(TABLE_NAME, insertTemplateInstance);
87 }
catch (JsonProcessingException ex) {
88 throw new SerializationException(
"Unable to convert object instance into a storable format", ex);
110 String serialAppData = SERIALIZER.writeValueAsString(tagDataBean);
111 String updateTemplateInstance = String.format(UPDATE_TAG_DATA,
112 oldTag.getContentTag().getId(), serialAppData, oldTag.getId());
115 .getCaseDbAccessManager()
116 .update(TABLE_NAME, updateTemplateInstance);
118 }
catch (JsonProcessingException ex) {
119 throw new SerializationException(
"Unable to convert object instance into a storable format", ex);
143 String selectTemplateInstance = String.format(SELECT_TAG_DATA, contentTag.getId());
147 .getCaseDbAccessManager()
148 .select(selectTemplateInstance, (ResultSet rs) -> {
151 long tagId = rs.getLong(1);
152 String appDetails = rs.getString(3);
154 T instance = SERIALIZER.readValue(appDetails, clazz);
156 }
catch (IOException ex) {
162 }
catch (SQLException ex) {
168 throw new TskCoreException(
"Unable to select tag from case db", result.
getException());
183 private SQLException
ex = null;
194 return this.ex != null;
216 String deleteTemplateInstance = String.format(DELETE_TAG_DATA, contentViewerTag.getId());
219 .getCaseDbAccessManager()
220 .delete(TABLE_NAME, deleteTemplateInstance);
233 private final long id;
260 public static class SerializationException
extends Exception {
263 super(message, source);
static final String UPDATE_TAG_DATA
static< T > ContentViewerTag< T > updateTag(ContentViewerTag< T > oldTag, T tagDataBean)
SerializationException(String message, Exception source)
static final String INSERT_TAG_DATA
static< T > void deleteTag(ContentViewerTag< T > contentViewerTag)
static< T > ContentViewerTag< T > getTag(ContentTag contentTag, Class< T > clazz)
final ContentTag contentTag
ContentViewerTag(long id, ContentTag contentTag, T details)
static final String SELECT_TAG_DATA
static final String TABLE_SCHEMA_SQLITE
SQLException getException()
static final String TABLE_NAME
SleuthkitCase getSleuthkitCase()
ContentTag getContentTag()
static final String DELETE_TAG_DATA
void setException(SQLException ex)
static< T > ContentViewerTag< T > saveTag(ContentTag contentTag, T tagDataBean)
static Case getCurrentCaseThrows()
static final String TABLE_SCHEMA_POSTGRESQL
static final ObjectMapper SERIALIZER
ContentViewerTagManager()