19package org.sleuthkit.autopsy.discovery.ui;
21import org.sleuthkit.autopsy.discovery.search.AbstractFilter;
22import java.util.LinkedHashMap;
23import javax.swing.SwingWorker;
26import java.util.logging.Level;
27import org.sleuthkit.autopsy.casemodule.Case;
28import org.sleuthkit.autopsy.coreutils.Logger;
29import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
30import org.sleuthkit.autopsy.discovery.search.DiscoveryAttributes;
31import org.sleuthkit.autopsy.discovery.search.DiscoveryEventUtils;
32import org.sleuthkit.autopsy.discovery.search.DiscoveryKeyUtils.GroupKey;
33import org.sleuthkit.autopsy.discovery.search.Group;
34import org.sleuthkit.autopsy.discovery.search.FileSearch;
35import org.sleuthkit.autopsy.discovery.search.DiscoveryException;
36import org.sleuthkit.autopsy.discovery.search.DomainSearch;
37import org.sleuthkit.autopsy.discovery.search.ResultsSorter;
38import org.sleuthkit.autopsy.discovery.search.SearchCancellationException;
39import org.sleuthkit.autopsy.discovery.search.SearchContext;
40import org.sleuthkit.autopsy.discovery.search.SearchData;
45final class SearchWorker
extends SwingWorker<Void, Void> {
47 private final static Logger logger = Logger.getLogger(SearchWorker.class.getName());
48 private static final String USER_NAME_PROPERTY =
"user.name";
49 private final List<AbstractFilter> filters;
50 private final DiscoveryAttributes.AttributeType groupingAttr;
51 private final ResultsSorter.SortingMethod fileSort;
52 private final Group.GroupSortingAlgorithm groupSortAlgorithm;
53 private final CentralRepository centralRepoDb;
54 private final SearchData.Type searchType;
55 private final Map<GroupKey, Integer> results =
new LinkedHashMap<>();
67 SearchWorker(CentralRepository centralRepo, SearchData.Type type, List<AbstractFilter> searchfilters, DiscoveryAttributes.AttributeType groupingAttribute, Group.GroupSortingAlgorithm groupSort, ResultsSorter.SortingMethod fileSortMethod) {
68 centralRepoDb = centralRepo;
70 filters = searchfilters;
71 groupingAttr = groupingAttribute;
72 groupSortAlgorithm = groupSort;
73 fileSort = fileSortMethod;
77 protected Void doInBackground() throws Exception {
80 SearchContext context =
new SwingWorkerSearchContext(
this);
81 if (searchType == SearchData.Type.DOMAIN) {
82 DomainSearch domainSearch =
new DomainSearch();
83 results.putAll(domainSearch.getGroupSizes(System.getProperty(USER_NAME_PROPERTY), filters,
87 Case.getCurrentCase().getSleuthkitCase(), centralRepoDb, context));
89 results.putAll(FileSearch.getGroupSizes(System.getProperty(USER_NAME_PROPERTY), filters,
93 Case.getCurrentCase().getSleuthkitCase(), centralRepoDb, context));
95 }
catch (DiscoveryException ex) {
96 logger.log(Level.SEVERE,
"Error running file search test.", ex);
98 }
catch (SearchCancellationException ex) {
101 logger.log(Level.INFO,
"Discovery search was cancelled.", ex);
107 protected void done() {
109 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.SearchCancelledEvent());
111 DiscoveryEventUtils.getDiscoveryEventBus().post(
new DiscoveryEventUtils.SearchCompleteEvent(results, filters, groupingAttr, groupSortAlgorithm, fileSort));