clients of normalizer class reflect new interface (throws exceptions)

This commit is contained in:
Brian Sweeney 2018-08-01 13:57:29 -06:00
parent 703b41dcec
commit 4d192e88ea
7 changed files with 43 additions and 31 deletions

View File

@ -38,7 +38,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import java.util.stream.Collectors;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
@ -57,6 +56,7 @@ import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.centralrepository.AddEditCentralRepoCommentAction;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoValidationException;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance;
@ -131,8 +131,8 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi
String currentComment = action.addEditCentralRepoComment();
selectedNode.updateComment(currentComment);
otherCasesTable.repaint();
} catch (EamDbException ex) {
logger.log(Level.SEVERE, "Error performing Add/Edit Comment action", ex);
} catch (CentralRepoValidationException ex) {
logger.log(Level.SEVERE, "Error performing Add/Edit Comment action", ex); //NON-NLS
}
}
}
@ -432,7 +432,11 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi
if (md5 != null && !md5.isEmpty() && null != artifactTypes && !artifactTypes.isEmpty()) {
for (CorrelationAttribute.Type aType : artifactTypes) {
if (aType.getId() == CorrelationAttribute.FILES_TYPE_ID) {
try {
ret.add(new CorrelationAttribute(aType, md5));
} catch (CentralRepoValidationException ex) {
logger.log(Level.WARNING, String.format("MD5 (%s) was not formatted correctly. Not being considered in correlation attributes.", md5), ex); //NON-NLS
}
break;
}
}
@ -447,7 +451,11 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi
if (this.file != null) {
String md5 = this.file.getMd5Hash();
if (md5 != null && !md5.isEmpty()) {
try {
ret.add(new CorrelationAttribute(CorrelationAttribute.getDefaultCorrelationTypes().get(0), md5));
} catch (CentralRepoValidationException ex) {
logger.log(Level.WARNING, String.format("MD5 (%s) was not formatted correctly. Not being considered in correlation attributes.", md5), ex); //NON-NLS
}
}
}
} catch (EamDbException ex) {

View File

@ -19,6 +19,7 @@
package org.sleuthkit.autopsy.centralrepository.contentviewer;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoValidationException;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
@ -133,9 +134,9 @@ class OtherOccurrenceNodeData {
* Should only be called if isCentralRepoNode() is true.
* @return the newly created CorrelationAttribute
*/
CorrelationAttribute createCorrelationAttribute() throws EamDbException {
CorrelationAttribute createCorrelationAttribute() throws CentralRepoValidationException {
if (! isCentralRepoNode() ) {
throw new EamDbException("Can not create CorrelationAttribute for non central repo node");
throw new CentralRepoValidationException("Can not create CorrelationAttribute for non central repo node"); //NON-NLS
}
CorrelationAttribute attr = new CorrelationAttribute(type, value);
attr.addInstance(originalCorrelationInstance);

View File

@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.casemodule.Case;
import static org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil.updateSchemaVersion;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -742,7 +743,7 @@ abstract class AbstractSqlEamDb implements EamDb {
artifactInstance = getEamArtifactInstanceFromResultSet(resultSet);
artifactInstances.add(artifactInstance);
}
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting artifact instances by artifactType and artifactValue.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -849,7 +850,7 @@ abstract class AbstractSqlEamDb implements EamDb {
resultSet = preparedStatement.executeQuery();
resultSet.next();
instanceCount = resultSet.getLong(1);
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting count of artifact instances by artifactType and artifactValue.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -907,7 +908,7 @@ abstract class AbstractSqlEamDb implements EamDb {
resultSet = preparedStatement.executeQuery();
resultSet.next();
instanceCount = resultSet.getLong(1);
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error counting unique caseDisplayName/dataSource tuples having artifactType and artifactValue.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -1335,7 +1336,7 @@ abstract class AbstractSqlEamDb implements EamDb {
instanceId, correlationCase, correlationDataSource, filePath, comment, TskData.FileKnown.valueOf((byte) knownStatus));
correlationAttribute.addInstance(artifactInstance);
}
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting notable artifact instances.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -1497,7 +1498,7 @@ abstract class AbstractSqlEamDb implements EamDb {
artifactInstance = getEamArtifactInstanceFromResultSet(resultSet);
artifactInstances.add(artifactInstance);
}
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting notable artifact instances.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -1600,7 +1601,7 @@ abstract class AbstractSqlEamDb implements EamDb {
resultSet = preparedStatement.executeQuery();
resultSet.next();
badInstances = resultSet.getLong(1);
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting count of notable artifact instances.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -1656,7 +1657,7 @@ abstract class AbstractSqlEamDb implements EamDb {
while (resultSet.next()) {
caseNames.add(resultSet.getString("case_name"));
}
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting notable artifact instances.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -1801,7 +1802,7 @@ abstract class AbstractSqlEamDb implements EamDb {
resultSet = preparedStatement.executeQuery();
resultSet.next();
matchingInstances = resultSet.getLong(1);
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error determining if value (" + value + ") is in reference set " + referenceSetID, ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -1845,7 +1846,7 @@ abstract class AbstractSqlEamDb implements EamDb {
resultSet = preparedStatement.executeQuery();
resultSet.next();
badInstances = resultSet.getLong(1);
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error determining if artifact is notable by reference.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement);
@ -2543,7 +2544,7 @@ abstract class AbstractSqlEamDb implements EamDb {
}
return globalFileInstances;
} catch (SQLException ex) {
} catch (CentralRepoValidationException | SQLException ex) {
throw new EamDbException("Error getting reference instances by type and value.", ex); // NON-NLS
} finally {
EamDbUtil.closeStatement(preparedStatement1);
@ -2913,7 +2914,7 @@ abstract class AbstractSqlEamDb implements EamDb {
);
}
private EamGlobalFileInstance getEamGlobalFileInstanceFromResultSet(ResultSet resultSet) throws SQLException, EamDbException {
private EamGlobalFileInstance getEamGlobalFileInstanceFromResultSet(ResultSet resultSet) throws SQLException, EamDbException, CentralRepoValidationException {
if (null == resultSet) {
return null;
}

View File

@ -82,7 +82,7 @@ public class EamArtifactUtil {
}
}
}
} catch (EamDbException ex) {
} catch (EamDbException | CentralRepoValidationException ex) {
logger.log(Level.SEVERE, "Error getting defined correlation types.", ex); // NON-NLS
return eamArtifacts;
}
@ -137,7 +137,7 @@ public class EamArtifactUtil {
* bbArtifact did not contain the needed data
*/
private static CorrelationAttribute getCorrelationAttributeFromBlackboardArtifact(CorrelationAttribute.Type correlationType,
BlackboardArtifact bbArtifact) throws EamDbException {
BlackboardArtifact bbArtifact) throws EamDbException, CentralRepoValidationException {
String value = null;
int artifactTypeID = bbArtifact.getArtifactTypeID();
@ -286,8 +286,8 @@ public class EamArtifactUtil {
af.getParentPath() + af.getName());
eamArtifact.addInstance(cei);
return eamArtifact;
} catch (TskCoreException | EamDbException | NoCurrentCaseException ex) {
logger.log(Level.SEVERE, "Error making correlation attribute.", ex);
} catch (TskCoreException | EamDbException | NoCurrentCaseException | CentralRepoValidationException ex) {
logger.log(Level.SEVERE, "Error making correlation attribute.", ex); //NON-NLS
return null;
}
}

View File

@ -36,7 +36,7 @@ public class EamGlobalFileInstance {
int globalSetID,
String MD5Hash,
TskData.FileKnown knownStatus,
String comment) throws EamDbException {
String comment) throws EamDbException, CentralRepoValidationException {
this(-1, globalSetID, MD5Hash, knownStatus, comment);
}
@ -45,9 +45,9 @@ public class EamGlobalFileInstance {
int globalSetID,
String MD5Hash,
TskData.FileKnown knownStatus,
String comment) throws EamDbException {
String comment) throws EamDbException, CentralRepoValidationException {
if(MD5Hash == null){
throw new EamDbException("null MD5 hash");
throw new EamDbException("null MD5 hash"); //NON-NLS
}
if(knownStatus == null){
throw new EamDbException("null known status");
@ -116,9 +116,9 @@ public class EamGlobalFileInstance {
/**
* @param MD5Hash the MD5Hash to set
*/
public void setMD5Hash(String MD5Hash) throws EamDbException {
public void setMD5Hash(String MD5Hash) throws EamDbException, CentralRepoValidationException {
if(MD5Hash == null){
throw new EamDbException("null MD5 hash");
throw new EamDbException("null MD5 hash"); //NON-NLS
}
this.MD5Hash = CentralRepoIONormalizer.normalize(CorrelationAttribute.FILES_TYPE_ID, MD5Hash);
}

View File

@ -28,6 +28,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.casemodule.services.Blackboard;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoValidationException;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.ingest.FileIngestModule;
@ -159,7 +160,7 @@ final class IngestModule implements FileIngestModule {
);
eamArtifact.addInstance(cefi);
dbManager.prepareBulkArtifact(eamArtifact);
} catch (EamDbException ex) {
} catch (EamDbException | CentralRepoValidationException ex) {
logger.log(Level.SEVERE, "Error adding artifact to bulk artifacts.", ex); // NON-NLS
return ProcessResult.ERROR;
}

View File

@ -39,6 +39,7 @@ import org.netbeans.api.progress.ProgressHandle;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoValidationException;
import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
@ -1238,8 +1239,8 @@ public class HashDbManager implements PropertyChangeListener {
EamGlobalFileInstance fileInstance = new EamGlobalFileInstance(referenceSetID, file.getMd5Hash(),
type, comment);
EamDb.getInstance().addReferenceInstance(fileInstance,EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID));
} catch (EamDbException ex){
throw new TskCoreException("Error adding hashes to " + getDisplayName(), ex);
} catch (EamDbException | CentralRepoValidationException ex){
throw new TskCoreException("Error adding hashes to " + getDisplayName(), ex); //NON-NLS
}
}
}
@ -1264,7 +1265,7 @@ public class HashDbManager implements PropertyChangeListener {
}
try {
globalFileInstances.add(new EamGlobalFileInstance(referenceSetID, hashEntry.getMd5Hash(), type, hashEntry.getComment()));
} catch (EamDbException ex){
} catch (EamDbException | CentralRepoValidationException ex){
throw new TskCoreException("Error adding hashes to " + getDisplayName(), ex);
}
}