19 package org.sleuthkit.autopsy.keywordsearch;
22 import java.nio.file.Paths;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.List;
27 import org.apache.commons.lang.math.NumberUtils;
37 private static final Logger logger = Logger.getLogger(IndexFinder.class.getName());
38 private static final String KWS_OUTPUT_FOLDER_NAME =
"keywordsearch";
39 private static final String KWS_DATA_FOLDER_NAME =
"data";
40 private static final String INDEX_FOLDER_NAME =
"index";
41 private static final String CURRENT_SOLR_VERSION =
"4";
42 private static final String CURRENT_SOLR_SCHEMA_VERSION =
"2.1";
44 static String getCurrentSolrVersion() {
45 return CURRENT_SOLR_VERSION;
48 static String getCurrentSchemaVersion() {
49 return CURRENT_SOLR_SCHEMA_VERSION;
52 static Index findLatestVersionIndexDir(List<Index> allIndexes) {
53 for (Index index : allIndexes) {
54 if (index.getSolrVersion().equals(CURRENT_SOLR_VERSION) && index.getSchemaVersion().equals(CURRENT_SOLR_SCHEMA_VERSION)) {
62 String indexFolderName =
"solr" + CURRENT_SOLR_VERSION +
"_schema" + CURRENT_SOLR_SCHEMA_VERSION;
64 File targetDirPath = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, indexFolderName, INDEX_FOLDER_NAME).toFile();
65 if (!targetDirPath.mkdirs()) {
66 throw new AutopsyService.
AutopsyServiceException(
"Unable to create text index directory " + targetDirPath.getAbsolutePath());
68 return new Index(targetDirPath.getAbsolutePath(), CURRENT_SOLR_VERSION, CURRENT_SOLR_SCHEMA_VERSION,
"", theCase.getName());
71 static Index identifyIndexToUse(List<Index> allIndexes) {
80 Index bestCandidateIndex = null;
81 double solrVerFound = 0.0;
82 double schemaVerFound = 0.0;
83 for (Index index : allIndexes) {
85 if (NumberUtils.toDouble(index.getSolrVersion()) >= solrVerFound) {
87 if (NumberUtils.toDouble(index.getSchemaVersion()) >= schemaVerFound) {
88 bestCandidateIndex = index;
89 solrVerFound = NumberUtils.toDouble(index.getSolrVersion());
90 schemaVerFound = NumberUtils.toDouble(index.getSchemaVersion());
94 return bestCandidateIndex;
106 static Index findOldIndexDir(Case theCase) {
108 if (theCase.getCaseType() == Case.CaseType.MULTI_USER_CASE) {
118 List<File> contents = getAllContentsInFolder(theCase.getCaseDirectory());
119 if (!contents.isEmpty()) {
122 String moduleOutDirName =
new File(theCase.getModuleDirectory()).getName();
125 for (File item : contents) {
126 File path = Paths.get(item.getAbsolutePath(), moduleOutDirName, KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, INDEX_FOLDER_NAME).toFile();
128 if (isNonEmptyIndexFolder(path)) {
129 return new Index(path.toString(),
"4",
"1.8", theCase.getTextIndexName(), theCase.getName());
139 File path = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, INDEX_FOLDER_NAME).toFile();
141 if (isNonEmptyIndexFolder(path)) {
142 return new Index(path.toString(),
"4",
"1.8", theCase.getTextIndexName(), theCase.getName());
155 private static List<File> getAllContentsInFolder(String path) {
156 File directory =
new File(path);
157 File[] contents = directory.listFiles();
158 if (contents == null) {
160 return Collections.emptyList();
161 }
else if (contents.length == 0) {
163 return Collections.emptyList();
166 return new ArrayList<>(Arrays.asList(contents));
170 private static boolean isNonEmptyIndexFolder(File path) {
171 if (path.exists() && path.isDirectory() && path.getName().equals(INDEX_FOLDER_NAME) && path.listFiles().length > 0) {
AutopsyServiceException(String message)