added callback and wrapper to process single row of file instance table by id.

This commit is contained in:
Andrew Ziehl 2018-06-27 12:01:30 -07:00
parent 69e6f47d38
commit dba86cd11e
4 changed files with 134 additions and 12 deletions

View File

@ -1782,6 +1782,46 @@ abstract class AbstractSqlEamDb implements EamDb {
* Process the Artifact instance in the EamDb
*
* @param type EamArtifact.Type to search for
* @param instanceTableCallback callback to process the instance
* @throws EamDbException
*/
@Override
public void processInstanceTableRow(CorrelationAttribute.Type type, int id, InstanceTableCallback instanceTableCallback) throws EamDbException {
if (type == null) {
throw new EamDbException("Correlation type is null");
}
if (instanceTableCallback == null) {
throw new EamDbException("Callback interface is null");
}
Connection conn = connect();
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String tableName = EamDbUtil.correlationTypeToInstanceTableName(type);
StringBuilder sql = new StringBuilder();
sql.append("select * from ");
sql.append(tableName);
sql.append("WHERE id = ?");
try {
preparedStatement = conn.prepareStatement(sql.toString());
preparedStatement.setInt(1, id);
resultSet = preparedStatement.executeQuery();
instanceTableCallback.process(resultSet);
} catch (SQLException ex) {
throw new EamDbException("Error getting all artifact instances from instances table", ex);
} finally {
EamDbUtil.closeStatement(preparedStatement);
EamDbUtil.closeResultSet(resultSet);
EamDbUtil.closeConnection(conn);
}
}
/**
* Process the Artifact instance in the EamDb
*
* @param type EamArtifact.Type to search for
* @param correlationCase CorrelationCase to filter by
* @param instanceTableCallback callback to process the instance
* @throws EamDbException

View File

@ -686,6 +686,16 @@ public interface EamDb {
*/
void processInstanceTable(CorrelationAttribute.Type type, InstanceTableCallback instanceTableCallback) throws EamDbException;
/**
* Process a single Artifact instance in the EamDb
*
* @param type EamArtifact.Type to search for
* @param id the id of the row to return
* @param instanceTableCallback callback to process the instance
* @throws EamDbException
*/
void processInstanceTableRow(CorrelationAttribute.Type type, int id, InstanceTableCallback instanceTableCallback) throws EamDbException;
/**
* Process the Artifact md5s in the EamDb for matches of case files which are not known
* @param type EamArtifact.Type to search for
@ -693,5 +703,5 @@ public interface EamDb {
* @param instanceTableCallback callback to process the instance
* @throws EamDbException
*/
public void processCaseInstancesTable(CorrelationAttribute.Type type, CorrelationCase correlationCase, InstanceTableCallback instanceTableCallback) throws EamDbException;
void processCaseInstancesTable(CorrelationAttribute.Type type, CorrelationCase correlationCase, InstanceTableCallback instanceTableCallback) throws EamDbException;
}

View File

@ -695,6 +695,25 @@ final class SqliteEamDb extends AbstractSqlEamDb {
releaseSharedLock();
}
}
/**
* Process a single Artifact instance row in the EamDb
*
* @param type EamArtifact.Type to search for
* @param id the id of the row to return
* @param instanceTableCallback callback to process the instance
* @throws EamDbException
*/
@Override
public void processInstanceTableRow(CorrelationAttribute.Type type, int id, InstanceTableCallback instanceTableCallback) throws EamDbException {
try {
acquireSharedLock();
super.processInstanceTableRow(type, id, instanceTableCallback);
} finally {
releaseSharedLock();
}
}
/**
* Process the Artifact md5s in the EamDb for matches of case files which are not known
* @param type EamArtifact.Type to search for

View File

@ -27,13 +27,15 @@ import java.util.logging.Level;
import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationCase;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
import org.sleuthkit.autopsy.centralrepository.datamodel.InstanceTableCallback;
import org.sleuthkit.autopsy.coreutils.Logger;
/**
* Used to process and return CorrelationCase md5s from the EamDB for CommonFilesSearch.
* Used to process and return CorrelationCase md5s from the EamDB for
* CommonFilesSearch.
*/
class EamDbAttributeInstancesAlgorithm {
@ -42,12 +44,29 @@ class EamDbAttributeInstancesAlgorithm {
private final Map<Integer, String> intercaseCommonValuesMap = new HashMap<>();
private final Map<Integer, String> intercaseCommonDatasourcesMap = new HashMap<>();
CorrelationAttribute processCorrelationCaseSingleAttribute(int attrbuteId) {
try {
EamDbAttributeInstanceRowCallback instancetableCallback = new EamDbAttributeInstanceRowCallback();
EamDb DbManager = EamDb.getInstance();
CorrelationAttribute.Type fileType = DbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
DbManager.processInstanceTableRow(fileType, attrbuteId, instancetableCallback);
return instancetableCallback.getCorrelationAttribute();
} catch (EamDbException ex) {
logger.log(Level.SEVERE, "Error accessing EamDb processing InstanceTable row.", ex);
}
return null;
}
void processCorrelationCaseAttributeValues(Case currentCase) {
try {
EamDbAttributeInstancesCallback instancetableCallback = new EamDbAttributeInstancesCallback();
EamDb DbManager = EamDb.getInstance();
CorrelationAttribute.Type fileType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
CorrelationAttribute.Type fileType = DbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
DbManager.processCaseInstancesTable(fileType, DbManager.getCase(currentCase), instancetableCallback);
intercaseCommonValuesMap.putAll(instancetableCallback.getCorrelationIdValueMap());
@ -97,4 +116,38 @@ class EamDbAttributeInstancesAlgorithm {
}
}
/**
* Callback to use with processCaseInstancesTable which generates a list of
* md5s for common files search
*/
private class EamDbAttributeInstanceRowCallback implements InstanceTableCallback {
CorrelationAttribute correlationAttribute = null;
@Override
public void process(ResultSet resultSet) {
try {
EamDb DbManager = EamDb.getInstance();
CorrelationAttribute.Type fileType = DbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
while (resultSet.next()) {
CorrelationCase correlationCase = DbManager.getCaseByUUID(String.valueOf(InstanceTableCallback.getCaseId(resultSet)));
correlationAttribute = DbManager.getCorrelationAttribute(fileType,
correlationCase,
DbManager.getDataSource(correlationCase, String.valueOf(InstanceTableCallback.getDataSourceId(resultSet))),
InstanceTableCallback.getValue(resultSet),
InstanceTableCallback.getFilePath(resultSet));
}
} catch (SQLException | EamDbException ex) {
Exceptions.printStackTrace(ex);
}
}
CorrelationAttribute getCorrelationAttribute() {
return correlationAttribute;
}
}
}