Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Index.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import org.apache.commons.lang.math.NumberUtils;
24 
28 final class Index {
29 
30  private final String indexPath;
31  private final String schemaVersion;
32  private final String solrVersion;
33  private final String indexName;
34  private static final String DEFAULT_CORE_NAME = "text_index"; //NON-NLS
35 
47  Index(String indexPath, String solrVersion, String schemaVersion, String coreName, String caseName) {
48  this.indexPath = indexPath;
49  this.solrVersion = solrVersion;
50  this.schemaVersion = schemaVersion;
51  if (coreName == null || coreName.isEmpty()) {
52  // come up with a new core name
53  coreName = createCoreName(caseName);
54  }
55  this.indexName = coreName;
56  }
57 
65  private String createCoreName(String caseName) {
66  String coreName = sanitizeCoreName(caseName);
67  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
68  Date date = new Date();
69  return coreName + "_" + dateFormat.format(date);
70  }
71 
85  static private String sanitizeCoreName(String coreName) {
86 
87  String result;
88 
89  // Allow these characters: '-', '.', '0'-'9', 'A'-'Z', '_', and 'a'-'z'.
90  // Replace all else with '_'.
91  result = coreName.replaceAll("[^-.0-9A-Z_a-z]", "_"); // NON-NLS
92 
93  // Make it all lowercase
94  result = result.toLowerCase();
95 
96  // Must not start with hyphen
97  if (result.length() > 0 && (result.codePointAt(0) == '-')) {
98  result = "_" + result;
99  }
100 
101  if (result.isEmpty()) {
102  result = DEFAULT_CORE_NAME;
103  }
104 
105  return result;
106  }
107 
111  String getIndexPath() {
112  return indexPath;
113  }
114 
118  String getSchemaVersion() {
119  return schemaVersion;
120  }
121 
125  String getSolrVersion() {
126  return solrVersion;
127  }
128 
132  String getIndexName() {
133  return indexName;
134  }
135 
144  boolean isCompatible(String version) {
145  // Versions are compatible if they have the same major version no
146  int currentMajorVersion = NumberUtils.toInt(schemaVersion.substring(0, schemaVersion.indexOf('.')));
147  int givenMajorVersion = NumberUtils.toInt(version.substring(0, version.indexOf('.')));
148 
149  return currentMajorVersion == givenMajorVersion;
150  }
151 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.