mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +00:00
Improved exception handling and logging.
This commit is contained in:
parent
780b930c65
commit
5b3be36fcc
@ -19,6 +19,7 @@
|
||||
package org.sleuthkit.autopsy.centralrepository;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.AbstractAction;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.openide.util.NbBundle.Messages;
|
||||
@ -30,6 +31,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationDataSource;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamArtifactUtil;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.datamodel.AbstractFile;
|
||||
import org.sleuthkit.datamodel.TskCoreException;
|
||||
|
||||
@ -39,6 +41,8 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
*/
|
||||
public final class AddEditCentralRepoCommentAction extends AbstractAction {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AddEditCentralRepoCommentAction.class.getName());
|
||||
|
||||
private boolean addToDatabase;
|
||||
private CorrelationAttribute correlationAttribute;
|
||||
|
||||
@ -60,30 +64,19 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
|
||||
* is derived.
|
||||
* @param displayName The text for the menu item.
|
||||
*/
|
||||
private AddEditCentralRepoCommentAction(AbstractFile file, String displayName) {
|
||||
private AddEditCentralRepoCommentAction(AbstractFile file, String displayName) throws EamDbException, NoCurrentCaseException, TskCoreException {
|
||||
|
||||
super(displayName);
|
||||
try {
|
||||
CorrelationAttribute.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
|
||||
CorrelationCase correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows());
|
||||
CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
|
||||
String value = file.getMd5Hash();
|
||||
String filePath = (file.getParentPath() + file.getName()).toLowerCase();
|
||||
CorrelationAttribute.Type type = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID);
|
||||
CorrelationCase correlationCase = EamDb.getInstance().getCase(Case.getCurrentCaseThrows());
|
||||
CorrelationDataSource correlationDataSource = CorrelationDataSource.fromTSKDataSource(correlationCase, file.getDataSource());
|
||||
String value = file.getMd5Hash();
|
||||
String filePath = (file.getParentPath() + file.getName()).toLowerCase();
|
||||
|
||||
correlationAttribute = EamDb.getInstance().getCorrelationAttribute(type, correlationCase, correlationDataSource, value, filePath);
|
||||
if (correlationAttribute == null) {
|
||||
addToDatabase = true;
|
||||
correlationAttribute = EamArtifactUtil.makeCorrelationAttributeFromContent(file);
|
||||
}
|
||||
} catch (TskCoreException ex) {
|
||||
//DLG:
|
||||
Exceptions.printStackTrace(ex);
|
||||
} catch (EamDbException ex) {
|
||||
//DLG:
|
||||
Exceptions.printStackTrace(ex);
|
||||
} catch (NoCurrentCaseException ex) {
|
||||
//DLG:
|
||||
Exceptions.printStackTrace(ex);
|
||||
correlationAttribute = EamDb.getInstance().getCorrelationAttribute(type, correlationCase, correlationDataSource, value, filePath);
|
||||
if (correlationAttribute == null) {
|
||||
addToDatabase = true;
|
||||
correlationAttribute = EamArtifactUtil.makeCorrelationAttributeFromContent(file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +107,7 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
|
||||
dbManager.updateAttributeInstanceComment(correlationAttribute);
|
||||
}
|
||||
} catch (EamDbException ex) {
|
||||
Exceptions.printStackTrace(ex); //DLG:
|
||||
logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -127,9 +120,15 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
|
||||
* derived.
|
||||
*
|
||||
* @return The instance.
|
||||
*
|
||||
* @throws EamDbException
|
||||
* @throws NoCurrentCaseException
|
||||
* @throws TskCoreException
|
||||
*/
|
||||
@Messages({"AddEditCentralRepoCommentAction.menuItemText.addEditCentralRepoComment=Add/Edit Central Repository Comment"})
|
||||
public static AddEditCentralRepoCommentAction createAddEditCentralRepoCommentAction(AbstractFile file) {
|
||||
public static AddEditCentralRepoCommentAction createAddEditCentralRepoCommentAction(AbstractFile file)
|
||||
throws EamDbException, NoCurrentCaseException, TskCoreException {
|
||||
|
||||
return new AddEditCentralRepoCommentAction(file,
|
||||
Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditCentralRepoComment());
|
||||
}
|
||||
@ -144,6 +143,7 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
|
||||
*/
|
||||
@Messages({"AddEditCentralRepoCommentAction.menuItemText.addEditComment=Add/Edit Comment"})
|
||||
public static AddEditCentralRepoCommentAction createAddEditCommentAction(CorrelationAttribute correlationAttribute) {
|
||||
|
||||
return new AddEditCentralRepoCommentAction(correlationAttribute,
|
||||
Bundle.AddEditCentralRepoCommentAction_menuItemText_addEditComment());
|
||||
}
|
||||
|
@ -85,7 +85,10 @@ public class CorrelationDataSource implements Serializable {
|
||||
throw new EamDbException("Error getting data source info: " + ex.getMessage());
|
||||
}
|
||||
|
||||
CorrelationDataSource correlationDataSource = EamDb.getInstance().getDataSource(correlationCase, deviceId);
|
||||
CorrelationDataSource correlationDataSource = null;
|
||||
if (EamDbUtil.useCentralRepo()) {
|
||||
correlationDataSource = EamDb.getInstance().getDataSource(correlationCase, deviceId);
|
||||
}
|
||||
if (correlationDataSource == null) {
|
||||
correlationDataSource = new CorrelationDataSource(correlationCase.getID(), deviceId, dataSource.getName());
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
import javax.swing.Action;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openide.nodes.Sheet;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.openide.util.Lookup;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.openide.util.WeakListeners;
|
||||
@ -49,6 +50,7 @@ import org.sleuthkit.autopsy.casemodule.events.BlackBoardArtifactTagDeletedEvent
|
||||
import org.sleuthkit.autopsy.casemodule.events.ContentTagAddedEvent;
|
||||
import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent;
|
||||
import org.sleuthkit.autopsy.centralrepository.AddEditCentralRepoCommentAction;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
||||
@ -70,7 +72,7 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
*/
|
||||
public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifact> {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(BlackboardArtifactNode.class.getName());
|
||||
private static final Logger logger = Logger.getLogger(BlackboardArtifactNode.class.getName());
|
||||
private static final Set<Case.Events> CASE_EVENTS_OF_INTEREST = EnumSet.of(Case.Events.BLACKBOARD_ARTIFACT_TAG_ADDED,
|
||||
Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED,
|
||||
Case.Events.CONTENT_TAG_ADDED,
|
||||
@ -223,7 +225,15 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
|
||||
// Create the "Add/Edit Central Repository Comment" menu item if the enabled.
|
||||
if (file != null && file.isFile() && EamDbUtil.useCentralRepo()) {
|
||||
actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
|
||||
try {
|
||||
actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
|
||||
} catch (EamDbException ex) {
|
||||
logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex); // NON-NLS
|
||||
} catch (NoCurrentCaseException ex) {
|
||||
logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS
|
||||
} catch (TskCoreException ex) {
|
||||
logger.log(Level.SEVERE, String.format("Could not retrieve data source from file '%s' (objId=%d).", file.getName(), file.getId()), ex); // NON-NLS
|
||||
}
|
||||
}
|
||||
|
||||
//if this artifact has a time stamp add the action to view it in the timeline
|
||||
@ -232,7 +242,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
actionsList.add(new ViewArtifactInTimelineAction(artifact));
|
||||
}
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting arttribute(s) from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
|
||||
logger.log(Level.SEVERE, MessageFormat.format("Error getting arttribute(s) from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
|
||||
MessageNotifyUtil.Notify.error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_resultErrorMessage());
|
||||
}
|
||||
|
||||
@ -243,7 +253,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
actionsList.add(ViewFileInTimelineAction.createViewFileAction(c));
|
||||
}
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
|
||||
logger.log(Level.SEVERE, MessageFormat.format("Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
|
||||
MessageNotifyUtil.Notify.error(Bundle.BlackboardArtifactNode_getAction_errorTitle(), Bundle.BlackboardArtifactNode_getAction_linkedFileMessage());
|
||||
}
|
||||
|
||||
@ -398,7 +408,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
try {
|
||||
sourcePath = associated.getUniquePath();
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.WARNING, "Failed to get unique path from: {0}", associated.getName()); //NON-NLS
|
||||
logger.log(Level.WARNING, "Failed to get unique path from: {0}", associated.getName()); //NON-NLS
|
||||
}
|
||||
|
||||
if (sourcePath.isEmpty() == false) {
|
||||
@ -446,7 +456,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
dataSourceStr = getRootParentName();
|
||||
}
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.WARNING, "Failed to get image name from {0}", associated.getName()); //NON-NLS
|
||||
logger.log(Level.WARNING, "Failed to get image name from {0}", associated.getName()); //NON-NLS
|
||||
}
|
||||
|
||||
if (dataSourceStr.isEmpty() == false) {
|
||||
@ -479,7 +489,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
tags.addAll(Case.getCurrentCaseThrows().getServices().getTagsManager().getBlackboardArtifactTagsByArtifact(artifact));
|
||||
tags.addAll(Case.getCurrentCaseThrows().getServices().getTagsManager().getContentTagsByContent(associated));
|
||||
} catch (TskCoreException | NoCurrentCaseException ex) {
|
||||
LOGGER.log(Level.SEVERE, "Failed to get tags for artifact " + artifact.getDisplayName(), ex);
|
||||
logger.log(Level.SEVERE, "Failed to get tags for artifact " + artifact.getDisplayName(), ex);
|
||||
}
|
||||
sheetSet.put(new NodeProperty<>("Tags", Bundle.BlackboardArtifactNode_createSheet_tags_displayName(),
|
||||
NO_DESCR, tags.stream().map(t -> t.getName().getDisplayName()).collect(Collectors.joining(", "))));
|
||||
@ -497,7 +507,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
parentName = parent.getName();
|
||||
}
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.WARNING, "Failed to get parent name from {0}", associated.getName()); //NON-NLS
|
||||
logger.log(Level.WARNING, "Failed to get parent name from {0}", associated.getName()); //NON-NLS
|
||||
return "";
|
||||
}
|
||||
return parentName;
|
||||
@ -558,7 +568,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
}
|
||||
}
|
||||
} catch (TskCoreException ex) {
|
||||
LOGGER.log(Level.SEVERE, "Getting attributes failed", ex); //NON-NLS
|
||||
logger.log(Level.SEVERE, "Getting attributes failed", ex); //NON-NLS
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,7 +631,7 @@ public class BlackboardArtifactNode extends AbstractContentNode<BlackboardArtifa
|
||||
return Lookups.fixed(artifact, content);
|
||||
}
|
||||
} catch (ExecutionException ex) {
|
||||
LOGGER.log(Level.WARNING, "Getting associated content for artifact failed", ex); //NON-NLS
|
||||
logger.log(Level.WARNING, "Getting associated content for artifact failed", ex); //NON-NLS
|
||||
return Lookups.fixed(artifact);
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,14 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.Action;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.openide.util.Utilities;
|
||||
import org.sleuthkit.autopsy.actions.AddContentTagAction;
|
||||
import org.sleuthkit.autopsy.actions.DeleteFileContentTagAction;
|
||||
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
|
||||
import org.sleuthkit.autopsy.centralrepository.AddEditCentralRepoCommentAction;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
|
||||
import org.sleuthkit.autopsy.coreutils.ContextMenuExtensionPoint;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
@ -160,7 +163,15 @@ public class FileNode extends AbstractFsContentNode<AbstractFile> {
|
||||
// Create the "Add/Edit Central Repository Comment" menu item if the enabled.
|
||||
AbstractFile file = content;
|
||||
if (file != null && file.isFile() && EamDbUtil.useCentralRepo()) {
|
||||
actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
|
||||
try {
|
||||
actionsList.add(AddEditCentralRepoCommentAction.createAddEditCentralRepoCommentAction(file));
|
||||
} catch (EamDbException ex) {
|
||||
logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex); // NON-NLS
|
||||
} catch (NoCurrentCaseException ex) {
|
||||
logger.log(Level.SEVERE, "Exception while getting open case.", ex); // NON-NLS
|
||||
} catch (TskCoreException ex) {
|
||||
logger.log(Level.SEVERE, String.format("Could not retrieve data source from file '%s' (objId=%d).", file.getName(), file.getId()), ex); // NON-NLS
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.getDirectoryBrowseMode()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user