From e4442cce82b55cc6889639fd48fd6d0d0bb5c21c Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 23 Feb 2021 14:24:32 -0500 Subject: [PATCH] fixes --- .../sleuthkit/autopsy/datamodel/HostNode.java | 5 ++- .../hosts/AssociateNewPersonAction.java | 10 ++++-- .../hosts/AssociatePersonAction.java | 13 ++++--- .../hosts/AssociatePersonsMenuAction.java | 15 +++++--- .../datamodel/persons/DeletePersonAction.java | 3 ++ .../datamodel/persons/EditPersonAction.java | 7 ++++ .../DirectoryTreeFilterNode.java | 35 +++++++++++++------ 7 files changed, 62 insertions(+), 26 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java index d00a61bd48..7e40db5f9d 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/HostNode.java @@ -246,20 +246,23 @@ public class HostNode extends DisplayableItemNode { Optional parent = Optional.empty(); + // if there is a host, then provide actions if (this.host != null) { try { - parent = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getPerson(this.host); + parent = Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().getPerson(this.host); } catch (NoCurrentCaseException | TskCoreException ex) { logger.log(Level.WARNING, String.format("Error fetching parent person of host: %s", this.host.getName() == null ? "" : this.host.getName()), ex); return new Action[0]; } + // if there is a parent, only give option to remove parent person. if (parent.isPresent()) { return new Action[]{ new RemoveParentPersonAction(this.host, parent.get()), null }; } else { + // otherwise provide options to associate with new person or existing persons List existingPersons = Collections.emptyList(); try { existingPersons = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().getPersons(); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java index fc81ab4e2a..6fbcdd6f8e 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociateNewPersonAction.java @@ -28,7 +28,6 @@ import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.persons.AddEditPersonDialog; import org.sleuthkit.datamodel.Host; @@ -64,7 +63,7 @@ public class AssociateNewPersonAction extends AbstractAction { public void actionPerformed(ActionEvent e) { String newPersonName = ""; try { - newPersonName = getAddDialogName(); + newPersonName = getAddDialogName(); if (StringUtils.isNotBlank(newPersonName)) { Person person = Case.getCurrentCaseThrows().getSleuthkitCase().getPersonManager().createPerson(newPersonName); Case.getCurrentCaseThrows().getSleuthkitCase().getHostManager().setPerson(host, person); @@ -82,6 +81,13 @@ public class AssociateNewPersonAction extends AbstractAction { } + /** + * Get dialog to add new person name. + * + * @return The name for the new person or null to cancel. + * @throws NoCurrentCaseException + * @throws TskCoreException + */ private String getAddDialogName() throws NoCurrentCaseException, TskCoreException { Frame parent = WindowManager.getDefault().getMainWindow(); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java index 341931941b..a58787997f 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonAction.java @@ -26,7 +26,6 @@ import org.openide.util.NbBundle.Messages; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; -import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.Host; import org.sleuthkit.datamodel.Person; @@ -51,14 +50,14 @@ public class AssociatePersonAction extends AbstractAction { /** * Main constructor. * - * @param host The host that will become parentless. - * @param person The person to be removed as a parent from the host. + * @param host The host that will get associated with the person. + * @param person The person to be the parent of the host. */ public AssociatePersonAction(Host host, Person person) { - super(person == null || person.getName() == null ? - Bundle.RemoveParentPersonAction_unknownPerson() : - person.getName()); - + super(person == null || person.getName() == null + ? Bundle.RemoveParentPersonAction_unknownPerson() + : person.getName()); + this.host = host; this.person = person; } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonsMenuAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonsMenuAction.java index 6c780f6662..c7bc7ed3ee 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonsMenuAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/AssociatePersonsMenuAction.java @@ -30,16 +30,22 @@ import org.sleuthkit.datamodel.Person; /** * - * JMenu item to show menu to associate given host with an existing person. + * JMenu item to show a menu giving options to associate the given host with an + * existing person. */ @Messages({ - "AssociatePersonsMenuAction_menuTitle=Associate with Existing Person", -}) + "AssociatePersonsMenuAction_menuTitle=Associate with Existing Person",}) public class AssociatePersonsMenuAction extends AbstractAction implements Presenter.Popup { private final List persons; private final Host host; + /** + * Main constructor. + * + * @param persons The persons that this host can be associated with. + * @param host The host. + */ public AssociatePersonsMenuAction(List persons, Host host) { super(""); this.persons = persons; @@ -63,6 +69,5 @@ public class AssociatePersonsMenuAction extends AbstractAction implements Presen return menu; } - - + } diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java index 47b3a42ce1..76312fb3a8 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/persons/DeletePersonAction.java @@ -58,6 +58,9 @@ public class DeletePersonAction extends AbstractAction { setEnabled(); } + /** + * Sets the action enabled only if no child hosts. + */ private void setEnabled() { if (person == null) { this.setEnabled(false); diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/persons/EditPersonAction.java b/Core/src/org/sleuthkit/autopsy/datamodel/persons/EditPersonAction.java index 042d1c6e28..2343557f6b 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/persons/EditPersonAction.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/persons/EditPersonAction.java @@ -76,6 +76,13 @@ public class EditPersonAction extends AbstractAction { } } + /** + * Presents a dialog that will allow the user to edit the person's name. + * @param person The person. + * @return The edited person's name or null if cancelled.. + * @throws NoCurrentCaseException + * @throws TskCoreException + */ private String getEditedPersonName(Person person) throws NoCurrentCaseException, TskCoreException { Frame parent = WindowManager.getDefault().getMainWindow(); diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java index 6dd6039d37..fc561da950 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java @@ -25,6 +25,7 @@ import java.util.logging.Level; import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; +import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.lookup.Lookups; import org.openide.util.lookup.ProxyLookup; @@ -36,6 +37,8 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE; import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.Host; +import org.sleuthkit.datamodel.Person; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; @@ -54,9 +57,9 @@ class DirectoryTreeFilterNode extends FilterNode { * the tree view and wraps the Children object of the wrapped node with a * DirectoryTreeFilterChildren. * - * @param nodeToWrap The node to wrap. + * @param nodeToWrap The node to wrap. * @param createChildren Whether to create the children of the wrapped node - * or treat it a a leaf node. + * or treat it a a leaf node. */ DirectoryTreeFilterNode(Node nodeToWrap, boolean createChildren) { super(nodeToWrap, @@ -131,7 +134,7 @@ class DirectoryTreeFilterNode extends FilterNode { numVisibleChildren--; } } else if (child instanceof BlackboardArtifact) { - + if (FilterNodeUtils.showMessagesInDatasourceTree()) { // In older versions of Autopsy, attachments were children of email/message artifacts // and hence email/messages with attachments are shown in the directory tree. @@ -141,8 +144,7 @@ class DirectoryTreeFilterNode extends FilterNode { && (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) { numVisibleChildren--; } - } - else { + } else { numVisibleChildren--; } } @@ -156,22 +158,33 @@ class DirectoryTreeFilterNode extends FilterNode { * Gets the context mneu (right click menu) actions for the wrapped node. * * @param context Whether to find actions for context meaning or for the - * node itself. + * node itself. * * @return */ @Override public Action[] getActions(boolean context) { List actions = new ArrayList<>(); - - //final Content content = this.getLookup().lookup(Content.class); - //if (content != null) { - actions.addAll(Arrays.asList(super.getActions(true))); - //} + actions.addAll(Arrays.asList(getNodeActions())); actions.add(collapseAllAction); return actions.toArray(new Action[actions.size()]); } + /** + * @return If lookup node is content, host, or person, returns super + * actions. Otherwise, returns empty array. + */ + private Action[] getNodeActions() { + Lookup lookup = this.getLookup(); + if (lookup.lookup(Content.class) != null + || lookup.lookup(Host.class) != null + || lookup.lookup(Person.class) != null) { + return super.getActions(true); + } else { + return new Action[0]; + } + } + /** * Get the wrapped node. *