Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
SearchWorker.java
Go to the documentation of this file.
1/*
2 * Autopsy
3 *
4 * Copyright 2019-2021 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.discovery.ui;
20
21import org.sleuthkit.autopsy.discovery.search.AbstractFilter;
22import java.util.LinkedHashMap;
23import javax.swing.SwingWorker;
24import java.util.List;
25import java.util.Map;
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;
41
45final class SearchWorker extends SwingWorker<Void, Void> {
46
47 private final static Logger logger = Logger.getLogger(SearchWorker.class.getName());
48 private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS
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<>();
56
67 SearchWorker(CentralRepository centralRepo, SearchData.Type type, List<AbstractFilter> searchfilters, DiscoveryAttributes.AttributeType groupingAttribute, Group.GroupSortingAlgorithm groupSort, ResultsSorter.SortingMethod fileSortMethod) {
68 centralRepoDb = centralRepo;
69 searchType = type;
70 filters = searchfilters;
71 groupingAttr = groupingAttribute;
72 groupSortAlgorithm = groupSort;
73 fileSort = fileSortMethod;
74 }
75
76 @Override
77 protected Void doInBackground() throws Exception {
78 try {
79 // Run the search
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,
84 groupingAttr,
85 groupSortAlgorithm,
86 fileSort,
87 Case.getCurrentCase().getSleuthkitCase(), centralRepoDb, context));
88 } else {
89 results.putAll(FileSearch.getGroupSizes(System.getProperty(USER_NAME_PROPERTY), filters,
90 groupingAttr,
91 groupSortAlgorithm,
92 fileSort,
93 Case.getCurrentCase().getSleuthkitCase(), centralRepoDb, context));
94 }
95 } catch (DiscoveryException ex) {
96 logger.log(Level.SEVERE, "Error running file search test.", ex);
97 cancel(true);
98 } catch (SearchCancellationException ex) {
99 //search cancellation exceptions should indicate that the user chose to cancell this search
100 //so would not be a problem but we might be curious what was being done when it was cancelled
101 logger.log(Level.INFO, "Discovery search was cancelled.", ex);
102 }
103 return null;
104 }
105
106 @Override
107 protected void done() {
108 if (isCancelled()) {
109 DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.SearchCancelledEvent());
110 } else {
111 DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.SearchCompleteEvent(results, filters, groupingAttr, groupSortAlgorithm, fileSort));
112 }
113 }
114}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.