19package org.sleuthkit.autopsy.centralrepository.datamodel;
21import java.sql.Connection;
22import java.sql.PreparedStatement;
23import java.sql.ResultSet;
24import java.sql.SQLException;
25import java.sql.Statement;
26import java.util.ArrayList;
28import java.util.logging.Level;
29import javax.swing.SwingUtilities;
30import org.openide.windows.TopComponent;
31import org.openide.windows.WindowManager;
32import org.sleuthkit.autopsy.coreutils.Logger;
33import org.sleuthkit.autopsy.coreutils.ModuleSettings;
34import static org.sleuthkit.autopsy.centralrepository.datamodel.RdbmsCentralRepo.SOFTWARE_CR_DB_SCHEMA_VERSION;
35import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings;
55 if (
null != statement) {
58 }
catch (SQLException ex) {
59 LOGGER.log(Level.SEVERE,
"Error closing Statement.", ex);
72 if (
null != resultSet) {
75 }
catch (SQLException ex) {
76 LOGGER.log(Level.SEVERE,
"Error closing ResultSet.", ex);
92 }
catch (SQLException ex) {
93 LOGGER.log(Level.SEVERE,
"Error closing Connection.", ex);
106 PreparedStatement preparedStatement =
null;
107 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
111 preparedStatement = conn.prepareStatement(sql);
113 preparedStatement.setInt(1, newType.getId());
114 preparedStatement.setString(2, newType.getDisplayName());
115 preparedStatement.setString(3, newType.getDbTableName());
116 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
117 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
119 preparedStatement.addBatch();
121 preparedStatement.executeBatch();
123 LOGGER.log(Level.SEVERE,
"Error inserting default correlation types.", ex);
140 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
141 try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
143 preparedStatement.setInt(1, correlationType.getId());
144 preparedStatement.setString(2, correlationType.getDisplayName());
145 preparedStatement.setString(3, correlationType.getDbTableName());
146 preparedStatement.setInt(4, correlationType.isSupported() ? 1 : 0);
147 preparedStatement.setInt(5, correlationType.isEnabled() ? 1 : 0);
149 preparedStatement.execute();
160 static void updateSchemaVersion(Connection conn)
throws SQLException {
161 try (Statement statement = conn.createStatement()) {
162 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MAJOR_VERSION_KEY +
"'");
163 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MINOR_VERSION_KEY +
"'");
177 ResultSet resultSet =
null;
179 Statement tester = conn.createStatement();
180 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
181 resultSet = tester.executeQuery(sql);
182 if (resultSet.next()) {
183 String value = resultSet.getString(
"value");
185 }
catch (SQLException ex) {
220 static boolean insertDefaultOrganization(Connection conn) {
225 PreparedStatement preparedStatement =
null;
226 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
228 preparedStatement = conn.prepareStatement(sql);
230 preparedStatement.setString(2,
"");
231 preparedStatement.setString(3,
"");
232 preparedStatement.setString(4,
"");
233 preparedStatement.executeUpdate();
234 }
catch (SQLException ex) {
235 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
238 CentralRepoDbUtil.closePreparedStatement(preparedStatement);
274 SwingUtilities.invokeLater(() -> {
275 TopComponent personasWindow = WindowManager.getDefault().findTopComponent(
"PersonasTopComponent");
276 if (personasWindow !=
null && personasWindow.isOpened()) {
277 personasWindow.close();
293 ResultSet resultSet =
null;
295 Statement tester = conn.createStatement();
296 resultSet = tester.executeQuery(validationQuery);
297 if (resultSet.next()) {
300 }
catch (SQLException ex) {
317 return type.getDbTableName() +
"_instances";
328 return "reference_" + type.getDbTableName();
374 boolean commentExists =
false;
378 String sqlSelect =
"SELECT EXISTS "
381 String sqlWhere =
" WHERE value=? "
387 params =
new ArrayList<>();
388 params.add(instance.getCorrelationValue());
391 if (commentCallback.doesCommentExist()) {
393 commentExists =
true;
398 return commentExists;
422 boolean doesCommentExist() {
static CentralRepoSettings getInstance()
String getModuleSettingsKey()
static String correlationTypeToReferenceTableName(CorrelationAttributeInstance.Type type)
static void closeResultSet(ResultSet resultSet)
static String getDefaultOrgName()
static void insertCorrelationType(Connection conn, CorrelationAttributeInstance.Type correlationType)
static boolean executeValidationQuery(Connection conn, String validationQuery)
static boolean insertDefaultCorrelationTypes(Connection conn)
static void closeStatement(Statement statement)
static void closeConnection(Connection conn)
static boolean schemaVersionIsSet(Connection conn)
static final Logger LOGGER
static void closePersonasTopComponent()
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
static boolean isDefaultOrg(CentralRepoOrganization org)
static final String CENTRAL_REPO_NAME
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
static void closePreparedStatement(PreparedStatement preparedStatement)
static final String DEFAULT_ORG_NAME
static final String CENTRAL_REPO_USE_KEY
static boolean allowUseOfCentralRepository()
static boolean commentExistsOnAttributes(List< CorrelationAttributeInstance > attributes)
static final int PHONE_TYPE_ID
static final int EMAIL_TYPE_ID
static List< CorrelationAttributeInstance.Type > getDefaultCorrelationTypes()
static final int ADDITIONAL_TYPES_BASE_ID
synchronized static Logger getLogger(String name)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static synchronized String getConfigSetting(String moduleName, String settingName)
static CentralRepository getInstance()
void executeQuery(String sql, List< Object > params, CentralRepositoryDbQueryCallback queryCallback)
static boolean isEnabled()