Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AutopsyTreeChildFactory.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  * Copyright 2018-2021 Basis Technology Corp.
4  * Contact: carrier <at> sleuthkit <dot> org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.sleuthkit.autopsy.datamodel;
19 
20 import java.beans.PropertyChangeEvent;
21 import java.beans.PropertyChangeListener;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.EnumSet;
25 import java.util.List;
26 import java.util.Objects;
27 import java.util.Set;
28 import java.util.logging.Level;
29 import java.util.stream.Collectors;
30 import org.apache.commons.collections.CollectionUtils;
31 import org.openide.nodes.ChildFactory;
32 import org.openide.nodes.Node;
33 import org.openide.util.WeakListeners;
38 import org.sleuthkit.datamodel.Person;
39 import org.sleuthkit.datamodel.PersonManager;
40 import org.sleuthkit.datamodel.SleuthkitCase;
41 import org.sleuthkit.datamodel.SleuthkitVisitableItem;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
50 public final class AutopsyTreeChildFactory extends ChildFactory.Detachable<Object> {
51 
52  private static final Set<Case.Events> EVENTS_OF_INTEREST = EnumSet.of(Case.Events.DATA_SOURCE_ADDED,
59  );
60 
61  private static final Set<String> EVENTS_OF_INTEREST_NAMES = EVENTS_OF_INTEREST.stream()
62  .map(evt -> evt.name())
63  .collect(Collectors.toSet());
64 
65  private static final Logger logger = Logger.getLogger(AutopsyTreeChildFactory.class.getName());
66 
74  private final PropertyChangeListener pcl = new PropertyChangeListener() {
75  @Override
76  public void propertyChange(PropertyChangeEvent evt) {
77  String eventType = evt.getPropertyName();
78  if (EVENTS_OF_INTEREST_NAMES.contains(eventType)
79  && Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true)) {
81  }
82  }
83  };
84 
85  private final PropertyChangeListener weakPcl = WeakListeners.propertyChange(pcl, null);
86 
87  @Override
88  protected void addNotify() {
89  super.addNotify();
91  }
92 
93  @Override
94  protected void finalize() throws Throwable {
95  super.finalize();
97  }
98 
113  @Override
114  protected boolean createKeys(List<Object> list) {
115  List<Object> nodes = Collections.emptyList();
116  try {
117  SleuthkitCase tskCase = Case.getCurrentCaseThrows().getSleuthkitCase();
118  if (Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(), true)) {
119  /*
120  * The user has selected the group by person/host tree view
121  * option.
122  */
123  PersonManager personManager = tskCase.getPersonManager();
124  List<Person> persons = personManager.getPersons();
125  // show persons level if there are persons to be shown
126  if (!CollectionUtils.isEmpty(persons)) {
127  nodes = persons.stream()
128  .map(PersonGrouping::new)
129  .sorted()
130  .collect(Collectors.toList());
131 
132  if (CollectionUtils.isNotEmpty(personManager.getHostsWithoutPersons())) {
133  nodes.add(new PersonGrouping(null));
134  }
135  } else {
136  // otherwise, just show host level
137  nodes = tskCase.getHostManager().getAllHosts().stream()
138  .map(HostGrouping::new)
139  .sorted()
140  .collect(Collectors.toList());
141  }
142 
143  // either way, add in reports node
144  nodes.add(new Reports());
145  } else {
146  // data source by type view
147  nodes = Arrays.asList(
148  new DataSourcesByType(),
150  new DataArtifacts(),
151  new AnalysisResults(),
153  new Tags(),
154  new Reports()
155  );
156  }
157  } catch (NoCurrentCaseException ex) {
158  logger.log(Level.SEVERE, "Failed to create tree because there is no current case", ex); //NON-NLS
159  } catch (TskCoreException ex) {
160  logger.log(Level.SEVERE, "Failed to create tree because of an error querying the case database", ex); //NON-NLS
161  }
162 
163  // add all nodes to the netbeans node list
164  list.addAll(nodes);
165  return true;
166  }
167 
176  @Override
177  protected Node createNodeForKey(Object key) {
178  Node node = null;
179  if (key != null) {
180  if (key instanceof SleuthkitVisitableItem) {
181  node = ((SleuthkitVisitableItem) key).accept(new CreateSleuthkitNodeVisitor());
182  } else if (key instanceof AutopsyVisitableItem) {
183  node = ((AutopsyVisitableItem) key).accept(new RootContentChildren.CreateAutopsyNodeVisitor());
184  } else {
185  logger.log(Level.SEVERE, "Unknown key type: ", key.getClass().getName());
186  }
187  }
188  return node;
189  }
190 
194  public void refreshChildren() {
195  refresh(true);
196  }
197 
198 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:711
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:756

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.