diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java b/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java index 8b9a7ef862..b51ad3b94d 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/AddEditCentralRepoCommentAction.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.centralrepository; import java.awt.event.ActionEvent; +import java.util.logging.Level; import javax.swing.AbstractAction; import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; @@ -30,6 +31,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationDataSource; import org.sleuthkit.autopsy.centralrepository.datamodel.EamArtifactUtil; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; @@ -39,6 +41,8 @@ import org.sleuthkit.datamodel.TskCoreException; */ public final class AddEditCentralRepoCommentAction extends AbstractAction { + private static final Logger logger = Logger.getLogger(AddEditCentralRepoCommentAction.class.getName()); + private boolean addToDatabase; private CorrelationAttribute correlationAttribute; @@ -60,30 +64,19 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction { * is derived. * @param displayName The text for the menu item. */ - private AddEditCentralRepoCommentAction(AbstractFile file, String displayName) { + private AddEditCentralRepoCommentAction(AbstractFile file, String displayName) throws EamDbException, NoCurrentCaseException, TskCoreException { super(displayName); - try { - CorrelationAttribute.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); - CorrelationCase correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows()); - CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource()); - String value = file.getMd5Hash(); - String filePath = (file.getParentPath() + file.getName()).toLowerCase(); + CorrelationAttribute.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); + CorrelationCase correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows()); + CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource()); + String value = file.getMd5Hash(); + String filePath = (file.getParentPath() + file.getName()).toLowerCase(); - correlationAttribute = EamDb.getInstance().getCorrelationAttribute(type, correlationCase, correlationDataSource, value, filePath); - if (correlationAttribute == null) { - addToDatabase = true; - correlationAttribute = EamArtifactUtil.makeCorrelationAttributeFromContent(file); - } - } catch (TskCoreException ex) { - //DLG: - Exceptions.printStackTrace(ex); - } catch (EamDbException ex) { - //DLG: - Exceptions.printStackTrace(ex); - } catch (NoCurrentCaseException ex) { - //DLG: - Exceptions.printStackTrace(ex); + correlationAttribute = EamDb.getInstance().getCorrelationAttribute(type, correlationCase, correlationDataSource, value, filePath); + if (correlationAttribute == null) { + addToDatabase = true; + correlationAttribute = EamArtifactUtil.makeCorrelationAttributeFromContent(file); } } @@ -114,7 +107,7 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction { dbManager.updateAttributeInstanceComment(correlationAttribute); } } catch (EamDbException ex) { - Exceptions.printStackTrace(ex); //DLG: + logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex); } } } @@ -127,9 +120,15 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction { * derived. * * @return The instance. + * + * @throws EamDbException + * @throws NoCurrentCaseException + * @throws TskCoreException */ @Messages({"AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoComment=Add/Edit Central Repository Comment"}) - public static AddEditCentralRepoCommentAction createAddEditCentralRepoCommentAction(AbstractFile file) { + public static AddEditCentralRepoCommentAction createAddEditCentralRepoCommentAction(AbstractFile file) + throws EamDbException, NoCurrentCaseException, TskCoreException { + return new AddEditCentralRepoCommentAction(file, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoComment()); } @@ -144,6 +143,7 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction { */ @Messages({"AddEditCentralRepoCommentAction.menuItemText.addEditComment=Add/Edit Comment"}) public static AddEditCentralRepoCommentAction createAddEditCommentAction(CorrelationAttribute correlationAttribute) { + return new AddEditCentralRepoCommentAction(correlationAttribute, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditComment()); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java index 32b11a943f..ffcb311dd8 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationDataSource.java @@ -85,7 +85,10 @@ public class CorrelationDataSource implements Serializable { throw new EamDbException("Error getting data source info: " + ex.getMessage()); } - CorrelationDataSource correlationDataSource = EamDb.getInstance().getDataSource(correlationCase, deviceId); + CorrelationDataSource correlationDataSource = null; + if (EamDbUtil.useCentralRepo()) { + correlationDataSource = EamDb.getInstance().getDataSource(correlationCase, deviceId); + } if (correlationDataSource == null) { correlationDataSource = new CorrelationDataSource(correlationCase.getID(), deviceId, dataSource.getName()); } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java index c59cea6be9..10a9d0d961 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java @@ -38,6 +38,7 @@ import java.util.stream.Collectors; import javax.swing.Action; import org.apache.commons.lang3.StringUtils; import org.openide.nodes.Sheet; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.WeakListeners; @@ -49,6 +50,7 @@ import org.sleuthkit.autopsy.casemodule.events.BlackBoardArtifactTagDeletedEvent import org.sleuthkit.autopsy.casemodule.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.centralrepository.AddEditCentralRepoCommentAction; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -70,7 +72,7 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class BlackboardArtifactNode extends AbstractContentNode { - private static final Logger LOGGER = Logger.getLogger(BlackboardArtifactNode.class.getName()); + private static final Logger logger = Logger.getLogger(BlackboardArtifactNode.class.getName()); private static final Set CASE_EVENTS_OF_INTEREST = EnumSet.of(Case.Events.BLACKBOARD_ARTIFACT_TAG_ADDED, Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED, Case.Events.CONTENT_TAG_ADDED, @@ -223,7 +225,15 @@ public class BlackboardArtifactNode extends AbstractContentNode("Tags", Bundle.BlackboardArtifactNode_createSheet_tags_displayName(), NO_DESCR, tags.stream().map(t -> t.getName().getDisplayName()).collect(Collectors.joining(", ")))); @@ -497,7 +507,7 @@ public class BlackboardArtifactNode extends AbstractContentNode { // Create the "Add/Edit Central Repository Comment" menu item if the enabled. AbstractFile file = content; if (file != null && file.isFile() && EamDbUtil.useCentralRepo()) { - actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file)); + try { + actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file)); + } catch (EamDbException ex) { + logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex); // NON-NLS + } catch (NoCurrentCaseException ex) { + logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Could not retrieve data source from file '%s' (objId=%d).", file.getName(), file.getId()), ex); // NON-NLS + } } if (!this.getDirectoryBrowseMode()) {