handle cache clears from preference updates

This commit is contained in:
Greg DiCristofaro 2022-04-20 14:57:02 -04:00
parent 7e9001305d
commit 8cedfcda60
3 changed files with 72 additions and 7 deletions

View File

@ -105,6 +105,7 @@ import org.sleuthkit.autopsy.mainui.datamodel.ViewsDAO.DeletedFileFetcher;
import org.sleuthkit.autopsy.mainui.datamodel.DeletedContentSearchParams;
import org.sleuthkit.autopsy.mainui.datamodel.ReportsDAO.ReportsFetcher;
import org.sleuthkit.autopsy.mainui.datamodel.ReportsSearchParams;
import org.sleuthkit.autopsy.mainui.datamodel.events.CacheClearEvent;
import org.sleuthkit.autopsy.mainui.nodes.ChildNodeSelectionInfo;
import org.sleuthkit.autopsy.mainui.nodes.SearchManager;
@ -189,10 +190,19 @@ public class DataResultPanel extends javax.swing.JPanel implements DataResult, C
private final PropertyChangeListener DAOListener = evt -> {
SearchManager manager = this.searchResultManager;
if (manager != null && evt != null && evt.getNewValue() instanceof DAOAggregateEvent) {
DAOAggregateEvent daoAggrEvt = (DAOAggregateEvent) evt.getNewValue();
if (daoAggrEvt.getEvents().stream().anyMatch((daoEvt) -> manager.isRefreshRequired(daoEvt))) {
refreshSearchResultChildren();
if (manager != null && evt != null) {
if (evt.getNewValue() instanceof DAOAggregateEvent) {
DAOAggregateEvent daoAggrEvt = (DAOAggregateEvent) evt.getNewValue();
if (daoAggrEvt.getEvents().stream().anyMatch((daoEvt) -> manager.isRefreshRequired(daoEvt))) {
refreshSearchResultChildren();
}
} else if (evt.getNewValue() instanceof CacheClearEvent) {
try {
this.searchResultManager = new SearchManager(this.searchResultManager.getDaoFetcher(), getPageSize());
displaySearchResults(this.searchResultManager.getResults(), true);
} catch (ExecutionException ex) {
logger.log(Level.WARNING, "An exception occurred while handling cache clear event.", ex);
}
}
}
};

View File

@ -43,6 +43,7 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.core.UserPreferences;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.mainui.datamodel.events.CacheClearEvent;
import org.sleuthkit.autopsy.mainui.datamodel.events.TreeEvent;
/**
@ -173,7 +174,7 @@ public class MainDAO extends AbstractDAO {
private final EmailsDAO emailsDAO = EmailsDAO.getInstance();
private final HostPersonDAO hostPersonDAO = HostPersonDAO.getInstance();
private final ReportsDAO reportsDAO = ReportsDAO.getInstance();
// NOTE: whenever adding a new sub-dao, it should be added to this list for event updates.
private final List<AbstractDAO> allDAOs = ImmutableList.of(dataArtifactDAO,
analysisResultDAO,
@ -248,7 +249,7 @@ public class MainDAO extends AbstractDAO {
public CommAccountsDAO getCommAccountsDAO() {
return commAccountsDAO;
}
public EmailsDAO getEmailsDAO() {
return emailsDAO;
}
@ -263,7 +264,7 @@ public class MainDAO extends AbstractDAO {
public ReportsDAO getReportsDAO() {
return reportsDAO;
}
}
public PropertyChangeManager getResultEventsManager() {
return this.resultEventsManager;
@ -276,6 +277,9 @@ public class MainDAO extends AbstractDAO {
@Override
void clearCaches() {
allDAOs.forEach((subDAO) -> subDAO.clearCaches());
resultEventsManager.firePropertyChange("DATA_CLEAR", null, CacheClearEvent.getInstance());
treeEventsManager.firePropertyChange("TREE_CLEAR", null, CacheClearEvent.getInstance());
}
@Override

View File

@ -0,0 +1,51 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2022 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.mainui.datamodel.events;
/**
* Event fired when all dao caches cleared.
*/
public class CacheClearEvent {
private final static CacheClearEvent instance = new CacheClearEvent();
/**
* @return Singleton instance of this class.
*/
public static CacheClearEvent getInstance() {
return instance;
}
private final String eventType = "CACHE_CLEAR";
private CacheClearEvent() {}
/**
* @return The event type string.
*/
public String getEventType() {
return eventType;
}
}