Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
PageWorker.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  */
19 package org.sleuthkit.autopsy.discovery.ui;
20 
22 import java.util.List;
23 import java.util.ArrayList;
24 import java.util.logging.Level;
25 import javax.swing.SwingWorker;
41 
45 final class PageWorker extends SwingWorker<Void, Void> {
46 
47  private final static Logger logger = Logger.getLogger(PageWorker.class.getName());
48  private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS
49  private final List<AbstractFilter> searchfilters;
50  private final DiscoveryAttributes.AttributeType groupingAttribute;
51  private final Group.GroupSortingAlgorithm groupSort;
52  private final ResultsSorter.SortingMethod fileSortMethod;
53  private final GroupKey groupKey;
54  private final int startingEntry;
55  private final int pageSize;
56  private final SearchData.Type resultType;
57  private final CentralRepository centralRepo;
58  private final List<Result> results = new ArrayList<>();
59 
76  PageWorker(List<AbstractFilter> searchfilters, DiscoveryAttributes.AttributeType groupingAttribute,
77  Group.GroupSortingAlgorithm groupSort, ResultsSorter.SortingMethod fileSortMethod, GroupKey groupKey,
78  int startingEntry, int pageSize, SearchData.Type resultType, CentralRepository centralRepo) {
79  this.searchfilters = searchfilters;
80  this.groupingAttribute = groupingAttribute;
81  this.groupSort = groupSort;
82  this.fileSortMethod = fileSortMethod;
83  this.groupKey = groupKey;
84  this.startingEntry = startingEntry;
85  this.pageSize = pageSize;
86  this.resultType = resultType;
87  this.centralRepo = centralRepo;
88  }
89 
90  @Override
91  protected Void doInBackground() throws Exception {
92  SearchContext context = new SwingWorkerSearchContext(this);
93  try {
94  // Run the search
95  if (resultType == SearchData.Type.DOMAIN) {
96  DomainSearch domainSearch = new DomainSearch();
97  results.addAll(domainSearch.getDomainsInGroup(System.getProperty(USER_NAME_PROPERTY), searchfilters,
98  groupingAttribute,
99  groupSort,
100  fileSortMethod, groupKey, startingEntry, pageSize,
101  Case.getCurrentCase().getSleuthkitCase(), centralRepo, context));
102  } else {
103  results.addAll(FileSearch.getFilesInGroup(System.getProperty(USER_NAME_PROPERTY), searchfilters,
104  groupingAttribute,
105  groupSort,
106  fileSortMethod, groupKey, startingEntry, pageSize,
107  Case.getCurrentCase().getSleuthkitCase(), centralRepo, context));
108  }
109  } catch (DiscoveryException ex) {
110  logger.log(Level.SEVERE, "Error running file search test", ex);
111  cancel(true);
112  } catch (SearchCancellationException ex) {
113  //The user does not explicitly have a way to cancel the loading of a page
114  //but they could have cancelled the search during the loading of the first page
115  //So this may or may not be an issue depending on when this occurred.
116  logger.log(Level.WARNING, "Search was cancelled while retrieving data for results page with starting entry: " + startingEntry, ex);
117  }
118  return null;
119  }
120 
121  @Override
122  protected void done() {
123  if (!isCancelled()) {
124  int currentPage = startingEntry / pageSize; //integer division should round down to get page number correctly
125  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.PageRetrievedEvent(resultType, currentPage, results));
126  }
127  }
128 
129 }

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