Autopsy  4.20.0
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  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
147  // data source by type view
148  nodes = Arrays.asList(
149  new DataSourcesByType(),
150  new Views(skCase),
151  new DataArtifacts(),
152  new AnalysisResults(),
153  new OsAccounts(skCase),
154  new Tags(),
155  new ScoreContent(skCase),
156  new Reports()
157  );
158  }
159  } catch (NoCurrentCaseException ex) {
160  logger.log(Level.SEVERE, "Failed to create tree because there is no current case", ex); //NON-NLS
161  } catch (TskCoreException ex) {
162  logger.log(Level.SEVERE, "Failed to create tree because of an error querying the case database", ex); //NON-NLS
163  }
164 
165  // add all nodes to the netbeans node list
166  list.addAll(nodes);
167  return true;
168  }
169 
178  @Override
179  protected Node createNodeForKey(Object key) {
180  Node node = null;
181  if (key != null) {
182  if (key instanceof SleuthkitVisitableItem) {
183  node = ((SleuthkitVisitableItem) key).accept(new CreateSleuthkitNodeVisitor());
184  } else if (key instanceof AutopsyVisitableItem) {
185  node = ((AutopsyVisitableItem) key).accept(new RootContentChildren.CreateAutopsyNodeVisitor());
186  } else {
187  logger.log(Level.SEVERE, "Unknown key type: ", key.getClass().getName());
188  }
189  }
190  return node;
191  }
192 
196  public void refreshChildren() {
197  refresh(true);
198  }
199 
200 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:704
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:749

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.