From 4d192e88ea9bed1de25d322d85d0fd83f9367a46 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Wed, 1 Aug 2018 13:57:29 -0600 Subject: [PATCH] clients of normalizer class reflect new interface (throws exceptions) --- .../DataContentViewerOtherCases.java | 18 +++++++++++---- .../OtherOccurrenceNodeData.java | 5 ++-- .../datamodel/AbstractSqlEamDb.java | 23 ++++++++++--------- .../datamodel/EamArtifactUtil.java | 8 +++---- .../datamodel/EamGlobalFileInstance.java | 10 ++++---- .../ingestmodule/IngestModule.java | 3 ++- .../modules/hashdatabase/HashDbManager.java | 7 +++--- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java index 8ead475d95..8be7387e79 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java @@ -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) { - ret.add(new CorrelationAttribute(aType, md5)); + 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()) { - ret.add(new CorrelationAttribute(CorrelationAttribute.getDefaultCorrelationTypes().get(0), md5)); + 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) { diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/OtherOccurrenceNodeData.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/OtherOccurrenceNodeData.java index 958068fb14..05a2bd03a9 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/OtherOccurrenceNodeData.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/OtherOccurrenceNodeData.java @@ -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); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index fd2b26a241..81988c6af5 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -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; } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java index 2fdae3d011..5d60f5a8f9 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java @@ -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; } } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalFileInstance.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalFileInstance.java index a290fd1609..9ac89ed786 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalFileInstance.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalFileInstance.java @@ -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); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java b/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java index 9c30cf05c5..562116900a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java @@ -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; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index ad6e2b5688..a237e9556a 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -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); } }