From 659b891f9b0fb00a5b696faec13c832f2e53adf1 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Mon, 6 Feb 2017 14:04:13 -0500 Subject: [PATCH] Logic to read and write all existing Solr cores into SolrCore.properties --- .../autopsy/keywordsearch/IndexMetadata.java | 8 +++----- .../autopsy/keywordsearch/SolrSearchService.java | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexMetadata.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexMetadata.java index af92108864..381ecb7dfa 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexMetadata.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/IndexMetadata.java @@ -52,7 +52,6 @@ public class IndexMetadata { private final Path metadataFilePath; private final String metadataFileName = "SolrCore.properties"; private final static String ROOT_ELEMENT_NAME = "SolrCores"; //NON-NLS - private final static String NUM_CORES_ELEMENT_NAME = "NumberOfCore"; //NON-NLS private final static String CORE_ELEMENT_NAME = "Core"; //NON-NLS private final static String CORE_NAME_ELEMENT_NAME = "CoreName"; //NON-NLS private final static String SCHEMA_VERSION_ELEMENT_NAME = "SchemaVersion"; //NON-NLS @@ -81,13 +80,13 @@ public class IndexMetadata { * Constructs an object that provides access to the text index metadata stored in * an existing text index metadata file. * - * @param metadataFilePath The full path to the text index metadata file. + * @param caseDirectory The full path to the top level case output folder. * * @throws TextIndexMetadataException If the new text index metadata file cannot be * read. */ - public IndexMetadata(Path metadataFilePath) throws TextIndexMetadataException { - this.metadataFilePath = metadataFilePath; + public IndexMetadata(String caseDirectory) throws TextIndexMetadataException { + this.metadataFilePath = Paths.get(caseDirectory, metadataFileName); readFromFile(); } @@ -148,7 +147,6 @@ public class IndexMetadata { */ Element rootElement = doc.createElement(ROOT_ELEMENT_NAME); doc.appendChild(rootElement); - // ELTODO REMOVE createChildElement(doc, rootElement, NUM_CORES_ELEMENT_NAME, Integer.toString(indexes.size())); /* * Create the children of the Solr cores element. diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java index d015988b1b..87d02245b9 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java @@ -193,12 +193,15 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { } // check if index needs upgrade - Index currentVersionIndex; + Index currentVersionIndex = null; if (indexes.isEmpty()) { // new case that doesn't have an existing index. create new index folder progressUnitsCompleted++; progress.progress(Bundle.SolrSearch_creatingNewIndex_msg(), progressUnitsCompleted); currentVersionIndex = IndexFinder.createLatestVersionIndexDir(context.getCase()); + + // add current index to the list of indexes that exist for this case + indexes.add(currentVersionIndex); } else { // check if one of the existing indexes is for latest Solr version and schema progressUnitsCompleted++; @@ -293,6 +296,9 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { logger.log(Level.SEVERE, String.format("Failed to delete %s when upgrade cancelled", newIndexVersionDir), ex); } } + + // add current index to the list of indexes that exist for this case + indexes.add(currentVersionIndex); } } } @@ -307,11 +313,10 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService { try { // store the new core name - indexes.add(currentVersionIndex); IndexMetadata indexMetadata = new IndexMetadata(context.getCase().getCaseDirectory(), indexes); // ELTODO remove - IndexMetadata ind = new IndexMetadata(indexMetadata.getFilePath()); + IndexMetadata ind = new IndexMetadata(context.getCase().getCaseDirectory()); } catch (IndexMetadata.TextIndexMetadataException ex) { throw new AutopsyServiceException("Failed to save core name in case metadata file", ex); }