19 package org.sleuthkit.autopsy.communications.relationships;
 
   21 import java.util.Arrays;
 
   22 import java.util.Collection;
 
   23 import java.util.HashSet;
 
   25 import java.util.TreeSet;
 
   26 import java.util.function.Consumer;
 
   27 import java.util.logging.Level;
 
   28 import org.openide.nodes.Children;
 
   29 import org.openide.nodes.Node;
 
   30 import org.openide.nodes.Sheet;
 
   31 import org.openide.util.NbBundle;
 
   47 final class AttachmentThumbnailsChildren 
extends Children.Keys<AbstractFile> {
 
   49     private static final Logger LOGGER = Logger.getLogger(AttachmentThumbnailsChildren.class.getName());
 
   51     private final Set<BlackboardArtifact> artifacts;
 
   60     AttachmentThumbnailsChildren(Set<BlackboardArtifact> artifacts) {
 
   63         this.artifacts = artifacts;
 
   68     protected Node[] createNodes(AbstractFile t) {
 
   69         return new Node[]{
new AttachementThumbnailNode(t)};
 
   73     protected void addNotify() {
 
   76         Set<AbstractFile> thumbnails = 
new TreeSet<>((AbstractFile file1, AbstractFile file2) -> {
 
   77             int result = Long.compare(file1.getSize(), file2.getSize());
 
   79                 result = file1.getName().compareTo(file2.getName());
 
   85         artifacts.forEach(
new Consumer<BlackboardArtifact>() {
 
   87             public void accept(BlackboardArtifact bba) {
 
   90                     BlackboardAttribute attachmentsAttr = bba.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ATTACHMENTS));
 
   91                     if (attachmentsAttr != null) {
 
   93                             MessageAttachments msgAttachments = BlackboardJsonAttrUtil.fromAttribute(attachmentsAttr, MessageAttachments.class);
 
   94                             Collection<FileAttachment> fileAttachments = msgAttachments.getFileAttachments();
 
   95                             for (FileAttachment fileAttachment : fileAttachments) {
 
   96                                 long attachedFileObjId = fileAttachment.getObjectId();
 
   97                                 if (attachedFileObjId >= 0) {
 
   98                                     AbstractFile attachedFile = bba.getSleuthkitCase().getAbstractFileById(attachedFileObjId);
 
   99                                     thumbnails.add(attachedFile);
 
  103                         catch (BlackboardJsonAttrUtil.InvalidJsonException ex) {
 
  104                             LOGGER.log(Level.WARNING, String.format(
"Unable to parse json for MessageAttachments object in artifact: %s", bba.getName()), ex);
 
  107                         for (Content childContent : bba.getChildren()) {
 
  108                             if (childContent instanceof AbstractFile) {
 
  109                                 thumbnails.add((AbstractFile) childContent);
 
  114                 } 
catch (TskCoreException ex) {
 
  115                     LOGGER.log(Level.WARNING, 
"Unable to get children from artifact.", ex); 
 
  126     static class AttachementThumbnailNode 
extends FileNode {
 
  128         AttachementThumbnailNode(AbstractFile file) {
 
  133         protected Sheet createSheet() {
 
  134             Sheet sheet = super.createSheet();
 
  135             Set<String> keepProps = 
new HashSet<>(Arrays.asList(
 
  136                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.nameColLbl"),
 
  137                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.createSheet.score.name"),
 
  138                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.createSheet.comment.name"),
 
  139                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.createSheet.count.name"),
 
  140                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.sizeColLbl"),
 
  141                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.mimeType"),
 
  142                     NbBundle.getMessage(AbstractAbstractFileNode.class, 
"AbstractAbstractFileNode.knownColLbl")));
 
  145             Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
 
  146             for (Node.Property<?> p : sheetSet.getProperties()) {
 
  147                 if (!keepProps.contains(p.getName())) {
 
  148                     sheetSet.remove(p.getName());