Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddEditCentralRepoCommentAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018-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.centralrepository;
20 
21 import java.awt.event.ActionEvent;
22 import java.util.logging.Level;
23 import javax.swing.AbstractAction;
24 import javax.swing.Action;
25 import org.apache.commons.lang.StringUtils;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.NbBundle.Messages;
35 import org.sleuthkit.datamodel.AbstractFile;
37 
42 @Messages({"AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoCommentEmptyFile=Add/Edit Central Repository Comment (Empty File)",
43  "AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoCommentNoMD5=Add/Edit Central Repository Comment (No MD5 Hash)",
44  "AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoComment=Add/Edit Central Repository Comment"})
45 public final class AddEditCentralRepoCommentAction extends AbstractAction {
46 
47  private static final Logger logger = Logger.getLogger(AddEditCentralRepoCommentAction.class.getName());
48  private static final long serialVersionUID = 1L;
49 
50  private boolean addToDatabase;
52  private String comment;
53  private final Long fileId;
54 
62  public AddEditCentralRepoCommentAction(AbstractFile file) {
63  fileId = file.getId();
64  correlationAttributeInstance = CorrelationAttributeUtil.getCorrAttrForFile(file);
65  if (correlationAttributeInstance == null) {
66  addToDatabase = true;
67  correlationAttributeInstance = CorrelationAttributeUtil.makeCorrAttrFromFile(file);
68  }
69  if (file.getSize() == 0) {
70  putValue(Action.NAME, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoCommentEmptyFile());
71  } else if (StringUtils.isBlank(file.getMd5Hash())) {
72  putValue(Action.NAME, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoCommentNoMD5());
73  } else {
74  putValue(Action.NAME, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoComment());
75  }
76  }
77 
89  @Override
90  public void actionPerformed(ActionEvent event) {
91  CentralRepoCommentDialog centralRepoCommentDialog = new CentralRepoCommentDialog(correlationAttributeInstance);
92  centralRepoCommentDialog.display();
93 
94  comment = null;
95 
96  if (centralRepoCommentDialog.isCommentUpdated()) {
97  CentralRepository dbManager;
98 
99  try {
100  dbManager = CentralRepository.getInstance();
101 
102  if (addToDatabase) {
103  dbManager.addArtifactInstance(correlationAttributeInstance);
104  } else {
105  dbManager.updateAttributeInstanceComment(correlationAttributeInstance);
106  }
107 
108  comment = centralRepoCommentDialog.getComment();
109  try {
111  } catch (NoCurrentCaseException ex) {
112  logger.log(Level.WARNING, "Case not open after changing central repository comment", ex);
113  }
114  } catch (CentralRepoException ex) {
115  logger.log(Level.SEVERE, "Error adding comment", ex);
116  NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Message(
117  "An error occurred while trying to save the comment to the central repository.",
118  NotifyDescriptor.ERROR_MESSAGE);
119  DialogDisplayer.getDefault().notify(notifyDescriptor);
120  }
121  }
122  }
123 
131  public String getComment() {
132  return comment;
133  }
134 
141  return correlationAttributeInstance;
142  }
143 }
static CorrelationAttributeInstance makeCorrAttrFromFile(AbstractFile file)
void notifyCentralRepoCommentChanged(long contentId, String newComment)
Definition: Case.java:1592
void updateAttributeInstanceComment(CorrelationAttributeInstance eamArtifact)
void addArtifactInstance(CorrelationAttributeInstance eamArtifact)
static CorrelationAttributeInstance getCorrAttrForFile(AbstractFile file)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.