Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactsWorker.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 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 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.concurrent.CancellationException;
24 import java.util.concurrent.ExecutionException;
25 import java.util.logging.Level;
26 import javax.swing.SwingWorker;
27 import org.apache.commons.lang3.StringUtils;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 
39 class ArtifactsWorker extends SwingWorker<List<BlackboardArtifact>, Void> {
40 
41  private final BlackboardArtifact.ARTIFACT_TYPE artifactType;
42  private final static Logger logger = Logger.getLogger(ArtifactsWorker.class.getName());
43  private final String domain;
44  private final boolean grabFocus;
45 
55  ArtifactsWorker(BlackboardArtifact.ARTIFACT_TYPE artifactType, String domain, boolean shouldGrabFocus) {
56  this.artifactType = artifactType;
57  this.domain = domain;
58  this.grabFocus = shouldGrabFocus;
59  }
60 
61  @Override
62  protected List<BlackboardArtifact> doInBackground() throws Exception {
63  if (artifactType != null && !StringUtils.isBlank(domain)) {
64  DomainSearch domainSearch = new DomainSearch();
65  try {
66  return domainSearch.getArtifacts(new DomainSearchArtifactsRequest(Case.getCurrentCase().getSleuthkitCase(), domain, artifactType));
67  } catch (DiscoveryException ex) {
68  if (ex.getCause() instanceof InterruptedException) {
69  this.cancel(true);
70  //ignore the exception as it was cancelled while the cache was performing its get and we support cancellation
71  } else {
72  throw ex;
73  }
74  }
75  }
76  return new ArrayList<>();
77  }
78 
79  @Override
80  protected void done() {
81  List<BlackboardArtifact> listOfArtifacts = new ArrayList<>();
82  if (!isCancelled()) {
83  try {
84  listOfArtifacts.addAll(get());
85  DiscoveryEventUtils.getDiscoveryEventBus().post(new DiscoveryEventUtils.ArtifactSearchResultEvent(artifactType, listOfArtifacts, grabFocus));
86  } catch (InterruptedException | ExecutionException ex) {
87  logger.log(Level.SEVERE, "Exception while trying to get list of artifacts for Domain details for artifact type: "
88  + artifactType.getDisplayName() + " and domain: " + domain, ex);
89  } catch (CancellationException ignored) {
90  //Worker was cancelled after previously finishing its background work, exception ignored to cut down on non-helpful logging
91  }
92  }
93 
94  }
95 }

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