From bd6d89c7869846aa5891d75020a6345c5f4209f5 Mon Sep 17 00:00:00 2001
From: adam-m <amalinowski@basistech.com>
Date: Thu, 17 Jan 2013 19:01:07 -0500
Subject: [PATCH] do not create bb attributes with empty comments if comment
 not set

---
 .../datamodel/BlackboardArtifactNode.java     |  3 ++-
 .../org/sleuthkit/autopsy/datamodel/Tags.java | 26 +++++++++++++------
 .../autopsy/directorytree/TagDialog.form      |  1 +
 .../autopsy/directorytree/TagDialog.java      |  6 +----
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java
index 9ddb752375..4f3da229dd 100644
--- a/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java
+++ b/Core/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java
@@ -168,7 +168,8 @@ private void fillPropertyMap(Map<String, Object> map, BlackboardArtifact artifac
                 } else {
                     switch (attribute.getValueType()) {
                         case STRING:
-                            map.put(attribute.getAttributeTypeDisplayName(), attribute.getValueString());
+                            String valString = attribute.getValueString();
+                            map.put(attribute.getAttributeTypeDisplayName(),  valString == null ? "":valString);
                             break;
                         case INTEGER:
                             map.put(attribute.getAttributeTypeDisplayName(), attribute.getValueInt());
diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/Tags.java b/Core/src/org/sleuthkit/autopsy/datamodel/Tags.java
index db55d3ae9a..f73d384449 100644
--- a/Core/src/org/sleuthkit/autopsy/datamodel/Tags.java
+++ b/Core/src/org/sleuthkit/autopsy/datamodel/Tags.java
@@ -63,6 +63,8 @@ public class Tags implements AutopsyVisitableItem {
     public static final String NAME = "Tags";
     private static final String TAG_ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png";
     private Map<BlackboardArtifact.ARTIFACT_TYPE, Map<String, List<BlackboardArtifact>>> tags;
+    
+    private static final String EMPTY_COMMENT = "No Comment";
 
     Tags(SleuthkitCase skCase) {
         this.skCase = skCase;
@@ -383,7 +385,7 @@ public void actionPerformed(ActionEvent e) {
      *
      * @param file to create tag for
      * @param tagName TSK_TAG_NAME
-     * @param comment the tag comment
+     * @param comment the tag comment, or null if not present
      */
     public static void createTag(AbstractFile file, String tagName, String comment) {
         try {
@@ -393,10 +395,13 @@ public static void createTag(AbstractFile file, String tagName, String comment)
 
             BlackboardAttribute attr1 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID(),
                     "", tagName);
-            BlackboardAttribute attr2 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID(),
-                    "", comment);
             attrs.add(attr1);
-            attrs.add(attr2);
+            
+            if (comment != null && ! comment.isEmpty()) {
+                BlackboardAttribute attr2 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID(),
+                    "", comment);
+                attrs.add(attr2);
+            }
             bookArt.addAttributes(attrs);
         } catch (TskCoreException ex) {
             logger.log(Level.SEVERE, "Failed to create tag for " + file.getName());
@@ -408,7 +413,7 @@ public static void createTag(AbstractFile file, String tagName, String comment)
      *
      * @param artifact to create tag for
      * @param tagName TSK_TAG_NAME
-     * @param comment the tag comment
+     * @param comment the tag comment or null if not present
      */
     public static void createTag(BlackboardArtifact artifact, String tagName, String comment) {
         try {
@@ -422,12 +427,17 @@ public static void createTag(BlackboardArtifact artifact, String tagName, String
 
             BlackboardAttribute attr1 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAG_NAME.getTypeID(),
                     "", tagName);
-            BlackboardAttribute attr2 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID(),
+            
+            if (comment != null && ! comment.isEmpty()) {
+                BlackboardAttribute attr2 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_COMMENT.getTypeID(),
                     "", comment);
+                attrs.add(attr2);
+            }
+            
             BlackboardAttribute attr3 = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TAGGED_ARTIFACT.getTypeID(),
                     "", artifact.getArtifactID());
             attrs.add(attr1);
-            attrs.add(attr2);
+            
             attrs.add(attr3);
             bookArt.addAttributes(attrs);
         } catch (TskCoreException ex) {
@@ -550,7 +560,7 @@ static String getCommentFromTag(long tagArtifactId) {
             logger.log(Level.SEVERE, "Failed to get artifact " + tagArtifactId + " from case.");
         }
 
-        return null;
+        return EMPTY_COMMENT;
     }
 
     /**
diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.form b/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.form
index f8bdce7c24..71174010c6 100644
--- a/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.form
+++ b/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.form
@@ -3,6 +3,7 @@
 <Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
   <SyntheticProperties>
     <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+    <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
   </SyntheticProperties>
   <Events>
     <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="closeDialog"/>
diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.java b/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.java
index 98332dbd1f..aab5bed9d0 100644
--- a/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.java
+++ b/Core/src/org/sleuthkit/autopsy/directorytree/TagDialog.java
@@ -236,11 +236,7 @@ String getSelectedTag() {
     }
 
     String getComment() {
-        String comment = commentText.getText();
-        if (comment == null || comment.isEmpty()) {
-            return "No Comment";
-        }
-        return comment;
+        return commentText.getText();
     }
 
     TagDialogResult getResult() {
-- 
GitLab