diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index ee017de8422..83746237a60 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -46,6 +46,8 @@ import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoAccount.CentralRepoAccountType; +import static org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil.correlationAttribHasAnAccount; +import static org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil.correlationTypeToInstanceTableName; import static org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil.updateSchemaVersion; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.healthmonitor.HealthMonitor; @@ -1668,7 +1670,14 @@ public void addAttributeInstanceBulk(CorrelationAttributeInstance eamArtifact) t @Override public void commitAttributeInstancesBulk() throws CentralRepoException { List artifactTypes = getDefinedCorrelationTypes(); - + + Map correlationHasAccount = new HashMap<>(); + for (CorrelationAttributeInstance.Type artifactType : artifactTypes) { + String tableName = correlationTypeToInstanceTableName(artifactType); + Boolean isAccount = Boolean.valueOf(correlationAttribHasAnAccount(artifactType)); + correlationHasAccount.put(correlationTypeToInstanceTableName(artifactType), Boolean.valueOf(correlationAttribHasAnAccount(artifactType))); + } + Connection conn = connect(); PreparedStatement bulkPs = null; @@ -1680,14 +1689,23 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { for (String tableName : bulkArtifacts.keySet()) { - String sql - = "INSERT INTO " - + tableName - + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) " - + "VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), " - + "(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?) " - + getConflictClause(); - + String sql; + if (correlationHasAccount.get(tableName)) { + sql = "INSERT INTO " + + tableName + + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id, account_id) " + + "VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), " + + "(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?, ?) " + + getConflictClause(); + } else { + sql = "INSERT INTO " + + tableName + + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) " + + "VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), " + + "(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?) " + + getConflictClause(); + } + bulkPs = conn.prepareStatement(sql); Collection eamArtifacts = bulkArtifacts.get(tableName); @@ -1730,6 +1748,9 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { bulkPs.setString(7, eamArtifact.getComment()); } bulkPs.setLong(8, eamArtifact.getFileObjectId()); + if (correlationHasAccount.get(tableName)) { + bulkPs.setLong(9, eamArtifact.getAccountId()); + } bulkPs.addBatch(); } else { logger.log(Level.WARNING, ("Artifact value too long for central repository."