Added reason for files not candidates to be added to hashsets

This commit is contained in:
U-BASIS\dsmyda 2018-09-27 14:48:40 -04:00
parent 0f9b42b9c2
commit 59ccaa50eb
2 changed files with 66 additions and 21 deletions

View File

@ -27,6 +27,7 @@ import javax.swing.AbstractAction;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.util.actions.Presenter;
@ -44,15 +45,28 @@ import org.sleuthkit.datamodel.TskCoreException;
final class AddContentToHashDbAction extends AbstractAction implements Presenter.Popup {
private static AddContentToHashDbAction instance;
private final static String SINGLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.singleSelectionName");
private final static String MULTIPLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
private final static String MULTI_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.multipleSelectionName");
//During ingest display strings. This text will be greyed out and unclickable
private final static String SINGLE_SELECTION_NAME_DURING_INGEST = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.singleSelectionNameDuringIngest");
private final static String MULTIPLE_SELECTION_NAME_DURING_INGEST = NbBundle.getMessage(AddContentToHashDbAction.class,
private final static String MULTI_SELECTION_NAME_DURING_INGEST = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.multipleSelectionNameDuringIngest");
//No MD5 Hash and Empty File display strings. This text will be greyed out and unclickable
private final static String SINGLE_SELECTION_NAME_EMPTY_FILE = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.singleSelectionNameEmpty");
private final static String MULTI_SELECTION_NAME_EMPTY_FILE = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.multipleSelectionNameEmpty");
private final static String SINGLE_SELECTION_NAME_NO_MD5 = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.singleSelectionNameNoMD5");
private final static String MULTI_SELECTION_NAME_NO_MD5 = NbBundle.getMessage(AddContentToHashDbAction.class,
"AddContentToHashDbAction.multipleSelectionNameNoMD5");
/**
* AddContentToHashDbAction is a singleton to support multi-selection of
* nodes, since org.openide.nodes.NodeOp.findActions(Node[] nodes) will only
@ -86,30 +100,40 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter
super(SINGLE_SELECTION_NAME);
// Get any AbstractFile objects from the lookup of the currently focused top component.
final Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
int numberOfFilesSelected = selectedFiles.size();
// Disable the menu if file ingest is in progress.
if (IngestManager.getInstance().isIngestRunning()) {
if(selectedFiles.size() > 1) {
//Displays: 'Add Files to Hash Set (Ingest is running)'
setText(MULTIPLE_SELECTION_NAME_DURING_INGEST);
} else {
setText(SINGLE_SELECTION_NAME_DURING_INGEST);
}
setEnabled(false);
setTextBasedOnNumberOfSelections(numberOfFilesSelected,
SINGLE_SELECTION_NAME_DURING_INGEST,
MULTI_SELECTION_NAME_DURING_INGEST);
return;
}
if (selectedFiles.isEmpty()) {
setEnabled(false);
return;
} else if (selectedFiles.size() > 1) {
setText(MULTIPLE_SELECTION_NAME);
} else {
setTextBasedOnNumberOfSelections(numberOfFilesSelected,
SINGLE_SELECTION_NAME,
MULTI_SELECTION_NAME);
}
// Disable the menu if hashes have not been calculated.
// Disable the menu if md5 have not been computed or if the file size
// is empty. Display the appropriate reason to the user.
for (AbstractFile file : selectedFiles) {
if (null == file.getMd5Hash()) {
if (file.getSize() == 0) {
setEnabled(false);
setTextBasedOnNumberOfSelections(numberOfFilesSelected,
SINGLE_SELECTION_NAME_EMPTY_FILE,
MULTI_SELECTION_NAME_EMPTY_FILE);
return;
} else if (null == file.getMd5Hash() || StringUtils.isBlank(file.getMd5Hash())) {
setEnabled(false);
setTextBasedOnNumberOfSelections(numberOfFilesSelected,
SINGLE_SELECTION_NAME_NO_MD5,
MULTI_SELECTION_NAME_NO_MD5);
return;
}
}
@ -154,6 +178,23 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter
add(newHashSetItem);
}
/**
* Determines which (2) display text should be set given the number of
* files selected.
*
* @param numberOfFilesSelected Number of currently selected files
* @param multiSelection Text to display with multiple selections
* @param singleSelection Text to display with single selection
*/
private void setTextBasedOnNumberOfSelections(int numberOfFilesSelected,
String singleSelection, String multiSelection) {
if (numberOfFilesSelected > 1) {
setText(multiSelection);
} else {
setText(singleSelection);
}
}
private void addFilesToHashSet(final Collection<? extends AbstractFile> files, HashDb hashSet) {
for (AbstractFile file : files) {
String md5Hash = file.getMd5Hash();
@ -187,8 +228,8 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter
NbBundle.getMessage(this.getClass(),
"AddContentToHashDbAction.addFilesToHashSet.unableToAddFileSzMsg",
files.size() > 1 ? NbBundle
.getMessage(this.getClass(),
"AddContentToHashDbAction.addFilesToHashSet.files") : NbBundle
.getMessage(this.getClass(),
"AddContentToHashDbAction.addFilesToHashSet.files") : NbBundle
.getMessage(this.getClass(),
"AddContentToHashDbAction.addFilesToHashSet.file")),
NbBundle.getMessage(this.getClass(),

View File

@ -155,6 +155,10 @@ AddContentToHashDbAction.singleSelectionName=Add File to Hash Set
AddContentToHashDbAction.multipleSelectionName=Add Files to Hash Set
AddContentToHashDbAction.singleSelectionNameDuringIngest=Add File to Hash Set (Ingest is running)
AddContentToHashDbAction.multipleSelectionNameDuringIngest=Add Files to Hash Set (Ingest is running)
AddContentToHashDbAction.singleSelectionNameNoMD5=Add File to Hash Set (No MD5 Hash)
AddContentToHashDbAction.multipleSelectionNameNoMD5=Add Files to Hash Set (No MD5 Hash)
AddContentToHashDbAction.singleSelectionNameEmpty=Add File to Hash Set (Empty File)
AddContentToHashDbAction.multipleSelectionNameEmpty=Add Files to Hash Set (Empty File)
HashDbManager.ingestRunningExceptionMsg=Ingest is ongoing; this service will be unavailable until it finishes.
HashDbManager.saveErrorExceptionMsg=Error saving hash configuration
HashLookupSettingsPanel.jButton3.text=Import Hash Set