Fix bundle strings, cleanup.

This commit is contained in:
Andrew Ziehl 2018-07-16 14:17:38 -07:00
parent 2b33110dcb
commit 071f783bb4
9 changed files with 53 additions and 64 deletions

View File

@ -27,20 +27,44 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.TskCoreException;
/**
*
* @author bsweeney
*/
abstract class ICommonFilesMetadataBuilder {
abstract class AbstractCommonFilesMetadataBuilder {
boolean filterByMedia;
boolean filterByDoc;
abstract CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, Exception;
@NbBundle.Messages({
"AbstractCommonFilesMetadataBuilder.buildTabTitle.titleIntraAll=Common Files (All Data Sources, %s)",
"AbstractCommonFilesMetadataBuilder.buildTabTitle.titleIntraSingle=Common Files (Data Source: %s, %s)",
"AbstractCommonFilesMetadataBuilder.buildTabTitle.titleInterAll=Common Files (All Central Repository Cases, %s)",
"AbstractCommonFilesMetadataBuilder.buildTabTitle.titleInterSingle=Common Files (Central Repository Case: %s, %s)",
})
abstract String buildTabTitle();
abstract String buildCategorySelectionString();
@NbBundle.Messages({
"AbstractCommonFilesMetadataBuilder.buildCategorySelectionString.doc=Documents",
"AbstractCommonFilesMetadataBuilder.buildCategorySelectionString.media=Media",
"AbstractCommonFilesMetadataBuilder.buildCategorySelectionString.all=All File Categories"
})
protected String buildCategorySelectionString() {
if (!this.filterByDoc && !this.filterByMedia) {
return Bundle.AbstractCommonFilesMetadataBuilder_buildCategorySelectionString_all();
} else {
List<String> filters = new ArrayList<>();
if (this.filterByDoc) {
filters.add(Bundle.AbstractCommonFilesMetadataBuilder_buildCategorySelectionString_doc());
}
if (this.filterByMedia) {
filters.add(Bundle.AbstractCommonFilesMetadataBuilder_buildCategorySelectionString_media());
}
return String.join(", ", filters);
}
}
static Map<Integer, List<Md5Metadata>> collateMatchesByNumberOfInstances(Map<String, Md5Metadata> commonFiles) {
//collate matches by number of matching instances - doing this in sql doesnt seem efficient

View File

@ -50,8 +50,10 @@ public class AllCasesEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMetad
}
@Override
String buildCategorySelectionString() {
//TODO
return "";
String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString();
final String titleTemplate = Bundle.AbstractCommonFilesMetadataBuilder_buildTabTitle_titleInterAll();
return String.format(titleTemplate, new Object[]{buildCategorySelectionString});
}
}

View File

@ -51,7 +51,7 @@ final public class AllDataSourcesCommonFilesAlgorithm extends IntraCaseCommonFil
@Override
protected String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString();
final String titleTemplate = Bundle.CommonFilesMetadataBuilder_buildTabTitle_titleAll();
final String titleTemplate = Bundle.AbstractCommonFilesMetadataBuilder_buildTabTitle_titleIntraAll();
return String.format(titleTemplate, new Object[]{buildCategorySelectionString});
}
}

View File

@ -30,7 +30,6 @@ import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import org.netbeans.api.progress.ProgressHandle;
import org.openide.explorer.ExplorerManager;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
@ -58,9 +57,6 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
private static final Long NO_DATA_SOURCE_SELECTED = -1L;
private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class.getName());
private boolean singleDataSource = false;
private String selectedDataSource = "";
private boolean pictureViewCheckboxState;
private boolean documentsCheckboxState;
@ -74,9 +70,6 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
initComponents();
this.errorText.setVisible(false);
this.intraCasePanel.setParent(this);
this.setupDataSources();
if (CommonFilesPanel.isEamDbAvailable()) {
@ -141,7 +134,7 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
Long dataSourceId = intraCasePanel.getSelectedDataSourceId();
Integer caseId = interCasePanel.getSelectedCaseId();
IntraCaseCommonFilesMetadataBuilder builder;
AbstractCommonFilesMetadataBuilder builder;
CommonFilesMetadata metadata;
boolean filterByMedia = false;
@ -173,8 +166,6 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
setTitleForSingleSource(dataSourceId);
}
}
//TODO set title from one method rather than two (or more) overloads
metadata = builder.findFiles();
this.tabTitle = builder.buildTabTitle();

View File

