Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReplaceBlackboardArtifactTagAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.actions;
20 
21 import java.util.Collection;
22 import java.util.concurrent.ExecutionException;
23 import java.util.logging.Level;
24 import javafx.application.Platform;
25 import javafx.scene.control.Alert;
26 import javax.swing.SwingWorker;
27 import org.openide.util.NbBundle;
28 import org.openide.util.Utilities;
33 import org.sleuthkit.datamodel.BlackboardArtifactTag;
34 import org.sleuthkit.datamodel.TagName;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
41 public final class ReplaceBlackboardArtifactTagAction extends ReplaceTagAction<BlackboardArtifactTag> {
42 
43  private static final Logger logger = Logger.getLogger(ReplaceBlackboardArtifactTagAction.class.getName());
44  private static final long serialVersionUID = 1L;
45 
46  // This class is a singleton to support multi-selection of nodes, since
47  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
48  // node in the array returns a reference to the same action object from Node.getActions(boolean).
50 
51  public static synchronized ReplaceBlackboardArtifactTagAction getInstance() {
52  if (null == instance) {
53  instance = new ReplaceBlackboardArtifactTagAction();
54  }
55  return instance;
56  }
57 
59  super(MENU_TEXT);
60  }
61 
69  @NbBundle.Messages({
70  "# {0} - old tag name",
71  "# {1} - artifactID",
72  "ReplaceBlackboardArtifactTagAction.replaceTag.alert=Unable to replace tag {0} for artifact {1}."})
73  @Override
74  protected void replaceTag( BlackboardArtifactTag oldArtifactTag, TagName newTagName, String newComment) {
75  new SwingWorker<Void, Void>() {
76 
77  @Override
78  protected Void doInBackground() throws Exception {
79  TagsManager tagsManager;
80  try {
82  } catch (NoCurrentCaseException ex) {
83  logger.log(Level.SEVERE, "Error replacing artifact tag. No open case found.", ex); //NON-NLS
84  Platform.runLater(()
85  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceBlackboardArtifactTagAction_replaceTag_alert(oldArtifactTag.getName().getDisplayName(), oldArtifactTag.getArtifact().getArtifactID())).show()
86  );
87  return null;
88  }
89 
90  try {
91  logger.log(Level.INFO, "Replacing tag {0} with tag {1} for artifact {2}", new Object[]{oldArtifactTag.getName().getDisplayName(), newTagName.getDisplayName(), oldArtifactTag.getContent().getName()}); //NON-NLS
92 
93  tagsManager.deleteBlackboardArtifactTag(oldArtifactTag);
94  tagsManager.addBlackboardArtifactTag(oldArtifactTag.getArtifact(), newTagName, newComment);
95 
96  } catch (TskCoreException tskCoreException) {
97  logger.log(Level.SEVERE, "Error replacing artifact tag", tskCoreException); //NON-NLS
98  Platform.runLater(()
99  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceBlackboardArtifactTagAction_replaceTag_alert(oldArtifactTag.getName().getDisplayName(), oldArtifactTag.getArtifact().getArtifactID())).show()
100  );
101  }
102  return null;
103  }
104 
105  @Override
106  protected void done() {
107  super.done();
108  try {
109  get();
110  } catch (InterruptedException | ExecutionException ex) {
111  logger.log(Level.SEVERE, "Unexpected exception while replacing artifact tag", ex); //NON-NLS
112  }
113  }
114  }.execute();
115  }
116 
122  @Override
123  Collection<? extends BlackboardArtifactTag> getTagsToReplace() {
124  return Utilities.actionsGlobalContext().lookupAll(BlackboardArtifactTag.class);
125  }
126 
127 }
BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName)
void deleteBlackboardArtifactTag(BlackboardArtifactTag tag)
static synchronized ReplaceBlackboardArtifactTagAction getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
void replaceTag(BlackboardArtifactTag oldArtifactTag, TagName newTagName, String newComment)

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.