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.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
/** abstract class AbstractCommonFilesMetadataBuilder {
*
* @author bsweeney boolean filterByMedia;
*/ boolean filterByDoc;
abstract class ICommonFilesMetadataBuilder {
abstract CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, Exception; 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 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) { static Map<Integer, List<Md5Metadata>> collateMatchesByNumberOfInstances(Map<String, Md5Metadata> commonFiles) {
//collate matches by number of matching instances - doing this in sql doesnt seem efficient //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 @Override
String buildCategorySelectionString() { String buildTabTitle() {
//TODO final String buildCategorySelectionString = this.buildCategorySelectionString();
return ""; 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 @Override
protected String buildTabTitle() { protected String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString(); 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}); return String.format(titleTemplate, new Object[]{buildCategorySelectionString});
} }
} }

View File

@ -30,7 +30,6 @@ import javax.swing.SwingUtilities;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandle;
import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerManager;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; 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 Long NO_DATA_SOURCE_SELECTED = -1L;
private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class.getName()); private static final Logger LOGGER = Logger.getLogger(CommonFilesPanel.class.getName());
private boolean singleDataSource = false;
private String selectedDataSource = "";
private boolean pictureViewCheckboxState; private boolean pictureViewCheckboxState;
private boolean documentsCheckboxState; private boolean documentsCheckboxState;
@ -74,9 +70,6 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
initComponents(); initComponents();
this.errorText.setVisible(false); this.errorText.setVisible(false);
this.intraCasePanel.setParent(this);
this.setupDataSources(); this.setupDataSources();
if (CommonFilesPanel.isEamDbAvailable()) { if (CommonFilesPanel.isEamDbAvailable()) {
@ -141,7 +134,7 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
Long dataSourceId = intraCasePanel.getSelectedDataSourceId(); Long dataSourceId = intraCasePanel.getSelectedDataSourceId();
Integer caseId = interCasePanel.getSelectedCaseId(); Integer caseId = interCasePanel.getSelectedCaseId();
IntraCaseCommonFilesMetadataBuilder builder; AbstractCommonFilesMetadataBuilder builder;
CommonFilesMetadata metadata; CommonFilesMetadata metadata;
boolean filterByMedia = false; boolean filterByMedia = false;
@ -173,8 +166,6 @@ public final class CommonFilesPanel extends javax.swing.JPanel {
setTitleForSingleSource(dataSourceId); setTitleForSingleSource(dataSourceId);
} }
} }
//TODO set title from one method rather than two (or more) overloads
metadata = builder.findFiles(); metadata = builder.findFiles();
this.tabTitle = builder.buildTabTitle(); 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 * Provides logic for selecting common files from all data sources and all cases
* in the Central Repo. * 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 //CONSIDER: we should create an interface which specifies the findFiles feature
// instead of an abstract class and then have two abstract classes: // instead of an abstract class and then have two abstract classes:
// inter- and intra- which implement the interface and then 4 subclasses // inter- and intra- which implement the interface and then 4 subclasses
@ -52,7 +52,8 @@ public abstract class InterCaseCommonFilesMetadataBuilder extends ICommonFilesMe
* @throws EamDbException * @throws EamDbException
*/ */
InterCaseCommonFilesMetadataBuilder(boolean filterByMediaMimeType, boolean filterByDocMimeType) 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(); dbManager = EamDb.getInstance();
} }
@ -105,13 +106,6 @@ public abstract class InterCaseCommonFilesMetadataBuilder extends ICommonFilesMe
return instanceCollatedCommonFiles; 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 { protected CorrelationCase getCorrelationCaseFromId(int correlationCaseId) throws EamDbException, Exception {
for (CorrelationCase cCase : this.dbManager.getCases()) { for (CorrelationCase cCase : this.dbManager.getCases()) {
if (cCase.getID() == correlationCaseId) { if (cCase.getID() == correlationCaseId) {

View File

@ -27,7 +27,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.datamodel.AbstractFile; 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. * This entire thing runs on a background thread where exceptions are handled.
*/ */
@SuppressWarnings("PMD.AbstractNaming") @SuppressWarnings("PMD.AbstractNaming")
public abstract class IntraCaseCommonFilesMetadataBuilder extends ICommonFilesMetadataBuilder { public abstract class IntraCaseCommonFilesMetadataBuilder extends AbstractCommonFilesMetadataBuilder {
private final Map<Long, String> dataSourceIdToNameMap; 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 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 NoCurrentCaseException
* @throws SQLException * @throws SQLException
*/ */
@Override
public CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, Exception { public CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, Exception {
//TODO do we need all those exceptions or can we differentiate when they are caught? //TODO do we need all those exceptions or can we differentiate when they are caught?
Map<String, Md5Metadata> commonFiles = new HashMap<>(); Map<String, Md5Metadata> commonFiles = new HashMap<>();
@ -174,23 +172,4 @@ public abstract class IntraCaseCommonFilesMetadataBuilder extends ICommonFilesMe
return mimeTypeString; 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; package org.sleuthkit.autopsy.commonfilesearch;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.openide.nodes.ChildFactory; import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children; import org.openide.nodes.Children;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.nodes.Sheet; import org.openide.nodes.Sheet;
import org.openide.util.NbBundle; 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.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNode; import org.sleuthkit.autopsy.datamodel.DisplayableItemNode;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNodeVisitor; import org.sleuthkit.autopsy.datamodel.DisplayableItemNodeVisitor;
import org.sleuthkit.autopsy.datamodel.NodeProperty; 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 * 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 { public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMetadataBuilder {
private final int corrleationCaseId; private final int corrleationCaseId;
private String correlationCaseName;
/** /**
* *
@ -48,6 +49,7 @@ public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMet
super(filterByMediaMimeType, filterByDocMimeType); super(filterByMediaMimeType, filterByDocMimeType);
this.corrleationCaseId = correlationCaseId; this.corrleationCaseId = correlationCaseId;
this.correlationCaseName = "";
} }
/** /**
@ -66,7 +68,7 @@ public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMet
public CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, EamDbException, Exception { public CommonFilesMetadata findFiles() throws TskCoreException, NoCurrentCaseException, SQLException, EamDbException, Exception {
CorrelationCase cCase = this.getCorrelationCaseFromId(this.corrleationCaseId); CorrelationCase cCase = this.getCorrelationCaseFromId(this.corrleationCaseId);
correlationCaseName = cCase.getDisplayName();
return this.findFiles(cCase); return this.findFiles(cCase);
} }
@ -82,8 +84,10 @@ public class SingleCaseEamDbCommonFilesAlgorithm extends InterCaseCommonFilesMet
} }
@Override @Override
String buildCategorySelectionString() { String buildTabTitle() {
//TODO final String buildCategorySelectionString = this.buildCategorySelectionString();
return ""; 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 @Override
public String buildTabTitle() { public String buildTabTitle() {
final String buildCategorySelectionString = this.buildCategorySelectionString(); 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}); return String.format(titleTemplate, new Object[]{this.dataSourceName, buildCategorySelectionString});
} }
} }