@ -34,7 +34,7 @@ import org.sleuthkit.datamodel.HashUtility;
* Provides logic for selecting common files from all data sources and all cases
* in the Central Repo.
*/
public abstract class InterCaseCommonFilesMetadataBuilder extends ICommonFilesMetadataBuilder {
public abstract class InterCaseCommonFilesMetadataBuilder extends AbstractCommonFilesMetadataBuilder {
//CONSIDER: we should create an interface which specifies the findFiles feature
// instead of an abstract class and then have two abstract classes:
// inter- and intra- which implement the interface and then 4 subclasses
@ -52,7 +52,8 @@ public abstract class InterCaseCommonFilesMetadataBuilder extends ICommonFilesMe
* @throws EamDbException
*/
InterCaseCommonFilesMetadataBuilder(boolean filterByMediaMimeType, boolean filterByDocMimeType) throws EamDbException {
//TODO these two boolean variables are unused for the intercase feature at the moment
filterByMedia = filterByMediaMimeType;
filterByDoc = filterByDocMimeType;
dbManager = EamDb.getInstance();
}
@ -105,13 +106,6 @@ public abstract class InterCaseCommonFilesMetadataBuilder extends ICommonFilesMe
return instanceCollatedCommonFiles;
}
@Override
String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString();
final String titleTemplate = Bundle.CommonFilesMetadataBuilder_buildTabTitle_titleEamDb();
return String.format(titleTemplate, new Object[]{buildCategorySelectionString});
}
protected CorrelationCase getCorrelationCaseFromId(int correlationCaseId) throws EamDbException, Exception {
for (CorrelationCase cCase : this.dbManager.getCases()) {
if (cCase.getID() == correlationCaseId) {

View File

@ -27,7 +27,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.AbstractFile;
@ -45,11 +44,9 @@ import org.sleuthkit.datamodel.TskCoreException;
* This entire thing runs on a background thread where exceptions are handled.
*/
@SuppressWarnings("PMD.AbstractNaming")
public abstract class IntraCaseCommonFilesMetadataBuilder extends ICommonFilesMetadataBuilder {
public abstract class IntraCaseCommonFilesMetadataBuilder extends AbstractCommonFilesMetadataBuilder {
private final Map<Long, String> dataSourceIdToNameMap;
private final boolean filterByMedia;
private final boolean filterByDoc;
private static final String FILTER_BY_MIME_TYPES_WHERE_CLAUSE = " and mime_type in (%s)"; //NON-NLS // where %s is csv list of mime_types to filter on
/**
@ -100,6 +97,7 @@ public abstract class IntraCaseCommonFilesMetadataBuilder extends ICommonFilesMe
* @throws NoCurrentCaseException
* @throws SQLException
*/
@Override
public CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, Exception {
//TODO do we need all those exceptions or can we differentiate when they are caught?
Map<String, Md5Metadata> commonFiles = new HashMap<>();
@ -174,23 +172,4 @@ public abstract class IntraCaseCommonFilesMetadataBuilder extends ICommonFilesMe
return mimeTypeString;
}
@NbBundle.Messages({
"CommonFilesMetadataBuilder.buildCategorySelectionString.doc=Documents",
"CommonFilesMetadataBuilder.buildCategorySelectionString.media=Media",
"CommonFilesMetadataBuilder.buildCategorySelectionString.all=All File Categories"
})
protected String buildCategorySelectionString() {
if (!this.filterByDoc && !this.filterByMedia) {
return Bundle.CommonFilesMetadataBuilder_buildCategorySelectionString_all();
} else {
List<String> filters = new ArrayList<>();
if (this.filterByDoc) {
filters.add(Bundle.CommonFilesMetadataBuilder_buildCategorySelectionString_doc());
}
if (this.filterByMedia) {
filters.add(Bundle.CommonFilesMetadataBuilder_buildCategorySelectionString_media());
}
return String.join(", ", filters);
}
}
}

View File

@ -19,21 +19,16 @@
*/
package org.sleuthkit.autopsy.commonfilesearch;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.Sheet;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.commonfilesearch.FileInstanceNodeGenerator;
import org.sleuthkit.autopsy.commonfilesearch.Md5Metadata;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNode;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNodeVisitor;
import org.sleuthkit.autopsy.datamodel.NodeProperty;
import org.sleuthkit.datamodel.AbstractFile;
/**
* Represents a common files match - two or more files which appear to be the

View File

@ -36,6 +36,7 @@ import org.sleuthkit.datamodel.TskCoreException;
public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMetadataBuilder {
private final int corrleationCaseId;
private String correlationCaseName;
/**
*
@ -48,6 +49,7 @@ public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMet
super(filterByMediaMimeType, filterByDocMimeType);
this.corrleationCaseId = correlationCaseId;
this.correlationCaseName = "";
}
/**
@ -66,7 +68,7 @@ public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMet
public CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, EamDbException, Exception {
CorrelationCase cCase = this.getCorrelationCaseFromId(this.corrleationCaseId);
correlationCaseName = cCase.getDisplayName();
return this.findFiles(cCase);
}
@ -82,8 +84,10 @@ public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMet
}
@Override
String buildCategorySelectionString() {
//TODO
return "";
String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString();
final String titleTemplate = Bundle.AbstractCommonFilesMetadataBuilder_buildTabTitle_titleInterSingle();
return String.format(titleTemplate, new Object[]{correlationCaseName, buildCategorySelectionString});
}
}

View File

@ -56,7 +56,7 @@ final public class SingleDataSourceCommonFilesAlgorithm extends IntraCaseCommonF
@Override
public String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString();
final String titleTemplate = Bundle.CommonFilesMetadataBuilder_buildTabTitle_titleSingle();
final String titleTemplate = Bundle.AbstractCommonFilesMetadataBuilder_buildTabTitle_titleIntraSingle();
return String.format(titleTemplate, new Object[]{this.dataSourceName, buildCategorySelectionString});
}
}