Autopsy  4.20.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.List;
23 import java.util.logging.Level;
24 import javax.swing.AbstractAction;
25 import javax.swing.Action;
26 import org.apache.commons.lang.StringUtils;
27 import org.openide.DialogDisplayer;
28 import org.openide.NotifyDescriptor;
29 import org.openide.util.NbBundle.Messages;
36 import org.sleuthkit.datamodel.AbstractFile;
38 
43 @Messages({"AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoCommentEmptyFile=Add/Edit Central Repository Comment (Empty File)",
44  "AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoCommentNoMD5=Add/Edit Central Repository Comment (No MD5 Hash)",
45  "AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoComment=Add/Edit Central Repository Comment"})
46 public final class AddEditCentralRepoCommentAction extends AbstractAction {
47 
48  private static final Logger logger = Logger.getLogger(AddEditCentralRepoCommentAction.class.getName());
49  private static final long serialVersionUID = 1L;
50 
51  private boolean addToDatabase;
53  private String comment;
54  private final Long fileId;
55 
63  public AddEditCentralRepoCommentAction(AbstractFile file) {
64  fileId = file.getId();
65  correlationAttributeInstance = CorrelationAttributeUtil.getCorrAttrForFile(file);
66  if (correlationAttributeInstance == null) {
67  addToDatabase = true;
68  final List<CorrelationAttributeInstance> md5CorrelationAttr = CorrelationAttributeUtil.makeCorrAttrsForSearch(file);
69  if (!md5CorrelationAttr.isEmpty()) {
70  //for an abstract file the 'list' of attributes will be a single attribute or empty and is returning a list for consistency with other makeCorrAttrsForSearch methods per 7852
71  correlationAttributeInstance = md5CorrelationAttr.get(0);
72  } else {
73  correlationAttributeInstance = null;
74  }
75  }
76  if (file.getSize() == 0) {
77  putValue(Action.NAME, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoCommentEmptyFile());
78  } else if (StringUtils.isBlank(file.getMd5Hash())) {
79  putValue(Action.NAME, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoCommentNoMD5());
80  } else {
81  putValue(Action.NAME, Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoComment());
82  }
83  }
84 
96  @Override
97  public void actionPerformed(ActionEvent event) {
98  CentralRepoCommentDialog centralRepoCommentDialog = new CentralRepoCommentDialog(correlationAttributeInstance);
99  centralRepoCommentDialog.display();
100 
101  comment = null;
102 
103  if (centralRepoCommentDialog.isCommentUpdated()) {
104  CentralRepository dbManager;
105 
106  try {
107  dbManager = CentralRepository.getInstance();
108 
109  if (addToDatabase) {
110  dbManager.addArtifactInstance(correlationAttributeInstance);
111  } else {
112  dbManager.updateAttributeInstanceComment(correlationAttributeInstance);
113  }
114 
115  comment = centralRepoCommentDialog.getComment();
116  try {
118  } catch (NoCurrentCaseException ex) {
119  logger.log(Level.WARNING, "Case not open after changing central repository comment", ex);
120  }
121  } catch (CentralRepoException ex) {
122  logger.log(Level.SEVERE, "Error adding comment", ex);
123  NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Message(
124  "An error occurred while trying to save the comment to the central repository.",
125  NotifyDescriptor.ERROR_MESSAGE);
126  DialogDisplayer.getDefault().notify(notifyDescriptor);
127  }
128  }
129  }
130 
138  public String getComment() {
139  return comment;
140  }
141 
148  return correlationAttributeInstance;
149  }
150 }
void notifyCentralRepoCommentChanged(long contentId, String newComment)
Definition: Case.java:1865
void updateAttributeInstanceComment(CorrelationAttributeInstance eamArtifact)
void addArtifactInstance(CorrelationAttributeInstance eamArtifact)
static List< CorrelationAttributeInstance > makeCorrAttrsForSearch(AnalysisResult analysisResult)
static CorrelationAttributeInstance getCorrAttrForFile(AbstractFile file)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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