Autopsy  4.7.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 
68  @NbBundle.Messages({
69  "# {0} - old tag name",
70  "# {1} - artifactID",
71  "ReplaceBlackboardArtifactTagAction.replaceTag.alert=Unable to replace tag {0} for artifact {1}."})
72  @Override
73  protected void replaceTag( BlackboardArtifactTag oldArtifactTag, TagName newTagName) {
74  new SwingWorker<Void, Void>() {
75 
76  @Override
77  protected Void doInBackground() throws Exception {
78  TagsManager tagsManager;
79  try {
81  } catch (NoCurrentCaseException ex) {
82  logger.log(Level.SEVERE, "Error replacing artifact tag. No open case found.", ex); //NON-NLS
83  Platform.runLater(()
84  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceBlackboardArtifactTagAction_replaceTag_alert(oldArtifactTag.getName().getDisplayName(), oldArtifactTag.getArtifact().getArtifactID())).show()
85  );
86  return null;
87  }
88 
89  try {
90  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
91 
92  tagsManager.deleteBlackboardArtifactTag(oldArtifactTag);
93  tagsManager.addBlackboardArtifactTag(oldArtifactTag.getArtifact(), newTagName);
94 
95  } catch (TskCoreException tskCoreException) {
96  logger.log(Level.SEVERE, "Error replacing artifact tag", tskCoreException); //NON-NLS
97  Platform.runLater(()
98  -> new Alert(Alert.AlertType.ERROR, Bundle.ReplaceBlackboardArtifactTagAction_replaceTag_alert(oldArtifactTag.getName().getDisplayName(), oldArtifactTag.getArtifact().getArtifactID())).show()
99  );
100  }
101  return null;
102  }
103 
104  @Override
105  protected void done() {
106  super.done();
107  try {
108  get();
109  } catch (InterruptedException | ExecutionException ex) {
110  logger.log(Level.SEVERE, "Unexpected exception while replacing artifact tag", ex); //NON-NLS
111  }
112  }
113  }.execute();
114  }
115 
121  @Override
122  Collection<? extends BlackboardArtifactTag> getTagsToReplace() {
123  return Utilities.actionsGlobalContext().lookupAll(BlackboardArtifactTag.class);
124  }
125 
126 }
BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName)
void deleteBlackboardArtifactTag(BlackboardArtifactTag tag)
void replaceTag(BlackboardArtifactTag oldArtifactTag, TagName newTagName)
static synchronized ReplaceBlackboardArtifactTagAction getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.