From d03108c4038c19f5fbdceb054483eb92d488c5a6 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 14 Feb 2017 10:57:26 -0500 Subject: [PATCH] Code review + bug fixes --- .../autopsy/keywordsearch/Index.java | 33 ++++++++++++------- .../keywordsearch/SolrSearchService.java | 24 +++++++------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Index.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Index.java index 05407888b6..53b65545b7 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Index.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Index.java @@ -26,14 +26,25 @@ import org.sleuthkit.autopsy.coreutils.UNCPathUtilities; * This class encapsulates KWS index data. */ final class Index { - + private final String indexPath; private final String schemaVersion; private final String solrVersion; private final String indexName; private static final String DEFAULT_CORE_NAME = "text_index"; //NON-NLS private final UNCPathUtilities uncPathUtilities = new UNCPathUtilities(); - + + /** + * Constructs a representation of a text index. + * + * @param indexPath The path to the index. + * @param solrVersion The Solr version of the index. + * @param schemaVersion The Solr schema version of the index. + * @param coreName The core name, may be the empty string or null if + * the corename should be generated. + * @param caseName The name of the case, ignored if coreName does not + * need to be generated. + */ Index(String indexPath, String solrVersion, String schemaVersion, String coreName, String caseName) { this.indexPath = convertPathToUNC(indexPath); this.solrVersion = solrVersion; @@ -44,7 +55,7 @@ final class Index { } this.indexName = coreName; } - + /** * Create and sanitize a core name. * @@ -53,19 +64,20 @@ final class Index { * @return The sanitized Solr core name */ private String createCoreName(String caseName) { + String coreName = sanitizeCoreName(caseName); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); Date date = new Date(); - String coreName = caseName + "_" + dateFormat.format(date); - return sanitizeCoreName(coreName); + return coreName + "_" + dateFormat.format(date); } - + /** * Sanitizes the case name for Solr cores. * * Solr: * http://stackoverflow.com/questions/29977519/what-makes-an-invalid-core-name - * may not be / \ : - * Starting Solr6: core names must consist entirely of periods, underscores, hyphens, and alphanumerics as well not start with a hyphen. may not contain space characters. + * may not be / \ : Starting Solr6: core names must consist entirely of + * periods, underscores, hyphens, and alphanumerics as well not start with a + * hyphen. may not contain space characters. * * @param coreName A candidate core name. * @@ -83,7 +95,7 @@ final class Index { // Remove spaces / \ : ? ' " result = result.replaceAll("[ /?:'\"\\\\]", "_"); //NON-NLS - + // Make it all lowercase result = result.toLowerCase(); @@ -100,9 +112,6 @@ final class Index { } String convertPathToUNC(String indexDir) { - if (uncPathUtilities == null) { - return indexDir; - } // if we can check for UNC paths, do so, otherwise just return the indexDir String result = uncPathUtilities.mappedDriveToUNC(indexDir); if (result == null) { diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java index 76ac64da41..c8eba28a07 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java @@ -184,7 +184,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { public void openCaseResources(CaseContext context) throws AutopsyServiceException { ProgressIndicator progress = context.getProgressIndicator(); int totalNumProgressUnits = 8; - int progressUnitsCompleted = 1; + int progressUnitsCompleted = 0; List indexes = new ArrayList<>(); try { @@ -311,6 +311,7 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { } catch (IOException ex) { logger.log(Level.SEVERE, String.format("Failed to delete %s when upgrade cancelled", newIndexVersionDir), ex); } + return; } // add current index to the list of indexes that exist for this case @@ -319,6 +320,16 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { } } + + try { + // update text index metadata file + if (!indexes.isEmpty()) { + IndexMetadata indexMetadata = new IndexMetadata(context.getCase().getCaseDirectory(), indexes); + } + } catch (IndexMetadata.TextIndexMetadataException ex) { + throw new AutopsyServiceException("Failed to save Solr core info in text index metadata file", ex); + } + // open core try { progress.progress(Bundle.SolrSearch_openCore_msg(), totalNumProgressUnits - 1); @@ -327,17 +338,6 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { throw new AutopsyServiceException(String.format("Failed to open or create core for %s", context.getCase().getCaseDirectory()), ex); } - try { - // update text index metadata file - if (!indexes.isEmpty()) { - // ELTODO REMOVE - List FAKEindexes = new ArrayList<>(); - IndexMetadata indexMetadata = new IndexMetadata(context.getCase().getCaseDirectory(), FAKEindexes); - } - } catch (IndexMetadata.TextIndexMetadataException ex) { - throw new AutopsyServiceException("Failed to save Solr core info in text index metadata file", ex); - } - progress.progress(Bundle.SolrSearch_complete_msg(), totalNumProgressUnits); }