mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Merge pull request #4819 from markmckinnon/2410-delete-data-sources-from-the-case-text-index
2410 delete data sources from the case text index
This commit is contained in:
commit
acaa15c359
@ -21,10 +21,13 @@ package org.sleuthkit.autopsy.actions;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.AbstractAction;
|
||||
import org.openide.util.Lookup;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.sleuthkit.autopsy.casemodule.Case;
|
||||
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
|
||||
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
|
||||
import org.sleuthkit.datamodel.TskCoreException;
|
||||
|
||||
/**
|
||||
@ -32,21 +35,30 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
*/
|
||||
public final class DeleteDataSourceAction extends AbstractAction {
|
||||
private static final Logger logger = Logger.getLogger(DeleteDataSourceAction.class.getName());
|
||||
private final Long selectedDataSource;
|
||||
private final Long dataSourceId;
|
||||
|
||||
@NbBundle.Messages({"DeleteDataSourceAction.name.text=Delete Data Source"})
|
||||
public DeleteDataSourceAction(Long selectedDataSource) {
|
||||
public DeleteDataSourceAction(Long dataSourceId) {
|
||||
super(Bundle.DeleteDataSourceAction_name_text());
|
||||
this.selectedDataSource = selectedDataSource;
|
||||
this.dataSourceId = dataSourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(selectedDataSource);
|
||||
} catch (NoCurrentCaseException | TskCoreException e) {
|
||||
logger.log(Level.WARNING, "Error Deleting Data source " + selectedDataSource, e);
|
||||
Case.getCurrentCaseThrows().getSleuthkitCase().deleteDataSource(dataSourceId);
|
||||
deleteDataSource(dataSourceId);
|
||||
} catch (NoCurrentCaseException | TskCoreException | KeywordSearchServiceException e) {
|
||||
logger.log(Level.WARNING, "Error Deleting Data source " + dataSourceId, e);
|
||||
}
|
||||
}
|
||||
private static void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException {
|
||||
try {
|
||||
KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class);
|
||||
kwsService.deleteDataSource(dataSourceId);
|
||||
} catch (KeywordSearchServiceException e) {
|
||||
logger.log(Level.WARNING, "KWS Error", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -97,4 +97,13 @@ public interface KeywordSearchService extends Closeable {
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the keyword search text for a specific data source.
|
||||
*
|
||||
* @param dataSourceId The data source id to be deleted.
|
||||
*
|
||||
* @throws KeywordSearchServiceException if unable to delete.
|
||||
*/
|
||||
void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException;
|
||||
|
||||
}
|
||||
|
@ -298,6 +298,7 @@ GlobalEditListPanel.editWordButton.text=Edit Keyword
|
||||
SolrSearchService.ServiceName=Solr Keyword Search Service
|
||||
SolrSearchService.IndexReadOnlyDialog.title=Text Index Is Read-Only
|
||||
SolrSearchService.IndexReadOnlyDialog.msg=<html>The text index for this case is read-only. <br />You will be able to see existing keyword search results and perform exact match and substring match keyword searches,<br />but you will not be able to add new text to the index or perform regex searches. You may instead open the case<br /> with your previous version of this application.</html>
|
||||
SolrSearchService.DeleteDataSource.msg=Error Deleting Solr data for data source id {0}
|
||||
ExtractedContentPanel.jLabel1.text=Text Source:
|
||||
ExtractedContentPanel.pagePreviousButton.actionCommand=pagePreviousButton
|
||||
ExtractedContentPanel.pagePreviousButton.text=
|
||||
|
@ -348,6 +348,7 @@ SolrSearch.openCore.msg=Opening text index
|
||||
SolrSearch.openGiantCore.msg=Opening text index. Text index for this case is very large and may take long time to load.
|
||||
SolrSearch.openLargeCore.msg=Opening text index. This may take several minutes.
|
||||
SolrSearch.readingIndexes.msg=Reading text index metadata file
|
||||
SolrSearchService.deleteDataSource.exceptionMessage.noCurrentSolrCore=DeleteDataSource did not contain a current Solr core so could not delete the Data Source
|
||||
# {0} - index folder path
|
||||
SolrSearchService.exceptionMessage.failedToDeleteIndexFiles=Failed to delete text index files at {0}
|
||||
SolrSearchService.exceptionMessage.noCurrentSolrCore=IndexMetadata did not contain a current Solr core so could not delete the case
|
||||
@ -357,6 +358,7 @@ SolrSearchService.indexingError=Unable to index blackboard artifact.
|
||||
SolrSearchService.ServiceName=Solr Keyword Search Service
|
||||
SolrSearchService.IndexReadOnlyDialog.title=Text Index Is Read-Only
|
||||
SolrSearchService.IndexReadOnlyDialog.msg=<html>The text index for this case is read-only. <br />You will be able to see existing keyword search results and perform exact match and substring match keyword searches,<br />but you will not be able to add new text to the index or perform regex searches. You may instead open the case<br /> with your previous version of this application.</html>
|
||||
SolrSearchService.DeleteDataSource.msg=Error Deleting Solr data for data source id {0}
|
||||
ExtractedContentPanel.jLabel1.text=Text Source:
|
||||
ExtractedContentPanel.pagePreviousButton.actionCommand=pagePreviousButton
|
||||
ExtractedContentPanel.pagePreviousButton.text=
|
||||
|
@ -189,9 +189,9 @@ public class Server {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* termfreq is a function which returns the number of times the term appears.
|
||||
* This is not an actual field defined in schema.xml, but can be gotten from returned documents
|
||||
* in the same way as fields.
|
||||
* termfreq is a function which returns the number of times the term
|
||||
* appears. This is not an actual field defined in schema.xml, but can
|
||||
* be gotten from returned documents in the same way as fields.
|
||||
*/
|
||||
TERMFREQ {
|
||||
@Override
|
||||
@ -892,12 +892,14 @@ public class Server {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the host and port for a multiuser case.
|
||||
* If the file solrserver.txt exists, then use the values from that file.
|
||||
* Otherwise use the settings from the properties file.
|
||||
* Get the host and port for a multiuser case. If the file solrserver.txt
|
||||
* exists, then use the values from that file. Otherwise use the settings
|
||||
* from the properties file.
|
||||
*
|
||||
* @param caseDirectory Current case directory
|
||||
* @return IndexingServerProperties containing the solr host/port for this case
|
||||
*
|
||||
* @return IndexingServerProperties containing the solr host/port for this
|
||||
* case
|
||||
*/
|
||||
public static IndexingServerProperties getMultiUserServerProperties(String caseDirectory) {
|
||||
|
||||
@ -929,16 +931,15 @@ public class Server {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick a solr server to use for this case and record it in the case directory.
|
||||
* Looks for a file named "solrServerList.txt" in the root output directory -
|
||||
* if this does not exist then no server is recorded.
|
||||
* Pick a solr server to use for this case and record it in the case
|
||||
* directory. Looks for a file named "solrServerList.txt" in the root output
|
||||
* directory - if this does not exist then no server is recorded.
|
||||
*
|
||||
* Format of solrServerList.txt:
|
||||
* (host),(port)
|
||||
* Ex: 10.1.2.34,8983
|
||||
* Format of solrServerList.txt: (host),(port) Ex: 10.1.2.34,8983
|
||||
*
|
||||
* @param rootOutputDirectory
|
||||
* @param caseDirectoryPath
|
||||
*
|
||||
* @throws KeywordSearchModuleException
|
||||
*/
|
||||
public static void selectSolrServerForCase(Path rootOutputDirectory, Path caseDirectoryPath) throws KeywordSearchModuleException {
|
||||
@ -999,6 +1000,7 @@ public class Server {
|
||||
* Helper class to store the current server properties
|
||||
*/
|
||||
public static class IndexingServerProperties {
|
||||
|
||||
private final String host;
|
||||
private final String port;
|
||||
|
||||
@ -1009,6 +1011,7 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Get the host
|
||||
*
|
||||
* @return host
|
||||
*/
|
||||
public String getHost() {
|
||||
@ -1017,6 +1020,7 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Get the port
|
||||
*
|
||||
* @return port
|
||||
*/
|
||||
public String getPort() {
|
||||
@ -1265,6 +1269,26 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a data source from SOLR.
|
||||
*
|
||||
* @param dataSourceId to delete
|
||||
*
|
||||
* @throws NoOpenCoreException
|
||||
*/
|
||||
void deleteDataSource(Long dataSourceId) throws IOException, KeywordSearchModuleException, NoOpenCoreException, SolrServerException {
|
||||
try {
|
||||
currentCoreLock.writeLock().lock();
|
||||
if (null == currentCore) {
|
||||
throw new NoOpenCoreException();
|
||||
}
|
||||
currentCore.deleteDataSource(dataSourceId);
|
||||
currentCore.commit();
|
||||
} finally {
|
||||
currentCoreLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text contents of the given file as stored in SOLR.
|
||||
*
|
||||
@ -1506,6 +1530,13 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDataSource(Long dsObjId) throws IOException, SolrServerException {
|
||||
String dataSourceId = Long.toString(dsObjId);
|
||||
String deleteQuery = "image_id:" + dataSourceId;
|
||||
|
||||
solrCore.deleteByQuery(deleteQuery);
|
||||
}
|
||||
|
||||
void addDocument(SolrInputDocument doc) throws KeywordSearchModuleException {
|
||||
try {
|
||||
solrCore.add(doc);
|
||||
@ -1527,7 +1558,8 @@ public class Server {
|
||||
* @param chunkID Chunk ID of the Solr document
|
||||
*
|
||||
* @return Text from matching Solr document (as String). Null if no
|
||||
* matching Solr document found or error while getting content from Solr
|
||||
* matching Solr document found or error while getting content
|
||||
* from Solr
|
||||
*/
|
||||
private String getSolrContent(long contentID, int chunkID) {
|
||||
final SolrQuery q = new SolrQuery();
|
||||
|
@ -60,8 +60,7 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
* text indexing and search.
|
||||
*/
|
||||
@ServiceProviders(value = {
|
||||
@ServiceProvider(service = KeywordSearchService.class)
|
||||
,
|
||||
@ServiceProvider(service = KeywordSearchService.class),
|
||||
@ServiceProvider(service = AutopsyService.class)
|
||||
})
|
||||
public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
||||
@ -194,6 +193,26 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a data source from Solr for a case.
|
||||
*
|
||||
* @param dataSourceId the id of the data source to delete.
|
||||
*
|
||||
* @throws
|
||||
* org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException
|
||||
*/
|
||||
@Override
|
||||
public void deleteDataSource(Long dataSourceId) throws KeywordSearchServiceException {
|
||||
|
||||
try {
|
||||
Server ddsServer = KeywordSearch.getServer();
|
||||
ddsServer.deleteDataSource(dataSourceId);
|
||||
} catch (IOException | KeywordSearchModuleException | NoOpenCoreException | SolrServerException ex) {
|
||||
logger.log(Level.WARNING, NbBundle.getMessage(SolrSearchService.class, "SolrSearchService.DeleteDataSource.msg", dataSourceId), ex);
|
||||
throw new KeywordSearchServiceException(NbBundle.getMessage(SolrSearchService.class, "SolrSearchService.DeleteDataSource.msg", dataSourceId), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes Solr core for a case.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user